#include "xspDataOpt.h" #include "../Hardware/boardinit.h" #include #include #include "public.h" #include "masterslave.h" testCollDa g_testCollDa; GunStatus g_gunStatus[4]; // 抬枪信号的状态 //static uint8_t g_srcDa[4][12]; // 读取的原始数据,每个port最多96位数据 uint8_t g_7egDa[29] = {0}; XspErrDa g_xspErrDa; uint8_t g_logbuff[128] = {0}; XspDataInfo g_xspReDa; // 显示屏的记录数据 Up7segData g_up7segData; XspCollDa g_xspCollDa; Error7Seg g_error7seg; NeedleTable g_neTable[128] = { {U1_ID,1,255,255},{U1_ID,0,18,5},{U1_ID,0,18,4},{U1_ID,0,18,3},{U1_ID,0,18,6},{U1_ID,1,18,6},{U1_ID,1,18,5},{U1_ID,1,18,4},//M1 P_A {U1_ID,1,255,255},{U1_ID,0,17,0},{U1_ID,0,18,7},{U1_ID,0,17,6},{U1_ID,0,17,1},{U1_ID,1,17,1},{U1_ID,1,17,0},{U1_ID,1,18,7},//M2 P_A {U1_ID,1,17,7}, {U1_ID,0,17,3},{U1_ID,0,17,2},{U1_ID,0,17,5},{U1_ID,0,17,4},{U1_ID,1,17,4},{U1_ID,1,17,3},{U1_ID,1,17,2},//M3 P_A {U1_ID,1,16,3}, {U1_ID,0,16,1},{U1_ID,0,16,0},{U1_ID,0,17,7},{U1_ID,0,16,2},{U1_ID,1,16,2},{U1_ID,1,16,1},{U1_ID,1,16,0},//M4 P_A {U1_ID,1,16,7}, {U1_ID,0,16,5},{U1_ID,0,16,4},{U1_ID,0,16,3},{U1_ID,0,16,6},{U1_ID,1,16,6},{U1_ID,1,16,5},{U1_ID,1,16,4},//M5 P_A {U1_ID,1,255,255},{U1_ID,0,15,1},{U1_ID,0,15,0},{U1_ID,0,16,7},{U1_ID,0,15,2},{U1_ID,1,15,2},{U1_ID,1,15,1},{U1_ID,1,15,0},//M6 P_A {U5_ID,0,255,255},{U5_ID,0, 2,4},{U5_ID,0, 2,5},{U5_ID,0, 2,3},{U5_ID,0, 2,2},{U5_ID,1, 2,2},{U5_ID,1, 2,4},{U5_ID,1, 2,5},//O1 P_A {U5_ID,0,255,255},{U5_ID,0, 2,0},{U5_ID,0, 2,1},{U5_ID,0, 3,7},{U5_ID,0, 3,6},{U5_ID,1, 3,6},{U5_ID,1, 2,0},{U5_ID,1, 2,1},//O2 P_A {U5_ID,0,6,0}, {U5_ID,0, 3,4},{U5_ID,0, 3,5},{U5_ID,0, 3,3},{U5_ID,0, 3,2},{U5_ID,1, 3,2},{U5_ID,1, 3,4},{U5_ID,1, 3,5},//O3 P_A {U5_ID,0,7,4}, {U5_ID,0, 6,2},{U5_ID,0, 6,3},{U5_ID,0 ,6,1},{U5_ID,1, 6,0},{U5_ID,1, 6,1},{U5_ID,1, 6,2},{U5_ID,1, 6,3},//O4 P_A {U5_ID,0,7,0}, {U5_ID,0, 7,6},{U5_ID,0, 7,7},{U5_ID,0, 7,5},{U5_ID,1, 7,4},{U5_ID,1, 7,5},{U5_ID,1, 7,6},{U5_ID,1, 7,7},//O5 P_A {U5_ID,0,255,255},{U5_ID,0, 7,2},{U5_ID,0, 7,3},{U5_ID,0, 7,1},{U5_ID,1, 7,0},{U5_ID,1, 7,1},{U5_ID,1, 7,2},{U5_ID,1, 7,3},//O6 P_A {U4_ID,0,5,7}, {U4_ID,0, 4,4},{U4_ID,0, 4,5},{U4_ID,0, 4,3},{U4_ID,0, 4,2},{U4_ID,1, 4,2},{U4_ID,1, 4,4},{U4_ID,1, 4,5},//P1 P_A {U4_ID,0,5,3}, {U4_ID,0, 4,0},{U4_ID,0, 4,1},{U4_ID,1, 5,7},{U4_ID,0, 5,6},{U4_ID,1, 5,6},{U4_ID,1, 4,0},{U4_ID,1, 4,1},//P2 P_A {U4_ID,0,6,7}, {U4_ID,0, 5,4},{U4_ID,0, 5,5},{U4_ID,1, 5,3},{U4_ID,0, 5,2},{U4_ID,1, 5,2},{U4_ID,1, 5,4},{U4_ID,1, 5,5},//P3 P_A {U4_ID,0,255,255},{U4_ID,0, 5,0},{U4_ID,0, 5,1},{U4_ID,1, 6,7},{U4_ID,0, 6,6},{U4_ID,1, 6,6},{U4_ID,1, 5,0},{U4_ID,1, 5,1},//P4 P_A }; static int8_t check_segCode(uint8_t segcode,uint8_t *error) { int8_t da; switch(segcode){ case 0x3E: case 0x3B: case 0x37: case 0x1F: *error = 1; case 0x3F: case 0xBF: da = 0; break; //0 case 0x0E: case 0x16: *error = 1; case 0x06: case 0x86: da = 1; break; //1 case 0x5A: case 0x59: case 0x53: case 0x1B: *error = 1; case 0x5B: case 0xDB: da = 2; break; //2 case 0x4E: *error = 1; case 0x4F: case 0xCF: da = 3; break; //3 case 0x64: case 0x62: case 0x76: *error = 1; case 0x66: case 0xE6: da = 4; break; //4 case 0x6C: case 0x69: case 0x65: case 0x2D: *error = 1; case 0x6D: case 0xED: da = 5; break; //5 case 0x7C: case 0x79: case 0x75: case 0x5D: *error = 1; case 0x7D: case 0xFD: da = 6; break; //6 case 0x05: case 0x03: case 0x17: case 0x27: *error = 1; case 0x07: case 0x87: da = 7; break; //7 case 0x7E: case 0x77: *error = 1; case 0x7F: case 0xFF: da = 8; break; //8 case 0x6B: *error = 1; case 0x6F: case 0xEF: da = 9; break; //9 case 0x46: da = -1; break; default: da = -1; break; } return da; } static int8_t check_segCode_first(uint8_t segcode[], Usrc7SegDa *seg, uint8_t *error) { int8_t da = 0x00; uint8_t i = 0,bpl = 0x00; uint16_t sum = 0; static uint8_t flag = 0; g_xspCollDa.bcorrect = 0; bpl = 0x00; for (i = 0; i < 16; i++) { switch (segcode[i]) { case 0x3E: case 0x3B: case 0x37: case 0x1F: *error = 1; case 0x3F: case 0xBF: seg->val[i] = 0x3F; break; //0 case 0x0E: case 0x16: *error = 1; case 0x06: case 0x86: seg->val[i] = 0x06; break; //1 case 0x5A: case 0x59: case 0x53: case 0x1B: *error = 1; case 0x5B: case 0xDB: seg->val[i] = 0x5B; break; //2 case 0x4E: *error = 1; case 0x4F: case 0xCF: seg->val[i] = 0x4F; break; //3 case 0x64: case 0x62: case 0x76: *error = 1; case 0x66: case 0xE6: seg->val[i] = 0x66; break; //4 case 0x6C: case 0x69: case 0x65: case 0x2D: *error = 1; case 0x6D: case 0xED: seg->val[i] = 0x6D; break; //5 case 0x7C: case 0x79: case 0x75: case 0x5D: *error = 1; case 0x7D: case 0xFD: seg->val[i] = 0x7D; break; //6 case 0x05: case 0x03: case 0x17: case 0x27: *error = 1; case 0x07: case 0x87: seg->val[i] = 0x07; break; //7 case 0x7E: case 0x77: *error = 1; case 0x7F: case 0xFF: seg->val[i] = 0x7F; break; //8 case 0x6B: *error = 1; case 0x6F: case 0xEF: seg->val[i] = 0x6F; break; //9 case 0x01: case 0x02: case 0x04: case 0x08: // 处理七段码非针的情况 case 0x10: case 0x20: case 0x40: seg->val[i] = 0x00; g_xspCollDa.bcorrect |= 0x01; break; case 0x80:// 只有点的情况,不算是错误码,直接转成空即不显示 seg->val[i] = 0x00; break; case 0x72: case 0x38: case 0xF2: case 0xB8: // 去掉P和L的情况 *error = 1; da = -1; bpl = 0x01; break; case 0x00: // 处理没有显示的数据 seg->val[i] = segcode[i]; break; default: *error = 1; seg->val[i] = segcode[i]; break; } sum += seg->val[i]; //printf("%02x,",segcode[i]); } //printf("\n"); if(bpl == 0x01) goto ERROR_END; if(da == 0x00){ // 考虑去掉P和L的情况 if (sum == 0) da = -1; else da = 1; } if(*error == 0x00) return da; ERROR_END: for(i=0;i<16;i++){ if(segcode[i] != g_xspErrDa.segDa[i]) { memcpy(g_xspErrDa.segDa,segcode,16); timeout_stop(&g_xspErrDa.timer); timeout_start(&g_xspErrDa.timer); flag = 1; break; } } if((g_logMsg.blogOpen == 1) && (g_logMsg.logType==LOG_TYPE_7SEG)){ if(flag == 1) { g_xspErrDa.bsend = 2; flag = 0; } if(timeout_isOut(&g_logMsg.timer)){ g_logMsg.blogOpen = 0; g_logMsg.logType = LOG_TYPE_NULL; timeout_stop(&g_logMsg.timer); } } else if(g_logMsg.logType == LOG_TYPE_NULL){ if(timeout_isOut(&g_xspErrDa.timer) && flag == 1){ for(i=0;i<16;i++){ if(g_xspErrDa.lastsegDa[i] != g_xspErrDa.segDa[i]) { memcpy(g_xspErrDa.lastsegDa,g_xspErrDa.segDa,16); timeout_stop(&g_xspErrDa.timer); timeout_start(&g_xspErrDa.timer); flag = 2; break; } } if(flag == 2) g_xspErrDa.bsend = 2; // 此条记录未发送 else g_xspErrDa.bsend = 1; flag = 0; } } if((segcode[0] == 0x78) &&(segcode[1]==0x5C) && (segcode[2]==0x78)) da = -1; //totl,在查询总累计的时候显示的 return da; } /*----------------------------------------------------------------------- * 将映射数据转换为实际的数据 * -----------------------------------------------------------------------*/ #if(0) static uint8_t get_data_from_7segCode(uint8_t *segcode, dispData *tempda ) { volatile uint8_t i,ret = 0,j=0,bprice = 0, bamount = 0, boil = 0; int8_t da,comDa[6] = {0},corrDa[6] = {0},bcorrDa = 0; uint8_t bsegright = 0, bright = 0, berror = 0; // 判断单价 油量 金额是否正确,0位:金额 1位:测量 2位:单价 uint32_t correctAmount = 0, calAmount = 0; // 纠正后的金额,计算的金额 char dastr[11] = {'\0'}; float price = 0,amount =0; static uint8_t flag = 0; uint16_t sum = 0, amountadd = 0; uint8_t segcode01[16] = {0}; g_xspoptDa.bcorrect = 0; if((segcode[0] == 0x72)){ // 去掉PP情况 定额加油的情况 ret = 0; goto ERROR_END; } if((segcode[0] == 0x38) ) {// 去掉LL情况 定量加油的情况 ret = 0; goto ERROR_END; } for(i=0;i<16;i++){// 去掉只有一个针的情况 switch (segcode[i]){ case 0x01: case 0x02: case 0x04: case 0x08: case 0x10: case 0x20: case 0x40: case 0x80: segcode01[i] = 0; bsegright = 1;// 错误 g_xspoptDa.bcorrect |= 0x01; break; default: segcode01[i] = segcode[i]; break; } if(i<6) amountadd += (segcode[i]&0x7F); sum += segcode[i]; } if(sum == 0) { ret = 0; goto ERROR_END; } if(segcode01[0] != 0x00){ if(segcode01[1] == 0x00 || segcode01[2] == 0x00 || segcode01[3] == 0x00){ ret = 0; goto ERROR_END; } } else { if(amountadd == 0x00){ ret = 0; goto ERROR_END; } } for(i=0;i<6;i++){ // 金额 if(segcode01[i] == 0x00 ){ da = 0; dastr[i] = 0x30;}// value = ((value<<(i*8))|da);} else { da = check_segCode(segcode01[i],&berror); if((i==5) && (da == -1)){ // 处理金额的最后一位错误,则不处理 dastr[i] = 0x30; } else if(da != -1){ dastr[i] = check_segCode(segcode01[i],&berror) |0x30; } else {bamount = 1; bright |= 0x01;} // 金额错误 } comDa[i] = da; } if(bamount == 0){ dastr[i] = 0; tempda->amount = atol(dastr); } j = 0; for(i=6;i<12;i++,j++) { // 油量 if(segcode01[i] == 0x00 ) { da = 0; dastr[i-6] = 0x30;}// value = ((value<<(j*8))|da);} else { da = check_segCode(segcode01[i],&berror); if(da != -1){ dastr[i-6] = check_segCode(segcode01[i],&berror) |0x30; } else {boil = 1; bright |= 0x02 ; break;} // 油量错误 } } if(boil == 0) { dastr[i-6] = 0; tempda->oil = atol(dastr); } if(0 == g_bhavePrice) { if(bamount == 0 && boil ==0){ if(tempda->oil !=0) price = (float)tempda->amount/(float)tempda->oil; else price = 0; tempda->price = (uint32_t)(price*100.0+0.5); } } else { j = 0; for(i=12;i<16;i++,j++){ // 单价 if(segcode01[i] == 0x00 ) { da = 0; dastr[i-12] = 0x30;}// value = ((value<<(j*8))|da);} else { da = check_segCode(segcode01[i],&berror); if(da != -1){ dastr[i-12] = check_segCode(segcode01[i],&berror) |0x30; } else {bprice = 1; bright |=0x04; break;} // 单价错误 } } if(bprice == 0){ dastr[i-12] = 0; tempda->price = atol(dastr); } } if((bright == 0x00) &&( bsegright==0x00)) { return 1;} // 数据是正确的 else if((bright == 0x00) && (bsegright == 0x01)) { // 数据除了有非针,其它情况全对 ret = 1; goto ERROR_END; } else if(bright == 0x07){ret = 0;} // 全错,无法纠正 else if(bright == 0x04){ // 金额和油量正确,单价错误,可以纠正 ret = 1; g_xspoptDa.bcorrect |= 0x02; if(tempda->oil != 0) tempda->price = (uint32_t)((float)tempda->amount/(float)tempda->oil*100.0); else tempda->price = 0; } else if(bright == 0x02){// 金额和单价正确, 油量错误,可以纠正 ret = 1; g_xspoptDa.bcorrect |= 0x02; tempda->oil = (uint32_t)((float)tempda->amount/(float)tempda->price*100.0+0.5); } else if(bright == 0x01){// 油量和单价正确, 金额错误, 可以纠正 ret = 1; g_xspoptDa.bcorrect |= 0x02; amount = (float)tempda->oil/100.0 *((float)tempda->price/100.0); calAmount = (uint32_t)(amount*100); // 直接计算的 correctAmount = (uint32_t)(amount+0.5)*100; // 取整后的 corrDa[0] = correctAmount/100000%10; corrDa[1] = correctAmount/10000%10; corrDa[2] = correctAmount/1000%10; corrDa[3] = correctAmount/100%10; corrDa[4] = correctAmount/10%10; corrDa[5] = correctAmount%10; for(i=0;i<6;i++){ if(comDa[i] == -1) continue; if(corrDa[i] != comDa[i]) {bcorrDa = 1; break;} // 不能用纠正后的数据,用直接计算的值 } if(bcorrDa == 1) tempda->amount = calAmount; // 直接计算的 else tempda->amount = correctAmount; // 校正后的 } else { ret = 0; // 错误其中任意两个 } ERROR_END: for(i=0;i<16;i++){ if(segcode[i] != g_xspErrDa.segDa[i]) { memcpy(g_xspErrDa.segDa,segcode,16); timeout_stop(&g_xspErrDa.timer); timeout_start(&g_xspErrDa.timer); flag = 1; break; } } if((g_logMsg.blogOpen == 1) && (g_logMsg.logType==LOG_TYPE_7SEG)){ if(flag == 1) { g_xspErrDa.bsend = 2; flag = 0; } if(timeout_isOut(&g_logMsg.timer)){ g_logMsg.blogOpen = 0; g_logMsg.logType = LOG_TYPE_NULL; timeout_stop(&g_logMsg.timer); } } else if(g_logMsg.logType == LOG_TYPE_NULL){ if(timeout_isOut(&g_xspErrDa.timer) && flag == 1){ for(i=0;i<16;i++){ if(g_xspErrDa.lastsegDa[i] != g_xspErrDa.segDa[i]) { memcpy(g_xspErrDa.lastsegDa,g_xspErrDa.segDa,16); timeout_stop(&g_xspErrDa.timer); timeout_start(&g_xspErrDa.timer); flag = 2; break; } } if(flag == 2) g_xspErrDa.bsend = 2; // 此条记录未发送 else g_xspErrDa.bsend = 1; flag = 0; } } return ret; } #else uint8_t get_data_from_7segCode(Usrc7SegDa *seg, dispData *tempda) { uint8_t i = 0, berror = 0,bright = 0, ret = 1; int8_t da = 0, comDa[6] = { 0 }; uint8_t bprice = 0, bamount = 0, boil = 0,corrDa[6] = { 0 }, bcorrDa = 0; uint8_t priceCnt = 0; // 单价的位数,单价必须为三个,如果为两数,则数据是错误的 char amountStr[6] = {'\0'}; char oilStr[6] = {'\0'}; char priceStr[5] = {'\0'}; uint32_t correctAmount = 0, calAmount = 0; // 纠正后的金额,计算的金额 static float price = 0; float amount = 0; for (i = 0; i < 6; i++) { if (seg->da.amount[i] == 0x00) { da = 0; amountStr[i] = 0x30; if(i>0) amountStr[i-1] = 0x30; } else { da = check_segCode(seg->da.amount[i],&berror); if ((i == 5) && (da == -1)) amountStr[i] = 0x30; // 处理金额的最后一位,如果金额的最后一位是错误的,则直接变为0 else if (da != -1) { amountStr[i] = da | 0x30; } else { bamount = 0x01; bright |= 0x01; } } comDa[i] = da; } if (bamount == 0) { tempda->amount = atol(amountStr); } for (i = 0; i < 6; i++) { if (seg->da.oil[i] == 0x00) { da = 0; oilStr[i] = 0x30; if(i>0) oilStr[i-1] = 0x30; } else { da = check_segCode(seg->da.oil[i], &berror); if ((i == 5) && (da == -1)) oilStr[i] = 0x30; else if (da != -1) { oilStr[i] = da | 0x30; } else { boil = 0x01; bright |= 0x02; } } } if (boil == 0) { tempda->oil = atol(oilStr); } if (0 == g_bhavePrice) { // 没有单价屏 if ((bamount == 0) &&( boil == 0)) { if (tempda->oil != 0) price = (float)tempda->amount / (float)tempda->oil; else price = 0; tempda->price = (uint32_t)(price*100.0 + 0.5); } else if((bamount == 1) && (boil == 0)){ // 金额错误,油量对 tempda->amount = price * tempda->oil/100; } else if((bamount == 0) && (boil == 1)){ // 金额对,油量错误 if(price > 0.1) tempda->oil = (uint32_t)((float)tempda->amount / price +0.5); } } else { // 有单价屏 priceCnt = 0x00; for (i = 0; i < 4; i++) { if (seg->da.price[i] == 0x00) { da = 0; priceStr[i] = 0x30; } else { priceCnt |= ((uint8_t)0x01 << (3-i)); da = check_segCode(seg->da.price[i], &berror); if (da != -1) { priceStr[i] = da | 0x30; } else { bprice = 0x01; bright |= 0x04; } } } if (bprice == 0) { if(priceCnt == 0x07) tempda->price = atol(priceStr); else { bright |= 0x04; } } } if(bright == 0x00) ret = 1; // 三项全对 else if (bright == 0x07) ret = 0; // 金额 油量 单价全部错误 else if (bright == 0x04) { // 单价错误 金额 油量正确 if (tempda->oil != 0) tempda->price = (uint32_t)((float)tempda->amount / (float)tempda->oil*100.0 + 0.5); else tempda->price = 0; g_xspCollDa.bcorrect |= 0x02; } else if (bright == 0x02) { // 油量错误 金额 单价正确 if(tempda->price != 0) tempda->oil = (uint32_t)((float)tempda->amount / (float)tempda->price*100.0 + 0.5); g_xspCollDa.bcorrect |= 0x02; } else if (bright == 0x01) { // 金额错误 油量 单价正确 amount = (float)tempda->oil / 100.0 *((float)tempda->price / 100.0); calAmount = (uint32_t)(amount * 100); // 直接计算的 correctAmount = (uint32_t)(amount + 0.5) * 100; // 取整后的 corrDa[0] = correctAmount / 100000 % 10; corrDa[1] = correctAmount / 10000 % 10; corrDa[2] = correctAmount / 1000 % 10; corrDa[3] = correctAmount / 100 % 10; corrDa[4] = correctAmount / 10 % 10; corrDa[5] = correctAmount % 10; for (i = 0; i < 6; i++) { if (comDa[i] == -1) continue; if (corrDa[i] != comDa[i]) { bcorrDa = 1; break; } // 不能用纠正后的数据,用直接计算的值 } if (bcorrDa == 1) tempda->amount = calAmount; // 直接计算的 else tempda->amount = correctAmount; // 校正后的 g_xspCollDa.bcorrect |= 0x02; } else { // 错误其中两项,无法纠正 ret = 0; } return ret; } #endif /*------------------------------------------------------------------------------- * 保存记录 * -------------------------------------------------------------------------------*/ void save_record_to_flash(uint8_t recordMode) { int amount = 0; // uint32_t addTime; // if(recordMode == 0x01){ // addTime = g_xspCollDa.gunDnTime - g_xspCollDa.gunUpTime; // 计算加油的时间 单位ms // printf("~~~~~~~~~~~~~~addtime = %d, oil = %d\n",addTime, g_xspCollDa.curDisp.oil); // } g_xspCollDa.lastbSaveRecord = 0; if((recordMode == 0x01) &&(g_xspCollDa.bcheckDa == 0) ){// if((g_xspCollDa.curDisp.amount == 888888) || (g_xspCollDa.curDisp.oil == 888888)) return; if((g_xspCollDa.curDisp.amount == 0) || (g_xspCollDa.curDisp.oil == 0)) return ; if(g_xspCollDa.curDisp.amount >=999999 || g_xspCollDa.curDisp.oil>=999999) return; g_xspReDa.reDa.amount = g_xspCollDa.curDisp.amount; g_xspReDa.reDa.price = g_xspCollDa.curDisp.price; g_xspReDa.reDa.oil = g_xspCollDa.curDisp.oil; g_xspReDa.reDa.tamount = g_xspCollDa.lastTamout + g_xspCollDa.curDisp.amount; g_xspReDa.reDa.toil = g_xspCollDa.lastToil + g_xspCollDa.curDisp.oil; } else { if((g_xspCollDa.lastDisp.amount == 888888) || (g_xspCollDa.lastDisp.oil == 888888)) return; if((g_xspCollDa.lastDisp.amount == 0) || (g_xspCollDa.lastDisp.oil == 0)) return ; if(g_xspCollDa.lastDisp.amount == g_xspCollDa.lastDisp.oil) return; if(g_xspCollDa.lastDisp.amount >=999999 || g_xspCollDa.lastDisp.oil>=999999) return; amount = g_xspCollDa.curDisp.amount - g_xspCollDa.lastDisp.amount; if((g_xspCollDa.curDisp.amount!=0) &&(amount>0) && (amount <50)){ // 和当前的值校正一下 g_xspCollDa.lastDisp.amount = g_xspCollDa.curDisp.amount; g_xspCollDa.lastDisp.oil = g_xspCollDa.curDisp.oil; } g_xspReDa.reDa.amount = g_xspCollDa.lastDisp.amount; g_xspReDa.reDa.price = g_xspCollDa.lastDisp.price; g_xspReDa.reDa.oil = g_xspCollDa.lastDisp.oil; g_xspReDa.reDa.tamount = g_xspCollDa.lastTamout + g_xspCollDa.lastDisp.amount; g_xspReDa.reDa.toil = g_xspCollDa.lastToil + g_xspCollDa.lastDisp.oil; } g_xspReDa.reDa.bcorrect = ((g_xspCollDa.bcorrect|0xFFFF)<<8); g_xspReDa.reDa.bsend = 0xFFFF; g_xspReDa.reDa.recodeMode = recordMode; g_xspReDa.reDa.timer = rtc_counter_get();// 产生记录的时间 g_xspCollDa.lastTamout = g_xspReDa.reDa.tamount; g_xspCollDa.lastToil = g_xspReDa.reDa.toil; g_xspReDa.reDa.recordId = (g_xspReDa.reDa.recordId+1)%0xFFFFFFFF; write_flash(g_xspReDa.data); printf("新记录: recordId=%d, amout:%d, oil:%d, tamout:%lld, toil:%lld\r\n",g_xspReDa.reDa.recordId,\ g_xspReDa.reDa.amount,g_xspReDa.reDa.oil,g_xspReDa.reDa.tamount,g_xspReDa.reDa.toil); memset(&g_xspCollDa.lastDisp, 0, sizeof(dispData)); // 存储完成后,要清除保留的数据 } /*------------------------------------------------------------------------ * 抬枪信号的处理 * -----------------------------------------------------------------------*/ void init_gun_status(void) { uint8_t i; for(i=0;i<4;i++){ g_gunStatus[i].curst = HIGHT_LEVEL; g_gunStatus[i].lastst = HIGHT_LEVEL; g_gunStatus[i].timer = 0; g_gunStatus[i].bsave = 0; } g_gunSta.bGunUp = 0; timeout_setValue(&g_gunSta.guntime,2000); timeout_setValue(&g_gunSta.taigunTime,500); } void deal_gun_status(uint32_t tick) { uint8_t status; static uint8_t laststatus = 0xFF; static uint8_t count = 0; if((tick%1000) != 0) return; // 10ms处理一次 if(g_xspCollDa.curstatus == STATUS_PROG) return; // 在加油过程中,不处理抬挂枪的信号 status = gpio_input_bit_get(TQ_PORT,TQ_PIN); if(status != laststatus) { laststatus = status; count = 0; } else count++; if(count>=4){ if(RESET == status) { // 有抬枪信号 g_gunStatus[0].curst = LOW_LEVEL; g_gunStatus[0].bsave = 0; timeout_stop(&g_gunSta.guntime); } else { // 没有抬枪信号,有挂枪 if(g_gunStatus[0].curst == LOW_LEVEL){ g_gunStatus[0].lastst = g_gunStatus[0].curst; timeout_start(&g_gunSta.guntime); // 启动抬枪的时候 g_gunStatus[0].bsave = 1; g_gunStatus[0].curst = LOW_HIGHT; } } count = 0; } } void check_gun_status_to_save_record(void) { uint8_t status; static uint8_t gunstatus = 0xFF; if(gunstatus != g_gunStatus[0].curst){ printf("gunstatus = %d ", g_gunStatus[0].curst); switch(g_gunStatus[0].curst){ case HIGHT_LOW: case LOW_LEVEL: if(gpio_input_bit_get(TQ_PORT,TQ_PIN)!= RESET) break; printf("抬枪\n"); g_xspCollDa.gunUpTime = Get_SysTick(); // 得到抬枪的时间 if((Get_SysTick() - g_xspCollDa.gunDnTime) <1000) break; if((g_xspCollDa.curstatus != STATUS_START) && (g_xspCollDa.curstatus != STATUS_PROG)){ g_xspCollDa.curstatus = STATUS_START; } g_xspCollDa.gunStatus = GUN_UP; break; case LOW_HIGHT: case HIGHT_LEVEL: g_xspCollDa.gunDnTime = Get_SysTick(); // 得到挂枪的时间 printf("挂枪\n"); if((g_xspCollDa.gunUpTime==0)){ g_gunStatus[0].bsave = 0; gunstatus = g_gunStatus[0].curst; return; } else if((g_xspCollDa.gunDnTime >= g_xspCollDa.gunUpTime)){ if(g_xspCollDa.gunDnTime-g_xspCollDa.gunUpTime<1000) { printf("干扰产生的抬枪信号\n"); g_gunStatus[0].bsave = 0; gunstatus = g_gunStatus[0].curst; return; } } g_xspCollDa.gunStatus = GUN_DOWN; g_xspCollDa.gunUpTime = 0; break; } gunstatus = g_gunStatus[0].curst; } status = gpio_input_bit_get(TQ_PORT,TQ_PIN); if(timeout_isOut(&g_gunSta.guntime) && (g_gunStatus[0].bsave == 1) && (g_xspCollDa.curstatus != STATUS_PROG)){ if((SET == gpio_input_bit_get(TQ_PORT,TQ_PIN)) && (g_xspCollDa.bSaveRecode == 1)){ printf("枪已经挂\n"); g_gunSta.bGunDn = 0; save_record_to_flash(0x01);//存储数据 g_xspCollDa.bSaveRecode = 0; printf("抬枪信号产生一笔新的记录\r\n"); g_gunSta.bgun = 0; g_gunStatus[0].bsave = 0; g_xspCollDa.curstatus = STATUS_END; g_xspCollDa.gunUpTime = 0; g_xspCollDa.startToprog = 0; } else { printf("空抬枪,未加油\n"); g_gunStatus[0].bsave = 0; g_xspCollDa.curstatus = STATUS_NULL; g_xspCollDa.gunUpTime = 0; } } } /*------------------------------------------------------------------------ * 时间 30分钟没有保存记录,则保存 * -----------------------------------------------------------------------*/ void init_xsp_run_data(void) { timeout_setValue(&g_xspErrDa.timer,3000); timeout_setValue(&g_xspCollDa.sameTimer, 3000); g_logMsg.logType = LOG_TYPE_NULL; } /*------------------------------------------------------------------------- * 上电对比上次保存和当前屏显是否一致 * 上电是只执行一次 * ------------------------------------------------------------------------*/ void power_up_check_last_cur(dispData *da) { return; // if((da->amount == 0) && (da->oil == 0)) g_xspoptDa.lastDawrite = 1; // else if((g_xspReDa.reDa.amount==da->amount) \ // && (g_xspReDa.reDa.oil==da->oil)) { // 当前屏显和上一比存储的是一比数据,本数据已存储 // g_xspoptDa.lastDawrite = 1; // g_xspCollDa.curDisp.oil = da->oil; // g_xspCollDa.curDisp.amount = da->amount; // printf("当前屏显与flash中存储的一致"); // } // else g_xspoptDa.lastDawrite = 0; } void analysis_7seg_code(uint8_t _7egDa[]) { uint8_t i = 0, bflag = 0,bequal = 0,bstart =0; uint8_t boil = 0, bamt = 0; uint32_t eAmount = 0, eOil = 0,tickoil,tickAm; // 用于存储差额的 int8_t ret = 0; uint32_t tampTime = 0; Usrc7SegDa *src7Da = NULL, *last1 = NULL, *last2 = NULL; static dispData temp,nostart; // float price; uint16_t uprice = 0; src7Da = &g_xspCollDa.cur; last1 = &g_xspCollDa.last1; last2 = &g_xspCollDa.last2; g_error7seg.berror = 0; ret = check_segCode_first(&_7egDa[START_ID],src7Da, &g_error7seg.berror); // 2. 第一次解析 if (ret == -1) { printf("采集到的7段码全部为0\n"); return; } bflag = g_xspCollDa.cur.da.amount[0] | g_xspCollDa.cur.da.amount[1] | g_xspCollDa.cur.da.amount[2] | g_xspCollDa.cur.da.oil[0] | g_xspCollDa.cur.da.oil[1] | g_xspCollDa.cur.da.oil[2]; if (bflag == 0x00) { // 金额 油量的高3个字节都为0(即不显示任何数)则判断是否是加油开始 if(g_xspCollDa.cur.da.amount[3] == 0x3F) {bamt |=0x01;} if(g_xspCollDa.cur.da.amount[4] == 0x3F) {bamt |=0x02;} if(g_xspCollDa.cur.da.amount[5] == 0x3F) {bamt |=0x04;} if(g_xspCollDa.cur.da.oil[3] == 0x3F) {boil |= 0x01; } if(g_xspCollDa.cur.da.oil[4] == 0x3F) {boil |= 0x02; } if(g_xspCollDa.cur.da.oil[5] == 0x3F) {boil |= 0x04; } if((bamt== 0x07) && (boil == 0x07 || boil==0x06 || boil==0x05 || boil==0x03)) bstart = 1; else if((boil== 0x07) && (bamt == 0x07 || bamt==0x06 || bamt==0x05 || bamt==0x03)) bstart=1; else bstart = 0; if (bstart == 0x01) { printf("显示屏显示为0.00, 加油开始.......\n"); if(g_xspCollDa.bSaveRecode == 0x01) {// 判断是否需要存储记录 save_record_to_flash(0x00); printf("xsp change 00 save\n"); g_xspCollDa.bSaveRecode = 0x00; } memset(&g_xspCollDa.lastDisp, 0, sizeof(dispData)); memset(&g_xspCollDa.curDisp, 0, sizeof(dispData)); g_xspCollDa.lastTick = Get_SysTick(); g_xspCollDa.startTime = Get_SysTick(); g_xspCollDa.startToprog = 0; g_xspCollDa.bcheckDa = 0; temp.amount = 0; temp.oil = 0; g_xspCollDa.curstatus = STATUS_START; // 加油开始 g_xspCollDa.bstart00 = 1; } } bequal = 0; for (i = 0; i < 3; i++) { if ((src7Da->uDa.da32[i] != last1->uDa.da32[i]) && (src7Da->uDa.da32[i] != last2->uDa.da32[i])) { bequal = 1; break; } } if (bequal == 1) { memcpy(last2->val, last1->val, 16); memcpy(last1->val, src7Da->val, 16); ret = get_data_from_7segCode(src7Da, &temp); if(ret == 0) goto ERROR_END; if(((temp.oil == 0x00) && (temp.amount!= 0x00))||((temp.oil!=0)&&(temp.amount==0))) return; tampTime = Get_SysTick()-g_xspCollDa.lastcomTick; g_xspCollDa.lastcomTick = Get_SysTick(); if ((g_xspCollDa.curstatus == STATUS_START) ) { if ((temp.amount > g_xspCollDa.curDisp.amount) || (temp.oil > g_xspCollDa.curDisp.oil)) { eAmount = abs((int)temp.amount - (int)g_xspCollDa.curDisp.amount); eOil = abs((int)temp.oil - (int)g_xspCollDa.curDisp.oil); //printf("aaaaaa = %d, eamout = %d, eoil = %d\n",Get_SysTick()-g_xspCollDa.lastTick,eAmount,eOil); if((eAmount < 100) && (eOil<50) && ((Get_SysTick()-g_xspCollDa.lastTick) < 500)){ //判断是额增长且时间差小于500ms g_xspCollDa.startToprog++; g_xspCollDa.lastTick = Get_SysTick(); } if((g_xspCollDa.startToprog > 5)||(g_xspCollDa.gunStatus==GUN_UP)){//||(g_gunStatus[0].curst==HIGHT_LOW)||(g_gunStatus[0].curst == LOW_LEVEL) g_xspCollDa.curstatus = STATUS_PROG; // 加油过程 memcpy(&g_xspCollDa.lastDisp, &temp, sizeof(dispData)); } g_xspCollDa.bcheckDa = 0; } } else { if((temp.amount==0x00)&&(temp.oil==0x00)){ //printf("ccccccccccccccccccc\n"); if(g_xspCollDa.lastbSaveRecord == 0x01) {// 判断是否需要存储记录 save_record_to_flash(0x00); printf("xsp change 01 save\n"); g_xspCollDa.lastbSaveRecord = 0x00; } memset(&g_xspCollDa.lastDisp, 0, sizeof(dispData)); memset(&g_xspCollDa.curDisp, 0, sizeof(dispData)); g_xspCollDa.lastTick = Get_SysTick(); g_xspCollDa.startTime = Get_SysTick(); g_xspCollDa.startToprog = 0; g_xspCollDa.bcheckDa = 0; g_xspCollDa.curstatus = STATUS_START; // 加油开始 } } memcpy(&g_xspCollDa.curDisp, &temp, sizeof(dispData)); if (g_xspCollDa.curstatus == STATUS_PROG) { // 加油中 uprice = (uint32_t)((float)temp.amount/(float)temp.oil*100.0+0.5); if ( (uprice<1200) && (temp.amount >= g_xspCollDa.lastDisp.amount) && (temp.oil >= g_xspCollDa.lastDisp.oil)) { eAmount = temp.amount - g_xspCollDa.lastDisp.amount; eOil = temp.oil - g_xspCollDa.lastDisp.oil; tickoil = ((Get_SysTick()-g_xspCollDa.lastTick)/10)+1;//*10; // 12毫秒 加10毫升的油 tickoil = ((tickoil <5) ? 5: tickoil); tickAm = (uint32_t)((float)tickoil*(float)temp.price/100.00+0.5)+1; if((eAmount <= tickAm) && (eOil <=tickoil) ){ memcpy(&g_xspCollDa.lastDisp1,&g_xspCollDa.lastDisp,sizeof(dispData)); memcpy(&g_xspCollDa.lastDisp, &temp, sizeof(dispData)); printf("有效,显示屏加油中.......(%010u) ", Get_SysTick()); g_xspCollDa.lastTick1 = g_xspCollDa.lastTick; g_xspCollDa.lastTick = Get_SysTick(); // 只有在加油时,记录时间戳 g_xspCollDa.bstart00 = 0; } else { printf("无效,显示屏加油中.......(%010u,%010u) ", Get_SysTick(),g_xspCollDa.lastTick); } printf("(%02d,%02d) %d,%d,%d\n",tickAm,tickoil, temp.amount, temp.oil, temp.price); g_xspCollDa.bSaveRecode = 1; } else { // 数据采集错误 ,是否可以纠正还原一下正确的数据??? if((temp.amount >=g_xspCollDa.lastDisp1.amount) && (temp.oil >= g_xspCollDa.lastDisp1.oil)){ eAmount = temp.amount - g_xspCollDa.lastDisp1.amount; eOil = temp.oil - g_xspCollDa.lastDisp1.oil; tickoil = ((Get_SysTick()-g_xspCollDa.lastTick1)/10)+1;//*9; tickoil = ((tickoil <5) ? 5: tickoil); tickAm = (uint32_t)((float)tickoil*(float)temp.price/100.00+0.5)+1; if((eAmount <= tickAm) && (eOil <=tickoil) ){ memcpy(&g_xspCollDa.lastDisp, &temp, sizeof(dispData)); printf("上次数据错误,这组数据矫正 %d, %d,%d\n ", temp.amount, temp.oil, temp.price); g_xspCollDa.lastTick = Get_SysTick(); // 只有在加油时,记录时间戳 } else { printf("%d,%d\n",g_xspCollDa.lastDisp1.amount,g_xspCollDa.lastDisp1.oil); printf("abcdef~~~~~ %d,%d,%d,%d,%d\n",tickAm,tickoil,temp.amount, temp.oil, temp.price); } } else { printf("加油中,数据采集错误 "); printf("%d,%d,%d\n", temp.amount, temp.oil, temp.price); } } g_xspCollDa.stopTime = Get_SysTick(); // 整个过程加油的停止时间 g_xspCollDa.bcheckDa = 0; g_gunStatus[0].bsave = 0; } else if (g_xspCollDa.curstatus == STATUS_STOP) { // 停止后,又开始变化的,要判断一下当前的数据是继续加油还是数据的查询 eAmount = abs((int)temp.amount - (int)g_xspCollDa.lastDisp.amount); eOil = abs((int)temp.oil - (int)g_xspCollDa.lastDisp.oil); if ((eAmount < 100) && (eOil < 10)) { printf("加油继续........(%010u) ", Get_SysTick()); printf("%d,%d,%d\n", temp.amount, temp.oil, temp.price); memcpy(&g_xspCollDa.lastDisp, &temp, sizeof(dispData)); g_xspCollDa.lastTick = Get_SysTick(); // 只有在加油时,记录时间戳 g_xspCollDa.curstatus = STATUS_PROG; g_xspCollDa.bSaveRecode = 1; } else { printf("数据查询 "); printf("%d,%d,%d\n", temp.amount, temp.oil, temp.price); g_xspCollDa.curstatus = STATUS_CHECK; g_xspCollDa.bcheckDa = 1; } } else { // 加油停止,或是加油查询时 END, CHECK ,NULL 或是开始到加油中的转换过程 printf("数据显示(%d) ",g_xspCollDa.curstatus); printf("%d,%d,%d\n", temp.amount, temp.oil, temp.price); if(((gpio_input_bit_get(TQ_PORT,TQ_PIN)==RESET)||(tampTime<500)) &&(g_xspCollDa.bstart00==0)){ // 没有检测到00,但检测到抬枪信号的开始 if ((temp.amount > nostart.amount) || (temp.oil > nostart.oil)) { eAmount = abs((int)temp.amount - (int)nostart.amount); eOil = abs((int)temp.oil - (int)nostart.oil); //printf("aaaaaa = %d, eamout = %d, eoil = %d\n",Get_SysTick()-g_xspCollDa.lastTick,eAmount,eOil); if((eAmount < 100) && (eOil<50) ){ //判断是额增长且时间差小于500ms g_xspCollDa.startToprog++; g_xspCollDa.lastTick = Get_SysTick(); } else g_xspCollDa.startToprog = 0; if(g_xspCollDa.startToprog > 5){ if(g_xspCollDa.lastbSaveRecord==0x01){ save_record_to_flash(0x00); printf("xsp change 02 save\n"); g_xspCollDa.lastbSaveRecord = 0x00; } memcpy(&g_xspCollDa.lastDisp,&temp,sizeof(dispData)); g_xspCollDa.lastTick1 = g_xspCollDa.lastTick; g_xspCollDa.lastTick = Get_SysTick(); // 只有在加油时,记录时间戳 g_xspCollDa.curstatus = STATUS_PROG; // 加油过程 } g_xspCollDa.bcheckDa = 0; } memcpy(&nostart, &temp, sizeof(dispData)); printf("aaaaaaaaaaaaaaaaaaa\n"); } } timeout_setValue(&g_xspCollDa.sameTimer, 3000); timeout_start(&g_xspCollDa.sameTimer); } else { if (timeout_isOut(&g_xspCollDa.sameTimer)) { ret = get_data_from_7segCode(src7Da, &temp); if(ret == 0) goto ERROR_END; if (g_xspCollDa.curstatus == STATUS_PROG) { memcpy(&g_xspCollDa.lastDisp, &temp, sizeof(dispData)); g_xspCollDa.curstatus = STATUS_STOP; // 加油停止 g_xspCollDa.bstart00 = 0; g_xspCollDa.lastbSaveRecord = g_xspCollDa.bSaveRecode; } if (g_xspCollDa.curstatus == STATUS_STOP) printf("加油中止,"); else if (g_xspCollDa.curstatus == STATUS_END) printf("加油结束,"); else if (g_xspCollDa.curstatus == STATUS_CHECK) { printf("查询数据,"); g_xspCollDa.bcheckDa = 1; } printf("显示屏数据未变化.......(%010u) ",Get_SysTick()); printf("%d,%d,%d\n", temp.amount, temp.oil, temp.price); g_xspCollDa.startToprog = 0; timeout_start(&g_xspCollDa.sameTimer); } else { if((temp.amount==0x00) && (temp.oil==0x00)){//显示屏显示00的时候, g_xspCollDa.lastTick = Get_SysTick(); g_xspCollDa.startTime = Get_SysTick(); } } return; } return; ERROR_END: printf("数据采集错误:"); for(i=0;i<17;i++){ printf("%02x,",_7egDa[i]); } printf("\n"); g_xspCollDa.errorNum++; return; } void anay_7eg(void) { uint8_t i;//,j; uint8_t index,pos;//,bindex // dispData tempda; // static uint8_t bfirst = 0; // uint8_t ret = 0; memset(g_7egDa,0,sizeof(g_7egDa)); if(g_devMsg.bHYdev == 0x00){ for(i=0;i24) || (index >8)) continue; //最多24个片选,8个数据位 g_7egDa[i/8+1] |= (((g_timeInfo.srcDa[pos]>>index)&0x01)<<(7-i%8));//(((g_srcDa[port][7-srcIndex]>>indexid)&0x01)<<(7-(i%8))); } } else if(g_devMsg.bHYdev == 0x01) { memcpy(g_7egDa,(char*)&g_timeInfo.srcDa[0],17); } else { for(i=0;i24) || (index >8)) continue; //最多24个片选,8个数据位 g_7egDa[i/8+1] |= (((g_timeInfo.srcDa[pos]>>index)&0x01)<<(7-i%8));//(((g_srcDa[port][7-srcIndex]>>indexid)&0x01)<<(7-(i%8))); } } //g_7egDa[12] = 0xFE;//g_7egDa[12]&(~0x01); //g_7egDa[4] &= 0x3F; check_gun_status_to_save_record(); analysis_7seg_code(g_7egDa); } void init_test_coll_data_info(uint8_t bstart) { memset(&g_testCollDa,0,sizeof(testCollDa)); g_testCollDa.bTestCollDa = bstart; if(g_devMsg.bHYdev == 0x01){ g_testCollDa.collTime = 20; // 100个节拍采集一次(即1ms) init_comMsg(); } else g_testCollDa.collTime = 50; // 100个节拍采集一次(即1ms) } ComId _comMsg[3][2]; void init_comMsg(void) { _comMsg[U5_ID][0].comPort = 8; _comMsg[U5_ID][0].comPin = 7; _comMsg[U5_ID][1].comPort = 8; _comMsg[U5_ID][1].comPin = 6; _comMsg[U1_ID][0].comPort = 15; _comMsg[U1_ID][0].comPin = 4;//5; _comMsg[U1_ID][1].comPort = 15; _comMsg[U1_ID][1].comPin = 3; _comMsg[U4_ID][0].comPort = 6; _comMsg[U4_ID][0].comPin = 5; _comMsg[U4_ID][1].comPort = 6; _comMsg[U4_ID][1].comPin = 4; } void deal_coll_data_com(void) { volatile uint16_t i = 0,j = 0,k = 0,mm = 0,m=0, dealIndex = 0; uint8_t val = 0,pos = 0,sameflag = 0,val1 = 0,bZero=0,bOne = 0;//,testi = 0; static uint8_t samecount = 0; volatile static uint16_t curIndex = 0, dealnum = 1; static uint32_t testflag = 0; uint8_t comstatus = 0; // uint8_t uid,cId,csId,pid,comval,bitval; if((g_testCollDa.collNum == g_testCollDa.dealNum)) return; if((g_testCollDa.bdealDa==0) && (g_testCollDa.collNum<2)) return; dealIndex = ((g_testCollDa.collNum == 0) ? TEST_COLL_DA_MAX_NUM: g_testCollDa.collNum); for(i=(curIndex+1);i>k)&0x01; pos = (j<<3) + 7- k; // j *8 + k; if(val != g_testCollDa.lastval[pos]){ g_testCollDa.lastval[pos] = val; g_testCollDa.tcollNum[pos]++; } testflag++; } sameflag = 0; samecount = 0; } else { testflag += 8; sameflag++; } } dealnum++; if(sameflag == (TEST_COLL_GROUP)){ memcpy(&g_testCollDa.lastDa[samecount][0],(char*)(&g_testCollDa.collDa[i][0]),TEST_COLL_GROUP); samecount++; } else { if(samecount>=SAME_GROUP) { break; } } } if(samecount >=SAME_GROUP) { if(i == (dealIndex)) curIndex = i-1; else curIndex = i; for(m=0;m> g_extimsg.comPin[m])&0x01; (comstatus == 0)? (bZero++) : (bOne++); } comstatus = ((bZero>bOne)?0:1); memset((char*)g_timeInfo.srcDa,0,sizeof(g_timeInfo.srcDa)); for(j=0;j>k)&0x01; if(val != comstatus) val1 = 1; else val1 = 0; g_timeInfo.srcDa[j] |= (val1<< k); } } samecount = 0; g_testCollDa.dealNum = i; anay_7eg(); } else { curIndex = i-1;// dealIndex-1; g_testCollDa.dealNum = i;//dealIndex; } if((g_testCollDa.bdealDa == 0x01)&& (dealnum ==(TEST_COLL_DA_MAX_NUM))) { // for(i=0;i<192;i++){ // //if((i%16) == 0) printf("\n"); // //printf("%03d,",g_testCollDa.tcollNum[i]); // g_testCollDa.tcollNum[i] = 0; // 这行必须有,确定放的位置 // } memcpy(g_testCollDa.sendCollNum,g_testCollDa.tcollNum,192); memset(g_testCollDa.tcollNum,0,192); g_testCollDa.bdealDa = 0; dealnum = 1; curIndex = 0; g_testCollDa.dealNum = 0; //printf("test flag %d\n",testflag); testflag = 0; samecount = 0; } } ComSrcDa g_comSrcDa; void deal_coll_data_HY(void) { volatile uint16_t i = 0,j = 0,k = 0,mm = 0, m=0,dealIndex = 0; // uint8_t val = 0,pos = 0,sameflag = 0,val1 = 0,bZero=0,bOne = 0,testi = 0; static uint8_t samecount = 0; volatile static uint16_t curIndex = 0, dealnum = 1; static uint32_t testflag = 0; // uint8_t comstatus = 0; uint8_t u1com0,flag;//u1com1,u4com0,u4com1,u5com0,u5com1,,valpos uint8_t uid,cId,csId,pid,comval,bitval,num; if((g_testCollDa.collNum == g_testCollDa.dealNum)) return; if((g_testCollDa.bdealDa==0) && (g_testCollDa.collNum<6)) return; dealIndex = ((g_testCollDa.collNum == 0) ? TEST_COLL_DA_MAX_NUM: g_testCollDa.collNum); for(i=(curIndex+1);i>_comMsg[U1_ID][0].comPin)&0x01; // u1com1 = (g_testCollDa.collDa[i][_comMsg[U1_ID][1].comPort] >>_comMsg[U1_ID][1].comPin)&0x01; // u4com0 = (g_testCollDa.collDa[i][_comMsg[U4_ID][0].comPort] >>_comMsg[U4_ID][0].comPin)&0x01; // u4com1 = (g_testCollDa.collDa[i][_comMsg[U4_ID][1].comPort] >>_comMsg[U4_ID][1].comPin)&0x01; // u5com0 = (g_testCollDa.collDa[i][_comMsg[U5_ID][0].comPort] >>_comMsg[U5_ID][0].comPin)&0x01; // u5com1 = (g_testCollDa.collDa[i][_comMsg[U5_ID][1].comPort] >>_comMsg[U5_ID][1].comPin)&0x01; //printf("%d,%d,%d,%d,%d,%d\n",u1com0,u1com1,u4com0,u4com1,u5com0,u5com1); for(j=0;j<3;j++){ for(k=0;k<2;k++){ flag = (0x01<<(j*2+k)); u1com0 = (g_testCollDa.collDa[i][_comMsg[U1_ID+j][k].comPort] >>_comMsg[U1_ID+j][k].comPin)&0x01; if((u1com0 == 0x00) && (g_comSrcDa.daMsg[U1_ID+j][k].lastvl==0)&&((g_comSrcDa.flag&flag) !=flag)){ num = g_comSrcDa.daMsg[U1_ID+j][k].num; memcpy(&g_comSrcDa.daMsg[U1_ID+j][k].tda[num][0],(char*)&g_testCollDa.collDa[i][0],TEST_COLL_GROUP); g_comSrcDa.daMsg[U1_ID+j][k].num++; } else { g_comSrcDa.daMsg[U1_ID+j][k].num = 0; } g_comSrcDa.daMsg[U1_ID+j][k].lastvl= u1com0; if((g_comSrcDa.daMsg[U1_ID+j][k].num>5)&&((g_comSrcDa.flag&flag) !=flag)){ g_comSrcDa.flag |= flag; g_comSrcDa.daMsg[U1_ID+j][k].num = 0; //valpos = (i - g_comSrcDa.daMsg[U1_ID+j][k].startpos)/2; memcpy(&g_comSrcDa.daMsg[U1_ID+j][k].da[0],&g_comSrcDa.daMsg[U1_ID+j][k].tda[3][0],TEST_COLL_GROUP); //break; } //printf("j=%d,k=%d,num = %d,flag = %02x\n",j,k,g_comSrcDa.daMsg[U1_ID+j][k].num,g_comSrcDa.flag); } if(g_comSrcDa.flag == 0x3F){ break; } } dealnum++; if(g_comSrcDa.flag == 0x3F){ g_comSrcDa.flag = 0; samecount = 4; break; } } if(samecount >=3) { // printf("ccccccccccccc\n"); if(i == (dealIndex)) curIndex = i-1; else curIndex = i; memset((char*)g_timeInfo.srcDa,0,sizeof(g_timeInfo.srcDa)); for(mm=0;mm<128;mm++){ uid = g_neTable[mm].uId; // u1 u4 或 u5 cId = g_neTable[mm].comIndex; // com0 还是com1 csId = g_neTable[mm].csIndex; // pid = g_neTable[mm].pinIndex; if(csId ==0xFF || pid == 0xFF) continue; comval = (g_comSrcDa.daMsg[uid][cId].da[_comMsg[uid][cId].comPort]>> _comMsg[uid][cId].comPin)&0x01; bitval = (g_comSrcDa.daMsg[uid][cId].da[csId]>>pid)&0x01; if(comval != bitval) g_timeInfo.srcDa[mm/8+1] |= (0x01<<(7-mm%8)); } samecount = 0; g_testCollDa.dealNum = i; anay_7eg(); } else { curIndex = i-1;// dealIndex-1; g_testCollDa.dealNum = i;//dealIndex; } if((g_testCollDa.bdealDa == 0x01)&& (dealnum ==(TEST_COLL_DA_MAX_NUM))) { memcpy(g_testCollDa.sendCollNum,g_testCollDa.tcollNum,192); memset(g_testCollDa.tcollNum,0,192); g_testCollDa.bdealDa = 0; dealnum = 1; curIndex = 0; g_testCollDa.dealNum = 0; //printf("test flag %d\n",testflag); testflag = 0; samecount = 0; } }