control.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774
  1. #include <control.h>
  2. /*
  3. * Copyright (c) 2006-2020, RT-Thread Development Team
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-05-30 Administrator the first version
  10. */
  11. #include "beep.h"
  12. #include "hmi.h"
  13. #include "easyflash.h"
  14. #include "stdio.h"
  15. #include "sound.h"
  16. #include "dtu_uart2.h"
  17. #include "sht30_collect.h"
  18. #include <user_mb_app.h>
  19. #define DBG_ENABLE
  20. #define DBG_COLOR
  21. #define DBG_TAG "control"
  22. #define DBG_LEVEL DBG_LOG
  23. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  24. //工作检测
  25. #define WORK_CHECK_THREAD_PRIORITY 23 //线程优先级
  26. #define WORK_CHECK_THREAD_STACK_SIZE 1024 //栈大小
  27. #define WORK_CHECK_THREAD_TIMESLICE 5 //时间片
  28. //工作流程
  29. #define WORK_LOOP_THREAD_PRIORITY 12 //线程优先级
  30. #define WORK_LOOP_THREAD_STACK_SIZE 2048 //栈大小
  31. #define WORK_LOOP_THREAD_TIMESLICE 5 //时间片
  32. #define PWM_EN 1 //0关闭,1-打开
  33. //设备状态表结构体
  34. Device_Status_typedef device_status;
  35. rt_thread_t tid_workloop = RT_NULL;
  36. rt_thread_t tid_wkstc = RT_NULL;
  37. rt_thread_t tid_ctr = RT_NULL;
  38. rt_thread_t tid_heat = RT_NULL;
  39. rt_thread_t tid_485_play = RT_NULL;
  40. rt_event_t event_485_play;
  41. extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
  42. /***************************************************************************/
  43. int thread_delete_workloop(void)
  44. {
  45. rt_err_t result;
  46. if(tid_workloop!=RT_NULL)
  47. {
  48. result = rt_thread_delete(tid_workloop);
  49. }
  50. return result;
  51. }
  52. int thread_restart_workloop(void)
  53. {
  54. rt_err_t result;
  55. result = Work_Loop_Task();
  56. return result;
  57. }
  58. /***************************************************************************/
  59. /* ==================== OTA 升级前的线程清理 ==================== */
  60. #define OTA_THREAD_MAX 24
  61. /* 保留名单: 这几类线程删掉反而会让升级失败 */
  62. static const char *g_ota_keep[] =
  63. {
  64. "syswatch", /* 喂狗线程: 删了 5s 后硬件看门狗就复位, 升级必中断 */
  65. "tshell", /* 控制台 */
  66. "tidle",
  67. "main",
  68. };
  69. /* 需要停掉的业务线程(写完整名即可, 比较时自动按 RT_NAME_MAX-1 截断)。
  70. *
  71. * 为什么用"前缀匹配 + 遍历"而不是 rt_thread_find(全名):
  72. * rtconfig.h 里 RT_NAME_MAX = 8, 线程名被内核截断到 7 个字符 ——
  73. * "Control_Clear_thread_entry" / "Control_Heat_thread_entry" 都变成 "Control";
  74. * "DTU_Uart_thread_send" / "DTU_Uart_thread_recv" 都截成 "DTU_Uar",
  75. * 而 recv 正是执行升级的当前线程, 用 rt_thread_find 有可能把调用者自己删掉。
  76. * 所以改成遍历线程对象链表, 并显式跳过 rt_thread_self()。 */
  77. static const char *g_ota_stop[] =
  78. {
  79. "work_loop_thread", /* 工作流程 */
  80. "work_status_check_thread", /* WorkCheck */
  81. "Control_Clear_thread_entry", /* 清扫, 会驱动电机 */
  82. "Control_Heat_thread_entry", /* 恒温 */
  83. "sht30_collect_thread", /* 光控/温控, 每 5s 打一行 LOG_I */
  84. "Power Check thread", /* 每秒读电流/电压 */
  85. "Hmi_Fresh_thread", /* 屏幕刷新 */
  86. "Ctr motor", /* 仓门/光源, 带 rt_kprintf */
  87. "sys_monitor", /* CPU/统计 */
  88. "DTU_Uart_thread_send", /* DTU 发送 (recv 是自身, 会被跳过) */
  89. "md_m_poll", /* modbus 轮询 */
  90. "md_m_send", /* modbus 发送 */
  91. "usage", /* cpu_usage 临时线程 */
  92. };
  93. /* 名字前缀比较: 内核只存了前 RT_NAME_MAX-1 个字符, 所以最多比这么多 */
  94. static int ota_name_match(const char *thread_name, const char *prefix)
  95. {
  96. rt_size_t n;
  97. if (thread_name == RT_NULL || prefix == RT_NULL || thread_name[0] == '\0')
  98. {
  99. return 0;
  100. }
  101. n = rt_strlen(prefix);
  102. if (n > RT_NAME_MAX - 1)
  103. {
  104. n = RT_NAME_MAX - 1;
  105. }
  106. if (n == 0)
  107. {
  108. return 0;
  109. }
  110. return (rt_strncmp(thread_name, prefix, n) == 0) ? 1 : 0;
  111. }
  112. static int ota_in_list(const char *thread_name, const char **list, int cnt)
  113. {
  114. int i;
  115. for (i = 0; i < cnt; i++)
  116. {
  117. if (ota_name_match(thread_name, list[i]))
  118. {
  119. return 1;
  120. }
  121. }
  122. return 0;
  123. }
  124. /**
  125. * OTA 升级前把所有业务线程停掉, 只留 tshell / idle / syswatch。
  126. *
  127. * 为什么必须停:
  128. * 1) ymodem_ota() 会把 console 切到 uart2(ymodem_ota.c:117), 之后**任何线程**
  129. * 的 LOG_xxx / rt_kprintf 都会打进 uart2, 直接污染 ymodem 字节流 -> 校验失败;
  130. * 2) sht30 / Power Check 持续读 ADC, 抢 CPU 会让 ymodem 丢字节;
  131. * 3) Control_Clear / Control_Heat / Ctr motor 会驱动电机, 升级过程中不该动机械部件。
  132. *
  133. * 实现说明: 本工程的线程**没有** `update_flag==1 break` 这类自退机制, 所以这里
  134. * 不做"置标志 + 等它自己退", 直接遍历 + 强删。强删时若线程正持有 IPC 或外设锁,
  135. * 由于紧接着就进 ymodem、结束即 rt_hw_cpu_reset(), 不会影响升级本身。
  136. * ★ 全程不改 device_status.update_flag —— 那个值一旦被落盘, 下次开机会被
  137. * Check_ParamConfig 判成"有升级请求"而再进 OTA。
  138. *
  139. * @return 实际删除的线程数; 负值为错误
  140. */
  141. int thread_stop_all_for_ota(void)
  142. {
  143. struct rt_object_information *info;
  144. rt_list_t *node;
  145. rt_thread_t victims[OTA_THREAD_MAX];
  146. rt_thread_t self;
  147. int nv = 0, i, done = 0;
  148. info = rt_object_get_information(RT_Object_Class_Thread);
  149. if (info == RT_NULL)
  150. {
  151. LOG_E("[ota] thread object information NOT found");
  152. return -RT_ERROR;
  153. }
  154. /* 收集待停线程。必须"先收集后删除": rt_thread_delete 会摘掉链表节点,
  155. 边遍历边删会把 object_list 走坏 */
  156. self = rt_thread_self();
  157. rt_enter_critical();
  158. rt_list_for_each(node, &info->object_list)
  159. {
  160. rt_thread_t t = rt_list_entry(node, struct rt_thread, list);
  161. if (t == self) /* 不能删自己 */
  162. {
  163. continue;
  164. }
  165. if (ota_in_list(t->name, g_ota_keep, sizeof(g_ota_keep) / sizeof(g_ota_keep[0])))
  166. {
  167. continue;
  168. }
  169. if (!ota_in_list(t->name, g_ota_stop, sizeof(g_ota_stop) / sizeof(g_ota_stop[0])))
  170. {
  171. continue; /* 不在名单里, 不动 */
  172. }
  173. if (nv < OTA_THREAD_MAX)
  174. {
  175. victims[nv++] = t;
  176. }
  177. }
  178. rt_exit_critical();
  179. /* 逐个删除 */
  180. for (i = 0; i < nv; i++)
  181. {
  182. if (rt_thread_delete(victims[i]) == RT_EOK)
  183. {
  184. done++;
  185. }
  186. }
  187. LOG_I("[ota] stopped %d of %d candidate thread(s)", done, nv);
  188. return done;
  189. }
  190. /**************************1.0定制2000W*************************************/
  191. uint8_t ctr_Fan_PUT(uint8_t status_ws)
  192. {
  193. rt_pin_mode(FAN_P, PIN_MODE_OUTPUT);
  194. if(status_ws==ON)
  195. {
  196. rt_pin_write(FAN_P,ON);
  197. }
  198. else {
  199. rt_pin_write(FAN_P, OFF);
  200. }
  201. return 0;
  202. }
  203. uint8_t ctr_Fan_IN(uint8_t status_ws)
  204. {
  205. rt_pin_mode(FAN_I, PIN_MODE_OUTPUT);
  206. if(status_ws==ON)
  207. {
  208. rt_pin_write(FAN_I,ON);
  209. }
  210. else {
  211. rt_pin_write(FAN_I, OFF);
  212. }
  213. return 0;
  214. }
  215. /****************************5.0***********************************/
  216. void ctr_turnv5(void)
  217. {
  218. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  219. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  220. // 转出
  221. rt_pin_write(CLEAR_R,ON);
  222. rt_pin_write(CLEAR_L,OFF);
  223. rt_thread_mdelay(300);
  224. //停止
  225. rt_pin_write(CLEAR_R,OFF);
  226. rt_pin_write(CLEAR_L,OFF);
  227. rt_thread_mdelay(300);
  228. //转入
  229. rt_pin_write(CLEAR_R,OFF);
  230. rt_pin_write(CLEAR_L,ON);
  231. rt_thread_mdelay(300);
  232. //停止
  233. rt_pin_write(CLEAR_R,OFF);
  234. rt_pin_write(CLEAR_L,OFF);
  235. rt_thread_mdelay(300);
  236. }
  237. /**************************机器人********************************/
  238. void ctr_Motor_Robot(uint8_t status_ws)
  239. {
  240. unsigned int close_timeout = 0;
  241. unsigned int open_timeout = 0;
  242. rt_pin_mode(LIMIT_OPEN, PIN_MODE_INPUT);
  243. rt_pin_mode(LIMIT_CLOSE, PIN_MODE_INPUT);
  244. rt_pin_mode(Motor_Power, PIN_MODE_OUTPUT);
  245. rt_pin_mode(Motor_Direction_Button, PIN_MODE_INPUT);
  246. rt_pin_mode(Motor_Direction_Ctr, PIN_MODE_OUTPUT);
  247. rt_pin_write(Motor_Power,OFF);
  248. rt_pin_write(Motor_Direction_Ctr,ON);
  249. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  250. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  251. if(status_ws == ON)
  252. {
  253. //检测按键状态
  254. while(rt_pin_read(Motor_Direction_Button)==1)
  255. {
  256. if(rt_pin_read(LIMIT_CLOSE)==1)
  257. {
  258. rt_pin_write(Motor_Direction_Ctr,ON);
  259. close_timeout++;
  260. //打开电机驱动器电源,默认关闭
  261. rt_pin_write(Motor_Power,ON);
  262. if(close_timeout==2)
  263. {
  264. rt_pin_write(CLEAR_R,ON);
  265. rt_pin_write(CLEAR_L,OFF);
  266. rt_pin_write(Motor_Power,OFF);
  267. rt_thread_delay(20);
  268. rt_pin_write(Motor_Power,ON);
  269. }
  270. rt_thread_delay(20);
  271. if(close_timeout>500)
  272. {
  273. close_timeout = 600;
  274. rt_pin_write(Motor_Power,OFF);
  275. rt_pin_write(CLEAR_R,OFF);
  276. rt_pin_write(CLEAR_L,OFF);
  277. }
  278. }
  279. else
  280. {
  281. close_timeout = 0;
  282. rt_pin_write(Motor_Power,OFF); //关闭驱动器电源
  283. rt_pin_write(CLEAR_R,OFF);
  284. rt_pin_write(CLEAR_L,OFF);
  285. }
  286. rt_thread_delay(20);
  287. }
  288. rt_pin_write(Motor_Power,OFF);
  289. rt_thread_delay(1000*2);
  290. while(rt_pin_read(Motor_Direction_Button)==0)
  291. {
  292. if(rt_pin_read(LIMIT_OPEN)==1)
  293. {
  294. open_timeout ++;
  295. //打开电机驱动器电源,默认关闭
  296. if(open_timeout==2){
  297. rt_pin_write(CLEAR_R,OFF);
  298. rt_pin_write(CLEAR_L,ON);
  299. }
  300. rt_pin_write(Motor_Power,ON);
  301. rt_pin_write(Motor_Direction_Ctr,OFF);
  302. if(open_timeout>500)
  303. {
  304. open_timeout = 600;
  305. rt_pin_write(Motor_Power,OFF);
  306. rt_pin_write(CLEAR_R,OFF);
  307. rt_pin_write(CLEAR_L,OFF);
  308. }
  309. rt_thread_delay(20);
  310. }
  311. if(rt_pin_read(LIMIT_OPEN)==0)
  312. {
  313. open_timeout = 0;
  314. rt_pin_write(Motor_Power,OFF);
  315. rt_pin_write(CLEAR_R,OFF);
  316. rt_pin_write(CLEAR_L,OFF);
  317. }
  318. rt_thread_delay(20);
  319. close_timeout = 0;
  320. }
  321. open_timeout = 0;
  322. close_timeout = 0;
  323. }
  324. else {
  325. rt_pin_write(Motor_Power,OFF);
  326. }
  327. }
  328. /*************************吸虫塔*********************************/
  329. //吸虫电机
  330. uint8_t ctr_Motor_xichong(uint8_t status_ws)
  331. {
  332. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  333. if(status_ws==ON)
  334. {
  335. rt_pin_write(MOTOR1_CTR_PIN,ON);
  336. }
  337. else {
  338. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  339. }
  340. return 0;
  341. }
  342. uint8_t ctr_Camera_Power(uint8_t status_ws)
  343. {
  344. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  345. if(status_ws==ON)
  346. {
  347. rt_pin_write(MOTOR1_CTR_PIN,ON);
  348. }
  349. else {
  350. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  351. }
  352. return 0;
  353. }
  354. //吸附电机
  355. uint8_t ctr_Motor_xifu(uint8_t status_ws)
  356. {
  357. rt_pin_mode(MOTOR2_CTR_PIN, PIN_MODE_OUTPUT);
  358. if(status_ws==ON)
  359. {
  360. rt_pin_write(MOTOR2_CTR_PIN,ON);
  361. }
  362. else {
  363. rt_pin_write(MOTOR2_CTR_PIN, OFF);
  364. }
  365. return 0;
  366. }
  367. //清扫-卷带电机
  368. void ctr_JD_Clear(uint8_t shake_sw)
  369. {
  370. rt_uint16_t turn_timeout = 0;
  371. rt_pin_mode(MOTOR_C_LIMIT,PIN_MODE_INPUT);
  372. ctr_cangmen_up(OFF); //清扫传送带的电机
  373. if(shake_sw==ON)
  374. {
  375. ctr_Heat(ON); //清洁风机
  376. Motor_shake(ON, 0);
  377. ctr_cangmen_up(OPEN); //打开清扫
  378. }
  379. else {
  380. Motor_shake(OFF, 0);
  381. ctr_cangmen_up(OPEN); //打开清扫
  382. }
  383. while(rt_pin_read(MOTOR_C_LIMIT)==0)
  384. {
  385. Motor_Juandai(ON);
  386. rt_thread_delay(50);
  387. turn_timeout++;
  388. if(turn_timeout==1000) break;
  389. }
  390. turn_timeout = 0;
  391. while(rt_pin_read(MOTOR_C_LIMIT)==1)
  392. {
  393. Motor_Juandai(ON);
  394. turn_timeout++;
  395. rt_thread_delay(50);
  396. if(turn_timeout==1000) break;
  397. }
  398. Motor_shake(OFF, 1);
  399. Motor_Juandai(OFF);
  400. ctr_cangmen_up(OFF); //关闭清扫
  401. ctr_Heat(OFF);
  402. }
  403. /**********************************************************************/
  404. /*光控*/
  405. uint8_t In_Light_status(void)
  406. {
  407. rt_pin_mode(LIGHT_PIN,PIN_MODE_INPUT);
  408. return rt_pin_read(LIGHT_PIN);
  409. }
  410. /*雨控*/
  411. uint8_t In_Rain_status(void)
  412. {
  413. rt_pin_mode(RAIN_PIN,PIN_MODE_INPUT);
  414. return rt_pin_read(RAIN_PIN);
  415. }
  416. /*加热*/
  417. uint8_t ctr_Heat(uint8_t status_heat)
  418. {
  419. device_status.heat_status = status_heat;
  420. rt_pin_mode(Heat_Pin, PIN_MODE_OUTPUT);
  421. rt_pin_write(Heat_Pin,status_heat);
  422. return status_heat;
  423. }
  424. /*制冷*/
  425. uint8_t ctr_Cold(uint8_t status_cold)
  426. {
  427. device_status.cold_status = status_cold;
  428. rt_pin_mode(Cold_Pin, PIN_MODE_OUTPUT);
  429. rt_pin_write(Cold_Pin,status_cold);
  430. return status_cold;
  431. }
  432. /*相机供电*/
  433. void ctr_photo(uint8_t status_photo)
  434. {
  435. rt_pin_mode(PHOTO,PIN_MODE_OUTPUT);
  436. rt_pin_write(PHOTO,status_photo);
  437. }
  438. /*************************************************
  439. Function: ctr_Cool_Fan
  440. Description: 散热风机的开关
  441. Calls:
  442. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  443. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  444. Input: ON-开,OFF-关
  445. Output: NULL
  446. Return: ON-开,OFF-关
  447. Others: NULL
  448. *************************************************/
  449. uint8_t ctr_Cool_Fan(uint8_t status_cool)
  450. {
  451. device_status.cool_fan_status = status_cool;
  452. rt_pin_mode(Cool_Fan_L, PIN_MODE_OUTPUT);
  453. rt_pin_mode(Cool_Fan_R, PIN_MODE_OUTPUT);
  454. if(status_cool==OFF)
  455. {
  456. rt_pin_write(Cool_Fan_L,OFF);
  457. rt_pin_write(Cool_Fan_R,OFF);
  458. }
  459. if(status_cool==ON)
  460. {
  461. rt_pin_write(Cool_Fan_L,ON);
  462. rt_pin_write(Cool_Fan_R,OFF);
  463. }
  464. return device_status.cool_fan_status;
  465. }
  466. /*************************************************
  467. Function: ctr_Collect_Fan
  468. Description: 采集风机的开关
  469. Calls:
  470. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  471. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  472. Input: ON-开,OFF-关
  473. Output: NULL
  474. Return: ON-开,OFF-关
  475. Others: NULL
  476. *************************************************/
  477. uint8_t ctr_Collect_Fan(uint8_t status_collect)
  478. {
  479. device_status.collect_fan_status = status_collect;
  480. rt_pin_mode(Collect_Fan, PIN_MODE_OUTPUT);
  481. if(status_collect==OFF)
  482. {
  483. rt_pin_write(Collect_Fan,OFF);
  484. }
  485. if(status_collect==ON)
  486. {
  487. rt_pin_write(Collect_Fan,ON);
  488. }
  489. return device_status.collect_fan_status;
  490. }
  491. /*************************************************
  492. Function: ctr_develop
  493. Description: 培养载玻片孢子
  494. Calls:
  495. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  496. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  497. Input: v=0(复位) v=90转90度
  498. Output: NULL
  499. Return: NULL
  500. Others: NULL
  501. *************************************************/
  502. /*上仓门*/
  503. uint8_t ctr_cangmen_up(uint8_t status_up)
  504. {
  505. rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
  506. rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
  507. if(status_up==OFF)
  508. {
  509. rt_pin_write(Collect_fan_R,ON);
  510. rt_pin_write(Collect_fan_L,ON);
  511. device_status.ctr_up_motor = 0;
  512. rt_thread_delay(1000);
  513. }
  514. if(status_up==OPEN)
  515. {
  516. device_status.up_status = 1;
  517. rt_pin_write(Collect_fan_R,OFF);
  518. rt_pin_write(Collect_fan_L,OFF);
  519. rt_pin_write(Collect_fan_R,ON);
  520. rt_pin_write(Collect_fan_L,OFF);
  521. }
  522. if(status_up==CLOSE)
  523. {
  524. device_status.up_status = 0;
  525. rt_pin_write(Collect_fan_R,OFF);
  526. rt_pin_write(Collect_fan_L,OFF);
  527. rt_pin_write(Collect_fan_R,OFF);
  528. rt_pin_write(Collect_fan_L,ON);
  529. }
  530. return device_status.up_status;
  531. }
  532. //下仓门
  533. uint8_t ctr_cangmen_down(uint8_t status_down)
  534. {
  535. rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
  536. rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
  537. if(status_down==OFF)
  538. {
  539. rt_pin_write(C_DOWN_R,ON);
  540. rt_pin_write(C_DOWN_L,ON);
  541. device_status.ctr_down_motor = 0;
  542. rt_thread_delay(1000);
  543. }
  544. if(status_down==OPEN)
  545. {
  546. device_status.down_status = 1;
  547. rt_pin_write(C_DOWN_R,OFF);
  548. rt_pin_write(C_DOWN_L,OFF);
  549. rt_pin_write(C_DOWN_R,ON);
  550. rt_pin_write(C_DOWN_L,OFF);
  551. }
  552. if(status_down==CLOSE)
  553. {
  554. device_status.down_status = 0;
  555. rt_pin_write(C_DOWN_R,OFF);
  556. rt_pin_write(C_DOWN_L,OFF);
  557. rt_pin_write(C_DOWN_R,OFF);
  558. rt_pin_write(C_DOWN_L,ON);
  559. }
  560. return device_status.down_status;
  561. }
  562. //镇流器
  563. uint8_t ctr_lamp(uint8_t status_lamp,uint8_t lamp_num)
  564. {
  565. rt_pin_mode(LAMP_SW, PIN_MODE_OUTPUT);
  566. rt_pin_mode(LAMP_1_SW, PIN_MODE_OUTPUT);
  567. rt_pin_mode(LAMP_2_SW, PIN_MODE_OUTPUT);
  568. if(status_lamp==ON)
  569. {
  570. switch(lamp_num){
  571. case 1:
  572. rt_pin_write(LAMP_SW,ON);
  573. device_status.lamp_status = status_lamp;
  574. break;
  575. case 2:
  576. rt_pin_write(LAMP_1_SW,ON);
  577. device_status.lamp_status = status_lamp;
  578. break;
  579. case 3:
  580. rt_pin_write(LAMP_2_SW,ON);
  581. device_status.lamp_status = status_lamp;
  582. break;
  583. default:
  584. break;
  585. }
  586. }
  587. else {
  588. switch(lamp_num){
  589. case 1:
  590. rt_pin_write(LAMP_SW,OFF);
  591. device_status.lamp_status = status_lamp;
  592. break;
  593. case 2:
  594. rt_pin_write(LAMP_1_SW,OFF);
  595. device_status.lamp1_status = status_lamp;
  596. break;
  597. case 3:
  598. rt_pin_write(LAMP_2_SW,OFF);
  599. device_status.lamp2_status = status_lamp;
  600. break;
  601. default:
  602. break;
  603. }
  604. }
  605. HMI_WRITE("sysTest.switchLamp.val=%d",device_status.lamp_status);
  606. return device_status.lamp_status;
  607. }
  608. //补光
  609. uint8_t ctr_led(uint8_t status_led)
  610. {
  611. rt_pin_mode(LED_SW, PIN_MODE_OUTPUT);
  612. if(device_status.version_type==6)
  613. rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
  614. if(status_led==ON)
  615. {
  616. rt_pin_write(LED_SW,ON);
  617. if(device_status.version_type==6)
  618. rt_pin_write(LED_P,ON);
  619. HMI_WRITE("sysTest.switchFill.val=%d",ON);
  620. }
  621. else if(status_led==OFF){
  622. rt_pin_write(LED_SW,OFF);
  623. if(device_status.version_type==6)
  624. rt_pin_write(LED_P,OFF);
  625. HMI_WRITE("sysTest.switchPhoto.val=%d",OFF);
  626. HMI_WRITE("sysTest.switchFill.val=%d",OFF);
  627. }
  628. return status_led;
  629. }
  630. /*
  631. *
  632. * */
  633. void ctr_Motor_Driver_Power(uint8_t status_ws)
  634. {
  635. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  636. rt_pin_write(SHAKE_SW, status_ws);
  637. }
  638. /*************************************************
  639. Function: ctr_Motor_Driver
  640. Description: 步进电机驱动
  641. Calls:
  642. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  643. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  644. Input: 50000000
  645. Output: NULL
  646. Return: shake_sec
  647. Others: NULL
  648. *************************************************/
  649. void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_out)
  650. {
  651. beep_init();
  652. rt_pin_mode(LIMIT_UP, PIN_MODE_INPUT);
  653. rt_pin_mode(LIMIT_DOWN, PIN_MODE_INPUT);
  654. rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
  655. rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
  656. if(EN==0)
  657. {
  658. rt_pin_write(Motor_Power,0);
  659. }
  660. else{
  661. rt_pin_write(Motor_EN, EN);
  662. }
  663. rt_pin_write(Motor_DIR, DIR);
  664. beep_set(pwm, pwm/2); //200kzh - 50%
  665. while(DIR==1&&rt_pin_read(LIMIT_DOWN)==1)
  666. {
  667. if(time_out==0)
  668. {
  669. break;
  670. }
  671. rt_thread_delay(50);
  672. time_out --;
  673. }
  674. while(DIR==0&&rt_pin_read(LIMIT_UP)==1)
  675. {
  676. if(time_out==0)
  677. {
  678. break;
  679. }
  680. rt_thread_delay(50);
  681. time_out --;
  682. }
  683. //rt_pin_write(Motor_EN, OFF);
  684. //if(device_status.autotakepic==0)
  685. //ctr_lamp(OFF, 1);
  686. beep_set(0, 0); //200kzh - 50%
  687. rt_thread_delay(50);
  688. }
  689. /*************************************************
  690. Function: ctr_Petroleum_jelly
  691. Description: 涂凡士林
  692. Calls:
  693. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  694. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  695. Input: NULL
  696. Output: NULL
  697. Return: NULL
  698. Others: NULL
  699. *************************************************/
  700. void ctr_Petroleum_jelly(rt_uint32_t delay)
  701. {
  702. beep_init();
  703. pwm_on(2,50000);
  704. rt_thread_delay(delay*1000);
  705. pwm_off(2,0);
  706. rt_thread_delay(1000);
  707. pwm_on(3, 50000);
  708. rt_thread_delay(delay*1000);
  709. pwm_off(3,0);
  710. device_status.fsl_sw = 0;
  711. }
  712. //1.0转仓
  713. void turnzp(void)
  714. {
  715. static uint16_t turn_timeout = 0;
  716. // rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  717. // rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  718. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  719. // rt_pin_write(CLEAR_R,OFF);
  720. // rt_pin_write(CLEAR_L,OFF);
  721. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  722. {
  723. rt_thread_delay(20);
  724. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  725. {
  726. // rt_pin_write(CLEAR_R,ON);
  727. // rt_pin_write(CLEAR_L,OFF);
  728. Motor_Juandai(ON);
  729. rt_thread_delay(50);
  730. turn_timeout++;
  731. if(turn_timeout==600)
  732. {
  733. LOG_E("检测不到限位,电机强制停止");
  734. char *ctr_zp_limit_warn =makeJson_Warn("电流不足/限位超时","转盘电机");
  735. DTU_Write("%s",ctr_zp_limit_warn);
  736. rt_free(ctr_zp_limit_warn);
  737. break;
  738. }
  739. }
  740. break;
  741. }
  742. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  743. {
  744. rt_thread_delay(20);
  745. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  746. {
  747. // rt_pin_write(CLEAR_R,ON);
  748. // rt_pin_write(CLEAR_L,OFF);
  749. Motor_Juandai(ON);
  750. rt_thread_delay(50);
  751. turn_timeout++;
  752. if(turn_timeout==600)
  753. {
  754. LOG_E("检测不到离开限位,电机或者限位开关异常,电机强制停止");
  755. char *ctr_zp_limit_warn =makeJson_Warn("检测不到离开限位,电机未启动或者限位开关故障","转盘电机");
  756. DTU_Write("%s",ctr_zp_limit_warn);
  757. rt_free(ctr_zp_limit_warn);
  758. break;
  759. }
  760. }
  761. break;
  762. }
  763. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  764. {
  765. rt_thread_delay(20);
  766. if(rt_pin_read(CLEAR_R_LIMIT)==0)
  767. {
  768. // rt_pin_write(CLEAR_R,OFF);
  769. // rt_pin_write(CLEAR_L,OFF);
  770. Motor_Juandai(OFF);
  771. break;
  772. }
  773. else {
  774. break;
  775. }
  776. }
  777. Motor_Juandai(OFF);
  778. // rt_pin_write(CLEAR_R,OFF);
  779. // rt_pin_write(CLEAR_L,OFF);
  780. turn_timeout = 0;
  781. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  782. HMI_WRITE("sysTest.switchClear.val=%d",0);
  783. rt_thread_delay(1000);
  784. }
  785. //清扫-常闭型限位开关
  786. //新结构使用推杆电机做清扫
  787. uint8_t ctr_clear(uint16_t status_clear)
  788. {
  789. static uint16_t clear_num = 0;
  790. #if PWM_EN == 0
  791. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  792. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  793. #endif
  794. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  795. rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
  796. /*************************************************************外接清扫
  797. rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  798. rt_pin_write(POWER_CLEAR,ON);
  799. rt_thread_delay(1000*100);
  800. rt_pin_write(POWER_CLEAR,OFF);
  801. ************************************************************/
  802. //停止
  803. #if PWM_EN == 0
  804. rt_pin_write(CLEAR_R,OFF);
  805. rt_pin_write(CLEAR_L,OFF);
  806. #else
  807. Motor_Qingsao_R_PWM(OFF);
  808. Motor_Qingsao_L_PWM(OFF);
  809. #endif
  810. if(status_clear==OFF||Read_Real_Voltage()/100<12) return 0;
  811. rt_thread_delay(100);
  812. //如果清扫位置在中间
  813. while(rt_pin_read(CLEAR_R_LIMIT)==0&&rt_pin_read(CLEAR_L_LIMIT)==0)
  814. {
  815. #if PWM_EN == 0
  816. rt_pin_write(CLEAR_R,ON);
  817. rt_pin_write(CLEAR_L,OFF);
  818. #else
  819. Motor_Qingsao_R_PWM(ON);
  820. Motor_Qingsao_L_PWM(OFF);
  821. #endif
  822. rt_thread_delay(50);
  823. clear_num++;
  824. //已到达检测位置
  825. if(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  826. {
  827. #if PWM_EN == 0
  828. rt_pin_write(CLEAR_R,ON);
  829. rt_pin_write(CLEAR_L,ON);
  830. #else
  831. Motor_Qingsao_R_PWM(OFF);
  832. Motor_Qingsao_L_PWM(OFF);
  833. #endif
  834. rt_thread_delay(2000);
  835. break;
  836. }
  837. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  838. {
  839. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  840. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  841. #if PWM_EN == 0
  842. rt_pin_write(CLEAR_R,ON);
  843. rt_pin_write(CLEAR_L,ON);
  844. #else
  845. Motor_Qingsao_R_PWM(OFF);
  846. Motor_Qingsao_L_PWM(OFF);
  847. #endif
  848. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  849. if(Read_Real_Voltage()/100<12)
  850. {
  851. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  852. HMI_WRITE("sysTest.switchClear.val=%d",0);
  853. device_status.clear_status = 0;
  854. return 0;
  855. }
  856. break;
  857. }
  858. }
  859. clear_num = 0;
  860. //如果清扫位置在左侧
  861. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  862. {
  863. #if PWM_EN == 0
  864. rt_pin_write(CLEAR_R,ON);
  865. rt_pin_write(CLEAR_L,OFF);
  866. #else
  867. Motor_Qingsao_R_PWM(ON);
  868. Motor_Qingsao_L_PWM(OFF);
  869. #endif
  870. rt_thread_delay(50);
  871. clear_num++;
  872. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  873. {
  874. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  875. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  876. #if PWM_EN == 0
  877. rt_pin_write(CLEAR_R,ON);
  878. rt_pin_write(CLEAR_L,ON);
  879. #else
  880. Motor_Qingsao_R_PWM(OFF);
  881. Motor_Qingsao_L_PWM(OFF);
  882. #endif
  883. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  884. if(Read_Real_Voltage()/100<12)
  885. {
  886. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  887. HMI_WRITE("sysTest.switchClear.val=%d",0);
  888. device_status.clear_status = 0;
  889. return 0;
  890. }
  891. break;
  892. }
  893. }
  894. clear_num = 0;
  895. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1||(Read_Real_Voltage()/100)<12)
  896. {
  897. #if PWM_EN == 0
  898. rt_pin_write(CLEAR_R,ON);
  899. rt_pin_write(CLEAR_L,ON);
  900. #else
  901. Motor_Qingsao_R_PWM(OFF);
  902. Motor_Qingsao_L_PWM(OFF);
  903. #endif
  904. if(Read_Real_Voltage()/100<12)
  905. {
  906. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  907. HMI_WRITE("sysTest.switchClear.val=%d",0);
  908. device_status.clear_status = 0;
  909. return 0;
  910. }
  911. rt_thread_delay(2000);
  912. break;
  913. }
  914. while(rt_pin_read(CLEAR_L_LIMIT)==0)
  915. {
  916. #if PWM_EN == 0
  917. rt_pin_write(CLEAR_R,OFF);
  918. rt_pin_write(CLEAR_L,ON);
  919. #else
  920. Motor_Qingsao_R_PWM(OFF);
  921. Motor_Qingsao_L_PWM(ON);
  922. #endif
  923. rt_thread_delay(50);
  924. clear_num++;
  925. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  926. {
  927. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  928. char * Clear_ERR = makeJson_Warn("Clear Motor ERR","device");
  929. //DTU_Write("%s",Clear_ERR);
  930. #if PWM_EN == 0
  931. rt_pin_write(CLEAR_R,ON);
  932. rt_pin_write(CLEAR_L,ON);
  933. #else
  934. Motor_Qingsao_R_PWM(OFF);
  935. Motor_Qingsao_L_PWM(OFF);
  936. #endif
  937. rt_free(Clear_ERR);
  938. if(Read_Real_Voltage()/100<12)
  939. {
  940. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  941. HMI_WRITE("sysTest.switchClear.val=%d",0);
  942. device_status.clear_status = 0;
  943. return 0;
  944. }
  945. break;
  946. }
  947. }
  948. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  949. {
  950. #if PWM_EN == 0
  951. rt_pin_write(CLEAR_R,ON);
  952. rt_pin_write(CLEAR_L,ON);
  953. #else
  954. Motor_Qingsao_R_PWM(OFF);
  955. Motor_Qingsao_L_PWM(OFF);
  956. #endif
  957. rt_thread_delay(2000);
  958. break;
  959. }
  960. while(rt_pin_read(CLEAR_L_LIMIT)==1&&rt_pin_read(CLEAR_R_LIMIT)==1)
  961. {
  962. #if PWM_EN == 0
  963. rt_pin_write(CLEAR_R,ON);
  964. rt_pin_write(CLEAR_L,ON);
  965. #else
  966. Motor_Qingsao_R_PWM(OFF);
  967. Motor_Qingsao_L_PWM(OFF);
  968. #endif
  969. if(device_status.version_type==41)
  970. {
  971. rt_kprintf("Clear Motor Limit Not Access:%d",atoi(device_status.power));
  972. char * Clear_ERR = makeJson_Warn("Clear Motor Limit Not Access","device");
  973. //DTU_Write("%s",Clear_ERR);
  974. rt_free(Clear_ERR);
  975. }
  976. return 0;
  977. }
  978. clear_num = 0;
  979. rt_thread_delay(2000);
  980. #if PWM_EN == 0
  981. rt_pin_write(CLEAR_R,ON);
  982. rt_pin_write(CLEAR_L,ON);
  983. #else
  984. Motor_Qingsao_R_PWM(OFF);
  985. Motor_Qingsao_L_PWM(OFF);
  986. #endif
  987. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  988. HMI_WRITE("sysTest.switchClear.val=%d",0);
  989. device_status.clear_status = 0;
  990. return 1;
  991. }
  992. //路由器供电
  993. void ctr_router(uint8_t status_router)
  994. {
  995. rt_pin_mode(ROUTER, PIN_MODE_OUTPUT);
  996. if(device_status.version_type==6)
  997. rt_pin_mode(ROUTER_P,PIN_MODE_OUTPUT);
  998. //rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  999. if(status_router==ON)
  1000. {
  1001. rt_pin_write(ROUTER,ON);
  1002. LOG_W("打开路由器电源!");
  1003. }
  1004. else {
  1005. rt_pin_write(ROUTER,OFF);
  1006. LOG_W("关闭路由器电源!");
  1007. }
  1008. }
  1009. //清扫-推杆电机
  1010. void ctr_TG_Clear(uint16_t clear_timeout)
  1011. {
  1012. #if 0
  1013. int current_clear[200];
  1014. int16_t Electric_current = atoi(device_status.power); //获取电机运动前的电流
  1015. LOG_I("清扫电机待机:%d",Electric_current);
  1016. #endif
  1017. static uint16_t clear_count = 0;
  1018. clear_count = clear_timeout;
  1019. #if PWM_EN == 0
  1020. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1021. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1022. #endif
  1023. while(clear_count!=0)
  1024. {
  1025. #if PWM_EN == 0
  1026. rt_pin_write(CLEAR_R,ON);
  1027. rt_pin_write(CLEAR_L,OFF);
  1028. #else
  1029. Motor_Qingsao_R_PWM(ON);
  1030. Motor_Qingsao_L_PWM(OFF);
  1031. #endif
  1032. clear_count--;
  1033. rt_thread_delay(100);
  1034. }
  1035. #if PWM_EN == 0
  1036. rt_pin_write(CLEAR_R,ON);
  1037. rt_pin_write(CLEAR_L,ON);
  1038. #else
  1039. Motor_Qingsao_R_PWM(OFF);
  1040. Motor_Qingsao_L_PWM(OFF);
  1041. #endif
  1042. rt_thread_delay(3000);
  1043. clear_count = 0;
  1044. while(clear_timeout!=clear_count)
  1045. {
  1046. #if PWM_EN == 0
  1047. rt_pin_write(CLEAR_R,OFF);
  1048. rt_pin_write(CLEAR_L,ON);
  1049. #else
  1050. Motor_Qingsao_R_PWM(OFF);
  1051. Motor_Qingsao_L_PWM(ON);
  1052. #endif
  1053. // if(clear_count<200)
  1054. // current_clear[clear_count] = atoi(device_status.power);
  1055. clear_count++;
  1056. rt_thread_delay(100);
  1057. }
  1058. #if PWM_EN == 0
  1059. rt_pin_write(CLEAR_R,ON);
  1060. rt_pin_write(CLEAR_L,ON);
  1061. #else
  1062. Motor_Qingsao_R_PWM(OFF);
  1063. Motor_Qingsao_L_PWM(OFF);
  1064. #endif
  1065. #if 0
  1066. bubblesort(current_clear,200);
  1067. if(current_clear[199]-Electric_current <100&&device_status.work_status==1&&Electric_current!=0&&Electric_current<5000)
  1068. {
  1069. LOG_E("清扫电机电流不足:%d!",current_clear[199]);
  1070. char *ctr_clear_warn = makeJson_Warn("电流不足","清扫电机");
  1071. DTU_Write("%s",ctr_clear_warn);
  1072. rt_free(ctr_clear_warn);
  1073. }
  1074. #endif
  1075. rt_thread_delay(2000);
  1076. device_status.clear_status = 0;
  1077. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1078. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1079. }
  1080. //DTU,RTU供电
  1081. void ctr_RTU_DTU(uint8_t status_rtu)
  1082. {
  1083. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  1084. if(status_rtu==ON)
  1085. {
  1086. LOG_W("RTU电源启动!!!");
  1087. rt_pin_write(RTU_DTU,ON);
  1088. }
  1089. else
  1090. {
  1091. LOG_W("RTU电源关闭!!!");
  1092. rt_pin_write(RTU_DTU,OFF);
  1093. }
  1094. }
  1095. //海康拍照
  1096. void Hk_Take_io(void)
  1097. {
  1098. rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
  1099. rt_pin_mode(HK_IO, PIN_MODE_OUTPUT);
  1100. rt_pin_write(HK_TAKE, 1);
  1101. rt_pin_write(HK_IO, 0);
  1102. if(device_status.dtype==3)
  1103. Beep_Tip(1000);
  1104. if(device_status.dtype==7)
  1105. rt_thread_mdelay(1000);
  1106. rt_pin_write(HK_TAKE, 0);
  1107. rt_pin_write(HK_IO, 1);
  1108. }
  1109. void calorstat(uint16_t heat_time)
  1110. {
  1111. //uint8_t heat_up_cnt = 0;
  1112. uint16_t n = 0;
  1113. uint16_t delay_heat = 60;
  1114. FlagStatus heat_flg = RESET;
  1115. device_status.heat_time_min = 0;
  1116. device_status.run_sta = device_status.heattem; //初始化加热实时温度
  1117. ctr_Heat(ON);
  1118. // UpLoad_Data(); //开始加热时的第一条数据
  1119. //恒温模式
  1120. for(n=0;n < heat_time;n++)
  1121. {
  1122. if(device_status.heattem>device_status.heatvalue&&heat_flg==RESET)
  1123. {
  1124. heat_flg = SET;
  1125. ctr_Heat(OFF);
  1126. while(delay_heat!=0)
  1127. {
  1128. delay_heat --;
  1129. rt_kprintf("正在恒温加热!!!:%d",delay_heat);
  1130. HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"",delay_heat);
  1131. rt_thread_delay(1000);
  1132. if(device_status.heattem>device_status.run_sta + 1){
  1133. device_status.run_sta = device_status.heattem;
  1134. }
  1135. }
  1136. delay_heat = 60;
  1137. //跳出FOR循环
  1138. n = n + 60;
  1139. }
  1140. if(device_status.heattem>device_status.run_sta + 1){
  1141. device_status.run_sta = device_status.heattem;
  1142. }
  1143. if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
  1144. {
  1145. //device_status.run_sta = device_status.heattem;
  1146. ctr_Heat(ON);
  1147. }
  1148. else if (device_status.heattem>=device_status.heatvalue&&heat_flg==SET)
  1149. {
  1150. // if(heat_up_cnt==0)
  1151. // {
  1152. // UpLoad_Data(); //加热到设定温度的数据
  1153. // heat_up_cnt = 1;
  1154. // }
  1155. //device_status.run_sta = device_status.heattem;
  1156. ctr_Heat(OFF);
  1157. }
  1158. if((n % 60)==0)
  1159. {
  1160. device_status.heat_time_min = device_status.heat_time_min + 1;
  1161. // if(device_status.heat_time_min % 5 == 0)
  1162. // {
  1163. // UpLoad_Data(); //从加热开始每5分钟上传的数据
  1164. // }
  1165. }
  1166. //如果触发异常退出加热
  1167. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1168. {
  1169. rt_thread_delay(1000);
  1170. if(device_status.bat_status == 1)
  1171. {
  1172. rt_kprintf("============================触发异常退出加热==========================");
  1173. ctr_lamp(OFF,1);
  1174. ctr_Heat(OFF);
  1175. break;
  1176. }
  1177. }
  1178. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1179. {
  1180. ctr_Heat(OFF);
  1181. rt_kprintf("异常退出!!!\n");
  1182. break;
  1183. }
  1184. rt_thread_delay(1000);
  1185. rt_kprintf("=======正在加热======:%d-%d\n",n,heat_time);
  1186. HMI_WRITE("workSta.g0.txt=\"正在加热!!!:%d-%d\"",n,heat_time);
  1187. }
  1188. ctr_Heat(OFF);
  1189. //UpLoad_Data(); //加热结束的数据
  1190. }
  1191. //初始化所有控制驱动,关闭
  1192. void HardWare_Init(uint8_t boot)
  1193. {
  1194. Beep_Tip(200);
  1195. //关闭上仓门
  1196. ctr_cangmen_up(OFF);
  1197. if(device_status.dtype==3){
  1198. //关闭下仓门电机
  1199. ctr_cangmen_down(OFF);
  1200. }
  1201. ctr_lamp(OFF,1);
  1202. //关闭加热
  1203. ctr_Heat(OFF);
  1204. //关闭补光灯
  1205. ctr_led(OFF);
  1206. //关闭12V供电(海康相机,RTU)
  1207. ctr_photo(OFF);
  1208. //关闭清扫电机驱动
  1209. ctr_clear(OFF);
  1210. }
  1211. //拍照
  1212. void HK_TakePhoto(void)
  1213. {
  1214. //打开补光灯
  1215. DTU_Write("takephoto.mp3");
  1216. rt_thread_delay(10000);
  1217. char *takephotojson = makeJson_takephoto();
  1218. DTU_Write("%s",takephotojson);
  1219. rt_free(takephotojson);
  1220. //吸虫塔
  1221. if(device_status.version_type!=6)
  1222. {
  1223. ctr_led(ON);
  1224. if(device_status.version_type==48)
  1225. {
  1226. rt_thread_delay(1000*60);
  1227. }
  1228. else {
  1229. rt_thread_delay(1000*15);
  1230. }
  1231. }
  1232. //触发海康相机拍照
  1233. Hk_Take_io();
  1234. if(device_status.version_type!=6)
  1235. {
  1236. rt_thread_delay(1000*45);
  1237. }
  1238. else {
  1239. ctr_led(ON);
  1240. rt_thread_delay(1000*19);
  1241. }
  1242. ctr_led(OFF);
  1243. }
  1244. //光控测试任务
  1245. void SunTest(void)
  1246. {
  1247. rt_uint16_t ui_timeout_l = 0;
  1248. //未检测到光照,一秒扫描等待,超时30S
  1249. while(Read_Light_Voltage()<500)
  1250. {
  1251. ui_timeout_l ++;
  1252. rt_thread_delay(1000);
  1253. if(ui_timeout_l==30) break;
  1254. }
  1255. rt_thread_delay(3000);
  1256. if(Read_Light_Voltage()<500)
  1257. {
  1258. device_status.sun_status = 0;//光控状态
  1259. }
  1260. if(Read_Light_Voltage()>500)
  1261. {
  1262. rt_thread_delay(1000);
  1263. }
  1264. rt_thread_delay(3000);
  1265. if(Read_Light_Voltage()>500)
  1266. {
  1267. device_status.sun_status = 1;
  1268. ctr_lamp(OFF,1);
  1269. }
  1270. HMI_WRITE("sysTest.switchSun.val=%d",0);
  1271. device_status.sun_test = 0;
  1272. device_status.work_status=0;
  1273. }
  1274. /*上电初始化*/
  1275. void ResetInit(void)
  1276. {
  1277. LOG_I("ResetInit...");
  1278. //1.打开路由器供电
  1279. ctr_router(ON);
  1280. //2. 打开RTU供电
  1281. ctr_RTU_DTU(ON);
  1282. //3.打开光栅供电
  1283. ctr_photo(ON);
  1284. //5.关闭加热
  1285. //6.关闭补光灯
  1286. ctr_led(OFF);
  1287. }
  1288. //出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
  1289. void HardWare_Check(uint8_t boot)
  1290. {
  1291. if(boot==0&&device_status.version_type!=6)
  1292. {
  1293. //停止所有动作 -完成
  1294. HardWare_Init(boot);
  1295. }
  1296. else {
  1297. //停止所有动作
  1298. //读取记录待机功耗(实测大概70mA)
  1299. //(需减去屏幕的功耗大概120mA)
  1300. //动作上仓门,读取功率值保存
  1301. //动作下仓门,读取功率值保存
  1302. //动作清扫,读取功率值保存
  1303. //打开镇流器,读取功率值保存
  1304. //打开海康相机供电,读取功率值保存
  1305. //打开补光灯,读取功率值保存
  1306. //打开路由器/RTU供电,读取功率值保存
  1307. //打开加热,读取功率值保存
  1308. }
  1309. }
  1310. void WorkCheck(void)
  1311. {
  1312. static rt_uint32_t light_timeout = 3600;
  1313. while(device_status.ds == 1 &&
  1314. device_status.rain_status == 0 &&
  1315. device_status.temp_status == 0 &&
  1316. device_status.bat_status == 0)
  1317. {
  1318. if(device_status.timeSwitch == 1) // 时控模式
  1319. {
  1320. LOG_I("***********时控*****************");
  1321. if(device_status.startBar == device_status.stopBar)
  1322. {
  1323. // 开始结束时间相同则24小时模式
  1324. device_status.work_status = 1;
  1325. rt_thread_delay(10000);
  1326. continue;
  1327. }
  1328. time_t now;
  1329. time(&now);
  1330. struct tm now_tm = *localtime(&now);
  1331. rt_uint32_t curr_sec = now_tm.tm_hour*3600 + now_tm.tm_min*60 + now_tm.tm_sec;
  1332. rt_uint32_t start_sec = device_status.startBar * 3600;
  1333. rt_uint32_t end_sec = device_status.stopBar * 3600;
  1334. // 修复跨天判断逻辑
  1335. if (start_sec < end_sec)
  1336. {
  1337. // 不跨天模式
  1338. device_status.work_status = (curr_sec >= start_sec && curr_sec < end_sec) ? 1 : 0;
  1339. }
  1340. else
  1341. {
  1342. // 跨天模式
  1343. device_status.work_status = (curr_sec >= start_sec || curr_sec < end_sec) ? 1 : 0;
  1344. }
  1345. LOG_I("时控模式:状态[%s] 当前时间:%02d:%02d:%02d 设置:%02d:00-%02d:00",
  1346. device_status.work_status ? "工作" : "待机",
  1347. now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
  1348. device_status.startBar, device_status.stopBar);
  1349. rt_thread_delay(10000);
  1350. }
  1351. else // 光控模式
  1352. {
  1353. LOG_I("光控定时模式!");
  1354. if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
  1355. {
  1356. device_status.light_over_tim--;
  1357. light_timeout = 3600; // 重置超时计数器
  1358. device_status.work_status = 1;
  1359. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  1360. }
  1361. else
  1362. {
  1363. // 仅在白天递减超时计数器
  1364. if(device_status.sun_status == 1 && light_timeout > 0) {
  1365. light_timeout--;
  1366. }
  1367. device_status.work_status = 0;
  1368. //没有在测试并且没有在自检
  1369. if(device_status.test_flag==0 && device_status.selfcheck_ws==0)
  1370. {
  1371. ctr_lamp(OFF,1);
  1372. }
  1373. // 连续1小时白天后重置
  1374. if(light_timeout == 0) {
  1375. device_status.light_over_tim = 0;
  1376. light_timeout = 3600; // 重置防止负数
  1377. }
  1378. // 白天且倒计时结束:重置夜晚时长
  1379. if(device_status.light_over_tim == 0 &&
  1380. device_status.sun_status == 1)
  1381. {
  1382. device_status.light_over_tim = device_status.sunBar * 3600;
  1383. }
  1384. }
  1385. }
  1386. rt_thread_delay(1000);
  1387. }
  1388. // 异常状态处理
  1389. device_status.work_status = 0;
  1390. rt_thread_delay(1000);
  1391. }
  1392. //拍照性诱工作任务流程
  1393. void WorkTask_XYV3(void)
  1394. {
  1395. static uint8_t gaoya_on = 0;
  1396. static uint8_t gaoya_on_sec = 0;
  1397. rt_uint32_t cal_n = device_status.cul_time * 60;
  1398. LOG_I("工作状态:%d",device_status.work_status);
  1399. LOG_I("开关机状态:%d",device_status.ds);
  1400. while(device_status.work_status==1&&
  1401. device_status.bat_status==0&&
  1402. device_status.ds==1&&
  1403. device_status.temp_status==0)
  1404. {
  1405. //高压板通电
  1406. ctr_lamp(ON, 1); //清扫-DC12v电机正反转
  1407. rt_thread_delay(10000);
  1408. ctr_lamp(OFF, 1); //清扫-DC12v电机正反转
  1409. //光栅传感器通电
  1410. ctr_photo(ON);
  1411. //拍照(?触发条件)计数?没有虫呢?定时
  1412. while(1){
  1413. ctr_router(ON);
  1414. ctr_RTU_DTU(ON);
  1415. cal_n--;
  1416. LOG_I("诱虫检测计数剩余时间:%d S",cal_n);
  1417. if(cal_n==0){
  1418. ctr_lamp(OFF, 1); //拍照时关闭高压
  1419. //发送拍照计数指令
  1420. device_status.photo_ws = 2;
  1421. cal_n = device_status.cul_time * 60;
  1422. }
  1423. if(cal_n>1000&&cal_n%1200==0) //每隔20分钟高压通电5S
  1424. {
  1425. ctr_lamp(ON, 1);
  1426. gaoya_on = 1;
  1427. }
  1428. if(gaoya_on){
  1429. gaoya_on_sec++;
  1430. if(gaoya_on_sec>5){
  1431. gaoya_on=0;
  1432. gaoya_on_sec = 0;
  1433. ctr_lamp(OFF, 1);
  1434. }
  1435. }
  1436. if(device_status.temp_status==1 || device_status.bat_status==1 || device_status.work_status==0){
  1437. ctr_lamp(OFF, 1);
  1438. device_status.photo_ws = 2;
  1439. break;
  1440. }
  1441. rt_thread_delay(1000);
  1442. }
  1443. rt_thread_delay(10000);
  1444. }
  1445. ctr_lamp(OFF, 1);
  1446. ctr_photo(OFF);
  1447. }
  1448. /* 入口函数-工作状态检测 */
  1449. static void Work_status_thread_entry(void *parameter)
  1450. {
  1451. static uint16_t sun_status_num = 120;
  1452. //如果是光控定时,进行光控监测的消抖
  1453. if(device_status.timeSwitch==0&&device_status.sun_status==0)
  1454. {
  1455. rt_kprintf("光控定时!!!\n");
  1456. while(sun_status_num!=0)
  1457. {
  1458. sun_status_num--;
  1459. rt_thread_delay(1000);
  1460. rt_kprintf("开机光控检测:%d\n",sun_status_num);
  1461. }
  1462. device_status.light_over_tim = device_status.sunBar * 3600;
  1463. device_status.test_flag = 0;
  1464. }
  1465. while(1)
  1466. {
  1467. WorkCheck();
  1468. }
  1469. }
  1470. /*入口函数-工作流程*/
  1471. static void Work_Loop_thread_entry(void *parameter)
  1472. {
  1473. rt_thread_delay(1000);
  1474. ResetInit();
  1475. while(1)
  1476. {
  1477. WorkTask_XYV3();
  1478. rt_thread_delay(1000);
  1479. }
  1480. }
  1481. /*入口函数清扫*/
  1482. static void Control_Clear_thread_entry(void *parameter)
  1483. {
  1484. static int selfcheck_cnt = 0;
  1485. while(1)
  1486. {
  1487. if(device_status.selfcheck_ws==1){
  1488. selfcheck_cnt++;
  1489. }else{
  1490. selfcheck_cnt = 0;
  1491. }
  1492. if(selfcheck_cnt>1200) //超过3分钟
  1493. {
  1494. device_status.selfcheck_ws = 0;
  1495. device_status.camera_sta = 1; //相机异常
  1496. //上报自检结果
  1497. //上报自检结果
  1498. char *json_temp = makeJson_selfCheck_(1);
  1499. DTU_Write("%s",json_temp);
  1500. free(json_temp);
  1501. }
  1502. if(device_status.clear_status==10){
  1503. //ctr_turn(90,0);
  1504. Motor_shake(1,800);
  1505. device_status.clear_status = 0;
  1506. }
  1507. rt_thread_delay(100);
  1508. }
  1509. }
  1510. /*入口函数加热*/
  1511. static void Control_Heat_thread_entry(void *parameter)
  1512. {
  1513. rt_pin_mode(SIGNAL_GaoYa, PIN_MODE_INPUT);
  1514. rt_pin_mode(SIGNAL_GuangShan, PIN_MODE_INPUT);
  1515. static int GaoyYa_cnt,GuangShan_cnt = 500; //10s
  1516. bool GaoYa = false;
  1517. bool GuangShan = false;
  1518. while(1)
  1519. {
  1520. if(rt_pin_read(SIGNAL_GaoYa)==0)
  1521. {
  1522. LOG_I("检测到高压计数!");
  1523. GaoYa = true;
  1524. }
  1525. if(rt_pin_read(SIGNAL_GuangShan)==0)
  1526. {
  1527. LOG_I("检测到光栅计数!");
  1528. GuangShan = true;
  1529. }
  1530. if(GaoYa)
  1531. {
  1532. GaoyYa_cnt --;
  1533. if(GaoyYa_cnt==0)
  1534. {
  1535. GaoyYa_cnt = 500;
  1536. GaoYa = false;
  1537. }
  1538. }
  1539. if(GuangShan)
  1540. {
  1541. GuangShan_cnt--;
  1542. if(GuangShan_cnt==0)
  1543. {
  1544. GuangShan_cnt = 500;
  1545. GuangShan = false;
  1546. }
  1547. }
  1548. if(GaoYa&&GuangShan)
  1549. {
  1550. device_status.all_ycct += 1; //计数值增加
  1551. //拍照
  1552. if(device_status.all_ycct>=1){
  1553. //device_status.photo_ws = 1;
  1554. }
  1555. GaoYa = false;
  1556. GuangShan = false;
  1557. GaoyYa_cnt = 500;
  1558. GuangShan_cnt = 500;
  1559. rt_thread_delay(1000);
  1560. }
  1561. rt_thread_delay(20);
  1562. }
  1563. }
  1564. //static void Control_Heat_thread_entry(void *parameter) {
  1565. // rt_pin_mode(SIGNAL_GaoYa, PIN_MODE_INPUT);
  1566. // rt_pin_mode(SIGNAL_GuangShan, PIN_MODE_INPUT);
  1567. //
  1568. // // 修正变量名和初始化
  1569. // static int GaoYa_cnt = 500, GuangShan_cnt = 500;
  1570. // static bool GaoYa = false, GuangShan = false;
  1571. // static int highPressureDuration = 0;
  1572. //
  1573. //
  1574. // while (1) {
  1575. // // 高压信号去抖动
  1576. // if (rt_pin_read(SIGNAL_GaoYa) == 0) {
  1577. // LOG_I("高压信号稳定触发");
  1578. // GaoYa = true;
  1579. // highPressureDuration ++;
  1580. // }else{
  1581. // highPressureDuration = 0;
  1582. // }
  1583. //
  1584. // // 光栅信号去抖动(类似逻辑)
  1585. // if(rt_pin_read(SIGNAL_GuangShan)==0)
  1586. // {
  1587. // LOG_I("检测到光栅计数!");
  1588. // GuangShan = true;
  1589. // }
  1590. // /* 高压持续时间监测 */
  1591. // if(GaoYa)
  1592. // {
  1593. // // 持续时间累计(每次循环+1,20ms/次)
  1594. // if(highPressureDuration >= 50)
  1595. // {
  1596. // LOG_E("高压持续超过5秒!");
  1597. // // 执行关闭高压操作(示例函数)
  1598. // //ctr_lamp(OFF, 1);
  1599. // // 可选:自动复位保护
  1600. //// rt_thread_mdelay(10000); // 等待10秒
  1601. //// ctr_lamp(ON, 1);
  1602. // highPressureDuration = 0;
  1603. // }
  1604. // }
  1605. // // 计数器逻辑
  1606. // if (GaoYa) {
  1607. // if (--GaoYa_cnt <= 0) {
  1608. // GaoYa = false;
  1609. // GaoYa_cnt = 500;
  1610. // }
  1611. // }
  1612. //
  1613. // if (GuangShan) {
  1614. // if (--GuangShan_cnt <= 0) {
  1615. // GuangShan = false;
  1616. // GuangShan_cnt = 500;
  1617. // }
  1618. // }
  1619. //
  1620. // // 触发拍照逻辑
  1621. // if (GaoYa && GuangShan) {
  1622. // device_status.all_ycct++;
  1623. // GaoYa = GuangShan = false;
  1624. // GaoYa_cnt = GuangShan_cnt = 500;
  1625. // }
  1626. // rt_thread_delay(20); // 保持20ms周期
  1627. // }
  1628. //}
  1629. /*清扫线程*/
  1630. int Control_clear(void)
  1631. {
  1632. /* 创建线程*/
  1633. tid_ctr = rt_thread_create("Control_Clear_thread_entry",
  1634. Control_Clear_thread_entry, RT_NULL,
  1635. 2048, //2048
  1636. 24, //23
  1637. WORK_CHECK_THREAD_TIMESLICE); //5
  1638. if(tid_ctr!=RT_NULL)
  1639. {
  1640. rt_thread_startup(tid_ctr);
  1641. }
  1642. return 0;
  1643. }
  1644. /*恒温加热线程*/
  1645. int Control_heat(void)
  1646. {
  1647. /* 创建线程*/
  1648. tid_heat = rt_thread_create("Control_Heat_thread_entry",
  1649. Control_Heat_thread_entry, RT_NULL,
  1650. 1024, //2048
  1651. 25, //23
  1652. WORK_CHECK_THREAD_TIMESLICE); //5
  1653. if(tid_heat!=RT_NULL)
  1654. {
  1655. rt_thread_startup(tid_heat);
  1656. }
  1657. return 0;
  1658. }
  1659. /* 创建线程 -工作状态检测*/
  1660. int Workstatus_check(void)
  1661. {
  1662. /* 创建线程*/
  1663. tid_wkstc = rt_thread_create("work_status_check_thread",
  1664. Work_status_thread_entry, RT_NULL,
  1665. WORK_CHECK_THREAD_STACK_SIZE, //1024
  1666. WORK_CHECK_THREAD_PRIORITY, //23
  1667. WORK_CHECK_THREAD_TIMESLICE); //5
  1668. if(tid_wkstc!=RT_NULL)
  1669. {
  1670. rt_thread_startup(tid_wkstc);
  1671. }
  1672. return 0;
  1673. }
  1674. /*工作流程线程*/
  1675. int Work_Loop_Task(void)
  1676. {
  1677. rt_err_t result_loop = 0;
  1678. /* 创建线程*/
  1679. tid_workloop = rt_thread_create("work_loop_thread",
  1680. Work_Loop_thread_entry, RT_NULL,
  1681. WORK_LOOP_THREAD_STACK_SIZE, //2048
  1682. WORK_LOOP_THREAD_PRIORITY, //12
  1683. WORK_LOOP_THREAD_TIMESLICE); //5
  1684. if(tid_workloop!=RT_NULL)
  1685. {
  1686. result_loop = rt_thread_startup(tid_workloop);
  1687. }
  1688. return result_loop;
  1689. }
  1690. MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
  1691. MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
  1692. MSH_CMD_EXPORT(ctr_Heat,ctr_Heat<ON|OFF>);
  1693. MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
  1694. MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);
  1695. //INIT_APP_EXPORT(Control_heat);