/* uartDebugParser.c * * This program parses an log file generated by uartDebugServer.c * The same table of states and events that used by uartDebugServer should be * used here too. If no state-event table is included, will simply display * the raw bytes provided by each node. * * Author: Wei Ye (USC/ISI) * Date: 03/10/2003 * */ #include #include #include #include #include #include // if debug another component, comment out following line // or include a corresponding debug table, which should be the same // as in uartDebugServer.c #include "smacDebugTab.h" #define MAXBUFLEN 80 int main(int argc, char ** argv) { unsigned int numbytes, i, msgNo; char buf[MAXBUFLEN]; unsigned int nodeId, days, hours, minutes, seconds, milisec; FILE *logFile; if (argc != 2) { printf("Usage: uartDebugParser logFile\n"); exit(1); } if ((logFile = fopen(argv[1], "r")) == NULL) { printf("Error: can't open log file.\n"); exit(1); } fgets(buf, MAXBUFLEN, logFile); printf("\n%s\n", buf); /* while ( EOF != fscanf(logFile, "%d %d %d %d %d", &nodeId, &hours, &minutes, &seconds, &milisec)) { printf("Node %d at %02d:%02d:%02d.%02d\n", nodeId, hours, minutes, seconds, milisec); */ while (EOF != fscanf(logFile, "%d", &nodeId)) { printf("Node %d:\n", nodeId); fscanf(logFile, "%d", &numbytes); // print out debugging info for(i = 0; i < numbytes; i++){ fscanf(logFile, "%d", &msgNo); #ifdef STATE_EVENT if (msgNo >= sizeof(stateEvent)) exit(1); printf(" %s\n", stateEvent[msgNo]); #else printf(" %d\n", msgNo); #endif } printf("\n"); } fclose(logFile); return 0; }