//2018 MEA2試験データ確認 // //2012 10 //現場でチェック用にヘッダ等のみを表示 #define TRUE 1 #define FALSE 0 // ソフト内での LinLog 圧縮時のカウントデータのビット幅 #define d_Lcl_ENA_CntDepth32 0x0 #define d_Lcl_ENA_CntDepth16 0x1 #define d_Lcl_ENA_CntDepth12 0x2 #include #include #include //#define MIA_PROC #define MEA2_PROC //#define MEA1_PROC #define MEA_PROC //#define MSA_PROC #ifdef MIA_PROC #define SNSR_ID 0x38 #endif #ifdef MEA2_PROC #define SNSR_ID 0x30 #endif #ifdef MEA1_PROC #define SNSR_ID 0x28 #endif #ifdef MSA_PROC #define SNSR_ID 0x40 #endif char USHORTtoDBL(double*, unsigned short*, unsigned int); char Log2Lin(unsigned int*, unsigned char*, unsigned int, unsigned char, unsigned int); int msa_len(unsigned char*); main(int argc, char *argv[]) { FILE *fp_inf, *fp_hk1, *fp_hk2, *fp_lm, *fp_mm, *fp_hm, *fp; int i,j, i_s, i_e, len, pckt_n, addr; char inf_fnme[100]; char out_fnmeHK1[100]; char out_fnmeHK2[100]; char out_fnmeLM[100]; char out_fnmeMM[100]; char out_fnmeHM[100]; char tmp_read_line[500]; int bdy_flg = 0; int hk_flg = 0; int ms_flg = 0; int line_n = 0; int hk_n = 0; int ms_n = 0; int mode = 0; int id = 0; int i_n = 0; int ii; unsigned int ui_TI; FILE *fp_msa_pn, *fp_proL, *fp_proM; int msa_rest = 0; int msa_l; unsigned char msa_pn_i[0x100]; unsigned char msa_pn[0x100][0x100]; unsigned char msa_dat[16]; int n, k, i0; int hcnt = 0; unsigned char dat[16], snsrhk[128], swhk[100], hdr[1100]; unsigned char Ldat[2000]; double vm[6*13*2]; unsigned short us_vm[6*13*2]; unsigned int ui_et[32*16]; unsigned char uc_hdr0[10]; if (argc <= 2) { fprintf(stderr, "[inputfile] [outputfile]\n"); exit(1); } for (i = 0; i <= 0x1c; ++i) msa_pn_i[i] = 1; for (i = 0x1d; i <= 0xff; ++i) msa_pn_i[i] = 0; for (j = 0; j <= 0xff; ++j) for (i = 0; i <= 0xff; ++i) msa_pn[j][i] = 0; sprintf(inf_fnme, "%s", argv[1]); sprintf(out_fnmeHK1,"./dat/%s.hk1",argv[2]); sprintf(out_fnmeHK2,"./dat/%s.hk2",argv[2]); sprintf(out_fnmeLM,"./dat/%s.lm",argv[2]); sprintf(out_fnmeMM,"./dat/%s.mm",argv[2]); sprintf(out_fnmeHM,"./dat/%s.hm",argv[2]); if(NULL == (fp_inf=fopen(inf_fnme,"r"))) { printf("cannot open %s \n",inf_fnme); exit(0); } if(NULL == (fp_hk1=fopen(out_fnmeHK1,"w"))) { printf("cannot open %s \n", out_fnmeHK1); exit(0); } // if(NULL == (fp_hk2=fopen(out_fnmeHK2,"w"))) { // printf("cannot open %s \n", out_fnmeHK2); // exit(0); // } if(NULL == (fp_lm=fopen(out_fnmeLM,"w"))) { printf("cannot open %s \n", out_fnmeLM); exit(0); } if(NULL == (fp_mm=fopen(out_fnmeMM,"w"))) { printf("cannot open %s \n", out_fnmeMM); exit(0); } if(NULL == (fp_hm=fopen(out_fnmeHM,"w"))) { printf("cannot open %s \n", out_fnmeHM); exit(0); } if(NULL == (fp_proL=fopen("./dat/productL.txt","w"))) { printf("cannot open ./dat/product.txt \n"); exit(0); } if(NULL == (fp_proM=fopen("./dat/productM.txt","w"))) { printf("cannot open ./dat/product.txt \n"); exit(0); } // if(NULL == (fp_msa_pn=fopen("./dat/msa_pn.txt","w"))) { // printf("cannot open %s \n", out_fnmeHM); // exit(0); // } while(1) { /* READ ONE LINE ON THE INFORMATION FILE */ if (NULL == fgets(tmp_read_line, 500, fp_inf)) break; //printf("%s", tmp_read_line); line_n++; //Get HK if (hk_flg >= 1) { //printf(">"); hk_flg++; sscanf(tmp_read_line, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n", &dat[0], &dat[1], &dat[2], &dat[3], &dat[4], &dat[5], &dat[6], &dat[7], &dat[8], &dat[9], &dat[10], &dat[11], &dat[12], &dat[13], &dat[14], &dat[15]); //for (i = 0; i < 16; ++i) printf("%02x ", dat[i]); //printf("\n"); // if (hk_flg == 2) for (i = 0; i < 10; ++i) uc_hdr0[i] = dat[i]; #ifdef MIA_PROC if (hk_flg == 2) for (i = 0; i < 6; ++i) snsrhk[i] = dat[i+10]; else if (hk_flg <= 9) for (i = 0; i < 16; ++i) snsrhk[i + 6 + 16*(hk_flg-3)] = dat[i]; else if (hk_flg == 10) { for (i = 0; i < 10; ++i) snsrhk[i + 6 + 16*(hk_flg-3)] = dat[i]; for (i = 10; i < 16; ++i) swhk[i - 10] = dat[i]; } else if (hk_flg == 11) for (i = 0; i < 16; ++i) swhk[i + 6] = dat[i]; else if (hk_flg == 12) { for (i = 0; i < 6; ++i) swhk[i + 22] = dat[i]; hk_flg = 0; //for (i = 0; i < 128; ++i) fprintf(fp_hk1, "%02x ", snsrhk[i]); //fprintf(fp_hk1, "\n"); //for (i = 0; i < 28; ++i) fprintf(fp_hk2, "%02x ", swhk[i]); //fprintf(fp_hk2, "\n"); //printf("\n"); printf("HK "); printf("%02x%02x %02x%02x%02x%02x ", uc_hdr0[0], uc_hdr0[1], uc_hdr0[2], uc_hdr0[3], uc_hdr0[4], uc_hdr0[5]); printf("%02x %02x %02x%02x%02x%02x\n", swhk[0], swhk[1], swhk[2], swhk[3], swhk[4], swhk[5]); } #endif #ifdef MSA_PROC if (hk_flg == 2) for (i = 0; i < 6; ++i) snsrhk[i] = dat[i+10]; else if (hk_flg <= 9) for (i = 0; i < 16; ++i) snsrhk[i + 6 + 16*(hk_flg-3)] = dat[i]; else if (hk_flg == 10) { for (i = 0; i < 10; ++i) snsrhk[i + 6 + 16*(hk_flg-3)] = dat[i]; for (i = 10; i < 16; ++i) swhk[i - 10] = dat[i]; } else if (hk_flg == 11) { for (i = 0; i < 6; ++i) swhk[i + 6] = dat[i]; hk_flg = 0; //for (i = 0; i < 128; ++i) fprintf(fp_hk1, "%02x ", snsrhk[i]); //fprintf(fp_hk1, "\n"); //for (i = 0; i < 12; ++i) fprintf(fp_hk2, "%02x ", swhk[i]); //fprintf(fp_hk2, "\n"); //printf("\n"); printf("HK "); printf("%02x%02x %02x%02x%02x%02x ", uc_hdr0[0], uc_hdr0[1], uc_hdr0[2], uc_hdr0[3], uc_hdr0[4], uc_hdr0[5]); printf("%02x %02x %02x%02x%02x%02x\n", swhk[0], swhk[1], swhk[2], swhk[3], swhk[4], swhk[5]); } #endif #ifdef MEA_PROC if (hk_flg == 2) for (i = 0; i < 6; ++i) snsrhk[i] = dat[i+10]; else if (hk_flg <= 9) for (i = 0; i < 16; ++i) snsrhk[i + 6 + 16*(hk_flg-3)] = dat[i]; else if (hk_flg == 10) { for (i = 0; i < 10; ++i) snsrhk[i + 6 + 16*(hk_flg-3)] = dat[i]; for (i = 10; i < 16; ++i) swhk[i - 10] = dat[i]; } else if (hk_flg <= 12) for (i = 0; i < 16; ++i) swhk[i + 6 + 16*(hk_flg-11)] = dat[i]; else if (hk_flg == 13) { for (i = 0; i < 8; ++i) swhk[i + 38] = dat[i]; hk_flg = 0; for (i = 0; i < 32; ++i) fprintf(fp_hk1, "%02x", snsrhk[i]); fprintf(fp_hk1, " "); fprintf(fp_hk1, "%02x%02x%02x%02x ", uc_hdr0[2], uc_hdr0[3], uc_hdr0[4], uc_hdr0[5]); for (i = 0; i < 46; ++i) fprintf(fp_hk1, "%02x ", swhk[i]); fprintf(fp_hk1, "\n"); printf("\n"); printf("HK "); printf("%02x%02x %02x%02x%02x%02x ", uc_hdr0[0], uc_hdr0[1], uc_hdr0[2], uc_hdr0[3], uc_hdr0[4], uc_hdr0[5]); printf("%02x %02x %02x%02x%02x%02x\n", swhk[0], swhk[1], swhk[2], swhk[3], swhk[4], swhk[5]); } #endif continue; } //Get MISSION PRODUCT if (ms_flg >= 1) { //BODYの終了処理 if (tmp_read_line[0] == '/') { if (mode) { //for (i = 0; i < len + 3; ++i) fprintf(fp, "%02x ", hdr[i]); //fprintf(fp, "\nLength:%02x%02x\n", hdr[0],hdr[1]); // 単体Packet? 複数? if (hdr[10] == SNSR_ID) { pckt_n = 1; addr = 12; }//1/1 単体Packet else if (hdr[14] == SNSR_ID) { pckt_n = 2; addr = 16; }//1/n else pckt_n = 0; //2-n/n if (pckt_n) { printf("MS1 "); printf("%02x%02x %02x%02x%02x%02x ", hdr[0], hdr[1], hdr[2], hdr[3], hdr[4], hdr[5]); //Size TI // modeでファイルを分ける if (mode == 1) { printf("L "); fp = fp_lm; } if (mode == 2) { printf("M "); fp = fp_mm; } if (mode == 3) { printf("H "); fp = fp_hm; } printf("%02x%02x%02x%02x ", hdr[addr],hdr[addr+1],hdr[addr+2],hdr[addr+3]); //TI printf("%02x%02x ", hdr[addr+6],hdr[addr+7]); //Size printf("%02x%02x %02x%02x %02x%02x %02x%02x ", hdr[addr+8], hdr[addr+9], hdr[addr+10], hdr[addr+11], hdr[addr+12], hdr[addr+13], hdr[addr+14], hdr[addr+15]); printf("%02x%02x%02x%02x\n", hdr[addr+16], hdr[addr+17], hdr[addr+18], hdr[addr+19]); // // FILEに記入 // /* Mission Packets */ fprintf(fp, "\n#################################################"); fprintf(fp, "TI: %02x%02x%02x%02x ", hdr[addr],hdr[addr+1],hdr[addr+2],hdr[addr+3]); fprintf(fp, "Size: %02x%02x\n", hdr[addr+6],hdr[addr+7]); //COMMENT fprintf(fp, "COMMENT: "); for (i = addr+8; i < addr+8 +8; ++i) fprintf(fp, "%02x", hdr[i]); fprintf(fp, "\n"); //decribing CMMNT if ( hdr[addr+10] & 0x01 ) fprintf(fp, " SNAP "); else fprintf(fp, "AVE "); if ( hdr[addr+10] >> 1 & 0x01 ) fprintf(fp, "ENG#"); else fprintf(fp, "SCI#"); fprintf(fp, "%d ", (hdr[addr+10] >> 2 & 0xf)); #ifdef MEA_PROC //decribing MDP_INFO fprintf(fp, "\n DataID=%d ", (hdr[addr+11] & 0xf)); id = hdr[addr+11] & 0xf; fprintf(fp, "Pot:%d (16s):", (hdr[addr+11] >> 4 & 1)); for (i = 5; i < 8; ++i) if ((hdr[addr+11] >> i & 1)) fprintf(fp, "*"); else fprintf(fp, "-"); fprintf(fp, "\n"); fprintf(fp, " SIZE: %02x%02x(%d) %02x%02x\n", hdr[addr+12], hdr[addr+13], 256*hdr[addr+12]+hdr[addr+13], hdr[addr+14], hdr[addr+15]); // //Product // L/M/H ? //HDR //fprintf(fp, "HK %02x%02x%02x%02x ", hdr[addr+16], hdr[addr+17], hdr[addr+18], hdr[addr+19]); //fprintf(fp, "%02x %02x %02x %02x\n", hdr[addr+20], hdr[addr+21], hdr[addr+22], hdr[addr+23]); //DATA //************************* // M mode //************************* if(mode == 2) { fprintf(fp, "[MISSION] len = %d\n", len); //HDR fprintf(fp, "HK %02x%02x%02x%02x ", hdr[addr+16], hdr[addr+17], hdr[addr+18], hdr[addr+19]); fprintf(fp, "%02x %02x %02x %02x\n", hdr[addr+20], hdr[addr+21], hdr[addr+22], hdr[addr+23]); if (id == 7) {// NOT mode 2 i_s = addr + 16 +8; for (i = 0; i < 32*16; ++i) { if (i%32 == 0) fprintf(fp, "\n"); fprintf(fp, "%02x%02x ", hdr[2*i +i_s],hdr[2*i +1 +i_s]); } fprintf(fp, "\n"); } else if (id <= 1) { i_s = addr + 16 +8; fprintf(fp, "INF(4s) 8B :%02x%02x%02x%02x%02x%02x%02x%02x\n", hdr[i_s],hdr[i_s +1],hdr[i_s +2],hdr[i_s +3], hdr[i_s +4],hdr[i_s +5],hdr[i_s +6],hdr[i_s +7]); fprintf(fp, " INF: 6b x5("); fprintf(fp, "%d ", hdr[i_s ] >> 2 & 0x3f); //6 fprintf(fp, "%d ", hdr[i_s ] << 4 & 0x30 | hdr[i_s + 1] >> 4 & 0x0f); //2 4 fprintf(fp, "%d ", hdr[i_s + 1] << 2 & 0x3c | hdr[i_s + 2] >> 6 & 0x03); // 4 2 fprintf(fp, "%d ", hdr[i_s + 2] & 0x3f); // 6 fprintf(fp, "%d)\n", hdr[i_s + 3] >> 2 & 0x3f); // 6 fprintf(fp, " Sc#-MGF:%d\n", hdr[i_s + 4]); fprintf(fp, " En#-VM:%d\n", hdr[i_s + 5]); fprintf(fp, " En#-Swp:%d\n", hdr[i_s + 6]); fprintf(fp, " Etbl:%d\n", hdr[i_s + 7]); i_s += 8; fprintf(fp, "Et-OMNm[32en](2s)x2 4B->1B:"); if (id == 0) i_n = 1; else if (id == 1) i_n = 2; for (i = 0; i < i_n*32; ++i) { if (i%32 == 0) fprintf(fp, "\n"); fprintf(fp, "%02x ", hdr[i +i_s]); } fprintf(fp, "\n"); fprintf(fp, ">>>>>>>>CONVERSION 8bit UCHAR ->32bit UINT"); Log2Lin(ui_et, &hdr[i_s], i_n*32, d_Lcl_ENA_CntDepth32, 0); for (i = 0; i < i_n*32; ++i) { if (i%16 == 0) fprintf(fp, "\n"); fprintf(fp, "%08x ", ui_et[i]); } fprintf(fp, "\n"); i_s += i_n*32; fprintf(fp, "Et-PAP[4en][16ch](2s) 4B->1B:"); for (i = 0; i < i_n*64; ++i) { if (i%16 == 0) fprintf(fp, "\n"); fprintf(fp, "%02x ", hdr[i +i_s]); } fprintf(fp, "\n"); fprintf(fp, ">>>>>>>>CONVERSION 8bit UCHAR ->32bit UINT"); Log2Lin(ui_et, &hdr[i_s], i_n*64, d_Lcl_ENA_CntDepth32, 0); for (i = 0; i < i_n*64; ++i) { if (i%16 == 0) fprintf(fp, "\n"); fprintf(fp, "%08x ", ui_et[i]); } fprintf(fp, "\n"); i_s += i_n*64; fprintf(fp, "VM(2,4s) [6en][13vm]:" ); for (i = 0; i < i_n*13*6; ++i) { if (i%13 == 0) fprintf(fp, "\n"); fprintf(fp, "%02x%02x ", hdr[2*i +i_s], hdr[2*i +1 +i_s]); } fprintf(fp, "\n"); fprintf(fp, ">>>>>>>>CONVERSION 16bit USHORT -> DOUBLE"); for (k = 0; k < i_n*13*6; ++k) us_vm[k] = hdr[2*k +i_s]*256 + hdr[2*k +1 +i_s]; USHORTtoDBL(vm, us_vm, i_n*13*6); for (k = 0; k < i_n*13*6; ++k) { if (k%13 == 0) fprintf(fp, "\n"); fprintf(fp, "%.3e ", vm[k]); } ui_TI = hdr[addr+16]*0x1000000 + hdr[addr+17]*0x10000 + hdr[addr+18]*0x100 + hdr[addr+19]; fprintf(fp_proM, "%ld %.2e\n", ui_TI, vm[0]); fprintf(fp_proM, "%ld %.2e\n", ui_TI+0x400, vm[13*6]); i_s += i_n*13*6*2; i = 0; //while (1) { // if (2*i + i_s >= len + 2) break; // fprintf(fp, "%02x%02x ", hdr[2*i +i_s], hdr[2*i +1 +i_s]); // ++i; //} fprintf(fp, "\n"); } } //************************* // H mode //************************* else if (mode == 3) { //if (id == 0) i_n = 1; //else if (id == 1) i_n = 2; fprintf(fp, "[MISSION] len = %d\n", len); hcnt = 0; i = 0; //HDR fprintf(fp, "HK %02x%02x%02x%02x ", hdr[addr+16], hdr[addr+17], hdr[addr+18], hdr[addr+19]); fprintf(fp, "%02x %02x %02x %02x\n", hdr[addr+20], hdr[addr+21], hdr[addr+22], hdr[addr+23]); fprintf(fp, "3D-H(2s or 4s) [32en][88dir]:\n"); i_s = addr + 16 +8; while (1) { if (hcnt%32 == 0) fprintf(fp, "\n %02d: ", hcnt/32); if (2*i + i_s >= len + 2) break; fprintf(fp, "%02x%02x ", hdr[2*i +i_s], hdr[2*i +1 +i_s]); ++i; hcnt++; } //fprintf(fp, "\n"); } //************************* // L mode //************************* else if (mode == 1) { fprintf(fp, "[MISSION] len = %d\n", len); memcpy(Ldat, hdr, len+2); } #endif } else { //複数パケット継続 printf("MSn "); printf("%02x%02x %02x%02x%02x%02x ", hdr[0], hdr[1], hdr[2], hdr[3], hdr[4], hdr[5]); //Size TI // modeでファイルを分ける if (mode == 1) { printf("L "); fp = fp_lm; } if (mode == 2) { printf("M "); fp = fp_mm; } if (mode == 3) { printf("H "); fp = fp_hm; } printf("\n"); #ifdef MEA_PROC //fprintf(fp, "\n[MISSION] len = %d\n", len); if (mode == 1) { //L mode memcpy(Ldat+1030, hdr+14, 512); //Ldatに複数パケットをまとめる i_s = addr + 16; for (ii = 0; ii < 16; ++ii) { //Break 16-spin products printf(" "); printf("%02x %02x %02x%02x ", Ldat[i_s], Ldat[i_s +1], Ldat[i_s +2], Ldat[i_s +3]); printf("%02x%02x%02x%02x ", Ldat[i_s +4], Ldat[i_s +5], Ldat[i_s +6], Ldat[i_s +7]); printf("%02x%02x%02x%02x\n", Ldat[i_s +8], Ldat[i_s +9], Ldat[i_s +10], Ldat[i_s +11]); //COMMENT fprintf(fp, "INF/MOD/LEN: %02x %02x %02x%02x ", Ldat[i_s], Ldat[i_s +1], Ldat[i_s +2], Ldat[i_s +3]); if ( Ldat[i_s] & 0x01 ) fprintf(fp, " SNAP "); else fprintf(fp, " AVE "); if ( Ldat[i_s] >> 1 & 0x01 ) fprintf(fp, "ENG#"); else fprintf(fp, "SCI#"); fprintf(fp, "%d ", (Ldat[i_s] >> 2 & 0xf)); //decribing MDP_INFO fprintf(fp, "\n DataID=%d ", (Ldat[i_s +1] & 0xf)); id = Ldat[i_s +1] & 0x3; fprintf(fp, "Pot:%d (16s):", (Ldat[i_s +1] >> 4 & 1)); //for (i = 5; i < 8; ++i) if ((Ldat[i_s +1] >> 5 & 1)) fprintf(fp, "INF/EtPAP/VM[16s]"); else fprintf(fp, "---------"); fprintf(fp, "\n"); fprintf(fp, " SIZE: %02x%02x(%d)\n", Ldat[i_s +2], Ldat[i_s +3], 256*Ldat[i_s +2]+Ldat[i_s +3]); //HDR fprintf(fp, "HK %02x%02x%02x%02x ", Ldat[i_s +4], Ldat[i_s +5], Ldat[i_s +6], Ldat[i_s +7]); fprintf(fp, "%02x %02x %02x %02x\n", Ldat[i_s +8], Ldat[i_s +9], Ldat[i_s +10], Ldat[i_s +11]); if (id == 7) {// NOT mode 2 for (i = 12; i < 12+32; ++i) fprintf(fp, "%02x ", Ldat[i +i_s]); fprintf(fp, "\n"); i_s += 256*Ldat[i_s +2]+Ldat[i_s +3]; continue; } fprintf(fp, "Et-OMN(4s): "); for (i = 12; i < 12+16; ++i) fprintf(fp, "%02x ", Ldat[i +i_s]); fprintf(fp, "\n"); fprintf(fp, ">>>>>>>>CONVERSION 8bit UCHAR ->32bit UINT\n"); Log2Lin(ui_et, &Ldat[12 +i_s], 16, d_Lcl_ENA_CntDepth32, 0); for (i = 0; i < 16; ++i) fprintf(fp, "%08x ", ui_et[i]); fprintf(fp, "\n"); if ((Ldat[i_s +1] >> 5 & 1)) { fprintf(fp, "INF2: 6b x5("); fprintf(fp, "%d ", Ldat[i_s +28] >> 2 & 0x3f); //6 fprintf(fp, "%d ", Ldat[i_s +28] << 4 & 0x30 | Ldat[i_s +29] >> 4 & 0x0f); //2 4 fprintf(fp, "%d ", Ldat[i_s +29] << 2 & 0x3c | Ldat[i_s +30] >> 6 & 0x03); // 4 2 fprintf(fp, "%d ", Ldat[i_s +30] & 0x3f); // 6 fprintf(fp, "%d)\n", Ldat[i_s +31] >> 2 & 0x3f); // 6 fprintf(fp, "Sc#-MGF:%d\n", Ldat[i_s +32]); fprintf(fp, "En#-VM:%d\n", Ldat[i_s +33]); fprintf(fp, "En#-Swp:%d\n", Ldat[i_s +34]); fprintf(fp, "Etbl:%d\n", Ldat[i_s +35]); fprintf(fp, "Et-PAP[4en][16ch](2s) x2 4B->1B:"); for (k = 0; k < 64; ++k) { if (k%16 == 0) fprintf(fp, "\n"); fprintf(fp, "%02x ", Ldat[k +i_s +36]); } fprintf(fp, "\n"); fprintf(fp, ">>>>>>>>CONVERSION 8bit UCHAR ->32bit UINT\n"); Log2Lin(ui_et, &Ldat[i_s +36], 64, d_Lcl_ENA_CntDepth32, 0); for (k = 0; k < 64; ++k) { if (k%16 == 0) fprintf(fp, "\n"); fprintf(fp, "%08x ", ui_et[k]); } fprintf(fp, "\n"); fprintf(fp, "VM(2,4s) [6en][13vm]:" ); for (k = 0; k < 13*6; ++k) { if (k%13 == 0) fprintf(fp, "\n"); fprintf(fp, "%02x%02x ", Ldat[2*k +i_s +36+64], Ldat[2*k +1 +i_s +36+64]); } fprintf(fp, "\n"); fprintf(fp, ">>>>>>>>CONVERSION 16bit USHORT -> DOUBLE"); for (k = 0; k < 13*6; ++k) us_vm[k] = Ldat[2*k +i_s +36+64]*256 + Ldat[2*k +1 +i_s +36+64]; USHORTtoDBL(vm, us_vm, 13*6); for (k = 0; k < 13*6; ++k) { if (k%13 == 0) fprintf(fp, "\n"); fprintf(fp, "%.3e ", vm[k]); } ui_TI = Ldat[i_s +4]*0x1000000 + Ldat[i_s +5]*0x10000 + Ldat[i_s +6]*0x100 + Ldat[i_s +7]; fprintf(fp_proL, "%ld %.2e\n", ui_TI, vm[0]); } i_s += 256*Ldat[i_s +2]+Ldat[i_s +3]; //fprintf(fp, "i_s = %d\n", i_s); } } else if (mode == 3) { //H mode i_s = 14; i = 0; while (1) { if (hcnt%32 == 0) fprintf(fp, "\n %02d: ", hcnt/32); if (2*i + i_s >= len + 2) break; fprintf(fp, "%02x%02x ", hdr[2*i +i_s], hdr[2*i +1 +i_s]); ++i; hcnt++; } } #endif } } ms_flg = 0; len = 0; mode = 0; continue; } //printf(">"); ms_flg++; sscanf(tmp_read_line, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n", &dat[0], &dat[1], &dat[2], &dat[3], &dat[4], &dat[5], &dat[6], &dat[7], &dat[8], &dat[9], &dat[10], &dat[11], &dat[12], &dat[13], &dat[14], &dat[15]); //for (i = 0; i < 16; ++i) printf("%02x ", dat[i]); //printf("\n"); for (i = 0; i < 16; ++i) hdr[i + 16*(ms_flg-2)] = dat[i]; if (ms_flg == 2) { len = dat[0]*0x100 + dat[1];//データ長 if (dat[6] == 0x33 && (dat[7] & 7) == 2) { mode = 1; }//fp = fp_lm; }//L-mode else if (dat[6] == 0x3d && (dat[7] & 7) == 3) { mode = 2; }//fp = fp_mm; }//M-mode else if (dat[6] == 0x5b && (dat[7] & 7) == 6) { mode = 3; }//fp = fp_hm; }//H-mode //fprintf(fp, "%02x%02x\n", dat[0],dat[1]); } /* if (ms_flg <= 4) for (i = 0; i < 16; ++i) hdr[i + 16*(ms_flg-2)] = dat[i]; else if (ms_flg == 5) { for (i = 0; i < 12; ++i) hdr[i + 48] = dat[i]; ms_flg = 0; i_s = 0; i_e = 0; if (hdr[6] == 0x33 && (hdr[7] & 7) == 2) { //L-mode if (hdr[10] == 0x38) { i_s = 10; i_e = 60; }// 1/1 else if (hdr[14] == 0x38) { i_s = 14; i_e = 60; }// 1/2 else { i_s = 13; i_e = 15; }// 2/2 for (i = i_s; i < i_e; ++i) fprintf(fp_lm, "%02x ", hdr[i]); fprintf(fp_lm, "%d\n", line_n); } if (hdr[6] == 0x3d && (hdr[7] & 7) == 3) { //M-mode i_s = 16; if (hdr[10] == 0x38) { i_s = 10; i_e = 60; }// 1/1 else if (hdr[14] == 0x38) { i_s = 14; i_e = 60; }// 1/2 else { i_s = 13; i_e = 15; }// 2/2 for (i = i_s; i < i_e; ++i) fprintf(fp_mm, "%02x ", hdr[i]); fprintf(fp_mm, "%d\n", line_n); } } */ continue; } //Find HK or MIS header if (bdy_flg == 1) { bdy_flg = 0; sscanf(tmp_read_line, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n", &dat[0], &dat[1], &dat[2], &dat[3], &dat[4], &dat[5], &dat[6], &dat[7], &dat[8], &dat[9], &dat[10], &dat[11], &dat[12], &dat[13], &dat[14], &dat[15]); //for (i = 0; i < 16; ++i) printf("%02x ", dat[i]); //printf("\n"); if (dat[12] == 0x0e && dat[13] == SNSR_ID) {//HK hk_flg = 1; ++hk_n; //printf("Find HK of %dth at Line%d\n", ++hk_n, line_n); } if (dat[12] == 0x0d && dat[13] == SNSR_ID) {//MISSION ms_flg = 1; ++ms_n; //printf("Find MIS of %dth at Line%d\n", ++ms_n, line_n); } continue; } /* FIND BODY */ if (tmp_read_line[0] == 'B' && tmp_read_line[1] == 'O' && tmp_read_line[2] == 'D' && tmp_read_line[3] == 'Y') { ++hk_n; //printf("Find BODY of %dth at Line%d\n", ++hk_n, line_n); bdy_flg = 1; continue; } } /* 1st while(1) loop */ fclose(fp_inf); fclose(fp_hk1); //fclose(fp_hk2); fclose(fp_lm); fclose(fp_mm); fclose(fp_hm); fclose(fp_proL); fclose(fp_proM); //for (j = 0; j <= 0xff; ++j) { // for (i = 0; i <= 0xff; ++i) fprintf(fp_msa_pn, "%d", msa_pn[j][i]); // fprintf(fp_msa_pn, "\n"); // } // fclose(fp_msa_pn); } int msa_len(unsigned char hdr[]) { int ans; if (hdr[0] == 0xf0) ans = 14; //MISHK else if (hdr[0] == 0xf1) ans = 128; //COMHK+FULLHK else if (hdr[0] == 0xfa || //SCI 1st hdr[0] == 0xfb) ans = 256*hdr[1] + hdr[2]; //SCI cont. else if (hdr[0] == 1 || //EVT post report 16 hdr[0] == 3 || //EVT progtrss report 16 hdr[0] == 12 || //EVT Memory error 22 hdr[0] == 13 || //EVT General errpr 22 hdr[0] == 14 ) ans = hdr[1]; //EVT CMD error 14 else if (hdr[0] >= 20 && hdr[0] <= 199) ans = hdr[1]; //EVT UDP, .. OCL program else if (hdr[0] == 254 ) ans = 12; //EVT Memory check report else ans = -1; return (ans); } char USHORTtoDBL(double *pf_outbuf, unsigned short *pus_inbuf, unsigned int len) { int i; //共用体 union { double d;//1(sign) + 11(exponent) + 52(fraction) unsigned char uc[8]; } un_dat; for(i = 0; i < len; i++){ //1(sign) + 5(exponent) + 10(fraction) --> // 1(sign) + 11(exponent) + 52(fraction) //1 + 11 + 52 if (*pus_inbuf == 0x7c00) { //+無限大 un_dat.uc[7] = 0x7f; un_dat.uc[6] = 0xf0; un_dat.uc[5] = 0; un_dat.uc[4] = 0; un_dat.uc[3] = 0; un_dat.uc[2] = 0; un_dat.uc[1] = 0; un_dat.uc[0] = 0; } else if (*pus_inbuf == 0xfc00) { //-無限大 un_dat.uc[7] = 0xff; un_dat.uc[6] = 0xf0; un_dat.uc[5] = 0; un_dat.uc[4] = 0; un_dat.uc[3] = 0; un_dat.uc[2] = 0; un_dat.uc[1] = 0; un_dat.uc[0] = 0; } else if (*pus_inbuf == 0) { //0 un_dat.d = 0; } else { //exp != 0 正規化 if ((*pus_inbuf >> 14) & 0x01) un_dat.uc[7] = (*pus_inbuf >> 8 & 0xc0); //exp > 0x0f else un_dat.uc[7] = (*pus_inbuf >> 8 & 0xc0) | 0x3f;//exp <= 0x0f un_dat.uc[6] = (((*pus_inbuf >> 8 & 0x3f) << 2) | (((*pus_inbuf & 0xff) >> 6) & 0x03) ); un_dat.uc[5] = (((*pus_inbuf & 0xff) & 0x3f) << 2); un_dat.uc[4] = 0; un_dat.uc[3] = 0; un_dat.uc[2] = 0; un_dat.uc[1] = 0; un_dat.uc[0] = 0; } *pf_outbuf++ = un_dat.d; pus_inbuf++; } return TRUE; } char Log2Lin(unsigned int *poutbuf, unsigned char *pinbuf, unsigned int len, unsigned char depth, unsigned int offset) { unsigned char uc; int i; unsigned int ui, ui0; /* if(depth == d_Lcl_ENA_CntDepth12){ for(i = 0; i < len/4; i++){ ui = *pinbuf++; if(ui < offset){ uc = 0; } else { ui -= offset; if ( !(ui & 0xffffffc0) ) { uc = (ui & 0x3f); } else if( !(ui & 0xffffff80) ) { uc = ( 0x40 + ((ui >> 1) & 0x1f) ); } else if( !(ui & 0xffffff00) ) { uc = ( 0x60 + ((ui >> 2) & 0x1f) ); } else if( !(ui & 0xfffffe00) ) { uc = ( 0x80 + ((ui >> 3) & 0x1f) ); } else if( !(ui & 0xfffffc00) ) { uc = ( 0xa0 + ((ui >> 4) & 0x1f) ); } else if( !(ui & 0xfffff800) ) { uc = ( 0xc0 + ((ui >> 5) & 0x1f) ); } else if( !(ui & 0xfffff000) ) { uc = ( 0xe0 + ((ui >> 6) & 0x1f) ); } else { uc = 0xff; } } *poutbuf++ = uc; } } else if(depth == d_Lcl_ENA_CntDepth16){ for(i = 0; i < len/4; i++){ ui = *pinbuf++; if(ui < offset){ uc = 0; } else { ui -= offset; if ( !(ui & 0xffffffc0) ) { uc = (ui & 0x3f); } else if( !(ui & 0xffffff80) ) { uc = ( 0x40 + ((ui >> 1) & 0x1f) ); } else if( !(ui & 0xffffff00) ) { uc = ( 0x60 + ((ui >> 2) & 0x1f) ); } else if( !(ui & 0xfffffe00) ) { uc = ( 0x80 + ((ui >> 4) & 0x0f) ); } else if( !(ui & 0xfffffc00) ) { uc = ( 0x90 + ((ui >> 5) & 0x0f) ); } else if( !(ui & 0xfffff800) ) { uc = ( 0xa0 + ((ui >> 6) & 0x0f) ); } else if( !(ui & 0xfffff000) ) { uc = ( 0xb0 + ((ui >> 7) & 0x0f) ); } else if( !(ui & 0xffffe000) ) { uc = ( 0xc0 + ((ui >> 8) & 0x0f) ); } else if( !(ui & 0xffffc000) ) { uc = ( 0xd0 + ((ui >> 9) & 0x0f) ); } else if( !(ui & 0xffff8000) ) { uc = ( 0xe0 + ((ui >> 10) & 0x0f) ); } else if( !(ui & 0xffff0000) ) { uc = ( 0xf0 + ((ui >> 11) & 0x0f) ); } else { uc = 0xff; } } *poutbuf++ = uc; } } */ if (depth == d_Lcl_ENA_CntDepth32) { for(i = 0; i < len; i++){ uc = *pinbuf++; //if(ui < offset){ // uc = 0; //} //else { // ui -= offset; ui0 = uc; if ( ((uc >> 5) & 0x07) == 0x00) { ui = ( ui0 & 0x0000001f); } else if( ((uc >> 4) & 0x0f) == 0x02) { ui = ( 0x00000020 + ((ui0 << 1) & 0x0000001f) ); } else if( ((uc >> 3) & 0x1f) == 0x06) { ui = ( 0x00000040 + ((ui0 << 3) & 0x0000003f) ); } else if( ((uc >> 3) & 0x1f) == 0x07) { ui = ( 0x00000080 + ((ui0 << 4) & 0x0000007f) ); } else if( ((uc >> 3) & 0x1f) == 0x08) { ui = ( 0x00000100 + ((ui0 << 5) & 0x000000ff) ); } else if( ((uc >> 3) & 0x1f) == 0x09) { ui = ( 0x00000200 + ((ui0 << 6) & 0x000001ff) ); } else if( ((uc >> 3) & 0x1f) == 0x0a) { ui = ( 0x00000400 + ((ui0 << 7) & 0x000003ff) ); } else if( ((uc >> 3) & 0x1f) == 0x0b) { ui = ( 0x00000800 + ((ui0 << 8) & 0x000007ff) ); } else if( ((uc >> 3) & 0x1f) == 0x0c) { ui = ( 0x00001000 + ((ui0 << 9) & 0x00000fff) ); } else if( ((uc >> 3) & 0x1f) == 0x0d) { ui = ( 0x00002000 + ((ui0 << 10) & 0x00001fff) ); } else if( ((uc >> 3) & 0x1f) == 0x0e) { ui = ( 0x00004000 + ((ui0 << 11) & 0x00003fff) ); } else if( ((uc >> 3) & 0x1f) == 0x0f) { ui = ( 0x00008000 + ((ui0 << 12) & 0x00007fff) ); } else if( ((uc >> 3) & 0x1f) == 0x10) { ui = ( 0x00010000 + ((ui0 << 13) & 0x0000ffff) ); } else if( ((uc >> 3) & 0x1f) == 0x11) { ui = ( 0x00020000 + ((ui0 << 14) & 0x0001ffff) ); } else if( ((uc >> 3) & 0x1f) == 0x12) { ui = ( 0x00040000 + ((ui0 << 15) & 0x0003ffff) ); } else if( ((uc >> 3) & 0x1f) == 0x13) { ui = ( 0x00080000 + ((ui0 << 16) & 0x0007ffff) ); } else if( ((uc >> 3) & 0x1f) == 0x14) { ui = ( 0x00100000 + ((ui0 << 17) & 0x000fffff) ); } else if( ((uc >> 3) & 0x1f) == 0x15) { ui = ( 0x00200000 + ((ui0 << 18) & 0x001fffff) ); } else if( ((uc >> 3) & 0x1f) == 0x16) { ui = ( 0x00400000 + ((ui0 << 19) & 0x003fffff) ); } else if( ((uc >> 3) & 0x1f) == 0x17) { ui = ( 0x00800000 + ((ui0 << 20) & 0x007fffff) ); } else if( ((uc >> 3) & 0x1f) == 0x18) { ui = ( 0x01000000 + ((ui0 << 21) & 0x00ffffff) ); } else if( ((uc >> 3) & 0x1f) == 0x19) { ui = ( 0x02000000 + ((ui0 << 22) & 0x01ffffff) ); } else if( ((uc >> 3) & 0x1f) == 0x1a) { ui = ( 0x04000000 + ((ui0 << 23) & 0x03ffffff) ); } else if( ((uc >> 3) & 0x1f) == 0x1b) { ui = ( 0x08000000 + ((ui0 << 24) & 0x07ffffff) ); } else if( ((uc >> 3) & 0x1f) == 0x1c) { ui = ( 0x10000000 + ((ui0 << 25) & 0x0fffffff) ); } else if( ((uc >> 3) & 0x1f) == 0x1d) { ui = ( 0x20000000 + ((ui0 << 26) & 0x1fffffff) ); } else if( ((uc >> 3) & 0x1f) == 0x1e) { ui = ( 0x40000000 + ((ui0 << 27) & 0x3fffffff) ); } else if( ((uc >> 3) & 0x1f) == 0x1f) { ui = ( 0x80000000 + ((ui0 << 28) & 0x7fffffff) ); } else { ui = 0; } //} *poutbuf++ = ui; } } return TRUE; }