weight.c 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064
  1. #include <rtthread.h>
  2. #include "buffer.h"
  3. #include "button.h"
  4. #include "ring_buffer.h"
  5. #include "flash.h"
  6. #include <stdlib.h>
  7. #include "usart.h"
  8. #include "plan.h"
  9. #include "rtc.h"
  10. #include "weight.h"
  11. #include "ad.h"
  12. #include "display.h"
  13. #include "stm32f1xx_hal.h"
  14. unsigned char isWeight = 0;
  15. static unsigned char WeightConst_RecFlag1 = 0; //正在接收重量标志 0xF0处理完成
  16. static unsigned char WeightConst_RecWeightPoint1 = 0; //接收重量指针
  17. static unsigned char WeightConst_RecWeightData1[250]; //接收重量临时表
  18. static unsigned char WeightConst_Drop=0; //抛弃数据
  19. static unsigned char WeightConst_WeightCount = 0; //重量数
  20. static signed short WeightConst_WeightMax = -32768; //最大重量
  21. static signed short WeightConst_WeightMin = 32767; //最小重量
  22. signed long WeightConst_WeightCurTem = 0; //当前临时重量
  23. unsigned char WeightConst_WeightCurTemZF = 1; //当前临时重量正负,用TMRII
  24. unsigned char WeightConst_WeightWS = 0; //小数位数
  25. unsigned char WeightConst_Weight_ZWS = 0; //整数位数
  26. signed short WeightConst_WeightLast; //上次按键重量 1S一次
  27. signed short WeightConst_WeightCur; //当前重量 1S一次
  28. signed short WeightConst_WeightOK; //OK重量 1S一次
  29. static unsigned char WeightConst_WeightCurCount = 0; //重量计数,用于每15秒取一次重量
  30. static signed short WeightConst_WeightCurTemLast = 0; //上次临时重量
  31. static unsigned short WeightConst_RecWeight_he1 = 0; //校验重量准确性
  32. static unsigned short WeightConst_RecWeight_he2 = 0; //校验重量准确性
  33. static unsigned short WeightConst_RecWeight_he3 = 0; //校验重量准确性
  34. static signed short WeightConst_WeightCur_last1=0;
  35. static signed short WeightConst_WeightCur_last2=0;
  36. static signed short WeightConst_WeightCur_last3=0;
  37. static long WeightConst_WeightSum = 0; //当前重量总和
  38. unsigned char WeightConst_oksum = 0; //符合目标重量数
  39. unsigned char WeightConst_allsum = 0; //总重量值数
  40. static unsigned char WeightConst_uoksum = 0;
  41. static unsigned char WeightConst_foksum = 0;
  42. static unsigned char WeightConst_uallsum = 0;
  43. unsigned char WeightConst_AutoSingleNSecondNum[30][3]; //自动跳转每秒值的数组
  44. unsigned char WeightConst_AutoSingleNSecondPoint = 0; //自动跳转的每秒的当前指针
  45. static unsigned char WeightConst_WeightTargetTpo = 65; //自动跳转的权重阀值固定为65%
  46. static unsigned char WeightConst_autotpo = 0; //自动跳转的权重阀值
  47. union timeweight_t timeweight;
  48. rt_sem_t weight_lock = RT_NULL;
  49. unsigned long mypow(unsigned char x,unsigned char y) {
  50. unsigned long z;
  51. if (y==0) z=1;
  52. else z=x;
  53. for (int i=1; i<y; i++)
  54. z = z*x;
  55. return z;
  56. }
  57. void weight_usart_Init(UART_HandleTypeDef* uartHandle)
  58. {
  59. extern unsigned char WeightConst_TQ;
  60. extern unsigned char iscowweight;
  61. if ((uartHandle->Instance==USART1) ||
  62. (uartHandle->Instance==USART2 && (WeightConst_BLE==1 || WeightConst_BLE==3)))
  63. {
  64. if (WeightConst_TQ==1)
  65. {
  66. uartHandle->Init.BaudRate = 9600;
  67. // uartHandle->Init.StopBits = UART_STOPBITS_2; //停止位1位
  68. }
  69. else if (WeightConst_TQ==7)
  70. {
  71. //RCC_PCLK2Config(RCC_HCLK_Div2);
  72. uartHandle->Init.BaudRate = 600;
  73. }
  74. else if (WeightConst_TQ==4)
  75. uartHandle->Init.BaudRate = 19200;
  76. else if (WeightConst_TQ==8)
  77. uartHandle->Init.BaudRate = 38400;
  78. // else if (WeightConst_TQ==9)
  79. // uartHandle->Init.BaudRate = 1200;
  80. else if (WeightConst_TQ==9)
  81. {
  82. uartHandle->Init.BaudRate = 9600;
  83. uartHandle->Init.Parity = UART_PARITY_NONE;
  84. uartHandle->Init.WordLength = UART_WORDLENGTH_8B; //8位数据
  85. // uartHandle->Init.StopBits = UART_STOPBITS_2; //停止位2位 海丰需要
  86. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  87. }
  88. else if (WeightConst_TQ==10)
  89. {
  90. uartHandle->Init.BaudRate = 9600;
  91. uartHandle->Init.Parity = UART_PARITY_NONE;
  92. uartHandle->Init.WordLength = UART_WORDLENGTH_8B; //8位数据
  93. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  94. }
  95. else
  96. uartHandle->Init.BaudRate = 9600;
  97. if (iscowweight==1 ){
  98. uartHandle->Init.BaudRate = 19200;
  99. uartHandle->Init.Parity = UART_PARITY_NONE;
  100. uartHandle->Init.WordLength = UART_WORDLENGTH_9B; //8位数据
  101. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  102. }
  103. }
  104. // else if ((uartHandle->Instance==USART3) && (iscowweight==1))
  105. // {
  106. // uartHandle->Init.BaudRate = 19200;
  107. // uartHandle->Init.Parity = UART_PARITY_EVEN;
  108. // uartHandle->Init.WordLength = UART_WORDLENGTH_9B; //8位数据
  109. // uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  110. // }
  111. }
  112. static void setWeightSM() { // 设定合计重量
  113. if ((WeightConst_WeightCurTem > (WeightConst_WeightCurTemLast+1000) ||
  114. (WeightConst_WeightCurTem < (WeightConst_WeightCurTemLast - 1000) && WeightConst_WeightCurTem!=32768))
  115. && WeightConst_RecWeight_he3 < 3)
  116. {
  117. WeightConst_WeightCurTem = WeightConst_WeightCurTemLast;
  118. WeightConst_RecWeight_he3 ++;
  119. }
  120. else //if (WeightConst_WeightCurTem>-32768)
  121. {
  122. WeightConst_WeightCurTemLast = WeightConst_WeightCurTem;
  123. WeightConst_RecWeight_he3 = 0;
  124. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  125. if (WeightConst_WeightMax < WeightConst_WeightCurTem) WeightConst_WeightMax = WeightConst_WeightCurTem; //修改最大重量
  126. if (WeightConst_WeightMin > WeightConst_WeightCurTem) WeightConst_WeightMin = WeightConst_WeightCurTem; //修改最小重量
  127. WeightConst_WeightSum = WeightConst_WeightSum + WeightConst_WeightCurTem; // 重量和
  128. WeightConst_WeightCount++; // 重量采样数
  129. WeightConst_allsum++;
  130. rt_sem_release(weight_lock);
  131. //判断是否在范围内
  132. if(pf_comp.data.autosecond>0 && WeightConst_WeightHaveBegin==1) { //跳转时间大于0
  133. if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin &&
  134. WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMax && WeightConst_ChanCheShu>1)
  135. || (WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0 && WeightConst_ChanCheShu==1)) //大目标 为正,且当前值小于大目标
  136. {
  137. if ((WeightConst_SBType==4||WeightConst_SBType==6) && WeightConst_Stop==0 && isn==0) {
  138. rt_event_send(&display_event, EVENT_Stop);
  139. WeightConst_Stop=1;
  140. }
  141. WeightConst_oksum++;
  142. WeightConst_WeightOK=WeightConst_WeightCurTem;
  143. }
  144. //WeightConst_WeightTargetAllow
  145. if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)
  146. ||(WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1))
  147. {
  148. alarm_on();
  149. //----------------------------if (WeightConst_SBType==5) ControlPlay(2, 1);
  150. }
  151. else if ((WeightConst_WeightCurTem < WeightConst_WeightTargetAllowMin && pf_comp.data.addorout == 0)
  152. || (WeightConst_WeightCurTem > WeightConst_WeightTargetAllowMin && pf_comp.data.addorout == 1))
  153. {
  154. //----------------------------if (WeightConst_SBType==5) ControlPlay(2, 0);
  155. alarm_off();
  156. }
  157. }
  158. }
  159. HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin);
  160. }
  161. void sendWeight() {
  162. /* key0 协议 34字节(上报实时重量):0x7E 0x20 0x01 0xF0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 1位起始位 + 1位长度 + 1位源地址 + 1位命令 + 28位重量(四段) + 1帧编号 + 1校验
  163. */
  164. if (rb_full_count(RecWeightQueue) > 28) {
  165. unsigned char buf[34] ;
  166. unsigned char CRCNum=0;
  167. buf[0]= 0x7E;
  168. buf[1]= 0x20;
  169. buf[2]= XbeeConst_DeviceAddress;
  170. buf[3]= 0xF0;
  171. for (int i=0; i <28; i++) buf[i+4]= rb_remove(RecWeightQueue);
  172. buf[32] = XbeeConst_FrameNum ++;
  173. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR3, buf[32]);
  174. for (int i=0; i< 33; i++) CRCNum+=buf[i];
  175. buf[33]= 0xff - CRCNum;
  176. for (int i=0; i <(int)(sizeof(buf)/sizeof(unsigned char)); i++)
  177. rb_push_insert(SendWeightQueue,buf[i]);
  178. }
  179. }
  180. void sendEIDWeight(unsigned char * eidbuf, signed short WeightCur) {
  181. /* key6 协议 34字节(上报电子称重):0x7E 0x0D 0x01 0xF6 0x00 0x00 0x00 0x00 0x00 0x00 0x00 1位起始位 + 1位长度 + 1位源地址 + 1位命令 + 7位耳标 + 2位重量 + 1帧编号 + 1校验
  182. */
  183. unsigned char buf[15] ;
  184. unsigned char CRCNum=0;
  185. if( eidbuf[0] == 5 && WeightCur>20){
  186. buf[0]= 0x7E;
  187. buf[1]= 0x0D;
  188. buf[2]= XbeeConst_DeviceAddress;
  189. buf[3]= 0xF6;
  190. for (int i=0; i <7; i++) buf[i+4]= eidbuf[i+1];
  191. buf[11]= (WeightCur>>8) &0xFF;
  192. buf[12]= WeightCur &0xFF;
  193. buf[13] = XbeeConst_FrameNum ++;
  194. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR3, buf[13]);
  195. for (int i=0; i< 14; i++) CRCNum+=buf[i];
  196. buf[14]= 0xff - CRCNum;
  197. for (int i=0; i <(int)(sizeof(buf)/sizeof(unsigned char)); i++)
  198. rb_push_insert(SendWeightQueue,buf[i]);
  199. }
  200. }
  201. void CheckWeightthread(void) {
  202. while (1) {
  203. if (WeightConst_DELAYON>0) //搅拌延时
  204. {
  205. WeightConst_DELAYTIME ++;
  206. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR5, WeightConst_DELAYTIME);
  207. if (WeightConst_DELAYTIME > (pf_comp.data.delaytime * 60)) //10 &&pf_comp.data.delaytime>0 )
  208. {
  209. write_Flash("begintime", &TimeConst, sizeof(TimeConst));
  210. // WeightConst_WeightBegin = WeightConst_WeightCur;
  211. // write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
  212. pf_comp.data.delaytime = 0;
  213. WeightConst_DELAYTIME = 0;
  214. WeightConst_DELAYON = 0;
  215. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR4, 0);
  216. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR5, 0);
  217. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR6, 0);
  218. rt_sem_release(pop_product_sem);//弹出最新内容
  219. }
  220. }
  221. // else {
  222. // WeightConst_DELAYTIME = 0;
  223. // WeightConst_DELAYON=0;
  224. // }
  225. if ( WeightConst_allsum > 0) {
  226. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  227. if (WeightConst_WeightCount>2) {
  228. WeightConst_WeightSum = WeightConst_WeightSum - WeightConst_WeightMin; // 重量和 减去最小值
  229. WeightConst_WeightSum = WeightConst_WeightSum - WeightConst_WeightMax; // 重量和 减去最大值
  230. WeightConst_WeightCount = WeightConst_WeightCount - 2;
  231. }
  232. WeightConst_WeightCur = WeightConst_WeightSum / WeightConst_WeightCount;
  233. if (WeightConst_WeightCurCount >= 0x0F) { //15秒准备发送后台重
  234. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  235. timeweight.Buffer[3] =TimeConst.Buffer[0];
  236. timeweight.Buffer[4] =TimeConst.Buffer[1];
  237. timeweight.Buffer[5] =TimeConst.Buffer[2];
  238. timeweight.Buffer[6] =TimeConst.Buffer[3];
  239. rt_sem_release(setTIME_lock);
  240. timeweight.data.Weight = WeightConst_WeightCur;
  241. timeweight.data.WeightWS = WeightConst_WeightWS;
  242. timeweight.data.WeightRun = WeightConst_Product_Run;
  243. timeweight.data.reserved = 0;
  244. ts_pushArrary(&ts_weightdb, timeweight.Buffer, 7);
  245. WeightConst_WeightCur_last3 = WeightConst_WeightCur_last2;
  246. WeightConst_WeightCur_last2 = WeightConst_WeightCur_last1;
  247. WeightConst_WeightCur_last1 = WeightConst_WeightCur;
  248. // if (WeightConst_WeightCur<0)
  249. // rb_push_insert(RecWeightQueue, (0<<7) | (WeightConst_WeightWS<<6>>1));//这边有问题,需要修改
  250. // else
  251. // rb_push_insert(RecWeightQueue, (0<<7) | (WeightConst_WeightWS<<6>>1));//这边有问题,需要修改
  252. WeightConst_WeightCurCount=0;
  253. }
  254. rt_sem_release(weight_lock);
  255. if (WeightConst_AutoSingleNSecondPoint>=pf_comp.data.autosecond || WeightConst_AutoSingleNSecondPoint>=30)
  256. WeightConst_AutoSingleNSecondPoint = 0;
  257. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][0] = WeightConst_oksum;
  258. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][1] = WeightConst_allsum;
  259. if (//( WeightConst_WeightMax - WeightConst_WeightMin)>WeightConst_WeightTargetAllow &&
  260. WeightConst_WeightCur > WeightConst_WeightTargetAllowMax
  261. && pf_comp.data.autosecond>0 && WeightConst_WeightHaveBegin==1)
  262. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][2] = 1;
  263. else
  264. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][2] = 0;
  265. WeightConst_WeightSum = 0;
  266. WeightConst_WeightCount = 0; //重量数
  267. WeightConst_WeightMax = -32768; //最大重量
  268. WeightConst_WeightMin = 32767; //最小重量
  269. WeightConst_AutoSingleNSecondPoint++;
  270. WeightConst_uoksum = 0;
  271. WeightConst_uallsum = 0;
  272. WeightConst_foksum = 0;
  273. for (int CheckWeight_i = 0; CheckWeight_i < pf_comp.data.autosecond; CheckWeight_i++) {
  274. WeightConst_uoksum = WeightConst_uoksum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][0];
  275. WeightConst_uallsum = WeightConst_uallsum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][1];
  276. WeightConst_foksum = WeightConst_foksum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][2];
  277. }
  278. if (WeightConst_uallsum == 0)
  279. WeightConst_uallsum = 100; //如果没接称,allsum有可能为0,此处进行保护
  280. WeightConst_autotpo = WeightConst_uoksum * 100 / WeightConst_uallsum; //合理停留秒数内接收到的符合跳转的数据占总接收数据的百分比
  281. if (WeightConst_autotpo > 100) WeightConst_autotpo = 0; //对百分比进行保护
  282. if ((WeightConst_autotpo > WeightConst_WeightTargetTpo)
  283. || (WeightConst_foksum>(pf_comp.data.autosecond>>1) && pf_comp.data.JMP)
  284. ) //触发自动按键
  285. {
  286. for (int CheckWeight_i = 0; CheckWeight_i < 30; CheckWeight_i++) {
  287. WeightConst_AutoSingleNSecondNum[CheckWeight_i][0]=0;
  288. WeightConst_AutoSingleNSecondNum[CheckWeight_i][1]=0;
  289. WeightConst_AutoSingleNSecondNum[CheckWeight_i][2]=0;
  290. }
  291. if (WeightConst_DELAYON == 0 && delayKeying == 0)
  292. {
  293. rt_sem_release(delay_key_sem);
  294. sendkey1(0xF1, 0);
  295. }
  296. button_state.b1 = 1; //5秒内禁止按1键
  297. }
  298. WeightConst_oksum = 0;
  299. WeightConst_allsum = 0;
  300. WeightConst_uoksum = 0;
  301. WeightConst_uallsum = 0;
  302. WeightConst_foksum = 0;
  303. // sendWeight(); //检查是否需要保存实时重量
  304. }
  305. WeightConst_WeightCurCount++;
  306. if (WeightConst_Product_Run > 0)
  307. {
  308. if (WeightConst_Nextfeed[0] == 0x20){
  309. if (findNextplan()>0)
  310. rt_event_send(&display_event, EVENT_Next);
  311. }
  312. if (WeightConst_Product_Run_time < 65535 && WeightConst_Product_Run_time>0 && pf_comp.data.addorout==0)
  313. WeightConst_Product_Run_time++;
  314. // else
  315. // WeightConst_Product_Run_time = 0;
  316. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR3, WeightConst_Product_Run_time);
  317. }
  318. rt_thread_mdelay(998);
  319. }
  320. }
  321. static void P_300G0() {
  322. // 02 20 2D 20 20 20 36 37 2E 30 6B 67 03 -67.0KG
  323. // 02 20 20 20 20 20 36 37 2E 36 6B 7F 03
  324. // 02 2B 30 30 30 30 30 30 33 03
  325. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  326. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  327. {
  328. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  329. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //TDI300G0
  330. {
  331. if (WeightConst_RecWeightPoint1 == 12 && WeightConst_RecWeightData1[0] == 0x02) {
  332. WeightConst_WeightCurTem = 0;
  333. WeightConst_WeightWS = 0;
  334. WeightConst_Weight_ZWS = 0;
  335. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  336. if (WeightConst_RecWeightData1[ReadWeight_i + 3] >= 0x30 && WeightConst_RecWeightData1[ReadWeight_i + 3] <= 0x39) {
  337. WeightConst_WeightCurTem = WeightConst_WeightCurTem + (WeightConst_RecWeightData1[ReadWeight_i + 3] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  338. WeightConst_Weight_ZWS++;
  339. } else if (WeightConst_RecWeightData1[ReadWeight_i + 3] == 0x2E) {
  340. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  341. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  342. }
  343. }
  344. if (WeightConst_RecWeightData1[2] == 0x2D) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  345. setWeightSM();
  346. WeightConst_RecFlag1 = 0x00;
  347. WeightConst_Drop = 1; //开始抛弃数据
  348. }
  349. WeightConst_RecWeightPoint1 = 0; //指针还原
  350. } else
  351. WeightConst_RecWeightPoint1++;
  352. }
  353. else
  354. {
  355. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  356. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) {
  357. WeightConst_Drop = 0;
  358. WeightConst_RecWeightPoint1 = 0; //指针还原
  359. }
  360. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  361. {
  362. WeightConst_Drop = 0;
  363. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  364. WeightConst_RecWeightPoint1 = 1;
  365. WeightConst_RecFlag1 = 0x00;
  366. }
  367. else {
  368. WeightConst_Drop++;
  369. WeightConst_RecWeightPoint1++;
  370. }
  371. }
  372. }
  373. static void P_300G1() {
  374. // 02 2D 20 20 20 36 37 2E 30 6B 67 03 -67.0KG
  375. // 02 20 20 20 20 32 2E 33 30 6B 67 03
  376. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  377. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  378. {
  379. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  380. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //TDI300G0
  381. {
  382. if (WeightConst_RecWeightPoint1 == 11 && WeightConst_RecWeightData1[0] == 0x02) {
  383. WeightConst_WeightCurTem = 0;
  384. WeightConst_WeightWS = 0;
  385. WeightConst_Weight_ZWS = 0;
  386. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  387. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30 && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  388. WeightConst_WeightCurTem = WeightConst_WeightCurTem + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  389. WeightConst_Weight_ZWS++;
  390. } else if (WeightConst_RecWeightData1[ReadWeight_i + 2] == 0x2E) {
  391. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  392. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  393. }
  394. }
  395. if (WeightConst_RecWeightData1[1] == 0x2D) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  396. setWeightSM();
  397. WeightConst_RecFlag1 = 0x00;
  398. WeightConst_Drop = 1; //开始抛弃数据
  399. }
  400. WeightConst_RecWeightPoint1 = 0; //指针还原
  401. }
  402. else
  403. WeightConst_RecWeightPoint1++;
  404. }
  405. else
  406. {
  407. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  408. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) {
  409. WeightConst_Drop = 0;
  410. WeightConst_RecWeightPoint1 = 0; //指针还原
  411. }
  412. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  413. {
  414. WeightConst_Drop = 0;
  415. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  416. WeightConst_RecWeightPoint1 = 1;
  417. WeightConst_RecFlag1 = 0x00;
  418. }
  419. else {
  420. WeightConst_Drop++;
  421. WeightConst_RecWeightPoint1++;
  422. }
  423. }
  424. }
  425. static void P_TDI200I() {
  426. //02 2B 30 30 30 30 30 30 33 03
  427. //02 +/- 十万 万 千 百 十 个 小数点位数 03
  428. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  429. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  430. {
  431. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  432. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //英展电子秤
  433. {
  434. if (WeightConst_RecWeightPoint1 == 9 && WeightConst_RecWeightData1[0] == 0x02) {
  435. WeightConst_WeightCurTem = 0;
  436. WeightConst_WeightWS = 0;
  437. WeightConst_Weight_ZWS = 0;
  438. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  439. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30
  440. && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  441. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  442. + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  443. WeightConst_Weight_ZWS++;
  444. }
  445. WeightConst_WeightWS = WeightConst_RecWeightData1[8] - 0x30; //设置小数位数
  446. }
  447. if (WeightConst_RecWeightData1[1] != 0x2B)
  448. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  449. setWeightSM();
  450. WeightConst_RecFlag1 = 0x00;
  451. WeightConst_Drop = 1; //开始抛弃数据
  452. }
  453. WeightConst_RecWeightPoint1 = 0; //指针还原
  454. } else
  455. WeightConst_RecWeightPoint1++;
  456. }
  457. else
  458. {
  459. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  460. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //英展电子秤
  461. {
  462. WeightConst_Drop = 0;
  463. WeightConst_RecWeightPoint1 = 0; //指针还原
  464. }
  465. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  466. {
  467. WeightConst_Drop = 0;
  468. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  469. WeightConst_RecWeightPoint1 = 1;
  470. WeightConst_RecFlag1 = 0x00;
  471. }
  472. else {
  473. WeightConst_Drop++;
  474. WeightConst_RecWeightPoint1++;
  475. }
  476. }
  477. }
  478. static void P_XK3190_C8() {
  479. //兼容XK3118K9
  480. //02 2D 30 30 30 31 32 30 31 03
  481. //02 2D 30 30 30 31 32 30 31 31 46 03
  482. //02 +/- 0 1 2 3 4 5 点位数 03
  483. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  484. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  485. {
  486. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  487. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //英展电子秤
  488. {
  489. if (WeightConst_RecWeightPoint1 == 11 && WeightConst_RecWeightData1[0] == 0x02) {
  490. WeightConst_WeightCurTem = 0;
  491. WeightConst_WeightWS = 0;
  492. WeightConst_Weight_ZWS = 0;
  493. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  494. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30
  495. && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  496. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  497. + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  498. WeightConst_Weight_ZWS++;
  499. }
  500. }
  501. WeightConst_WeightWS = WeightConst_RecWeightData1[8] - 0x30; //设置小数位数
  502. if (WeightConst_WeightWS==1)
  503. {
  504. WeightConst_WeightWS = 0;
  505. WeightConst_WeightCurTem = WeightConst_WeightCurTem/10;
  506. }
  507. if (WeightConst_RecWeightData1[1] != 0x2B)
  508. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  509. setWeightSM();
  510. WeightConst_RecFlag1 = 0x00;
  511. WeightConst_Drop = 1; //开始抛弃数据
  512. }
  513. WeightConst_RecWeightPoint1 = 0; //指针还原
  514. } else {
  515. WeightConst_RecWeightPoint1++;
  516. }
  517. }
  518. else
  519. {
  520. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  521. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //英展电子秤
  522. {
  523. WeightConst_Drop = 0;
  524. WeightConst_RecWeightPoint1 = 0; //指针还原
  525. }
  526. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  527. {
  528. WeightConst_Drop = 0;
  529. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  530. WeightConst_RecWeightPoint1 = 1;
  531. WeightConst_RecFlag1 = 0x00;
  532. }
  533. else {
  534. WeightConst_Drop++;
  535. WeightConst_RecWeightPoint1++;
  536. }
  537. }
  538. }
  539. static void P_AWH_30_SA() {
  540. //展会 //53 54 2C 47 53 2C 2B 20 20 30 2E 38 37 36 6B 67 0d 0a
  541. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  542. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  543. {
  544. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  545. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  546. {
  547. if (WeightConst_RecWeightPoint1 == 17) {
  548. WeightConst_WeightCurTem = 0;
  549. WeightConst_WeightWS = 0;
  550. WeightConst_Weight_ZWS = 0;
  551. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  552. if (WeightConst_RecWeightData1[ReadWeight_i + 7] >= 0x30
  553. && WeightConst_RecWeightData1[ReadWeight_i + 7] <= 0x39) {
  554. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  555. + (WeightConst_RecWeightData1[ReadWeight_i + 7] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  556. WeightConst_Weight_ZWS++;
  557. } else if (WeightConst_RecWeightData1[ReadWeight_i + 7] == 0x2E) {
  558. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  559. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  560. }
  561. }
  562. if (WeightConst_RecWeightData1[6] != 0x2b)
  563. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  564. setWeightSM();
  565. WeightConst_RecFlag1 = 0x00;
  566. WeightConst_Drop = 1; //开始抛弃数据
  567. }
  568. WeightConst_RecWeightPoint1 = 0; //指针还原
  569. } else {
  570. WeightConst_RecWeightPoint1++;
  571. }
  572. }
  573. else
  574. {
  575. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  576. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  577. {
  578. WeightConst_Drop = 0;
  579. WeightConst_RecWeightPoint1 = 0; //指针还原
  580. WeightConst_RecFlag1 = 0x00;
  581. } else {
  582. WeightConst_Drop++;
  583. WeightConst_RecWeightPoint1++;
  584. }
  585. }
  586. }
  587. static void P_digi() {
  588. //2E 44 30 2D 20 20 2D 33 36 30 30 30 39 09
  589. //2E 44 30 2D 20 33 39 32 32 30 30 30 42 09
  590. //2E 44 30 74 54 6F 74 61 6C 20 57 65 69 67 68 74 20 38 09
  591. if (WeightConst_RecWeightPoint1>140) WeightConst_RecWeightPoint1 = 0; //指针还原
  592. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  593. if (WeightConst_RecFlag1 != 0xF0) //上一条完整数据没有处理完
  594. {
  595. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09 &&
  596. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10] == 0x2D) //英展电子秤
  597. {
  598. WeightConst_WeightWS = 0;
  599. WeightConst_Weight_ZWS = 0;
  600. WeightConst_WeightCurTem = 0;
  601. WeightConst_WeightCurTemZF = 0;
  602. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  603. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] >= 0x30
  604. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] <= 0x39) {
  605. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  606. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  607. WeightConst_Weight_ZWS++;
  608. } else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] == 0x2D)
  609. WeightConst_WeightCurTemZF = 1;
  610. }
  611. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  612. setWeightSM();
  613. WeightConst_RecFlag1 = 0x00;
  614. WeightConst_Drop = 0; //开始抛弃数据
  615. }
  616. WeightConst_RecWeightPoint1 = 0; //指针还原
  617. } else {
  618. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09) //英展电子秤
  619. {
  620. WeightConst_Drop = 0;
  621. WeightConst_RecWeightPoint1 = 0; //指针还原
  622. WeightConst_RecFlag1 = 0x00;
  623. }
  624. else WeightConst_RecWeightPoint1++;
  625. }
  626. }
  627. static void P_AWT_ZM303() {
  628. //展会 //20 20 20 20 20 31 37 34 20 6B 67 20 47 0D 0A
  629. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  630. if (WeightConst_RecWeightPoint1>50) WeightConst_RecWeightPoint1 = 0; //指针还原
  631. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  632. {
  633. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  634. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  635. {
  636. if (WeightConst_RecWeightPoint1 == 13 && WeightConst_RecWeightData1[0] == 0x3D) {
  637. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  638. WeightConst_WeightCurTem = 0;
  639. WeightConst_WeightCurTemZF = 0;
  640. WeightConst_WeightWS = 0;
  641. WeightConst_Weight_ZWS = 0;
  642. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  643. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30
  644. && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  645. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  646. + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30)
  647. * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  648. WeightConst_Weight_ZWS++;
  649. }
  650. }
  651. if (WeightConst_RecWeightData1[1] == 0x2D) WeightConst_WeightCurTemZF = 1;
  652. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  653. setWeightSM();
  654. WeightConst_RecFlag1 = 0x00;
  655. WeightConst_Drop = 0; //开始抛弃数据
  656. }
  657. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-6]==0x20 &&
  658. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-5]==0x6B ) {
  659. //20 20 20 20 20 31 37 34 20 6B 67 20 47 0D 0A
  660. //20 20 20 20 20 2D 31 38 20 6B 67 20 47 0D 0A
  661. WeightConst_WeightCurTem = 0;
  662. WeightConst_WeightCurTemZF = 0;
  663. WeightConst_WeightWS = 0;
  664. WeightConst_Weight_ZWS = 0;
  665. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  666. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 -12 + ReadWeight_i ] >= 0x30
  667. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 -12 + ReadWeight_i ] <= 0x39) {
  668. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  669. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 -12 + ReadWeight_i ] - 0x30)
  670. * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  671. WeightConst_Weight_ZWS++;
  672. }
  673. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 -12 + ReadWeight_i ] == 0x2D)
  674. WeightConst_WeightCurTemZF = 1;
  675. }
  676. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  677. setWeightSM();
  678. WeightConst_RecFlag1 = 0x00;
  679. WeightConst_Drop = 0; //开始抛弃数据
  680. }
  681. else if (WeightConst_RecWeightPoint1 == 43 && WeightConst_RecWeightData1[0] == 0x31) {
  682. // 31 2C 53 54 2C 20 20 20 20 20 20 20 2D 32 35 2C 20 20 20 20 20 20 20 20 20 20 20 30 2C 20 20 20 20 20 20 20 20 20 30 2C 6B 67 0D 0A
  683. WeightConst_WeightCurTem = 0;
  684. WeightConst_WeightCurTemZF = 0;
  685. WeightConst_WeightWS = 0;
  686. WeightConst_Weight_ZWS = 0;
  687. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  688. if (WeightConst_RecWeightData1[ReadWeight_i + 9] >= 0x30
  689. && WeightConst_RecWeightData1[ReadWeight_i + 9] <= 0x39) {
  690. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  691. + (WeightConst_RecWeightData1[ReadWeight_i + 9] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  692. WeightConst_Weight_ZWS++;
  693. }
  694. else if (WeightConst_RecWeightData1[ReadWeight_i + 9] == 0x2D)
  695. WeightConst_WeightCurTemZF = 1;
  696. }
  697. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  698. setWeightSM();
  699. WeightConst_RecFlag1 = 0x00;
  700. WeightConst_Drop = 0; //开始抛弃数据
  701. }
  702. WeightConst_RecWeightPoint1 = 0; //指针还原
  703. }
  704. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09 &&
  705. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10] == 0x2D) //英展电子秤
  706. {
  707. WeightConst_WeightWS = 0;
  708. WeightConst_Weight_ZWS = 0;
  709. WeightConst_WeightCurTem = 0;
  710. WeightConst_WeightCurTemZF = 0;
  711. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  712. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] >= 0x30
  713. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] <= 0x39) {
  714. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  715. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  716. WeightConst_Weight_ZWS++;
  717. } else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] == 0x2D)
  718. WeightConst_WeightCurTemZF = 1;
  719. }
  720. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  721. setWeightSM();
  722. WeightConst_RecFlag1 = 0x00;
  723. WeightConst_Drop = 0; //开始抛弃数据
  724. } else {
  725. WeightConst_RecWeightPoint1++;
  726. }
  727. }
  728. else
  729. {
  730. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  731. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  732. {
  733. WeightConst_Drop = 0;
  734. WeightConst_RecWeightPoint1 = 0; //指针还原
  735. WeightConst_RecFlag1 = 0x00;
  736. }
  737. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09 ) //英展电子秤
  738. {
  739. WeightConst_Drop = 0;
  740. WeightConst_RecWeightPoint1 = 0; //指针还原
  741. WeightConst_RecFlag1 = 0x00;
  742. }
  743. else {
  744. WeightConst_Drop++;
  745. WeightConst_RecWeightPoint1++;
  746. }
  747. }
  748. }
  749. static void P_T_2000() {
  750. // 55 53 2C 47 53 20 20 20 20 32 2E 37 32 6B 67 0D 0A 2.72 不稳定
  751. // 53 54 2C 47 53 20 20 20 20 32 2E 34 33 6B 67 0D 0A 2.43 稳定
  752. // 55 53 2C 47 53 2D 20 20 20 30 2E 33 38 6B 67 0D 0A -0.38 不稳定
  753. // 77 6E 30 30 30 30 38 33 33 35 6B 67 0D 0A
  754. if (WeightConst_RecWeightPoint1>40) WeightConst_RecWeightPoint1 = 0; //指针还原
  755. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  756. {
  757. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  758. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A ||
  759. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x0D) //英展电子秤
  760. {
  761. if (WeightConst_RecWeightPoint1 >= 12) {
  762. WeightConst_WeightCurTem = 0;
  763. WeightConst_WeightWS = 0;
  764. WeightConst_Weight_ZWS = 0;
  765. if (WeightConst_RecWeightPoint1==12) {
  766. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  767. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 9] >= 0x30
  768. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 9] <= 0x39) {
  769. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  770. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 9] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  771. WeightConst_Weight_ZWS++;
  772. } else if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 90] == 0x2E) {
  773. WeightConst_WeightWS = 5 - ReadWeight_i; //设置小数位数
  774. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  775. }
  776. }
  777. } else if (WeightConst_RecWeightPoint1>=13) {
  778. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  779. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 10] >= 0x30
  780. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 10] <= 0x39) {
  781. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  782. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 10] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  783. WeightConst_Weight_ZWS++;
  784. } else if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 10] == 0x2E) {
  785. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  786. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  787. }
  788. }
  789. }
  790. if (WeightConst_RecWeightData1[3] == 0x2D)
  791. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  792. setWeightSM();
  793. WeightConst_RecFlag1 = 0x00;
  794. WeightConst_Drop = 0; //开始抛弃数据
  795. }
  796. WeightConst_RecWeightPoint1 = 0; //指针还原
  797. } else {
  798. WeightConst_RecWeightPoint1++;
  799. }
  800. }
  801. else
  802. {
  803. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  804. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  805. {
  806. WeightConst_Drop = 0;
  807. WeightConst_RecWeightPoint1 = 0; //指针还原
  808. }
  809. else {
  810. WeightConst_Drop++;
  811. WeightConst_RecWeightPoint1++;
  812. }
  813. }
  814. }
  815. static void P_HF() {
  816. // 01 10 00 01 00 02 04 00 00 17 9C 3D FA 01 10 00 01 00 02 10 08
  817. // 02 10 00 01 00 02 04 08 00 00 A2 BE FE 02 10 00 01 00 02 10 3B
  818. // 03 10 00 01 00 02 04 08 00 00 A4 3A 00 03 10 00 01 00 02 10 3B
  819. if (WeightConst_RecWeightPoint1>140) WeightConst_RecWeightPoint1 = 0; //指针还原
  820. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  821. if (WeightConst_RecFlag1 != 0xF0) //上一条完整数据没有处理完
  822. {
  823. if ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]&0xf0) == 0x10 &&
  824. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x02 &&
  825. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x00 &&
  826. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-3] == 0x01 &&
  827. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-4] == 0x00 &&
  828. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-5] == 0x10 &&
  829. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-6] == XbeeConst_DeviceAddress) //英展电子秤
  830. {
  831. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19] == XbeeConst_DeviceAddress)
  832. {
  833. WeightConst_WeightWS = 0;
  834. WeightConst_Weight_ZWS = 0;
  835. WeightConst_WeightCurTem = ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-11]<<16)
  836. |
  837. (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10]<<8)
  838. |
  839. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-9]);
  840. if ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-12]&0x08) == 0x08)
  841. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  842. setWeightSM();
  843. WeightConst_RecFlag1 = 0x00;
  844. WeightConst_Drop = 0; //开始抛弃数据
  845. }
  846. WeightConst_RecWeightPoint1 = 0; //指针还原
  847. } else {
  848. WeightConst_RecWeightPoint1++;
  849. }
  850. }
  851. else
  852. {
  853. WeightConst_RecWeightPoint1++;
  854. }
  855. }
  856. static void P_E_2000() {
  857. // 3D 30 30 30 30 31 30 30 0D 0A
  858. // 3D 2D 30 30 30 31 30 30 0D 0A
  859. if (WeightConst_RecWeightPoint1>40) WeightConst_RecWeightPoint1 = 0; //指针还原
  860. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  861. {
  862. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  863. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D) //英展电子秤
  864. {
  865. if (WeightConst_RecWeightPoint1 > 9) {
  866. WeightConst_WeightCurTem = 0;
  867. WeightConst_WeightWS = 0;
  868. WeightConst_Weight_ZWS = 0;
  869. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  870. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] >= 0x30
  871. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] <= 0x39) {
  872. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  873. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] - 0x30)
  874. * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  875. WeightConst_Weight_ZWS++;
  876. }
  877. }
  878. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-7] == 0x2D)
  879. {
  880. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  881. WeightConst_WeightCurTemZF = 1;
  882. }
  883. setWeightSM();
  884. WeightConst_RecFlag1 = 0x00;
  885. WeightConst_Drop = 1; //开始抛弃数据
  886. }
  887. WeightConst_RecWeightPoint1 = 0; //指针还原
  888. } else {
  889. WeightConst_RecWeightPoint1++;
  890. }
  891. }
  892. else
  893. {
  894. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  895. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  896. {
  897. WeightConst_Drop = 0;
  898. WeightConst_RecWeightPoint1 = 0; //指针还原
  899. WeightConst_RecFlag1 = 0x00;
  900. }
  901. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x53 &&
  902. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x47 &&
  903. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x2C) {
  904. WeightConst_RecWeightData1[0] = 0x2C;
  905. WeightConst_RecWeightData1[1] = 0x47;
  906. WeightConst_RecWeightData1[2] = 0x53;
  907. WeightConst_RecWeightPoint1 = 2; //指针还原
  908. WeightConst_RecFlag1 = 0x00;
  909. WeightConst_Drop = 0;
  910. }
  911. else {
  912. WeightConst_Drop++;
  913. WeightConst_RecWeightPoint1++;
  914. }
  915. }
  916. }
  917. static void P_TMI_II() {
  918. //23 03 BD 18 00 2D 34 37 39 38 0A 00 0D 00 00 00 00 00 00 00 00 00 00 00 AF BA 04 - 4 7 9 8 //波特率19200
  919. //23 03 02 18 00 20 2D 31 38 32 0A 00 0D 00 00 00 00 00 00 00 00 00 00 00 7D FE 04
  920. //23 03 03 18 00 20 2D 31 38 32 0A 00 0D 00 00 00 00 00 00 00 00 00 00 00 D4 A3 04
  921. //23 03 04 18 00 20 2D 31 38 32 0A 00 0D 00 00 00 00 00 00 00 00 00 00 00 92 03 04 -182
  922. WeightConst_RecWeightPoint1++;
  923. if (WeightConst_RecWeightPoint1>53) WeightConst_RecWeightPoint1 = 0; //指针还原
  924. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  925. if (WeightConst_RecWeightPoint1>=1 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x03 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x23) {
  926. WeightConst_RecWeightData1[0] = 0x23;
  927. WeightConst_RecWeightData1[1] = 0x03;
  928. WeightConst_RecWeightPoint1 = 1; //指针还原
  929. WeightConst_RecFlag1 = 0x00;
  930. WeightConst_Drop = 0;
  931. }
  932. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  933. {
  934. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x04 ||
  935. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x00) //英展电子秤
  936. {
  937. if (WeightConst_RecWeightPoint1 == 26 && WeightConst_RecWeightData1[0] == 0x23 && WeightConst_RecWeightData1[1] == 0x03
  938. && WeightConst_RecWeightData1[10] == 0x0A) {
  939. WeightConst_WeightCurTem = 0;
  940. WeightConst_WeightCurTemZF = 0;
  941. WeightConst_WeightWS = 0;
  942. WeightConst_Weight_ZWS = 0;
  943. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  944. if (WeightConst_RecWeightData1[ReadWeight_i + 5] >= 0x30
  945. && WeightConst_RecWeightData1[ReadWeight_i + 5] <= 0x39) {
  946. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  947. + (WeightConst_RecWeightData1[ReadWeight_i + 5] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  948. WeightConst_Weight_ZWS++;
  949. } else if (WeightConst_RecWeightData1[ReadWeight_i + 5] == 0x2D) {
  950. WeightConst_WeightCurTemZF = 1;
  951. }
  952. }
  953. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  954. setWeightSM();
  955. WeightConst_RecFlag1 = 0x00;
  956. WeightConst_Drop = 1; //开始抛弃数据
  957. }
  958. }
  959. }
  960. /*
  961. else
  962. {
  963. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x04 || WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x00) //英展电子秤
  964. {
  965. WeightConst_Drop = 0;
  966. WeightConst_RecWeightPoint1 = 0; //指针还原
  967. } else {
  968. WeightConst_Drop++;
  969. WeightConst_RecWeightPoint1++;
  970. }
  971. }*/
  972. }
  973. static void P_TMI_III() {
  974. //0x20 0x2d 0x31 0x34 0x32 0x0d -142
  975. //2D 33 36 35 34 0D
  976. if (WeightConst_RecWeightPoint1>17) WeightConst_RecWeightPoint1 = 0; //指针还原
  977. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  978. {
  979. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  980. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D) //英展电子秤
  981. {
  982. if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x29 &&
  983. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-4] == 0x28 )
  984. { //3D 30 30 30 30 30 30 36 28 6B 67 29 0D 0A
  985. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  986. WeightConst_WeightCurTem = 0;
  987. WeightConst_WeightCurTemZF = 0;
  988. WeightConst_WeightWS = 0;
  989. WeightConst_Weight_ZWS = 0;
  990. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  991. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(9-ReadWeight_i)] >= 0x30
  992. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(9-ReadWeight_i)] <= 0x39) {
  993. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  994. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(9-ReadWeight_i)] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  995. WeightConst_Weight_ZWS++;
  996. };
  997. }
  998. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-11] == 0x2D && WeightConst_WeightCurTemZF==0)
  999. {
  1000. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1001. WeightConst_WeightCurTemZF = 1;
  1002. }
  1003. setWeightSM();
  1004. WeightConst_RecFlag1 = 0x00;
  1005. WeightConst_Drop = 1; //开始抛弃数据
  1006. }
  1007. /*else if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x67 &&
  1008. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x6B )
  1009. {
  1010. //77 6E 2D 30 30 30 30 30 35 31 6B 67 0D 0A
  1011. WeightConst_WeightCurTem = 0;
  1012. WeightConst_WeightCurTemZF = 0;
  1013. WeightConst_WeightWS = 0;
  1014. WeightConst_Weight_ZWS = 0;
  1015. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  1016. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(7-ReadWeight_i)] >= 0x30
  1017. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(7-ReadWeight_i)] <= 0x39) {
  1018. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1019. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(7-ReadWeight_i)] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  1020. WeightConst_Weight_ZWS++;
  1021. };
  1022. }
  1023. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10] == 0x2D && WeightConst_WeightCurTemZF==0)
  1024. {
  1025. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1026. WeightConst_WeightCurTemZF = 1;
  1027. }
  1028. setWeightSM();
  1029. WeightConst_RecFlag1 = 0x00;
  1030. WeightConst_Drop = 1; //开始抛弃数据
  1031. }*/
  1032. else if (WeightConst_RecWeightPoint1>4 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] != 0x20) {
  1033. WeightConst_WeightCurTem = 0;
  1034. WeightConst_WeightCurTemZF = 0;
  1035. WeightConst_WeightWS = 0;
  1036. WeightConst_Weight_ZWS = 0;
  1037. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  1038. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] >= 0x30
  1039. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] <= 0x39) {
  1040. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1041. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  1042. WeightConst_Weight_ZWS++;
  1043. }
  1044. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] == 0x2D)
  1045. WeightConst_WeightCurTemZF = 1;
  1046. }
  1047. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1048. if (WeightConst_RecWeightPoint1>6 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-7] == 0x2D && WeightConst_WeightCurTemZF==0)
  1049. {
  1050. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1051. WeightConst_WeightCurTemZF = 1;
  1052. }
  1053. setWeightSM();
  1054. WeightConst_RecFlag1 = 0x00;
  1055. WeightConst_Drop = 1; //开始抛弃数据
  1056. }
  1057. WeightConst_RecWeightPoint1 = 0; //指针还原
  1058. } else {
  1059. WeightConst_RecWeightPoint1++;
  1060. }
  1061. }
  1062. else
  1063. {
  1064. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1065. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D) //英展电子秤
  1066. {
  1067. WeightConst_Drop = 0;
  1068. WeightConst_RecWeightPoint1 = 0; //指针还原
  1069. }
  1070. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x20 ||
  1071. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x30 ||
  1072. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x3D ||
  1073. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x2D)
  1074. {
  1075. WeightConst_Drop = 0;
  1076. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  1077. WeightConst_RecWeightPoint1 = 1;
  1078. WeightConst_RecFlag1 = 0x00;
  1079. }
  1080. else {
  1081. WeightConst_Drop++;
  1082. WeightConst_RecWeightPoint1++;
  1083. }
  1084. }
  1085. }
  1086. static void P_EZ4300() {
  1087. //82 2D A0 A0 A0 B1 39 8D 库恩表头出来是7位数据,8位是校验位,将数据的高位去掉,则得到下面正确的数据
  1088. //02 2D 20 20 20 31 39 0D
  1089. if (WeightConst_RecWeightPoint1>10) WeightConst_RecWeightPoint1 = 0; //指针还原
  1090. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1091. {
  1092. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1) & 0x7F;
  1093. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  1094. {
  1095. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  1096. WeightConst_RecWeightPoint1 = 1;
  1097. WeightConst_RecFlag1 = 0x00;
  1098. WeightConst_Drop = 0;
  1099. }
  1100. else if (WeightConst_RecWeightPoint1 >= 7 && WeightConst_RecWeightData1[0] == 0x02 && WeightConst_RecWeightData1[6] != 0x20) {
  1101. WeightConst_WeightCurTem = 0;
  1102. WeightConst_WeightWS = 0;
  1103. WeightConst_Weight_ZWS = 0;
  1104. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  1105. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30
  1106. && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  1107. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1108. + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  1109. WeightConst_Weight_ZWS++;
  1110. }
  1111. WeightConst_WeightWS = 0;
  1112. }
  1113. if (WeightConst_RecWeightData1[1] == 0x2D) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1114. setWeightSM();
  1115. WeightConst_RecFlag1 = 0x00;
  1116. WeightConst_Drop = 0; //开始抛弃数据
  1117. WeightConst_RecWeightPoint1 = 0; //指针还原
  1118. }
  1119. else WeightConst_RecWeightPoint1++;
  1120. }
  1121. else
  1122. {
  1123. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1)& 0x7F;
  1124. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D)
  1125. {
  1126. WeightConst_Drop = 0;
  1127. WeightConst_RecWeightPoint1 = 0; //指针还原
  1128. }
  1129. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  1130. {
  1131. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  1132. WeightConst_RecWeightPoint1 = 1;
  1133. WeightConst_RecFlag1 = 0x00;
  1134. WeightConst_Drop = 0;
  1135. }
  1136. else {
  1137. WeightConst_Drop++;
  1138. WeightConst_RecWeightPoint1++;
  1139. }
  1140. }
  1141. }
  1142. static void P_TQ() {
  1143. // 7E 7E F0 10 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 AB FE
  1144. // 7E 7E F0 10 00 00 00 00 00 00 00 03 04 00 00 00 00 00 03 04 F2 FE
  1145. // 7E 7E F0 10 01 00 00 00 00 00 00 06 08 80 00 00 00 00 06 08 63 FE
  1146. // 7E 7E FF 10 01 00 00 00 00 00 00 06 08 80 00 00 00 00 06 08 54 FE
  1147. if (WeightConst_RecWeightPoint1>43) WeightConst_RecWeightPoint1 = 0; //指针还原
  1148. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1149. if (WeightConst_RecWeightPoint1>=1 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x7E && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x7E) {
  1150. WeightConst_RecWeightData1[0] = 0x7E;
  1151. WeightConst_RecWeightData1[1] = 0x7E;
  1152. WeightConst_RecWeightPoint1 = 1; //指针还原
  1153. WeightConst_RecFlag1 = 0x00;
  1154. WeightConst_Drop = 0;
  1155. }
  1156. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1157. {
  1158. if (WeightConst_RecWeightPoint1<44) {
  1159. if (WeightConst_RecWeightPoint1 >= 21 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-21]==0x7E
  1160. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-20]==0x7E
  1161. && (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19]==0xF0 || WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19]==0xFF)
  1162. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-17]!=0x55) {
  1163. WeightConst_RecWeight_he2 = 0;
  1164. WeightConst_RecWeight_he1 = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]
  1165. + WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] * 256; //判断接收到的重量协议是否正确
  1166. for(int i=0; i<18; i++) WeightConst_RecWeight_he2 += WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2-i];
  1167. WeightConst_RecWeight_he2 = ~WeightConst_RecWeight_he2+1;
  1168. if (WeightConst_RecWeight_he1==WeightConst_RecWeight_he2)
  1169. {
  1170. WeightConst_WeightCurTem = 0;
  1171. WeightConst_WeightWS = 0;
  1172. WeightConst_Weight_ZWS = 0;
  1173. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1174. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 7] <= 0x09) {
  1175. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1176. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 7]) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1177. WeightConst_Weight_ZWS++;
  1178. }
  1179. }
  1180. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-8] == 0x80)
  1181. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1182. WeightConst_WeightWS = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 16]; //设置小数位数
  1183. setWeightSM();
  1184. }
  1185. WeightConst_RecFlag1 = 0x00;
  1186. WeightConst_Drop = 1; //开始抛弃数据
  1187. WeightConst_RecWeightPoint1 = 0; //指针还原
  1188. } else
  1189. WeightConst_RecWeightPoint1++;
  1190. }
  1191. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1192. }
  1193. else
  1194. {
  1195. WeightConst_RecWeightPoint1++;
  1196. }
  1197. }
  1198. static void P_XL10000() {
  1199. // 02 2A 30 20 30 30 30 32 32 30 30 30 30 30 30 30 0D 33
  1200. if (WeightConst_RecWeightPoint1>38) WeightConst_RecWeightPoint1 = 0; //指针还原
  1201. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1202. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] & 0x7F;
  1203. if (WeightConst_RecWeightPoint1>=3 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02 ) {
  1204. WeightConst_RecWeightData1[0] = 0x02;
  1205. WeightConst_RecWeightPoint1 = 0; //指针还原
  1206. WeightConst_RecFlag1 = 0x00;
  1207. WeightConst_Drop = 0;
  1208. }
  1209. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1210. {
  1211. if (WeightConst_RecWeightPoint1<38) {
  1212. if (WeightConst_RecWeightPoint1 >= 17 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-17]==0x02
  1213. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x0D)
  1214. {
  1215. WeightConst_WeightCurTem = 0;
  1216. WeightConst_WeightWS = 0;
  1217. WeightConst_Weight_ZWS = 0;
  1218. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1219. if (WeightConst_RecWeightData1[ReadWeight_i + 4] >= 0x30
  1220. && WeightConst_RecWeightData1[ReadWeight_i + 4] <= 0x39) {
  1221. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1222. + (WeightConst_RecWeightData1[ReadWeight_i + 4] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1223. WeightConst_Weight_ZWS++;
  1224. }
  1225. }
  1226. if ((WeightConst_RecWeightData1[2] & 0x02) == 0x02)
  1227. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1228. WeightConst_WeightWS = 0; //设置小数位数
  1229. setWeightSM();
  1230. WeightConst_RecFlag1 = 0x00;
  1231. WeightConst_Drop = 1; //开始抛弃数据
  1232. WeightConst_RecWeightPoint1 = 0; //指针还原
  1233. } else
  1234. WeightConst_RecWeightPoint1++;
  1235. }
  1236. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1237. }
  1238. else
  1239. {
  1240. WeightConst_RecWeightPoint1++;
  1241. }
  1242. }
  1243. static void XK3190_A27E() {
  1244. // 77 6E 30 30 30 30 30 36 31 35 6B 67 0D 0A 615 boudrate=1200
  1245. // 77 6E 2D 30 30 30 30 30 36 35 6B 67 0D 0A -65
  1246. // 77 6E 2D 30 30 30 31 32 20 6B 67 0D 0A
  1247. // 77 6E 30 30 30 30 31 2E 32 6B 67 0D 0A
  1248. if (WeightConst_RecWeightPoint1>37) WeightConst_RecWeightPoint1 = 0; //指针还原
  1249. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1250. if ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x77 &&
  1251. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x6E) ||
  1252. (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x77 &&
  1253. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x77)) {
  1254. WeightConst_RecWeightData1[0] = 0x77;
  1255. WeightConst_RecWeightData1[1] = 0x6E;
  1256. WeightConst_RecWeightPoint1 = 1; //指针还原
  1257. WeightConst_RecFlag1 = 0x00;
  1258. WeightConst_Drop = 0;
  1259. }
  1260. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1261. {
  1262. if (WeightConst_RecWeightPoint1<15) {
  1263. if (WeightConst_RecWeightPoint1 >= 12
  1264. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x0D
  1265. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x0A) {
  1266. WeightConst_WeightCurTem = 0;
  1267. WeightConst_WeightWS = 0;
  1268. WeightConst_Weight_ZWS = 0;
  1269. if (WeightConst_RecWeightPoint1 == 13)
  1270. {
  1271. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  1272. if (WeightConst_RecWeightData1[ReadWeight_i+3] >= 0x30
  1273. && WeightConst_RecWeightData1[ReadWeight_i+3] <= 0x39) {
  1274. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1275. + (WeightConst_RecWeightData1[ReadWeight_i+3] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  1276. WeightConst_Weight_ZWS++;
  1277. } else if (WeightConst_RecWeightData1[ReadWeight_i + 3] == 0x2E) {
  1278. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  1279. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  1280. }
  1281. }
  1282. }
  1283. else if(WeightConst_RecWeightPoint1 == 12)
  1284. {
  1285. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  1286. if (WeightConst_RecWeightData1[ReadWeight_i+3] >= 0x30
  1287. && WeightConst_RecWeightData1[ReadWeight_i+3] <= 0x39) {
  1288. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1289. + (WeightConst_RecWeightData1[ReadWeight_i+3] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  1290. WeightConst_Weight_ZWS++;
  1291. } else if (WeightConst_RecWeightData1[ReadWeight_i + 2] == 0x2E) {
  1292. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  1293. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  1294. }
  1295. }
  1296. //if (WeightConst_WeightWS == 0) WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  1297. }
  1298. if (WeightConst_RecWeightData1[2] == 0x2D)
  1299. WeightConst_WeightCurTemZF = 1;
  1300. else WeightConst_WeightCurTemZF = 0;
  1301. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1302. //WeightConst_WeightWS = 0; //设置小数位数
  1303. setWeightSM();
  1304. WeightConst_RecFlag1 = 0x00;
  1305. WeightConst_Drop = 1; //开始抛弃数据
  1306. WeightConst_RecWeightPoint1 = 0; //指针还原
  1307. } else
  1308. WeightConst_RecWeightPoint1++;
  1309. }
  1310. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1311. }
  1312. else
  1313. {
  1314. WeightConst_RecWeightPoint1++;
  1315. }
  1316. }
  1317. static void P_NEWLabel() {
  1318. // 57 20 FC 01 29 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 C4 00 88 00 80 00 00 00 00 00 08 40 44 8C 00
  1319. // 20 20 20 20 20 20 20 4E 45 54 20 57 45 49 47 48 54 20 20 20 20 20 20 20 54 4F 54 41 4C 20 57 45 49 47
  1320. // 48 54 3A 20 20 20 20 20 20 20 20 31 35 20 58 80 5C
  1321. //4F 54 41 4C 20 57 45 49 47 48 54 3A 20 20 20 20 20 20 20 20 31 35 20
  1322. // 16 17 18 19 20 21
  1323. //波特率 115200
  1324. WeightConst_RecWeightPoint1++;
  1325. if (WeightConst_RecWeightPoint1>60) WeightConst_RecWeightPoint1 = 0; //指针还原
  1326. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1327. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x4F) {
  1328. WeightConst_RecWeightData1[0] = 0x4F;
  1329. WeightConst_RecWeightPoint1 = 0; //指针还原
  1330. WeightConst_RecFlag1 = 0x00;
  1331. WeightConst_Drop = 0;
  1332. }
  1333. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1334. {
  1335. // if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x74
  1336. // && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x68
  1337. // && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x67) //英展电子秤
  1338. {
  1339. //C9 74 2D 35 38 31 30 80 00 00 54 6F 74 61 6C 20 77 65 69 67 68 74
  1340. // if (WeightConst_RecWeightPoint1 == 22 && WeightConst_RecWeightData1[0] == 0xC9 && WeightConst_RecWeightData1[22] == 0x74) {
  1341. // if (WeightConst_RecWeightPoint1 == 6 && WeightConst_RecWeightData1[0] == 0x02) {
  1342. if (WeightConst_RecWeightPoint1 == 21 && WeightConst_RecWeightData1[0] == 0x4F && WeightConst_RecWeightData1[1] == 0x54 && WeightConst_RecWeightData1[2] == 0x41) {
  1343. WeightConst_WeightCurTem = 0;
  1344. WeightConst_WeightCurTemZF = 0;
  1345. WeightConst_WeightWS = 0;
  1346. WeightConst_Weight_ZWS = 0;
  1347. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  1348. if (WeightConst_RecWeightData1[ReadWeight_i + 16] >= 0x30
  1349. && WeightConst_RecWeightData1[ReadWeight_i + 16] <= 0x39) {
  1350. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1351. + (WeightConst_RecWeightData1[ReadWeight_i + 16] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1352. WeightConst_Weight_ZWS++;
  1353. } else if (WeightConst_RecWeightData1[ReadWeight_i + 16] == 0x2D) {
  1354. WeightConst_WeightCurTemZF = 1;
  1355. }
  1356. }
  1357. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1358. setWeightSM();
  1359. WeightConst_RecFlag1 = 0x00;
  1360. WeightConst_Drop = 1; //开始抛弃数据
  1361. }
  1362. }
  1363. }
  1364. }
  1365. static void P_PTM() {
  1366. // 02 30 30 54 4F 54 41 4C 20 57 45 49 47 48 54 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4B 67 20 20 20 20 20 38 54 20 80 81 81 38 3E 03
  1367. //波特率 38400
  1368. WeightConst_RecWeightPoint1++;
  1369. if (WeightConst_RecWeightPoint1>68) WeightConst_RecWeightPoint1 = 0; //指针还原
  1370. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1371. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  1372. WeightConst_RecWeightData1[0] = 0x02;
  1373. WeightConst_RecWeightPoint1 = 0; //指针还原
  1374. WeightConst_RecFlag1 = 0x00;
  1375. WeightConst_Drop = 0;
  1376. }
  1377. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1378. {
  1379. // if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x74
  1380. // && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x68
  1381. // && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x67) //英展电子秤
  1382. {
  1383. //C9 74 2D 35 38 31 30 80 00 00 54 6F 74 61 6C 20 77 65 69 67 68 74
  1384. // if (WeightConst_RecWeightPoint1 == 22 && WeightConst_RecWeightData1[0] == 0xC9 && WeightConst_RecWeightData1[22] == 0x74) {
  1385. // if (WeightConst_RecWeightPoint1 == 6 && WeightConst_RecWeightData1[0] == 0x02) {
  1386. if (WeightConst_RecWeightPoint1 == 48 && WeightConst_RecWeightData1[0] == 0x02 && WeightConst_RecWeightData1[48] == 0x03) {
  1387. WeightConst_WeightCurTem = 0;
  1388. WeightConst_WeightCurTemZF = 0;
  1389. WeightConst_WeightWS = 0;
  1390. WeightConst_Weight_ZWS = 0;
  1391. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1392. if (WeightConst_RecWeightData1[ReadWeight_i + 35] >= 0x30
  1393. && WeightConst_RecWeightData1[ReadWeight_i + 35] <= 0x39) {
  1394. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1395. + (WeightConst_RecWeightData1[ReadWeight_i + 35] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1396. WeightConst_Weight_ZWS++;
  1397. } else if (WeightConst_RecWeightData1[ReadWeight_i + 35] == 0x2D) {
  1398. WeightConst_WeightCurTemZF = 1;
  1399. }
  1400. }
  1401. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1402. setWeightSM();
  1403. WeightConst_RecFlag1 = 0x00;
  1404. WeightConst_Drop = 1; //开始抛弃数据
  1405. }
  1406. }
  1407. }
  1408. }
  1409. static void P_XDNZ_BC02() {
  1410. // 02 22 32 20 30 30 30 30 30 33 30 30 30 30 30 30 0D -3
  1411. // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D 48
  1412. // 02 22 30 20 30 30 30 30 36 34 30 30 30 30 30 30 0D 64
  1413. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  1414. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1415. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] & 0x7F;
  1416. if (WeightConst_RecWeightPoint1>=1 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  1417. WeightConst_RecWeightData1[0] = 0x02;
  1418. WeightConst_RecWeightPoint1 = 0; //指针还原
  1419. WeightConst_RecFlag1 = 0x00;
  1420. WeightConst_Drop = 0;
  1421. }
  1422. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1423. {
  1424. if (WeightConst_RecWeightPoint1<34) {
  1425. if (WeightConst_RecWeightPoint1 >= 16
  1426. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-16]==0x02
  1427. && (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-14]==0x30
  1428. || WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-14]==0x32)
  1429. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x0D) {
  1430. WeightConst_WeightCurTem = 0;
  1431. WeightConst_WeightWS = 0;
  1432. WeightConst_Weight_ZWS = 0;
  1433. // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D 48
  1434. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1435. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] >= 0x30
  1436. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] <= 0x39)
  1437. {
  1438. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1439. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] -0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1440. WeightConst_Weight_ZWS++;
  1441. }
  1442. }
  1443. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-14] == 0x32)
  1444. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1445. WeightConst_WeightWS = 0; //设置小数位数
  1446. setWeightSM();
  1447. WeightConst_RecFlag1 = 0x00;
  1448. WeightConst_Drop = 1; //开始抛弃数据
  1449. WeightConst_RecWeightPoint1 = 0; //指针还原
  1450. }else if (WeightConst_RecWeightPoint1 >= 7
  1451. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-7]==0x02
  1452. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x04){
  1453. WeightConst_WeightCurTem = 0;
  1454. WeightConst_WeightWS = 0;
  1455. WeightConst_Weight_ZWS = 0;
  1456. WeightConst_WeightCurTemZF=0;
  1457. //1B 4F 6D 30 32 02 2D 31 33 32 30 36 04 1B 4F 61 40 40 41 40 40 45 04 1B 4F 75 30 36 04 1A 04
  1458. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1459. if (WeightConst_RecWeightData1[ReadWeight_i + 1] >= 0x30
  1460. && WeightConst_RecWeightData1[ReadWeight_i + 1] <= 0x39)
  1461. {
  1462. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1463. + (WeightConst_RecWeightData1[ReadWeight_i +1] -0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1464. WeightConst_Weight_ZWS++;
  1465. }else if (WeightConst_RecWeightData1[ReadWeight_i + 1] == 0x2D)
  1466. {
  1467. WeightConst_WeightCurTemZF=1;
  1468. };
  1469. }
  1470. if (WeightConst_WeightCurTemZF>0) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1471. WeightConst_WeightWS = 0; //设置小数位数
  1472. setWeightSM();
  1473. WeightConst_RecFlag1 = 0x00;
  1474. WeightConst_Drop = 1; //开始抛弃数据
  1475. WeightConst_RecWeightPoint1 = 0; //指针还原
  1476. }
  1477. else
  1478. WeightConst_RecWeightPoint1++;
  1479. }
  1480. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1481. }
  1482. else
  1483. {
  1484. WeightConst_RecWeightPoint1++;
  1485. }
  1486. }
  1487. static void P_ID511() {
  1488. // 02 3A 50 70 30 30 30 30 30 35 30 30 30 30 30 30 0D
  1489. // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D
  1490. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  1491. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1492. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  1493. WeightConst_RecWeightData1[0] = 0x02;
  1494. WeightConst_RecWeightPoint1 = 0; //指针还原
  1495. WeightConst_RecFlag1 = 0x00;
  1496. WeightConst_Drop = 0;
  1497. }
  1498. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1499. {
  1500. if (WeightConst_RecWeightPoint1<34) {
  1501. if (WeightConst_RecWeightPoint1 >= 16
  1502. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-16]==0x02
  1503. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x0D) {
  1504. WeightConst_WeightCurTem = 0;
  1505. WeightConst_WeightWS = 0;
  1506. WeightConst_Weight_ZWS = 0;
  1507. // 02 3A 50 70 30 30 30 30 30 35 30 30 30 30 30 30 0D
  1508. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1509. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] >= 0x30
  1510. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] <= 0x39)
  1511. {
  1512. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1513. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] -0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1514. WeightConst_Weight_ZWS++;
  1515. }
  1516. }
  1517. //if ((WeightConst_RecWeightData1[2] & 0x02)>0)
  1518. // WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1519. if (WeightConst_RecWeightData1[2] ==0x62)
  1520. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1521. WeightConst_WeightWS = 0; //设置小数位数
  1522. setWeightSM();
  1523. WeightConst_RecFlag1 = 0x00;
  1524. WeightConst_Drop = 1; //开始抛弃数据
  1525. WeightConst_RecWeightPoint1 = 0; //指针还原
  1526. } else
  1527. WeightConst_RecWeightPoint1++;
  1528. }
  1529. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1530. }
  1531. else
  1532. {
  1533. WeightConst_RecWeightPoint1++;
  1534. }
  1535. }
  1536. static void P_AD250() {
  1537. // C9 20 20 20 20 33 38 3B 34 D9 38
  1538. // C9 20 20 C4 31 32 38 36 38 D9 -128
  1539. // C9 30 20 20 31 33 32 3C 3F D9 132
  1540. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  1541. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1542. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0xC9) {
  1543. WeightConst_RecWeightData1[0] = 0xC9;
  1544. WeightConst_RecWeightPoint1 = 0; //指针还原
  1545. WeightConst_RecFlag1 = 0x00;
  1546. WeightConst_Drop = 0;
  1547. }
  1548. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1549. {
  1550. if (WeightConst_RecWeightPoint1<34) {
  1551. if (WeightConst_RecWeightPoint1 >= 9
  1552. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-9]==0xC9
  1553. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0xD9) {
  1554. WeightConst_WeightCurTem = 0;
  1555. WeightConst_WeightWS = 0;
  1556. WeightConst_Weight_ZWS = 0;
  1557. WeightConst_WeightCurTemZF = 0;
  1558. // C9 54 20 20 20 20 30 3C 3D D9
  1559. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1560. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 8] >= 0x30
  1561. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 8] <= 0x39)
  1562. {
  1563. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1564. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 8] -0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1565. WeightConst_Weight_ZWS++;
  1566. }
  1567. else if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 8] == 0xC4)
  1568. WeightConst_WeightCurTemZF = 1;
  1569. }
  1570. if (WeightConst_WeightCurTemZF)
  1571. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1572. WeightConst_WeightWS = 0; //设置小数位数
  1573. setWeightSM();
  1574. WeightConst_RecFlag1 = 0x00;
  1575. WeightConst_Drop = 1; //开始抛弃数据
  1576. WeightConst_RecWeightPoint1 = 0; //指针还原
  1577. } else
  1578. WeightConst_RecWeightPoint1++;
  1579. }
  1580. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1581. }
  1582. else
  1583. {
  1584. WeightConst_RecWeightPoint1++;
  1585. }
  1586. }
  1587. extern unsigned char eid[10];
  1588. unsigned long long curEID = 0; //当前临时耳标
  1589. unsigned long long lastEID = 0; //上次临时耳标
  1590. static void ReadEID() {
  1591. // 02 03 00 16 00 0a 24 3a
  1592. // 02 03 14 ff 57 83 e7 00 6b 96 1d 5d 00 ff 10 43 e6 1c be 99 1a 15 df 5d 31
  1593. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  1594. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1595. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  1596. WeightConst_RecWeightData1[0] = 0x02;
  1597. WeightConst_RecWeightPoint1 = 0; //指针还原
  1598. WeightConst_RecFlag1 = 0x00;
  1599. WeightConst_Drop = 0;
  1600. }
  1601. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1602. {
  1603. if (WeightConst_RecWeightPoint1<34) {
  1604. if (WeightConst_RecWeightPoint1 >= 3
  1605. && (WeightConst_RecWeightPoint1 >= WeightConst_RecWeightData1[2]+2)) {
  1606. // 02 03 14 ff 57 83 e7 00 6b 96 1d 5d 00 ff 10 43 e6 1c be 99 1a 15 df 5d 31
  1607. eid[0]=5;
  1608. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++)
  1609. eid[ReadWeight_i+1] = WeightConst_RecWeightData1[ReadWeight_i+7];
  1610. eid[eid[0]+1]= WeightConst_RecWeightData1[3];
  1611. eid[eid[0]+2]= WeightConst_RecWeightData1[4];
  1612. // eid[1]=0x00;eid[2]=0x0C;eid[3]=0x12;eid[4]=0x63;eid[5]=0xE0;
  1613. if (eid[eid[0]+1] ==0xFF){
  1614. WeightConst_feed[0]=0xCE;
  1615. WeightConst_feed[1]=0xDE;
  1616. WeightConst_feed[2]=0xB6;
  1617. WeightConst_feed[3]=0xFA;
  1618. WeightConst_feed[4]=0xB1;
  1619. WeightConst_feed[5]=0xEA;
  1620. WeightConst_feed[6]=0x20;
  1621. WeightConst_feed[7]=0x20;
  1622. }
  1623. else
  1624. {
  1625. curEID = 0;
  1626. for (int i = 0; i < eid[0]; i++) {
  1627. curEID = curEID << 8;
  1628. curEID = curEID | eid[i+1];
  1629. }
  1630. if (WeightConst_WeightCur>30 && lastEID != curEID)
  1631. {
  1632. sendEIDWeight(eid, WeightConst_WeightCur);
  1633. lastEID = curEID;
  1634. }
  1635. rt_memset(WeightConst_feed, 0x20, 40);
  1636. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
  1637. if (SendDisplay_i>0) curEID=curEID/10;
  1638. if (abs(curEID)>0) WeightConst_feed[7-SendDisplay_i] = abs(curEID%10)+'0';
  1639. else break;
  1640. }
  1641. }
  1642. WeightConst_RecFlag1 = 0x00;
  1643. WeightConst_Drop = 1; //开始抛弃数据
  1644. WeightConst_RecWeightPoint1 = 0; //指针还原
  1645. } else
  1646. WeightConst_RecWeightPoint1++;
  1647. }
  1648. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1649. }
  1650. else
  1651. {
  1652. WeightConst_RecWeightPoint1++;
  1653. }
  1654. }
  1655. void ReadWeight(void)
  1656. {
  1657. rt_sem_take(display_lock, RT_WAITING_FOREVER);
  1658. if (WeightConst_TQ==0)
  1659. P_XDNZ_BC02();
  1660. else if (WeightConst_TQ==1)
  1661. //P_300G0();
  1662. P_XDNZ_BC02();
  1663. //P_NEWLabel();
  1664. else if (WeightConst_TQ==2)
  1665. //P_300G1();
  1666. P_AWT_ZM303();
  1667. else if (WeightConst_TQ==3)
  1668. XK3190_A27E();
  1669. else if (WeightConst_TQ==4)
  1670. P_TMI_II();
  1671. else if (WeightConst_TQ==5)
  1672. P_TMI_III();
  1673. else if (WeightConst_TQ==6)
  1674. P_EZ4300();
  1675. else if (WeightConst_TQ==7)
  1676. //P_TQ();
  1677. P_AD250();
  1678. else if (WeightConst_TQ==8)
  1679. P_PTM();
  1680. else if (WeightConst_TQ==9)
  1681. P_T_2000();
  1682. //P_HF();
  1683. else if (WeightConst_TQ==10)
  1684. P_XL10000();
  1685. else if (WeightConst_TQ==11)
  1686. P_XK3190_C8();
  1687. else if (WeightConst_TQ==12)
  1688. P_TDI200I();
  1689. //P_E_2000();
  1690. else if (WeightConst_TQ==13)
  1691. P_ID511();
  1692. else if (WeightConst_TQ==14) {
  1693. if (iscowweight==1) {
  1694. ReadEID();
  1695. }
  1696. else {
  1697. while (rb_full_count(rb_usart1) > 0) {
  1698. rb_remove(rb_usart1);
  1699. }
  1700. }
  1701. }
  1702. rt_sem_release(display_lock);
  1703. }
  1704. uint16_t tempWeight;
  1705. uint16_t tempWeighttime = 0;
  1706. void ReadWeightthread(void) {
  1707. while(1)
  1708. {
  1709. if (WeightConst_TQ==14 );// && CanButton== 0x01);
  1710. {
  1711. tempWeight = get_weight();
  1712. rt_sem_take(display_lock, RT_WAITING_FOREVER);
  1713. if (nag) WeightConst_WeightCurTem = (signed long)(tempWeight*-1);
  1714. else WeightConst_WeightCurTem = (signed long)(tempWeight);
  1715. WeightConst_WeightWS = ad_Point;
  1716. setWeightSM();
  1717. rt_sem_release(display_lock);
  1718. }
  1719. rt_thread_mdelay(125);
  1720. }
  1721. }
  1722. union timekeyweight_t getTimeWeight(int i) {
  1723. if ((i==0xF1) && (WeightConst_WeightOK > -32768)) {
  1724. WeightConst_WeightLast = WeightConst_WeightOK; //保存按键时的重量
  1725. WeightConst_WeightOK = 0;
  1726. }
  1727. else {
  1728. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  1729. WeightConst_WeightLast = WeightConst_WeightCur; //保存按键时的重量
  1730. rt_sem_release(weight_lock);
  1731. }
  1732. union timekeyweight_t timekeyweight;
  1733. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  1734. timekeyweight.data.datetime.year = TimeConst.data.year;
  1735. timekeyweight.data.datetime.month = TimeConst.data.month;
  1736. timekeyweight.data.datetime.date = TimeConst.data.date;
  1737. timekeyweight.data.datetime.hh = TimeConst.data.hh;
  1738. timekeyweight.data.datetime.mm = TimeConst.data.mm;
  1739. timekeyweight.data.datetime.ss = TimeConst.data.ss;
  1740. rt_sem_release(setTIME_lock);
  1741. timekeyweight.data.WeightBegin = WeightConst_WeightBegin;
  1742. timekeyweight.data.WeightLast = WeightConst_WeightLast;
  1743. timekeyweight.data.WeightWS = WeightConst_WeightWS;
  1744. timekeyweight.data.WeightZF = 0;
  1745. timekeyweight.data.reserved = 0;
  1746. timekeyweight.data.WeightRun = 1;
  1747. // if (WeightConst_WeightLast < 0)
  1748. // s[8] = (0<<7) | (WeightConst_WeightWS<<6>>1);
  1749. // else
  1750. // s[8] = (0<<7) | (WeightConst_WeightWS<<6>>1);
  1751. return timekeyweight;
  1752. }
  1753. static rt_thread_t checkweight_tid = RT_NULL;
  1754. static rt_thread_t readweight_tid = RT_NULL;
  1755. void ReadWeight_thread(void)
  1756. {
  1757. if (WeightConst_TQ==14 )
  1758. {
  1759. readweight_tid = rt_thread_create("ReadWeight",
  1760. ReadWeightthread, RT_NULL,
  1761. 0x800,
  1762. 4, 5);
  1763. /* 如果获得线程控制块,启动这个线程 */
  1764. if (readweight_tid != RT_NULL) rt_thread_startup(readweight_tid);
  1765. }
  1766. }
  1767. void CheckWeight_thread(void)
  1768. {
  1769. checkweight_tid = rt_thread_create("CheckWeight",
  1770. CheckWeightthread, RT_NULL,
  1771. 0x400,
  1772. 4, 5);
  1773. /* 如果获得线程控制块,启动这个线程 */
  1774. if (checkweight_tid != RT_NULL) rt_thread_startup(checkweight_tid);
  1775. }
  1776. void ReadEIDthread(void) {
  1777. while (1) {
  1778. rt_sem_take(uart1_lock, RT_WAITING_FOREVER);
  1779. // 02 03 00 16 00 05 64 3E
  1780. // 02 03 00 16 00 0a 24 3a
  1781. usart1_send_data[0] = 0x02;
  1782. usart1_send_data[1] = 0x03;
  1783. usart1_send_data[2] = 0x00;
  1784. usart1_send_data[3] = 0x16;
  1785. usart1_send_data[4] = 0x00;
  1786. usart1_send_data[5] = 0x05;
  1787. usart1_send_data[6] = 0x64;
  1788. usart1_send_data[7] = 0x3e;
  1789. HAL_UART_Transmit_DMA(&huart1, usart1_send_data, 8); //remoteSerial
  1790. rt_thread_mdelay(50);
  1791. rt_sem_release(uart1_lock);
  1792. rt_thread_mdelay(1000);
  1793. }
  1794. }
  1795. static rt_thread_t readEID_tid = RT_NULL;
  1796. void ReadEID_thread(void)
  1797. {
  1798. extern unsigned char iscowweight;
  1799. if (iscowweight==1 )
  1800. {
  1801. readEID_tid = rt_thread_create("ReadEID",
  1802. ReadEIDthread, RT_NULL,
  1803. 0x200,
  1804. 4, 5);
  1805. /* 如果获得线程控制块,启动这个线程 */
  1806. if (readEID_tid != RT_NULL) rt_thread_startup(readEID_tid);
  1807. }
  1808. }