control.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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. #define DBG_TAG "control.c"
  17. #define DBG_LVL LOG_LVL_INFO
  18. #include "dtu_uart2.h"
  19. #include "sht30_collect.h"
  20. //工作检测
  21. #define WORK_CHECK_THREAD_PRIORITY 23 //线程优先级
  22. #define WORK_CHECK_THREAD_STACK_SIZE 1024 //栈大小
  23. #define WORK_CHECK_THREAD_TIMESLICE 5 //时间片
  24. //工作流程
  25. #define WORK_LOOP_THREAD_PRIORITY 12 //线程优先级
  26. #define WORK_LOOP_THREAD_STACK_SIZE 1024 //栈大小
  27. #define WORK_LOOP_THREAD_TIMESLICE 5 //时间片
  28. //设备状态表结构体
  29. Device_Status_typedef device_status;
  30. rt_thread_t tid_workloop = RT_NULL;
  31. rt_thread_t tid_wkstc = RT_NULL;
  32. /*光控*/
  33. uint8_t In_Light_status(void)
  34. {
  35. rt_pin_mode(LIGHT_PIN,PIN_MODE_INPUT);
  36. return rt_pin_read(LIGHT_PIN);
  37. }
  38. /*雨控*/
  39. uint8_t In_Rain_status(void)
  40. {
  41. rt_pin_mode(RAIN_PIN,PIN_MODE_INPUT);
  42. return rt_pin_read(RAIN_PIN);
  43. }
  44. /*加热*/
  45. uint8_t ctr_Heat(uint8_t status_heat)
  46. {
  47. device_status.heat_status = status_heat;
  48. rt_pin_mode(Heat_Pin, PIN_MODE_OUTPUT);
  49. rt_pin_write(Heat_Pin,status_heat);
  50. return status_heat;
  51. }
  52. /*相机供电*/
  53. void ctr_photo(uint8_t status_photo)
  54. {
  55. rt_pin_mode(PHOTO,PIN_MODE_OUTPUT);
  56. rt_pin_write(PHOTO,status_photo);
  57. }
  58. /*采集风机/上仓门*/
  59. uint8_t ctr_cangmen_up(uint8_t status_up)
  60. {
  61. rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
  62. rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
  63. if(status_up==OFF)
  64. {
  65. rt_pin_write(Collect_fan_R,ON);
  66. rt_pin_write(Collect_fan_L,ON);
  67. device_status.ctr_up_motor = 0;
  68. rt_thread_delay(1000);
  69. }
  70. if(status_up==OPEN)
  71. {
  72. device_status.up_status = 1;
  73. rt_pin_write(Collect_fan_R,OFF);
  74. rt_pin_write(Collect_fan_L,OFF);
  75. rt_pin_write(Collect_fan_R,ON);
  76. rt_pin_write(Collect_fan_L,OFF);
  77. }
  78. if(status_up==CLOSE)
  79. {
  80. device_status.up_status = 0;
  81. rt_pin_write(Collect_fan_R,OFF);
  82. rt_pin_write(Collect_fan_L,OFF);
  83. rt_pin_write(Collect_fan_R,OFF);
  84. rt_pin_write(Collect_fan_L,ON);
  85. }
  86. return device_status.up_status;
  87. }
  88. //下仓门
  89. uint8_t ctr_cangmen_down(uint8_t status_down)
  90. {
  91. rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
  92. rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
  93. if(status_down==OFF)
  94. {
  95. rt_pin_write(C_DOWN_R,ON);
  96. rt_pin_write(C_DOWN_L,ON);
  97. device_status.ctr_down_motor = 0;
  98. rt_thread_delay(1000);
  99. }
  100. if(status_down==OPEN)
  101. {
  102. device_status.down_status = 1;
  103. rt_pin_write(C_DOWN_R,OFF);
  104. rt_pin_write(C_DOWN_L,OFF);
  105. rt_pin_write(C_DOWN_R,ON);
  106. rt_pin_write(C_DOWN_L,OFF);
  107. }
  108. if(status_down==CLOSE)
  109. {
  110. device_status.down_status = 0;
  111. rt_pin_write(C_DOWN_R,OFF);
  112. rt_pin_write(C_DOWN_L,OFF);
  113. rt_pin_write(C_DOWN_R,OFF);
  114. rt_pin_write(C_DOWN_L,ON);
  115. }
  116. return device_status.down_status;
  117. }
  118. //镇流器
  119. uint8_t ctr_lamp(uint8_t status_lamp)
  120. {
  121. rt_pin_mode(LAMP_SW, PIN_MODE_OUTPUT);
  122. if(status_lamp==ON)
  123. {
  124. rt_pin_write(LAMP_SW,ON);
  125. device_status.lamp_status = status_lamp;
  126. }
  127. else {
  128. rt_pin_write(LAMP_SW, OFF);
  129. device_status.lamp_status = status_lamp;
  130. }
  131. return device_status.lamp_status;
  132. }
  133. //LED
  134. void ctr_LED(uint8_t Sta_BLUE,uint8_t Sta_YELLOW,uint8_t Sta_PURPLE,uint8_t Sta_GREEN)
  135. {
  136. rt_pin_mode(LED_YELLOW, PIN_MODE_OUTPUT);
  137. rt_pin_mode(LED_BLUE, PIN_MODE_OUTPUT);
  138. rt_pin_mode(LED_PURPLE, PIN_MODE_OUTPUT);
  139. rt_pin_mode(LED_GREEN, PIN_MODE_OUTPUT);
  140. rt_pin_write(LED_YELLOW,Sta_YELLOW);
  141. rt_pin_write(LED_BLUE,Sta_BLUE);
  142. rt_pin_write(LED_PURPLE,Sta_PURPLE);
  143. rt_pin_write(LED_GREEN,Sta_GREEN);
  144. }
  145. //震动电机
  146. uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec)
  147. {
  148. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  149. if(status_shake==ON&&device_status.shake_ws==1)
  150. {
  151. rt_pin_write(SHAKE_SW,ON);
  152. rt_thread_delay(shake_sec*100);
  153. rt_pin_write(SHAKE_SW,OFF);
  154. HMI_WRITE("cangWei.switchShake.val=%d",0);
  155. }
  156. else
  157. {
  158. rt_pin_write(SHAKE_SW,OFF);
  159. HMI_WRITE("cangWei.switchShake.val=%d",0);
  160. }
  161. return status_shake;
  162. }
  163. //补光
  164. uint8_t ctr_led(uint8_t status_led)
  165. {
  166. rt_pin_mode(LED_SW, PIN_MODE_OUTPUT);
  167. if(status_led==ON)
  168. {
  169. rt_pin_write(LED_SW,ON);
  170. HMI_WRITE("sysTest.switchFill.val=%d",ON);
  171. }
  172. else if(status_led==OFF){
  173. rt_pin_write(LED_SW,OFF);
  174. HMI_WRITE("sysTest.switchPhoto.val=%d",OFF);
  175. HMI_WRITE("sysTest.switchFill.val=%d",OFF);
  176. }
  177. return status_led;
  178. }
  179. //转仓
  180. void turnzp(void)
  181. {
  182. static uint16_t turn_timeout = 0;
  183. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  184. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  185. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  186. rt_pin_write(CLEAR_R,OFF);
  187. rt_pin_write(CLEAR_L,OFF);
  188. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  189. {
  190. rt_thread_delay(20);
  191. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  192. {
  193. rt_pin_write(CLEAR_R,ON);
  194. rt_pin_write(CLEAR_L,OFF);
  195. rt_thread_delay(50);
  196. turn_timeout++;
  197. if(turn_timeout==1000) break;
  198. }
  199. break;
  200. }
  201. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  202. {
  203. rt_thread_delay(20);
  204. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  205. {
  206. rt_thread_delay(50);
  207. rt_pin_write(CLEAR_R,ON);
  208. rt_pin_write(CLEAR_L,OFF);
  209. turn_timeout++;
  210. if(turn_timeout==1000) break;
  211. }
  212. break;
  213. }
  214. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  215. {
  216. rt_thread_delay(20);
  217. if(rt_pin_read(CLEAR_R_LIMIT)==0)
  218. {
  219. rt_pin_write(CLEAR_R,OFF);
  220. rt_pin_write(CLEAR_L,OFF);
  221. break;
  222. }
  223. else {
  224. break;
  225. }
  226. }
  227. rt_pin_write(CLEAR_R,OFF);
  228. rt_pin_write(CLEAR_L,OFF);
  229. turn_timeout = 0;
  230. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  231. HMI_WRITE("sysTest.switchClear.val=%d",0);
  232. rt_thread_delay(1000);
  233. }
  234. //清扫-常闭型限位开关
  235. //新结构使用推杆电机做清扫
  236. uint8_t ctr_clear(uint16_t status_clear)
  237. {
  238. static uint16_t clear_num = 0;
  239. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  240. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  241. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  242. rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
  243. /*************************************************************外接清扫
  244. rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  245. rt_pin_write(POWER_CLEAR,ON);
  246. rt_thread_delay(1000*100);
  247. rt_pin_write(POWER_CLEAR,OFF);
  248. ************************************************************/
  249. //停止
  250. rt_pin_write(CLEAR_R,OFF);
  251. rt_pin_write(CLEAR_L,OFF);
  252. if(status_clear==OFF||Read_Real_Voltage()/100<12) return 0;
  253. rt_thread_delay(100);
  254. //如果清扫位置在中间
  255. while(rt_pin_read(CLEAR_R_LIMIT)==0&&rt_pin_read(CLEAR_L_LIMIT)==0)
  256. {
  257. rt_pin_write(CLEAR_R,ON);
  258. rt_pin_write(CLEAR_L,OFF);
  259. rt_thread_delay(50);
  260. clear_num++;
  261. //已到达检测位置
  262. if(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  263. {
  264. rt_pin_write(CLEAR_R,ON);
  265. rt_pin_write(CLEAR_L,ON);
  266. rt_thread_delay(2000);
  267. break;
  268. }
  269. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  270. {
  271. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  272. DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  273. rt_pin_write(CLEAR_R,ON);
  274. rt_pin_write(CLEAR_L,ON);
  275. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  276. if(Read_Real_Voltage()/100<12)
  277. {
  278. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  279. HMI_WRITE("sysTest.switchClear.val=%d",0);
  280. device_status.clear_status = 0;
  281. return 0;
  282. }
  283. break;
  284. }
  285. }
  286. clear_num = 0;
  287. //如果清扫位置在左侧
  288. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  289. {
  290. rt_pin_write(CLEAR_L,ON);
  291. rt_pin_write(CLEAR_R,OFF);
  292. rt_thread_delay(50);
  293. clear_num++;
  294. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  295. {
  296. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  297. DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  298. rt_pin_write(CLEAR_R,ON);
  299. rt_pin_write(CLEAR_L,ON);
  300. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  301. if(Read_Real_Voltage()/100<12)
  302. {
  303. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  304. HMI_WRITE("sysTest.switchClear.val=%d",0);
  305. device_status.clear_status = 0;
  306. return 0;
  307. }
  308. break;
  309. }
  310. }
  311. clear_num = 0;
  312. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1||(Read_Real_Voltage()/100)<12)
  313. {
  314. rt_pin_write(CLEAR_R,ON);
  315. rt_pin_write(CLEAR_L,ON);
  316. if(Read_Real_Voltage()/100<12)
  317. {
  318. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  319. HMI_WRITE("sysTest.switchClear.val=%d",0);
  320. device_status.clear_status = 0;
  321. return 0;
  322. }
  323. rt_thread_delay(2000);
  324. break;
  325. }
  326. while(rt_pin_read(CLEAR_L_LIMIT)==0)
  327. {
  328. rt_pin_write(CLEAR_L,OFF);
  329. rt_pin_write(CLEAR_R,ON);
  330. rt_thread_delay(50);
  331. clear_num++;
  332. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  333. {
  334. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  335. char * Clear_ERR = makeJson_Warn("Clear Motor ERR","device");
  336. DTU_Write("%s",Clear_ERR);
  337. rt_pin_write(CLEAR_R,ON);
  338. rt_pin_write(CLEAR_L,ON);
  339. rt_free(Clear_ERR);
  340. if(Read_Real_Voltage()/100<12)
  341. {
  342. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  343. HMI_WRITE("sysTest.switchClear.val=%d",0);
  344. device_status.clear_status = 0;
  345. return 0;
  346. }
  347. break;
  348. }
  349. }
  350. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  351. {
  352. rt_pin_write(CLEAR_R,ON);
  353. rt_pin_write(CLEAR_L,ON);
  354. rt_thread_delay(2000);
  355. break;
  356. }
  357. while(rt_pin_read(CLEAR_L_LIMIT)==1&&rt_pin_read(CLEAR_R_LIMIT)==1)
  358. {
  359. rt_kprintf("Clear Motor Limit Not Access:%d",atoi(device_status.power));
  360. char * Clear_ERR = makeJson_Warn("Clear Motor Limit Not Access","device");
  361. DTU_Write("%s",Clear_ERR);
  362. rt_free(Clear_ERR);
  363. rt_pin_write(CLEAR_R,ON);
  364. rt_pin_write(CLEAR_L,ON);
  365. return 0;
  366. }
  367. clear_num = 0;
  368. rt_thread_delay(3000);
  369. rt_pin_write(CLEAR_R,OFF);
  370. rt_pin_write(CLEAR_L,OFF);
  371. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  372. HMI_WRITE("sysTest.switchClear.val=%d",0);
  373. device_status.clear_status = 0;
  374. return 1;
  375. }
  376. //路由器供电
  377. void ctr_router(uint8_t status_router)
  378. {
  379. rt_pin_mode(ROUTER, PIN_MODE_OUTPUT);
  380. if(status_router==ON)
  381. {
  382. rt_pin_write(ROUTER,ON);
  383. //rt_pin_write(POWER_CLEAR,ON);
  384. }
  385. else {
  386. rt_pin_write(ROUTER,OFF);
  387. //rt_pin_write(POWER_CLEAR,OFF);
  388. }
  389. }
  390. //DTU_RTU供电
  391. void ctr_DTU_Power(uint8_t DTU_Power)
  392. {
  393. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  394. if(DTU_Power==ON)
  395. {
  396. rt_pin_write(ROUTER,ON);
  397. }
  398. else {
  399. rt_pin_write(ROUTER,OFF);
  400. }
  401. }
  402. //清扫-推杆电机
  403. void ctr_TG_Clear(uint16_t clear_timeout)
  404. {
  405. static uint16_t clear_count = 0;
  406. clear_count = clear_timeout;
  407. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  408. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  409. while(clear_count!=0)
  410. {
  411. rt_pin_write(CLEAR_R,ON);
  412. rt_pin_write(CLEAR_L,OFF);
  413. clear_count--;
  414. rt_thread_delay(100);
  415. }
  416. rt_pin_write(CLEAR_R,ON);
  417. rt_pin_write(CLEAR_L,ON);
  418. rt_thread_delay(3000);
  419. while(clear_timeout!=clear_count)
  420. {
  421. rt_pin_write(CLEAR_R,OFF);
  422. rt_pin_write(CLEAR_L,ON);
  423. clear_count++;
  424. rt_thread_delay(100);
  425. }
  426. rt_pin_write(CLEAR_R,ON);
  427. rt_pin_write(CLEAR_L,ON);
  428. rt_thread_delay(3000);
  429. rt_pin_write(CLEAR_R,OFF);
  430. rt_pin_write(CLEAR_L,OFF);
  431. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  432. HMI_WRITE("sysTest.switchClear.val=%d",0);
  433. }
  434. //DTU,RTU供电
  435. void ctr_RTU_DTU(uint8_t status_rtu)
  436. {
  437. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  438. if(status_rtu==ON)
  439. {
  440. rt_pin_write(RTU_DTU,ON);
  441. }
  442. else
  443. {
  444. rt_kprintf("RTU电源复位!!!\n");
  445. rt_pin_write(RTU_DTU,OFF);
  446. }
  447. }
  448. //海康拍照
  449. void Hk_Take_io(void)
  450. {
  451. rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
  452. rt_pin_write(HK_TAKE, 1);
  453. Beep_Tip(1000);
  454. rt_pin_write(HK_TAKE, 0);
  455. }
  456. void calorstat(uint16_t heat_time)
  457. {
  458. uint8_t heat_up_cnt = 0;
  459. uint16_t n = 0;
  460. uint16_t delay_heat = 60;
  461. FlagStatus heat_flg = RESET;
  462. device_status.heat_time_min = 0;
  463. ctr_Heat(ON);
  464. UpLoad_Data(); //开始加热时的第一条数据
  465. //恒温模式
  466. for(n=0;n < heat_time;n++)
  467. {
  468. if(device_status.heattem>device_status.heatvalue&&heat_flg==RESET)
  469. {
  470. heat_flg = SET;
  471. ctr_Heat(OFF);
  472. while(delay_heat!=0)
  473. {
  474. delay_heat --;
  475. rt_kprintf("正在恒温加热!!!:%d",delay_heat);
  476. rt_thread_delay(1000);
  477. }
  478. delay_heat = 60;
  479. //跳出FOR循环
  480. n = n + 60;
  481. }
  482. if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
  483. {
  484. heat_up_cnt = 0;
  485. ctr_Heat(ON);
  486. }
  487. else if (device_status.heattem>device_status.heatvalue&&heat_flg==SET)
  488. {
  489. if(heat_up_cnt==0)
  490. {
  491. UpLoad_Data(); //加热到设定温度的数据
  492. heat_up_cnt = 1;
  493. }
  494. ctr_Heat(OFF);
  495. }
  496. if((n % 60)==0)
  497. {
  498. device_status.heat_time_min = device_status.heat_time_min + 1;
  499. if(device_status.heat_time_min % 2 == 0)
  500. {
  501. UpLoad_Data(); //从加热开始每两分钟上传的数据
  502. }
  503. }
  504. //如果触发异常退出加热
  505. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  506. {
  507. rt_kprintf("============================触发异常退出加热==========================");
  508. ctr_lamp(OFF);
  509. ctr_Heat(OFF);
  510. break;
  511. }
  512. rt_thread_delay(1000);
  513. rt_kprintf("=======正在加热======:%d-%d\n",n,heat_time);
  514. }
  515. ctr_Heat(OFF);
  516. UpLoad_Data(); //加热结束的数据
  517. }
  518. //初始化所有控制驱动,关闭
  519. void HardWare_Init(uint8_t boot)
  520. {
  521. Beep_Tip(200);
  522. //关闭上仓门
  523. ctr_cangmen_up(OFF);
  524. if(boot==1)
  525. {
  526. HMI_WRITE("hardcheck.checktip.txt=\"上仓门电机已停止!!!\"");
  527. rt_thread_delay(1000);
  528. }
  529. //关闭下仓门电机
  530. ctr_cangmen_down(OFF);
  531. if(boot==1)
  532. {
  533. HMI_WRITE("hardcheck.checktip.txt=\"下仓门电机已停止!!!\"");
  534. rt_thread_delay(1000);
  535. }
  536. //关闭镇流器
  537. //ctr_lamp(OFF);
  538. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  539. if(boot==1)
  540. {
  541. HMI_WRITE("hardcheck.checktip.txt=\"镇流器已关闭!!!\"");
  542. rt_thread_delay(1000);
  543. }
  544. //关闭震动电机
  545. ctr_shake(OFF,0);
  546. if(boot==1)
  547. {
  548. HMI_WRITE("hardcheck.checktip.txt=\"震动电机已关闭!!!\"");
  549. rt_thread_delay(1000);
  550. }
  551. //关闭清扫电机
  552. if(boot==1)
  553. {
  554. HMI_WRITE("hardcheck.checktip.txt=\"清扫电机已关闭!!!\"");
  555. rt_thread_delay(1000);
  556. }
  557. //关闭加热
  558. ctr_Heat(OFF);
  559. if(boot==1)
  560. {
  561. HMI_WRITE("hardcheck.checktip.txt=\"加热带已关闭!!!\"");
  562. rt_thread_delay(1000);
  563. }
  564. //关闭补光灯
  565. ctr_led(OFF);
  566. if(boot==1)
  567. {
  568. HMI_WRITE("hardcheck.checktip.txt=\"补光灯已关闭!!!\"");
  569. rt_thread_delay(1000);
  570. }
  571. //关闭12V供电(海康相机,RTU)
  572. ctr_photo(OFF);
  573. if(boot==1)
  574. {
  575. HMI_WRITE("hardcheck.checktip.txt=\"12V供电已关闭!!!\"");
  576. rt_thread_delay(1000);
  577. }
  578. }
  579. //拍照
  580. void HK_TakePhoto(void)
  581. {
  582. //打开补光灯
  583. ctr_led(ON);
  584. DTU_Write("takephoto.mp3");
  585. //延时
  586. rt_thread_delay(1000*10);
  587. rt_kprintf("\n测试拍照!\n");
  588. char *takephotojson = makeJson_takephoto();
  589. DTU_Write("%s",takephotojson);
  590. rt_free(takephotojson);
  591. //触发海康相机拍照
  592. Hk_Take_io();
  593. rt_thread_delay(1000*45);
  594. ctr_led(OFF);
  595. }
  596. //光控测试任务
  597. void SunTest(void)
  598. {
  599. while(Read_Light_Voltage()<500)
  600. {
  601. rt_thread_delay(1000);
  602. }
  603. rt_thread_delay(3000);
  604. if(Read_Light_Voltage()<500)
  605. {
  606. device_status.sun_status = 0;//光控状态
  607. }
  608. if(Read_Light_Voltage()>500)
  609. {
  610. rt_thread_delay(1000);
  611. }
  612. rt_thread_delay(3000);
  613. if(Read_Light_Voltage()>500)
  614. {
  615. device_status.sun_status = 1;
  616. ctr_lamp(OFF);
  617. }
  618. HMI_WRITE("sysTest.switchSun.val=%d",0);
  619. device_status.sun_test = 0;
  620. device_status.work_status=0;
  621. }
  622. /*上电初始化*/
  623. void ResetInit(void)
  624. {
  625. device_status.work_done = 1;
  626. //1.打开路由器供电
  627. ctr_router(ON);
  628. ctr_RTU_DTU(ON);
  629. //2.打开相机供电
  630. ctr_photo(ON);
  631. //3.关闭镇流器
  632. ctr_lamp(OFF);
  633. //4.关闭震动电机
  634. ctr_shake(OFF, 0);
  635. //5.关闭加热
  636. ctr_Heat(OFF);
  637. //6.关闭补光灯
  638. ctr_led(OFF);
  639. if(device_status.bat_status==1||atoi(device_status.fuse_voltage)<1)
  640. {
  641. rt_kprintf("欠压!!!\n");
  642. return;
  643. }
  644. //7.关闭上仓门
  645. device_status.ctr_up_motor = 2;
  646. while(device_status.ctr_up_motor!=0)
  647. {
  648. rt_kprintf("关闭上仓门...\n");
  649. rt_thread_delay(100);
  650. }
  651. //8.关闭下仓门
  652. device_status.ctr_down_motor = 2;
  653. while(device_status.ctr_down_motor!=0)
  654. {
  655. rt_kprintf("关闭下仓门....\n");
  656. rt_thread_delay(100);
  657. }
  658. //9.清扫
  659. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  660. {
  661. rt_kprintf("异常退出!!!\n");
  662. return;
  663. }
  664. if(device_status.version_type==4)
  665. {
  666. if(ctr_clear(650)==0)
  667. ctr_TG_Clear(350);
  668. }
  669. else if (device_status.version_type==1) {
  670. turnzp();
  671. }
  672. rt_thread_delay(1000);
  673. }
  674. //出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
  675. void HardWare_Check(uint8_t boot)
  676. {
  677. if(boot==0)
  678. {
  679. //停止所有动作 -完成
  680. HardWare_Init(boot);
  681. }
  682. else {
  683. //停止所有动作
  684. //读取记录待机功耗(实测大概70mA)
  685. //(需减去屏幕的功耗大概120mA)
  686. //动作上仓门,读取功率值保存
  687. //动作下仓门,读取功率值保存
  688. //动作清扫,读取功率值保存
  689. //打开镇流器,读取功率值保存
  690. //打开海康相机供电,读取功率值保存
  691. //打开补光灯,读取功率值保存
  692. //打开路由器/RTU供电,读取功率值保存
  693. //打开加热,读取功率值保存
  694. }
  695. }
  696. //工作状态检测
  697. void WorkCheck(void)
  698. {
  699. //雨控检测,温控检测,电池电压检测
  700. while(device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
  701. {
  702. //工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
  703. if(device_status.timeSwitch==1)
  704. {
  705. rt_kprintf("***************时控*****************\n");
  706. //如果开始和结束是同一天
  707. if(device_status.startBar<device_status.stopBar)
  708. {
  709. rt_kprintf("开始和结束是同一天");
  710. time_t now;
  711. time(&now);
  712. static struct tm nowtime; //现在
  713. static struct tm starttime; //开始
  714. static struct tm endtime; //结束
  715. //获取当前时间戳
  716. nowtime =*localtime(&now);
  717. nowtime.tm_hour = nowtime.tm_hour-8;
  718. //获取定时开始的时间戳
  719. starttime = *localtime(&now);
  720. starttime.tm_hour = device_status.startBar-8;
  721. starttime.tm_min = 0;
  722. starttime.tm_sec = 0;
  723. //获取定时结束的时间戳
  724. endtime = *localtime(&now);
  725. endtime.tm_hour = device_status.stopBar-8;
  726. endtime.tm_min = 0;
  727. endtime.tm_sec = 0;
  728. rt_kprintf("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***\n",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  729. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  730. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
  731. {
  732. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中!!!\n");
  733. device_status.work_status = 1;
  734. }
  735. //如果当前时间小于开始时间
  736. else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
  737. {
  738. rt_kprintf("当前时间小于开始时间,不工作!!!-%d-%d\n",mktime(&nowtime),mktime(&starttime));
  739. device_status.work_status = 0;
  740. }
  741. //当前时间大于结束时间
  742. else {
  743. rt_kprintf("当前时间大于结束时间,不工作!!!-%d-%d\n",mktime(&nowtime),mktime(&starttime));
  744. device_status.work_status = 0;
  745. }
  746. }
  747. //如果结束时间是第二天
  748. else if (device_status.startBar>device_status.stopBar) {
  749. time_t now;
  750. time(&now);
  751. static struct tm nowtime; //现在
  752. static struct tm starttime; //开始
  753. static struct tm endtime; //结束
  754. //获取当前时间戳
  755. nowtime =*localtime(&now);
  756. nowtime.tm_hour = nowtime.tm_hour-8;
  757. //获取定时开始的时间戳
  758. starttime = *localtime(&now);
  759. starttime.tm_hour = device_status.startBar-8;
  760. starttime.tm_min = 0;
  761. starttime.tm_sec = 0;
  762. //获取定时结束的时间戳
  763. endtime = *localtime(&now);
  764. endtime.tm_hour = device_status.stopBar-8;
  765. endtime.tm_min = 0;
  766. endtime.tm_sec = 0;
  767. rt_kprintf("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!\n",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  768. //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
  769. if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
  770. {
  771. //获取定时结束的时间戳
  772. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  773. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  774. endtime.tm_min = 0;
  775. endtime.tm_sec = 0;
  776. device_status.work_status = 1;
  777. rt_kprintf("当前前时间大于开始时间,且没有开始工作\n");
  778. }
  779. //当前时间小于开始时间
  780. else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
  781. {
  782. //获取定时结束的时间戳
  783. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  784. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  785. endtime.tm_min = 0;
  786. endtime.tm_sec = 0;
  787. //如果当前时间戳小于结束时间戳
  788. if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
  789. {
  790. rt_kprintf("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间\n");
  791. device_status.work_status = 1;
  792. }
  793. else
  794. {
  795. rt_kprintf("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间!!!\n");
  796. device_status.work_status = 0; //不在工作时间,待机
  797. }
  798. }
  799. }
  800. }
  801. else {
  802. rt_kprintf("光控定时模式!!!\n");
  803. time_t now;
  804. time(&now);
  805. static struct tm nowstamp;
  806. nowstamp =*localtime(&now);
  807. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  808. static rt_uint32_t nowstamp_num = 0;
  809. nowstamp_num = mktime(&nowstamp);
  810. rt_kprintf("now stamp:%d\n",nowstamp_num);
  811. if(device_status.sun_status==0)
  812. {
  813. //检测到光控,计算定时
  814. if(device_status.light_over_tim > nowstamp_num)
  815. {
  816. device_status.work_status = 1;
  817. rt_kprintf("光控定时,计时中:%d----%d\n",device_status.light_over_tim,nowstamp_num);
  818. }
  819. else
  820. {
  821. device_status.work_status = 0; //置位工作状态
  822. rt_kprintf("光控定时任务已完成!!!\n");
  823. }
  824. }
  825. else
  826. {
  827. device_status.work_status = 0;
  828. device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
  829. rt_kprintf("光控中,白天:%d!!!\n",nowstamp_num);
  830. }
  831. }
  832. rt_thread_delay(1000);
  833. }
  834. rt_kprintf("雨控状态,温控状态,电压状态:\n%d\n%d\n%d\n",device_status.rain_status,device_status.temp_status,device_status.bat_status);
  835. device_status.work_status = 0;
  836. rt_thread_delay(1000);
  837. }
  838. //工作状态检测-LED
  839. void WorkCheck_LED(void)
  840. {
  841. while(device_status.temp_status==0&&device_status.bat_status==0&&device_status.rain_status==0&&device_status.ds==1)
  842. {
  843. time_t now;
  844. time(&now);
  845. static struct tm nowtime; //现在
  846. static struct tm start_time; //阶段1:17:30-18:30
  847. static struct tm end_time_1; //阶段1:17:30-18:30
  848. static struct tm end_time_2; //阶段2:18:30-19:30
  849. static struct tm end_time_3; //阶段3:19:30-20:30
  850. static struct tm end_time_4; //阶段3:20:30-22:30
  851. static struct tm end_time_5; //阶段3:22:30-01:30
  852. static struct tm end_time_6; //阶段3:01:30-05:30
  853. static struct tm end_time_7; //阶段3:05:30-06:30
  854. //获取当前时间戳
  855. nowtime =*localtime(&now);
  856. nowtime.tm_hour = nowtime.tm_hour-8;
  857. //获取阶段1的开始时间戳
  858. start_time = *localtime(&now);
  859. start_time.tm_hour = 17-8;
  860. start_time.tm_min = 30;
  861. start_time.tm_sec = 0;
  862. //获取阶段1的结束时间戳
  863. end_time_1 = *localtime(&now);
  864. end_time_1.tm_hour = 18-8;
  865. end_time_1.tm_min = 30;
  866. end_time_1.tm_sec = 0;
  867. //获取阶段2的结束时间戳
  868. end_time_2 = *localtime(&now);
  869. end_time_2.tm_hour = 19-8;
  870. end_time_2.tm_min = 30;
  871. end_time_2.tm_sec = 0;
  872. //获取阶段3的结束时间
  873. end_time_3 = *localtime(&now);
  874. end_time_3.tm_hour = 20-8;
  875. end_time_3.tm_min = 30;
  876. end_time_3.tm_sec = 0;
  877. //获取阶段4的结束时间戳
  878. end_time_4 = *localtime(&now);
  879. end_time_4.tm_hour = 22 - 8;
  880. end_time_4.tm_min = 30;
  881. end_time_4.tm_sec = 0;
  882. //获取阶段5的结束时间戳
  883. end_time_5 = *localtime(&now);
  884. end_time_5.tm_hour = 1 - 8;
  885. end_time_5.tm_min = 30;
  886. end_time_5.tm_sec = 0;
  887. //获取阶段6的结束时间戳
  888. end_time_6 = *localtime(&now);
  889. end_time_6.tm_hour = 5 - 8;
  890. end_time_6.tm_min = 30;
  891. end_time_6.tm_sec = 0;
  892. //获取阶段6的结束时间戳
  893. end_time_7 = *localtime(&now);
  894. end_time_7.tm_hour = 6 - 8;
  895. end_time_7.tm_min = 30;
  896. end_time_7.tm_sec = 0;
  897. rt_kprintf("阶段1:现在时间:%d-开始时间1:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&start_time),mktime(&end_time_1));
  898. rt_kprintf("阶段2:现在时间:%d-开始时间2:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_1),mktime(&end_time_2));
  899. rt_kprintf("阶段3:现在时间:%d-开始时间3:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_2),mktime(&end_time_3));
  900. rt_kprintf("阶段4:现在时间:%d-开始时间4:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_3),mktime(&end_time_4));
  901. rt_kprintf("阶段5:现在时间:%d-开始时间5:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_4),mktime(&end_time_5));
  902. rt_kprintf("阶段6:现在时间:%d-开始时间6:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_5),mktime(&end_time_6));
  903. rt_kprintf("阶段7:现在时间:%d-开始时间7:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_6),mktime(&end_time_7));
  904. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  905. if((difftime(mktime(&nowtime), mktime(&start_time)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_1))<0))
  906. {
  907. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,亮紫灯!!!\n");
  908. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_ON, GREEN_OFF);
  909. device_status.work_status = 1;
  910. }
  911. else if ((difftime(mktime(&nowtime), mktime(&end_time_1)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_2))<0)) {
  912. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,黄绿光灯打开,蓝紫光灯关!!!\n");
  913. ctr_LED(BLUE_OFF, YELLOW_ON, PURPLE_OFF, GREEN_ON);
  914. device_status.work_status = 1;
  915. }
  916. else if ((difftime(mktime(&nowtime), mktime(&end_time_2)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_3))<0)) {
  917. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,紫光灯打开,黄绿蓝光灯关!!!\n");
  918. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_ON, GREEN_OFF);
  919. device_status.work_status = 1;
  920. }
  921. else if ((difftime(mktime(&nowtime), mktime(&end_time_3)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_4))<0)) {
  922. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,蓝光灯打开,黄绿紫光灯关!!!\n");
  923. ctr_LED(BLUE_ON, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  924. device_status.work_status = 1;
  925. }
  926. else if ((difftime(mktime(&nowtime), mktime(&end_time_4)) >=0)) {
  927. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,紫光灯打开,黄绿蓝光灯关!!!\n");
  928. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_ON, GREEN_OFF);
  929. device_status.work_status = 1;
  930. }
  931. else if ((difftime(mktime(&nowtime),mktime(&end_time_4))<0)&&(difftime(mktime(&nowtime),mktime(&end_time_5)) < 0)) {
  932. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,紫光灯打开,黄绿蓝光灯关!!!\n");
  933. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_ON, GREEN_OFF);
  934. device_status.work_status = 1;
  935. }
  936. else if ((difftime(mktime(&nowtime), mktime(&end_time_5)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_6))<0)) {
  937. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  938. device_status.work_status = 0;
  939. rt_kprintf("全部关灯,节约用电!!!\n");
  940. }
  941. else if ((difftime(mktime(&nowtime), mktime(&end_time_6)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_7))<0)) {
  942. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,黄绿灯打开,紫蓝光灯关!!!\n");
  943. ctr_LED(BLUE_OFF, YELLOW_ON, PURPLE_OFF, GREEN_ON);
  944. device_status.work_status = 1;
  945. }
  946. else {
  947. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  948. device_status.work_status = 0;
  949. rt_kprintf("全部关灯,进入充电程序!!!\n");
  950. }
  951. rt_thread_delay(1000);
  952. }
  953. rt_kprintf("雨控状态,温控状态,电压状态:\n%d\n%d\n%d\n",device_status.rain_status,device_status.temp_status,device_status.bat_status);
  954. device_status.work_status = 0;
  955. rt_thread_delay(1000);
  956. }
  957. //工作任务流程s
  958. void WorkTast(void)
  959. {
  960. ctr_router(ON); //打开路由器供电
  961. static int clt_time = 0; //收集时间差秒数
  962. rt_kprintf("工作状态:%d\n",device_status.work_status);
  963. rt_kprintf("开关机状态:%d\n",device_status.ds);
  964. while(device_status.work_status==1&&device_status.temp_status==0&&device_status.bat_status==0&&device_status.rain_status==0&&device_status.ds==1)
  965. {
  966. device_status.work_done = 0;
  967. if(clt_time==0) DTU_Write("workstart.mp3");
  968. rt_thread_delay(5000); //待灯管启动再往下执行,否则会触发电机过流
  969. //2.打开上仓门
  970. rt_kprintf("打开上仓门!!!\n");
  971. device_status.ctr_up_motor = 1;
  972. //3.收集
  973. clt_time = device_status.clt_time * 60;
  974. while(clt_time!=1)
  975. {
  976. clt_time --;
  977. rt_thread_delay(1000);
  978. rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
  979. //如果触发异常
  980. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  981. {
  982. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  983. rt_kprintf("异常退出!!!\n");
  984. break;
  985. }
  986. }
  987. clt_time = 1;
  988. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  989. {
  990. //ctr_lamp(OFF);
  991. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  992. rt_kprintf("异常退出!!!\n");
  993. break;
  994. }
  995. //4.关闭上仓门
  996. device_status.ctr_up_motor = 2;
  997. rt_kprintf("关闭上仓门!!!\n");
  998. // while(device_status.ctr_up_motor!=0)
  999. // {
  1000. // rt_thread_delay(100);
  1001. // rt_kprintf("等待上仓门关闭!!!\n");
  1002. // }
  1003. //5.加热
  1004. rt_kprintf("加热!!!\n");
  1005. calorstat(device_status.heattime*60);
  1006. //6.打开下仓门
  1007. if(device_status.rain_status==0)
  1008. {
  1009. device_status.ctr_down_motor =1;
  1010. }
  1011. //待下仓门完全打开
  1012. while(device_status.ctr_down_motor!=0)
  1013. {
  1014. rt_thread_delay(100);
  1015. rt_kprintf("等待下仓门打开!!!\n");
  1016. }
  1017. rt_thread_delay(3000);
  1018. //关闭下仓门
  1019. device_status.ctr_down_motor = 2;
  1020. while(device_status.ctr_down_motor!=0)
  1021. {
  1022. rt_thread_delay(100);
  1023. rt_kprintf("等待下仓门关闭!!!\n");
  1024. }
  1025. if(device_status.version_type==4)
  1026. {
  1027. //震动
  1028. ctr_shake(ON, 1);
  1029. //补光&&拍照
  1030. rt_kprintf("拍照!!!\n");
  1031. HK_TakePhoto();
  1032. //清扫
  1033. if(ctr_clear(1200)==0)
  1034. ctr_TG_Clear(350);
  1035. //清扫失效则使用震动
  1036. //ctr_shake(ON, 100);
  1037. }
  1038. }
  1039. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1||device_status.ds==0)
  1040. {
  1041. rt_kprintf("-------------------not work--------------------\n");
  1042. device_status.work_status = 0;
  1043. }
  1044. //工作结束
  1045. if(device_status.work_done==0&&device_status.work_status==0)
  1046. {
  1047. DTU_Write("workdone");
  1048. ResetInit();
  1049. }
  1050. rt_kprintf("***not work-device status:%d\n",device_status.ds);
  1051. }
  1052. /* 入口函数-工作状态检测 */
  1053. static void Work_status_thread_entry(void *parameter)
  1054. {
  1055. // static uint16_t sun_status_num = 300;
  1056. // //如果是光控定时,进行光控监测的消抖
  1057. // if(device_status.timeSwitch==0&&device_status.sun_status==0)
  1058. // {
  1059. // rt_kprintf("光控定时!!!\n");
  1060. // while(sun_status_num!=0)
  1061. // {
  1062. // sun_status_num--;
  1063. // rt_thread_delay(1000);
  1064. // rt_kprintf("开机光控检测:%d\n",sun_status_num);
  1065. // }
  1066. // time_t now;
  1067. // time(&now);
  1068. // static struct tm nowstamp;
  1069. // nowstamp =*localtime(&now);
  1070. // nowstamp.tm_hour = nowstamp.tm_hour - 8;
  1071. // static rt_uint32_t nowstamp_num = 0;
  1072. // nowstamp_num = mktime(&nowstamp);
  1073. // device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
  1074. // }
  1075. while(1)
  1076. {
  1077. WorkCheck_LED();
  1078. rt_thread_delay(1);
  1079. }
  1080. }
  1081. /*入口函数-工作流程*/
  1082. static void Work_Loop_thread_entry(void *parameter)
  1083. {
  1084. rt_thread_delay(1000);
  1085. ResetInit();
  1086. while(1)
  1087. {
  1088. WorkTast();
  1089. rt_thread_delay(1000);
  1090. }
  1091. }
  1092. /* 创建线程 -是否置位工作状态*/
  1093. int Workstatus_check(void)
  1094. {
  1095. /* 创建线程*/
  1096. tid_wkstc = rt_thread_create("work_status_check_thread",
  1097. Work_status_thread_entry, RT_NULL,
  1098. WORK_CHECK_THREAD_STACK_SIZE, //2048
  1099. WORK_CHECK_THREAD_PRIORITY, //23
  1100. WORK_CHECK_THREAD_TIMESLICE); //5
  1101. if(tid_wkstc!=RT_NULL)
  1102. {
  1103. rt_thread_startup(tid_wkstc);
  1104. }
  1105. return 0;
  1106. }
  1107. /*工作流程线程*/
  1108. int Work_Loop_Task(void)
  1109. {
  1110. /* 创建线程*/
  1111. tid_workloop = rt_thread_create("work_loop_thread",
  1112. Work_Loop_thread_entry, RT_NULL,
  1113. WORK_LOOP_THREAD_STACK_SIZE, //2048
  1114. WORK_LOOP_THREAD_PRIORITY, //12
  1115. WORK_LOOP_THREAD_TIMESLICE); //5
  1116. if(tid_workloop!=RT_NULL)
  1117. {
  1118. rt_thread_startup(tid_workloop);
  1119. }
  1120. return 0;
  1121. }
  1122. MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
  1123. MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
  1124. MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
  1125. MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);