// hchk.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "fcntl.h" #include #include #include typedef struct { int day; /* 0 .. 999 */ unsigned char hr; /* 0 .. 23 */ unsigned char min; /* 0 .. 59 */ unsigned char sec; /* 0 .. 59 */ int msec; /* 0 .. 999 */ } cal_rec; struct block { unsigned long list[1096]; }; struct block iblk; void msec_to_cal (int seconds, int milliseconds, cal_rec &cal) { int temp; temp = (seconds / 86400) + 1; if (temp >= 1000) seconds -= (temp - 999) * 86400; cal.day = seconds / 86400; seconds -= cal.day * 86400; cal.hr = seconds / 3600; seconds -= cal.hr * 3600; cal.min = seconds / 60; cal.sec = seconds - (cal.min * 60); cal.msec = milliseconds; cal.day++; } /* msec_to_cal */ char *msec_to_str(unsigned int coarse, unsigned char fine, char *str) { cal_rec cal; int milliseconds, seconds; if ((coarse < 0) || (fine > 124)) { seconds = 0; milliseconds = 0; } else { seconds = coarse / 8; milliseconds = ((coarse % 8) * 125) + fine; } msec_to_cal (seconds, milliseconds, cal); sprintf (str, "%03d %02d:%02d:%02d.%03d",cal.day, cal.hr, cal.min, cal.sec, cal.msec); return str; } /* msec_to_str */ int main(int argc, char* argv[]) { int synced = 0; int length = 0; int ecnt,fcnt; int c; char tm[20]; __int64 rcount = 0; int fc = _open (argv[1], _O_RDONLY | O_BINARY); if (fc < 0) { printf ("Failed to open %s\n", argv[1]); exit (0); } if ((length = _read (fc, &iblk, sizeof (struct block))) < sizeof (struct block)) { printf ("Unable to read %s\n", argv[1]); exit (0); } if (iblk.list[0] != 0xc33caa55) { printf ("%s Doesn't start with a sync word\n", argv[1]); synced = 0; ecnt = 0; } else { synced = 1; ecnt = ((iblk.list[1] & 0xff) * 256) + ((iblk.list[1] >> 8) & 0xff); printf ("File ID = %d\n", ecnt); c = ((iblk.list[4] >> 16) & 0xff); c += (((iblk.list[4] >> 8) & 0xff) << 8); c += (((iblk.list[4] >> 0) & 0xff) << 16); c += (((iblk.list[3] >> 24) & 0xff) << 24); printf ("Start time = %s\n", msec_to_str (c, 0, tm)); } do { if ((iblk.list[0] != 0xc33caa55) && synced) { printf ("Sync lost at offset %I64d\n", rcount); synced = 0; } else if ((iblk.list[0] == 0xc33caa55) && !synced) { printf ("Sync found at offset %I64d\n", rcount); synced = 1; } if (iblk.list[0] == 0xc33caa55) { fcnt = ((iblk.list[1] & 0xff) * 256) + ((iblk.list[1] >> 8) & 0xff); if (fcnt != ecnt) { c = ((iblk.list[4] >> 16) & 0xff); c += (((iblk.list[4] >> 8) & 0xff) << 8); c += (((iblk.list[4] >> 0) & 0xff) << 16); c += (((iblk.list[3] >> 24) & 0xff) << 24); printf ("File ID changed to %d at %s at offset %I64d\n", fcnt, msec_to_str (c,0, tm), rcount); ecnt = fcnt; } } rcount += length; length = _read (fc, &iblk, sizeof (struct block)); } while (length == sizeof (struct block)); printf ("File Complete at offset %I64d\n", rcount + length); return 0; }