// // Dump Motorola Oncore @@Ba binary messages from log file. // #include #include #include unsigned char Record[1000]; long Skip = 0; long Take = 0; #define SIZE_Ba 68 #define SIZE_HEADER 4 // @@Ba void main (int argc, char *argv[]) { int c; int i; FILE *Input; long LinesIn, LinesOut; int Size; int State; if ((argc < 2) || (argc > 1 && strcmp(argv[1], "/?") == 0)) { fprintf(stderr, "%s [Filename] [Skip] [Take]\n", argv[0]); exit(0); } if (argc > 1) { Input = fopen(argv[1], "rb"); if (Input == NULL) { fprintf(stderr, "%s: open error\n", argv[1]); exit(1); } } if (argc > 2) { sscanf(argv[2], "%ld", &Skip); if (Skip < 0) { Skip = 0; } fprintf(stderr, "Skip %ld\n", Skip); } if (argc > 3) { sscanf(argv[3], "%ld", &Take); if (Take < 1) { Take = 1; } fprintf(stderr, "Take %ld\n", Take); } LinesIn = LinesOut = 0; while ((c = fgetc(Input)) != EOF) { if (State == 0 && c == '@') { State += 1; } else if (State == 1 && c == '@') { State += 1; } else if (State == 2 && c == 'B') { State += 1; } else if (State == 3 && c == 'a') { State += 1; Size = 0; } else if (State == 4) { Record[Size] = c; Size += 1; if (SIZE_HEADER + Size < SIZE_Ba) { continue; } LinesIn += 1; if (LinesIn > Skip) { int month, day, year, hour, minute, second; long fraction; printf("@@Ba "); // for (i = 0; i < Size; i += 1) { for (i = 0; i < 19; i += 1) { printf("%.2x", Record[i]); } printf("..."); // @@Ba on page 6.73 of VP manual month = Record[0]; day = Record[1]; year = 0; year = year * 256 + Record[2]; year = year * 256 + Record[3]; hour = Record[4]; minute = Record[5]; second = Record[6]; fraction = 0; fraction = fraction * 256 + Record[7]; fraction = fraction * 256 + Record[8]; fraction = fraction * 256 + Record[9]; fraction = fraction * 256 + Record[10]; printf(" %.2d/%.2d/%.4d", month, day, year); printf(" %.2d/%.2d/%.2d", hour, minute, second); printf(".%.9d", fraction); printf("\n"); LinesOut += 1; if (Take != 0 && LinesOut == Take) { break; } } State = 0; } else { State = 0; } } fprintf(stderr, "%ld lines in", LinesIn); if (Skip != 0) { fprintf(stderr, ", %ld lines skipped", Skip); } fprintf(stderr, ", %ld lines out", LinesOut); fprintf(stderr, "\n"); return; }