control.c 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900
  1. #include <control.h>
  2. /*
  3. * Copyright (c) 2006-2020, RT-Thread Development Team
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-05-30 Administrator the first version
  10. */
  11. #include "beep.h"
  12. #include "hmi.h"
  13. #include "easyflash.h"
  14. #include "stdio.h"
  15. #include "sound.h"
  16. #include "dtu_uart2.h"
  17. #include "sht30_collect.h"
  18. #include "string.h"
  19. #define DBG_ENABLE
  20. #define DBG_COLOR
  21. #define DBG_TAG "control"
  22. #define DBG_LEVEL DBG_LOG
  23. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  24. #include "sys_monitor.h"
  25. //工作检测
  26. #define WORK_CHECK_THREAD_PRIORITY 23 //线程优先级
  27. #define WORK_CHECK_THREAD_STACK_SIZE 1024 //栈大小
  28. #define WORK_CHECK_THREAD_TIMESLICE 5 //时间片
  29. //工作流程
  30. #define WORK_LOOP_THREAD_PRIORITY 12 //线程优先级
  31. #define WORK_LOOP_THREAD_STACK_SIZE 2048 //栈大小
  32. #define WORK_LOOP_THREAD_TIMESLICE 5 //时间片
  33. #define PWM_EN 1 //0关闭,1-打开
  34. //设备状态表结构体
  35. Device_Status_typedef device_status;
  36. System_stats_t system_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. int thread_delete_workloop(void)
  42. {
  43. LOG_W("thread_delete_workloop.");
  44. rt_err_t result;
  45. if(tid_workloop!=RT_NULL)
  46. {
  47. result = rt_thread_delete(tid_workloop);
  48. }
  49. if(tid_wkstc!=RT_NULL)
  50. {
  51. result = rt_thread_delete(tid_wkstc);
  52. }
  53. if(tid_heat!=RT_NULL)
  54. {
  55. result = rt_thread_delete(tid_heat);
  56. }
  57. if(tid_ctr!=RT_NULL)
  58. {
  59. result = rt_thread_delete(tid_ctr);
  60. }
  61. return 0;
  62. }
  63. int thread_restart_workloop(void)
  64. {
  65. rt_err_t result;
  66. result = Work_Loop_Task();
  67. return result;
  68. }
  69. /**************************1.0定制2000W*************************************/
  70. uint8_t ctr_Fan_PUT(uint8_t status_ws)
  71. {
  72. rt_pin_mode(FAN_P, PIN_MODE_OUTPUT);
  73. if(status_ws==ON)
  74. {
  75. rt_pin_write(FAN_P,ON);
  76. }
  77. else {
  78. rt_pin_write(FAN_P, OFF);
  79. }
  80. return 0;
  81. }
  82. uint8_t ctr_Fan_IN(uint8_t status_ws)
  83. {
  84. rt_pin_mode(FAN_I, PIN_MODE_OUTPUT);
  85. if(status_ws==ON)
  86. {
  87. rt_pin_write(FAN_I,ON);
  88. }
  89. else {
  90. rt_pin_write(FAN_I, OFF);
  91. }
  92. return 0;
  93. }
  94. /****************************定制色诱*************************************/
  95. /**/
  96. #if Color_EN == 1
  97. uint8_t Read_Color_Key(rt_base_t key_pin)
  98. {
  99. rt_uint32_t sta_s = 0;
  100. rt_pin_mode(key_pin, PIN_MODE_INPUT);
  101. while(rt_pin_read(key_pin)==1)
  102. {
  103. sta_s++;
  104. /*持续的*/
  105. rt_thread_delay(50);
  106. }
  107. while(rt_pin_read(key_pin)==0)
  108. {
  109. rt_thread_delay(50);
  110. if(sta_s>0) break;
  111. }
  112. LOG_W("检测到IO0翻转!!!");
  113. return 1;
  114. }
  115. /*读限位开关状态*/
  116. uint8_t Read_Color_Limit(rt_base_t pin_limit)
  117. {
  118. uint8_t l_sta = 0;
  119. rt_pin_mode(pin_limit, PIN_MODE_INPUT);
  120. l_sta = rt_pin_read(pin_limit);
  121. rt_thread_delay(20);
  122. l_sta = rt_pin_read(pin_limit);
  123. return l_sta;
  124. }
  125. /*色诱板*/
  126. int ctr_Color_board(uint8_t forward,uint16_t time_board)
  127. {
  128. if(forward==CLOSE) //归位
  129. {
  130. if(device_status.cul_time>0)
  131. device_status.cul_time--;
  132. ctr_cangmen_down(OFF);
  133. ctr_cangmen_up(OFF);
  134. rt_thread_delay(1000);
  135. // if(device_status.cul_time>7) device_status.cul_time=7;
  136. // if(device_status.cul_time!=7)
  137. // {
  138. // uint8_t ct = device_status.cul_time;
  139. // while(1)
  140. // {
  141. // Beep_Tip(100);
  142. // rt_thread_delay(100);
  143. // ct--;
  144. // if(ct==0) break;
  145. // }
  146. // //return device_status.cul_time;
  147. // }
  148. if(Read_Color_Limit(LIMIT_RESET)==0)
  149. {
  150. device_status.cul_time = 0;
  151. LOG_W("已在初始位置!");
  152. Beep_Tip(1000);
  153. return 0;
  154. //黄板已经在复位状态,直接返回0;
  155. }
  156. ctr_cangmen_up(CLOSE);
  157. rt_thread_delay(20000);
  158. ctr_cangmen_up(OFF);
  159. // if(device_status.cul_time==7&&Read_Color_Limit(LIMIT_BOARD)==0)
  160. // {
  161. // LOG_W("第七天!!!");
  162. // ctr_cangmen_down(CLOSE);
  163. // rt_thread_delay(500);
  164. // }
  165. LOG_W("先打开运行到限位的右侧!");
  166. while(Read_Color_Limit(LIMIT_BOARD)==0)
  167. {
  168. LOG_W("归位:到达限位中间");
  169. ctr_cangmen_down(CLOSE);
  170. if(Read_Color_Limit(LIMIT_RESET)==0)
  171. {
  172. ctr_cangmen_down(OFF);
  173. break;
  174. }
  175. }
  176. //先打开运行到限位的右侧
  177. while(Read_Color_Limit(LIMIT_BOARD)==1)
  178. {
  179. LOG_W("归位:运行!");
  180. ctr_cangmen_down(CLOSE);
  181. if(Read_Color_Limit(LIMIT_RESET)==0)
  182. {
  183. ctr_cangmen_down(OFF);
  184. break;
  185. }
  186. }
  187. while(Read_Color_Limit(LIMIT_BOARD)==0) //到达限位中间 继续运行
  188. {
  189. LOG_W("归位:到达限位中间");
  190. ctr_cangmen_down(CLOSE);
  191. if(Read_Color_Limit(LIMIT_RESET)==0)
  192. {
  193. ctr_cangmen_down(OFF);
  194. break;
  195. }
  196. }
  197. if(Read_Color_Limit(LIMIT_RESET)==0) return 0;
  198. LOG_W("到达限位左侧!");
  199. //停止电机
  200. ctr_cangmen_down(OFF);
  201. rt_thread_delay(2000);
  202. //将推杆电机归位
  203. LOG_D("*推杆电机归位*");
  204. /*推杆电机伸出*/
  205. ctr_cangmen_up(OPEN);
  206. rt_thread_delay(20000);
  207. ctr_cangmen_up(OFF);
  208. return 2;
  209. }
  210. else if(forward==OPEN)
  211. {
  212. ctr_cangmen_down(OFF);
  213. ctr_cangmen_up(OFF);
  214. rt_thread_delay(1000);
  215. if(device_status.cul_time==7)
  216. {
  217. Beep_Tip(5000);
  218. return 7;
  219. }
  220. LOG_W("打开推杆电机!");
  221. //2023-04-18:add
  222. //if(Read_Color_Limit(LIMIT_BOARD)==0)
  223. {
  224. LOG_D("*推杆电机归位*");
  225. /*推杆电机归位*/
  226. ctr_cangmen_up(CLOSE);
  227. rt_thread_delay(20000);
  228. ctr_cangmen_up(OFF);
  229. }
  230. if(device_status.cul_time<7)
  231. device_status.cul_time++;
  232. while(Read_Color_Limit(LIMIT_BOARD)==0)
  233. {
  234. ctr_cangmen_down(forward);
  235. rt_thread_delay(50);
  236. }
  237. while(Read_Color_Limit(LIMIT_BOARD)==1)
  238. {
  239. time_board--;
  240. if(time_board==0) break;
  241. ctr_cangmen_down(forward);
  242. rt_thread_delay(50);
  243. }
  244. ctr_cangmen_down(OFF);
  245. rt_thread_delay(1000);
  246. ctr_cangmen_up(OPEN);
  247. rt_thread_delay(20000);
  248. ctr_cangmen_up(OFF);
  249. // ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  250. return OPEN;
  251. }
  252. else if (forward==RESET) {
  253. ctr_cangmen_up(OFF);
  254. ctr_cangmen_down(OFF);
  255. if(Read_Color_Limit(LIMIT_RESET)==0)
  256. {
  257. device_status.cul_time = 0;
  258. //ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  259. LOG_W("已在初始位置!");
  260. Beep_Tip(1000);
  261. ctr_cangmen_up(CLOSE);
  262. rt_thread_delay(20000);
  263. ctr_cangmen_up(OFF);
  264. device_status.cul_time = 0;
  265. return 0;
  266. //黄板已经在复位状态,直接返回0;
  267. }
  268. //if(Read_Color_Limit(LIMIT_BOARD)==0)
  269. {
  270. LOG_D("*推杆电机归位*");
  271. /*推杆电机归位*/
  272. ctr_cangmen_up(CLOSE);
  273. rt_thread_delay(20000);
  274. ctr_cangmen_up(OFF);
  275. }
  276. while(Read_Color_Limit(LIMIT_RESET)==1)
  277. {
  278. time_board--;
  279. if(time_board==0) break;
  280. ctr_cangmen_down(CLOSE);
  281. rt_thread_delay(20);
  282. }
  283. device_status.cul_time = 0;
  284. ctr_cangmen_down(OFF);
  285. }
  286. // device_status.cul_time = 0;
  287. //ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  288. return RESET; //复位返回0
  289. }
  290. #endif
  291. /****************************5.0***********************************/
  292. void ctr_turnv5(void)
  293. {
  294. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  295. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  296. // 转出
  297. rt_pin_write(CLEAR_R,ON);
  298. rt_pin_write(CLEAR_L,OFF);
  299. rt_thread_mdelay(300);
  300. //停止
  301. rt_pin_write(CLEAR_R,OFF);
  302. rt_pin_write(CLEAR_L,OFF);
  303. rt_thread_mdelay(300);
  304. //转入
  305. rt_pin_write(CLEAR_R,OFF);
  306. rt_pin_write(CLEAR_L,ON);
  307. rt_thread_mdelay(300);
  308. //停止
  309. rt_pin_write(CLEAR_R,OFF);
  310. rt_pin_write(CLEAR_L,OFF);
  311. rt_thread_mdelay(300);
  312. }
  313. /**************************机器人********************************/
  314. void ctr_Motor_Robot(uint8_t status_ws)
  315. {
  316. unsigned int close_timeout = 0;
  317. unsigned int open_timeout = 0;
  318. rt_pin_mode(LIMIT_OPEN, PIN_MODE_INPUT);
  319. rt_pin_mode(LIMIT_CLOSE, PIN_MODE_INPUT);
  320. rt_pin_mode(Motor_Power, PIN_MODE_OUTPUT);
  321. rt_pin_mode(Motor_Direction_Button, PIN_MODE_INPUT);
  322. rt_pin_mode(Motor_Direction_Ctr, PIN_MODE_OUTPUT);
  323. rt_pin_write(Motor_Power,OFF);
  324. rt_pin_write(Motor_Direction_Ctr,ON);
  325. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  326. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  327. if(status_ws == ON)
  328. {
  329. //检测按键状态
  330. while(rt_pin_read(Motor_Direction_Button)==1)
  331. {
  332. if(rt_pin_read(LIMIT_CLOSE)==1)
  333. {
  334. rt_pin_write(Motor_Direction_Ctr,ON);
  335. close_timeout++;
  336. //打开电机驱动器电源,默认关闭
  337. rt_pin_write(Motor_Power,ON);
  338. if(close_timeout==2)
  339. {
  340. rt_pin_write(CLEAR_R,ON);
  341. rt_pin_write(CLEAR_L,OFF);
  342. rt_pin_write(Motor_Power,OFF);
  343. rt_thread_delay(20);
  344. rt_pin_write(Motor_Power,ON);
  345. }
  346. rt_thread_delay(20);
  347. if(close_timeout>500)
  348. {
  349. close_timeout = 600;
  350. rt_pin_write(Motor_Power,OFF);
  351. rt_pin_write(CLEAR_R,OFF);
  352. rt_pin_write(CLEAR_L,OFF);
  353. }
  354. }
  355. else
  356. {
  357. close_timeout = 0;
  358. rt_pin_write(Motor_Power,OFF); //关闭驱动器电源
  359. rt_pin_write(CLEAR_R,OFF);
  360. rt_pin_write(CLEAR_L,OFF);
  361. }
  362. rt_thread_delay(20);
  363. }
  364. rt_pin_write(Motor_Power,OFF);
  365. rt_thread_delay(1000*2);
  366. while(rt_pin_read(Motor_Direction_Button)==0)
  367. {
  368. if(rt_pin_read(LIMIT_OPEN)==1)
  369. {
  370. open_timeout ++;
  371. //打开电机驱动器电源,默认关闭
  372. if(open_timeout==2){
  373. rt_pin_write(CLEAR_R,OFF);
  374. rt_pin_write(CLEAR_L,ON);
  375. }
  376. rt_pin_write(Motor_Power,ON);
  377. rt_pin_write(Motor_Direction_Ctr,OFF);
  378. if(open_timeout>500)
  379. {
  380. open_timeout = 600;
  381. rt_pin_write(Motor_Power,OFF);
  382. rt_pin_write(CLEAR_R,OFF);
  383. rt_pin_write(CLEAR_L,OFF);
  384. }
  385. rt_thread_delay(20);
  386. }
  387. if(rt_pin_read(LIMIT_OPEN)==0)
  388. {
  389. open_timeout = 0;
  390. rt_pin_write(Motor_Power,OFF);
  391. rt_pin_write(CLEAR_R,OFF);
  392. rt_pin_write(CLEAR_L,OFF);
  393. }
  394. rt_thread_delay(20);
  395. close_timeout = 0;
  396. }
  397. open_timeout = 0;
  398. close_timeout = 0;
  399. }
  400. else {
  401. rt_pin_write(Motor_Power,OFF);
  402. }
  403. }
  404. /*************************吸虫塔*********************************/
  405. //吸虫电机
  406. uint8_t ctr_Motor_xichong(uint8_t status_ws)
  407. {
  408. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  409. if(status_ws==ON)
  410. {
  411. rt_pin_write(MOTOR1_CTR_PIN,ON);
  412. }
  413. else {
  414. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  415. }
  416. return 0;
  417. }
  418. uint8_t ctr_Camera_Power(uint8_t status_ws)
  419. {
  420. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  421. if(status_ws==ON)
  422. {
  423. rt_pin_write(MOTOR1_CTR_PIN,ON);
  424. }
  425. else {
  426. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  427. }
  428. return 0;
  429. }
  430. //吸附电机
  431. uint8_t ctr_Motor_xifu(uint8_t status_ws)
  432. {
  433. rt_pin_mode(MOTOR2_CTR_PIN, PIN_MODE_OUTPUT);
  434. if(status_ws==ON)
  435. {
  436. rt_pin_write(MOTOR2_CTR_PIN,ON);
  437. }
  438. else {
  439. rt_pin_write(MOTOR2_CTR_PIN, OFF);
  440. }
  441. return 0;
  442. }
  443. //清扫-卷带电机
  444. void ctr_JD_Clear(uint8_t shake_sw)
  445. {
  446. rt_uint16_t turn_timeout = 0;
  447. rt_pin_mode(MOTOR_C_LIMIT,PIN_MODE_INPUT);
  448. ctr_cangmen_up(OFF); //清扫传送带的电机
  449. if(shake_sw==ON)
  450. {
  451. ctr_Heat(ON); //清洁风机
  452. Motor_shake(ON, 0);
  453. ctr_cangmen_up(OPEN); //打开清扫
  454. }
  455. else {
  456. Motor_shake(OFF, 0);
  457. ctr_cangmen_up(OPEN); //打开清扫
  458. }
  459. while(rt_pin_read(MOTOR_C_LIMIT)==0)
  460. {
  461. Motor_Juandai(ON);
  462. rt_thread_delay(50);
  463. turn_timeout++;
  464. if(turn_timeout==1000) break;
  465. }
  466. turn_timeout = 0;
  467. while(rt_pin_read(MOTOR_C_LIMIT)==1)
  468. {
  469. Motor_Juandai(ON);
  470. turn_timeout++;
  471. rt_thread_delay(50);
  472. if(turn_timeout==1000) break;
  473. }
  474. Motor_shake(OFF, 1);
  475. Motor_Juandai(OFF);
  476. ctr_cangmen_up(OFF); //关闭清扫
  477. ctr_Heat(OFF);
  478. }
  479. //工作任务流程
  480. void WorkTask_XCT(void)
  481. {
  482. while(device_status.work_status==1&&device_status.ds==1)
  483. {
  484. ctr_Motor_xifu(ON);
  485. //打开相机供电
  486. ctr_Camera_Power(ON);
  487. //ctr_Heat(ON); //清洁风机
  488. uint32_t photo_fre = 0;
  489. photo_fre = device_status.dattim * 60;
  490. while(photo_fre!=0)
  491. {
  492. photo_fre --;
  493. rt_thread_delay(1000);
  494. LOG_I("收集中,等待开始拍照:%d",photo_fre);
  495. }
  496. //卷带
  497. ctr_JD_Clear(OFF);
  498. //拍照
  499. HK_TakePhoto();
  500. //关闭吸附风机
  501. ctr_Motor_xifu(OFF);
  502. //关闭相机供电
  503. //ctr_Heat(OFF);
  504. ctr_Camera_Power(OFF);
  505. //卷带
  506. ctr_JD_Clear(ON);
  507. // rt_thread_delay(1000);
  508. // ctr_JD_Clear(ON);
  509. //震动
  510. Motor_shake(ON, device_status.shake_sec);
  511. }
  512. //关闭风机
  513. ctr_Motor_xichong(OFF);
  514. ctr_Motor_xifu(OFF);
  515. LOG_I("不在工作时间,未工作!!!");
  516. }
  517. /**********************************************************************/
  518. /*光控*/
  519. uint8_t In_Light_status(void)
  520. {
  521. rt_pin_mode(LIGHT_PIN,PIN_MODE_INPUT);
  522. return rt_pin_read(LIGHT_PIN);
  523. }
  524. /*雨控*/
  525. uint8_t In_Rain_status(void)
  526. {
  527. rt_pin_mode(RAIN_PIN,PIN_MODE_INPUT);
  528. return rt_pin_read(RAIN_PIN);
  529. }
  530. /*加热*/
  531. uint8_t ctr_Heat(uint8_t status_heat)
  532. {
  533. rt_bool_t is_currently_on;
  534. rt_tick_t now;
  535. now = rt_tick_get();
  536. is_currently_on = (system_status.heat_start_time != 0);
  537. device_status.heat_status = status_heat;
  538. rt_pin_mode(Heat_Pin, PIN_MODE_OUTPUT);
  539. rt_pin_write(Heat_Pin,status_heat);
  540. if(status_heat==ON){
  541. // 已经开着 → 不重复计时
  542. if (is_currently_on) {
  543. return ON;
  544. }
  545. // 关 → 开,记录起始时间
  546. system_status.heat_start_time = now;
  547. }else{
  548. // 已经关着 → 不重复结算
  549. if (!is_currently_on) {
  550. return OFF;
  551. }
  552. // 开 → 关,结算运行时间
  553. system_status.heater_running_time +=
  554. (now - system_status.heat_start_time);
  555. system_status.heat_start_time = 0;
  556. }
  557. return status_heat;
  558. }
  559. /*制冷*/
  560. uint8_t ctr_Cold(uint8_t status_cold)
  561. {
  562. device_status.cold_status = status_cold;
  563. rt_pin_mode(Cold_Pin, PIN_MODE_OUTPUT);
  564. rt_pin_write(Cold_Pin,status_cold);
  565. return status_cold;
  566. }
  567. /*相机供电*/
  568. void ctr_photo(uint8_t status_photo)
  569. {
  570. rt_pin_mode(PHOTO,PIN_MODE_OUTPUT);
  571. rt_pin_write(PHOTO,status_photo);
  572. }
  573. /*************************************************
  574. Function: ctr_Cool_Fan
  575. Description: 散热风机的开关
  576. Calls:
  577. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  578. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  579. Input: ON-开,OFF-关
  580. Output: NULL
  581. Return: ON-开,OFF-关
  582. Others: NULL
  583. *************************************************/
  584. uint8_t ctr_Cool_Fan(uint8_t status_cool)
  585. {
  586. device_status.cool_fan_status = status_cool;
  587. rt_pin_mode(Cool_Fan_L, PIN_MODE_OUTPUT);
  588. rt_pin_mode(Cool_Fan_R, PIN_MODE_OUTPUT);
  589. if(status_cool==OFF)
  590. {
  591. rt_pin_write(Cool_Fan_L,OFF);
  592. rt_pin_write(Cool_Fan_R,OFF);
  593. }
  594. if(status_cool==ON)
  595. {
  596. rt_pin_write(Cool_Fan_L,ON);
  597. rt_pin_write(Cool_Fan_R,OFF);
  598. }
  599. return device_status.cool_fan_status;
  600. }
  601. /*************************************************
  602. Function: ctr_Collect_Fan
  603. Description: 采集风机的开关
  604. Calls:
  605. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  606. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  607. Input: ON-开,OFF-关
  608. Output: NULL
  609. Return: ON-开,OFF-关
  610. Others: NULL
  611. *************************************************/
  612. void ctr_develop(void)
  613. {
  614. rt_kprintf("===============开始培养=================:%d\n",device_status.cul_time);
  615. //已经培养的时间-分钟
  616. device_status.stay_time = 0;
  617. rt_uint32_t ii = 0;
  618. while(device_status.develop_flag==1)
  619. {
  620. float stayedtime = 0.01;
  621. char stayed[5];
  622. stayedtime = (float)device_status.stay_time / 60.0;
  623. sprintf(stayed,"%0.02f",stayedtime);
  624. HMI_WRITE("workSta.staytime.txt=\"%s\"",stayed);
  625. ii++;
  626. LOG_I("developing...................................%d\n",ii);
  627. LOG_I("============================设定的培养温度:%d\n",device_status.heatvalue);
  628. LOG_I("============================培养仓实时温度:%d\n",device_status.pre_temp);
  629. if(device_status.pre_temp<(device_status.heatvalue-5))
  630. {
  631. //未制冷
  632. if(device_status.cold_status==0)
  633. {
  634. ctr_Heat(ON);
  635. }
  636. }
  637. else
  638. {
  639. ctr_Heat(OFF);
  640. }
  641. LOG_I("============================制冷开关:%d\n",device_status.cold_sw);
  642. if(device_status.cold_sw==1)
  643. {
  644. if(device_status.pre_temp>(device_status.heatvalue-10))
  645. {
  646. if(device_status.heat_status==0)
  647. {
  648. ctr_Cold(ON);
  649. }
  650. }
  651. else
  652. {
  653. ctr_Cold(OFF);
  654. }
  655. }
  656. if(ii%60==0)
  657. {
  658. device_status.stay_time++;
  659. if(device_status.stay_time / 60 == device_status.cul_time) device_status.develop_flag = 0;
  660. LOG_I("developed...................................%d分钟\n",device_status.stay_time);
  661. }
  662. if(device_status.box_temp>35)
  663. {
  664. ctr_Cool_Fan(ON);
  665. }
  666. else if (device_status.box_temp<30)
  667. {
  668. ctr_Cool_Fan(OFF);
  669. }
  670. rt_thread_delay(1000);
  671. }
  672. ctr_Cold(OFF);
  673. ctr_Heat(OFF);
  674. LOG_I("=========!!!培养完成!!!==========");
  675. }
  676. uint8_t ctr_Collect_Fan(uint8_t status_collect)
  677. {
  678. device_status.collect_fan_status = status_collect;
  679. rt_pin_mode(Collect_Fan, PIN_MODE_OUTPUT);
  680. if(status_collect==OFF)
  681. {
  682. rt_pin_write(Collect_Fan,OFF);
  683. }
  684. if(status_collect==ON)
  685. {
  686. rt_pin_write(Collect_Fan,ON);
  687. }
  688. return device_status.collect_fan_status;
  689. }
  690. /*************************************************
  691. Function: ctr_develop
  692. Description: 培养载玻片孢子
  693. Calls:
  694. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  695. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  696. Input: v=0(复位) v=90转90度
  697. Output: NULL
  698. Return: NULL
  699. Others: NULL
  700. *************************************************/
  701. /*上仓门*/
  702. uint8_t ctr_cangmen_up(uint8_t status_up)
  703. {
  704. rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
  705. rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
  706. if(status_up==OFF)
  707. {
  708. rt_pin_write(Collect_fan_R,ON);
  709. rt_pin_write(Collect_fan_L,ON);
  710. device_status.ctr_up_motor = 0;
  711. rt_thread_delay(1000);
  712. }
  713. if(status_up==OPEN)
  714. {
  715. device_status.up_status = 1;
  716. rt_pin_write(Collect_fan_R,OFF);
  717. rt_pin_write(Collect_fan_L,OFF);
  718. rt_pin_write(Collect_fan_R,ON);
  719. rt_pin_write(Collect_fan_L,OFF);
  720. }
  721. if(status_up==CLOSE)
  722. {
  723. device_status.up_status = 0;
  724. rt_pin_write(Collect_fan_R,OFF);
  725. rt_pin_write(Collect_fan_L,OFF);
  726. rt_pin_write(Collect_fan_R,OFF);
  727. rt_pin_write(Collect_fan_L,ON);
  728. }
  729. return device_status.up_status;
  730. }
  731. //下仓门
  732. uint8_t ctr_cangmen_down(uint8_t status_down)
  733. {
  734. rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
  735. rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
  736. if(status_down==OFF)
  737. {
  738. rt_pin_write(C_DOWN_R,ON);
  739. rt_pin_write(C_DOWN_L,ON);
  740. device_status.ctr_down_motor = 0;
  741. rt_thread_delay(1000);
  742. }
  743. if(status_down==OPEN)
  744. {
  745. device_status.down_status = 1;
  746. rt_pin_write(C_DOWN_R,OFF);
  747. rt_pin_write(C_DOWN_L,OFF);
  748. rt_pin_write(C_DOWN_R,ON);
  749. rt_pin_write(C_DOWN_L,OFF);
  750. }
  751. if(status_down==CLOSE)
  752. {
  753. device_status.down_status = 0;
  754. rt_pin_write(C_DOWN_R,OFF);
  755. rt_pin_write(C_DOWN_L,OFF);
  756. rt_pin_write(C_DOWN_R,OFF);
  757. rt_pin_write(C_DOWN_L,ON);
  758. }
  759. return device_status.down_status;
  760. }
  761. //镇流器
  762. uint8_t ctr_lamp(uint8_t status_lamp, uint8_t lamp_num)
  763. {
  764. rt_pin_mode(LAMP_SW, PIN_MODE_OUTPUT);
  765. rt_pin_mode(LAMP_1_SW, PIN_MODE_OUTPUT);
  766. rt_pin_mode(LAMP_2_SW, PIN_MODE_OUTPUT);
  767. rt_bool_t is_currently_on;
  768. rt_tick_t now;
  769. now = rt_tick_get();
  770. is_currently_on = (system_status.lamp_start_time != 0);
  771. if (status_lamp == ON)
  772. {
  773. // ====== 开灯 ======
  774. switch (lamp_num) {
  775. case 1:
  776. rt_pin_write(LAMP_SW, ON);
  777. device_status.lamp_status = ON;
  778. break;
  779. case 2:
  780. rt_pin_write(LAMP_1_SW, ON);
  781. device_status.lamp1_status = ON;
  782. break;
  783. case 3:
  784. rt_pin_write(LAMP_2_SW, ON);
  785. device_status.lamp2_status = ON;
  786. break;
  787. default:
  788. break;
  789. }
  790. // 已经开着 → 不重复计时
  791. if (is_currently_on) {
  792. return ON;
  793. }
  794. // 关 → 开,记录起始时间
  795. system_status.lamp_start_time = now;
  796. }
  797. else
  798. {
  799. // ====== 关灯 ======
  800. switch (lamp_num) {
  801. case 1:
  802. rt_pin_write(LAMP_SW, OFF);
  803. device_status.lamp_status = OFF;
  804. break;
  805. case 2:
  806. rt_pin_write(LAMP_1_SW, OFF);
  807. device_status.lamp1_status = OFF;
  808. break;
  809. case 3:
  810. rt_pin_write(LAMP_2_SW, OFF);
  811. device_status.lamp2_status = OFF;
  812. break;
  813. default:
  814. break;
  815. }
  816. // 已经关着 → 不重复结算
  817. if (!is_currently_on) {
  818. return OFF;
  819. }
  820. // 开 → 关,结算运行时间
  821. system_status.lamp_running_time +=
  822. (now - system_status.lamp_start_time);
  823. system_status.lamp_start_time = 0;
  824. }
  825. HMI_WRITE("sysTest.switchLamp.val=%d", device_status.lamp_status);
  826. return device_status.lamp_status;
  827. }
  828. //震动电机
  829. uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec)
  830. {
  831. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  832. #if 0
  833. rt_pin_write(SHAKE_SW,ON);
  834. return 0;
  835. #endif
  836. if(status_shake==ON&&device_status.shake_ws==1)
  837. {
  838. if(device_status.dtype==3)
  839. {
  840. for(uint8_t shake_i = 0;shake_i<shake_sec;shake_i++)
  841. {
  842. rt_pin_write(SHAKE_SW,ON);
  843. rt_thread_delay(100);
  844. rt_pin_write(SHAKE_SW,OFF);
  845. rt_thread_delay(1000);
  846. }
  847. }
  848. rt_pin_write(SHAKE_SW,OFF);
  849. HMI_WRITE("cangWei.switchShake.val=%d",0);
  850. system_status.vibration_count += 1;
  851. }
  852. else
  853. {
  854. rt_pin_write(SHAKE_SW,OFF);
  855. HMI_WRITE("cangWei.switchShake.val=%d",0);
  856. }
  857. return status_shake;
  858. }
  859. //补光
  860. uint8_t ctr_led(uint8_t status_led)
  861. {
  862. rt_pin_mode(LED_SW, PIN_MODE_OUTPUT);
  863. if(device_status.version_type==6)
  864. rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
  865. if(status_led==ON)
  866. {
  867. rt_pin_write(LED_SW,ON);
  868. if(device_status.version_type==6)
  869. rt_pin_write(LED_P,ON);
  870. HMI_WRITE("sysTest.switchFill.val=%d",ON);
  871. }
  872. else if(status_led==OFF){
  873. rt_pin_write(LED_SW,OFF);
  874. if(device_status.version_type==6)
  875. rt_pin_write(LED_P,OFF);
  876. HMI_WRITE("sysTest.switchPhoto.val=%d",OFF);
  877. HMI_WRITE("sysTest.switchFill.val=%d",OFF);
  878. }
  879. return status_led;
  880. }
  881. /*************************************************
  882. Function: ctr_turn
  883. Description: 转盘驱动
  884. Calls:
  885. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  886. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  887. Input: v=0(复位) v=90转90度
  888. Output: NULL
  889. Return: NULL
  890. Others: NULL
  891. *************************************************/
  892. void ctr_turn(uint8_t v,uint8_t sta)
  893. {
  894. DTU_Write("turn.mp3");
  895. LOG_I("================v===============:%d",v);
  896. rt_uint16_t turn_cnt = 0;
  897. rt_pin_mode(TURN_ZP_R, PIN_MODE_OUTPUT);
  898. rt_pin_mode(TURN_ZP_L, PIN_MODE_OUTPUT);
  899. rt_pin_mode(LIMIT_0, PIN_MODE_INPUT);
  900. rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
  901. //if(v==0&&rt_pin_read(LIMIT_0)==0) return; //如果在初始位置,则不再往下执行
  902. while(rt_pin_read(LIMIT_0)==0||rt_pin_read(LIMIT_90)==0)
  903. {
  904. rt_pin_write(TURN_ZP_R, ON);
  905. rt_pin_write(TURN_ZP_L, OFF);
  906. //Motor_shake(ON,0);
  907. turn_cnt ++;
  908. rt_thread_delay(100);
  909. if(turn_cnt==1000)
  910. {
  911. turn_cnt = 0;
  912. rt_pin_write(TURN_ZP_R, OFF);
  913. rt_pin_write(TURN_ZP_L, OFF);
  914. //Motor_shake(OFF,0);
  915. char *turn_warn =makeJson_Warn("未检测到限位", "转盘");
  916. DTU_Write("%s",turn_warn);
  917. rt_free(turn_warn);
  918. break;
  919. }
  920. }
  921. turn_cnt = 0;
  922. while(v==0&&rt_pin_read(LIMIT_0)==1)
  923. {
  924. rt_pin_write(TURN_ZP_R, ON);
  925. rt_pin_write(TURN_ZP_L, OFF);
  926. Motor_shake(ON,0);
  927. rt_thread_delay(200); //10 to 100
  928. turn_cnt ++;
  929. if(turn_cnt==300) //6000 to 600
  930. {
  931. turn_cnt = 0;
  932. // rt_pin_write(TURN_ZP_R, OFF);
  933. // rt_pin_write(TURN_ZP_L, OFF);
  934. // char *turn_warn =makeJson_Warn("超时", "转盘复位");
  935. // DTU_Write("%s",turn_warn);
  936. // rt_free(turn_warn);
  937. break;
  938. }
  939. }
  940. while(v==0&&rt_pin_read(LIMIT_0)==1)
  941. {
  942. rt_pin_write(TURN_ZP_R, ON);
  943. rt_pin_write(TURN_ZP_L, OFF);
  944. //Motor_shake(ON,0);
  945. rt_thread_delay(50); //10 to 50
  946. turn_cnt ++;
  947. if(turn_cnt==10) //6000 to 1200
  948. {
  949. turn_cnt = 0;
  950. rt_pin_write(TURN_ZP_R, OFF);
  951. rt_pin_write(TURN_ZP_L, OFF);
  952. //Motor_shake(OFF,0);
  953. char *turn_warn =makeJson_Warn("超时", "转盘复位");
  954. DTU_Write("%s",turn_warn);
  955. rt_free(turn_warn);
  956. break;
  957. }
  958. }
  959. turn_cnt = 0;
  960. while(v==90&&rt_pin_read(LIMIT_90)==1)
  961. {
  962. rt_pin_write(TURN_ZP_R, ON);
  963. rt_pin_write(TURN_ZP_L, OFF);
  964. //Motor_shake(ON,0);
  965. rt_thread_delay(200);
  966. turn_cnt ++;
  967. if(turn_cnt==150)
  968. {
  969. turn_cnt = 0;
  970. // rt_pin_write(TURN_ZP_R, OFF);
  971. // rt_pin_write(TURN_ZP_L, OFF);
  972. // char *turn_warn =makeJson_Warn("超时", "转盘");
  973. // DTU_Write(turn_warn);
  974. // rt_free(turn_warn);
  975. break;
  976. }
  977. }
  978. while(v==90&&rt_pin_read(LIMIT_90)==1)
  979. {
  980. // rt_pin_write(TURN_ZP_R, ON);
  981. // rt_pin_write(TURN_ZP_L, OFF);
  982. Motor_shake(ON,0);
  983. rt_thread_delay(50);
  984. turn_cnt ++;
  985. if(turn_cnt==10)
  986. {
  987. turn_cnt = 0;
  988. rt_pin_write(TURN_ZP_R, OFF);
  989. rt_pin_write(TURN_ZP_L, OFF);
  990. //Motor_shake(OFF,0);
  991. char *turn_warn =makeJson_Warn("超时", "转盘");
  992. DTU_Write(turn_warn);
  993. rt_free(turn_warn);
  994. break;
  995. }
  996. }
  997. if(sta!=0)
  998. {
  999. //保存位置
  1000. device_status.run_sta = sta;
  1001. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  1002. }
  1003. turn_cnt = 0;
  1004. rt_pin_write(TURN_ZP_R, OFF);
  1005. rt_pin_write(TURN_ZP_L, OFF);
  1006. Motor_shake(OFF,0);
  1007. HMI_WRITE("cangWei.rotateFlag.val=0");
  1008. }
  1009. /*************************************************
  1010. Function: ctr_Motor_Driver
  1011. Description: 步进电机驱动
  1012. Calls:
  1013. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  1014. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  1015. Input: 50000000
  1016. Output: NULL
  1017. Return: shake_sec
  1018. Others: NULL
  1019. *************************************************/
  1020. void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_out)
  1021. {
  1022. beep_init();
  1023. rt_pin_mode(LIMIT_UP, PIN_MODE_INPUT);
  1024. rt_pin_mode(LIMIT_DOWN, PIN_MODE_INPUT);
  1025. rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
  1026. rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
  1027. if(EN==0)
  1028. {
  1029. rt_pin_write(Motor_Power,0);
  1030. }
  1031. else{
  1032. rt_pin_write(Motor_EN, EN);
  1033. }
  1034. rt_pin_write(Motor_DIR, DIR);
  1035. beep_set(pwm, pwm/2); //200kzh - 50%
  1036. while(DIR==1&&rt_pin_read(LIMIT_DOWN)==1)
  1037. {
  1038. if(time_out==0)
  1039. {
  1040. break;
  1041. }
  1042. rt_thread_delay(50);
  1043. time_out --;
  1044. }
  1045. while(DIR==0&&rt_pin_read(LIMIT_UP)==1)
  1046. {
  1047. if(time_out==0)
  1048. {
  1049. break;
  1050. }
  1051. rt_thread_delay(50);
  1052. time_out --;
  1053. }
  1054. rt_pin_write(Motor_EN, OFF);
  1055. if(device_status.autotakepic==0)
  1056. ctr_lamp(OFF, 1);
  1057. beep_set(0, 0); //200kzh - 50%
  1058. }
  1059. /*************************************************
  1060. Function: ctr_Petroleum_jelly
  1061. Description: 涂凡士林
  1062. Calls:
  1063. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  1064. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  1065. Input: NULL
  1066. Output: NULL
  1067. Return: NULL
  1068. Others: NULL
  1069. *************************************************/
  1070. void ctr_Petroleum_jelly(rt_uint32_t delay)
  1071. {
  1072. beep_init();
  1073. pwm_on(2,50000);
  1074. rt_thread_delay(delay*1000);
  1075. pwm_off(2,0);
  1076. rt_thread_delay(1000);
  1077. pwm_on(3, 50000);
  1078. rt_thread_delay(delay*1000);
  1079. pwm_off(3,0);
  1080. device_status.fsl_sw = 0;
  1081. }
  1082. //1.0转仓
  1083. void turnzp(void)
  1084. {
  1085. static uint16_t turn_timeout = 0;
  1086. //rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1087. //rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1088. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  1089. // rt_pin_write(CLEAR_R,OFF);
  1090. // rt_pin_write(CLEAR_L,OFF);
  1091. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  1092. {
  1093. rt_thread_delay(20);
  1094. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  1095. {
  1096. // rt_pin_write(CLEAR_R,ON);
  1097. // rt_pin_write(CLEAR_L,OFF);
  1098. Motor_Juandai(ON);
  1099. rt_thread_delay(50);
  1100. turn_timeout++;
  1101. if(turn_timeout==600)
  1102. {
  1103. LOG_E("检测不到限位,电机强制停止");
  1104. char *ctr_zp_limit_warn =makeJson_Warn("电流不足/限位超时","转盘电机");
  1105. DTU_Write("%s",ctr_zp_limit_warn);
  1106. rt_free(ctr_zp_limit_warn);
  1107. break;
  1108. }
  1109. }
  1110. break;
  1111. }
  1112. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  1113. {
  1114. rt_thread_delay(20);
  1115. while(rt_pin_read(CLEAR_R_LIMIT)==1)
  1116. {
  1117. // rt_pin_write(CLEAR_R,ON);
  1118. // rt_pin_write(CLEAR_L,OFF);
  1119. Motor_Juandai(ON);
  1120. rt_thread_delay(50);
  1121. turn_timeout++;
  1122. if(turn_timeout==600)
  1123. {
  1124. LOG_E("检测不到离开限位,电机或者限位开关异常,电机强制停止");
  1125. char *ctr_zp_limit_warn =makeJson_Warn("检测不到离开限位,电机未启动或者限位开关故障","转盘电机");
  1126. DTU_Write("%s",ctr_zp_limit_warn);
  1127. rt_free(ctr_zp_limit_warn);
  1128. break;
  1129. }
  1130. }
  1131. break;
  1132. }
  1133. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  1134. {
  1135. rt_thread_delay(20);
  1136. if(rt_pin_read(CLEAR_R_LIMIT)==0)
  1137. {
  1138. // rt_pin_write(CLEAR_R,OFF);
  1139. // rt_pin_write(CLEAR_L,OFF);
  1140. Motor_Juandai(OFF);
  1141. break;
  1142. }
  1143. else {
  1144. break;
  1145. }
  1146. }
  1147. Motor_Juandai(OFF);
  1148. // rt_pin_write(CLEAR_R,OFF);
  1149. // rt_pin_write(CLEAR_L,OFF);
  1150. turn_timeout = 0;
  1151. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1152. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1153. rt_thread_delay(1000);
  1154. }
  1155. //清扫-常闭型限位开关
  1156. //新结构使用推杆电机做清扫
  1157. uint8_t ctr_clear(uint16_t status_clear)
  1158. {
  1159. static uint16_t clear_num = 0;
  1160. #if PWM_EN == 0
  1161. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1162. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1163. #endif
  1164. rt_pin_mode(CLEAR_R_LIMIT,PIN_MODE_INPUT);
  1165. rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
  1166. /*************************************************************外接清扫
  1167. rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  1168. rt_pin_write(POWER_CLEAR,ON);
  1169. rt_thread_delay(1000*100);
  1170. rt_pin_write(POWER_CLEAR,OFF);
  1171. ************************************************************/
  1172. //停止
  1173. #if PWM_EN == 0
  1174. rt_pin_write(CLEAR_R,OFF);
  1175. rt_pin_write(CLEAR_L,OFF);
  1176. #else
  1177. Motor_Qingsao_R_PWM(OFF);
  1178. Motor_Qingsao_L_PWM(OFF);
  1179. #endif
  1180. if(status_clear==OFF||Read_Real_Voltage()/100<12) return 0;
  1181. rt_thread_delay(100);
  1182. //如果清扫位置在中间
  1183. while(rt_pin_read(CLEAR_R_LIMIT)==0&&rt_pin_read(CLEAR_L_LIMIT)==0)
  1184. {
  1185. #if PWM_EN == 0
  1186. rt_pin_write(CLEAR_R,ON);
  1187. rt_pin_write(CLEAR_L,OFF);
  1188. #else
  1189. Motor_Qingsao_R_PWM(ON);
  1190. Motor_Qingsao_L_PWM(OFF);
  1191. #endif
  1192. rt_thread_delay(50);
  1193. clear_num++;
  1194. //已到达检测位置
  1195. if(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  1196. {
  1197. #if PWM_EN == 0
  1198. rt_pin_write(CLEAR_R,ON);
  1199. rt_pin_write(CLEAR_L,ON);
  1200. #else
  1201. Motor_Qingsao_R_PWM(OFF);
  1202. Motor_Qingsao_L_PWM(OFF);
  1203. #endif
  1204. rt_thread_delay(2000);
  1205. break;
  1206. }
  1207. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  1208. {
  1209. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  1210. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  1211. #if PWM_EN == 0
  1212. rt_pin_write(CLEAR_R,ON);
  1213. rt_pin_write(CLEAR_L,ON);
  1214. #else
  1215. Motor_Qingsao_R_PWM(OFF);
  1216. Motor_Qingsao_L_PWM(OFF);
  1217. #endif
  1218. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  1219. if(Read_Real_Voltage()/100<12)
  1220. {
  1221. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1222. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1223. device_status.clear_status = 0;
  1224. return 0;
  1225. }
  1226. break;
  1227. }
  1228. }
  1229. clear_num = 0;
  1230. //如果清扫位置在左侧
  1231. while(rt_pin_read(CLEAR_R_LIMIT)==0)
  1232. {
  1233. #if PWM_EN == 0
  1234. rt_pin_write(CLEAR_R,ON);
  1235. rt_pin_write(CLEAR_L,OFF);
  1236. #else
  1237. Motor_Qingsao_R_PWM(ON);
  1238. Motor_Qingsao_L_PWM(OFF);
  1239. #endif
  1240. rt_thread_delay(50);
  1241. clear_num++;
  1242. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  1243. {
  1244. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  1245. //DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  1246. #if PWM_EN == 0
  1247. rt_pin_write(CLEAR_R,ON);
  1248. rt_pin_write(CLEAR_L,ON);
  1249. #else
  1250. Motor_Qingsao_R_PWM(OFF);
  1251. Motor_Qingsao_L_PWM(OFF);
  1252. #endif
  1253. rt_free(makeJson_Warn("Clear Motor ERR","device"));
  1254. if(Read_Real_Voltage()/100<12)
  1255. {
  1256. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1257. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1258. device_status.clear_status = 0;
  1259. return 0;
  1260. }
  1261. break;
  1262. }
  1263. }
  1264. clear_num = 0;
  1265. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1||(Read_Real_Voltage()/100)<12)
  1266. {
  1267. #if PWM_EN == 0
  1268. rt_pin_write(CLEAR_R,ON);
  1269. rt_pin_write(CLEAR_L,ON);
  1270. #else
  1271. Motor_Qingsao_R_PWM(OFF);
  1272. Motor_Qingsao_L_PWM(OFF);
  1273. #endif
  1274. if(Read_Real_Voltage()/100<12)
  1275. {
  1276. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1277. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1278. device_status.clear_status = 0;
  1279. return 0;
  1280. }
  1281. rt_thread_delay(2000);
  1282. break;
  1283. }
  1284. while(rt_pin_read(CLEAR_L_LIMIT)==0)
  1285. {
  1286. #if PWM_EN == 0
  1287. rt_pin_write(CLEAR_R,OFF);
  1288. rt_pin_write(CLEAR_L,ON);
  1289. #else
  1290. Motor_Qingsao_R_PWM(OFF);
  1291. Motor_Qingsao_L_PWM(ON);
  1292. #endif
  1293. rt_thread_delay(50);
  1294. clear_num++;
  1295. if(clear_num>=status_clear||atoi(device_status.power)>2000||(Read_Real_Voltage()/100)<12)
  1296. {
  1297. rt_kprintf("Clear Motor ERR:%d",atoi(device_status.power));
  1298. char * Clear_ERR = makeJson_Warn("Clear Motor ERR","device");
  1299. //DTU_Write("%s",Clear_ERR);
  1300. #if PWM_EN == 0
  1301. rt_pin_write(CLEAR_R,ON);
  1302. rt_pin_write(CLEAR_L,ON);
  1303. #else
  1304. Motor_Qingsao_R_PWM(OFF);
  1305. Motor_Qingsao_L_PWM(OFF);
  1306. #endif
  1307. rt_free(Clear_ERR);
  1308. if(Read_Real_Voltage()/100<12)
  1309. {
  1310. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1311. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1312. device_status.clear_status = 0;
  1313. return 0;
  1314. }
  1315. break;
  1316. }
  1317. }
  1318. while(rt_pin_read(CLEAR_L_LIMIT)==1||rt_pin_read(CLEAR_R_LIMIT)==1)
  1319. {
  1320. #if PWM_EN == 0
  1321. rt_pin_write(CLEAR_R,ON);
  1322. rt_pin_write(CLEAR_L,ON);
  1323. #else
  1324. Motor_Qingsao_R_PWM(OFF);
  1325. Motor_Qingsao_L_PWM(OFF);
  1326. #endif
  1327. rt_thread_delay(2000);
  1328. break;
  1329. }
  1330. while(rt_pin_read(CLEAR_L_LIMIT)==1&&rt_pin_read(CLEAR_R_LIMIT)==1)
  1331. {
  1332. #if PWM_EN == 0
  1333. rt_pin_write(CLEAR_R,ON);
  1334. rt_pin_write(CLEAR_L,ON);
  1335. #else
  1336. Motor_Qingsao_R_PWM(OFF);
  1337. Motor_Qingsao_L_PWM(OFF);
  1338. #endif
  1339. if(device_status.version_type==41)
  1340. {
  1341. rt_kprintf("Clear Motor Limit Not Access:%d",atoi(device_status.power));
  1342. char * Clear_ERR = makeJson_Warn("Clear Motor Limit Not Access","device");
  1343. //DTU_Write("%s",Clear_ERR);
  1344. rt_free(Clear_ERR);
  1345. }
  1346. return 0;
  1347. }
  1348. clear_num = 0;
  1349. rt_thread_delay(2000);
  1350. #if PWM_EN == 0
  1351. rt_pin_write(CLEAR_R,ON);
  1352. rt_pin_write(CLEAR_L,ON);
  1353. #else
  1354. Motor_Qingsao_R_PWM(OFF);
  1355. Motor_Qingsao_L_PWM(OFF);
  1356. #endif
  1357. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1358. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1359. device_status.clear_status = 0;
  1360. return 1;
  1361. }
  1362. //路由器供电
  1363. void ctr_router(uint8_t status_router)
  1364. {
  1365. rt_pin_mode(ROUTER, PIN_MODE_OUTPUT);
  1366. if(device_status.version_type==6)
  1367. rt_pin_mode(ROUTER_P,PIN_MODE_OUTPUT);
  1368. //rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  1369. if(status_router==ON)
  1370. {
  1371. rt_pin_write(ROUTER,ON);
  1372. //
  1373. #if LAMP_EN == 0
  1374. if(device_status.version_type==6)
  1375. rt_pin_write(ROUTER_P,ON);
  1376. #endif
  1377. }
  1378. else {
  1379. rt_pin_write(ROUTER,OFF);
  1380. //
  1381. #if LAMP_EN == 0
  1382. if(device_status.version_type==6)
  1383. rt_pin_write(ROUTER_P,OFF);
  1384. #endif
  1385. }
  1386. }
  1387. //清扫-推杆电机
  1388. void ctr_TG_Clear(uint16_t clear_timeout)
  1389. {
  1390. #if 0
  1391. int current_clear[200];
  1392. int16_t Electric_current = atoi(device_status.power); //获取电机运动前的电流
  1393. LOG_I("清扫电机待机:%d",Electric_current);
  1394. #endif
  1395. static uint16_t clear_count = 0;
  1396. clear_count = clear_timeout;
  1397. #if PWM_EN == 0
  1398. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1399. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1400. #endif
  1401. while(clear_count!=0)
  1402. {
  1403. #if PWM_EN == 0
  1404. rt_pin_write(CLEAR_R,ON);
  1405. rt_pin_write(CLEAR_L,OFF);
  1406. #else
  1407. Motor_Qingsao_R_PWM(ON);
  1408. Motor_Qingsao_L_PWM(OFF);
  1409. #endif
  1410. clear_count--;
  1411. rt_thread_delay(100);
  1412. }
  1413. #if PWM_EN == 0
  1414. rt_pin_write(CLEAR_R,ON);
  1415. rt_pin_write(CLEAR_L,ON);
  1416. #else
  1417. Motor_Qingsao_R_PWM(OFF);
  1418. Motor_Qingsao_L_PWM(OFF);
  1419. #endif
  1420. rt_thread_delay(3000);
  1421. clear_count = 0;
  1422. while(clear_timeout!=clear_count)
  1423. {
  1424. #if PWM_EN == 0
  1425. rt_pin_write(CLEAR_R,OFF);
  1426. rt_pin_write(CLEAR_L,ON);
  1427. #else
  1428. Motor_Qingsao_R_PWM(OFF);
  1429. Motor_Qingsao_L_PWM(ON);
  1430. #endif
  1431. // if(clear_count<200)
  1432. // current_clear[clear_count] = atoi(device_status.power);
  1433. clear_count++;
  1434. rt_thread_delay(100);
  1435. }
  1436. #if PWM_EN == 0
  1437. rt_pin_write(CLEAR_R,ON);
  1438. rt_pin_write(CLEAR_L,ON);
  1439. #else
  1440. Motor_Qingsao_R_PWM(OFF);
  1441. Motor_Qingsao_L_PWM(OFF);
  1442. #endif
  1443. #if 0
  1444. bubblesort(current_clear,200);
  1445. if(current_clear[199]-Electric_current <100&&device_status.work_status==1&&Electric_current!=0&&Electric_current<5000)
  1446. {
  1447. LOG_E("清扫电机电流不足:%d!",current_clear[199]);
  1448. char *ctr_clear_warn = makeJson_Warn("电流不足","清扫电机");
  1449. DTU_Write("%s",ctr_clear_warn);
  1450. rt_free(ctr_clear_warn);
  1451. }
  1452. #endif
  1453. rt_thread_delay(2000);
  1454. device_status.clear_status = 0;
  1455. HMI_WRITE("cangWei.rotateFlag.val=%d",0);
  1456. HMI_WRITE("sysTest.switchClear.val=%d",0);
  1457. }
  1458. //DTU,RTU供电
  1459. void ctr_RTU_DTU(uint8_t status_rtu)
  1460. {
  1461. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  1462. if(status_rtu==ON)
  1463. {
  1464. rt_pin_write(RTU_DTU,ON);
  1465. }
  1466. else
  1467. {
  1468. LOG_W("RTU电源复位!!!");
  1469. rt_pin_write(RTU_DTU,OFF);
  1470. }
  1471. }
  1472. //海康拍照
  1473. void Hk_Take_io(void)
  1474. {
  1475. rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
  1476. rt_pin_mode(HK_IO, PIN_MODE_OUTPUT);
  1477. rt_pin_write(HK_TAKE, 1);
  1478. rt_pin_write(HK_IO, 0);
  1479. if(device_status.dtype==3)
  1480. Beep_Tip(1000);
  1481. if(device_status.dtype==7)
  1482. rt_thread_mdelay(1000);
  1483. rt_pin_write(HK_TAKE, 0);
  1484. rt_pin_write(HK_IO, 1);
  1485. }
  1486. void calorstat(uint16_t heat_time)
  1487. {
  1488. //uint8_t heat_up_cnt = 0;
  1489. uint16_t n = 0;
  1490. uint16_t delay_heat = 60;
  1491. FlagStatus heat_flg = RESET;
  1492. device_status.heat_time_min = 0;
  1493. device_status.heat_tem_max = device_status.heattem; //初始化加热实时温度
  1494. ctr_Heat(ON);
  1495. // UpLoad_Data(); //开始加热时的第一条数据
  1496. //恒温模式
  1497. for(n=0;n < heat_time;n++)
  1498. {
  1499. if(device_status.heattem>device_status.heatvalue&&heat_flg==RESET)
  1500. {
  1501. heat_flg = SET;
  1502. ctr_Heat(OFF);
  1503. while(delay_heat!=0)
  1504. {
  1505. delay_heat --;
  1506. rt_kprintf("正在恒温加热!!!:%d",delay_heat);
  1507. HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"",delay_heat);
  1508. rt_thread_delay(1000);
  1509. if(device_status.heattem>device_status.heat_tem_max + 1){
  1510. device_status.heat_tem_max = device_status.heattem;
  1511. }
  1512. //如果触发异常退出加热
  1513. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1514. {
  1515. rt_thread_delay(1000);
  1516. if(device_status.bat_status == 1)
  1517. {
  1518. LOG_W("============================触发异常退出加热==========================");
  1519. ctr_lamp(OFF,1);
  1520. ctr_Heat(OFF);
  1521. break;
  1522. }
  1523. }
  1524. }
  1525. delay_heat = 60;
  1526. //跳出FOR循环
  1527. n = n + 60;
  1528. }
  1529. if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
  1530. {
  1531. device_status.heat_tem_max = device_status.heattem;
  1532. ctr_Heat(ON);
  1533. }
  1534. else if (device_status.heattem>=device_status.heatvalue&&heat_flg==SET)
  1535. {
  1536. // if(heat_up_cnt==0)
  1537. // {
  1538. // UpLoad_Data(); //加热到设定温度的数据
  1539. // heat_up_cnt = 1;
  1540. // }
  1541. device_status.heat_tem_max = device_status.heattem;
  1542. ctr_Heat(OFF);
  1543. }
  1544. if((n % 60)==0)
  1545. {
  1546. device_status.heat_time_min = device_status.heat_time_min + 1;
  1547. // if(device_status.heat_time_min % 5 == 0)
  1548. // {
  1549. // UpLoad_Data(); //从加热开始每5分钟上传的数据
  1550. // }
  1551. }
  1552. //如果触发异常退出加热
  1553. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1554. {
  1555. rt_thread_delay(1000);
  1556. if(device_status.bat_status == 1)
  1557. {
  1558. rt_kprintf("============================触发异常退出加热==========================");
  1559. ctr_lamp(OFF,1);
  1560. ctr_Heat(OFF);
  1561. break;
  1562. }
  1563. }
  1564. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  1565. {
  1566. ctr_Heat(OFF);
  1567. rt_kprintf("异常退出!!!\n");
  1568. break;
  1569. }
  1570. rt_thread_delay(1000);
  1571. rt_kprintf("=======正在加热======:%d-%d\n",n,heat_time);
  1572. HMI_WRITE("workSta.g0.txt=\"正在加热!!!:%d-%d\"",n,heat_time);
  1573. }
  1574. ctr_Heat(OFF);
  1575. //UpLoad_Data(); //加热结束的数据
  1576. }
  1577. //初始化所有控制驱动,关闭
  1578. void HardWare_Init(uint8_t boot)
  1579. {
  1580. Beep_Tip(200);
  1581. //关闭上仓门
  1582. ctr_cangmen_up(OFF);
  1583. if(device_status.dtype==3){
  1584. //关闭下仓门电机
  1585. ctr_cangmen_down(OFF);
  1586. }
  1587. //关闭镇流器
  1588. if(device_status.autotakepic==0)
  1589. ctr_lamp(OFF,1);
  1590. //关闭震动电机
  1591. ctr_shake(OFF,0);
  1592. //关闭加热
  1593. ctr_Heat(OFF);
  1594. //关闭补光灯
  1595. ctr_led(OFF);
  1596. //关闭12V供电(海康相机,RTU)
  1597. //ctr_photo(OFF);
  1598. }
  1599. //拍照
  1600. void HK_TakePhoto(void)
  1601. {
  1602. //打开补光灯
  1603. ctr_led(ON);
  1604. //播放语音
  1605. DTU_Write("takephoto.mp3");
  1606. rt_thread_delay(1000);
  1607. //吸虫塔,水稻
  1608. if(device_status.version_type!=6&&device_status.version_type!=4)
  1609. {
  1610. rt_thread_delay(1000*15);
  1611. }
  1612. char *takephotojson = makeJson_takephoto();
  1613. DTU_Write("%s",takephotojson);
  1614. rt_free(takephotojson);
  1615. //触发海康相机拍照
  1616. Hk_Take_io();
  1617. if(device_status.version_type!=6)
  1618. {
  1619. rt_thread_delay(1000*45);
  1620. }
  1621. else {
  1622. ctr_led(ON);
  1623. rt_thread_delay(1000*19);
  1624. }
  1625. ctr_led(OFF);
  1626. }
  1627. //光控测试任务
  1628. void SunTest(void)
  1629. {
  1630. rt_uint16_t ui_timeout_l = 0;
  1631. //未检测到光照,一秒扫描等待,超时30S
  1632. while(Read_Light_Voltage()<500)
  1633. {
  1634. ui_timeout_l ++;
  1635. rt_thread_delay(1000);
  1636. if(ui_timeout_l==30) break;
  1637. }
  1638. rt_thread_delay(3000);
  1639. if(Read_Light_Voltage()<500)
  1640. {
  1641. device_status.sun_status = 0;//光控状态
  1642. }
  1643. if(Read_Light_Voltage()>500)
  1644. {
  1645. rt_thread_delay(1000);
  1646. }
  1647. rt_thread_delay(3000);
  1648. if(Read_Light_Voltage()>500)
  1649. {
  1650. device_status.sun_status = 1;
  1651. ctr_lamp(OFF,1);
  1652. }
  1653. HMI_WRITE("sysTest.switchSun.val=%d",0);
  1654. device_status.sun_test = 0;
  1655. device_status.work_status=0;
  1656. }
  1657. /*上电初始化*/
  1658. void ResetInit(void)
  1659. {
  1660. if(device_status.dtype==7)
  1661. {
  1662. ctr_Motor_Driver(0, 0, 0, 0);
  1663. //关闭电磁阀
  1664. ctr_shake(OFF, 0);
  1665. //关闭加热
  1666. ctr_Heat(OFF);
  1667. //关闭制冷
  1668. ctr_Cold(OFF);
  1669. //关闭补光灯
  1670. ctr_led(OFF);
  1671. //转盘复位
  1672. if(device_status.run_sta==0)
  1673. ctr_turn(0, 0);
  1674. }
  1675. if(device_status.version_type!=6&&device_status.version_type!=7)
  1676. {
  1677. device_status.work_done = 1;
  1678. //1.打开路由器供电
  1679. if(device_status.power_status==1)
  1680. {
  1681. ctr_router(ON);
  1682. ctr_RTU_DTU(ON);
  1683. //2.打开相机供电
  1684. ctr_photo(ON);
  1685. }
  1686. //3.关闭镇流器
  1687. ctr_lamp(OFF,1);
  1688. #if LAMP_EN == 1
  1689. ctr_lamp(OFF,2);
  1690. ctr_lamp(OFF,3);
  1691. #endif
  1692. //4.关闭震动电机
  1693. ctr_shake(OFF, 0);
  1694. //5.关闭加热
  1695. ctr_Heat(OFF);
  1696. //6.关闭补光灯
  1697. ctr_led(OFF);
  1698. if(device_status.bat_status==1||atoi(device_status.fuse_voltage)<1)
  1699. {
  1700. LOG_W("欠压!");
  1701. return;
  1702. }
  1703. //7.关闭上仓门
  1704. device_status.ctr_up_motor = 2;
  1705. // while(device_status.ctr_up_motor!=0)
  1706. // {
  1707. // LOG_I("关闭上仓门...");
  1708. // rt_thread_delay(100);
  1709. // }
  1710. //8.关闭下仓门
  1711. device_status.ctr_down_motor = 2;
  1712. while(device_status.ctr_down_motor!=0)
  1713. {
  1714. LOG_I("关闭下仓门....");
  1715. rt_thread_delay(100);
  1716. }
  1717. //9.清扫
  1718. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  1719. {
  1720. LOG_W("异常退出!!!\n");
  1721. return;
  1722. }
  1723. #if 0//LAMP_EN == 0
  1724. ctr_Fan_PUT(OFF);
  1725. ctr_Fan_IN(OFF);
  1726. #endif
  1727. if(device_status.version_type==4||
  1728. device_status.version_type==41||
  1729. device_status.version_type==42||
  1730. device_status.version_type==43||
  1731. device_status.version_type==12)
  1732. {
  1733. device_status.clear_status=1;
  1734. while(device_status.clear_status==1){
  1735. rt_thread_delay(1000);
  1736. }
  1737. }
  1738. #if DZ_260519 == 1
  1739. device_status.clear_status = 2;
  1740. #endif
  1741. #if LAMP_EN == 0
  1742. //排虫
  1743. if(device_status.handle_bugger==0){
  1744. device_status.run_sta = 111; //排虫
  1745. }else{
  1746. device_status.run_sta = 112; //收虫
  1747. }
  1748. #endif
  1749. }
  1750. else {
  1751. if(device_status.power_status==1)
  1752. {
  1753. //1.打开路由器供电
  1754. ctr_router(ON);
  1755. ctr_RTU_DTU(ON);
  1756. //2.打开相机供电
  1757. ctr_photo(ON);
  1758. }
  1759. //5.关闭加热
  1760. //6.关闭补光灯
  1761. ctr_led(OFF);
  1762. }
  1763. }
  1764. /*三色光源*/
  1765. void Led_Check(uint8_t tp)
  1766. {
  1767. if(tp==3)
  1768. {
  1769. if(device_status.light_over_tim>2*3600)
  1770. {
  1771. device_status.work_status = 1;
  1772. device_status.lamp_status = 1;
  1773. device_status.lamp1_status = 0;
  1774. device_status.lamp2_status = 0;
  1775. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1776. }
  1777. else if (device_status.light_over_tim>3600&&device_status.light_over_tim<7200) {
  1778. device_status.work_status = 1;
  1779. device_status.lamp_status = 0;
  1780. device_status.lamp1_status = 1;
  1781. device_status.lamp2_status = 0;
  1782. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1783. }
  1784. else if (device_status.light_over_tim<1*3600) {
  1785. device_status.work_status = 1;
  1786. device_status.lamp_status = 0;
  1787. device_status.lamp1_status = 0;
  1788. device_status.lamp2_status = 1;
  1789. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1790. }
  1791. }
  1792. else if (tp==6) {
  1793. if(device_status.light_over_tim>4*3600)
  1794. {
  1795. device_status.work_status = 1;
  1796. device_status.lamp_status = 1;
  1797. device_status.lamp1_status = 0;
  1798. device_status.lamp2_status = 0;
  1799. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1800. }
  1801. else if (device_status.light_over_tim<14400&&device_status.light_over_tim>7200) {
  1802. device_status.work_status = 1;
  1803. device_status.lamp_status = 0;
  1804. device_status.lamp1_status = 1;
  1805. device_status.lamp2_status = 0;
  1806. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1807. }
  1808. else if (device_status.light_over_tim<7200) {
  1809. device_status.work_status = 1;
  1810. device_status.lamp_status = 0;
  1811. device_status.lamp1_status = 0;
  1812. device_status.lamp2_status = 1;
  1813. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1814. }
  1815. }
  1816. else if (tp==9) {
  1817. if(device_status.light_over_tim>6*3600)
  1818. {
  1819. device_status.work_status = 1;
  1820. device_status.lamp_status = 1;
  1821. device_status.lamp1_status = 0;
  1822. device_status.lamp2_status = 0;
  1823. LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
  1824. }
  1825. else if (device_status.light_over_tim<6*3600&&device_status.light_over_tim>3*3600) {
  1826. device_status.work_status = 1;
  1827. device_status.lamp_status = 0;
  1828. device_status.lamp1_status = 1;
  1829. device_status.lamp2_status = 0;
  1830. LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
  1831. }
  1832. else if (device_status.light_over_tim<3*3600) {
  1833. device_status.work_status = 1;
  1834. device_status.lamp_status = 0;
  1835. device_status.lamp1_status = 0;
  1836. device_status.lamp2_status = 1;
  1837. LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
  1838. }
  1839. }
  1840. }
  1841. //出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
  1842. void HardWare_Check(uint8_t boot)
  1843. {
  1844. if(boot==0&&device_status.version_type!=6)
  1845. {
  1846. //停止所有动作 -完成
  1847. HardWare_Init(boot);
  1848. }
  1849. else {
  1850. //停止所有动作
  1851. //读取记录待机功耗(实测大概70mA)
  1852. //(需减去屏幕的功耗大概120mA)
  1853. //动作上仓门,读取功率值保存
  1854. //动作下仓门,读取功率值保存
  1855. //动作清扫,读取功率值保存
  1856. //打开镇流器,读取功率值保存
  1857. //打开海康相机供电,读取功率值保存
  1858. //打开补光灯,读取功率值保存
  1859. //打开路由器/RTU供电,读取功率值保存
  1860. //打开加热,读取功率值保存
  1861. }
  1862. }
  1863. #if 0
  1864. //工作状态检测
  1865. void WorkCheck(void)
  1866. {
  1867. static rt_uint32_t light_timeout = 3600;
  1868. //雨控检测,温控检测,电池电压检测
  1869. while(device_status.ds==1&&device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
  1870. {
  1871. //工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
  1872. if(device_status.timeSwitch==1)
  1873. {
  1874. LOG_I("***********时控*****************");
  1875. if(device_status.startBar==device_status.stopBar&&device_status.startBar==0){
  1876. device_status.work_status = 1;
  1877. LOG_I("24 hours work...");
  1878. #if LAMP_EN == 1
  1879. device_status.lamp_status = 1;
  1880. device_status.lamp1_status = 0;
  1881. device_status.lamp2_status = 0;
  1882. if(device_status.sun_status==1){
  1883. ctr_lamp(OFF, 1);
  1884. ctr_lamp(OFF, 2);
  1885. ctr_lamp(OFF, 3);
  1886. }
  1887. #endif
  1888. }
  1889. //如果开始和结束是同一天
  1890. if(device_status.startBar<device_status.stopBar)
  1891. {
  1892. LOG_I("开始和结束是同一天");
  1893. time_t now;
  1894. time(&now);
  1895. static struct tm nowtime; //现在
  1896. static struct tm starttime; //开始
  1897. static struct tm endtime; //结束
  1898. //获取当前时间戳
  1899. nowtime =*localtime(&now);
  1900. nowtime.tm_hour = nowtime.tm_hour-8;
  1901. //获取定时开始的时间戳
  1902. starttime = *localtime(&now);
  1903. starttime.tm_hour = device_status.startBar-8;
  1904. starttime.tm_min = 0;
  1905. starttime.tm_sec = 0;
  1906. //获取定时结束的时间戳
  1907. endtime = *localtime(&now);
  1908. endtime.tm_hour = device_status.stopBar-8;
  1909. endtime.tm_min = 0;
  1910. endtime.tm_sec = 0;
  1911. LOG_I("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1912. //如果当前时间大于开始时间且小于结束时间,且没有开始工作
  1913. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
  1914. {
  1915. LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
  1916. device_status.work_status = 1;
  1917. }
  1918. //如果当前时间小于开始时间
  1919. else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
  1920. {
  1921. LOG_I("当前时间小于开始时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1922. device_status.work_status = 0;
  1923. }
  1924. //当前时间大于结束时间
  1925. else {
  1926. LOG_I("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
  1927. device_status.work_status = 0;
  1928. }
  1929. #if LAMP_EN == 1
  1930. //如果当前时间超过20点,未到21点
  1931. if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+3600)<0))
  1932. {
  1933. LOG_I("3led:20~21");
  1934. device_status.lamp_status = 1;
  1935. device_status.lamp1_status = 0;
  1936. device_status.lamp2_status = 0;
  1937. }
  1938. else if ((difftime(mktime(&nowtime), mktime(&starttime)+3600) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+7200)<0)) {
  1939. LOG_I("3led:21~22");
  1940. device_status.lamp1_status = 1;
  1941. device_status.lamp_status = 0;
  1942. device_status.lamp2_status = 0;
  1943. }
  1944. else if ((difftime(mktime(&nowtime), mktime(&starttime)+7200) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+10800)<0)) {
  1945. LOG_I("3led:22~23");
  1946. device_status.lamp2_status = 1;
  1947. device_status.lamp_status = 0;
  1948. device_status.lamp1_status =0;
  1949. }
  1950. #endif
  1951. }
  1952. //如果结束时间是第二天
  1953. else if (device_status.startBar>device_status.stopBar) {
  1954. time_t now;
  1955. time(&now);
  1956. static struct tm nowtime; //现在
  1957. static struct tm starttime; //开始
  1958. static struct tm endtime; //结束
  1959. //获取当前时间戳
  1960. nowtime =*localtime(&now);
  1961. nowtime.tm_hour = nowtime.tm_hour-8;
  1962. //获取定时开始的时间戳
  1963. starttime = *localtime(&now);
  1964. starttime.tm_hour = device_status.startBar-8;
  1965. starttime.tm_min = 0;
  1966. starttime.tm_sec = 0;
  1967. //获取定时结束的时间戳
  1968. endtime = *localtime(&now);
  1969. endtime.tm_hour = device_status.stopBar-8;
  1970. endtime.tm_min = 0;
  1971. endtime.tm_sec = 0;
  1972. LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
  1973. //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
  1974. if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
  1975. {
  1976. //获取定时结束的时间戳
  1977. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1978. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1979. endtime.tm_min = 0;
  1980. endtime.tm_sec = 0;
  1981. device_status.work_status = 1;
  1982. LOG_I("当前前时间大于开始时间,且没有开始工作");
  1983. }
  1984. //当前时间小于开始时间
  1985. else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
  1986. {
  1987. //获取定时结束的时间戳
  1988. endtime = *localtime(&now); //将获取到的时间转换为时间戳
  1989. endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
  1990. endtime.tm_min = 0;
  1991. endtime.tm_sec = 0;
  1992. //如果当前时间戳小于结束时间戳
  1993. if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
  1994. {
  1995. LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
  1996. device_status.work_status = 1;
  1997. }
  1998. else
  1999. {
  2000. LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
  2001. device_status.work_status = 0; //不在工作时间,待机
  2002. }
  2003. }
  2004. }
  2005. }
  2006. else {
  2007. LOG_I("光控定时模式!");
  2008. /*
  2009. time_t now;
  2010. time(&now);
  2011. static struct tm nowstamp;
  2012. nowstamp =*localtime(&now);
  2013. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  2014. static rt_uint32_t nowstamp_num = 0;
  2015. nowstamp_num = mktime(&nowstamp);
  2016. rt_kprintf("now stamp:%d\n",nowstamp_num);
  2017. */
  2018. if(device_status.sun_status==0&&device_status.light_over_tim!=0)
  2019. {
  2020. device_status.light_over_tim--;
  2021. light_timeout = 3600;
  2022. #if LAMP_EN == 1
  2023. Led_Check(device_status.sunBar);
  2024. #else
  2025. device_status.work_status = 1;;
  2026. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  2027. #endif
  2028. }
  2029. else
  2030. {
  2031. light_timeout --;
  2032. //没有在测试并且没有在自检
  2033. if(device_status.test_flag==0&&device_status.selfcheck_ws==0)
  2034. {
  2035. ctr_lamp(OFF,1);
  2036. #if LAMP_EN == 1
  2037. ctr_lamp(OFF,2);
  2038. ctr_lamp(OFF,3);
  2039. #endif
  2040. }
  2041. device_status.work_status = 0;
  2042. if(light_timeout==0) device_status.light_over_tim=0;
  2043. if(device_status.light_over_tim==0&&device_status.sun_status==1) device_status.light_over_tim = device_status.sunBar * 3600;
  2044. LOG_I("光控中,白天:%d!!!",device_status.sun_status);
  2045. }
  2046. }
  2047. rt_thread_delay(1000);
  2048. }
  2049. LOG_I("雨控状态,温控状态,电压状态:%d-%d-%d",device_status.rain_status,device_status.temp_status,device_status.bat_status);
  2050. device_status.work_status = 0;
  2051. rt_thread_delay(1000);
  2052. }
  2053. #endif
  2054. void WorkCheck(void)
  2055. {
  2056. static rt_uint32_t light_timeout = 3600;
  2057. while(device_status.ds == 1 &&
  2058. device_status.rain_status == 0 &&
  2059. device_status.temp_status == 0 &&
  2060. device_status.bat_status == 0)
  2061. {
  2062. if(device_status.timeSwitch == 1) // 时控模式
  2063. {
  2064. LOG_I("***********时控*****************");
  2065. if(device_status.startBar == device_status.stopBar)
  2066. {
  2067. // 开始结束时间相同则24小时模式
  2068. device_status.work_status = 1;
  2069. rt_thread_delay(10000);
  2070. continue;
  2071. }
  2072. time_t now;
  2073. time(&now);
  2074. struct tm now_tm = *localtime(&now);
  2075. rt_uint32_t curr_sec = now_tm.tm_hour*3600 + now_tm.tm_min*60 + now_tm.tm_sec;
  2076. rt_uint32_t start_sec = device_status.startBar * 3600;
  2077. rt_uint32_t end_sec = device_status.stopBar * 3600;
  2078. // 修复跨天判断逻辑
  2079. if (start_sec < end_sec)
  2080. {
  2081. // 不跨天模式
  2082. device_status.work_status = (curr_sec >= start_sec && curr_sec < end_sec) ? 1 : 0;
  2083. }
  2084. else
  2085. {
  2086. // 跨天模式
  2087. device_status.work_status = (curr_sec >= start_sec || curr_sec < end_sec) ? 1 : 0;
  2088. }
  2089. LOG_I("时控模式:状态[%s] 当前时间:%02d:%02d:%02d 设置:%02d:00-%02d:00",
  2090. device_status.work_status ? "工作" : "待机",
  2091. now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
  2092. device_status.startBar, device_status.stopBar);
  2093. rt_thread_delay(10000);
  2094. }
  2095. else // 光控模式
  2096. {
  2097. LOG_I("光控定时模式!");
  2098. if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
  2099. {
  2100. device_status.light_over_tim--;
  2101. light_timeout = 3600; // 重置超时计数器
  2102. device_status.work_status = 1;
  2103. LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
  2104. }
  2105. else
  2106. {
  2107. // 仅在白天递减超时计数器
  2108. if(device_status.sun_status == 1 && light_timeout > 0) {
  2109. light_timeout--;
  2110. }
  2111. device_status.work_status = 0;
  2112. //没有在测试并且没有在自检
  2113. if(device_status.test_flag==0 && device_status.selfcheck_ws==0)
  2114. {
  2115. ctr_lamp(OFF,1);
  2116. }
  2117. // 连续1小时白天后重置
  2118. if(light_timeout == 0) {
  2119. device_status.light_over_tim = 0;
  2120. light_timeout = 3600; // 重置防止负数
  2121. }
  2122. // 白天且倒计时结束:重置夜晚时长
  2123. if(device_status.light_over_tim == 0 &&
  2124. device_status.sun_status == 1)
  2125. {
  2126. device_status.light_over_tim = device_status.sunBar * 3600;
  2127. }
  2128. }
  2129. }
  2130. rt_thread_delay(1000);
  2131. }
  2132. // 异常状态处理
  2133. device_status.work_status = 0;
  2134. rt_thread_delay(1000);
  2135. }
  2136. void WorkTask_BZY(void)
  2137. {
  2138. if(device_status.ds==1)
  2139. {
  2140. //时间段判断
  2141. //先判断第一个时间段
  2142. time_t now;
  2143. time(&now);
  2144. static struct tm now_stamp; //现在
  2145. static struct tm cul_sh1_stamp; //开始1
  2146. static struct tm cul_eh1_stamp; //结束1
  2147. static struct tm cul_sh2_stamp; //开始2
  2148. static struct tm cul_eh2_stamp; //结束2
  2149. static struct tm cul_sh3_stamp; //开始3
  2150. static struct tm cul_eh3_stamp; //结束3
  2151. now_stamp = *localtime(&now);
  2152. //获取定时开始的时间戳
  2153. cul_sh1_stamp = *localtime(&now);
  2154. cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2155. cul_sh1_stamp.tm_min = 0;
  2156. cul_sh1_stamp.tm_sec = 0;
  2157. cul_sh2_stamp = *localtime(&now);
  2158. cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2159. cul_sh2_stamp.tm_min = 0;
  2160. cul_sh2_stamp.tm_sec = 0;
  2161. cul_sh3_stamp = *localtime(&now);
  2162. cul_sh3_stamp.tm_hour = device_status.collecting_sh3;
  2163. cul_sh3_stamp.tm_min = 0;
  2164. cul_sh3_stamp.tm_sec = 0;
  2165. //获取定时结束的时间戳
  2166. cul_eh1_stamp = *localtime(&now);
  2167. cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2168. cul_eh1_stamp.tm_min = 0;
  2169. cul_eh1_stamp.tm_sec = 0;
  2170. cul_eh2_stamp = *localtime(&now);
  2171. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2172. cul_eh2_stamp.tm_min = 0;
  2173. cul_eh2_stamp.tm_sec = 0;
  2174. cul_eh3_stamp = *localtime(&now);
  2175. cul_eh3_stamp.tm_hour = device_status.collecting_eh3;
  2176. cul_eh3_stamp.tm_min = 0;
  2177. cul_eh3_stamp.tm_sec = 0;
  2178. LOG_I("采集时间1-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_sh1_stamp.tm_year+1900,cul_sh1_stamp.tm_mon+1,cul_sh1_stamp.tm_mday,cul_sh1_stamp.tm_hour,cul_sh1_stamp.tm_min,cul_sh1_stamp.tm_sec);
  2179. LOG_I("采集时间2-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_sh2_stamp.tm_year+1900,cul_sh2_stamp.tm_mon+1,cul_sh2_stamp.tm_mday,cul_sh2_stamp.tm_hour,cul_sh2_stamp.tm_min,cul_sh2_stamp.tm_sec);
  2180. LOG_I("采集时间3-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_sh3_stamp.tm_year+1900,cul_sh3_stamp.tm_mon+1,cul_sh3_stamp.tm_mday,cul_sh3_stamp.tm_hour,cul_sh3_stamp.tm_min,cul_sh3_stamp.tm_sec);
  2181. LOG_I("结束时间1-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_eh1_stamp.tm_year+1900,cul_eh1_stamp.tm_mon+1,cul_eh1_stamp.tm_mday,cul_eh1_stamp.tm_hour,cul_eh1_stamp.tm_min,cul_eh1_stamp.tm_sec);
  2182. LOG_I("结束时间2-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_eh2_stamp.tm_year+1900,cul_eh2_stamp.tm_mon+1,cul_eh2_stamp.tm_mday,cul_eh2_stamp.tm_hour,cul_eh2_stamp.tm_min,cul_eh2_stamp.tm_sec);
  2183. LOG_I("结束时间3-%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_eh3_stamp.tm_year+1900,cul_eh3_stamp.tm_mon+1,cul_eh3_stamp.tm_mday,cul_eh3_stamp.tm_hour,cul_eh3_stamp.tm_min,cul_eh3_stamp.tm_sec);
  2184. //此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
  2185. //当前时间戳小于第一段开始时间戳
  2186. if(difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
  2187. {
  2188. time_t now;
  2189. time(&now);
  2190. cul_sh1_stamp = *localtime(&now);
  2191. cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2192. cul_sh1_stamp.tm_min = 0;
  2193. cul_sh1_stamp.tm_sec = 0;
  2194. now_stamp = *localtime(&now);
  2195. LOG_I("======收集时间1:%04d年%02d月%02d日%02d时%02d分%02d秒.",cul_sh1_stamp.tm_year+1900,cul_sh1_stamp.tm_mon+1,cul_sh1_stamp.tm_mday,cul_sh1_stamp.tm_hour,cul_sh1_stamp.tm_min,cul_sh1_stamp.tm_sec);
  2196. LOG_I("======未到收集时间1:%04d年%02d月%02d日%02d时%02d分%02d秒.",now_stamp.tm_year+1900,now_stamp.tm_mon+1,now_stamp.tm_mday,now_stamp.tm_hour,now_stamp.tm_min,now_stamp.tm_sec);
  2197. LOG_D("run_sta:%d",device_status.run_sta);
  2198. }
  2199. //当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
  2200. if(difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0&&difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
  2201. {
  2202. time_t now;
  2203. time(&now);
  2204. cul_sh2_stamp = *localtime(&now);
  2205. cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2206. cul_sh2_stamp.tm_min = 0;
  2207. cul_sh2_stamp.tm_sec = 0;
  2208. now_stamp = *localtime(&now);
  2209. LOG_I("==============收集时间2:%04d年%02d月%02d日%02d时%02d分%02d秒.\n",cul_sh2_stamp.tm_year+1900,cul_sh2_stamp.tm_mon+1,cul_sh2_stamp.tm_mday,cul_sh2_stamp.tm_hour,cul_sh2_stamp.tm_min,cul_sh2_stamp.tm_sec);
  2210. LOG_I("==============未到收集时间2:%04d年%02d月%02d日%02d时%02d分%02d秒.\n",now_stamp.tm_year+1900,now_stamp.tm_mon+1,now_stamp.tm_mday,now_stamp.tm_hour,now_stamp.tm_min,now_stamp.tm_sec);
  2211. LOG_D("run_sta:%d",device_status.run_sta);
  2212. }
  2213. //如果当前 时间戳大于开始时间戳并且小于 结束时间戳
  2214. if(difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0&&difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
  2215. {
  2216. //转盘到涂凡士林位置
  2217. if(device_status.run_sta==0)
  2218. {
  2219. LOG_I("start to collect!!!");
  2220. DTU_Write("collect.mp3");
  2221. ctr_turn(90,4);
  2222. rt_thread_delay(2000);
  2223. //涂凡士林
  2224. ctr_Petroleum_jelly(10);
  2225. rt_thread_delay(5000);
  2226. }
  2227. /*转盘到采集位置*/
  2228. if(device_status.run_sta==4)
  2229. ctr_turn(90,1);
  2230. //只有开始和结束时刻不同的时间段,才有效
  2231. if((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0)||(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0))
  2232. {
  2233. if((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0)&& difftime(mktime(&now_stamp),mktime(&cul_sh1_stamp)) > 0)
  2234. {
  2235. device_status.work_status = 1;
  2236. ctr_Collect_Fan(ON);
  2237. //当前时间戳小于第一段结束时间戳
  2238. while(difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp))>0)
  2239. {
  2240. time(&now);
  2241. now_stamp = *localtime(&now);
  2242. cul_eh1_stamp = *localtime(&now);
  2243. cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2244. cul_eh1_stamp.tm_min = 0;
  2245. cul_eh1_stamp.tm_sec = 0;
  2246. if(device_status.run_sta!=1) break;
  2247. LOG_I("1===========采集风机启动,正在收集.....%d-%d",mktime(&now_stamp),mktime(&cul_eh1_stamp));
  2248. rt_thread_mdelay(10000);
  2249. }
  2250. }
  2251. else {
  2252. device_status.work_status=0;
  2253. ctr_Collect_Fan(OFF);
  2254. LOG_I("未到收集1时间!");
  2255. }
  2256. if(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0 && difftime(mktime(&now_stamp),mktime(&cul_sh2_stamp)) > 0)
  2257. {
  2258. device_status.work_status = 1;
  2259. ctr_Collect_Fan(ON);
  2260. while(difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp))>0)
  2261. {
  2262. time(&now);
  2263. now_stamp = *localtime(&now);
  2264. cul_eh2_stamp = *localtime(&now);
  2265. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2266. cul_eh2_stamp.tm_min = 0;
  2267. cul_eh2_stamp.tm_sec = 0;
  2268. if(device_status.run_sta!=1) break;
  2269. LOG_I("2===========采集风机启动,正在收集.....%d-%d",mktime(&now_stamp),mktime(&cul_eh2_stamp));
  2270. rt_thread_mdelay(10000);
  2271. }
  2272. }
  2273. else {
  2274. device_status.work_status=0;
  2275. ctr_Collect_Fan(OFF);
  2276. LOG_I("未到收集2时间!");
  2277. }
  2278. }
  2279. else
  2280. {
  2281. LOG_I("this collect time is 0s,The wait time cannot be negative!");
  2282. }
  2283. }
  2284. if(device_status.run_sta==2)
  2285. {
  2286. ctr_Collect_Fan(OFF);
  2287. device_status.develop_flag = 1;
  2288. device_status.work_status = 2;
  2289. ctr_develop(); //培养
  2290. ctr_turn(90,3);
  2291. }
  2292. if(device_status.run_sta==3)
  2293. {
  2294. ctr_Collect_Fan(OFF);
  2295. device_status.work_status = 3;
  2296. device_status.autotakepic=1; //对焦拍照
  2297. }
  2298. //在培养之前再次确认时间戳
  2299. time(&now);
  2300. now_stamp = *localtime(&now);
  2301. cul_eh2_stamp = *localtime(&now);
  2302. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2303. cul_eh2_stamp.tm_min = 0;
  2304. cul_eh2_stamp.tm_sec = 0;
  2305. //当前时间戳大于收集结束时间戳并且run_sta==1
  2306. if(device_status.run_sta==1 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) > 0)
  2307. {
  2308. ctr_Collect_Fan(OFF);
  2309. LOG_I("===============collect ok,turn to drop!!!");
  2310. device_status.develop_flag=1;
  2311. device_status.work_status=2; //现在是培养
  2312. DTU_Write("develop.mp3");
  2313. if(device_status.run_sta==1)
  2314. ctr_turn(90,2); /*转盘到培养位置*/
  2315. rt_thread_delay(1000);
  2316. ctr_shake(ON,device_status.shake_sec);
  2317. rt_thread_delay(1000);
  2318. ctr_develop(); //培养
  2319. if(device_status.run_sta==2)
  2320. ctr_turn(90,3); /*转盘到拍照位置*/
  2321. rt_thread_delay(1000);
  2322. device_status.work_status=3; //现在是拍照
  2323. device_status.autotakepic=1; //对焦拍照
  2324. while(device_status.autotakepic==0)
  2325. {
  2326. rt_thread_delay(1000);
  2327. LOG_I("正在对焦拍照............");
  2328. }
  2329. device_status.work_status = 0; //待机
  2330. DTU_Write("wait.mp3");
  2331. LOG_I("=====================work finished==================");
  2332. }
  2333. rt_thread_delay(1000);
  2334. }
  2335. device_status.work_status = 0; //待机
  2336. LOG_W("==================!!!设备已待机!!!===================");
  2337. }
  2338. void WorkTask_BZYV2(void)
  2339. {
  2340. //打开采集风机
  2341. ctr_Collect_Fan(ON);
  2342. //打开胶带步进电机
  2343. //等待采集结束
  2344. //拍照
  2345. //打开相机供电
  2346. //打开补光灯
  2347. //滑台归位
  2348. //滑台启动
  2349. }
  2350. //工作任务流程s
  2351. void WorkTask(void)
  2352. {
  2353. static int clt_time = 0; //收集时间差秒数
  2354. static int heat_time = 0;
  2355. static uint8_t workloop = 0;
  2356. LOG_I("工作状态:%d",device_status.work_status);
  2357. LOG_I("开关机状态:%d",device_status.ds);
  2358. 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)
  2359. {
  2360. workloop++;
  2361. device_status.work_done = 0;
  2362. if(clt_time==0)
  2363. {
  2364. #if 0
  2365. if(device_status.version_type==41&&atoi(device_status.power)<350)
  2366. {
  2367. LOG_W("相机电流不足!");
  2368. char *ctr_hk_p_warn = makeJson_Warn("电流不足", "相机");
  2369. DTU_Write("%s",ctr_hk_p_warn);
  2370. rt_free(ctr_hk_p_warn);
  2371. }
  2372. #endif
  2373. #if 0//LAMP_EN == 0
  2374. ctr_Fan_PUT(ON);
  2375. #endif
  2376. DTU_Write("workstart.mp3");
  2377. }
  2378. //1.打开灯管
  2379. #if LAMP_EN == 1
  2380. if(device_status.lamp_status==1&&device_status.sun_status==0) //光控状态不亮灯
  2381. {
  2382. ctr_lamp(ON,1);
  2383. ctr_lamp(OFF,2);
  2384. ctr_lamp(OFF,3);
  2385. }
  2386. else if (device_status.lamp1_status==1&&device_status.sun_status==0) {
  2387. ctr_lamp(OFF,1);
  2388. ctr_lamp(ON,2);
  2389. ctr_lamp(OFF,3);
  2390. }
  2391. else if (device_status.lamp2_status==1&&device_status.sun_status==0) {
  2392. ctr_lamp(OFF,1);
  2393. ctr_lamp(OFF,2);
  2394. ctr_lamp(ON,3);
  2395. }
  2396. #else
  2397. ctr_lamp(ON,1);
  2398. if(device_status.version_type==12)
  2399. {
  2400. ctr_Heat(ON);
  2401. }
  2402. #endif
  2403. LOG_I("打开灯管!!!");
  2404. #if 0
  2405. rt_thread_delay(2000);
  2406. if(atoi(device_status.power)<450)
  2407. {
  2408. LOG_I("Current is:%d",atoi(device_status.power));
  2409. if(atoi(device_status.power)>50&&atoi(device_status.power)<5000) //过滤电流检测芯片损坏导致电流异常
  2410. {
  2411. char* lamp_err_warn = makeJson_Warn("电流不足", "灯管");
  2412. DTU_Write("%s",lamp_err_warn);
  2413. rt_free(lamp_err_warn);
  2414. }
  2415. }
  2416. #endif
  2417. if(device_status.version_type!=5)
  2418. {
  2419. rt_thread_delay(1000); //待灯管启动再往下执行,否则会触发电机过流
  2420. //2.打开上仓门
  2421. LOG_I("打开上仓门!!!");
  2422. device_status.ctr_up_motor = 1;
  2423. //3.收集
  2424. clt_time = device_status.clt_time * 60;
  2425. while(clt_time!=1)
  2426. {
  2427. #if 0//LAMP_EN == 0
  2428. ctr_Fan_IN(ON);
  2429. #endif
  2430. clt_time --;
  2431. rt_thread_delay(1000);
  2432. #if 0//LAMP_EN == 0
  2433. if(clt_time%30==0)
  2434. ctr_Fan_PUT(OFF);
  2435. #endif
  2436. rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
  2437. HMI_WRITE("workSta.g0.txt=\"正在收集.....剩余时间:%d分-%d秒\"",device_status.clt_time,clt_time);
  2438. //如果触发异常
  2439. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  2440. {
  2441. ctr_lamp(OFF,1);
  2442. #if LAMP_EN == 1
  2443. ctr_lamp(OFF,2);
  2444. ctr_lamp(OFF,3);
  2445. #endif
  2446. #if 0//LAMP_EN == 0
  2447. ctr_Fan_IN(OFF);
  2448. #endif
  2449. rt_kprintf("异常退出!!!\n");
  2450. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2451. break;
  2452. }
  2453. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  2454. {
  2455. ctr_lamp(OFF,1);
  2456. #if LAMP_EN == 1
  2457. ctr_lamp(OFF,2);
  2458. ctr_lamp(OFF,3);
  2459. #endif
  2460. #if 0//LAMP_EN == 0
  2461. ctr_Fan_IN(OFF);
  2462. #endif
  2463. rt_kprintf("异常退出!!!\n");
  2464. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2465. break;
  2466. }
  2467. }
  2468. clt_time = 1;
  2469. if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
  2470. {
  2471. ctr_lamp(OFF,1);
  2472. #if LAMP_EN == 1
  2473. ctr_lamp(OFF,2);
  2474. ctr_lamp(OFF,3);
  2475. #endif
  2476. #if 0//LAMP_EN == 0
  2477. ctr_Fan_IN(OFF);
  2478. #endif
  2479. rt_kprintf("异常退出!!!\n");
  2480. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2481. break;
  2482. }
  2483. if(device_status.timeSwitch==0&&device_status.sun_status==1)
  2484. {
  2485. ctr_lamp(OFF,1);
  2486. #if LAMP_EN == 1
  2487. ctr_lamp(OFF,2);
  2488. ctr_lamp(OFF,3);
  2489. #endif
  2490. #if 0//LAMP_EN == 0
  2491. ctr_Fan_IN(OFF);
  2492. #endif
  2493. rt_kprintf("异常退出!!!\n");
  2494. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  2495. break;
  2496. }
  2497. #if 0//LAMP_EN == 0
  2498. ctr_Fan_IN(OFF);
  2499. #endif
  2500. //4.关闭上仓门
  2501. device_status.ctr_up_motor = 2;
  2502. rt_kprintf("关闭上仓门!!!\n");
  2503. HMI_WRITE("workSta.g0.txt=\"关闭上仓门!\"");
  2504. while(device_status.ctr_up_motor!=0)
  2505. {
  2506. rt_thread_delay(100);
  2507. LOG_I("等待上仓门关闭!!!");
  2508. }
  2509. //5.加热
  2510. if(device_status.heat_sw==0&&device_status.version_type!=12)
  2511. {
  2512. calorstat(device_status.heattime*60);
  2513. }
  2514. else {
  2515. heat_time = device_status.heattime * 60;
  2516. while(heat_time!=0)
  2517. {
  2518. heat_time--;
  2519. LOG_I("正在加热状态!!!");
  2520. rt_thread_delay(1000);
  2521. }
  2522. }
  2523. //6.打开下仓门
  2524. if(device_status.rain_status==0)
  2525. {
  2526. uint16_t cnt_photo = 0;
  2527. while(device_status.photo_ws==1) //如果正在拍照,要等拍照结束
  2528. {
  2529. rt_thread_delay(1000);
  2530. cnt_photo++;
  2531. if(cnt_photo>=60) break;
  2532. }
  2533. device_status.ctr_down_motor =1;
  2534. }
  2535. else {
  2536. device_status.ctr_down_motor = 2;
  2537. device_status.ctr_up_motor = 2;
  2538. }
  2539. //待下仓门完全打开
  2540. while(device_status.ctr_down_motor!=0)
  2541. {
  2542. rt_thread_delay(100);
  2543. rt_kprintf("等待下仓门打开!!!\n");
  2544. HMI_WRITE("workSta.g0.txt=\"等待下仓门打开!\"");
  2545. }
  2546. rt_thread_delay(3000);
  2547. //关闭下仓门
  2548. device_status.ctr_down_motor = 2;
  2549. while(device_status.ctr_down_motor!=0)
  2550. {
  2551. rt_thread_delay(100);
  2552. rt_kprintf("等待下仓门关闭!!!\n");
  2553. HMI_WRITE("workSta.g0.txt=\"等待下仓门关闭!\"");
  2554. }
  2555. //2022-04-12add:
  2556. LOG_I("打开上仓门!!!");
  2557. HMI_WRITE("workSta.g0.txt=\"打开上仓门!\"");
  2558. if(device_status.rain_status==0)
  2559. {
  2560. device_status.ctr_up_motor = 1;
  2561. }
  2562. if(device_status.version_type==4||
  2563. device_status.version_type==41||
  2564. device_status.version_type==42||
  2565. device_status.version_type==43||
  2566. device_status.version_type==12)
  2567. {
  2568. //震动
  2569. ctr_shake(ON, device_status.shake_sec);
  2570. device_status.photo_ws = 1;
  2571. }
  2572. #if DZ_260519 == 1
  2573. if(workloop==3&&device_status.clt_time==10&&device_status.heattime==10){
  2574. workloop = 0;
  2575. device_status.clear_status = 2;
  2576. }
  2577. #endif
  2578. }
  2579. }
  2580. if(device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status==1 || device_status.ds==0)
  2581. {
  2582. rt_kprintf("-------------------not work--------------------\n");
  2583. device_status.work_status = 0;
  2584. }
  2585. //工作结束
  2586. if(device_status.work_done==0&&device_status.work_status==0)
  2587. {
  2588. DTU_Write("workdone");
  2589. HMI_WRITE("workSta.g0.txt=\"工作任务已完成!\"");
  2590. ResetInit();
  2591. clt_time = 0;
  2592. upload_sys_monitor_info();
  2593. }
  2594. rt_kprintf("***not work-device status:%d\n",device_status.ds);
  2595. }
  2596. /* 入口函数-工作状态检测 */
  2597. static void Work_status_thread_entry(void *parameter)
  2598. {
  2599. static uint16_t sun_status_num = 120;
  2600. //如果是光控定时,进行光控监测的消抖
  2601. if(device_status.timeSwitch==0&&device_status.sun_status==0)
  2602. {
  2603. rt_kprintf("光控定时!!!\n");
  2604. while(sun_status_num!=0)
  2605. {
  2606. sun_status_num--;
  2607. rt_thread_delay(1000);
  2608. rt_kprintf("开机光控检测:%d\n",sun_status_num);
  2609. }
  2610. device_status.light_over_tim = device_status.sunBar * 3600;
  2611. device_status.test_flag = 0;
  2612. }
  2613. while(1)
  2614. {
  2615. WorkCheck();
  2616. }
  2617. }
  2618. /*入口函数-工作流程*/
  2619. static void Work_Loop_thread_entry(void *parameter)
  2620. {
  2621. rt_thread_delay(1000);
  2622. ResetInit();
  2623. while(1)
  2624. {
  2625. if(device_status.dtype==7)
  2626. {
  2627. WorkTask_BZY();
  2628. }
  2629. if(device_status.version_type!=6&&device_status.dtype==3)
  2630. {
  2631. WorkTask();
  2632. }
  2633. if(device_status.version_type==6)
  2634. {
  2635. WorkTask_XCT();
  2636. }
  2637. rt_thread_delay(1000);
  2638. }
  2639. }
  2640. /*入口函数清扫*/
  2641. static void Control_Clear_thread_entry(void *parameter)
  2642. {
  2643. static int selfcheck_cnt = 0;
  2644. float voltage_f = 0.0;
  2645. while(1)
  2646. {
  2647. #if ROBOT_EN ==1
  2648. ctr_Motor_Robot(ON);
  2649. rt_thread_delay(100);
  2650. #else
  2651. #if Color_EN ==1
  2652. /*复位*/
  2653. if(Read_Color_Key(KEY_RESET)==1)
  2654. {
  2655. ctr_Color_board(RESET, 1200);
  2656. rt_thread_delay(5000);
  2657. }
  2658. #else
  2659. if(device_status.selfcheck_ws==1){
  2660. selfcheck_cnt ++;
  2661. if(selfcheck_cnt==1){
  2662. ctr_lamp(ON,1);
  2663. rt_thread_delay(1000);
  2664. device_status.ctr_up_motor = 1;
  2665. device_status.ctr_down_motor = 1;
  2666. //记录当前电压
  2667. voltage_f = atof(device_status.voltage);
  2668. rt_thread_delay(1500);
  2669. //开启加热
  2670. ctr_Heat(ON);
  2671. }
  2672. if(selfcheck_cnt==50){
  2673. double voltage_n = atof(device_status.voltage);
  2674. //判断当前电压和加热前的电压差
  2675. if(voltage_f-voltage_n<0.5){
  2676. device_status.heat_sta = 1; //加热异常
  2677. //上报预警,加热故障
  2678. char *heat_warn = makeJson_Warn("加热报警", "heat-error");
  2679. DTU_Write("%s", heat_warn);
  2680. rt_free(heat_warn);
  2681. }else{
  2682. device_status.heat_sta = 0;
  2683. }
  2684. rt_thread_delay(1000);
  2685. //关闭加热
  2686. ctr_Heat(OFF);
  2687. //振动
  2688. ctr_shake(ON, 1);
  2689. //device_status.clear_status = 1;
  2690. ctr_lamp(OFF, 1);
  2691. }
  2692. if(selfcheck_cnt>1800){ //超过3分钟
  2693. device_status.selfcheck_ws = 0;
  2694. device_status.ctr_up_motor = 0;
  2695. device_status.ctr_down_motor = 0;
  2696. //
  2697. device_status.camsta = 1; //相机异常
  2698. device_status.led_sta = 1;
  2699. //上报自检结果
  2700. //上报自检结果
  2701. char *json_temp = makeJson_selfCheck_(1);
  2702. DTU_Write("%s",json_temp);
  2703. free(json_temp);
  2704. }
  2705. }
  2706. if(device_status.selfcheck_ws==0){
  2707. selfcheck_cnt = 0;
  2708. }
  2709. if(device_status.clear_status==1)
  2710. {
  2711. ///if(ctr_clear(1200)==0)
  2712. ctr_TG_Clear(500); //2025-1021,由400修改为500,解决金朵推杆慢导致行程走不完
  2713. system_status.cleaning_count +=1; //清扫次数
  2714. }
  2715. if(device_status.clear_status==2){
  2716. turnzp();
  2717. device_status.clear_status=0;
  2718. }
  2719. rt_thread_delay(100);
  2720. #endif
  2721. #endif
  2722. }
  2723. }
  2724. /*入口函数加热*/
  2725. static void Control_Heat_thread_entry(void *parameter)
  2726. {
  2727. while(1)
  2728. {
  2729. if(device_status.work_status==1&&device_status.heat_sw==1)
  2730. {
  2731. calorstat(device_status.heattime*60);
  2732. rt_thread_delay(10000);
  2733. }
  2734. else
  2735. {
  2736. LOG_I("Not calorstat!%d",device_status.selfcheck_ws);
  2737. if(device_status.selfcheck_ws==2)
  2738. {
  2739. static int total_seconds = 200;
  2740. static int current_second = 0;
  2741. while(current_second <= total_seconds)
  2742. {
  2743. int process = (current_second * 100) / total_seconds;
  2744. device_status.process = process / 100.0;
  2745. LOG_I("process:%d",process);
  2746. HMI_WRITE("selfcheck.s106.val=%d",process);
  2747. rt_thread_delay(1000);
  2748. current_second++;
  2749. if(device_status.selfcheck_ws==0)
  2750. {
  2751. HMI_WRITE("selfcheck.s106.val=100");
  2752. break;
  2753. }
  2754. }
  2755. HMI_WRITE("selfcheck.s106.val=100");
  2756. }
  2757. }
  2758. rt_thread_delay(1000);
  2759. }
  2760. }
  2761. /*清扫线程*/
  2762. int Control_clear(void)
  2763. {
  2764. /* 创建线程*/
  2765. tid_ctr = rt_thread_create("Control_Clear_thread_entry",
  2766. Control_Clear_thread_entry, RT_NULL,
  2767. 2048, //2048
  2768. 24, //23
  2769. WORK_CHECK_THREAD_TIMESLICE); //5
  2770. if(tid_ctr!=RT_NULL)
  2771. {
  2772. rt_thread_startup(tid_ctr);
  2773. }
  2774. return 0;
  2775. }
  2776. /*恒温加热线程*/
  2777. int Control_heat(void)
  2778. {
  2779. /* 创建线程*/
  2780. tid_heat = rt_thread_create("Control_Heat_thread_entry",
  2781. Control_Heat_thread_entry, RT_NULL,
  2782. 1024, //2048
  2783. 25, //23
  2784. WORK_CHECK_THREAD_TIMESLICE); //5
  2785. if(tid_heat!=RT_NULL)
  2786. {
  2787. rt_thread_startup(tid_heat);
  2788. }
  2789. return 0;
  2790. }
  2791. /* 创建线程 -工作状态检测*/
  2792. int Workstatus_check(void)
  2793. {
  2794. /* 创建线程*/
  2795. tid_wkstc = rt_thread_create("work_status_check_thread",
  2796. Work_status_thread_entry, RT_NULL,
  2797. WORK_CHECK_THREAD_STACK_SIZE, //1024
  2798. WORK_CHECK_THREAD_PRIORITY, //23
  2799. WORK_CHECK_THREAD_TIMESLICE); //5
  2800. if(tid_wkstc!=RT_NULL)
  2801. {
  2802. rt_thread_startup(tid_wkstc);
  2803. }
  2804. return 0;
  2805. }
  2806. /*工作流程线程*/
  2807. int Work_Loop_Task(void)
  2808. {
  2809. /* 创建线程*/
  2810. tid_workloop = rt_thread_create("work_loop_thread",
  2811. Work_Loop_thread_entry, RT_NULL,
  2812. WORK_LOOP_THREAD_STACK_SIZE, //2048
  2813. WORK_LOOP_THREAD_PRIORITY, //12
  2814. WORK_LOOP_THREAD_TIMESLICE); //5
  2815. #if Color_EN == 0
  2816. if(tid_workloop!=RT_NULL)
  2817. {
  2818. rt_thread_startup(tid_workloop);
  2819. }
  2820. #endif
  2821. return 0;
  2822. }
  2823. MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
  2824. MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
  2825. MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
  2826. MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);