weight.c 88 KB

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