control.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406
  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. uint8_t ctr_Motor_xichong(uint8_t status_ws)
  110. {
  111. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  112. if(status_ws==ON)
  113. {
  114. rt_pin_write(MOTOR1_CTR_PIN,ON);
  115. }
  116. else {
  117. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  118. }
  119. return 0;
  120. }
  121. uint8_t ctr_Camera_Power(uint8_t status_ws)
  122. {
  123. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  124. if(status_ws==ON)
  125. {
  126. rt_pin_write(MOTOR1_CTR_PIN,ON);
  127. }
  128. else {
  129. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  130. }
  131. return 0;
  132. }
  133. //吸附电机
  134. uint8_t ctr_Motor_xifu(uint8_t status_ws)
  135. {
  136. rt_pin_mode(MOTOR2_CTR_PIN, PIN_MODE_OUTPUT);
  137. if(status_ws==ON)
  138. {
  139. rt_pin_write(MOTOR2_CTR_PIN,ON);
  140. }
  141. else {
  142. rt_pin_write(MOTOR2_CTR_PIN, OFF);
  143. }
  144. return 0;
  145. }
  146. //清扫-卷带电机
  147. void ctr_JD_Clear(uint8_t shake_sw)
  148. {
  149. rt_uint16_t turn_timeout = 0;
  150. rt_pin_mode(MOTOR_C_LIMIT,PIN_MODE_INPUT);
  151. ctr_cangmen_up(OFF); //清扫传送带的电机
  152. if(shake_sw==ON)
  153. {
  154. ctr_Heat(ON); //清洁风机
  155. Motor_shake(ON, 0);
  156. ctr_cangmen_up(OPEN); //打开清扫
  157. }
  158. else {
  159. Motor_shake(OFF, 0);
  160. ctr_cangmen_up(OPEN); //打开清扫
  161. }
  162. while(rt_pin_read(MOTOR_C_LIMIT)==0)
  163. {
  164. Motor_Juandai(ON);
  165. rt_thread_delay(50);
  166. turn_timeout++;
  167. if(turn_timeout==1000) break;
  168. }
  169. turn_timeout = 0;
  170. while(rt_pin_read(MOTOR_C_LIMIT)==1)
  171. {
  172. Motor_Juandai(ON);
  173. turn_timeout++;
  174. rt_thread_delay(50);
  175. if(turn_timeout==1000) break;
  176. }
  177. Motor_shake(OFF, 1);
  178. Motor_Juandai(OFF);
  179. ctr_cangmen_up(OFF); //关闭清扫
  180. ctr_Heat(OFF);
  181. }
  182. //工作任务流程
  183. void WorkTask_XCT(void)
  184. {
  185. while(device_status.work_status==1&&device_status.ds==1)
  186. {
  187. ctr_Motor_xifu(ON);
  188. //打开相机供电
  189. ctr_Camera_Power(ON);
  190. //ctr_Heat(ON); //清洁风机
  191. uint32_t photo_fre = 0;
  192. photo_fre = device_status.dattim * 60;
  193. while(photo_fre!=0)
  194. {
  195. photo_fre --;
  196. rt_thread_delay(1000);
  197. LOG_I("收集中,等待开始拍照:%d",photo_fre);
  198. }
  199. //卷带
  200. ctr_JD_Clear(OFF);
  201. //拍照
  202. HK_TakePhoto();
  203. //关闭吸附风机
  204. ctr_Motor_xifu(OFF);
  205. //关闭相机供电
  206. //ctr_Heat(OFF);
  207. ctr_Camera_Power(OFF);
  208. //卷带
  209. ctr_JD_Clear(ON);
  210. // rt_thread_delay(1000);
  211. // ctr_JD_Clear(ON);
  212. //震动
  213. Motor_shake(ON, device_status.shake_sec);
  214. }
  215. //关闭风机
  216. ctr_Motor_xichong(OFF);
  217. ctr_Motor_xifu(OFF);
  218. LOG_I("不在工作时间,未工作!!!");
  219. }
  220. /**********************************************************************/
  221. /*光控*/
  222. uint8_t In_Light_status(void)
  223. {
  224. rt_pin_mode(LIGHT_PIN,PIN_MODE_INPUT);
  225. return rt_pin_read(LIGHT_PIN);
  226. }
  227. /*雨控*/
  228. uint8_t In_Rain_status(void)
  229. {
  230. rt_pin_mode(RAIN_PIN,PIN_MODE_INPUT);
  231. return rt_pin_read(RAIN_PIN);
  232. }
  233. /*加热*/
  234. uint8_t ctr_Heat(uint8_t status_heat)
  235. {
  236. device_status.heat_status = status_heat;
  237. rt_pin_mode(Heat_Pin, PIN_MODE_OUTPUT);
  238. rt_pin_write(Heat_Pin,status_heat);
  239. return status_heat;
  240. }
  241. /*制冷*/
  242. uint8_t ctr_Cold(uint8_t status_cold)
  243. {
  244. device_status.cold_status = status_cold;
  245. rt_pin_mode(Cold_Pin, PIN_MODE_OUTPUT);
  246. rt_pin_write(Cold_Pin,status_cold);
  247. return status_cold;
  248. }
  249. /*相机供电*/
  250. void ctr_photo(uint8_t status_photo)
  251. {
  252. rt_pin_mode(PHOTO,PIN_MODE_OUTPUT);
  253. rt_pin_write(PHOTO,status_photo);
  254. }
  255. /*************************************************
  256. Function: ctr_Cool_Fan
  257. Description: 散热风机的开关
  258. Calls:
  259. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  260. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  261. Input: ON-开,OFF-关
  262. Output: NULL
  263. Return: ON-开,OFF-关
  264. Others: NULL
  265. *************************************************/
  266. uint8_t ctr_Cool_Fan(uint8_t status_cool)
  267. {
  268. device_status.cool_fan_status = status_cool;
  269. rt_pin_mode(Cool_Fan_L, PIN_MODE_OUTPUT);
  270. rt_pin_mode(Cool_Fan_R, PIN_MODE_OUTPUT);
  271. if(status_cool==OFF)
  272. {
  273. rt_pin_write(Cool_Fan_L,OFF);
  274. rt_pin_write(Cool_Fan_R,OFF);
  275. }
  276. if(status_cool==ON)
  277. {
  278. rt_pin_write(Cool_Fan_L,ON);
  279. rt_pin_write(Cool_Fan_R,OFF);
  280. }
  281. return device_status.cool_fan_status;
  282. }
  283. /*************************************************
  284. Function: ctr_Collect_Fan
  285. Description: 采集风机的开关
  286. Calls:
  287. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  288. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  289. Input: ON-开,OFF-关
  290. Output: NULL
  291. Return: ON-开,OFF-关
  292. Others: NULL
  293. *************************************************/
  294. uint8_t ctr_Collect_Fan(uint8_t status_collect)
  295. {
  296. device_status.collect_fan_status = status_collect;
  297. rt_pin_mode(Collect_Fan, PIN_MODE_OUTPUT);
  298. if(status_collect==OFF)
  299. {
  300. rt_pin_write(Collect_Fan,OFF);
  301. }
  302. if(status_collect==ON)
  303. {
  304. rt_pin_write(Collect_Fan,ON);
  305. }
  306. return device_status.collect_fan_status;
  307. }
  308. /*************************************************
  309. Function: ctr_develop
  310. Description: 培养载玻片孢子
  311. Calls:
  312. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  313. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  314. Input: v=0(复位) v=90转90度
  315. Output: NULL
  316. Return: NULL
  317. Others: NULL
  318. *************************************************/
  319. /*上仓门*/
  320. uint8_t ctr_cangmen_up(uint8_t status_up)
  321. {
  322. rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
  323. rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
  324. if(status_up==OFF)
  325. {
  326. rt_pin_write(Collect_fan_R,ON);
  327. rt_pin_write(Collect_fan_L,ON);
  328. device_status.ctr_up_motor = 0;
  329. rt_thread_delay(1000);
  330. }
  331. if(status_up==OPEN)
  332. {
  333. device_status.up_status = 1;
  334. rt_pin_write(Collect_fan_R,OFF);
  335. rt_pin_write(Collect_fan_L,OFF);
  336. #if PCB_V1 == 1
  337. rt_pin_write(Collect_fan_R,ON);
  338. rt_pin_write(Collect_fan_L,OFF);
  339. #else
  340. rt_pin_write(Collect_fan_R,OFF);
  341. rt_pin_write(Collect_fan_L,ON);
  342. #endif
  343. }
  344. if(status_up==CLOSE)
  345. {
  346. device_status.up_status = 0;
  347. rt_pin_write(Collect_fan_R,OFF);
  348. rt_pin_write(Collect_fan_L,OFF);
  349. #if PCB_V1 == 1
  350. rt_pin_write(Collect_fan_R,OFF);
  351. rt_pin_write(Collect_fan_L,ON);
  352. #else
  353. rt_pin_write(Collect_fan_R,ON);
  354. rt_pin_write(Collect_fan_L,OFF);
  355. #endif
  356. }
  357. return device_status.up_status;
  358. }
  359. //下仓门
  360. uint8_t ctr_cangmen_down(uint8_t status_down)
  361. {
  362. rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
  363. rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
  364. if(status_down==OFF)
  365. {
  366. rt_pin_write(C_DOWN_R,ON);
  367. rt_pin_write(C_DOWN_L,ON);
  368. device_status.ctr_down_motor = 0;
  369. rt_thread_delay(1000);
  370. }
  371. if(status_down==OPEN)
  372. {
  373. device_status.down_status = 1;
  374. rt_pin_write(C_DOWN_R,OFF);
  375. rt_pin_write(C_DOWN_L,OFF);
  376. rt_pin_write(C_DOWN_R,ON);
  377. rt_pin_write(C_DOWN_L,OFF);
  378. }
  379. if(status_down==CLOSE)
  380. {
  381. device_status.down_status = 0;
  382. rt_pin_write(C_DOWN_R,OFF);
  383. rt_pin_write(C_DOWN_L,OFF);
  384. rt_pin_write(C_DOWN_R,OFF);
  385. rt_pin_write(C_DOWN_L,ON);
  386. }
  387. return device_status.down_status;
  388. }
  389. //镇流器
  390. uint8_t ctr_lamp(uint8_t status_lamp,uint8_t lamp_num)
  391. {
  392. rt_pin_mode(LAMP_SW, PIN_MODE_OUTPUT);
  393. rt_pin_mode(LAMP_1_SW, PIN_MODE_OUTPUT);
  394. rt_pin_mode(LAMP_2_SW, PIN_MODE_OUTPUT);
  395. if(status_lamp==ON)
  396. {
  397. switch(lamp_num){
  398. case 1:
  399. rt_pin_write(LAMP_SW,ON);
  400. device_status.lamp_status = status_lamp;
  401. break;
  402. case 2:
  403. rt_pin_write(LAMP_1_SW,ON);
  404. device_status.lamp_status = status_lamp;
  405. break;
  406. case 3:
  407. rt_pin_write(LAMP_2_SW,ON);
  408. device_status.lamp_status = status_lamp;
  409. break;
  410. default:
  411. break;
  412. }
  413. }
  414. else {
  415. switch(lamp_num){
  416. case 1:
  417. rt_pin_write(LAMP_SW,OFF);
  418. device_status.lamp_status = status_lamp;
  419. break;
  420. case 2:
  421. rt_pin_write(LAMP_1_SW,OFF);
  422. device_status.lamp1_status = status_lamp;
  423. break;
  424. case 3:
  425. rt_pin_write(LAMP_2_SW,OFF);
  426. device_status.lamp2_status = status_lamp;
  427. break;
  428. default:
  429. break;
  430. }
  431. }
  432. HMI_WRITE("sysTest.switchLamp.val=%d",device_status.lamp_status);
  433. return device_status.lamp_status;
  434. }
  435. //震动电机
  436. uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec)
  437. {
  438. static rt_uint16_t shake_i = 0;
  439. if(device_status.dtype==7&&shake_sec!=0)
  440. DTU_Write("drop");
  441. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  442. #if 0
  443. rt_pin_write(SHAKE_SW,ON);
  444. return 0;
  445. #endif
  446. if(status_shake==ON&&device_status.shake_ws==1)
  447. {
  448. if(device_status.dtype==3)
  449. {
  450. while(shake_sec--)
  451. {
  452. rt_pin_write(SHAKE_SW,ON);
  453. rt_thread_delay(50);
  454. rt_pin_write(SHAKE_SW,OFF);
  455. rt_thread_delay(1000);
  456. }
  457. }
  458. if(device_status.dtype==7) rt_thread_delay(shake_sec*1000);
  459. rt_pin_write(SHAKE_SW,OFF);
  460. HMI_WRITE("cangWei.switchShake.val=%d",0);
  461. }
  462. else
  463. {
  464. rt_pin_write(SHAKE_SW,OFF);
  465. HMI_WRITE("cangWei.switchShake.val=%d",0);
  466. }
  467. if(device_status.dtype==7)
  468. HMI_WRITE("sysTest.switchDrop.val=%d",OFF);
  469. return status_shake;
  470. }
  471. //补光
  472. uint8_t ctr_led(uint8_t status_led)
  473. {
  474. rt_pin_mode(LED_SW, PIN_MODE_OUTPUT);
  475. if(device_status.version_type==6)
  476. rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
  477. if(status_led==ON)
  478. {
  479. rt_pin_write(LED_SW,ON);
  480. if(device_status.version_type==6)
  481. rt_pin_write(LED_P,ON);
  482. HMI_WRITE("sysTest.switchFill.val=%d",ON);
  483. }
  484. else if(status_led==OFF){
  485. rt_pin_write(LED_SW,OFF);
  486. if(device_status.version_type==6)
  487. rt_pin_write(LED_P,OFF);
  488. HMI_WRITE("sysTest.switchPhoto.val=%d",OFF);
  489. HMI_WRITE("sysTest.switchFill.val=%d",OFF);
  490. }
  491. return status_led;
  492. }
  493. /*************************************************
  494. Function: ctr_turn
  495. Description: 转盘驱动
  496. Calls:
  497. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  498. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  499. Input: v=0(复位) v=90转90度
  500. Output: NULL
  501. Return: NULL
  502. Others: NULL
  503. *************************************************/
  504. void ctr_turn(uint8_t v,uint8_t sta)
  505. {
  506. DTU_Write("turn.mp3");
  507. LOG_I("================v===============:%d",v);
  508. rt_uint16_t turn_cnt = 0;
  509. rt_pin_mode(TURN_ZP_R, PIN_MODE_OUTPUT);
  510. rt_pin_mode(TURN_ZP_L, PIN_MODE_OUTPUT);
  511. rt_pin_mode(LIMIT_0, PIN_MODE_INPUT);
  512. rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
  513. //if(v==0&&rt_pin_read(LIMIT_0)==0) return; //如果在初始位置,则不再往下执行
  514. while(rt_pin_read(LIMIT_0)==0||rt_pin_read(LIMIT_90)==0)
  515. {
  516. rt_pin_write(TURN_ZP_R, ON);
  517. rt_pin_write(TURN_ZP_L, OFF);
  518. //Motor_shake(ON,0);
  519. turn_cnt ++;
  520. rt_thread_delay(100);
  521. if(turn_cnt==1000)
  522. {
  523. turn_cnt = 0;
  524. rt_pin_write(TURN_ZP_R, OFF);
  525. rt_pin_write(TURN_ZP_L, OFF);
  526. //Motor_shake(OFF,0);
  527. char *turn_warn =makeJson_Warn("未检测到限位", "转盘");
  528. DTU_Write("%s",turn_warn);
  529. rt_free(turn_warn);
  530. break;
  531. }
  532. }
  533. turn_cnt = 0;
  534. while(v==0&&rt_pin_read(LIMIT_0)==1)
  535. {
  536. rt_pin_write(TURN_ZP_R, ON);
  537. rt_pin_write(TURN_ZP_L, OFF);
  538. Motor_shake(ON,0);
  539. rt_thread_delay(200); //10 to 100
  540. turn_cnt ++;
  541. if(turn_cnt==300) //6000 to 600
  542. {
  543. turn_cnt = 0;
  544. // rt_pin_write(TURN_ZP_R, OFF);
  545. // rt_pin_write(TURN_ZP_L, OFF);
  546. // char *turn_warn =makeJson_Warn("超时", "转盘复位");
  547. // DTU_Write("%s",turn_warn);
  548. // rt_free(turn_warn);
  549. break;
  550. }
  551. }
  552. while(v==0&&rt_pin_read(LIMIT_0)==1)
  553. {
  554. rt_pin_write(TURN_ZP_R, ON);
  555. rt_pin_write(TURN_ZP_L, OFF);
  556. //Motor_shake(ON,0);
  557. rt_thread_delay(50); //10 to 50
  558. turn_cnt ++;
  559. if(turn_cnt==10) //6000 to 1200
  560. {
  561. turn_cnt = 0;
  562. rt_pin_write(TURN_ZP_R, OFF);
  563. rt_pin_write(TURN_ZP_L, OFF);
  564. //Motor_shake(OFF,0);
  565. char *turn_warn =makeJson_Warn("超时", "转盘复位");
  566. DTU_Write("%s",turn_warn);
  567. rt_free(turn_warn);
  568. break;
  569. }
  570. }
  571. turn_cnt = 0;
  572. while(v==90&&rt_pin_read(LIMIT_90)==1)
  573. {
  574. rt_pin_write(TURN_ZP_R, ON);
  575. rt_pin_write(TURN_ZP_L, OFF);
  576. //Motor_shake(ON,0);
  577. rt_thread_delay(200);
  578. turn_cnt ++;
  579. if(turn_cnt==150)
  580. {
  581. turn_cnt = 0;
  582. // rt_pin_write(TURN_ZP_R, OFF);
  583. // rt_pin_write(TURN_ZP_L, OFF);
  584. // char *turn_warn =makeJson_Warn("超时", "转盘");
  585. // DTU_Write(turn_warn);
  586. // rt_free(turn_warn);
  587. break;
  588. }
  589. }
  590. while(v==90&&rt_pin_read(LIMIT_90)==1)
  591. {
  592. // rt_pin_write(TURN_ZP_R, ON);
  593. // rt_pin_write(TURN_ZP_L, OFF);
  594. Motor_shake(ON,0);
  595. rt_thread_delay(50);
  596. turn_cnt ++;
  597. if(turn_cnt==10)
  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. char *turn_warn =makeJson_Warn("超时", "转盘");
  604. DTU_Write(turn_warn);
  605. rt_free(turn_warn);
  606. break;
  607. }
  608. }
  609. if(sta!=0)
  610. {
  611. //保存位置
  612. device_status.run_sta = sta;
  613. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  614. }
  615. turn_cnt = 0;
  616. rt_pin_write(TURN_ZP_R, OFF);
  617. rt_pin_write(TURN_ZP_L, OFF);
  618. Motor_shake(OFF,0);
  619. HMI_WRITE("cangWei.rotateFlag.val=0");
  620. }
  621. /*
  622. *
  623. * */
  624. void ctr_Motor_Driver_Power(uint8_t status_ws)
  625. {
  626. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  627. rt_pin_write(SHAKE_SW, status_ws);
  628. }
  629. /*************************************************
  630. Function: ctr_Motor_Driver
  631. Description: 步进电机驱动
  632. Calls:
  633. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  634. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  635. Input: 50000000
  636. Output: NULL
  637. Return: shake_sec
  638. Others: NULL
  639. *************************************************/
  640. void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_out)
  641. {
  642. beep_init();
  643. rt_pin_mode(LIMIT_UP, PIN_MODE_INPUT);
  644. rt_pin_mode(LIMIT_DOWN, PIN_MODE_INPUT);
  645. rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
  646. rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
  647. rt_pin_write(Motor_EN, EN);
  648. rt_pin_write(Motor_DIR, DIR);
  649. beep_set(pwm, pwm/2); //200kzh - 50%
  650. while(DIR==1&&rt_pin_read(LIMIT_DOWN)==1)
  651. {
  652. if(time_out==0)
  653. {
  654. break;
  655. }
  656. rt_thread_delay(50);
  657. time_out --;
  658. }
  659. while(DIR==0&&rt_pin_read(LIMIT_UP)==1)
  660. {
  661. if(time_out==0)
  662. {
  663. break;
  664. }
  665. rt_thread_delay(50);
  666. time_out --;
  667. }
  668. //rt_pin_write(Motor_EN, OFF);
  669. //if(device_status.autotakepic==0)
  670. //ctr_lamp(OFF, 1);
  671. beep_set(0, 0); //200kzh - 50%
  672. rt_thread_delay(50);
  673. }
  674. /*************************************************
  675. Function: ctr_Petroleum_jelly
  676. Description: 涂凡士林
  677. Calls:
  678. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  679. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  680. Input: NULL
  681. Output: NULL
  682. Return: NULL
  683. Others: NULL
  684. *************************************************/
  685. void ctr_Petroleum_jelly(rt_uint32_t delay)
  686. {
  687. beep_init();
  688. pwm_on(2,50000);
  689. rt_thread_delay(delay*1000);
  690. pwm_off(2,0);
  691. rt_thread_delay(1000);
  692. pwm_on(3, 50000);
  693. rt_thread_delay(delay*1000);
  694. pwm_off(3,0);
  695. device_status.fsl_sw = 0;
  696. }
  697. //1.0转仓
  698. void turnzp(void)
  699. {
  700. static uint16_t turn_timeout = 0;
  701. // rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  702. // rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  703. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  704. // rt_pin_write(CLEAR_R,OFF);
  705. // rt_pin_write(CLEAR_L,OFF);
  706. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  707. {
  708. rt_thread_delay(20);
  709. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  710. {
  711. ctr_Collect_Fan(ON);
  712. rt_thread_delay(50);
  713. turn_timeout++;
  714. if(turn_timeout==600)
  715. {
  716. LOG_E("检测不到限位,电机强制停止");
  717. char *ctr_zp_limit_warn =makeJson_Warn("电流不足/限位超时","转盘电机");
  718. DTU_Write("%s",ctr_zp_limit_warn);
  719. rt_free(ctr_zp_limit_warn);
  720. break;
  721. }
  722. }
  723. break;
  724. }
  725. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  726. {
  727. rt_thread_delay(20);
  728. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  729. {
  730. // rt_pin_write(CLEAR_R,ON);
  731. // rt_pin_write(CLEAR_L,OFF);
  732. ctr_Collect_Fan(ON);
  733. rt_thread_delay(50);
  734. turn_timeout++;
  735. if(turn_timeout==600)
  736. {
  737. LOG_E("检测不到离开限位,电机或者限位开关异常,电机强制停止");
  738. char *ctr_zp_limit_warn =makeJson_Warn("检测不到离开限位,电机未启动或者限位开关故障","转盘电机");
  739. DTU_Write("%s",ctr_zp_limit_warn);
  740. rt_free(ctr_zp_limit_warn);
  741. break;
  742. }
  743. }
  744. break;
  745. }
  746. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  747. {
  748. rt_thread_delay(20);
  749. if(rt_pin_read(CLEAR_R_LIMIT)==0)
  750. {
  751. // rt_pin_write(CLEAR_R,OFF);
  752. // rt_pin_write(CLEAR_L,OFF);
  753. ctr_Collect_Fan(OFF);
  754. break;
  755. }
  756. else {
  757. break;
  758. }
  759. }
  760. ctr_Collect_Fan(OFF);
  761. turn_timeout = 0;
  762. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  763. rt_thread_delay(1000);
  764. }
  765. //清扫-常闭型限位开关
  766. //新结构使用推杆电机做清扫
  767. uint8_t ctr_clear(uint16_t status_clear)
  768. {
  769. static uint16_t clear_num = 0;
  770. #if PWM_EN == 0
  771. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  772. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  773. #endif
  774. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  775. rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
  776. /*************************************************************外接清扫
  777. rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  778. rt_pin_write(POWER_CLEAR,ON);
  779. rt_thread_delay(1000*100);
  780. rt_pin_write(POWER_CLEAR,OFF);
  781. ************************************************************/
  782. //停止
  783. #if PWM_EN == 0
  784. rt_pin_write(CLEAR_R,OFF);
  785. rt_pin_write(CLEAR_L,OFF);
  786. #else
  787. Motor_Qingsao_R_PWM(OFF);
  788. Motor_Qingsao_L_PWM(OFF);
  789. #endif
  790. if(status_clear==OFF||Read_Real_Voltage()/100<12) return 0;
  791. rt_thread_delay(100);
  792. //如果清扫位置在中间
  793. while(rt_pin_read(CLEAR_R_LIMIT)==0&&rt_pin_read(CLEAR_L_LIMIT)==0)
  794. {
  795. #if PWM_EN == 0
  796. rt_pin_write(CLEAR_R,ON);
  797. rt_pin_write(CLEAR_L,OFF);
  798. #else
  799. Motor_Qingsao_R_PWM(ON);
  800. Motor_Qingsao_L_PWM(OFF);
  801. #endif
  802. rt_thread_delay(50);
  803. clear_num++;
  804. //已到达检测位置
  805. if(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  806. {
  807. #if PWM_EN == 0
  808. rt_pin_write(CLEAR_R,ON);
  809. rt_pin_write(CLEAR_L,ON);
  810. #else
  811. Motor_Qingsao_R_PWM(OFF);
  812. Motor_Qingsao_L_PWM(OFF);
  813. #endif
  814. rt_thread_delay(2000);
  815. break;
  816. }
  817. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  818. {
  819. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  820. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  821. #if PWM_EN == 0
  822. rt_pin_write(CLEAR_R,ON);
  823. rt_pin_write(CLEAR_L,ON);
  824. #else
  825. Motor_Qingsao_R_PWM(OFF);
  826. Motor_Qingsao_L_PWM(OFF);
  827. #endif
  828. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  829. if(Read_Real_Voltage()/100<12)
  830. {
  831. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  832. HMI_WRITE("sysTest.switchClear.val=%d",0);
  833. device_status.clear_status = 0;
  834. return 0;
  835. }
  836. break;
  837. }
  838. }
  839. clear_num = 0;
  840. //如果清扫位置在左侧
  841. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  842. {
  843. #if PWM_EN == 0
  844. rt_pin_write(CLEAR_R,ON);
  845. rt_pin_write(CLEAR_L,OFF);
  846. #else
  847. Motor_Qingsao_R_PWM(ON);
  848. Motor_Qingsao_L_PWM(OFF);
  849. #endif
  850. rt_thread_delay(50);
  851. clear_num++;
  852. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  853. {
  854. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  855. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  856. #if PWM_EN == 0
  857. rt_pin_write(CLEAR_R,ON);
  858. rt_pin_write(CLEAR_L,ON);
  859. #else
  860. Motor_Qingsao_R_PWM(OFF);
  861. Motor_Qingsao_L_PWM(OFF);
  862. #endif
  863. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  864. if(Read_Real_Voltage()/100<12)
  865. {
  866. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  867. HMI_WRITE("sysTest.switchClear.val=%d",0);
  868. device_status.clear_status = 0;
  869. return 0;
  870. }
  871. break;
  872. }
  873. }
  874. clear_num = 0;
  875. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1||(Read_Real_Voltage()/100)<12)
  876. {
  877. #if PWM_EN == 0
  878. rt_pin_write(CLEAR_R,ON);
  879. rt_pin_write(CLEAR_L,ON);
  880. #else
  881. Motor_Qingsao_R_PWM(OFF);
  882. Motor_Qingsao_L_PWM(OFF);
  883. #endif
  884. if(Read_Real_Voltage()/100<12)
  885. {
  886. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  887. HMI_WRITE("sysTest.switchClear.val=%d",0);
  888. device_status.clear_status = 0;
  889. return 0;
  890. }
  891. rt_thread_delay(2000);
  892. break;
  893. }
  894. while(rt_pin_read(CLEAR_L_LIMIT)==0)
  895. {
  896. #if PWM_EN == 0
  897. rt_pin_write(CLEAR_R,OFF);
  898. rt_pin_write(CLEAR_L,ON);
  899. #else
  900. Motor_Qingsao_R_PWM(OFF);
  901. Motor_Qingsao_L_PWM(ON);
  902. #endif
  903. rt_thread_delay(50);
  904. clear_num++;
  905. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  906. {
  907. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  908. char * Clear_ERR = makeJson_Warn("Clear Motor ERR","device");
  909. //DTU_Write("%s",Clear_ERR);
  910. #if PWM_EN == 0
  911. rt_pin_write(CLEAR_R,ON);
  912. rt_pin_write(CLEAR_L,ON);
  913. #else
  914. Motor_Qingsao_R_PWM(OFF);
  915. Motor_Qingsao_L_PWM(OFF);
  916. #endif
  917. rt_free(Clear_ERR);
  918. if(Read_Real_Voltage()/100<12)
  919. {
  920. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  921. HMI_WRITE("sysTest.switchClear.val=%d",0);
  922. device_status.clear_status = 0;
  923. return 0;
  924. }
  925. break;
  926. }
  927. }
  928. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  929. {
  930. #if PWM_EN == 0
  931. rt_pin_write(CLEAR_R,ON);
  932. rt_pin_write(CLEAR_L,ON);
  933. #else
  934. Motor_Qingsao_R_PWM(OFF);
  935. Motor_Qingsao_L_PWM(OFF);
  936. #endif
  937. rt_thread_delay(2000);
  938. break;
  939. }
  940. while(rt_pin_read(CLEAR_L_LIMIT)==1&&rt_pin_read(CLEAR_R_LIMIT)==1)
  941. {
  942. #if PWM_EN == 0
  943. rt_pin_write(CLEAR_R,ON);
  944. rt_pin_write(CLEAR_L,ON);
  945. #else
  946. Motor_Qingsao_R_PWM(OFF);
  947. Motor_Qingsao_L_PWM(OFF);
  948. #endif
  949. if(device_status.version_type==41)
  950. {
  951. rt_kprintf("Clear Motor Limit Not Access:%d",atoi(device_status.power));
  952. char * Clear_ERR = makeJson_Warn("Clear Motor Limit Not Access","device");
  953. //DTU_Write("%s",Clear_ERR);
  954. rt_free(Clear_ERR);
  955. }
  956. return 0;
  957. }
  958. clear_num = 0;
  959. rt_thread_delay(2000);
  960. #if PWM_EN == 0
  961. rt_pin_write(CLEAR_R,ON);
  962. rt_pin_write(CLEAR_L,ON);
  963. #else
  964. Motor_Qingsao_R_PWM(OFF);
  965. Motor_Qingsao_L_PWM(OFF);
  966. #endif
  967. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  968. HMI_WRITE("sysTest.switchClear.val=%d",0);
  969. device_status.clear_status = 0;
  970. return 1;
  971. }
  972. //路由器供电
  973. void ctr_router(uint8_t status_router)
  974. {
  975. rt_pin_mode(ROUTER, PIN_MODE_OUTPUT);
  976. if(device_status.version_type==6)
  977. rt_pin_mode(ROUTER_P,PIN_MODE_OUTPUT);
  978. //rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  979. if(status_router==ON)
  980. {
  981. rt_pin_write(ROUTER,ON);
  982. //
  983. #if LAMP_EN == 0
  984. if(device_status.version_type==6)
  985. rt_pin_write(ROUTER_P,ON);
  986. #endif
  987. }
  988. else {
  989. rt_pin_write(ROUTER,OFF);
  990. //
  991. #if LAMP_EN == 0
  992. if(device_status.version_type==6)
  993. rt_pin_write(ROUTER_P,OFF);
  994. #endif
  995. }
  996. }
  997. //清扫-推杆电机
  998. void ctr_TG_Clear(uint16_t clear_timeout)
  999. {
  1000. #if 0
  1001. int current_clear[200];
  1002. int16_t Electric_current = atoi(device_status.power); //获取电机运动前的电流
  1003. LOG_I("清扫电机待机:%d",Electric_current);
  1004. #endif
  1005. static uint16_t clear_count = 0;
  1006. clear_count = clear_timeout;
  1007. #if PWM_EN == 0
  1008. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1009. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1010. #endif
  1011. while(clear_count!=0)
  1012. {
  1013. #if PWM_EN == 0
  1014. rt_pin_write(CLEAR_R,ON);
  1015. rt_pin_write(CLEAR_L,OFF);
  1016. #else
  1017. #if QINGSAO_IO == 1
  1018. Motor_Qingsao_R_PWM(OFF);
  1019. Motor_Qingsao_L_PWM(ON);
  1020. #else
  1021. Motor_Qingsao_R_PWM(ON);
  1022. Motor_Qingsao_L_PWM(OFF);
  1023. #endif
  1024. #endif
  1025. clear_count--;
  1026. rt_thread_delay(100);
  1027. }
  1028. #if PWM_EN == 0
  1029. rt_pin_write(CLEAR_R,ON);
  1030. rt_pin_write(CLEAR_L,ON);
  1031. #else
  1032. Motor_Qingsao_R_PWM(OFF);
  1033. Motor_Qingsao_L_PWM(OFF);
  1034. #endif
  1035. rt_thread_delay(3000);
  1036. clear_count = 0;
  1037. while(clear_timeout!=clear_count)
  1038. {
  1039. #if PWM_EN == 0
  1040. rt_pin_write(CLEAR_R,OFF);
  1041. rt_pin_write(CLEAR_L,ON);
  1042. #else
  1043. #if QINGSAO_IO == 1
  1044. Motor_Qingsao_R_PWM(ON);
  1045. Motor_Qingsao_L_PWM(OFF);
  1046. #else
  1047. Motor_Qingsao_R_PWM(OFF);
  1048. Motor_Qingsao_L_PWM(ON);
  1049. #endif
  1050. #endif
  1051. // if(clear_count<200)
  1052. // current_clear[clear_count] = atoi(device_status.power);
  1053. clear_count++;
  1054. rt_thread_delay(100);
  1055. }
  1056. #if PWM_EN == 0
  1057. rt_pin_write(CLEAR_R,ON);
  1058. rt_pin_write(CLEAR_L,ON);
  1059. #else
  1060. Motor_Qingsao_R_PWM(OFF);
  1061. Motor_Qingsao_L_PWM(OFF);
  1062. #endif
  1063. #if 0
  1064. bubblesort(current_clear,200);
  1065. if(current_clear[199]-Electric_current <100&&device_status.work_status==1&&Electric_current!=0&&Electric_current<5000)
  1066. {
  1067. LOG_E("清扫电机电流不足:%d!",current_clear[199]);
  1068. char *ctr_clear_warn = makeJson_Warn("电流不足","清扫电机");
  1069. DTU_Write("%s",ctr_clear_warn);
  1070. rt_free(ctr_clear_warn);
  1071. }
  1072. #endif
  1073. rt_thread_delay(2000);
  1074. device_status.clear_status = 0;
  1075. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1076. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1077. }
  1078. //DTU,RTU供电
  1079. void ctr_RTU_DTU(uint8_t status_rtu)
  1080. {
  1081. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  1082. if(status_rtu==ON)
  1083. {
  1084. rt_pin_write(RTU_DTU,ON);
  1085. }
  1086. else
  1087. {
  1088. LOG_W("RTU电源复位!!!");
  1089. rt_pin_write(RTU_DTU,OFF);
  1090. }
  1091. }
  1092. //海康拍照
  1093. void Hk_Take_io(void)
  1094. {
  1095. rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
  1096. rt_pin_mode(HK_IO, PIN_MODE_OUTPUT);
  1097. rt_pin_write(HK_TAKE, 1);
  1098. rt_pin_write(HK_IO, 0);
  1099. if(device_status.dtype==3)
  1100. Beep_Tip(1000);
  1101. if(device_status.dtype==7)
  1102. rt_thread_mdelay(1000);
  1103. rt_pin_write(HK_TAKE, 0);
  1104. rt_pin_write(HK_IO, 1);
  1105. }
  1106. void calorstat(uint16_t heat_time)
  1107. {
  1108. //uint8_t heat_up_cnt = 0;
  1109. uint16_t n = 0;
  1110. uint16_t delay_heat = 60;
  1111. FlagStatus heat_flg = RESET;
  1112. device_status.heat_time_min = 0;
  1113. device_status.run_sta = device_status.heattem; //初始化加热实时温度
  1114. ctr_Heat(ON);
  1115. // UpLoad_Data(); //开始加热时的第一条数据
  1116. //恒温模式
  1117. for(n=0;n < heat_time;n++)
  1118. {
  1119. if(device_status.heattem>device_status.heatvalue&&heat_flg==RESET)
  1120. {
  1121. heat_flg = SET;
  1122. ctr_Heat(OFF);
  1123. while(delay_heat!=0)
  1124. {
  1125. device_status.C01 &= ~(1<<1); //加热 正常
  1126. delay_heat --;
  1127. rt_kprintf("正在恒温加热!!!:%d",delay_heat);
  1128. HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"",delay_heat);
  1129. rt_thread_delay(1000);
  1130. if(device_status.heattem>device_status.run_sta + 1){
  1131. device_status.run_sta = device_status.heattem;
  1132. }
  1133. }
  1134. delay_heat = 60;
  1135. //跳出FOR循环
  1136. n = n + 60;
  1137. }
  1138. if(device_status.heattem>device_status.run_sta + 1){
  1139. device_status.run_sta = device_status.heattem;
  1140. }
  1141. if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
  1142. {
  1143. //device_status.run_sta = device_status.heattem;
  1144. ctr_Heat(ON);
  1145. }
  1146. else if (device_status.heattem>=device_status.heatvalue&&heat_flg==SET)
  1147. {
  1148. // if(heat_up_cnt==0)
  1149. // {
  1150. // UpLoad_Data(); //加热到设定温度的数据
  1151. // heat_up_cnt = 1;
  1152. // }
  1153. //device_status.run_sta = device_status.heattem;
  1154. ctr_Heat(OFF);
  1155. }
  1156. if((n % 60)==0)
  1157. {
  1158. device_status.heat_time_min = device_status.heat_time_min + 1;
  1159. if(device_status.heat_time_min % 5 == 0) //加热5分钟温度低于50,判定加热故障
  1160. {
  1161. if(device_status.heattem<50) {
  1162. device_status.C01 |= (1 << 1); // 第1位变为1,加热故障
  1163. }else {
  1164. device_status.C01 &= ~(1<<1); //加热 正常
  1165. }
  1166. }
  1167. }
  1168. //如果触发异常退出加热
  1169. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1170. {
  1171. rt_thread_delay(1000);
  1172. if(device_status.bat_status == 1)
  1173. {
  1174. rt_kprintf("============================触发异常退出加热==========================");
  1175. ctr_lamp(OFF,1);
  1176. ctr_Heat(OFF);
  1177. break;
  1178. }
  1179. }
  1180. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1181. {
  1182. ctr_Heat(OFF);
  1183. rt_kprintf("异常退出!!!\n");
  1184. break;
  1185. }
  1186. rt_thread_delay(1000);
  1187. rt_kprintf("=======正在加热======:%d-%d\n",n,heat_time);
  1188. HMI_WRITE("workSta.g0.txt=\"正在加热!!!:%d-%d\"",n,heat_time);
  1189. }
  1190. ctr_Heat(OFF);
  1191. //UpLoad_Data(); //加热结束的数据
  1192. }
  1193. //初始化所有控制驱动,关闭
  1194. void HardWare_Init(uint8_t boot)
  1195. {
  1196. Beep_Tip(200);
  1197. //关闭上仓门
  1198. ctr_cangmen_up(OFF);
  1199. if(device_status.dtype==3){
  1200. //关闭下仓门电机
  1201. ctr_cangmen_down(OFF);
  1202. }
  1203. //关闭镇流器
  1204. if(device_status.autotakepic==0)
  1205. ctr_lamp(OFF,1);
  1206. //关闭震动电机
  1207. ctr_shake(OFF,0);
  1208. //关闭加热
  1209. ctr_Heat(OFF);
  1210. //关闭补光灯
  1211. ctr_led(OFF);
  1212. //关闭12V供电(海康相机,RTU)
  1213. ctr_photo(OFF);
  1214. //关闭清扫电机驱动
  1215. ctr_clear(OFF);
  1216. }
  1217. //拍照
  1218. void HK_TakePhoto(void)
  1219. {
  1220. //打开补光灯
  1221. //DTU_Write("takephoto.mp3");
  1222. rt_thread_delay(10000);
  1223. rt_timer_start(timer_takephoto);
  1224. char *takephotojson = makeJson_takephoto();
  1225. DTU_Write("%s",takephotojson);
  1226. rt_free(takephotojson);
  1227. //吸虫塔
  1228. if(device_status.version_type!=6)
  1229. {
  1230. ctr_led(ON);
  1231. if(device_status.version_type==48)
  1232. {
  1233. rt_thread_delay(1000*60);
  1234. }
  1235. else {
  1236. rt_thread_delay(1000*15);
  1237. }
  1238. }
  1239. //触发海康相机拍照
  1240. Hk_Take_io();
  1241. if(device_status.version_type!=6)
  1242. {
  1243. rt_thread_delay(1000*45);
  1244. }
  1245. else {
  1246. ctr_led(ON);
  1247. rt_thread_delay(1000*19);
  1248. }
  1249. ctr_led(OFF);
  1250. }
  1251. //光控测试任务
  1252. void SunTest(void)
  1253. {
  1254. rt_uint16_t ui_timeout_l = 0;
  1255. //未检测到光照,一秒扫描等待,超时30S
  1256. while(Read_Light_Voltage()<500)
  1257. {
  1258. ui_timeout_l ++;
  1259. rt_thread_delay(1000);
  1260. if(ui_timeout_l==30) break;
  1261. }
  1262. rt_thread_delay(3000);
  1263. if(Read_Light_Voltage()<500)
  1264. {
  1265. device_status.sun_status = 0;//光控状态
  1266. }
  1267. if(Read_Light_Voltage()>500)
  1268. {
  1269. rt_thread_delay(1000);
  1270. }
  1271. rt_thread_delay(3000);
  1272. if(Read_Light_Voltage()>500)
  1273. {
  1274. device_status.sun_status = 1;
  1275. ctr_lamp(OFF,1);
  1276. }
  1277. HMI_WRITE("sysTest.switchSun.val=%d",0);
  1278. device_status.sun_test = 0;
  1279. device_status.work_status=0;
  1280. }
  1281. /*上电初始化*/
  1282. void ResetInit(void)
  1283. {
  1284. if(device_status.dtype==7)
  1285. {
  1286. ctr_Motor_Driver(0, 0, 0, 0);
  1287. //关闭电磁阀
  1288. ctr_shake(OFF, 0);
  1289. //关闭加热
  1290. ctr_Heat(OFF);
  1291. //关闭制冷
  1292. ctr_Cold(OFF);
  1293. //关闭补光灯
  1294. ctr_led(OFF);
  1295. //转盘复位
  1296. if(device_status.run_sta==0)
  1297. ctr_turn(0, 0);
  1298. }
  1299. if(device_status.version_type!=6&&device_status.version_type!=7)
  1300. {
  1301. device_status.work_done = 1;
  1302. //1.打开路由器供电
  1303. if(device_status.power_status==1)
  1304. {
  1305. #if MATCH_DEVICE ==0
  1306. ctr_router(ON);
  1307. #endif
  1308. ctr_RTU_DTU(ON);
  1309. //2.打开相机供电
  1310. ctr_photo(ON);
  1311. }
  1312. //3.关闭镇流器
  1313. ctr_lamp(OFF,1);
  1314. //4.关闭震动电机
  1315. ctr_shake(OFF, 0);
  1316. //5.关闭加热
  1317. ctr_Heat(OFF);
  1318. //6.关闭补光灯
  1319. ctr_led(OFF);
  1320. if(device_status.bat_status==1||atoi(device_status.fuse_voltage)<1)
  1321. {
  1322. LOG_W("欠压!");
  1323. return;
  1324. }
  1325. //7.关闭上仓门
  1326. device_status.ctr_up_motor = 2;
  1327. // while(device_status.ctr_up_motor!=0)
  1328. // {
  1329. // LOG_I("关闭上仓门...");
  1330. // rt_thread_delay(100);
  1331. // }
  1332. //8.关闭下仓门
  1333. device_status.ctr_down_motor = 2;
  1334. while(device_status.ctr_down_motor!=0)
  1335. {
  1336. LOG_I("关闭下仓门....");
  1337. rt_thread_delay(100);
  1338. }
  1339. //9.清扫
  1340. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1341. {
  1342. LOG_W("异常退出!!!\n");
  1343. return;
  1344. }
  1345. if(device_status.version_type==4||device_status.version_type==41)
  1346. {
  1347. if(device_status.photo_ws==0) device_status.clear_status=1;
  1348. while(device_status.clear_status==1){
  1349. rt_thread_delay(1000);
  1350. }
  1351. }
  1352. }
  1353. else {
  1354. if(device_status.power_status==1)
  1355. {
  1356. //1.打开路由器供电
  1357. #if MATCH_DEVICE ==0
  1358. ctr_router(ON);
  1359. #endif
  1360. ctr_RTU_DTU(ON);
  1361. //2.打开相机供电
  1362. ctr_photo(ON);
  1363. }
  1364. //5.关闭加热
  1365. //6.关闭补光灯
  1366. ctr_led(OFF);
  1367. }
  1368. }
  1369. /*三色光源*/
  1370. void Led_Check(uint8_t tp)
  1371. {
  1372. if(tp==3)
  1373. {
  1374. if(device_status.light_over_tim>2*3600)
  1375. {
  1376. device_status.work_status = 1;
  1377. device_status.lamp_status = 1;
  1378. device_status.lamp1_status = 0;
  1379. device_status.lamp2_status = 0;
  1380. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1381. }
  1382. else if (device_status.light_over_tim>3600&&device_status.light_over_tim<7200) {
  1383. device_status.work_status = 1;
  1384. device_status.lamp_status = 0;
  1385. device_status.lamp1_status = 1;
  1386. device_status.lamp2_status = 0;
  1387. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1388. }
  1389. else if (device_status.light_over_tim<1*3600) {
  1390. device_status.work_status = 1;
  1391. device_status.lamp_status = 0;
  1392. device_status.lamp1_status = 0;
  1393. device_status.lamp2_status = 1;
  1394. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1395. }
  1396. }
  1397. else if (tp==6) {
  1398. if(device_status.light_over_tim>4*3600)
  1399. {
  1400. device_status.work_status = 1;
  1401. device_status.lamp_status = 1;
  1402. device_status.lamp1_status = 0;
  1403. device_status.lamp2_status = 0;
  1404. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1405. }
  1406. else if (device_status.light_over_tim<14400&&device_status.light_over_tim>7200) {
  1407. device_status.work_status = 1;
  1408. device_status.lamp_status = 0;
  1409. device_status.lamp1_status = 1;
  1410. device_status.lamp2_status = 0;
  1411. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1412. }
  1413. else if (device_status.light_over_tim<7200) {
  1414. device_status.work_status = 1;
  1415. device_status.lamp_status = 0;
  1416. device_status.lamp1_status = 0;
  1417. device_status.lamp2_status = 1;
  1418. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1419. }
  1420. }
  1421. else if (tp==9) {
  1422. if(device_status.light_over_tim>6*3600)
  1423. {
  1424. device_status.work_status = 1;
  1425. device_status.lamp_status = 1;
  1426. device_status.lamp1_status = 0;
  1427. device_status.lamp2_status = 0;
  1428. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1429. }
  1430. else if (device_status.light_over_tim<6*3600&&device_status.light_over_tim>3*3600) {
  1431. device_status.work_status = 1;
  1432. device_status.lamp_status = 0;
  1433. device_status.lamp1_status = 1;
  1434. device_status.lamp2_status = 0;
  1435. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1436. }
  1437. else if (device_status.light_over_tim<3*3600) {
  1438. device_status.work_status = 1;
  1439. device_status.lamp_status = 0;
  1440. device_status.lamp1_status = 0;
  1441. device_status.lamp2_status = 1;
  1442. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1443. }
  1444. }
  1445. }
  1446. void WorkCheck(void)
  1447. {
  1448. static rt_uint32_t light_timeout = 3600;
  1449. while(device_status.ds == 1 &&
  1450. device_status.rain_status == 0 &&
  1451. device_status.temp_status == 0 &&
  1452. device_status.bat_status == 0)
  1453. {
  1454. if(device_status.timeSwitch == 1) // 时控模式
  1455. {
  1456. LOG_I("***********时控*****************");
  1457. time_t now;
  1458. time(&now);
  1459. struct tm now_tm = *localtime(&now);
  1460. if(device_status.startBar == device_status.stopBar)
  1461. {
  1462. // 开始结束时间相同则24小时模式
  1463. device_status.work_status = 1;
  1464. rt_thread_delay(10000);
  1465. LOG_I("时控模式:状态[%s] 当前时间:%02d:%02d:%02d 设置:%02d:00-%02d:00",
  1466. device_status.work_status ? "工作" : "待机",
  1467. now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
  1468. device_status.startBar, device_status.stopBar);
  1469. continue;
  1470. }
  1471. rt_uint32_t curr_sec = now_tm.tm_hour*3600 + now_tm.tm_min*60 + now_tm.tm_sec;
  1472. rt_uint32_t start_sec = device_status.startBar * 3600;
  1473. rt_uint32_t end_sec = device_status.stopBar * 3600;
  1474. // 修复跨天判断逻辑
  1475. if (start_sec < end_sec)
  1476. {
  1477. // 不跨天模式
  1478. device_status.work_status = (curr_sec >= start_sec && curr_sec < end_sec) ? 1 : 0;
  1479. }
  1480. else
  1481. {
  1482. // 跨天模式
  1483. device_status.work_status = (curr_sec >= start_sec || curr_sec < end_sec) ? 1 : 0;
  1484. }
  1485. LOG_I("时控模式:状态[%s] 当前时间:%02d:%02d:%02d 设置:%02d:00-%02d:00",
  1486. device_status.work_status ? "工作" : "待机",
  1487. now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
  1488. device_status.startBar, device_status.stopBar);
  1489. rt_thread_delay(10000);
  1490. }
  1491. else // 光控模式
  1492. {
  1493. LOG_I("光控定时模式!");
  1494. if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
  1495. {
  1496. device_status.light_over_tim--;
  1497. light_timeout = 3600; // 重置超时计数器
  1498. device_status.work_status = 1;
  1499. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  1500. }
  1501. else
  1502. {
  1503. // 仅在白天递减超时计数器
  1504. if(device_status.sun_status == 1 && light_timeout > 0) {
  1505. light_timeout--;
  1506. }
  1507. device_status.work_status = 0;
  1508. //没有在测试并且没有在自检
  1509. if(device_status.test_flag==0 && device_status.selfcheck_ws==0)
  1510. {
  1511. ctr_lamp(OFF,1);
  1512. }
  1513. // 连续1小时白天后重置
  1514. if(light_timeout == 0) {
  1515. device_status.light_over_tim = 0;
  1516. light_timeout = 3600; // 重置防止负数
  1517. }
  1518. // 白天且倒计时结束:重置夜晚时长
  1519. if(device_status.light_over_tim == 0 &&
  1520. device_status.sun_status == 1)
  1521. {
  1522. device_status.light_over_tim = device_status.sunBar * 3600;
  1523. }
  1524. }
  1525. }
  1526. rt_thread_delay(1000);
  1527. }
  1528. // 异常状态处理
  1529. device_status.work_status = 0;
  1530. rt_thread_delay(1000);
  1531. }
  1532. #if 0
  1533. //工作状态检测
  1534. void WorkCheck(void)
  1535. {
  1536. static rt_uint32_t light_timeout = 3600;
  1537. static int check_stamp_cnt = 0;
  1538. //雨控检测,温控检测,电池电压检测
  1539. while(device_status.ds==1&&device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
  1540. {
  1541. //工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
  1542. if(device_status.timeSwitch==1)
  1543. {
  1544. LOG_I("***********时控*****************");
  1545. if(device_status.startBar==device_status.stopBar&&device_status.startBar==0){
  1546. device_status.work_status = 1;
  1547. LOG_I("24 hours work...");
  1548. #if LAMP_EN == 1
  1549. device_status.lamp_status = 1;
  1550. device_status.lamp1_status = 0;
  1551. device_status.lamp2_status = 0;
  1552. if(device_status.sun_status==1){
  1553. ctr_lamp(OFF, 1);
  1554. ctr_lamp(OFF, 2);
  1555. ctr_lamp(OFF, 3);
  1556. }
  1557. #endif
  1558. }
  1559. //如果开始和结束是同一天
  1560. if(device_status.startBar<device_status.stopBar)
  1561. {
  1562. LOG_I("开始和结束是同一天");
  1563. time_t now;
  1564. time(&now);
  1565. static struct tm nowtime; //现在
  1566. static struct tm starttime; //开始
  1567. static struct tm endtime; //结束
  1568. //获取当前时间戳
  1569. nowtime =*localtime(&now);
  1570. nowtime.tm_hour = nowtime.tm_hour-8;
  1571. //获取定时开始的时间戳
  1572. starttime = *localtime(&now);
  1573. starttime.tm_hour = device_status.startBar-8;
  1574. starttime.tm_min = 0;
  1575. starttime.tm_sec = 0;
  1576. //获取定时结束的时间戳
  1577. endtime = *localtime(&now);
  1578. endtime.tm_hour = device_status.stopBar-8;
  1579. endtime.tm_min = 0;
  1580. endtime.tm_sec = 0;
  1581. LOG_I("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1582. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  1583. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
  1584. {
  1585. LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
  1586. check_stamp_cnt++;
  1587. if(check_stamp_cnt>20)
  1588. {
  1589. device_status.work_status = 1;
  1590. }
  1591. }
  1592. //如果当前时间小于开始时间
  1593. else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
  1594. {
  1595. LOG_I("当前时间小于开始时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1596. device_status.work_status = 0;
  1597. check_stamp_cnt = 0;
  1598. }
  1599. //当前时间大于结束时间
  1600. else {
  1601. LOG_I("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1602. device_status.work_status = 0;
  1603. check_stamp_cnt = 0;
  1604. }
  1605. #if LAMP_EN == 1
  1606. //如果当前时间超过20点,未到21点
  1607. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+3600)<0))
  1608. {
  1609. LOG_I("3led:20~21");
  1610. device_status.lamp_status = 1;
  1611. device_status.lamp1_status = 0;
  1612. device_status.lamp2_status = 0;
  1613. }
  1614. else if ((difftime(mktime(&nowtime), mktime(&starttime)+3600) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+7200)<0)) {
  1615. LOG_I("3led:21~22");
  1616. device_status.lamp1_status = 1;
  1617. device_status.lamp_status = 0;
  1618. device_status.lamp2_status = 0;
  1619. }
  1620. else if ((difftime(mktime(&nowtime), mktime(&starttime)+7200) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+10800)<0)) {
  1621. LOG_I("3led:22~23");
  1622. device_status.lamp2_status = 1;
  1623. device_status.lamp_status = 0;
  1624. device_status.lamp1_status =0;
  1625. }
  1626. #endif
  1627. }
  1628. //如果结束时间是第二天
  1629. else if (device_status.startBar>device_status.stopBar) {
  1630. time_t now;
  1631. time(&now);
  1632. static struct tm nowtime; //现在
  1633. static struct tm starttime; //开始
  1634. static struct tm endtime; //结束
  1635. //获取当前时间戳
  1636. nowtime =*localtime(&now);
  1637. nowtime.tm_hour = nowtime.tm_hour-8;
  1638. //获取定时开始的时间戳
  1639. starttime = *localtime(&now);
  1640. starttime.tm_hour = device_status.startBar-8;
  1641. starttime.tm_min = 0;
  1642. starttime.tm_sec = 0;
  1643. //获取定时结束的时间戳
  1644. endtime = *localtime(&now);
  1645. endtime.tm_hour = device_status.stopBar-8;
  1646. endtime.tm_min = 0;
  1647. endtime.tm_sec = 0;
  1648. LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1649. //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
  1650. if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
  1651. {
  1652. //获取定时结束的时间戳
  1653. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1654. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1655. endtime.tm_min = 0;
  1656. endtime.tm_sec = 0;
  1657. device_status.work_status = 1;
  1658. LOG_I("当前前时间大于开始时间,且没有开始工作");
  1659. }
  1660. //当前时间小于开始时间
  1661. else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
  1662. {
  1663. //获取定时结束的时间戳
  1664. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1665. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1666. endtime.tm_min = 0;
  1667. endtime.tm_sec = 0;
  1668. //如果当前时间戳小于结束时间戳
  1669. if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
  1670. {
  1671. LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
  1672. device_status.work_status = 1;
  1673. }
  1674. else
  1675. {
  1676. LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
  1677. device_status.work_status = 0; //不在工作时间,待机
  1678. }
  1679. }
  1680. }
  1681. }
  1682. else {
  1683. LOG_I("光控定时模式!");
  1684. if(device_status.sun_status==0&&device_status.light_over_tim!=0)
  1685. {
  1686. device_status.light_over_tim--;
  1687. light_timeout = 3600;
  1688. #if LAMP_EN == 1
  1689. Led_Check(device_status.sunBar);
  1690. #else
  1691. device_status.work_status = 1;;
  1692. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  1693. #endif
  1694. }
  1695. else
  1696. {
  1697. light_timeout --;
  1698. //没有在测试并且没有在自检
  1699. if(device_status.test_flag==0&&device_status.selfcheck_ws==0)
  1700. {
  1701. ctr_lamp(OFF,1);
  1702. #if LAMP_EN == 1
  1703. ctr_lamp(OFF,2);
  1704. ctr_lamp(OFF,3);
  1705. #endif
  1706. }
  1707. device_status.work_status = 0;
  1708. if(light_timeout==0) device_status.light_over_tim = 0; //持续1小时白天,清除光控计时,20250519
  1709. if(device_status.light_over_tim==0&&device_status.sun_status==1) device_status.light_over_tim = device_status.sunBar * 3600;
  1710. LOG_I("光控中,白天:%d!!!",device_status.sun_status);
  1711. }
  1712. }
  1713. rt_thread_delay(1000);
  1714. }
  1715. LOG_I("雨控状态,温控状态,电压状态:%d-%d-%d",device_status.rain_status,device_status.temp_status,device_status.bat_status);
  1716. device_status.work_status = 0;
  1717. rt_thread_delay(1000);
  1718. }
  1719. #endif
  1720. //工作任务流程s
  1721. void WorkTask(void)
  1722. {
  1723. static int clt_time = 0; //收集时间差秒数
  1724. static int heat_time = 0;
  1725. LOG_I("工作状态:%d",device_status.work_status);
  1726. LOG_I("开关机状态:%d",device_status.ds);
  1727. 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&&device_status.clear_status==0)
  1728. {
  1729. device_status.work_done = 0;
  1730. if(clt_time==0)
  1731. {
  1732. DTU_Write("workstart.mp3");
  1733. if(device_status.debug_ws==1)
  1734. {
  1735. time_t stamp=time(RT_NULL);
  1736. static struct tm tm;
  1737. gmtime_r(&stamp, &tm);
  1738. rt_sprintf(device_status.stamp,"%04d%02d%02d%02d%02d%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  1739. char* debug_str = makeJson_Warn("Work start!", device_status.stamp);
  1740. DTU_Write(debug_str);
  1741. rt_free(debug_str);
  1742. }
  1743. }
  1744. //1.打开灯管
  1745. #if LAMP_EN == 1
  1746. if(device_status.lamp_status==1&&device_status.sun_status==0) //光控状态不亮灯
  1747. {
  1748. ctr_lamp(ON,1);
  1749. ctr_lamp(OFF,2);
  1750. ctr_lamp(OFF,3);
  1751. }
  1752. else if (device_status.lamp1_status==1&&device_status.sun_status==0) {
  1753. ctr_lamp(OFF,1);
  1754. ctr_lamp(ON,2);
  1755. ctr_lamp(OFF,3);
  1756. }
  1757. else if (device_status.lamp2_status==1&&device_status.sun_status==0) {
  1758. ctr_lamp(OFF,1);
  1759. ctr_lamp(OFF,2);
  1760. ctr_lamp(ON,3);
  1761. }
  1762. #else
  1763. ctr_lamp(ON,1);
  1764. #endif
  1765. LOG_I("打开灯管!!!");
  1766. if(device_status.version_type!=5)
  1767. {
  1768. rt_thread_delay(1000); //待灯管启动再往下执行,否则会触发电机过流
  1769. //2.打开上仓门
  1770. LOG_I("打开上仓门!!!");
  1771. device_status.ctr_up_motor = 1;
  1772. //3.收集
  1773. clt_time = device_status.clt_time * 60;
  1774. while(clt_time!=1)
  1775. {
  1776. #if 0//LAMP_EN == 0
  1777. ctr_Fan_IN(ON);
  1778. #endif
  1779. clt_time --;
  1780. rt_thread_delay(1000);
  1781. #if 0//LAMP_EN == 0
  1782. if(clt_time%30==0)
  1783. ctr_Fan_PUT(OFF);
  1784. #endif
  1785. rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
  1786. //如果触发异常
  1787. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1788. {
  1789. ctr_lamp(OFF,1);
  1790. #if LAMP_EN == 1
  1791. ctr_lamp(OFF,2);
  1792. ctr_lamp(OFF,3);
  1793. #endif
  1794. #if 0//LAMP_EN == 0
  1795. ctr_Fan_IN(OFF);
  1796. #endif
  1797. rt_kprintf("异常退出!!!\n");
  1798. break;
  1799. }
  1800. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1801. {
  1802. ctr_lamp(OFF,1);
  1803. #if LAMP_EN == 1
  1804. ctr_lamp(OFF,2);
  1805. ctr_lamp(OFF,3);
  1806. #endif
  1807. #if 0//LAMP_EN == 0
  1808. ctr_Fan_IN(OFF);
  1809. #endif
  1810. rt_kprintf("异常退出!!!\n");
  1811. break;
  1812. }
  1813. }
  1814. clt_time = 1;
  1815. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1816. {
  1817. ctr_lamp(OFF,1);
  1818. #if LAMP_EN == 1
  1819. ctr_lamp(OFF,2);
  1820. ctr_lamp(OFF,3);
  1821. #endif
  1822. #if 0//LAMP_EN == 0
  1823. ctr_Fan_IN(OFF);
  1824. #endif
  1825. rt_kprintf("异常退出!!!\n");
  1826. break;
  1827. }
  1828. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1829. {
  1830. ctr_lamp(OFF,1);
  1831. #if LAMP_EN == 1
  1832. ctr_lamp(OFF,2);
  1833. ctr_lamp(OFF,3);
  1834. #endif
  1835. #if 0//LAMP_EN == 0
  1836. ctr_Fan_IN(OFF);
  1837. #endif
  1838. rt_kprintf("异常退出!!!\n");
  1839. break;
  1840. }
  1841. #if 0//LAMP_EN == 0
  1842. ctr_Fan_IN(OFF);
  1843. #endif
  1844. //4.关闭上仓门
  1845. device_status.ctr_up_motor = 2;
  1846. rt_kprintf("关闭上仓门!!!\n");
  1847. while(device_status.ctr_up_motor!=0)
  1848. {
  1849. rt_thread_delay(100);
  1850. LOG_I("等待上仓门关闭!!!");
  1851. }
  1852. //5.加热
  1853. if(device_status.heat_sw==0)
  1854. {
  1855. calorstat(device_status.heattime*60);
  1856. }
  1857. else {
  1858. heat_time = device_status.heattime * 60;
  1859. while(heat_time!=0)
  1860. {
  1861. heat_time--;
  1862. LOG_I("正在加热状态!!!");
  1863. rt_thread_delay(1000);
  1864. }
  1865. }
  1866. #if TG_MODULE == 0
  1867. //6.打开下仓门
  1868. if(device_status.rain_status==0)
  1869. {
  1870. device_status.ctr_down_motor =1;
  1871. }
  1872. else {
  1873. device_status.ctr_down_motor = 2;
  1874. device_status.ctr_up_motor = 2;
  1875. }
  1876. //待下仓门完全打开
  1877. while(device_status.ctr_down_motor!=0)
  1878. {
  1879. rt_thread_delay(100);
  1880. rt_kprintf("等待下仓门打开!!!\n");
  1881. }
  1882. rt_thread_delay(3000);
  1883. //关闭下仓门
  1884. device_status.ctr_down_motor = 2;
  1885. while(device_status.ctr_down_motor!=0)
  1886. {
  1887. rt_thread_delay(100);
  1888. rt_kprintf("等待下仓门关闭!!!\n");
  1889. }
  1890. //2022-04-12add:
  1891. LOG_I("打开上仓门!!!");
  1892. device_status.ctr_up_motor = 1;
  1893. #else
  1894. //打开下仓门
  1895. ctr_cangmen_down(OPEN);
  1896. while(1)
  1897. {
  1898. if(rt_pin_read(CTR_UPC_LIMIT)==0) break;
  1899. rt_thread_delay(50);
  1900. }
  1901. ctr_cangmen_down(OFF);
  1902. rt_thread_delay(1000);
  1903. #endif
  1904. if(device_status.version_type==4||device_status.version_type==41)
  1905. {
  1906. //震动
  1907. ctr_shake(ON, device_status.shake_sec);
  1908. //补光&&拍照
  1909. LOG_I("拍照!!!");
  1910. device_status.photo_ws = 1;
  1911. }
  1912. #if TG_MODULE == 1
  1913. while(device_status.photo_ws == 1)
  1914. {
  1915. rt_thread_delay(1000);
  1916. LOG_I("等待拍照完成...");
  1917. }
  1918. while(device_status.clear_status==1)
  1919. {
  1920. rt_thread_delay(1000);
  1921. LOG_I("等待清扫完成...");
  1922. }
  1923. device_status.ctr_down_motor =1;
  1924. //待下仓门完全打开
  1925. while(device_status.ctr_down_motor!=0)
  1926. {
  1927. rt_thread_delay(100);
  1928. rt_kprintf("等待下仓门打开!!!\n");
  1929. }
  1930. rt_thread_delay(2000);
  1931. device_status.photo_ws = 1;
  1932. //关闭下仓门
  1933. device_status.ctr_down_motor = 2;
  1934. //待下仓门完全关闭
  1935. while(device_status.ctr_down_motor!=0)
  1936. {
  1937. rt_thread_delay(100);
  1938. rt_kprintf("等待下仓门关闭!!!\n");
  1939. }
  1940. device_status.ctr_up_motor = 1; //打开上仓门
  1941. #endif
  1942. }
  1943. }
  1944. if(device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status==1 || device_status.ds==0)
  1945. {
  1946. LOG_I("-------------------not work--------------------");
  1947. device_status.work_status = 0;
  1948. }
  1949. //工作结束
  1950. if(device_status.work_done==0&&device_status.work_status==0)
  1951. {
  1952. DTU_Write("workdone");
  1953. if (device_status.version_type==1) {
  1954. turnzp(); //2024-03-21 :开机不再转仓
  1955. }
  1956. ResetInit();
  1957. clt_time = 0;
  1958. }
  1959. rt_kprintf("***not work-device status:%d\n",device_status.ds);
  1960. }
  1961. void guanshan_on(void *args)
  1962. {
  1963. LOG_W("guanshan_on!");
  1964. rt_event_send(event_485_play, 0x01);
  1965. }
  1966. static void pin_guangshan_bind(void)
  1967. {
  1968. /* PC14引脚为输入模式 */
  1969. rt_pin_mode(GUANG_SHAN, PIN_MODE_INPUT);
  1970. /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
  1971. rt_pin_attach_irq(GUANG_SHAN, PIN_IRQ_MODE_RISING, guanshan_on, RT_NULL);
  1972. /* 使能中断 */
  1973. rt_pin_irq_enable(GUANG_SHAN, PIN_IRQ_ENABLE);
  1974. }
  1975. static void pin_guangshan_unbind(void)
  1976. {
  1977. rt_pin_detach_irq(GUANG_SHAN);
  1978. }
  1979. #define PULES 1 //延时时间 ms 5.0测报灯电机归零延时使用
  1980. void slidelock()
  1981. {
  1982. ctr_Motor_Driver_Power(ON); //电机驱动供电
  1983. rt_thread_delay(10);
  1984. rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT); //使能电机驱动引脚 PB14
  1985. rt_pin_write(Motor_EN, ON); //引脚输出高使能有效
  1986. }
  1987. /* 入口函数-工作状态检测 */
  1988. static void Work_status_thread_entry(void *parameter)
  1989. {
  1990. static uint16_t sun_status_num = 120;
  1991. //如果是光控定时,进行光控监测的消抖
  1992. if(device_status.timeSwitch==0&&device_status.sun_status==0)
  1993. {
  1994. rt_kprintf("光控定时!!!\n");
  1995. while(sun_status_num!=0)
  1996. {
  1997. sun_status_num--;
  1998. rt_thread_delay(1000);
  1999. rt_kprintf("开机光控检测:%d\n",sun_status_num);
  2000. }
  2001. device_status.light_over_tim = device_status.sunBar * 3600;
  2002. device_status.test_flag = 0;
  2003. }
  2004. while(1)
  2005. {
  2006. WorkCheck();
  2007. }
  2008. }
  2009. /*入口函数-工作流程*/
  2010. static void Work_Loop_thread_entry(void *parameter)
  2011. {
  2012. rt_thread_delay(1000);
  2013. ResetInit();
  2014. rt_pin_mode(CTR_UPC_LIMIT, PIN_MODE_INPUT);
  2015. while(1)
  2016. {
  2017. if(device_status.dtype==3)
  2018. {
  2019. WorkTask();
  2020. }
  2021. rt_thread_delay(1000);
  2022. }
  2023. }
  2024. /*入口函数清扫*/
  2025. static void Control_Clear_thread_entry(void *parameter)
  2026. {
  2027. while(1)
  2028. {
  2029. if(device_status.update_flag==1) break;
  2030. if(device_status.clear_status==1)
  2031. {
  2032. if(device_status.version_type==41){
  2033. ctr_TG_Clear(300);
  2034. }else {
  2035. ctr_TG_Clear(350);
  2036. }
  2037. }
  2038. if(device_status.clear_status==2)
  2039. {
  2040. turnzp();
  2041. device_status.clear_status = 0;
  2042. }
  2043. rt_thread_delay(100);
  2044. }
  2045. }
  2046. /*入口函数,自检*/
  2047. static void Control_Check_thread_entry(void *parameter)
  2048. {
  2049. static int total_seconds = 200;
  2050. static int current_second = 0;
  2051. static int process = 0;
  2052. #if MATCH_DEVICE == 1
  2053. rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
  2054. rt_pin_write(LED_P,ON);
  2055. #endif
  2056. device_status.C01 = 0;
  2057. rt_thread_delay(10000);
  2058. while(1)
  2059. {
  2060. if(device_status.update_flag==1) break;
  2061. if(device_status.work_status==1&&device_status.heat_sw==1)
  2062. {
  2063. ctr_lamp(ON, 1);
  2064. rt_thread_delay(10000);
  2065. calorstat(device_status.heattime*60);
  2066. }
  2067. else
  2068. {
  2069. if(device_status.selfcheck_ws==2)
  2070. {
  2071. while(current_second <= total_seconds)
  2072. {
  2073. process = (current_second * 100) / total_seconds;
  2074. device_status.process = process / 100.0;
  2075. LOG_I("process:%d",process);
  2076. HMI_WRITE("selfcheck.s106.val=%d",process);
  2077. rt_thread_delay(1000);
  2078. current_second++;
  2079. if(device_status.selfcheck_ws==0)
  2080. {
  2081. HMI_WRITE("selfcheck.s106.val=100");
  2082. break;
  2083. }
  2084. }
  2085. HMI_WRITE("selfcheck.s106.val=100");
  2086. }else {
  2087. process = 0;
  2088. current_second = 0;
  2089. #if MATCH_DEVICE == 1
  2090. if(device_status.rain_status==0)
  2091. {
  2092. rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
  2093. rt_pin_write(LED_P,ON);
  2094. }
  2095. //根据故障码 亮指示灯
  2096. //灯管故障
  2097. if(device_status.C01 & (1 << 0))
  2098. {
  2099. LOG_E("灯管故障!");
  2100. //发送红灯常亮信号
  2101. write_single_holding_register(0x01,0x00C2,0x0011,1000);
  2102. //延时10S
  2103. rt_thread_delay(10000);
  2104. }
  2105. //加热故障
  2106. if(device_status.C01 & (1 << 1))
  2107. {
  2108. LOG_E("加热故障!");
  2109. //发送红灯慢闪信号
  2110. write_single_holding_register(0x01,0x00C2,0x0021,1000);
  2111. //延时10S
  2112. rt_thread_delay(10000);
  2113. }
  2114. //相机拍照故障
  2115. if(device_status.C01 & (1 << 2))
  2116. {
  2117. LOG_E("拍照故障!");
  2118. //发送红灯快闪信号
  2119. write_single_holding_register(0x01,0x00C2,0x0031,1000);
  2120. //延时10S
  2121. rt_thread_delay(10000);
  2122. }
  2123. //补光灯故障
  2124. if(device_status.C01 & (1 << 3))
  2125. {
  2126. LOG_E("补光灯故障!");
  2127. //发送绿灯慢闪信号
  2128. write_single_holding_register(0x01,0x00C2,0x0023,1000);
  2129. //延时10S
  2130. rt_thread_delay(10000);
  2131. }
  2132. //上仓门故障
  2133. if(device_status.C01 & (1 << 8))
  2134. {
  2135. LOG_E("上仓门故障!");
  2136. //发送黄灯常亮信号
  2137. write_single_holding_register(0x01,0x00C2,0x0012,1000);
  2138. //延时10S
  2139. rt_thread_delay(10000);
  2140. }
  2141. //下仓门故障
  2142. if(device_status.C01 & (1 << 9))
  2143. {
  2144. LOG_E("下仓门故障!");
  2145. //发送黄灯慢闪信号
  2146. write_single_holding_register(0x01,0x00C2,0x0022,1000);
  2147. //延时10S
  2148. rt_thread_delay(10000);
  2149. }
  2150. //清扫故障
  2151. if(device_status.C01 & (1 << 10))
  2152. {
  2153. LOG_E("清扫故障!");
  2154. //发送黄灯爆闪信号
  2155. write_single_holding_register(0x01,0x00C2,0x0032,1000);
  2156. //延时10S
  2157. rt_thread_delay(10000);
  2158. }
  2159. //通信故障
  2160. if(device_status.C01 & (1 << 13))
  2161. {
  2162. LOG_E("通信故障!");
  2163. //发送绿灯爆闪信号
  2164. write_single_holding_register(0x01,0x00C2,0x0033,1000);
  2165. //延时10S
  2166. rt_thread_delay(10000);
  2167. }
  2168. if(device_status.C01==0)
  2169. {
  2170. LOG_W("无故障!");
  2171. //发送绿灯常亮信号
  2172. write_single_holding_register(0x01,0x00C2,0x0013,1000);
  2173. //延时10S
  2174. rt_thread_delay(10000);
  2175. }
  2176. #endif
  2177. }
  2178. }
  2179. rt_thread_delay(1000);
  2180. }
  2181. }
  2182. static void thread_485_play_entry(void *param)
  2183. {
  2184. static USHORT sound105[] = {0x736F,0x756E,0x6431,0x3037};
  2185. rt_uint32_t e;
  2186. // 创建事件控制块
  2187. event_485_play = rt_event_create("event", RT_IPC_FLAG_FIFO);
  2188. if (event_485_play == RT_NULL)
  2189. {
  2190. LOG_E("Event create failed!");
  2191. return;
  2192. }
  2193. while(1)
  2194. {
  2195. if(device_status.update_flag==1) break;
  2196. //等待事件
  2197. if(rt_event_recv(event_485_play, 0x01, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e)==RT_EOK)
  2198. {
  2199. LOG_I("Interrupt occurred and processed.");
  2200. _485_play(sound105, 4);
  2201. //发送串口消息,通知JETSON计算卡进行拍照
  2202. DTU_Write("{\"guangshan\":\"on\"}");
  2203. }
  2204. }
  2205. }
  2206. /*清扫线程*/
  2207. int Control_clear(void)
  2208. {
  2209. /* 创建线程*/
  2210. tid_ctr = rt_thread_create("Control_Clear_thread_entry",
  2211. Control_Clear_thread_entry, RT_NULL,
  2212. 2048, //2048
  2213. 24, //23
  2214. WORK_CHECK_THREAD_TIMESLICE); //5
  2215. if(tid_ctr!=RT_NULL)
  2216. {
  2217. rt_thread_startup(tid_ctr);
  2218. }
  2219. return 0;
  2220. }
  2221. /*恒温加热线程*/
  2222. int Control_Check(void)
  2223. {
  2224. /* 创建线程*/
  2225. tid_heat = rt_thread_create("Control_Check_thread_entry",
  2226. Control_Check_thread_entry, RT_NULL,
  2227. 1024, //2048
  2228. 25, //23
  2229. WORK_CHECK_THREAD_TIMESLICE); //5
  2230. if(tid_heat!=RT_NULL)
  2231. {
  2232. rt_thread_startup(tid_heat);
  2233. }
  2234. return 0;
  2235. }
  2236. int thread_485_play(void)
  2237. {
  2238. tid_485_play = rt_thread_create("thread_485play",
  2239. thread_485_play_entry, RT_NULL,
  2240. 1024, //1024
  2241. 26, //23
  2242. 5); //5
  2243. if(tid_485_play!=RT_NULL)
  2244. {
  2245. rt_thread_startup(tid_485_play);
  2246. }
  2247. else {
  2248. LOG_E("thread_485_play start failed!");
  2249. }
  2250. return 0;
  2251. }
  2252. /* 创建线程 -工作状态检测*/
  2253. int Workstatus_check(void)
  2254. {
  2255. /* 创建线程*/
  2256. tid_wkstc = rt_thread_create("work_status_check_thread",
  2257. Work_status_thread_entry, RT_NULL,
  2258. WORK_CHECK_THREAD_STACK_SIZE, //1024
  2259. WORK_CHECK_THREAD_PRIORITY, //23
  2260. WORK_CHECK_THREAD_TIMESLICE); //5
  2261. if(tid_wkstc!=RT_NULL)
  2262. {
  2263. rt_thread_startup(tid_wkstc);
  2264. }
  2265. return 0;
  2266. }
  2267. /*工作流程线程*/
  2268. int Work_Loop_Task(void)
  2269. {
  2270. rt_err_t result_loop = 0;
  2271. /* 创建线程*/
  2272. tid_workloop = rt_thread_create("work_loop_thread",
  2273. Work_Loop_thread_entry, RT_NULL,
  2274. WORK_LOOP_THREAD_STACK_SIZE, //2048
  2275. WORK_LOOP_THREAD_PRIORITY, //12
  2276. WORK_LOOP_THREAD_TIMESLICE); //5
  2277. if(tid_workloop!=RT_NULL)
  2278. {
  2279. result_loop = rt_thread_startup(tid_workloop);
  2280. }
  2281. return result_loop;
  2282. }
  2283. #ifdef RT_USING_ALARM
  2284. void alarm_callback_router_on(rt_alarm_t alarm, time_t timestamp)
  2285. {
  2286. LOG_W("alarm_callback_router_on.\n");
  2287. ctr_router(ON);
  2288. }
  2289. void alarm_callback_router_off(rt_alarm_t alarm, time_t timestamp)
  2290. {
  2291. LOG_W("alarm_callback_router_off.\n");
  2292. ctr_router(OFF);
  2293. }
  2294. void alarm_app_router(void)
  2295. {
  2296. struct rt_alarm_setup setup;
  2297. struct rt_alarm * alarm_router_on = RT_NULL;
  2298. if (alarm_router_on != RT_NULL)
  2299. return;
  2300. setup.flag = RT_ALARM_DAILY;
  2301. setup.wktime.tm_hour = 23;
  2302. setup.wktime.tm_min = 0;
  2303. setup.wktime.tm_sec = 0;
  2304. alarm_router_on = rt_alarm_create(alarm_callback_router_on, &setup);
  2305. if(RT_NULL != alarm_router_on)
  2306. {
  2307. LOG_I("设置闹钟: %d:%d:%d",setup.wktime.tm_hour,setup.wktime.tm_min,setup.wktime.tm_sec);
  2308. rt_alarm_start(alarm_router_on);
  2309. }
  2310. }
  2311. #endif
  2312. MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
  2313. MSH_CMD_EXPORT(ctr_Heat,ctr_Heat<ON|OFF>);
  2314. MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
  2315. MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);
  2316. //INIT_APP_EXPORT(Control_heat);