Fixed timestamps in SER files

test16bit
Stefan Jahn 3 years ago
parent 3b44f3ae66
commit 3182cb51e5

@ -188,7 +188,7 @@ int SER::writeHeader(void) {
/* allocate some memory for the upcoming timestamps */ /* allocate some memory for the upcoming timestamps */
if((TimeStamps = (int64_t *)malloc(sizeof(header.DateTime) * NumberOfTimeStamps)) == NULL) { if((TimeStamps = (int64_t *)malloc(sizeof(header.DateTime) * NumberOfTimeStamps)) == NULL) {
fprintf(stderr, "Error: failed to allocate %lu bytes for timestamps\n", fprintf(stderr, "Error: failed to allocate %lu bytes for timestamps\n",
sizeof(header.DateTime) * NumberOfTimeStamps); sizeof(header.DateTime) * (long)NumberOfTimeStamps);
return -1; return -1;
} }
@ -246,13 +246,13 @@ int SER::appendFrame(void *data) {
NumberOfTimeStamps *= 2; NumberOfTimeStamps *= 2;
if((TimeStamps = (int64_t *)realloc(TimeStamps, sizeof(header.DateTime) * NumberOfTimeStamps)) == NULL) { if((TimeStamps = (int64_t *)realloc(TimeStamps, sizeof(header.DateTime) * NumberOfTimeStamps)) == NULL) {
fprintf(stderr, "Error: failed to re-allocate %lu bytes for timestamps\n", fprintf(stderr, "Error: failed to re-allocate %lu bytes for timestamps\n",
sizeof(header.DateTime) * NumberOfTimeStamps); sizeof(header.DateTime) * (long)NumberOfTimeStamps);
return -1; return -1;
} }
} }
/* save timestamp for this frame */ /* save timestamp for this frame */
TimeStamps[FramePointer++] = currentDateTime(); TimeStamps[FramePointer++] = currentDateTimeUTC();
return 0; return 0;
} }
@ -344,7 +344,7 @@ void * SER::allocFrame(void) {
/* Try allocating new frame data. */ /* Try allocating new frame data. */
if((Frame = malloc(FrameSize)) == NULL) { if((Frame = malloc(FrameSize)) == NULL) {
fprintf(stderr, "Error: failed to allocate %lu bytes for frame\n", FrameSize); fprintf(stderr, "Error: failed to allocate %lu bytes for frame\n", (long)FrameSize);
return NULL; return NULL;
} }
return Frame; return Frame;
@ -430,10 +430,10 @@ int32_t SER::getNumberOfFrames(void) {
*/ */
int64_t SER::setDateTime(void) { int64_t SER::setDateTime(void) {
int64_t hundred_nano_seconds = currentDateTime(); int64_t hundred_nano_seconds = currentDateTimeUTC();
header.DateTime = hundred_nano_seconds; header.DateTimeUTC = hundred_nano_seconds;
header.DateTimeUTC = hundred_nano_seconds + differenceLocalUTC(); header.DateTime = hundred_nano_seconds + differenceLocalUTC();
return header.DateTime; return header.DateTime;
} }
@ -448,14 +448,13 @@ int64_t SER::setDateTime(void) {
maximum value represents 100 nanoseconds before the beginning of maximum value represents 100 nanoseconds before the beginning of
January 1 of the year 10000. January 1 of the year 10000.
*/ */
int64_t SER::currentDateTime(void) { int64_t SER::currentDateTimeUTC(void) {
int64_t hundred_nano_seconds; int64_t hundred_nano_seconds;
struct timeval current_time; struct timeval current_time;
struct timezone current_zone;
/* get time since 01.01.1970 00:00 */ /* get time since 01.01.1970 00:00 */
gettimeofday (&current_time, &current_zone); gettimeofday (&current_time, NULL);
hundred_nano_seconds = (62135596800L + current_time.tv_sec) * 10000000L + hundred_nano_seconds = (62135596800L + current_time.tv_sec) * 10000000L +
current_time.tv_usec * 10L; current_time.tv_usec * 10L;
return hundred_nano_seconds; return hundred_nano_seconds;
@ -486,5 +485,5 @@ int64_t SER::differenceLocalUTC(void) {
fprintf(stdout, "Debug: difference between local time and UTC is %ld hours\n", fprintf(stdout, "Debug: difference between local time and UTC is %ld hours\n",
(loc_ts - gmt_ts) / 3600); (loc_ts - gmt_ts) / 3600);
return ((int64_t)gmt_ts - (int64_t)loc_ts) * 10000000L; return ((int64_t)loc_ts - (int64_t)gmt_ts) * 10000000L;
} }

@ -105,7 +105,7 @@ class SER {
int32_t getNumberOfFrames(void); int32_t getNumberOfFrames(void);
void setNumberOfFrames(int32_t); void setNumberOfFrames(int32_t);
int64_t setDateTime(void); int64_t setDateTime(void);
int64_t currentDateTime(void); int64_t currentDateTimeUTC(void);
size_t getFrameSize(void); size_t getFrameSize(void);
int setFile(char *); int setFile(char *);

Loading…
Cancel
Save