control.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405
  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||device_status.version_type==42||device_status.version_type==43)
  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||device_status.version_type==42||device_status.version_type==43)
  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);