xspDataOpt.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. #include "xspDataOpt.h"
  2. #include "../Hardware/boardinit.h"
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "public.h"
  6. GunStatus g_gunStatus[4]; // 抬枪信号的状态
  7. static uint8_t g_srcDa[4][12]; // 读取的原始数据,每个port最多96位数据
  8. uint8_t g_7egDa[29] = {0};
  9. char table_7eg[16][8] = {
  10. /*{61 ,56 ,57 ,11 ,12 ,14 ,13 ,8 },
  11. {9 ,10 ,69 ,64 ,65 ,19 ,20 ,22 },
  12. {21 ,16 ,17 ,18 ,77 ,72 ,73 ,27 },
  13. {28 ,30 ,29 ,24 ,25 ,26 ,85 ,80 },
  14. {31 ,81 ,35 ,36 ,38 ,37 ,32 ,33 },
  15. {34 ,93 ,88 ,39 ,44 ,46 ,45 ,40 },
  16. {41 ,42 ,43 ,89 ,47 ,52 ,53 ,48 },
  17. {49 ,54 ,50 ,51 ,101,0 ,0 ,255},
  18. {62 ,60 ,59 ,58 ,70 ,68 ,67 ,66 },
  19. {78 ,76 ,75 ,104,109,110,108,107},
  20. {106,105,74 ,111,79 ,116,115,114},
  21. {119,124,123,122,127,132,131,130},
  22. {134,129,128,133,121,120,125,126},
  23. {118,113,112,117,86 ,84 ,83 ,82 },
  24. {87 ,92 ,91 ,90 ,95 ,94 ,100,99 },
  25. {98 ,102,97 ,96 ,255,255,255,255},*/
  26. {0 ,1 ,61 ,56 ,57 ,11 ,12 ,14 },
  27. {13 ,8 ,9 ,10 ,69 ,64 ,65 ,19 },
  28. {20 ,22 ,21 ,16 ,17 ,18 ,77 ,72 },
  29. {73 ,27 ,28 ,30 ,29 ,24 ,25 ,26 },
  30. {85 ,80 ,1 ,81 ,35 ,36 ,38 ,37 },
  31. {32 ,33 ,34 ,93 ,88 ,39 ,44 ,46 },
  32. {45 ,40 ,41 ,42 ,43 ,89 ,2 ,52 },
  33. {53 ,48 ,49 ,54 ,50 ,51 ,101,1 },
  34. {94 ,100,99 ,98 ,102,97 ,96 ,1 },
  35. {84 ,83 ,82 ,87 ,92 ,91 ,90 ,7 },
  36. {120,125,126,118,113,112,117,86 },
  37. {132,131,130,134,129,128,133,121},
  38. {116,115,114,119,124,123,122,6 },
  39. {110,108,107,106,105,74 ,4 ,5 },
  40. {67 ,66 ,3 ,78 ,76 ,75 ,104,109},
  41. {1 ,1 ,62 ,60 ,59 ,58 ,70 ,68 },
  42. };
  43. const uint8_t g_table[128][2] = {
  44. {0,65},{0,62},{0,63},{0,61},{0,60},{0,50},{0,49},{0,48},{0,65},{0,40},
  45. {0,41},{0,55},{0,54},{0,44},{0,43},{0,42},{0,65},{0,34},{0,35},{0,33},
  46. {0,32},{0,38},{0,37},{0,36},{0,20},{0,29},{0,30},{0,28},{0,27},{0,17},
  47. {0,16},{0,31},{0,65},{0,22},{0,23},{0,21},{0,11},{0,10},{0, 9},{0, 8},
  48. {0,65},{0, 2},{0,15},{0,14},{0, 4},{0, 3},{0, 1},{0, 0},{0,65},{3, 5},
  49. {0,57},{3, 4},{3, 3},{3, 2},{0,59},{0,58},{0,65},{3, 1},{0,51},{3, 0},
  50. {3,15},{3,14},{0,53},{0,52},{0,65},{3,12},{0,45},{3,11},{3,10},{3,18},
  51. {0,47},{0,46},{3,52},{3,40},{0,39},{3,55},{3,54},{3,53},{0,26},{0,24},
  52. {0,65},{3,63},{0,18},{3,51},{3,50},{3,49},{0,12},{0,19},{0,65},{3,59},
  53. {0, 5},{3,62},{3,61},{3,60},{3,58},{3,57},{0,65},{3,23},{3, 8},{3,22},
  54. {3,21},{3,20},{3,19},{3,9 },{3,28},{3,44},{3,41},{3,31},{3,30},{3,29},
  55. {3,43},{3,42},{0,65},{3,45},{3,46},{3,27},{3,26},{3,25},{3,32},{3,47},
  56. {0,65},{3,36},{3,33},{3,39},{3,38},{3,37},{3,35},{3,34},
  57. };
  58. xspoptData g_xspoptDa; // 显示屏的过程数据
  59. XspDataInfo g_xspReDa; // 显示屏的记录数据
  60. Up7segData g_up7segData;
  61. static int8_t check_segCode(uint8_t segcode)
  62. {
  63. int8_t da;
  64. switch(segcode){
  65. case 0x3F: case 0xBF: da = 0; break; //0
  66. case 0x06: case 0x86: da = 1; break; //1
  67. case 0x5B: case 0xDB: da = 2; break; //2
  68. case 0x4F: case 0xCF: da = 3; break; //3
  69. case 0x66: case 0xE6: da = 4; break; //4
  70. case 0x6D: case 0xED: da = 5; break; //5
  71. case 0x7D: case 0xFD: da = 6; break; //6
  72. case 0x07: case 0x87: da = 7; break; //7
  73. case 0x7F: case 0xFF: da = 8; break; //8
  74. case 0x6F: case 0xEF: da = 9; break; //9
  75. case 0x46: da = -1; break;
  76. default: da = -1; break;
  77. }
  78. return da;
  79. }
  80. /*-----------------------------------------------------------------------
  81. * 将映射数据转换为实际的数据
  82. * -----------------------------------------------------------------------*/
  83. #if(0)
  84. static uint32_t get_data_from_7segCode00(uint8_t *segcode, uint8_t len)
  85. {
  86. volatile int i=0;
  87. uint32_t da = 0;
  88. char dastr[11] = {'\0'};
  89. for(i=0;i<len;i++){
  90. if(segcode[i] == 0) dastr[i] = 0x30;
  91. else dastr[i] = check_segCode(segcode[i]) |0x30;
  92. }
  93. da = atol(dastr);
  94. return da;
  95. }
  96. #endif
  97. static void get_data_from_7segCode(uint8_t *segcode, dispData *tempda )
  98. {
  99. volatile uint8_t i,ret = 0,j=0;
  100. int8_t da;
  101. char dastr[11] = {'\0'};
  102. uint32_t value = 0;
  103. for(i=0;i<6;i++){ // 金额
  104. if(segcode[i] == 0x00 ){ da = 0; dastr[i] = 0x30;}// value = ((value<<(i*8))|da);}
  105. else {
  106. da = check_segCode(segcode[i]);
  107. if(da != -1){
  108. dastr[i] = check_segCode(segcode[i]) |0x30;
  109. //value = ((value<<(i*8))|da);
  110. }
  111. else {ret = 1; break;}
  112. }
  113. }
  114. if(ret == 1) goto ERROR_END;
  115. dastr[i] = 0;
  116. tempda->amount = atol(dastr);
  117. value = 0; j = 0;
  118. for(i;i<12;i++,j++) { // 油量
  119. if(segcode[i] == 0x00 ) { da = 0; dastr[i-6] = 0x30;}// value = ((value<<(j*8))|da);}
  120. else {
  121. da = check_segCode(segcode[i]);
  122. if(da != -1){
  123. dastr[i-6] = check_segCode(segcode[i]) |0x30;
  124. //value = ((value<<(j*8))|da);
  125. }
  126. else {ret = 1; break;}
  127. }
  128. }
  129. if(ret == 1) goto ERROR_END;
  130. dastr[i-6] = 0;
  131. tempda->oil = atol(dastr);
  132. value = 0; j = 0;
  133. for(i;i<16;i++,j++){ // 单价
  134. if(segcode[i] == 0x00 ) { da = 0; dastr[i-12] = 0x30;}// value = ((value<<(j*8))|da);}
  135. else {
  136. da = check_segCode(segcode[i]);
  137. if(da != -1){
  138. dastr[i-12] = check_segCode(segcode[i]) |0x30;
  139. //value = ((value<<(j*8))|da);
  140. }
  141. else {ret = 1; break;}
  142. }
  143. }
  144. if(ret == 1) goto ERROR_END;
  145. dastr[i-12] = 0;
  146. tempda->price = atol(dastr);
  147. return;
  148. ERROR_END:
  149. tempda->amount = 0;
  150. tempda->oil = 0;
  151. tempda->price = 0;
  152. return;
  153. }
  154. /*-------------------------------------------------------------------------------
  155. * 保存记录
  156. * -------------------------------------------------------------------------------*/
  157. void save_record_to_flash(uint8_t recordMode)
  158. {
  159. g_xspReDa.reDa.recordId = (g_xspReDa.reDa.recordId+1)%0xFFFFFFFF;
  160. g_xspReDa.reDa.amount = g_xspoptDa.lastDa.amount;
  161. g_xspReDa.reDa.price = g_xspoptDa.lastDa.price;
  162. g_xspReDa.reDa.oil = g_xspoptDa.lastDa.oil;
  163. g_xspReDa.reDa.tamount = g_xspoptDa.lastTamout + g_xspoptDa.lastDa.amount;
  164. g_xspReDa.reDa.toil = g_xspoptDa.lastToil + g_xspoptDa.lastDa.oil;
  165. g_xspReDa.reDa.bsend = 0xFFFF;
  166. g_xspReDa.reDa.recodeMode = recordMode;
  167. g_xspReDa.reDa.timer = rtc_counter_get();// 产生记录的时间
  168. g_xspoptDa.lastTamout = g_xspReDa.reDa.tamount;
  169. g_xspoptDa.lastToil = g_xspReDa.reDa.toil;
  170. write_flash(g_xspReDa.data);
  171. printf("新记录: recordId=%d, amout:%d, oil:%d, tamout:%lld, toil:%lld\r\n",g_xspReDa.reDa.recordId,\
  172. g_xspReDa.reDa.amount,g_xspReDa.reDa.oil,g_xspReDa.reDa.tamount,g_xspReDa.reDa.toil);
  173. }
  174. /*------------------------------------------------------------------------
  175. * 保存屏显示数据到flash,用于安装时,按键驱动
  176. * -----------------------------------------------------------------------*/
  177. void save_display_data_to_flash(void)
  178. {
  179. XspDataInfo xspReDa;
  180. static uint32_t recordId = 0;
  181. memset(xspReDa.data,0,64);
  182. xspReDa.reDa.recordId = (recordId+1)%0xFFFFFFFF;
  183. xspReDa.reDa.amount = g_xspoptDa.curDa.amount;//g_xspoptDa.lastDa.amount;
  184. xspReDa.reDa.price = g_xspoptDa.curDa.price;//g_xspoptDa.lastDa.price;
  185. xspReDa.reDa.oil = g_xspoptDa.curDa.oil;//g_xspoptDa.lastDa.oil;
  186. xspReDa.reDa.tamount = 0;
  187. xspReDa.reDa.toil = 0;
  188. xspReDa.reDa.bsend = 0xFFFF;
  189. xspReDa.reDa.recodeMode = 3;
  190. xspReDa.reDa.timer = rtc_counter_get();// 产生记录的时间
  191. write_flash(xspReDa.data);
  192. printf("按键产生记录: recordId=%d, amout:%d, oil:%d, tamout:%lld, toil:%lld\r\n",xspReDa.reDa.recordId,\
  193. xspReDa.reDa.amount,xspReDa.reDa.oil,xspReDa.reDa.tamount,xspReDa.reDa.toil);
  194. }
  195. /*------------------------------------------------------------------------
  196. * 抬枪信号的处理
  197. * -----------------------------------------------------------------------*/
  198. void init_gun_status(void)
  199. {
  200. uint8_t i;
  201. for(i=0;i<4;i++){
  202. g_gunStatus[i].curst = HIGHT_LEVEL;
  203. g_gunStatus[i].lastst = HIGHT_LEVEL;
  204. g_gunStatus[i].timer = 0;
  205. g_gunStatus[i].bsave = 0;
  206. }
  207. }
  208. void deal_gun_status(uint32_t tick)
  209. {
  210. uint8_t status;
  211. static uint8_t laststatus = 0xFF;
  212. if(g_gunStatus[0].timer == 0 ) g_gunStatus[0].timer = tick;
  213. if(tick - g_gunStatus[0].timer >= GUN_STATUS_TIMER){
  214. status = gpio_input_bit_get(GPIOB,GPIO_PIN_15); // IN4
  215. if(status != laststatus) {
  216. g_gunStatus[0].count = 0;
  217. laststatus = status;
  218. }
  219. else g_gunStatus[0].count++;
  220. g_gunStatus[0].timer = 0;
  221. if(g_gunStatus[0].count >=4){
  222. g_gunStatus[0].curst = (status ==0 ? LOW_LEVEL : HIGHT_LEVEL);
  223. if(g_gunStatus[0].curst != g_gunStatus[0].lastst){
  224. if((g_gunStatus[0].curst == HIGHT_LEVEL) && (g_gunStatus[0].lastst == LOW_LEVEL)){
  225. g_gunStatus[0].bsave = 1;
  226. }
  227. g_gunStatus[0].lastst = g_gunStatus[0].curst;
  228. }
  229. g_gunStatus[0].count = 0;
  230. }
  231. }
  232. }
  233. void check_gun_status_to_save_record(void)
  234. {
  235. uint8_t status;
  236. status = gpio_input_bit_get(GPIOB,GPIO_PIN_15);
  237. if((status == HIGHT_LEVEL) && (g_gunStatus[0].bsave == 1)){ // 已挂枪
  238. save_record_to_flash(0x01);//存储数据
  239. g_xspoptDa.lastDawrite = 1;
  240. g_gunStatus[0].bsave = 0;
  241. printf("抬枪信号产生一笔新的记录\r\n");
  242. }
  243. if(status == HIGHT_LEVEL) g_xspoptDa.bstartAdd =0; // 加油结束,没有在加油过程中
  244. }
  245. /*------------------------------------------------------------------------
  246. * 处理显示屏的记录
  247. * ------------------------------------------------------------------------*/
  248. void processing_display_data(dispData *da)
  249. {
  250. float oil_f;
  251. uint32_t oil_i,count;
  252. int erroil;
  253. static uint8_t bfist = 0;
  254. //static uint8_t bfirst = 0;
  255. if(da->price == 0) return;
  256. oil_f = 0.0;
  257. erroil = 0;
  258. oil_i = 0;count=0;
  259. g_xspoptDa.curDa.price = da->price;
  260. if(da->amount==0 && da->oil==0){ // 新的一笔加油开始,需要把上一笔油存储
  261. if(gpio_input_bit_get(GPIOB,GPIO_PIN_15)==0) { // 低电平,有抬枪信号
  262. g_xspoptDa.bstartAdd = 1; // 加油开始
  263. }
  264. if(g_xspoptDa.lastDawrite == 0){ // 数据只存储一次
  265. if(gpio_input_bit_get(GPIOB,GPIO_PIN_15)==1) // 高电平,没有抬枪信号
  266. save_record_to_flash(0x00);//存储数据
  267. g_xspoptDa.lastDawrite = 1;
  268. }
  269. else {
  270. if(g_xspoptDa.bsame4++ >30){
  271. g_xspoptDa.bsame4 = 0;
  272. printf("--显示屏数据:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  273. }
  274. }
  275. g_xspoptDa.lastDa.amount = 0;
  276. g_xspoptDa.lastDa.oil = 0;
  277. g_xspoptDa.changeCnt = 0;
  278. g_xspoptDa.startDa.amount = 0;
  279. g_xspoptDa.startDa.oil = 0;
  280. g_xspoptDa.curDa.amount = 0;
  281. g_xspoptDa.curDa.oil = 0;
  282. g_xspoptDa.noChangeCnt = 0;
  283. g_xspoptDa.bCheckDa = 0;
  284. }
  285. else {
  286. oil_f = (float)da->amount/(float)da->price;
  287. oil_i = (uint32_t)(oil_f*100);
  288. erroil = da->oil-oil_i;
  289. if((erroil<=2) && (erroil>=-2)){ // 正确交易数据
  290. // printf("数据正确 oil_i = %d\r\n",oil_i);
  291. if(g_xspoptDa.startDa.amount==0 && g_xspoptDa.startDa.oil==0){ // 从屏幕0开始变化的
  292. if((da->oil > g_xspoptDa.curDa.oil) || (da->amount>g_xspoptDa.curDa.amount) ){ // 处于递增的趋势
  293. g_xspoptDa.curDa.amount = da->amount;
  294. g_xspoptDa.curDa.price = da->price;
  295. g_xspoptDa.curDa.oil = da->oil;
  296. g_xspoptDa.gunStatus = 1;
  297. g_xspoptDa.lastDawrite = 0;
  298. g_xspoptDa.changeCnt++;
  299. g_xspoptDa.noChangeCnt = 0;
  300. g_xspoptDa.bCheckDa = 0;
  301. printf("正在加油:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  302. }
  303. else if((da->oil == g_xspoptDa.curDa.oil) && (da->amount == g_xspoptDa.curDa.amount) ) { // 显示屏数据没有变化
  304. g_xspoptDa.noChangeCnt++;
  305. if((g_xspoptDa.noChangeCnt>3 && (g_xspoptDa.changeCnt>1))|| (bfist==0)){
  306. g_xspoptDa.startDa.amount = da->oil;
  307. g_xspoptDa.startDa.oil = da->oil;
  308. g_xspoptDa.noChangeCnt = 0;
  309. g_xspoptDa.bCheckDa = 1;
  310. g_xspoptDa.changeCnt = 0;
  311. g_xspoptDa.lastDa.amount = da->amount;
  312. g_xspoptDa.lastDa.price = da->price;
  313. g_xspoptDa.lastDa.oil = da->oil;
  314. bfist = 1;
  315. g_xspoptDa.lastDawrite = 0;
  316. g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
  317. printf("加油停止:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  318. }
  319. else{
  320. if((g_xspoptDa.bsame4++) >20){
  321. g_xspoptDa.bsame4 = 0;
  322. g_xspoptDa.gunStatus = 0;
  323. printf("未加油:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  324. }
  325. }
  326. }
  327. else { // 显示屏发性变化,
  328. if(g_xspoptDa.bCheckDa == 0) return;
  329. if(g_xspoptDa.bstartAdd == 1) return;
  330. printf("+++++++数据查询%d,%d,%d,%d,\r\n",da->amount,da->oil,g_xspoptDa.curDa.amount,g_xspoptDa.curDa.oil);
  331. g_xspoptDa.curDa.amount = da->amount;
  332. g_xspoptDa.curDa.price = da->price;
  333. g_xspoptDa.curDa.oil = da->oil;
  334. g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
  335. }
  336. }
  337. else{ // 从当前屏幕的数据开始变化的
  338. if((da->oil > g_xspoptDa.curDa.oil) || (da->amount> g_xspoptDa.curDa.amount)){
  339. g_xspoptDa.curDa.amount = da->amount;
  340. g_xspoptDa.curDa.price = da->price;
  341. g_xspoptDa.curDa.oil = da->oil;
  342. g_xspoptDa.changeCnt++;
  343. g_xspoptDa.noChangeCnt = 0;
  344. printf("当前数据的基础上变化 amout = %d,oil=%d,price=%d\r\n",da->amount,da->oil,da->price);
  345. }
  346. else if((da->oil == g_xspoptDa.curDa.oil) && (da->amount == g_xspoptDa.curDa.amount)) {
  347. g_xspoptDa.noChangeCnt++;
  348. count = g_xspoptDa.noChangeCnt;//-g_xspoptDa.lastCnt;
  349. if((count>=3) && (g_xspoptDa.changeCnt>1)){ // 加油时为了凑整
  350. g_xspoptDa.startDa.amount = da->amount;
  351. g_xspoptDa.startDa.oil = da->oil;
  352. g_xspoptDa.lastDawrite = 0;
  353. g_xspoptDa.lastCnt = g_xspoptDa.changeCnt;
  354. g_xspoptDa.changeCnt = 0;
  355. g_xspoptDa.bCheckDa = 1;
  356. g_xspoptDa.noChangeCnt = 0;
  357. g_xspoptDa.lastDa.amount = da->amount;
  358. g_xspoptDa.lastDa.price = da->price;
  359. g_xspoptDa.lastDa.oil = da->oil;
  360. printf("+++加油停止:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  361. }
  362. else {
  363. if((g_xspoptDa.bsame4++) >20){
  364. g_xspoptDa.bsame4 = 0;
  365. g_xspoptDa.gunStatus = 0;
  366. if(g_xspoptDa.changeCnt ==1) g_xspoptDa.changeCnt = 0;
  367. printf("未加油,数据没有变化:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  368. }
  369. }
  370. }
  371. else { // 数据查询,不用记录
  372. if(g_xspoptDa.bstartAdd == 1) return;
  373. if(g_xspoptDa.bCheckDa == 0) return;
  374. if(g_xspoptDa.changeCnt >1) {return;}
  375. g_xspoptDa.changeCnt = 0;
  376. g_xspoptDa.curDa.amount = da->amount;
  377. g_xspoptDa.curDa.price = da->price;
  378. g_xspoptDa.curDa.oil = da->oil;
  379. g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
  380. //g_xspoptDa.bCheckDa = 1;
  381. printf("-------数据查询\r\n");
  382. }
  383. }
  384. }
  385. else { // 错误数据 或非交易数据
  386. printf("数据错误 amount=%d,oil=%d,price=%d, oil_i = %d\r\n",da->amount,da->oil,da->price,oil_i);
  387. }
  388. }
  389. }
  390. /*---------------------------------------------------------------------------------------
  391. * 解析数据,是否为一笔交易,数据中没有单价
  392. * --------------------------------------------------------------------------------------*/
  393. void processing_display_data_no_price(dispData *da)
  394. {
  395. float oil_f;
  396. uint32_t oil_i,count;
  397. int erroil;
  398. static uint8_t bfist = 0;
  399. oil_f = 0.0;
  400. erroil = 0;
  401. oil_i = 0;count=0;
  402. g_xspoptDa.curDa.price = da->price;
  403. if(da->amount==0 && da->oil==0){ // 新的一笔加油开始,需要把上一笔油存储
  404. if(gpio_input_bit_get(GPIOB,GPIO_PIN_15)==0) { // 低电平,有抬枪信号
  405. g_xspoptDa.bstartAdd = 1; // 加油开始
  406. }
  407. if(g_xspoptDa.lastDawrite == 0){ // 数据只存储一次
  408. if(gpio_input_bit_get(GPIOB,GPIO_PIN_15)==1) // 高电平,没有抬枪信号
  409. save_record_to_flash(0x00);//存储数据
  410. g_xspoptDa.lastDawrite = 1;
  411. }
  412. else {
  413. if(g_xspoptDa.bsame4++ >30){
  414. g_xspoptDa.bsame4 = 0;
  415. printf("--显示屏数据:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  416. }
  417. }
  418. g_xspoptDa.lastDa.amount = 0;
  419. g_xspoptDa.lastDa.oil = 0;
  420. g_xspoptDa.changeCnt = 0;
  421. g_xspoptDa.startDa.amount = 0;
  422. g_xspoptDa.startDa.oil = 0;
  423. g_xspoptDa.curDa.amount = 0;
  424. g_xspoptDa.curDa.oil = 0;
  425. g_xspoptDa.noChangeCnt = 0;
  426. g_xspoptDa.bCheckDa = 0;
  427. }
  428. else {
  429. if(g_xspoptDa.startDa.amount==0 && g_xspoptDa.startDa.oil==0){ // 从屏幕0开始变化的
  430. if((da->oil > g_xspoptDa.curDa.oil) || (da->amount>g_xspoptDa.curDa.amount) ){ // 处于递增的趋势
  431. g_xspoptDa.curDa.amount = da->amount;
  432. g_xspoptDa.curDa.price = da->price;
  433. g_xspoptDa.curDa.oil = da->oil;
  434. g_xspoptDa.gunStatus = 1;
  435. g_xspoptDa.lastDawrite = 0;
  436. g_xspoptDa.changeCnt++;
  437. g_xspoptDa.noChangeCnt = 0;
  438. g_xspoptDa.bCheckDa = 0;
  439. printf("正在加油:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  440. }
  441. else if((da->oil == g_xspoptDa.curDa.oil) && (da->amount == g_xspoptDa.curDa.amount) ) { // 显示屏数据没有变化
  442. g_xspoptDa.noChangeCnt++;
  443. if((g_xspoptDa.noChangeCnt>3 && (g_xspoptDa.changeCnt>1))|| (bfist==0)){
  444. g_xspoptDa.startDa.amount = da->oil;
  445. g_xspoptDa.startDa.oil = da->oil;
  446. g_xspoptDa.noChangeCnt = 0;
  447. g_xspoptDa.bCheckDa = 1;
  448. g_xspoptDa.changeCnt = 0;
  449. g_xspoptDa.lastDa.amount = da->amount;
  450. g_xspoptDa.lastDa.price = da->price;
  451. g_xspoptDa.lastDa.oil = da->oil;
  452. bfist = 1;
  453. g_xspoptDa.lastDawrite = 0;
  454. g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
  455. printf("加油停止:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  456. }
  457. else{
  458. if((g_xspoptDa.bsame4++) >20){
  459. g_xspoptDa.bsame4 = 0;
  460. g_xspoptDa.gunStatus = 0;
  461. printf("未加油:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  462. }
  463. }
  464. }
  465. else { // 显示屏发性变化,
  466. if(g_xspoptDa.bCheckDa == 0) return;
  467. if(g_xspoptDa.bstartAdd == 1) return;
  468. printf("+++++++数据查询%d,%d,%d,%d,\r\n",da->amount,da->oil,g_xspoptDa.curDa.amount,g_xspoptDa.curDa.oil);
  469. g_xspoptDa.curDa.amount = da->amount;
  470. g_xspoptDa.curDa.price = da->price;
  471. g_xspoptDa.curDa.oil = da->oil;
  472. g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
  473. }
  474. }
  475. else{ // 从当前屏幕的数据开始变化的
  476. if((da->oil > g_xspoptDa.curDa.oil) || (da->amount> g_xspoptDa.curDa.amount)){
  477. g_xspoptDa.curDa.amount = da->amount;
  478. g_xspoptDa.curDa.price = da->price;
  479. g_xspoptDa.curDa.oil = da->oil;
  480. g_xspoptDa.changeCnt++;
  481. g_xspoptDa.noChangeCnt = 0;
  482. printf("当前数据的基础上变化 amout = %d,oil=%d,price=%d\r\n",da->amount,da->oil,da->price);
  483. }
  484. else if((da->oil == g_xspoptDa.curDa.oil) && (da->amount == g_xspoptDa.curDa.amount)) {
  485. g_xspoptDa.noChangeCnt++;
  486. count = g_xspoptDa.noChangeCnt;//-g_xspoptDa.lastCnt;
  487. if((count>=3) && (g_xspoptDa.changeCnt>1)){ // 加油时为了凑整
  488. g_xspoptDa.startDa.amount = da->amount;
  489. g_xspoptDa.startDa.oil = da->oil;
  490. g_xspoptDa.lastDawrite = 0;
  491. g_xspoptDa.lastCnt = g_xspoptDa.changeCnt;
  492. g_xspoptDa.changeCnt = 0;
  493. g_xspoptDa.bCheckDa = 1;
  494. g_xspoptDa.noChangeCnt = 0;
  495. g_xspoptDa.lastDa.amount = da->amount;
  496. g_xspoptDa.lastDa.price = da->price;
  497. g_xspoptDa.lastDa.oil = da->oil;
  498. printf("+++加油停止:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  499. }
  500. else {
  501. if((g_xspoptDa.bsame4++) >20){
  502. g_xspoptDa.bsame4 = 0;
  503. g_xspoptDa.gunStatus = 0;
  504. if(g_xspoptDa.changeCnt ==1) g_xspoptDa.changeCnt = 0;
  505. printf("未加油,数据没有变化:%d,%d,%d\r\n",da->amount,da->oil,da->price);
  506. }
  507. }
  508. }
  509. else { // 数据查询,不用记录
  510. if(g_xspoptDa.bstartAdd == 1) return;
  511. if(g_xspoptDa.bCheckDa == 0) return;
  512. if(g_xspoptDa.changeCnt >1) {return;}
  513. g_xspoptDa.changeCnt = 0;
  514. g_xspoptDa.curDa.amount = da->amount;
  515. g_xspoptDa.curDa.price = da->price;
  516. g_xspoptDa.curDa.oil = da->oil;
  517. g_xspoptDa.lastCnt = g_xspoptDa.lastCnt;
  518. //g_xspoptDa.bCheckDa = 1;
  519. printf("-------数据查询\r\n");
  520. }
  521. }
  522. }
  523. }
  524. /*---------------------------------------------------------------
  525. * 将原始数据解析成对应金额 测量 以及单价的16个字节(664)
  526. * ---------------------------------------------------------------*/
  527. void analysis_srcdata_seg(void)
  528. {
  529. uint16_t i = 0;
  530. uint8_t port,index;
  531. uint8_t srcIndex,indexid;
  532. memset(g_7egDa,0,sizeof(g_7egDa));
  533. for(i=0;i<g_table1027.groupNum;i++){
  534. //port = g_table[i][0];
  535. //index = g_table[i][1]; //位
  536. port = g_table1027.table[i][0];
  537. index = g_table1027.table[i][1]; //位
  538. if(index == 65) continue;
  539. srcIndex = index/8;
  540. indexid = index%8;
  541. g_7egDa[i/8+1] |= (((g_srcDa[port][7-srcIndex]>>indexid)&0x01)<<(7-(i%8)));
  542. }
  543. // for(i=0;i<17;i++) printf("0x%02x,",g_7egDa[i]);
  544. // printf("\r\n");
  545. }
  546. /*-------------------------------------------------------------------------
  547. * 读取74HC165的原始数据
  548. * ------------------------------------------------------------------------*/
  549. void read_74HC1165_data(void)
  550. {
  551. uint8_t i,j;
  552. memset(g_srcDa,0,sizeof(g_srcDa));
  553. #if (0)
  554. for(j=0;j<4;j++){
  555. //reset_port_pin(PLN,j);
  556. //delay_ms(1);
  557. //set_port_pin(PLN,j);
  558. reset_port_pin(CEN,j);
  559. for(i=0;i<g_portMsg[j].num;i++){
  560. g_srcDa[j][i/8] <<= 1;
  561. if(1 == read_daout_pin(j)){
  562. g_srcDa[j][i/8] |= 0x01;
  563. }
  564. reset_port_pin(CLK,j);
  565. delay_ms(1);
  566. set_port_pin(CLK,j);
  567. }
  568. reset_port_pin(CLK,j);
  569. set_port_pin(CEN,j);
  570. }
  571. #else
  572. reset_port_all_pin(CEN,PORT_ALL);
  573. for(i=0;i<PORT_MAX_NUM;i++){
  574. for(j=0;j<4;j++){
  575. g_srcDa[j][i/8] <<= 1;
  576. if(1 == read_daout_pin(j)){
  577. g_srcDa[j][i/8] |= 0x01;
  578. }
  579. }
  580. reset_port_all_pin(CLK,PORT_ALL);
  581. delay_us(10);
  582. set_port_all_pin(CLK,PORT_ALL);
  583. delay_us(10);
  584. }
  585. set_port_all_pin(CLK,PORT_ALL);
  586. set_port_all_pin(CEN,PORT_ALL);
  587. #endif
  588. // for(j=0;j<4;j++){
  589. // printf("port_%02d:",j);
  590. // for(i=0;i<11;i++){
  591. // printf("%02x ",g_srcDa[j][i]);
  592. // }
  593. // printf(" ");
  594. // }
  595. // printf("\r\n");
  596. analysis_srcdata_seg();
  597. }
  598. void anay_7eg(void)
  599. {
  600. //uint8_t i;//,j;
  601. // uint8_t index,bindex,pos;
  602. dispData tempda;
  603. #if SEL_74CH165
  604. read_74HC1165_data();
  605. #else
  606. for(i=0;i<16;i++){
  607. for(j=0;j<8;j++){
  608. pos = table_7eg[i][j];
  609. index = pos/8;
  610. bindex = pos%8;
  611. g_7egDa[index] |= (((g_timeInfo.srcDa[i]>>j)&0x01)<<bindex);
  612. }
  613. }
  614. #endif
  615. memset(&tempda,0,sizeof(dispData));
  616. get_data_from_7segCode(&g_7egDa[1],&tempda);
  617. // for(i=0;i<17;i++){
  618. // printf("%02x,",g_7egDa[i]);
  619. // g_7egDa[i] = 0x00;
  620. // }
  621. check_gun_status_to_save_record();
  622. processing_display_data(&tempda);
  623. // processing_display_data_no_price(&tempda);
  624. // memset(g_7egDa,0,sizeof(g_7egDa));
  625. }