control.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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. if(device_status.version_type==6)
  384. {
  385. rt_pin_write(POWER_CLEAR,ON);
  386. }
  387. //rt_pin_write(POWER_CLEAR,ON);
  388. }
  389. else {
  390. rt_pin_write(ROUTER,OFF);
  391. if(device_status.version_type==6)
  392. rt_pin_write(POWER_CLEAR,OFF);
  393. }
  394. }
  395. //DTU_RTU供电
  396. void ctr_DTU_Power(uint8_t DTU_Power)
  397. {
  398. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  399. if(DTU_Power==ON)
  400. {
  401. rt_pin_write(ROUTER,ON);
  402. }
  403. else {
  404. rt_pin_write(ROUTER,OFF);
  405. }
  406. }
  407. //清扫-推杆电机
  408. void ctr_TG_Clear(uint16_t clear_timeout)
  409. {
  410. static uint16_t clear_count = 0;
  411. clear_count = clear_timeout;
  412. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  413. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  414. while(clear_count!=0)
  415. {
  416. rt_pin_write(CLEAR_R,ON);
  417. rt_pin_write(CLEAR_L,OFF);
  418. clear_count--;
  419. rt_thread_delay(100);
  420. }
  421. rt_pin_write(CLEAR_R,ON);
  422. rt_pin_write(CLEAR_L,ON);
  423. rt_thread_delay(3000);
  424. while(clear_timeout!=clear_count)
  425. {
  426. rt_pin_write(CLEAR_R,OFF);
  427. rt_pin_write(CLEAR_L,ON);
  428. clear_count++;
  429. rt_thread_delay(100);
  430. }
  431. rt_pin_write(CLEAR_R,ON);
  432. rt_pin_write(CLEAR_L,ON);
  433. rt_thread_delay(3000);
  434. rt_pin_write(CLEAR_R,OFF);
  435. rt_pin_write(CLEAR_L,OFF);
  436. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  437. HMI_WRITE("sysTest.switchClear.val=%d",0);
  438. }
  439. //DTU,RTU供电
  440. void ctr_RTU_DTU(uint8_t status_rtu)
  441. {
  442. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  443. if(status_rtu==ON)
  444. {
  445. rt_pin_write(RTU_DTU,ON);
  446. }
  447. else
  448. {
  449. rt_kprintf("RTU电源复位!!!\n");
  450. rt_pin_write(RTU_DTU,OFF);
  451. }
  452. }
  453. //海康拍照
  454. void Hk_Take_io(void)
  455. {
  456. rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
  457. rt_pin_write(HK_TAKE, 1);
  458. Beep_Tip(1000);
  459. rt_pin_write(HK_TAKE, 0);
  460. }
  461. void calorstat(uint16_t heat_time)
  462. {
  463. uint8_t heat_up_cnt = 0;
  464. uint16_t n = 0;
  465. uint16_t delay_heat = 60;
  466. FlagStatus heat_flg = RESET;
  467. device_status.heat_time_min = 0;
  468. ctr_Heat(ON);
  469. UpLoad_Data(); //开始加热时的第一条数据
  470. //恒温模式
  471. for(n=0;n < heat_time;n++)
  472. {
  473. if(device_status.heattem>device_status.heatvalue&&heat_flg==RESET)
  474. {
  475. heat_flg = SET;
  476. ctr_Heat(OFF);
  477. while(delay_heat!=0)
  478. {
  479. delay_heat --;
  480. rt_kprintf("正在恒温加热!!!:%d",delay_heat);
  481. rt_thread_delay(1000);
  482. }
  483. delay_heat = 60;
  484. //跳出FOR循环
  485. n = n + 60;
  486. }
  487. if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
  488. {
  489. heat_up_cnt = 0;
  490. ctr_Heat(ON);
  491. }
  492. else if (device_status.heattem>device_status.heatvalue&&heat_flg==SET)
  493. {
  494. if(heat_up_cnt==0)
  495. {
  496. UpLoad_Data(); //加热到设定温度的数据
  497. heat_up_cnt = 1;
  498. }
  499. ctr_Heat(OFF);
  500. }
  501. if((n % 60)==0)
  502. {
  503. device_status.heat_time_min = device_status.heat_time_min + 1;
  504. if(device_status.heat_time_min % 2 == 0)
  505. {
  506. UpLoad_Data(); //从加热开始每两分钟上传的数据
  507. }
  508. }
  509. //如果触发异常退出加热
  510. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  511. {
  512. rt_kprintf("============================触发异常退出加热==========================");
  513. ctr_lamp(OFF);
  514. ctr_Heat(OFF);
  515. break;
  516. }
  517. rt_thread_delay(1000);
  518. rt_kprintf("=======正在加热======:%d-%d\n",n,heat_time);
  519. }
  520. ctr_Heat(OFF);
  521. UpLoad_Data(); //加热结束的数据
  522. }
  523. //初始化所有控制驱动,关闭
  524. void HardWare_Init(uint8_t boot)
  525. {
  526. Beep_Tip(200);
  527. //关闭上仓门
  528. ctr_cangmen_up(OFF);
  529. if(boot==1)
  530. {
  531. HMI_WRITE("hardcheck.checktip.txt=\"上仓门电机已停止!!!\"");
  532. rt_thread_delay(1000);
  533. }
  534. //关闭下仓门电机
  535. ctr_cangmen_down(OFF);
  536. if(boot==1)
  537. {
  538. HMI_WRITE("hardcheck.checktip.txt=\"下仓门电机已停止!!!\"");
  539. rt_thread_delay(1000);
  540. }
  541. //关闭镇流器
  542. //ctr_lamp(OFF);
  543. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  544. if(boot==1)
  545. {
  546. HMI_WRITE("hardcheck.checktip.txt=\"镇流器已关闭!!!\"");
  547. rt_thread_delay(1000);
  548. }
  549. //关闭震动电机
  550. ctr_shake(OFF,0);
  551. if(boot==1)
  552. {
  553. HMI_WRITE("hardcheck.checktip.txt=\"震动电机已关闭!!!\"");
  554. rt_thread_delay(1000);
  555. }
  556. //关闭清扫电机
  557. if(boot==1)
  558. {
  559. HMI_WRITE("hardcheck.checktip.txt=\"清扫电机已关闭!!!\"");
  560. rt_thread_delay(1000);
  561. }
  562. //关闭加热
  563. ctr_Heat(OFF);
  564. if(boot==1)
  565. {
  566. HMI_WRITE("hardcheck.checktip.txt=\"加热带已关闭!!!\"");
  567. rt_thread_delay(1000);
  568. }
  569. //关闭补光灯
  570. ctr_led(OFF);
  571. if(boot==1)
  572. {
  573. HMI_WRITE("hardcheck.checktip.txt=\"补光灯已关闭!!!\"");
  574. rt_thread_delay(1000);
  575. }
  576. //关闭12V供电(海康相机,RTU)
  577. ctr_photo(OFF);
  578. if(boot==1)
  579. {
  580. HMI_WRITE("hardcheck.checktip.txt=\"12V供电已关闭!!!\"");
  581. rt_thread_delay(1000);
  582. }
  583. }
  584. //拍照
  585. void HK_TakePhoto(void)
  586. {
  587. //打开补光灯
  588. ctr_led(ON);
  589. DTU_Write("takephoto.mp3");
  590. //延时
  591. rt_thread_delay(1000*10);
  592. rt_kprintf("\n测试拍照!\n");
  593. char *takephotojson = makeJson_takephoto();
  594. DTU_Write("%s",takephotojson);
  595. rt_free(takephotojson);
  596. //触发海康相机拍照
  597. Hk_Take_io();
  598. rt_thread_delay(1000*45);
  599. ctr_led(OFF);
  600. }
  601. //光控测试任务
  602. void SunTest(void)
  603. {
  604. while(Read_Light_Voltage()<500)
  605. {
  606. rt_thread_delay(1000);
  607. }
  608. rt_thread_delay(3000);
  609. if(Read_Light_Voltage()<500)
  610. {
  611. device_status.sun_status = 0;//光控状态
  612. }
  613. if(Read_Light_Voltage()>500)
  614. {
  615. rt_thread_delay(1000);
  616. }
  617. rt_thread_delay(3000);
  618. if(Read_Light_Voltage()>500)
  619. {
  620. device_status.sun_status = 1;
  621. ctr_lamp(OFF);
  622. }
  623. HMI_WRITE("sysTest.switchSun.val=%d",0);
  624. device_status.sun_test = 0;
  625. device_status.work_status=0;
  626. }
  627. /*上电初始化*/
  628. void ResetInit(void)
  629. {
  630. device_status.work_done = 1;
  631. //1.打开路由器供电
  632. ctr_router(ON);
  633. ctr_RTU_DTU(ON);
  634. //2.打开相机供电
  635. ctr_photo(ON);
  636. //3.关闭镇流器
  637. ctr_lamp(OFF);
  638. //4.关闭震动电机
  639. ctr_shake(OFF, 0);
  640. //5.关闭加热
  641. ctr_Heat(OFF);
  642. //6.关闭补光灯
  643. ctr_led(OFF);
  644. if(device_status.bat_status==1||atoi(device_status.fuse_voltage)<1)
  645. {
  646. rt_kprintf("欠压!!!\n");
  647. return;
  648. }
  649. //7.关闭上仓门
  650. device_status.ctr_up_motor = 2;
  651. while(device_status.ctr_up_motor!=0)
  652. {
  653. rt_kprintf("关闭上仓门...\n");
  654. rt_thread_delay(100);
  655. }
  656. //8.关闭下仓门
  657. device_status.ctr_down_motor = 2;
  658. while(device_status.ctr_down_motor!=0)
  659. {
  660. rt_kprintf("关闭下仓门....\n");
  661. rt_thread_delay(100);
  662. }
  663. //9.清扫
  664. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  665. {
  666. rt_kprintf("异常退出!!!\n");
  667. return;
  668. }
  669. if(device_status.version_type==4)
  670. {
  671. if(ctr_clear(650)==0)
  672. ctr_TG_Clear(350);
  673. }
  674. else if (device_status.version_type==1) {
  675. turnzp();
  676. }
  677. rt_thread_delay(1000);
  678. }
  679. //出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
  680. void HardWare_Check(uint8_t boot)
  681. {
  682. if(boot==0)
  683. {
  684. //停止所有动作 -完成
  685. HardWare_Init(boot);
  686. }
  687. else {
  688. //停止所有动作
  689. //读取记录待机功耗(实测大概70mA)
  690. //(需减去屏幕的功耗大概120mA)
  691. //动作上仓门,读取功率值保存
  692. //动作下仓门,读取功率值保存
  693. //动作清扫,读取功率值保存
  694. //打开镇流器,读取功率值保存
  695. //打开海康相机供电,读取功率值保存
  696. //打开补光灯,读取功率值保存
  697. //打开路由器/RTU供电,读取功率值保存
  698. //打开加热,读取功率值保存
  699. }
  700. }
  701. //工作状态检测
  702. void WorkCheck(void)
  703. {
  704. //雨控检测,温控检测,电池电压检测
  705. while(device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
  706. {
  707. //工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
  708. if(device_status.timeSwitch==1)
  709. {
  710. rt_kprintf("***************时控*****************\n");
  711. //如果开始和结束是同一天
  712. if(device_status.startBar<device_status.stopBar)
  713. {
  714. rt_kprintf("开始和结束是同一天");
  715. time_t now;
  716. time(&now);
  717. static struct tm nowtime; //现在
  718. static struct tm starttime; //开始
  719. static struct tm endtime; //结束
  720. //获取当前时间戳
  721. nowtime =*localtime(&now);
  722. nowtime.tm_hour = nowtime.tm_hour-8;
  723. //获取定时开始的时间戳
  724. starttime = *localtime(&now);
  725. starttime.tm_hour = device_status.startBar-8;
  726. starttime.tm_min = 0;
  727. starttime.tm_sec = 0;
  728. //获取定时结束的时间戳
  729. endtime = *localtime(&now);
  730. endtime.tm_hour = device_status.stopBar-8;
  731. endtime.tm_min = 0;
  732. endtime.tm_sec = 0;
  733. rt_kprintf("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***\n",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  734. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  735. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
  736. {
  737. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中!!!\n");
  738. device_status.work_status = 1;
  739. }
  740. //如果当前时间小于开始时间
  741. else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
  742. {
  743. rt_kprintf("当前时间小于开始时间,不工作!!!-%d-%d\n",mktime(&nowtime),mktime(&starttime));
  744. device_status.work_status = 0;
  745. }
  746. //当前时间大于结束时间
  747. else {
  748. rt_kprintf("当前时间大于结束时间,不工作!!!-%d-%d\n",mktime(&nowtime),mktime(&starttime));
  749. device_status.work_status = 0;
  750. }
  751. }
  752. //如果结束时间是第二天
  753. else if (device_status.startBar>device_status.stopBar) {
  754. time_t now;
  755. time(&now);
  756. static struct tm nowtime; //现在
  757. static struct tm starttime; //开始
  758. static struct tm endtime; //结束
  759. //获取当前时间戳
  760. nowtime =*localtime(&now);
  761. nowtime.tm_hour = nowtime.tm_hour-8;
  762. //获取定时开始的时间戳
  763. starttime = *localtime(&now);
  764. starttime.tm_hour = device_status.startBar-8;
  765. starttime.tm_min = 0;
  766. starttime.tm_sec = 0;
  767. //获取定时结束的时间戳
  768. endtime = *localtime(&now);
  769. endtime.tm_hour = device_status.stopBar-8;
  770. endtime.tm_min = 0;
  771. endtime.tm_sec = 0;
  772. rt_kprintf("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!\n",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  773. //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
  774. if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
  775. {
  776. //获取定时结束的时间戳
  777. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  778. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  779. endtime.tm_min = 0;
  780. endtime.tm_sec = 0;
  781. device_status.work_status = 1;
  782. rt_kprintf("当前前时间大于开始时间,且没有开始工作\n");
  783. }
  784. //当前时间小于开始时间
  785. else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
  786. {
  787. //获取定时结束的时间戳
  788. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  789. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  790. endtime.tm_min = 0;
  791. endtime.tm_sec = 0;
  792. //如果当前时间戳小于结束时间戳
  793. if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
  794. {
  795. rt_kprintf("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间\n");
  796. device_status.work_status = 1;
  797. }
  798. else
  799. {
  800. rt_kprintf("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间!!!\n");
  801. device_status.work_status = 0; //不在工作时间,待机
  802. }
  803. }
  804. }
  805. }
  806. else {
  807. rt_kprintf("光控定时模式!!!\n");
  808. time_t now;
  809. time(&now);
  810. static struct tm nowstamp;
  811. nowstamp =*localtime(&now);
  812. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  813. static rt_uint32_t nowstamp_num = 0;
  814. nowstamp_num = mktime(&nowstamp);
  815. rt_kprintf("now stamp:%d\n",nowstamp_num);
  816. if(device_status.sun_status==0)
  817. {
  818. //检测到光控,计算定时
  819. if(device_status.light_over_tim > nowstamp_num)
  820. {
  821. device_status.work_status = 1;
  822. rt_kprintf("光控定时,计时中:%d----%d\n",device_status.light_over_tim,nowstamp_num);
  823. }
  824. else
  825. {
  826. device_status.work_status = 0; //置位工作状态
  827. rt_kprintf("光控定时任务已完成!!!\n");
  828. }
  829. }
  830. else
  831. {
  832. device_status.work_status = 0;
  833. device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
  834. rt_kprintf("光控中,白天:%d!!!\n",nowstamp_num);
  835. }
  836. }
  837. rt_thread_delay(1000);
  838. }
  839. rt_kprintf("雨控状态,温控状态,电压状态:\n%d\n%d\n%d\n",device_status.rain_status,device_status.temp_status,device_status.bat_status);
  840. device_status.work_status = 0;
  841. rt_thread_delay(1000);
  842. }
  843. //工作状态检测-LED
  844. void WorkCheck_LED(void)
  845. {
  846. while(device_status.temp_status==0&&device_status.bat_status==0&&device_status.rain_status==0&&device_status.ds==1)
  847. {
  848. time_t now;
  849. time(&now);
  850. static struct tm nowtime; //现在
  851. static struct tm start_time; //阶段1:17:30-18:30
  852. static struct tm end_time_1; //阶段1:17:30-18:30
  853. static struct tm end_time_2; //阶段2:18:30-19:30
  854. static struct tm end_time_3; //阶段3:19:30-20:30
  855. static struct tm end_time_4; //阶段3:20:30-22:30
  856. static struct tm end_time_5; //阶段3:22:30-01:30
  857. static struct tm end_time_6; //阶段3:01:30-05:30
  858. static struct tm end_time_7; //阶段3:05:30-06:30
  859. //获取当前时间戳
  860. nowtime =*localtime(&now);
  861. nowtime.tm_hour = nowtime.tm_hour-8;
  862. //获取阶段1的开始时间戳
  863. start_time = *localtime(&now);
  864. start_time.tm_hour = 17-8;
  865. start_time.tm_min = 30;
  866. start_time.tm_sec = 0;
  867. //获取阶段1的结束时间戳
  868. end_time_1 = *localtime(&now);
  869. end_time_1.tm_hour = 18-8;
  870. end_time_1.tm_min = 30;
  871. end_time_1.tm_sec = 0;
  872. //获取阶段2的结束时间戳
  873. end_time_2 = *localtime(&now);
  874. end_time_2.tm_hour = 19-8;
  875. end_time_2.tm_min = 30;
  876. end_time_2.tm_sec = 0;
  877. //获取阶段3的结束时间
  878. end_time_3 = *localtime(&now);
  879. end_time_3.tm_hour = 20-8;
  880. end_time_3.tm_min = 30;
  881. end_time_3.tm_sec = 0;
  882. //获取阶段4的结束时间戳
  883. end_time_4 = *localtime(&now);
  884. end_time_4.tm_hour = 22 - 8;
  885. end_time_4.tm_min = 30;
  886. end_time_4.tm_sec = 0;
  887. //获取阶段5的结束时间戳
  888. end_time_5 = *localtime(&now);
  889. end_time_5.tm_hour = 1 - 8;
  890. end_time_5.tm_min = 30;
  891. end_time_5.tm_sec = 0;
  892. //获取阶段6的结束时间戳
  893. end_time_6 = *localtime(&now);
  894. end_time_6.tm_hour = 5 - 8;
  895. end_time_6.tm_min = 30;
  896. end_time_6.tm_sec = 0;
  897. //获取阶段6的结束时间戳
  898. end_time_7 = *localtime(&now);
  899. end_time_7.tm_hour = 6 - 8;
  900. end_time_7.tm_min = 30;
  901. end_time_7.tm_sec = 0;
  902. rt_kprintf("阶段1:现在时间:%d-开始时间1:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&start_time),mktime(&end_time_1));
  903. rt_kprintf("阶段2:现在时间:%d-开始时间2:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_1),mktime(&end_time_2));
  904. rt_kprintf("阶段3:现在时间:%d-开始时间3:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_2),mktime(&end_time_3));
  905. rt_kprintf("阶段4:现在时间:%d-开始时间4:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_3),mktime(&end_time_4));
  906. rt_kprintf("阶段5:现在时间:%d-开始时间5:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_4),mktime(&end_time_5));
  907. rt_kprintf("阶段6:现在时间:%d-开始时间6:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_5),mktime(&end_time_6));
  908. rt_kprintf("阶段7:现在时间:%d-开始时间7:%d-结束时间1:%d***\n",mktime(&nowtime),mktime(&end_time_6),mktime(&end_time_7));
  909. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  910. if((difftime(mktime(&nowtime), mktime(&start_time)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_1))<0))
  911. {
  912. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,亮紫灯!!!\n");
  913. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_ON, GREEN_OFF);
  914. device_status.work_status = 1;
  915. }
  916. else if ((difftime(mktime(&nowtime), mktime(&end_time_1)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_2))<0)) {
  917. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,黄绿光灯打开,蓝紫光灯关!!!\n");
  918. ctr_LED(BLUE_OFF, YELLOW_ON, PURPLE_OFF, GREEN_ON);
  919. device_status.work_status = 1;
  920. }
  921. else if ((difftime(mktime(&nowtime), mktime(&end_time_2)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_3))<0)) {
  922. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,紫光灯打开,黄绿蓝光灯关!!!\n");
  923. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_ON, GREEN_OFF);
  924. device_status.work_status = 1;
  925. }
  926. else if ((difftime(mktime(&nowtime), mktime(&end_time_3)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_4))<0)) {
  927. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,蓝光灯打开,黄绿紫光灯关!!!\n");
  928. ctr_LED(BLUE_ON, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  929. device_status.work_status = 1;
  930. }
  931. else if ((difftime(mktime(&nowtime), mktime(&end_time_4)) >=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_4))<0)&&(difftime(mktime(&nowtime),mktime(&end_time_5)) < 0)) {
  937. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,紫光灯打开,黄绿蓝光灯关!!!\n");
  938. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_ON, GREEN_OFF);
  939. device_status.work_status = 1;
  940. }
  941. else if ((difftime(mktime(&nowtime), mktime(&end_time_5)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_6))<0)) {
  942. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  943. device_status.work_status = 0;
  944. rt_kprintf("全部关灯,节约用电!!!\n");
  945. }
  946. else if ((difftime(mktime(&nowtime), mktime(&end_time_6)) >=0) && (difftime(mktime(&nowtime),mktime(&end_time_7))<0)) {
  947. rt_kprintf("当前时间大于开始时间,小于结束时间,工作中,黄绿灯打开,紫蓝光灯关!!!\n");
  948. ctr_LED(BLUE_OFF, YELLOW_ON, PURPLE_OFF, GREEN_ON);
  949. device_status.work_status = 1;
  950. }
  951. else {
  952. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  953. device_status.work_status = 0;
  954. rt_kprintf("全部关灯,进入充电程序!!!\n");
  955. }
  956. rt_thread_delay(1000);
  957. }
  958. rt_kprintf("雨控状态,温控状态,电压状态:\n%d\n%d\n%d\n",device_status.rain_status,device_status.temp_status,device_status.bat_status);
  959. device_status.work_status = 0;
  960. rt_thread_delay(1000);
  961. }
  962. //工作任务流程s
  963. void WorkTast(void)
  964. {
  965. ctr_router(ON); //打开路由器供电
  966. static int clt_time = 0; //收集时间差秒数
  967. rt_kprintf("工作状态:%d\n",device_status.work_status);
  968. rt_kprintf("开关机状态:%d\n",device_status.ds);
  969. 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)
  970. {
  971. device_status.work_done = 0;
  972. if(clt_time==0) DTU_Write("workstart.mp3");
  973. rt_thread_delay(5000); //待灯管启动再往下执行,否则会触发电机过流
  974. //2.打开上仓门
  975. rt_kprintf("打开上仓门!!!\n");
  976. device_status.ctr_up_motor = 1;
  977. //3.收集
  978. clt_time = device_status.clt_time * 60;
  979. while(clt_time!=1)
  980. {
  981. clt_time --;
  982. rt_thread_delay(1000);
  983. rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
  984. //如果触发异常
  985. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  986. {
  987. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  988. rt_kprintf("异常退出!!!\n");
  989. break;
  990. }
  991. }
  992. clt_time = 1;
  993. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  994. {
  995. //ctr_lamp(OFF);
  996. ctr_LED(BLUE_OFF, YELLOW_OFF, PURPLE_OFF, GREEN_OFF);
  997. rt_kprintf("异常退出!!!\n");
  998. break;
  999. }
  1000. //4.关闭上仓门
  1001. device_status.ctr_up_motor = 2;
  1002. rt_kprintf("关闭上仓门!!!\n");
  1003. // while(device_status.ctr_up_motor!=0)
  1004. // {
  1005. // rt_thread_delay(100);
  1006. // rt_kprintf("等待上仓门关闭!!!\n");
  1007. // }
  1008. //5.加热
  1009. rt_kprintf("加热!!!\n");
  1010. calorstat(device_status.heattime*60);
  1011. //6.打开下仓门
  1012. if(device_status.rain_status==0)
  1013. {
  1014. device_status.ctr_down_motor =1;
  1015. }
  1016. //待下仓门完全打开
  1017. while(device_status.ctr_down_motor!=0)
  1018. {
  1019. rt_thread_delay(100);
  1020. rt_kprintf("等待下仓门打开!!!\n");
  1021. }
  1022. rt_thread_delay(3000);
  1023. //关闭下仓门
  1024. device_status.ctr_down_motor = 2;
  1025. while(device_status.ctr_down_motor!=0)
  1026. {
  1027. rt_thread_delay(100);
  1028. rt_kprintf("等待下仓门关闭!!!\n");
  1029. }
  1030. if(device_status.version_type==4)
  1031. {
  1032. //震动
  1033. ctr_shake(ON, 1);
  1034. //补光&&拍照
  1035. rt_kprintf("拍照!!!\n");
  1036. HK_TakePhoto();
  1037. //清扫
  1038. if(ctr_clear(1200)==0)
  1039. ctr_TG_Clear(350);
  1040. //清扫失效则使用震动
  1041. //ctr_shake(ON, 100);
  1042. }
  1043. }
  1044. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1||device_status.ds==0)
  1045. {
  1046. rt_kprintf("-------------------not work--------------------\n");
  1047. device_status.work_status = 0;
  1048. }
  1049. //工作结束
  1050. if(device_status.work_done==0&&device_status.work_status==0)
  1051. {
  1052. DTU_Write("workdone");
  1053. ResetInit();
  1054. }
  1055. rt_kprintf("***not work-device status:%d\n",device_status.ds);
  1056. }
  1057. /* 入口函数-工作状态检测 */
  1058. static void Work_status_thread_entry(void *parameter)
  1059. {
  1060. // static uint16_t sun_status_num = 300;
  1061. // //如果是光控定时,进行光控监测的消抖
  1062. // if(device_status.timeSwitch==0&&device_status.sun_status==0)
  1063. // {
  1064. // rt_kprintf("光控定时!!!\n");
  1065. // while(sun_status_num!=0)
  1066. // {
  1067. // sun_status_num--;
  1068. // rt_thread_delay(1000);
  1069. // rt_kprintf("开机光控检测:%d\n",sun_status_num);
  1070. // }
  1071. // time_t now;
  1072. // time(&now);
  1073. // static struct tm nowstamp;
  1074. // nowstamp =*localtime(&now);
  1075. // nowstamp.tm_hour = nowstamp.tm_hour - 8;
  1076. // static rt_uint32_t nowstamp_num = 0;
  1077. // nowstamp_num = mktime(&nowstamp);
  1078. // device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
  1079. // }
  1080. while(1)
  1081. {
  1082. WorkCheck_LED();
  1083. rt_thread_delay(1);
  1084. }
  1085. }
  1086. /*入口函数-工作流程*/
  1087. static void Work_Loop_thread_entry(void *parameter)
  1088. {
  1089. rt_thread_delay(1000);
  1090. ResetInit();
  1091. while(1)
  1092. {
  1093. WorkTast();
  1094. rt_thread_delay(1000);
  1095. }
  1096. }
  1097. /* 创建线程 -是否置位工作状态*/
  1098. int Workstatus_check(void)
  1099. {
  1100. /* 创建线程*/
  1101. tid_wkstc = rt_thread_create("work_status_check_thread",
  1102. Work_status_thread_entry, RT_NULL,
  1103. WORK_CHECK_THREAD_STACK_SIZE, //2048
  1104. WORK_CHECK_THREAD_PRIORITY, //23
  1105. WORK_CHECK_THREAD_TIMESLICE); //5
  1106. if(tid_wkstc!=RT_NULL)
  1107. {
  1108. rt_thread_startup(tid_wkstc);
  1109. }
  1110. return 0;
  1111. }
  1112. /*工作流程线程*/
  1113. int Work_Loop_Task(void)
  1114. {
  1115. /* 创建线程*/
  1116. tid_workloop = rt_thread_create("work_loop_thread",
  1117. Work_Loop_thread_entry, RT_NULL,
  1118. WORK_LOOP_THREAD_STACK_SIZE, //2048
  1119. WORK_LOOP_THREAD_PRIORITY, //12
  1120. WORK_LOOP_THREAD_TIMESLICE); //5
  1121. if(tid_workloop!=RT_NULL)
  1122. {
  1123. rt_thread_startup(tid_workloop);
  1124. }
  1125. return 0;
  1126. }
  1127. MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
  1128. MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
  1129. MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
  1130. MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);