weight.c 88 KB

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