# HG changeset patch # User viric # Date 1324502780 -3600 # Node ID f85465640dd42cc120a0664467f9a43786010ad6 # Parent 021968512187eb168cd259c12e470d03063e093f Making pce print timestamps in the download. diff -r 021968512187 -r f85465640dd4 pce.c --- a/pce.c Wed Dec 21 21:41:32 2011 +0100 +++ b/pce.c Wed Dec 21 22:26:20 2011 +0100 @@ -32,6 +32,11 @@ int ep_in = 1; int ep_out = 2; + +/* Downloading, the base timestamp */ +time_t timestamp; +int time_per_sample; + enum { HELP, @@ -157,19 +162,42 @@ void parse_data(char *data) { - fprintf(outfile, "# Start: %hi-%hhi-%hhi %hhi:%hhi:%hhi\n", - *((short int *) (data + 16)), - *((unsigned char *) (data + 28))+1, - *((unsigned char *) (data + 29)), - *((unsigned char *) (data + 30)), - *((unsigned char *) (data + 31)), - *((unsigned char *) (data + 32))); + time_t now; + struct tm *tm_now; + struct tm tm; + + now = time(0); + + tm_now = localtime(&now); + memset(&tm, 0, sizeof(tm)); + + tm.tm_isdst = tm_now->tm_isdst; + tm.tm_year = *((short int *) (data + 16)) - 1900; + tm.tm_mon = *((unsigned char *) (data + 28)); + tm.tm_mday = *((unsigned char *) (data + 29)); + tm.tm_hour = *((unsigned char *) (data + 30)); + tm.tm_min = *((unsigned char *) (data + 31)); + tm.tm_sec = *((unsigned char *) (data + 32)); + + timestamp = mktime(&tm); + + fprintf(outfile, "# Start: %i-%i-%i %i:%i:%i @%llu\n", + tm.tm_year + 1900, + tm.tm_mon+1, + tm.tm_mday, + tm.tm_hour, + tm.tm_min, + tm.tm_sec, + (unsigned long long) timestamp); + fprintf(outfile, "# Num Samples: %hi\n", *((short int *) (data + 8)) ); - fprintf(outfile, "# Time between samples: %hi s\n", - *((short int *) (data + 12)) - ); + + time_per_sample = *((short int *) (data + 12)); + + fprintf(outfile, "# Time between samples: %i s\n", + time_per_sample); } int @@ -204,7 +232,7 @@ parse_data(data); - int sec = 0; + int sample = 0; int block = 0; do { @@ -234,8 +262,13 @@ { float temp = *((short int *) (data + j)) / 10.; float hum = *((short int *) (data + j + 2)) / 10.; - fprintf(outfile, "%i %g %g\n", sec, temp, hum); - sec++; + + time_t sampletime = timestamp + time_per_sample * sample; + + fprintf(outfile, "%i %llu %g %g\n", sample, + (unsigned long long) sampletime, + temp, hum); + sample++; } num -= 64; num_frames -= 1;