control.c 75 KB

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