| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654 |
- #include "xspDataOpt.h"
- #include "../Hardware/boardinit.h"
- #include <stdlib.h>
- #include <string.h>
- #include "public.h"
- GunStatus g_gunStatus[4]; // 抬枪信号的状态
- static uint8_t g_srcDa[4][12]; // 读取的原始数据,每个port最多96位数据
- uint8_t g_7egDa[29] = {0};
- char table_7eg[16][8] = {
- /*{61 ,56 ,57 ,11 ,12 ,14 ,13 ,8 },
- {9 ,10 ,69 ,64 ,65 ,19 ,20 ,22 },
- {21 ,16 ,17 ,18 ,77 ,72 ,73 ,27 },
- {28 ,30 ,29 ,24 ,25 ,26 ,85 ,80 },
- {31 ,81 ,35 ,36 ,38 ,37 ,32 ,33 },
- {34 ,93 ,88 ,39 ,44 ,46 ,45 ,40 },
- {41 ,42 ,43 ,89 ,47 ,52 ,53 ,48 },
- {49 ,54 ,50 ,51 ,101,0 ,0 ,255},
- {62 ,60 ,59 ,58 ,70 ,68 ,67 ,66 },
- {78 ,76 ,75 ,104,109,110,108,107},
- {106,105,74 ,111,79 ,116,115,114},
- {119,124,123,122,127,132,131,130},
- {134,129,128,133,121,120,125,126},
- {118,113,112,117,86 ,84 ,83 ,82 },
- {87 ,92 ,91 ,90 ,95 ,94 ,100,99 },
- {98 ,102,97 ,96 ,255,255,255,255},*/
- {0 ,1 ,61 ,56 ,57 ,11 ,12 ,14 },
- {13 ,8 ,9 ,10 ,69 ,64 ,65 ,19 },
- {20 ,22 ,21 ,16 ,17 ,18 ,77 ,72 },
- {73 ,27 ,28 ,30 ,29 ,24 ,25 ,26 },
- {85 ,80 ,1 ,81 ,35 ,36 ,38 ,37 },
- {32 ,33 ,34 ,93 ,88 ,39 ,44 ,46 },
- {45 ,40 ,41 ,42 ,43 ,89 ,2 ,52 },
- {53 ,48 ,49 ,54 ,50 ,51 ,101,1 },
- {94 ,100,99 ,98 ,102,97 ,96 ,1 },
- {84 ,83 ,82 ,87 ,92 ,91 ,90 ,7 },
- {120,125,126,118,113,112,117,86 },
- {132,131,130,134,129,128,133,121},
- {116,115,114,119,124,123,122,6 },
- {110,108,107,106,105,74 ,4 ,5 },
- {67 ,66 ,3 ,78 ,76 ,75 ,104,109},
- {1 ,1 ,62 ,60 ,59 ,58 ,70 ,68 },
- };
- const uint8_t g_table[128][2] = {
- {0,65},{0,62},{0,63},{0,61},{0,60},{0,50},{0,49},{0,48},{0,65},{0,40},
- {0,41},{0,55},{0,54},{0,44},{0,43},{0,42},{0,65},{0,34},{0,35},{0,33},
- {0,32},{0,38},{0,37},{0,36},{0,20},{0,29},{0,30},{0,28},{0,27},{0,17},
- {0,16},{0,31},{0,65},{0,22},{0,23},{0,21},{0,11},{0,10},{0, 9},{0, 8},
- {0,65},{0, 2},{0,15},{0,14},{0, 4},{0, 3},{0, 1},{0, 0},{0,65},{3, 5},
- {0,57},{3, 4},{3, 3},{3, 2},{0,59},{0,58},{0,65},{3, 1},{0,51},{3, 0},
- {3,15},{3,14},{0,53},{0,52},{0,65},{3,12},{0,45},{3,11},{3,10},{3,18},
- {0,47},{0,46},{3,52},{3,40},{0,39},{3,55},{3,54},{3,53},{0,26},{0,24},
- {0,65},{3,63},{0,18},{3,51},{3,50},{3,49},{0,12},{0,19},{0,65},{3,59},
- {0, 5},{3,62},{3,61},{3,60},{3,58},{3,57},{0,65},{3,23},{3, 8},{3,22},
- {3,21},{3,20},{3,19},{3,9 },{3,28},{3,44},{3,41},{3,31},{3,30},{3,29},
- {3,43},{3,42},{0,65},{3,45},{3,46},{3,27},{3,26},{3,25},{3,32},{3,47},
- {0,65},{3,36},{3,33},{3,39},{3,38},{3,37},{3,35},{3,34},
- };
- xspoptData g_xspoptDa; // 显示屏的过程数据
- XspDataInfo g_xspReDa; // 显示屏的记录数据
- Up7segData g_up7segData;
- static int8_t check_segCode(uint8_t segcode)
- {
- int8_t da;
- switch(segcode){
- case 0x3F: case 0xBF: da = 0; break; //0
- case 0x06: case 0x86: da = 1; break; //1
- case 0x5B: case 0xDB: da = 2; break; //2
- case 0x4F: case 0xCF: da = 3; break; //3
- case 0x66: case 0xE6: da = 4; break; //4
- case 0x6D: case 0xED: da = 5; break; //5
- case 0x7D: case 0xFD: da = 6; break; //6
- case 0x07: case 0x87: da = 7; break; //7
- case 0x7F: case 0xFF: da = 8; break; //8
- case 0x6F: case 0xEF: da = 9; break; //9
- case 0x46: da = -1; break;
- default: da = -1; break;
- }
- return da;
- }
- /*-----------------------------------------------------------------------
- * 将映射数据转换为实际的数据
- * -----------------------------------------------------------------------*/
- #if(0)
- static uint32_t get_data_from_7segCode00(uint8_t *segcode, uint8_t len)
- {
- volatile int i=0;
- uint32_t da = 0;
- char dastr[11] = {'\0'};
- for(i=0;i<len;i++){
- if(segcode[i] == 0) dastr[i] = 0x30;
- else dastr[i] = check_segCode(segcode[i]) |0x30;
- }
- da = atol(dastr);
- return da;
- }
- #endif
- static void get_data_from_7segCode(uint8_t *segcode, dispData *tempda )
- {
- volatile uint8_t i,ret = 0,j=0;
- int8_t da;
- char dastr[11] = {'\0'};
- uint32_t value = 0;
- for(i=0;i<6;i++){ // 金额
- if(segcode[i] == 0x00 ){ da = 0; dastr[i] = 0x30;}// value = ((value<<(i*8))|da);}
- else {
- da = check_segCode(segcode[i]);
- if(da != -1){
- dastr[i] = check_segCode(segcode[i]) |0x30;
- //value = ((value<<(i*8))|da);
- }
- else {ret = 1; break;}
- }
- }
- if(ret == 1) goto ERROR_END;
- dastr[i] = 0;
- tempda->amount = atol(dastr);
- value = 0; j = 0;
- for(i;i<12;i++,j++) { // 油量
- if(segcode[i] == 0x00 ) { da = 0; dastr[i-6] = 0x30;}// value = ((value<<(j*8))|da);}
- else {
- da = check_segCode(segcode[i]);
- if(da != -1){
- dastr[i-6] = check_segCode(segcode[i]) |0x30;
- //value = ((value<<(j*8))|da);
- }
- else {ret = 1; break;}
- }
- }
- if(ret == 1) goto ERROR_END;
- dastr[i-6] = 0;
- tempda->oil = atol(dastr);
- value = 0; j = 0;
- for(i;i<16;i++,j++){ // 单价
- if(segcode[i] == 0x00 ) { da = 0; dastr[i-12] = 0x30;}// value = ((value<<(j*8))|da);}
- else {
- da = check_segCode(segcode[i]);
- if(da != -1){
- dastr[i-12] = check_segCode(segcode[i]) |0x30;
- //value = ((value<<(j*8))|da);
- }
- else {ret = 1; break;}
- }
- }
- if(ret == 1) goto ERROR_END;
- dastr[i-12] = 0;
- tempda->price = atol(dastr);
- return;
- ERROR_END:
- tempda->amount = 0;
- tempda->oil = 0;
- tempda->price = 0;
- return;
- }
- /*-------------------------------------------------------------------------------
- * 保存记录
- * -------------------------------------------------------------------------------*/
- void save_record_to_flash(uint8_t recordMode)
- {
- g_xspReDa.reDa.recordId = (g_xspReDa.reDa.recordId+1)%0xFFFFFFFF;
- g_xspReDa.reDa.amount = g_xspoptDa.lastDa.amount;
- g_xspReDa.reDa.price = g_xspoptDa.lastDa.price;
- g_xspReDa.reDa.oil = g_xspoptDa.lastDa.oil;
- g_xspReDa.reDa.tamount = g_xspoptDa.lastTamout + g_xspoptDa.lastDa.amount;
- g_xspReDa.reDa.toil = g_xspoptDa.lastToil + g_xspoptDa.lastDa.oil;
- g_xspReDa.reDa.bsend = 0xFFFF;
- g_xspReDa.reDa.recodeMode = recordMode;
- g_xspReDa.reDa.timer = rtc_counter_get();// 产生记录的时间
- g_xspoptDa.lastTamout = g_xspReDa.reDa.tamount;
- g_xspoptDa.lastToil = g_xspReDa.reDa.toil;
- 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);
- }
- /*------------------------------------------------------------------------
- * 保存屏显示数据到flash,用于安装时,按键驱动
- * -----------------------------------------------------------------------*/
- void save_display_data_to_flash(void)
- {
- XspDataInfo xspReDa;
- static uint32_t recordId = 0;
- memset(xspReDa.data,0,64);
- xspReDa.reDa.recordId = (recordId+1)%0xFFFFFFFF;
- xspReDa.reDa.amount = g_xspoptDa.curDa.amount;//g_xspoptDa.lastDa.amount;
- xspReDa.reDa.price = g_xspoptDa.curDa.price;//g_xspoptDa.lastDa.price;
- xspReDa.reDa.oil = g_xspoptDa.curDa.oil;//g_xspoptDa.lastDa.oil;
- xspReDa.reDa.tamount = 0;
- xspReDa.reDa.toil = 0;
- xspReDa.reDa.bsend = 0xFFFF;
- xspReDa.reDa.recodeMode = 3;
- xspReDa.reDa.timer = rtc_counter_get();// 产生记录的时间
- write_flash(xspReDa.data);
- printf("按键产生记录: recordId=%d, amout:%d, oil:%d, tamout:%lld, toil:%lld\r\n",xspReDa.reDa.recordId,\
- xspReDa.reDa.amount,xspReDa.reDa.oil,xspReDa.reDa.tamount,xspReDa.reDa.toil);
- }
- /*------------------------------------------------------------------------
- * 抬枪信号的处理
- * -----------------------------------------------------------------------*/
- 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;
- }
- }
- void deal_gun_status(uint32_t tick)
- {
- uint8_t status;
- static uint8_t laststatus = 0xFF;
- if(g_gunStatus[0].timer == 0 ) g_gunStatus[0].timer = tick;
- if(tick - g_gunStatus[0].timer >= GUN_STATUS_TIMER){
- status = gpio_input_bit_get(GPIOB,GPIO_PIN_15); // IN4
- if(status != laststatus) {
- g_gunStatus[0].count = 0;
- laststatus = status;
- }
- else g_gunStatus[0].count++;
- g_gunStatus[0].timer = 0;
- if(g_gunStatus[0].count >=4){
- g_gunStatus[0].curst = (status ==0 ? LOW_LEVEL : HIGHT_LEVEL);
- if(g_gunStatus[0].curst != g_gunStatus[0].lastst){
- if((g_gunStatus[0].curst == HIGHT_LEVEL) && (g_gunStatus[0].lastst == LOW_LEVEL)){
- g_gunStatus[0].bsave = 1;
- }
- g_gunStatus[0].lastst = g_gunStatus[0].curst;
- }
- g_gunStatus[0].count = 0;
- }
- }
- }
- void check_gun_status_to_save_record(void)
- {
- uint8_t status;
- status = gpio_input_bit_get(GPIOB,GPIO_PIN_15);
- if((status == HIGHT_LEVEL) && (g_gunStatus[0].bsave == 1)){ // 已挂枪
- save_record_to_flash(0x01);//存储数据
- g_xspoptDa.lastDawrite = 1;
- g_gunStatus[0].bsave = 0;
- printf("抬枪信号产生一笔新的记录\r\n");
- }
- if(status == HIGHT_LEVEL) g_xspoptDa.bstartAdd =0; // 加油结束,没有在加油过程中
- }
- /*------------------------------------------------------------------------
- * 处理显示屏的记录
- * ------------------------------------------------------------------------*/
- void processing_display_data(dispData *da)
- {
- float oil_f;
- uint32_t oil_i,count;
- int erroil;
- static uint8_t bfist = 0;
- //static uint8_t bfirst = 0;
- if(da->price == 0) return;
- oil_f = 0.0;
- erroil = 0;
- oil_i = 0;count=0;
- g_xspoptDa.curDa.price = da->price;
- if(da->amount==0 && da->oil==0){ // 新的一笔加油开始,需要把上一笔油存储
- if(gpio_input_bit_get(GPIOB,GPIO_PIN_15)==0) { // 低电平,有抬枪信号
- g_xspoptDa.bstartAdd = 1; // 加油开始
- }
- if(g_xspoptDa.lastDawrite == 0){ // 数据只存储一次
- if(gpio_input_bit_get(GPIOB,GPIO_PIN_15)==1) // 高电平,没有抬枪信号
- save_record_to_flash(0x00);//存储数据
- g_xspoptDa.lastDawrite = 1;
- }
- else {
- if(g_xspoptDa.bsame4++ >30){
- g_xspoptDa.bsame4 = 0;
- printf("--显示屏数据:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- }
- g_xspoptDa.lastDa.amount = 0;
- g_xspoptDa.lastDa.oil = 0;
- g_xspoptDa.changeCnt = 0;
- g_xspoptDa.startDa.amount = 0;
- g_xspoptDa.startDa.oil = 0;
- g_xspoptDa.curDa.amount = 0;
- g_xspoptDa.curDa.oil = 0;
- g_xspoptDa.noChangeCnt = 0;
- g_xspoptDa.bCheckDa = 0;
- }
- else {
- oil_f = (float)da->amount/(float)da->price;
- oil_i = (uint32_t)(oil_f*100);
- erroil = da->oil-oil_i;
- if((erroil<=2) && (erroil>=-2)){ // 正确交易数据
- // printf("数据正确 oil_i = %d\r\n",oil_i);
- if(g_xspoptDa.startDa.amount==0 && g_xspoptDa.startDa.oil==0){ // 从屏幕0开始变化的
- if((da->oil > g_xspoptDa.curDa.oil) || (da->amount>g_xspoptDa.curDa.amount) ){ // 处于递增的趋势
- g_xspoptDa.curDa.amount = da->amount;
- g_xspoptDa.curDa.price = da->price;
- g_xspoptDa.curDa.oil = da->oil;
- g_xspoptDa.gunStatus = 1;
- g_xspoptDa.lastDawrite = 0;
- g_xspoptDa.changeCnt++;
- g_xspoptDa.noChangeCnt = 0;
- g_xspoptDa.bCheckDa = 0;
- printf("正在加油:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- else if((da->oil == g_xspoptDa.curDa.oil) && (da->amount == g_xspoptDa.curDa.amount) ) { // 显示屏数据没有变化
- g_xspoptDa.noChangeCnt++;
- if((g_xspoptDa.noChangeCnt>3 && (g_xspoptDa.changeCnt>1))|| (bfist==0)){
- g_xspoptDa.startDa.amount = da->oil;
- g_xspoptDa.startDa.oil = da->oil;
- g_xspoptDa.noChangeCnt = 0;
- g_xspoptDa.bCheckDa = 1;
- g_xspoptDa.changeCnt = 0;
- g_xspoptDa.lastDa.amount = da->amount;
- g_xspoptDa.lastDa.price = da->price;
- g_xspoptDa.lastDa.oil = da->oil;
- bfist = 1;
- g_xspoptDa.lastDawrite = 0;
- g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
- printf("加油停止:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- else{
- if((g_xspoptDa.bsame4++) >20){
- g_xspoptDa.bsame4 = 0;
- g_xspoptDa.gunStatus = 0;
- printf("未加油:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- }
- }
- else { // 显示屏发性变化,
- if(g_xspoptDa.bCheckDa == 0) return;
- if(g_xspoptDa.bstartAdd == 1) return;
- printf("+++++++数据查询%d,%d,%d,%d,\r\n",da->amount,da->oil,g_xspoptDa.curDa.amount,g_xspoptDa.curDa.oil);
- g_xspoptDa.curDa.amount = da->amount;
- g_xspoptDa.curDa.price = da->price;
- g_xspoptDa.curDa.oil = da->oil;
- g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
- }
- }
- else{ // 从当前屏幕的数据开始变化的
- if((da->oil > g_xspoptDa.curDa.oil) || (da->amount> g_xspoptDa.curDa.amount)){
- g_xspoptDa.curDa.amount = da->amount;
- g_xspoptDa.curDa.price = da->price;
- g_xspoptDa.curDa.oil = da->oil;
- g_xspoptDa.changeCnt++;
- g_xspoptDa.noChangeCnt = 0;
- printf("当前数据的基础上变化 amout = %d,oil=%d,price=%d\r\n",da->amount,da->oil,da->price);
- }
- else if((da->oil == g_xspoptDa.curDa.oil) && (da->amount == g_xspoptDa.curDa.amount)) {
- g_xspoptDa.noChangeCnt++;
- count = g_xspoptDa.noChangeCnt;//-g_xspoptDa.lastCnt;
- if((count>=3) && (g_xspoptDa.changeCnt>1)){ // 加油时为了凑整
- g_xspoptDa.startDa.amount = da->amount;
- g_xspoptDa.startDa.oil = da->oil;
- g_xspoptDa.lastDawrite = 0;
- g_xspoptDa.lastCnt = g_xspoptDa.changeCnt;
- g_xspoptDa.changeCnt = 0;
- g_xspoptDa.bCheckDa = 1;
- g_xspoptDa.noChangeCnt = 0;
- g_xspoptDa.lastDa.amount = da->amount;
- g_xspoptDa.lastDa.price = da->price;
- g_xspoptDa.lastDa.oil = da->oil;
- printf("+++加油停止:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- else {
- if((g_xspoptDa.bsame4++) >20){
- g_xspoptDa.bsame4 = 0;
- g_xspoptDa.gunStatus = 0;
- if(g_xspoptDa.changeCnt ==1) g_xspoptDa.changeCnt = 0;
- printf("未加油,数据没有变化:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- }
- }
- else { // 数据查询,不用记录
- if(g_xspoptDa.bstartAdd == 1) return;
- if(g_xspoptDa.bCheckDa == 0) return;
- if(g_xspoptDa.changeCnt >1) {return;}
- g_xspoptDa.changeCnt = 0;
- g_xspoptDa.curDa.amount = da->amount;
- g_xspoptDa.curDa.price = da->price;
- g_xspoptDa.curDa.oil = da->oil;
- g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
- //g_xspoptDa.bCheckDa = 1;
- printf("-------数据查询\r\n");
- }
- }
- }
- else { // 错误数据 或非交易数据
- printf("数据错误 amount=%d,oil=%d,price=%d, oil_i = %d\r\n",da->amount,da->oil,da->price,oil_i);
- }
- }
- }
- /*---------------------------------------------------------------------------------------
- * 解析数据,是否为一笔交易,数据中没有单价
- * --------------------------------------------------------------------------------------*/
- void processing_display_data_no_price(dispData *da)
- {
- float oil_f;
- uint32_t oil_i,count;
- int erroil;
- static uint8_t bfist = 0;
- oil_f = 0.0;
- erroil = 0;
- oil_i = 0;count=0;
- g_xspoptDa.curDa.price = da->price;
- if(da->amount==0 && da->oil==0){ // 新的一笔加油开始,需要把上一笔油存储
- if(gpio_input_bit_get(GPIOB,GPIO_PIN_15)==0) { // 低电平,有抬枪信号
- g_xspoptDa.bstartAdd = 1; // 加油开始
- }
- if(g_xspoptDa.lastDawrite == 0){ // 数据只存储一次
- if(gpio_input_bit_get(GPIOB,GPIO_PIN_15)==1) // 高电平,没有抬枪信号
- save_record_to_flash(0x00);//存储数据
- g_xspoptDa.lastDawrite = 1;
- }
- else {
- if(g_xspoptDa.bsame4++ >30){
- g_xspoptDa.bsame4 = 0;
- printf("--显示屏数据:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- }
- g_xspoptDa.lastDa.amount = 0;
- g_xspoptDa.lastDa.oil = 0;
- g_xspoptDa.changeCnt = 0;
- g_xspoptDa.startDa.amount = 0;
- g_xspoptDa.startDa.oil = 0;
- g_xspoptDa.curDa.amount = 0;
- g_xspoptDa.curDa.oil = 0;
- g_xspoptDa.noChangeCnt = 0;
- g_xspoptDa.bCheckDa = 0;
- }
- else {
- if(g_xspoptDa.startDa.amount==0 && g_xspoptDa.startDa.oil==0){ // 从屏幕0开始变化的
- if((da->oil > g_xspoptDa.curDa.oil) || (da->amount>g_xspoptDa.curDa.amount) ){ // 处于递增的趋势
- g_xspoptDa.curDa.amount = da->amount;
- g_xspoptDa.curDa.price = da->price;
- g_xspoptDa.curDa.oil = da->oil;
- g_xspoptDa.gunStatus = 1;
- g_xspoptDa.lastDawrite = 0;
- g_xspoptDa.changeCnt++;
- g_xspoptDa.noChangeCnt = 0;
- g_xspoptDa.bCheckDa = 0;
- printf("正在加油:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- else if((da->oil == g_xspoptDa.curDa.oil) && (da->amount == g_xspoptDa.curDa.amount) ) { // 显示屏数据没有变化
- g_xspoptDa.noChangeCnt++;
- if((g_xspoptDa.noChangeCnt>3 && (g_xspoptDa.changeCnt>1))|| (bfist==0)){
- g_xspoptDa.startDa.amount = da->oil;
- g_xspoptDa.startDa.oil = da->oil;
- g_xspoptDa.noChangeCnt = 0;
- g_xspoptDa.bCheckDa = 1;
- g_xspoptDa.changeCnt = 0;
- g_xspoptDa.lastDa.amount = da->amount;
- g_xspoptDa.lastDa.price = da->price;
- g_xspoptDa.lastDa.oil = da->oil;
- bfist = 1;
- g_xspoptDa.lastDawrite = 0;
- g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
- printf("加油停止:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- else{
- if((g_xspoptDa.bsame4++) >20){
- g_xspoptDa.bsame4 = 0;
- g_xspoptDa.gunStatus = 0;
- printf("未加油:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- }
- }
- else { // 显示屏发性变化,
- if(g_xspoptDa.bCheckDa == 0) return;
- if(g_xspoptDa.bstartAdd == 1) return;
- printf("+++++++数据查询%d,%d,%d,%d,\r\n",da->amount,da->oil,g_xspoptDa.curDa.amount,g_xspoptDa.curDa.oil);
- g_xspoptDa.curDa.amount = da->amount;
- g_xspoptDa.curDa.price = da->price;
- g_xspoptDa.curDa.oil = da->oil;
- g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
- }
- }
- else{ // 从当前屏幕的数据开始变化的
- if((da->oil > g_xspoptDa.curDa.oil) || (da->amount> g_xspoptDa.curDa.amount)){
- g_xspoptDa.curDa.amount = da->amount;
- g_xspoptDa.curDa.price = da->price;
- g_xspoptDa.curDa.oil = da->oil;
- g_xspoptDa.changeCnt++;
- g_xspoptDa.noChangeCnt = 0;
- printf("当前数据的基础上变化 amout = %d,oil=%d,price=%d\r\n",da->amount,da->oil,da->price);
- }
- else if((da->oil == g_xspoptDa.curDa.oil) && (da->amount == g_xspoptDa.curDa.amount)) {
- g_xspoptDa.noChangeCnt++;
- count = g_xspoptDa.noChangeCnt;//-g_xspoptDa.lastCnt;
- if((count>=3) && (g_xspoptDa.changeCnt>1)){ // 加油时为了凑整
- g_xspoptDa.startDa.amount = da->amount;
- g_xspoptDa.startDa.oil = da->oil;
- g_xspoptDa.lastDawrite = 0;
- g_xspoptDa.lastCnt = g_xspoptDa.changeCnt;
- g_xspoptDa.changeCnt = 0;
- g_xspoptDa.bCheckDa = 1;
- g_xspoptDa.noChangeCnt = 0;
- g_xspoptDa.lastDa.amount = da->amount;
- g_xspoptDa.lastDa.price = da->price;
- g_xspoptDa.lastDa.oil = da->oil;
- printf("+++加油停止:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- else {
- if((g_xspoptDa.bsame4++) >20){
- g_xspoptDa.bsame4 = 0;
- g_xspoptDa.gunStatus = 0;
- if(g_xspoptDa.changeCnt ==1) g_xspoptDa.changeCnt = 0;
- printf("未加油,数据没有变化:%d,%d,%d\r\n",da->amount,da->oil,da->price);
- }
- }
- }
- else { // 数据查询,不用记录
- if(g_xspoptDa.bstartAdd == 1) return;
- if(g_xspoptDa.bCheckDa == 0) return;
- if(g_xspoptDa.changeCnt >1) {return;}
- g_xspoptDa.changeCnt = 0;
- g_xspoptDa.curDa.amount = da->amount;
- g_xspoptDa.curDa.price = da->price;
- g_xspoptDa.curDa.oil = da->oil;
- g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
- //g_xspoptDa.bCheckDa = 1;
- printf("-------数据查询\r\n");
- }
- }
- }
- }
- /*---------------------------------------------------------------
- * 将原始数据解析成对应金额 测量 以及单价的16个字节(664)
- * ---------------------------------------------------------------*/
- void analysis_srcdata_seg(void)
- {
- uint16_t i = 0;
- uint8_t port,index;
- uint8_t srcIndex,indexid;
- memset(g_7egDa,0,sizeof(g_7egDa));
- for(i=0;i<g_table1027.groupNum;i++){
- //port = g_table[i][0];
- //index = g_table[i][1]; //位
- port = g_table1027.table[i][0];
- index = g_table1027.table[i][1]; //位
- if(index == 65) continue;
- srcIndex = index/8;
- indexid = index%8;
- g_7egDa[i/8+1] |= (((g_srcDa[port][7-srcIndex]>>indexid)&0x01)<<(7-(i%8)));
- }
- // for(i=0;i<17;i++) printf("0x%02x,",g_7egDa[i]);
- // printf("\r\n");
- }
- /*-------------------------------------------------------------------------
- * 读取74HC165的原始数据
- * ------------------------------------------------------------------------*/
- void read_74HC1165_data(void)
- {
- uint8_t i,j;
- memset(g_srcDa,0,sizeof(g_srcDa));
- #if (0)
- for(j=0;j<4;j++){
- //reset_port_pin(PLN,j);
- //delay_ms(1);
- //set_port_pin(PLN,j);
- reset_port_pin(CEN,j);
- for(i=0;i<g_portMsg[j].num;i++){
- g_srcDa[j][i/8] <<= 1;
- if(1 == read_daout_pin(j)){
- g_srcDa[j][i/8] |= 0x01;
- }
- reset_port_pin(CLK,j);
- delay_ms(1);
- set_port_pin(CLK,j);
- }
- reset_port_pin(CLK,j);
- set_port_pin(CEN,j);
- }
- #else
- reset_port_all_pin(CEN,PORT_ALL);
- for(i=0;i<PORT_MAX_NUM;i++){
- for(j=0;j<4;j++){
- g_srcDa[j][i/8] <<= 1;
- if(1 == read_daout_pin(j)){
- g_srcDa[j][i/8] |= 0x01;
- }
- }
- reset_port_all_pin(CLK,PORT_ALL);
- delay_us(10);
- set_port_all_pin(CLK,PORT_ALL);
- delay_us(10);
- }
- set_port_all_pin(CLK,PORT_ALL);
- set_port_all_pin(CEN,PORT_ALL);
- #endif
- // for(j=0;j<4;j++){
- // printf("port_%02d:",j);
- // for(i=0;i<11;i++){
- // printf("%02x ",g_srcDa[j][i]);
- // }
- // printf(" ");
- // }
- // printf("\r\n");
- analysis_srcdata_seg();
- }
- void anay_7eg(void)
- {
- //uint8_t i;//,j;
- // uint8_t index,bindex,pos;
- dispData tempda;
- #if SEL_74CH165
- read_74HC1165_data();
- #else
- for(i=0;i<16;i++){
- for(j=0;j<8;j++){
- pos = table_7eg[i][j];
- index = pos/8;
- bindex = pos%8;
- g_7egDa[index] |= (((g_timeInfo.srcDa[i]>>j)&0x01)<<bindex);
- }
- }
- #endif
- memset(&tempda,0,sizeof(dispData));
- get_data_from_7segCode(&g_7egDa[1],&tempda);
- // for(i=0;i<17;i++){
- // printf("%02x,",g_7egDa[i]);
- // g_7egDa[i] = 0x00;
- // }
- check_gun_status_to_save_record();
- processing_display_data(&tempda);
- // processing_display_data_no_price(&tempda);
- // memset(g_7egDa,0,sizeof(g_7egDa));
- }
|