weight.c 88 KB

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