weight.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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 = 1200;
  74. }
  75. else if (WeightConst_TQ==4)
  76. uartHandle->Init.BaudRate = 19200;
  77. else if (WeightConst_TQ==8)
  78. uartHandle->Init.BaudRate = 38400;
  79. // else if (WeightConst_TQ==9)
  80. // uartHandle->Init.BaudRate = 1200;
  81. else if (WeightConst_TQ==9)
  82. {
  83. uartHandle->Init.BaudRate = 9600;
  84. uartHandle->Init.Parity = UART_PARITY_NONE;
  85. uartHandle->Init.WordLength = UART_WORDLENGTH_8B; //8位数据
  86. // uartHandle->Init.StopBits = UART_STOPBITS_2; //停止位2位 海丰需要
  87. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  88. }
  89. else if (WeightConst_TQ==10)
  90. {
  91. uartHandle->Init.BaudRate = 9600;
  92. uartHandle->Init.Parity = UART_PARITY_NONE;
  93. uartHandle->Init.WordLength = UART_WORDLENGTH_8B; //8位数据
  94. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  95. }
  96. else
  97. uartHandle->Init.BaudRate = 9600;
  98. if (iscowweight==1 ){
  99. uartHandle->Init.BaudRate = 19200;
  100. uartHandle->Init.Parity = UART_PARITY_NONE;
  101. uartHandle->Init.WordLength = UART_WORDLENGTH_9B; //8位数据
  102. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  103. }
  104. }
  105. else if (uartHandle->Instance==UART5)
  106. {
  107. uartHandle->Init.BaudRate = 9600;
  108. }
  109. // else if ((uartHandle->Instance==USART3) && (iscowweight==1))
  110. // {
  111. // uartHandle->Init.BaudRate = 19200;
  112. // uartHandle->Init.Parity = UART_PARITY_EVEN;
  113. // uartHandle->Init.WordLength = UART_WORDLENGTH_9B; //8位数据
  114. // uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  115. // }
  116. }
  117. static void setWeightSM() { // 设定合计重量
  118. if ((WeightConst_WeightCurTem > (WeightConst_WeightCurTemLast+1000) ||
  119. (WeightConst_WeightCurTem < (WeightConst_WeightCurTemLast - 1000) && WeightConst_WeightCurTem!=32768))
  120. && WeightConst_RecWeight_he3 < 3)
  121. {
  122. WeightConst_WeightCurTem = WeightConst_WeightCurTemLast;
  123. WeightConst_RecWeight_he3 ++;
  124. }
  125. else //if (WeightConst_WeightCurTem>-32768)
  126. {
  127. WeightConst_WeightCurTemLast = WeightConst_WeightCurTem;
  128. WeightConst_RecWeight_he3 = 0;
  129. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  130. if (WeightConst_WeightMax < WeightConst_WeightCurTem) WeightConst_WeightMax = WeightConst_WeightCurTem; //修改最大重量
  131. if (WeightConst_WeightMin > WeightConst_WeightCurTem) WeightConst_WeightMin = WeightConst_WeightCurTem; //修改最小重量
  132. WeightConst_WeightSum = WeightConst_WeightSum + WeightConst_WeightCurTem; // 重量和
  133. WeightConst_WeightCount++; // 重量采样数
  134. WeightConst_allsum++;
  135. rt_sem_release(weight_lock);
  136. if (isTag==2)
  137. {
  138. get_modbusmsg(1,10,308,WeightConst_WeightCurTem);
  139. }
  140. //判断是否在范围内
  141. if(pf_comp.data.autosecond>0 && WeightConst_WeightHaveBegin==1 && WeightConst_Product_Run > 0) { //跳转时间大于0
  142. if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin &&
  143. WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMax && WeightConst_ChanCheShu>1)
  144. || (WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0 && WeightConst_ChanCheShu==1)) //大目标 为正,且当前值小于大目标
  145. {
  146. if ((WeightConst_SBType==4||WeightConst_SBType==6) && WeightConst_Stop==0 && isn==0) {
  147. rt_event_send(&display_event, EVENT_Stop);
  148. WeightConst_Stop=1;
  149. }
  150. WeightConst_oksum++;
  151. WeightConst_WeightOK=WeightConst_WeightCurTem;
  152. }
  153. if (WeightConst_WeightCurTem > WeightConst_WeightTargetAllowMax)
  154. WeightConst_joksum++;
  155. //WeightConst_WeightTargetAllow
  156. if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)
  157. ||(WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1))
  158. {
  159. alarm_on();
  160. //----------------------------if (WeightConst_SBType==5) ControlPlay(2, 1);
  161. }
  162. else if ((WeightConst_WeightCurTem < WeightConst_WeightTargetAllowMin && pf_comp.data.addorout == 0)
  163. || (WeightConst_WeightCurTem > WeightConst_WeightTargetAllowMin && pf_comp.data.addorout == 1))
  164. {
  165. //----------------------------if (WeightConst_SBType==5) ControlPlay(2, 0);
  166. alarm_off();
  167. }
  168. }
  169. }
  170. HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin);
  171. }
  172. void readnumber(unsigned char* weightbuf, unsigned char length, unsigned char idlelength,
  173. unsigned char wlength, unsigned char zfpos,unsigned char fchar,unsigned char pointpos){
  174. signed long WeightCurTem_ = 0;
  175. unsigned char WeightCurTemZF = 0;
  176. unsigned char WeightWS = 0;
  177. unsigned char Weight_ZWS = 0;
  178. unsigned char curchar = 0;
  179. WeightCurTem_ = 0;
  180. for (int ReadWeight_i = 0; ReadWeight_i < wlength; ReadWeight_i++) {
  181. curchar = weightbuf[length -idlelength - wlength +ReadWeight_i] ;
  182. if (curchar >= 0x30 && curchar <= 0x39) {
  183. WeightCurTem_ = WeightCurTem_ + (curchar - 0x30) * mypow(10, wlength - 1 - ReadWeight_i); //计算重量,无小数位的
  184. Weight_ZWS++;
  185. }
  186. else if (curchar == fchar && zfpos == 0xFF)
  187. WeightCurTemZF = 1;
  188. else if (curchar == 0x2E) {
  189. WeightWS = wlength - 1 - ReadWeight_i; //设置小数位数
  190. WeightCurTem_ = WeightCurTem_ / 10;
  191. }
  192. }
  193. if (pointpos < 0xFF && WeightWS==0 && weightbuf[length-pointpos]>0x30 && weightbuf[length-pointpos]<0x34){
  194. WeightWS = weightbuf[length-pointpos] - 0x30; //设置小数位数
  195. }
  196. if (zfpos < 0xFF && ((weightbuf[length-zfpos]&fchar) == fchar) && WeightCurTemZF == 0)
  197. WeightCurTemZF = 1;
  198. if (WeightCurTemZF == 1) WeightCurTem_ = WeightCurTem_ * -1;
  199. WeightConst_WeightCurTem = WeightCurTem_;
  200. WeightConst_WeightCurTemZF = WeightCurTemZF;
  201. WeightConst_WeightWS = WeightWS;
  202. WeightConst_Weight_ZWS = Weight_ZWS;
  203. setWeightSM();
  204. }
  205. void sendWeight() {
  206. /* key0 协议 34字节(上报实时重量):0x7E 0x20 0x01 0xF0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 1位起始位 + 1位长度 + 1位源地址 + 1位命令 + 28位重量(四段) + 1帧编号 + 1校验
  207. */
  208. if (rb_full_count(RecWeightQueue) > 28) {
  209. unsigned char buf[34] ;
  210. unsigned char CRCNum=0;
  211. buf[0]= 0x7E;
  212. buf[1]= 0x20;
  213. buf[2]= XbeeConst_DeviceAddress;
  214. buf[3]= 0xF0;
  215. for (int i=0; i <28; i++) buf[i+4]= rb_remove(RecWeightQueue);
  216. buf[32] = XbeeConst_FrameNum ++;
  217. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR3, buf[32]);
  218. for (int i=0; i< 33; i++) CRCNum+=buf[i];
  219. buf[33]= 0xff - CRCNum;
  220. for (int i=0; i <(int)(sizeof(buf)/sizeof(unsigned char)); i++)
  221. rb_push_insert(SendWeightQueue,buf[i]);
  222. }
  223. }
  224. void sendEIDWeight(unsigned char * eidbuf, signed short WeightCur) {
  225. /* key6 协议 34字节(上报电子称重):0x7E 0x0D 0x01 0xF6 0x00 0x00 0x00 0x00 0x00 0x00 0x00 1位起始位 + 1位长度 + 1位源地址 + 1位命令 + 7位耳标 + 2位重量 + 1帧编号 + 1校验
  226. */
  227. unsigned char buf[15] ;
  228. unsigned char CRCNum=0;
  229. if( eidbuf[0] == 5 && WeightCur>20){
  230. buf[0]= 0x7E;
  231. buf[1]= 0x0D;
  232. buf[2]= XbeeConst_DeviceAddress;
  233. buf[3]= 0xF6;
  234. for (int i=0; i <7; i++) buf[i+4]= eidbuf[i+1];
  235. buf[11]= (WeightCur>>8) &0xFF;
  236. buf[12]= WeightCur &0xFF;
  237. buf[13] = XbeeConst_FrameNum ++;
  238. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR3, buf[13]);
  239. for (int i=0; i< 14; i++) CRCNum+=buf[i];
  240. buf[14]= 0xff - CRCNum;
  241. for (int i=0; i <(int)(sizeof(buf)/sizeof(unsigned char)); i++)
  242. rb_push_insert(SendWeightQueue,buf[i]);
  243. }
  244. }
  245. void CheckWeightthread(void) {
  246. while (1) {
  247. if (WeightConst_DELAYON>0) //搅拌延时
  248. {
  249. WeightConst_DELAYTIME ++;
  250. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR5, WeightConst_DELAYTIME);
  251. if (WeightConst_DELAYTIME > (pf_comp.data.delaytime * 60)) //10 &&pf_comp.data.delaytime>0 )
  252. {
  253. write_Flash("begintime", &TimeConst, sizeof(TimeConst));
  254. WeightConst_WeightBegin = WeightConst_WeightCur;
  255. write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
  256. pf_comp.data.delaytime = 0;
  257. WeightConst_DELAYTIME = 0;
  258. WeightConst_DELAYON = 0;
  259. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR4, 0);
  260. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR5, 0);
  261. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR6, 0);
  262. rt_sem_release(pop_product_sem);//弹出最新内容
  263. }
  264. }
  265. // else {
  266. // WeightConst_DELAYTIME = 0;
  267. // WeightConst_DELAYON=0;
  268. // }
  269. if ( WeightConst_allsum > 0) {
  270. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  271. if (WeightConst_WeightCount>2) {
  272. WeightConst_WeightSum = WeightConst_WeightSum - WeightConst_WeightMin; // 重量和 减去最小值
  273. WeightConst_WeightSum = WeightConst_WeightSum - WeightConst_WeightMax; // 重量和 减去最大值
  274. WeightConst_WeightCount = WeightConst_WeightCount - 2;
  275. }
  276. if (WeightConst_WeightCount>0)
  277. WeightConst_WeightCur = WeightConst_WeightSum / WeightConst_WeightCount;
  278. else
  279. WeightConst_WeightCur = WeightConst_WeightCurTem;
  280. WeightConst_WeightSum = 0;
  281. WeightConst_WeightCount = 0; //重量数
  282. WeightConst_WeightMax = -32768; //最大重量
  283. WeightConst_WeightMin = 32767; //最小重量
  284. if (WeightConst_WeightCurCount >= 0x0F) { //15秒准备发送后台重
  285. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  286. timeweight.Buffer[3] =TimeConst.Buffer[0];
  287. timeweight.Buffer[4] =TimeConst.Buffer[1];
  288. timeweight.Buffer[5] =TimeConst.Buffer[2];
  289. timeweight.Buffer[6] =TimeConst.Buffer[3];
  290. rt_sem_release(setTIME_lock);
  291. timeweight.data.Weight = WeightConst_WeightCur;
  292. timeweight.data.WeightWS = WeightConst_WeightWS;
  293. timeweight.data.WeightRun = WeightConst_Product_Run;
  294. timeweight.data.reserved = 0;
  295. ts_pushArrary(&ts_weightdb, timeweight.Buffer, 7);
  296. WeightConst_WeightCur_last3 = WeightConst_WeightCur_last2;
  297. WeightConst_WeightCur_last2 = WeightConst_WeightCur_last1;
  298. WeightConst_WeightCur_last1 = WeightConst_WeightCur;
  299. // if (WeightConst_WeightCur<0)
  300. // rb_push_insert(RecWeightQueue, (0<<7) | (WeightConst_WeightWS<<6>>1));//这边有问题,需要修改
  301. // else
  302. // rb_push_insert(RecWeightQueue, (0<<7) | (WeightConst_WeightWS<<6>>1));//这边有问题,需要修改
  303. WeightConst_WeightCurCount=0;
  304. }
  305. rt_sem_release(weight_lock);
  306. if (WeightConst_Product_Run > 0) {
  307. if (WeightConst_AutoSingleNSecondPoint >= (pf_comp.data.autosecond * 3) || WeightConst_AutoSingleNSecondPoint>=30)
  308. WeightConst_AutoSingleNSecondPoint = 0;
  309. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][0] = WeightConst_oksum;
  310. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][1] = WeightConst_allsum;
  311. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][2] = WeightConst_joksum;
  312. WeightConst_AutoSingleNSecondPoint++;
  313. WeightConst_uoksum = 0;
  314. WeightConst_uallsum = 0;
  315. WeightConst_foksum = 0;
  316. for (int CheckWeight_i = 0; CheckWeight_i < (pf_comp.data.autosecond * 3); CheckWeight_i++) {
  317. WeightConst_uoksum = WeightConst_uoksum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][0];
  318. WeightConst_uallsum = WeightConst_uallsum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][1];
  319. WeightConst_foksum = WeightConst_foksum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][2];
  320. }
  321. if (WeightConst_uallsum == 0)
  322. WeightConst_uallsum = 100; //如果没接称,allsum有可能为0,此处进行保护
  323. WeightConst_autotpo = WeightConst_uoksum * 100 / WeightConst_uallsum; //合理停留秒数内接收到的符合跳转的数据占总接收数据的百分比
  324. if (WeightConst_autotpo > 100) WeightConst_autotpo = 0; //对百分比进行保护
  325. if ((WeightConst_autotpo > WeightConst_WeightTargetTpo)
  326. || ((WeightConst_foksum * 100 / WeightConst_uallsum)>WeightConst_WeightTargetTpo
  327. && pf_comp.data.JMP)
  328. ) //触发自动按键
  329. {
  330. for (int CheckWeight_i = 0; CheckWeight_i < 30; CheckWeight_i++) {
  331. WeightConst_AutoSingleNSecondNum[CheckWeight_i][0]=0;
  332. WeightConst_AutoSingleNSecondNum[CheckWeight_i][1]=0;
  333. WeightConst_AutoSingleNSecondNum[CheckWeight_i][2]=0;
  334. }
  335. if (WeightConst_DELAYON == 0 && delayKeying == 0)
  336. {
  337. rt_sem_release(delay_key_sem);
  338. sendkey1(0xF1, 0);
  339. }
  340. button_state.b1 = 1; //5秒内禁止按1键
  341. }
  342. WeightConst_oksum = 0;
  343. WeightConst_joksum = 0;
  344. WeightConst_allsum = 0;
  345. WeightConst_uoksum = 0;
  346. WeightConst_uallsum = 0;
  347. WeightConst_foksum = 0;
  348. // sendWeight(); //检查是否需要保存实时重量
  349. }
  350. }
  351. WeightConst_WeightCurCount++;
  352. if (WeightConst_Product_Run > 0)
  353. {
  354. if (WeightConst_Nextfeed[0] == 0x20){
  355. if (findNextplan()>0)
  356. rt_event_send(&display_event, EVENT_Next);
  357. }
  358. if (WeightConst_Product_Run_time < 65535 && WeightConst_Product_Run_time>0 && pf_comp.data.addorout==0)
  359. WeightConst_Product_Run_time++;
  360. // else
  361. // WeightConst_Product_Run_time = 0;
  362. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR3, WeightConst_Product_Run_time);
  363. }
  364. rt_thread_mdelay(1000);
  365. }
  366. }
  367. static void P_TDI200I() {
  368. // 02 20 2D 20 20 20 36 37 2E 30 6B 67 03 -67.0KG 300G0
  369. // 02 20 20 20 20 20 36 37 2E 36 6B 7F 03 300G0
  370. // 02 2B 30 30 30 30 30 30 33 03 300G0
  371. // 02 2D 20 20 20 36 37 2E 30 6B 67 03 -67.0KG 300G1
  372. // 02 20 20 20 20 32 2E 33 30 6B 67 03 300G1
  373. //02 2B 30 30 30 30 30 30 33 03
  374. //02 +/- 十万 万 千 百 十 个 小数点位数 03 TDI200I
  375. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  376. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  377. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02) {
  378. WeightConst_RecWeightData1[0] = 0x02;
  379. WeightConst_RecWeightPoint1 = 0;
  380. }
  381. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03)
  382. {
  383. if (WeightConst_RecWeightPoint1>11 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x6B)
  384. {
  385. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 2, 7, 0x0A, 0x2d, 0xFF);
  386. }
  387. else if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x6B)
  388. {
  389. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 2, 7, 0x0A,0x2d, 0xFF);
  390. }
  391. else if (WeightConst_RecWeightPoint1==9)
  392. {
  393. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 1, 6, 0x08,0x2d, 0x01);
  394. }
  395. WeightConst_RecWeightPoint1 = 0; //指针还原
  396. } else {
  397. WeightConst_RecWeightPoint1++;
  398. }
  399. }
  400. static void P_XK3190_C8() {
  401. //兼容XK3118K9
  402. //02 2D 30 30 30 31 32 30 31 03
  403. //02 2D 30 30 30 31 32 30 31 31 46 03
  404. //02 +/- 0 1 2 3 4 5 点位数 03
  405. //02 47 20 20 20 37 37 30 36 20 20 2C 30 31 2D 30 31 2D 30 36 2C 30 30 3A 30 30 3A 34 31 03 04 1B
  406. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  407. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  408. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02) {
  409. WeightConst_RecWeightData1[0] = 0x02;
  410. WeightConst_RecWeightPoint1 = 0;
  411. }
  412. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03)
  413. {
  414. if (WeightConst_RecWeightPoint1==29)
  415. { //02 2D 30 30 30 31 32 30 31 03
  416. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 20, 6, 0xFF, 0x2d, 0xFF);
  417. }
  418. else if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x6B)
  419. { //02 2D 20 20 20 36 37 2E 31 6B 67 03
  420. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 2, 6, 0x0A, 0x2d, 0x02);
  421. }
  422. else if (WeightConst_RecWeightPoint1==9)
  423. { //02 47 20 20 20 37 37 30 36 20 20 2C 30 31 2D 30 31 2D 30 36 2C 30 30 3A 30 30 3A 34 31 03 04 1B
  424. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 0, 6, 0x08, 0x2d, 0x01);
  425. }
  426. WeightConst_RecWeightPoint1 = 0; //指针还原
  427. } else {
  428. WeightConst_RecWeightPoint1++;
  429. }
  430. }
  431. static void P_AWH_30_SA() {
  432. //展会 //53 54 2C 47 53 2C 2B 20 20 30 2E 38 37 36 6B 67 0d 0a
  433. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  434. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  435. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A)
  436. {
  437. if (WeightConst_RecWeightPoint1==17)
  438. {
  439. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 3, 7, 0x0B, 0x2d, 0xFF);
  440. }
  441. WeightConst_RecWeightPoint1 = 0; //指针还原
  442. } else {
  443. WeightConst_RecWeightPoint1++;
  444. }
  445. }
  446. static void P_digi() {
  447. //2E 44 30 2D 20 20 2D 33 36 30 30 30 39 09
  448. //2E 44 30 2D 20 33 39 32 32 30 30 30 42 09
  449. //2E 44 30 74 54 6F 74 61 6C 20 57 65 69 67 68 74 20 38 09
  450. if (WeightConst_RecWeightPoint1>140) WeightConst_RecWeightPoint1 = 0; //指针还原
  451. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  452. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x2E) {
  453. WeightConst_RecWeightData1[0] = 0x2E;
  454. WeightConst_RecWeightPoint1 = 0;
  455. }
  456. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09)
  457. {
  458. if (WeightConst_RecWeightPoint1 == 13 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10] == 0x2D)
  459. {
  460. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 4, 5, 0x0A, 0x2d, 0xFF);
  461. }
  462. WeightConst_RecWeightPoint1 = 0; //指针还原
  463. } else {
  464. WeightConst_RecWeightPoint1++;
  465. }
  466. }
  467. static void P_AWT_ZM303() {
  468. //展会 //20 20 20 20 20 31 37 34 20 6B 67 20 47 0D 0A
  469. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  470. if (WeightConst_RecWeightPoint1>50) WeightConst_RecWeightPoint1 = 0; //指针还原
  471. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  472. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A)
  473. {
  474. if (WeightConst_RecWeightPoint1 == 13 && WeightConst_RecWeightData1[0] == 0x3D) {
  475. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  476. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 5, 6, 0x0C, 0x2d, 0xFF);
  477. }
  478. else if (WeightConst_RecWeightPoint1 == 14 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-5]==0x6B ) {
  479. //20 20 20 20 20 31 37 34 20 6B 67 20 47 0D 0A
  480. //20 20 20 20 20 2D 31 38 20 6B 67 20 47 0D 0A
  481. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 6, 6, 0xFF, 0x2d, 0xFF);
  482. }
  483. else if (WeightConst_RecWeightPoint1 == 43 && WeightConst_RecWeightData1[0] == 0x31) {
  484. // 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
  485. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 28, 6, 0xFF, 0x2d, 0xFF);
  486. }
  487. WeightConst_RecWeightPoint1 = 0; //指针还原
  488. } else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09)
  489. {
  490. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10] == 0x2D) {
  491. // 2E 44 30 2D 20 20 2D 33 36 30 30 30 39 09
  492. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 4, 5, 0xFF, 0x2d, 0xFF);
  493. }
  494. WeightConst_RecWeightPoint1 = 0; //指针还原
  495. }
  496. else {
  497. WeightConst_RecWeightPoint1++;
  498. }
  499. }
  500. static void P_T_2000() {
  501. // 55 53 2C 47 53 20 20 20 20 32 2E 37 32 6B 67 0D 0A 2.72 不稳定
  502. // 53 54 2C 47 53 20 20 20 20 32 2E 34 33 6B 67 0D 0A 2.43 稳定
  503. // 55 53 2C 47 53 2D 20 20 20 30 2E 33 38 6B 67 0D 0A -0.38 不稳定
  504. // 77 6E 30 30 30 30 38 33 33 35 6B 67 0D 0A
  505. if (WeightConst_RecWeightPoint1>40) WeightConst_RecWeightPoint1 = 0; //指针还原
  506. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  507. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A)
  508. {
  509. if (WeightConst_RecWeightPoint1 == 12) {
  510. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 3, 6, 0xFF, 0x2d, 0xFF);
  511. }
  512. else if (WeightConst_RecWeightPoint1>=13) {
  513. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 3, 7, 11, 0x2d, 0xFF);
  514. }
  515. WeightConst_RecWeightPoint1 = 0; //指针还原
  516. } else {
  517. WeightConst_RecWeightPoint1++;
  518. }
  519. }
  520. static void P_HF() {
  521. // 01 10 00 01 00 02 04 00 00 17 9C 3D FA 01 10 00 01 00 02 10 08
  522. // 02 10 00 01 00 02 04 08 00 00 A2 BE FE 02 10 00 01 00 02 10 3B
  523. // 03 10 00 01 00 02 04 08 00 00 A4 3A 00 03 10 00 01 00 02 10 3B
  524. signed long WeightCurTem_ = 0;
  525. if (WeightConst_RecWeightPoint1>140) WeightConst_RecWeightPoint1 = 0; //指针还原
  526. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  527. if (WeightConst_RecFlag1 != 0xF0) //上一条完整数据没有处理完
  528. {
  529. if ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]&0xf0) == 0x10 &&
  530. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x02 &&
  531. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x00 &&
  532. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-3] == 0x01 &&
  533. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-4] == 0x00 &&
  534. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-5] == 0x10 &&
  535. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-6] == XbeeConst_DeviceAddress) //英展电子秤
  536. {
  537. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19] == XbeeConst_DeviceAddress)
  538. {
  539. WeightCurTem_ = 0;
  540. WeightCurTem_ = ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-11]<<16)
  541. |
  542. (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10]<<8)
  543. |
  544. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-9]);
  545. if ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-12]&0x08) == 0x08){
  546. WeightCurTem_ = WeightCurTem_ * -1;
  547. WeightConst_WeightCurTemZF = 1;
  548. }
  549. WeightConst_WeightCurTem = WeightCurTem_;
  550. WeightConst_WeightWS = 0;
  551. WeightConst_Weight_ZWS = 0;
  552. setWeightSM();
  553. WeightConst_RecFlag1 = 0x00;
  554. WeightConst_Drop = 0; //开始抛弃数据
  555. }
  556. WeightConst_RecWeightPoint1 = 0; //指针还原
  557. } else {
  558. WeightConst_RecWeightPoint1++;
  559. }
  560. }
  561. else
  562. {
  563. WeightConst_RecWeightPoint1++;
  564. }
  565. }
  566. static void P_E_2000() {
  567. // 3D 30 30 30 30 31 30 30 0D 0A
  568. // 3D 2D 30 30 30 31 30 30 0D 0A
  569. if (WeightConst_RecWeightPoint1>40) WeightConst_RecWeightPoint1 = 0; //指针还原
  570. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  571. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A)
  572. {
  573. if (WeightConst_RecWeightPoint1 == 9) {
  574. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 1, 6, 8, 0x2d, 0xFF);
  575. }
  576. WeightConst_RecWeightPoint1 = 0; //指针还原
  577. } else {
  578. WeightConst_RecWeightPoint1++;
  579. }
  580. }
  581. static void P_TMI_II() {
  582. //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
  583. //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
  584. //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
  585. //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
  586. if (WeightConst_RecWeightPoint1>53) WeightConst_RecWeightPoint1 = 0; //指针还原
  587. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  588. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x23){
  589. WeightConst_RecWeightData1[0] = 0x23;
  590. WeightConst_RecWeightPoint1 = 0;
  591. }
  592. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D) //英展电子秤
  593. {
  594. if (WeightConst_RecWeightPoint1>11 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x0A &&
  595. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-12] == 0x23 )
  596. {
  597. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 2, 5,0xFF,0x2d, 0xFF);
  598. }
  599. WeightConst_RecWeightPoint1 = 0; //指针还原
  600. } else {
  601. WeightConst_RecWeightPoint1++;
  602. }
  603. }
  604. static void P_TMI_III() {
  605. //0x20 0x2d 0x31 0x34 0x32 0x0d -142
  606. //2D 33 36 35 34 0D
  607. if (WeightConst_RecWeightPoint1>17) WeightConst_RecWeightPoint1 = 0; //指针还原
  608. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  609. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D) //英展电子秤
  610. {
  611. if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x29 &&
  612. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-4] == 0x28 )
  613. { //3D 30 30 30 30 30 30 36 28 6B 67 29 0D 0A
  614. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  615. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1,4, 5,11,0x2d, 0xFF);
  616. }
  617. else if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x67 &&
  618. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x6B )
  619. {
  620. //77 6E 2D 30 30 30 30 30 35 31 6B 67 0D 0A
  621. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1,2, 5,10,0x2d, 0xFF);
  622. }
  623. else if (WeightConst_RecWeightPoint1>4 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] != 0x20) {
  624. //2D 33 36 35 34 0D
  625. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1,0, 5, 0xff,0x2d, 0xFF);
  626. }
  627. WeightConst_RecWeightPoint1 = 0; //指针还原
  628. } else {
  629. WeightConst_RecWeightPoint1++;
  630. }
  631. }
  632. static void P_EZ4300() {
  633. //82 2D A0 A0 A0 B1 39 8D 库恩表头出来是7位数据,8位是校验位,将数据的高位去掉,则得到下面正确的数据
  634. //02 2D 20 20 20 31 39 0D
  635. //02 47 20 20 20 37 37 30 36 20 20 2C 30 31 2D 30 31 2D 30 36 2C 30 30 3A 30 30 3A 34 31 03 04 1B
  636. //02 47 20 20 20 37 37 30 36 20 20 2C 30 31 2D 30 31 2D 30 36 2C 30 30 3A 30 30 3A 34 31 03 04 1B
  637. if (WeightConst_RecWeightPoint1>10) WeightConst_RecWeightPoint1 = 0; //指针还原
  638. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1) & 0x7F;
  639. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02) {
  640. WeightConst_RecWeightData1[0] = 0x02;
  641. WeightConst_RecWeightPoint1 = 0;
  642. }
  643. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D)
  644. {
  645. if (WeightConst_RecWeightPoint1 == 7)
  646. {
  647. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 0, 5, 6, 0x2d, 0xFF);
  648. }
  649. WeightConst_RecWeightPoint1 = 0; //指针还原
  650. } else {
  651. WeightConst_RecWeightPoint1++;
  652. }
  653. }
  654. static void P_TQ() {
  655. // 7E 7E F0 10 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 AB FE
  656. // 7E 7E F0 10 00 00 00 00 00 00 00 03 04 00 00 00 00 00 03 04 F2 FE
  657. // 7E 7E F0 10 01 00 00 00 00 00 00 06 08 80 00 00 00 00 06 08 63 FE
  658. // 7E 7E FF 10 01 00 00 00 00 00 00 06 08 80 00 00 00 00 06 08 54 FE
  659. if (WeightConst_RecWeightPoint1>43) WeightConst_RecWeightPoint1 = 0; //指针还原
  660. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  661. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0xFE)
  662. {
  663. if (WeightConst_RecWeightPoint1 >= 21 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-21]==0x7E
  664. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-20]==0x7E
  665. && (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19]==0xF0 || WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19]==0xFF)
  666. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-17]!=0x55)
  667. {
  668. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 1, 6, 8, 0x80, 0xFF);
  669. }
  670. WeightConst_RecWeightPoint1 = 0; //指针还原
  671. } else {
  672. WeightConst_RecWeightPoint1++;
  673. }
  674. }
  675. static void P_XL10000() {
  676. // 02 2A 30 20 30 30 30 32 32 30 30 30 30 30 30 30 0D 33
  677. if (WeightConst_RecWeightPoint1>38) WeightConst_RecWeightPoint1 = 0; //指针还原
  678. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1) & 0x7F;
  679. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02) {
  680. WeightConst_RecWeightData1[0] = 0x02;
  681. WeightConst_RecWeightPoint1 = 0;
  682. }
  683. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D)
  684. {
  685. if (WeightConst_RecWeightPoint1 == 16)
  686. {
  687. readnumber(WeightConst_RecWeightData1,WeightConst_RecWeightPoint1, 5, 6, 14, 0x02, 0xFF);
  688. }
  689. WeightConst_RecWeightPoint1 = 0; //指针还原
  690. } else {
  691. WeightConst_RecWeightPoint1++;
  692. }
  693. }
  694. static void P_XK3190_A27E() {
  695. // 77 6E 30 30 30 30 30 36 31 35 6B 67 0D 0A 615 boudrate=1200
  696. // 77 6E 2D 30 30 30 30 30 36 35 6B 67 0D 0A -65
  697. // 77 6E 2D 30 30 30 31 32 20 6B 67 0D 0A
  698. // 77 6E 30 30 30 30 31 2E 32 6B 67 0D 0A
  699. if (WeightConst_RecWeightPoint1>37) WeightConst_RecWeightPoint1 = 0; //指针还原
  700. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  701. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x77) {
  702. WeightConst_RecWeightData1[0] = 0x77;
  703. WeightConst_RecWeightPoint1 = 0;
  704. }
  705. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A)
  706. {
  707. if (WeightConst_RecWeightPoint1 == 13) {
  708. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 4, 6, 11, 0x2d, 0xFF);
  709. }
  710. else if (WeightConst_RecWeightPoint1 == 12) {
  711. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 3, 6, 10, 0x2d, 0xFF);
  712. }
  713. WeightConst_RecWeightPoint1 = 0; //指针还原
  714. } else {
  715. WeightConst_RecWeightPoint1++;
  716. }
  717. }
  718. static void P_NEWLabel() {
  719. // 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
  720. // 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
  721. //4F 54 41 4C 20 57 45 49 47 48 54 3A 20 20 20 20 20 20 20 20 31 35 20 58 80 5C
  722. //4F 54 41 4C 20 57 45 49 47 48 54 3A 20 20 20 20 20 20 20 20 31 35 20
  723. // 16 17 18 19 20 21
  724. //波特率 115200
  725. if (WeightConst_RecWeightPoint1>60) WeightConst_RecWeightPoint1 = 0; //指针还原
  726. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  727. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x4F) {
  728. WeightConst_RecWeightData1[0] = 0x4F;
  729. WeightConst_RecWeightPoint1 = 0;
  730. }
  731. if (WeightConst_RecWeightPoint1 == 21)
  732. {
  733. if (WeightConst_RecWeightData1[0] == 0x4F && WeightConst_RecWeightData1[1] == 0x54 && WeightConst_RecWeightData1[2] == 0x41)
  734. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 0, 7, 0xFF, 0x2d, 0xFF);
  735. WeightConst_RecWeightPoint1 = 0; //指针还原
  736. } else {
  737. WeightConst_RecWeightPoint1++;
  738. }
  739. }
  740. static void P_PTM() {
  741. // 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
  742. //波特率 38400
  743. if (WeightConst_RecWeightPoint1>68) WeightConst_RecWeightPoint1 = 0; //指针还原
  744. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  745. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02) {
  746. WeightConst_RecWeightData1[0] = 0x02;
  747. WeightConst_RecWeightPoint1 = 0;
  748. }
  749. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03)
  750. {
  751. if (WeightConst_RecWeightPoint1 == 48 )
  752. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 7, 6, 11, 0x2d, 0xFF);
  753. WeightConst_RecWeightPoint1 = 0; //指针还原
  754. } else {
  755. WeightConst_RecWeightPoint1++;
  756. }
  757. }
  758. static void P_XDNZ_BC02() {
  759. // 02 22 32 20 30 30 30 30 30 33 30 30 30 30 30 30 0D -3
  760. // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D 48
  761. // 02 22 30 20 30 30 30 30 36 34 30 30 30 30 30 30 0D 64
  762. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  763. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1) & 0x7F;
  764. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02) {
  765. WeightConst_RecWeightData1[0] = 0x02;
  766. WeightConst_RecWeightPoint1 = 0;
  767. }
  768. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D)
  769. { // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D 48
  770. if (WeightConst_RecWeightPoint1 == 16)
  771. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 6, 6, 14, 0x32, 0xFF);
  772. WeightConst_RecWeightPoint1 = 0; //指针还原
  773. }
  774. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x04){
  775. //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
  776. if (WeightConst_RecWeightPoint1 == 7)
  777. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 0, 6, 0xFF, 0x2D, 0xFF);
  778. WeightConst_RecWeightPoint1 = 0; //指针还原
  779. }
  780. else {
  781. WeightConst_RecWeightPoint1++;
  782. }
  783. }
  784. static void P_ID511() {
  785. // 02 3A 50 70 30 30 30 30 30 35 30 30 30 30 30 30 0D
  786. // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D
  787. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  788. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  789. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02) {
  790. WeightConst_RecWeightData1[0] = 0x02;
  791. WeightConst_RecWeightPoint1 = 0;
  792. }
  793. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D)
  794. {
  795. if (WeightConst_RecWeightPoint1 == 16)
  796. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 6, 6, 15, 0x62, 0xFF);
  797. WeightConst_RecWeightPoint1 = 0; //指针还原
  798. } else {
  799. WeightConst_RecWeightPoint1++;
  800. }
  801. }
  802. static void P_AD250() {
  803. // C9 20 20 20 20 33 38 3B 34 D9 38
  804. // C9 20 20 C4 31 32 38 36 38 D9 -128
  805. // C9 30 20 20 31 33 32 3C 3F D9 132
  806. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  807. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  808. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0xC9) {
  809. WeightConst_RecWeightData1[0] = 0xC9;
  810. WeightConst_RecWeightPoint1 = 0;
  811. }
  812. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0xD9)
  813. {
  814. if (WeightConst_RecWeightPoint1 == 9)
  815. readnumber(WeightConst_RecWeightData1, WeightConst_RecWeightPoint1, 2, 6, 0xFF, 0xC4, 0xFF);
  816. WeightConst_RecWeightPoint1 = 0; //指针还原
  817. } else {
  818. WeightConst_RecWeightPoint1++;
  819. }
  820. }
  821. extern unsigned char eid[10];
  822. unsigned long long curEID = 0; //当前临时耳标
  823. unsigned long long lastEID = 0; //上次临时耳标
  824. static void ReadEID() {
  825. // 02 03 00 16 00 0a 24 3a
  826. // 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
  827. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  828. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  829. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  830. WeightConst_RecWeightData1[0] = 0x02;
  831. WeightConst_RecWeightPoint1 = 0; //指针还原
  832. WeightConst_RecFlag1 = 0x00;
  833. WeightConst_Drop = 0;
  834. }
  835. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  836. {
  837. if (WeightConst_RecWeightPoint1<34) {
  838. if (WeightConst_RecWeightPoint1 >= 3
  839. && (WeightConst_RecWeightPoint1 >= WeightConst_RecWeightData1[2]+2)) {
  840. // 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
  841. eid[0]=5;
  842. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++)
  843. eid[ReadWeight_i+1] = WeightConst_RecWeightData1[ReadWeight_i+7];
  844. eid[eid[0]+1]= WeightConst_RecWeightData1[3];
  845. eid[eid[0]+2]= WeightConst_RecWeightData1[4];
  846. // eid[1]=0x00;eid[2]=0x0C;eid[3]=0x12;eid[4]=0x63;eid[5]=0xE0;
  847. if (eid[eid[0]+1] ==0xFF){
  848. WeightConst_feed[0]=0xCE;
  849. WeightConst_feed[1]=0xDE;
  850. WeightConst_feed[2]=0xB6;
  851. WeightConst_feed[3]=0xFA;
  852. WeightConst_feed[4]=0xB1;
  853. WeightConst_feed[5]=0xEA;
  854. WeightConst_feed[6]=0x20;
  855. WeightConst_feed[7]=0x20;
  856. }
  857. else
  858. {
  859. curEID = 0;
  860. for (int i = 0; i < eid[0]; i++) {
  861. curEID = curEID << 8;
  862. curEID = curEID | eid[i+1];
  863. }
  864. if (WeightConst_WeightCur>30 && lastEID != curEID)
  865. {
  866. sendEIDWeight(eid, WeightConst_WeightCur);
  867. lastEID = curEID;
  868. }
  869. rt_memset(WeightConst_feed, 0x20, 40);
  870. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
  871. if (SendDisplay_i>0) curEID=curEID/10;
  872. if (abs(curEID)>0) WeightConst_feed[7-SendDisplay_i] = abs(curEID%10)+'0';
  873. else break;
  874. }
  875. }
  876. WeightConst_RecFlag1 = 0x00;
  877. WeightConst_Drop = 1; //开始抛弃数据
  878. WeightConst_RecWeightPoint1 = 0; //指针还原
  879. } else
  880. WeightConst_RecWeightPoint1++;
  881. }
  882. else WeightConst_RecWeightPoint1 = 0; //指针还原
  883. }
  884. else
  885. {
  886. WeightConst_RecWeightPoint1++;
  887. }
  888. }
  889. void ReadWeight(void)
  890. {
  891. rt_sem_take(display_lock, RT_WAITING_FOREVER);
  892. if (WeightConst_TQ==0)
  893. P_XDNZ_BC02();
  894. else if (WeightConst_TQ==1)
  895. //P_300G0();
  896. P_XDNZ_BC02();
  897. //P_NEWLabel();
  898. else if (WeightConst_TQ==2)
  899. //P_300G1();
  900. P_AWT_ZM303();
  901. else if (WeightConst_TQ==3)
  902. P_XK3190_A27E();
  903. else if (WeightConst_TQ==4)
  904. P_TMI_II();
  905. else if (WeightConst_TQ==5)
  906. P_TMI_III();
  907. else if (WeightConst_TQ==6)
  908. P_EZ4300();
  909. else if (WeightConst_TQ==7)
  910. //P_TQ();
  911. P_AD250();
  912. else if (WeightConst_TQ==8)
  913. P_PTM();
  914. else if (WeightConst_TQ==9)
  915. P_T_2000();
  916. //P_HF();
  917. else if (WeightConst_TQ==10)
  918. P_XL10000();
  919. else if (WeightConst_TQ==11)
  920. P_XK3190_C8();
  921. else if (WeightConst_TQ==12)
  922. P_TDI200I();
  923. //P_E_2000();
  924. else if (WeightConst_TQ==13)
  925. P_ID511();
  926. else if (WeightConst_TQ==14) {
  927. if (iscowweight==1) {
  928. ReadEID();
  929. }
  930. else {
  931. while (rb_full_count(rb_usart1) > 0) {
  932. rb_remove(rb_usart1);
  933. }
  934. }
  935. }
  936. rt_sem_release(display_lock);
  937. }
  938. uint16_t tempWeight;
  939. uint16_t tempWeighttime = 0;
  940. void ReadWeightthread(void) {
  941. WeightConst_WeightCurTem = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR7);
  942. while(1)
  943. {
  944. if (WeightConst_TQ==14 );// && CanButton== 0x01);
  945. {
  946. tempWeight = get_weight();
  947. rt_sem_take(display_lock, RT_WAITING_FOREVER);
  948. if (nag) WeightConst_WeightCurTem = (signed long)(tempWeight*-1);
  949. else WeightConst_WeightCurTem = (signed long)(tempWeight);
  950. HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR7, WeightConst_WeightCurTem);
  951. WeightConst_WeightWS = ad_Point;
  952. setWeightSM();
  953. rt_sem_release(display_lock);
  954. }
  955. rt_thread_mdelay(125);
  956. }
  957. }
  958. union timekeyweight_t getTimeWeight(int i) {
  959. if ((i==0xF1) && (WeightConst_WeightOK > -32768)) {
  960. WeightConst_WeightLast = WeightConst_WeightOK; //保存按键时的重量
  961. WeightConst_WeightOK = -32760;
  962. }
  963. else {
  964. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  965. WeightConst_WeightLast = WeightConst_WeightCur; //保存按键时的重量
  966. rt_sem_release(weight_lock);
  967. }
  968. union timekeyweight_t timekeyweight;
  969. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  970. timekeyweight.data.datetime.year = TimeConst.data.year;
  971. timekeyweight.data.datetime.month = TimeConst.data.month;
  972. timekeyweight.data.datetime.date = TimeConst.data.date;
  973. timekeyweight.data.datetime.hh = TimeConst.data.hh;
  974. timekeyweight.data.datetime.mm = TimeConst.data.mm;
  975. timekeyweight.data.datetime.ss = TimeConst.data.ss;
  976. rt_sem_release(setTIME_lock);
  977. timekeyweight.data.WeightBegin = WeightConst_WeightBegin;
  978. timekeyweight.data.WeightLast = WeightConst_WeightLast;
  979. timekeyweight.data.WeightWS = WeightConst_WeightWS;
  980. timekeyweight.data.WeightZF = 0;
  981. timekeyweight.data.reserved = 0;
  982. timekeyweight.data.WeightRun = 1;
  983. // if (WeightConst_WeightLast < 0)
  984. // s[8] = (0<<7) | (WeightConst_WeightWS<<6>>1);
  985. // else
  986. // s[8] = (0<<7) | (WeightConst_WeightWS<<6>>1);
  987. return timekeyweight;
  988. }
  989. static rt_thread_t checkweight_tid = RT_NULL;
  990. static rt_thread_t readweight_tid = RT_NULL;
  991. void ReadWeight_thread(void)
  992. {
  993. if (WeightConst_TQ==14 )
  994. {
  995. readweight_tid = rt_thread_create("ReadWeight",
  996. ReadWeightthread, RT_NULL,
  997. 0x800,
  998. 4, 5);
  999. /* 如果获得线程控制块,启动这个线程 */
  1000. if (readweight_tid != RT_NULL) rt_thread_startup(readweight_tid);
  1001. }
  1002. }
  1003. void CheckWeight_thread(void)
  1004. {
  1005. checkweight_tid = rt_thread_create("CheckWeight",
  1006. CheckWeightthread, RT_NULL,
  1007. 0x400,
  1008. 4, 5);
  1009. /* 如果获得线程控制块,启动这个线程 */
  1010. if (checkweight_tid != RT_NULL) rt_thread_startup(checkweight_tid);
  1011. }
  1012. void ReadEIDthread(void) {
  1013. while (1) {
  1014. rt_sem_take(uart1_lock, RT_WAITING_FOREVER);
  1015. // 02 03 00 16 00 05 64 3E
  1016. // 02 03 00 16 00 0a 24 3a
  1017. usart1_send_data[0] = 0x02;
  1018. usart1_send_data[1] = 0x03;
  1019. usart1_send_data[2] = 0x00;
  1020. usart1_send_data[3] = 0x16;
  1021. usart1_send_data[4] = 0x00;
  1022. usart1_send_data[5] = 0x05;
  1023. usart1_send_data[6] = 0x64;
  1024. usart1_send_data[7] = 0x3e;
  1025. HAL_UART_Transmit_DMA(&huart1, usart1_send_data, 8); //remoteSerial
  1026. rt_thread_mdelay(50);
  1027. rt_sem_release(uart1_lock);
  1028. rt_thread_mdelay(1000);
  1029. }
  1030. }
  1031. static rt_thread_t readEID_tid = RT_NULL;
  1032. void ReadEID_thread(void)
  1033. {
  1034. extern unsigned char iscowweight;
  1035. if (iscowweight==1 )
  1036. {
  1037. readEID_tid = rt_thread_create("ReadEID",
  1038. ReadEIDthread, RT_NULL,
  1039. 0x200,
  1040. 4, 5);
  1041. /* 如果获得线程控制块,启动这个线程 */
  1042. if (readEID_tid != RT_NULL) rt_thread_startup(readEID_tid);
  1043. }
  1044. }