control.c 52 KB

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