weight.c 88 KB

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