#include #include #include typedef struct { unsigned char uc[11]; unsigned long ul_ti0, ul_ti1; } Product; Product Ldat, Mdat; unsigned char uc_pnum[2]; void SetProduct(Product*, unsigned char*); // ***************** MAIN ******************* int main( int argc, char **argv ) { int i; FILE *fp_lm, *fp_mm, *fp_hm, *fp_hr; int i_lf = 0; int i_mf = 0; char out_fnmeLM[100]; char out_fnmeMM[100]; char out_fnmeHM[100]; char out_fnmeHR[100]; unsigned char uc[11]; uc_pnum[0] = 0; uc_pnum[1] = 0; sprintf(out_fnmeLM, "./dat/%s.lm", argv[1]); sprintf(out_fnmeMM, "./dat/%s.mm", argv[1]); sprintf(out_fnmeHM, "./dat/%s.hm", argv[1]); sprintf(out_fnmeHR, "./dat/%s_rslt.txt", argv[1]); if(NULL == (fp_lm=fopen(out_fnmeLM,"r"))) { printf("cannot open %s ¥n", out_fnmeLM); exit(0); } if(NULL == (fp_mm=fopen(out_fnmeMM,"r"))) { printf("cannot open %s ¥n", out_fnmeMM); exit(0); } if(NULL == (fp_hm=fopen(out_fnmeHM,"r"))) { printf("cannot open %s ¥n", out_fnmeHM); exit(0); } if(NULL == (fp_hr=fopen(out_fnmeHR,"w"))) { printf("cannot open %s ¥n", out_fnmeHR); exit(0); } fscanf(fp_lm, "%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ¥n", &uc[0], &uc[1], &uc[2], &uc[3], &uc[4], &uc[5], &uc[6], &uc[7], &uc[8], &uc[9], &uc[10]); SetProduct(&Ldat, uc); printf("%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ¥n", uc[0], uc[1], uc[2], uc[3], uc[4], uc[5], uc[6], uc[7], uc[8], uc[9], uc[10]); fscanf(fp_mm, "%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ¥n", &uc[0], &uc[1], &uc[2], &uc[3], &uc[4], &uc[5], &uc[6], &uc[7], &uc[8], &uc[9], &uc[10]); SetProduct(&Mdat, uc); printf("%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ¥n", uc[0], uc[1], uc[2], uc[3], uc[4], uc[5], uc[6], uc[7], uc[8], uc[9], uc[10]); // ***MAIN*** while (1) { if (i_lf && i_mf) break; if ( !i_lf && (( Mdat.ul_ti0 > Ldat.ul_ti0 || ( Mdat.ul_ti0 == Ldat.ul_ti0 && Mdat.ul_ti1 > Ldat.ul_ti1) || ( Mdat.ul_ti0 == Ldat.ul_ti0 && Mdat.ul_ti1 == Ldat.ul_ti1 && Mdat.uc[7] > Ldat.uc[7]) ) || i_mf)) { fprintf(fp_hr, "%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ", Ldat.uc[0], Ldat.uc[1], Ldat.uc[2], Ldat.uc[3], Ldat.uc[4], Ldat.uc[5], Ldat.uc[6], Ldat.uc[7], Ldat.uc[8], Ldat.uc[9], Ldat.uc[10]); //==== CHECK the Packet No. ==== uc_pnum[1] = uc_pnum[0]; uc_pnum[0] = Ldat.uc[7]; if (uc_pnum[0] - uc_pnum[1] == 1 || uc_pnum[1] == 0xff) fprintf(fp_hr, "¥n"); else fprintf(fp_hr, "<============== ¥n"); if (EOF != fscanf(fp_lm, "%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ¥n", &uc[0], &uc[1], &uc[2], &uc[3], &uc[4], &uc[5], &uc[6], &uc[7], &uc[8], &uc[9], &uc[10])) { SetProduct(&Ldat, uc); printf("%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ¥n", uc[0], uc[1], uc[2], uc[3], uc[4], uc[5], uc[6], uc[7], uc[8], uc[9], uc[10]); continue; } else i_lf = 1; } else if (!i_mf) { fprintf(fp_hr, "%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ", Mdat.uc[0], Mdat.uc[1], Mdat.uc[2], Mdat.uc[3], Mdat.uc[4], Mdat.uc[5], Mdat.uc[6], Mdat.uc[7], Mdat.uc[8], Mdat.uc[9], Mdat.uc[10]); //==== CHECK the Packet No. ==== uc_pnum[1] = uc_pnum[0]; uc_pnum[0] = Mdat.uc[7]; if (uc_pnum[0] - uc_pnum[1] == 1 || uc_pnum[1] == 0xff) fprintf(fp_hr, "¥n"); else fprintf(fp_hr, "<============== ¥n"); if (EOF != fscanf(fp_mm, "%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ¥n", &uc[0], &uc[1], &uc[2], &uc[3], &uc[4], &uc[5], &uc[6], &uc[7], &uc[8], &uc[9], &uc[10])) { SetProduct(&Mdat, uc); printf("%02x%02x%02x%02x%02x%02x %02x %02x %02x %02x%02x ¥n", uc[0], uc[1], uc[2], uc[3], uc[4], uc[5], uc[6], uc[7], uc[8], uc[9], uc[10]); continue; } else i_mf = 1; } } fclose(fp_lm); fclose(fp_mm); fclose(fp_hm); fclose(fp_hr); } void SetProduct(Product* pP, unsigned char uc[]) { int i; for (i = 0; i < 11; ++i) pP->uc[i] = uc[i]; pP->ul_ti0 = 0x1000000*uc[0] + 0x10000*uc[1] + 0x100*uc[2] + uc[3]; pP->ul_ti1 = 0x100*uc[4] + uc[5]; }