control.c 75 KB

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