control.c 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830
  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. #define DBG_ENABLE
  19. #define DBG_COLOR
  20. #define DBG_TAG "control"
  21. #define DBG_LEVEL DBG_LOG
  22. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  23. // 工作检测
  24. #define WORK_CHECK_THREAD_PRIORITY 23 // 线程优先级
  25. #define WORK_CHECK_THREAD_STACK_SIZE 1024 // 栈大小
  26. #define WORK_CHECK_THREAD_TIMESLICE 5 // 时间片
  27. // 工作流程
  28. #define WORK_LOOP_THREAD_PRIORITY 12 // 线程优先级
  29. #define WORK_LOOP_THREAD_STACK_SIZE 2048 // 栈大小
  30. #define WORK_LOOP_THREAD_TIMESLICE 5 // 时间片
  31. #define PWM_EN 1 // 0关闭,1-打开
  32. #define LOG_INR 10 // 默认的log打印间隔(作用域在本文件)
  33. // 设备状态表结构体
  34. Device_Status_typedef device_status;
  35. rt_thread_t tid_workloop = RT_NULL;
  36. rt_thread_t tid_wkstc = RT_NULL;
  37. rt_thread_t tid_ctr = RT_NULL;
  38. rt_thread_t tid_heat = RT_NULL;
  39. /**************************1.0定制2000W*************************************/
  40. /**
  41. * @brief 控制风扇输出
  42. *
  43. * @param status_ws 开关量
  44. * @return uint8_t -
  45. */
  46. uint8_t ctr_Fan_PUT(uint8_t status_ws)
  47. {
  48. rt_pin_mode(FAN_P, PIN_MODE_OUTPUT);
  49. if (status_ws == ON)
  50. {
  51. rt_pin_write(FAN_P, ON);
  52. }
  53. else
  54. {
  55. rt_pin_write(FAN_P, OFF);
  56. }
  57. return 0;
  58. }
  59. /**
  60. * @brief 控制风扇输出
  61. *
  62. * @param status_ws 开关量
  63. * @return uint8_t -
  64. */
  65. uint8_t ctr_Fan_IN(uint8_t status_ws)
  66. {
  67. rt_pin_mode(FAN_I, PIN_MODE_OUTPUT);
  68. if (status_ws == ON)
  69. {
  70. rt_pin_write(FAN_I, ON);
  71. }
  72. else
  73. {
  74. rt_pin_write(FAN_I, OFF);
  75. }
  76. return 0;
  77. }
  78. /****************************定制色诱*************************************/
  79. /**/
  80. #if Color_EN == 1
  81. /**
  82. * @brief 检测色诱按键是否有下降沿出现
  83. *
  84. * @param key_pin 引脚号
  85. * @return uint8_t 无意义
  86. */
  87. uint8_t Read_Color_Key(rt_base_t key_pin)
  88. {
  89. rt_uint32_t sta_s = 0;
  90. rt_pin_mode(key_pin, PIN_MODE_INPUT);
  91. while (rt_pin_read(key_pin) == 1)
  92. {
  93. sta_s++;
  94. /*持续的*/
  95. rt_thread_delay(50);
  96. }
  97. while (rt_pin_read(key_pin) == 0)
  98. {
  99. rt_thread_delay(50);
  100. if (sta_s > 0)
  101. break;
  102. }
  103. LOG_W("检测到IO0翻转!!!");
  104. return 1;
  105. }
  106. /*读限位开关状态*/
  107. /**
  108. * @brief 读取限位开关的状态
  109. *
  110. * @param pin_limit 引脚号
  111. * @return uint8_t 读取结果
  112. */
  113. uint8_t Read_Color_Limit(rt_base_t pin_limit)
  114. {
  115. uint8_t l_sta = 0;
  116. rt_pin_mode(pin_limit, PIN_MODE_INPUT);
  117. l_sta = rt_pin_read(pin_limit);
  118. rt_thread_delay(20);
  119. l_sta = rt_pin_read(pin_limit);
  120. return l_sta;
  121. }
  122. /*色诱板*/
  123. /**
  124. * @brief 色诱板的控制逻辑
  125. *
  126. * @param forward 下一步进行的动作
  127. * @param time_board 计数?
  128. * @return int 操作完成的动作
  129. */
  130. int ctr_Color_board(uint8_t forward, uint16_t time_board)
  131. {
  132. if (forward == CLOSE) // 归位
  133. {
  134. if (device_status.cul_time > 0)
  135. device_status.cul_time--;
  136. ctr_cangmen_down(OFF);
  137. ctr_cangmen_up(OFF);
  138. rt_thread_delay(1000);
  139. // if(device_status.cul_time>7) device_status.cul_time=7;
  140. // if(device_status.cul_time!=7)
  141. // {
  142. // uint8_t ct = device_status.cul_time;
  143. // while(1)
  144. // {
  145. // Beep_Tip(100);
  146. // rt_thread_delay(100);
  147. // ct--;
  148. // if(ct==0) break;
  149. // }
  150. // //return device_status.cul_time;
  151. // }
  152. if (Read_Color_Limit(LIMIT_RESET) == 0)
  153. {
  154. device_status.cul_time = 0;
  155. LOG_W("已在初始位置!");
  156. Beep_Tip(1000);
  157. return 0;
  158. // 黄板已经在复位状态,直接返回0;
  159. }
  160. ctr_cangmen_up(CLOSE);
  161. rt_thread_delay(20000);
  162. ctr_cangmen_up(OFF);
  163. // if(device_status.cul_time==7&&Read_Color_Limit(LIMIT_BOARD)==0)
  164. // {
  165. // LOG_W("第七天!!!");
  166. // ctr_cangmen_down(CLOSE);
  167. // rt_thread_delay(500);
  168. // }
  169. LOG_W("先打开运行到限位的右侧!");
  170. while (Read_Color_Limit(LIMIT_BOARD) == 0)
  171. {
  172. LOG_W("归位:到达限位中间");
  173. ctr_cangmen_down(CLOSE);
  174. if (Read_Color_Limit(LIMIT_RESET) == 0)
  175. {
  176. ctr_cangmen_down(OFF);
  177. break;
  178. }
  179. }
  180. // 先打开运行到限位的右侧
  181. while (Read_Color_Limit(LIMIT_BOARD) == 1)
  182. {
  183. LOG_W("归位:运行!");
  184. ctr_cangmen_down(CLOSE);
  185. if (Read_Color_Limit(LIMIT_RESET) == 0)
  186. {
  187. ctr_cangmen_down(OFF);
  188. break;
  189. }
  190. }
  191. while (Read_Color_Limit(LIMIT_BOARD) == 0) // 到达限位中间 继续运行
  192. {
  193. LOG_W("归位:到达限位中间");
  194. ctr_cangmen_down(CLOSE);
  195. if (Read_Color_Limit(LIMIT_RESET) == 0)
  196. {
  197. ctr_cangmen_down(OFF);
  198. break;
  199. }
  200. }
  201. if (Read_Color_Limit(LIMIT_RESET) == 0)
  202. return 0;
  203. LOG_W("到达限位左侧!");
  204. // 停止电机
  205. ctr_cangmen_down(OFF);
  206. rt_thread_delay(2000);
  207. // 将推杆电机归位
  208. LOG_D("*推杆电机归位*");
  209. /*推杆电机伸出*/
  210. ctr_cangmen_up(OPEN);
  211. rt_thread_delay(20000);
  212. ctr_cangmen_up(OFF);
  213. return 2;
  214. }
  215. else if (forward == OPEN)
  216. {
  217. ctr_cangmen_down(OFF);
  218. ctr_cangmen_up(OFF);
  219. rt_thread_delay(1000);
  220. if (device_status.cul_time == 7)
  221. {
  222. Beep_Tip(5000);
  223. return 7;
  224. }
  225. LOG_W("打开推杆电机!");
  226. // 2023-04-18:add
  227. // if(Read_Color_Limit(LIMIT_BOARD)==0)
  228. {
  229. LOG_D("*推杆电机归位*");
  230. /*推杆电机归位*/
  231. ctr_cangmen_up(CLOSE);
  232. rt_thread_delay(20000);
  233. ctr_cangmen_up(OFF);
  234. }
  235. if (device_status.cul_time < 7)
  236. device_status.cul_time++;
  237. while (Read_Color_Limit(LIMIT_BOARD) == 0)
  238. {
  239. ctr_cangmen_down(forward);
  240. rt_thread_delay(50);
  241. }
  242. while (Read_Color_Limit(LIMIT_BOARD) == 1)
  243. {
  244. time_board--;
  245. if (time_board == 0)
  246. break;
  247. ctr_cangmen_down(forward);
  248. rt_thread_delay(50);
  249. }
  250. ctr_cangmen_down(OFF);
  251. rt_thread_delay(1000);
  252. ctr_cangmen_up(OPEN);
  253. rt_thread_delay(20000);
  254. ctr_cangmen_up(OFF);
  255. // ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  256. return OPEN;
  257. }
  258. else if (forward == RESET)
  259. {
  260. ctr_cangmen_up(OFF);
  261. ctr_cangmen_down(OFF);
  262. if (Read_Color_Limit(LIMIT_RESET) == 0)
  263. {
  264. device_status.cul_time = 0;
  265. // ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  266. LOG_W("已在初始位置!");
  267. Beep_Tip(1000);
  268. ctr_cangmen_up(CLOSE);
  269. rt_thread_delay(20000);
  270. ctr_cangmen_up(OFF);
  271. device_status.cul_time = 0;
  272. return 0;
  273. // 黄板已经在复位状态,直接返回0;
  274. }
  275. // if(Read_Color_Limit(LIMIT_BOARD)==0)
  276. {
  277. LOG_D("*推杆电机归位*");
  278. /*推杆电机归位*/
  279. ctr_cangmen_up(CLOSE);
  280. rt_thread_delay(20000);
  281. ctr_cangmen_up(OFF);
  282. }
  283. while (Read_Color_Limit(LIMIT_RESET) == 1)
  284. {
  285. time_board--;
  286. if (time_board == 0)
  287. break;
  288. ctr_cangmen_down(CLOSE);
  289. rt_thread_delay(20);
  290. }
  291. device_status.cul_time = 0;
  292. ctr_cangmen_down(OFF);
  293. }
  294. // device_status.cul_time = 0;
  295. // ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  296. return RESET; // 复位返回0
  297. }
  298. #endif
  299. /****************************5.0***********************************/
  300. void ctr_turnv5(void)
  301. {
  302. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  303. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  304. // 转出
  305. rt_pin_write(CLEAR_R, ON);
  306. rt_pin_write(CLEAR_L, OFF);
  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. rt_pin_write(CLEAR_R, OFF);
  314. rt_pin_write(CLEAR_L, ON);
  315. rt_thread_mdelay(300);
  316. // 停止
  317. rt_pin_write(CLEAR_R, OFF);
  318. rt_pin_write(CLEAR_L, OFF);
  319. rt_thread_mdelay(300);
  320. }
  321. /**************************机器人********************************/
  322. void ctr_Motor_Robot(uint8_t status_ws)
  323. {
  324. unsigned int close_timeout = 0;
  325. unsigned int open_timeout = 0;
  326. rt_pin_mode(LIMIT_OPEN, PIN_MODE_INPUT);
  327. rt_pin_mode(LIMIT_CLOSE, PIN_MODE_INPUT);
  328. rt_pin_mode(Motor_Power, PIN_MODE_OUTPUT);
  329. rt_pin_mode(Motor_Direction_Button, PIN_MODE_INPUT);
  330. rt_pin_mode(Motor_Direction_Ctr, PIN_MODE_OUTPUT);
  331. rt_pin_write(Motor_Power, OFF);
  332. rt_pin_write(Motor_Direction_Ctr, ON);
  333. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  334. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  335. if (status_ws == ON)
  336. {
  337. // 检测按键状态
  338. while (rt_pin_read(Motor_Direction_Button) == 1)
  339. {
  340. if (rt_pin_read(LIMIT_CLOSE) == 1)
  341. {
  342. rt_pin_write(Motor_Direction_Ctr, ON);
  343. close_timeout++;
  344. // 打开电机驱动器电源,默认关闭
  345. rt_pin_write(Motor_Power, ON);
  346. if (close_timeout == 2)
  347. {
  348. rt_pin_write(CLEAR_R, ON);
  349. rt_pin_write(CLEAR_L, OFF);
  350. rt_pin_write(Motor_Power, OFF);
  351. rt_thread_delay(20);
  352. rt_pin_write(Motor_Power, ON);
  353. }
  354. rt_thread_delay(20);
  355. if (close_timeout > 500)
  356. {
  357. close_timeout = 600;
  358. rt_pin_write(Motor_Power, OFF);
  359. rt_pin_write(CLEAR_R, OFF);
  360. rt_pin_write(CLEAR_L, OFF);
  361. }
  362. }
  363. else
  364. {
  365. close_timeout = 0;
  366. rt_pin_write(Motor_Power, OFF); // 关闭驱动器电源
  367. rt_pin_write(CLEAR_R, OFF);
  368. rt_pin_write(CLEAR_L, OFF);
  369. }
  370. rt_thread_delay(20);
  371. }
  372. rt_pin_write(Motor_Power, OFF);
  373. rt_thread_delay(1000 * 2);
  374. while (rt_pin_read(Motor_Direction_Button) == 0)
  375. {
  376. if (rt_pin_read(LIMIT_OPEN) == 1)
  377. {
  378. open_timeout++;
  379. // 打开电机驱动器电源,默认关闭
  380. if (open_timeout == 2)
  381. {
  382. rt_pin_write(CLEAR_R, OFF);
  383. rt_pin_write(CLEAR_L, ON);
  384. }
  385. rt_pin_write(Motor_Power, ON);
  386. rt_pin_write(Motor_Direction_Ctr, OFF);
  387. if (open_timeout > 500)
  388. {
  389. open_timeout = 600;
  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. }
  396. if (rt_pin_read(LIMIT_OPEN) == 0)
  397. {
  398. open_timeout = 0;
  399. rt_pin_write(Motor_Power, OFF);
  400. rt_pin_write(CLEAR_R, OFF);
  401. rt_pin_write(CLEAR_L, OFF);
  402. }
  403. rt_thread_delay(20);
  404. close_timeout = 0;
  405. }
  406. open_timeout = 0;
  407. close_timeout = 0;
  408. }
  409. else
  410. {
  411. rt_pin_write(Motor_Power, OFF);
  412. }
  413. }
  414. /*************************吸虫塔*********************************/
  415. // 吸虫电机
  416. uint8_t ctr_Motor_xichong(uint8_t status_ws)
  417. {
  418. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  419. if (status_ws == ON)
  420. {
  421. rt_pin_write(MOTOR1_CTR_PIN, ON);
  422. }
  423. else
  424. {
  425. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  426. }
  427. return 0;
  428. }
  429. uint8_t ctr_Camera_Power(uint8_t status_ws)
  430. {
  431. rt_pin_mode(MOTOR1_CTR_PIN, PIN_MODE_OUTPUT);
  432. if (status_ws == ON)
  433. {
  434. rt_pin_write(MOTOR1_CTR_PIN, ON);
  435. }
  436. else
  437. {
  438. rt_pin_write(MOTOR1_CTR_PIN, OFF);
  439. }
  440. return 0;
  441. }
  442. // 吸附电机
  443. uint8_t ctr_Motor_xifu(uint8_t status_ws)
  444. {
  445. rt_pin_mode(MOTOR2_CTR_PIN, PIN_MODE_OUTPUT);
  446. if (status_ws == ON)
  447. {
  448. rt_pin_write(MOTOR2_CTR_PIN, ON);
  449. }
  450. else
  451. {
  452. rt_pin_write(MOTOR2_CTR_PIN, OFF);
  453. }
  454. return 0;
  455. }
  456. // 清扫-卷带电机
  457. void ctr_JD_Clear(uint8_t shake_sw)
  458. {
  459. rt_uint16_t turn_timeout = 0;
  460. rt_pin_mode(MOTOR_C_LIMIT, PIN_MODE_INPUT);
  461. ctr_cangmen_up(OFF); // 清扫传送带的电机
  462. if (shake_sw == ON)
  463. {
  464. ctr_Heat(ON); // 清洁风机
  465. Motor_shake(ON, 0);
  466. ctr_cangmen_up(OPEN); // 打开清扫
  467. }
  468. else
  469. {
  470. Motor_shake(OFF, 0);
  471. ctr_cangmen_up(OPEN); // 打开清扫
  472. }
  473. while (rt_pin_read(MOTOR_C_LIMIT) == 0)
  474. {
  475. Motor_Juandai(ON);
  476. rt_thread_delay(50);
  477. turn_timeout++;
  478. if (turn_timeout == 1000)
  479. break;
  480. }
  481. turn_timeout = 0;
  482. while (rt_pin_read(MOTOR_C_LIMIT) == 1)
  483. {
  484. Motor_Juandai(ON);
  485. turn_timeout++;
  486. rt_thread_delay(50);
  487. if (turn_timeout == 1000)
  488. break;
  489. }
  490. Motor_shake(OFF, 1);
  491. Motor_Juandai(OFF);
  492. ctr_cangmen_up(OFF); // 关闭清扫
  493. ctr_Heat(OFF);
  494. }
  495. // 工作任务流程
  496. void WorkTask_XCT(void)
  497. {
  498. while (device_status.work_status == 1 && device_status.ds == 1)
  499. {
  500. ctr_Motor_xifu(ON);
  501. // 打开相机供电
  502. ctr_Camera_Power(ON);
  503. // ctr_Heat(ON); //清洁风机
  504. uint32_t photo_fre = 0;
  505. photo_fre = device_status.dattim * 60;
  506. while (photo_fre != 0)
  507. {
  508. photo_fre--;
  509. rt_thread_delay(1000);
  510. LOG_I("收集中,等待开始拍照:%d", photo_fre);
  511. }
  512. // 卷带
  513. ctr_JD_Clear(OFF);
  514. // 拍照
  515. HK_TakePhoto();
  516. // 关闭吸附风机
  517. ctr_Motor_xifu(OFF);
  518. // 关闭相机供电
  519. // ctr_Heat(OFF);
  520. ctr_Camera_Power(OFF);
  521. // 卷带
  522. ctr_JD_Clear(ON);
  523. // rt_thread_delay(1000);
  524. // ctr_JD_Clear(ON);
  525. // 震动
  526. Motor_shake(ON, device_status.shake_sec);
  527. }
  528. // 关闭风机
  529. ctr_Motor_xichong(OFF);
  530. ctr_Motor_xifu(OFF);
  531. LOG_I("不在工作时间,未工作!!!");
  532. }
  533. /**********************************************************************/
  534. /*光控*/
  535. uint8_t In_Light_status(void)
  536. {
  537. rt_pin_mode(LIGHT_PIN, PIN_MODE_INPUT);
  538. return rt_pin_read(LIGHT_PIN);
  539. }
  540. /*雨控*/
  541. uint8_t In_Rain_status(void)
  542. {
  543. rt_pin_mode(RAIN_PIN, PIN_MODE_INPUT);
  544. return rt_pin_read(RAIN_PIN);
  545. }
  546. /*加热*/
  547. uint8_t ctr_Heat(uint8_t status_heat)
  548. {
  549. device_status.heat_status = status_heat;
  550. rt_pin_mode(Heat_Pin, PIN_MODE_OUTPUT);
  551. rt_pin_write(Heat_Pin, status_heat);
  552. return status_heat;
  553. }
  554. /*制冷*/
  555. uint8_t ctr_Cold(uint8_t status_cold)
  556. {
  557. device_status.cold_status = status_cold;
  558. rt_pin_mode(Cold_Pin, PIN_MODE_OUTPUT);
  559. rt_pin_write(Cold_Pin, status_cold);
  560. return status_cold;
  561. }
  562. /*相机供电*/
  563. void ctr_photo(uint8_t status_photo)
  564. {
  565. rt_pin_mode(PHOTO, PIN_MODE_OUTPUT);
  566. rt_pin_write(PHOTO, status_photo);
  567. }
  568. /*************************************************
  569. Function: ctr_Cool_Fan
  570. Description: 散热风机的开关
  571. Calls:
  572. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  573. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  574. Input: ON-开,OFF-关
  575. Output: NULL
  576. Return: ON-开,OFF-关
  577. Others: NULL
  578. *************************************************/
  579. uint8_t ctr_Cool_Fan(uint8_t status_cool)
  580. {
  581. device_status.cool_fan_status = status_cool;
  582. rt_pin_mode(Cool_Fan_L, PIN_MODE_OUTPUT);
  583. rt_pin_mode(Cool_Fan_R, PIN_MODE_OUTPUT);
  584. if (status_cool == OFF)
  585. {
  586. rt_pin_write(Cool_Fan_L, OFF);
  587. rt_pin_write(Cool_Fan_R, OFF);
  588. }
  589. if (status_cool == ON)
  590. {
  591. rt_pin_write(Cool_Fan_L, ON);
  592. rt_pin_write(Cool_Fan_R, OFF);
  593. }
  594. return device_status.cool_fan_status;
  595. }
  596. /*************************************************
  597. Function: ctr_Collect_Fan
  598. Description: 采集风机的开关
  599. Calls:
  600. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  601. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  602. Input: ON-开,OFF-关
  603. Output: NULL
  604. Return: ON-开,OFF-关
  605. Others: NULL
  606. *************************************************/
  607. uint8_t ctr_Collect_Fan(uint8_t status_collect)
  608. {
  609. device_status.collect_fan_status = status_collect;
  610. rt_pin_mode(Collect_Fan, PIN_MODE_OUTPUT);
  611. if (status_collect == OFF)
  612. {
  613. rt_pin_write(Collect_Fan, OFF);
  614. }
  615. if (status_collect == ON)
  616. {
  617. rt_pin_write(Collect_Fan, ON);
  618. }
  619. return device_status.collect_fan_status;
  620. }
  621. /*************************************************
  622. Function: ctr_develop
  623. Description: 培养载玻片孢子
  624. Calls:
  625. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  626. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  627. Input: v=0(复位) v=90转90度
  628. Output: NULL
  629. Return: NULL
  630. Others: NULL
  631. *************************************************/
  632. void ctr_develop(void)
  633. {
  634. rt_kprintf("===============开始培养=================:%d\n", device_status.cul_time);
  635. // 已经培养的时间-分钟
  636. device_status.stay_time = 0;
  637. rt_uint32_t ii = 0;
  638. while (device_status.develop_flag == 1)
  639. {
  640. float stayedtime = 0.01;
  641. char stayed[5];
  642. stayedtime = (float)device_status.stay_time / 60.0;
  643. sprintf(stayed, "%0.02f", stayedtime);
  644. HMI_WRITE("workSta.staytime.txt=\"%s\"", stayed);
  645. ii++;
  646. LOG_I("developing...................................%d\n", ii);
  647. LOG_I("============================设定的培养温度:%d\n", device_status.heatvalue);
  648. LOG_I("============================培养仓实时温度:%d\n", device_status.pre_temp);
  649. if (device_status.pre_temp < (device_status.heatvalue - 5))
  650. {
  651. // 未制冷
  652. if (device_status.cold_status == 0)
  653. {
  654. ctr_Heat(ON);
  655. }
  656. }
  657. else
  658. {
  659. ctr_Heat(OFF);
  660. }
  661. LOG_I("============================制冷开关:%d\n", device_status.cold_sw);
  662. if (device_status.cold_sw == 1)
  663. {
  664. if (device_status.pre_temp > (device_status.heatvalue - 10))
  665. {
  666. if (device_status.heat_status == 0)
  667. {
  668. ctr_Cold(ON);
  669. }
  670. }
  671. else
  672. {
  673. ctr_Cold(OFF);
  674. }
  675. }
  676. if (ii % 60 == 0)
  677. {
  678. device_status.stay_time++;
  679. if (device_status.stay_time / 60 == device_status.cul_time)
  680. device_status.develop_flag = 0;
  681. LOG_I("developed...................................%d分钟\n", device_status.stay_time);
  682. }
  683. if (device_status.box_temp > 35)
  684. {
  685. ctr_Cool_Fan(ON);
  686. }
  687. else if (device_status.box_temp < 30)
  688. {
  689. ctr_Cool_Fan(OFF);
  690. }
  691. rt_thread_delay(1000);
  692. }
  693. ctr_Cold(OFF);
  694. ctr_Heat(OFF);
  695. LOG_I("=========!!!培养完成!!!==========");
  696. }
  697. /*上仓门*/
  698. /**
  699. * @brief 控制仓门升起
  700. *
  701. * @param status_down 指令
  702. * @return uint8_t 执行后的状态
  703. */
  704. uint8_t ctr_cangmen_up(uint8_t status_up)
  705. {
  706. rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
  707. rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
  708. if (status_up == OFF)
  709. {
  710. rt_pin_write(Collect_fan_R, ON);
  711. rt_pin_write(Collect_fan_L, ON);
  712. device_status.ctr_up_motor = 0;
  713. rt_thread_delay(1000);
  714. }
  715. if (status_up == OPEN)
  716. {
  717. device_status.up_status = 1;
  718. rt_pin_write(Collect_fan_R, OFF);
  719. rt_pin_write(Collect_fan_L, OFF);
  720. rt_pin_write(Collect_fan_R, ON);
  721. rt_pin_write(Collect_fan_L, OFF);
  722. }
  723. if (status_up == CLOSE)
  724. {
  725. device_status.up_status = 0;
  726. rt_pin_write(Collect_fan_R, OFF);
  727. rt_pin_write(Collect_fan_L, OFF);
  728. rt_pin_write(Collect_fan_R, OFF);
  729. rt_pin_write(Collect_fan_L, ON);
  730. }
  731. return device_status.up_status;
  732. }
  733. // 下仓门
  734. /**
  735. * @brief 控制仓门落下
  736. *
  737. * @param status_down 指令
  738. * @return uint8_t 执行后的状态
  739. */
  740. uint8_t ctr_cangmen_down(uint8_t status_down)
  741. {
  742. rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
  743. rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
  744. if (status_down == OFF)
  745. {
  746. rt_pin_write(C_DOWN_R, ON);
  747. rt_pin_write(C_DOWN_L, ON);
  748. device_status.ctr_down_motor = 0;
  749. rt_thread_delay(1000);
  750. }
  751. if (status_down == OPEN)
  752. {
  753. device_status.down_status = 1;
  754. rt_pin_write(C_DOWN_R, OFF);
  755. rt_pin_write(C_DOWN_L, OFF);
  756. rt_pin_write(C_DOWN_R, ON);
  757. rt_pin_write(C_DOWN_L, OFF);
  758. }
  759. if (status_down == CLOSE)
  760. {
  761. device_status.down_status = 0;
  762. rt_pin_write(C_DOWN_R, OFF);
  763. rt_pin_write(C_DOWN_L, OFF);
  764. rt_pin_write(C_DOWN_R, OFF);
  765. rt_pin_write(C_DOWN_L, ON);
  766. }
  767. return device_status.down_status;
  768. }
  769. // 镇流器
  770. /**
  771. * @brief 控制镇流器动作
  772. *
  773. * @param status_lamp 指令
  774. * @param lamp_num 镇流器编号
  775. * @return uint8_t 更新后的镇流器状态
  776. */
  777. uint8_t ctr_lamp(uint8_t status_lamp, uint8_t lamp_num)
  778. {
  779. rt_pin_mode(LAMP_SW, PIN_MODE_OUTPUT);
  780. rt_pin_mode(LAMP_1_SW, PIN_MODE_OUTPUT);
  781. rt_pin_mode(LAMP_2_SW, PIN_MODE_OUTPUT);
  782. if (status_lamp == ON)
  783. {
  784. switch (lamp_num)
  785. {
  786. case 1:
  787. rt_pin_write(LAMP_SW, ON);
  788. device_status.lamp_status = status_lamp;
  789. break;
  790. case 2:
  791. rt_pin_write(LAMP_1_SW, ON);
  792. device_status.lamp_status = status_lamp;
  793. break;
  794. case 3:
  795. rt_pin_write(LAMP_2_SW, ON);
  796. device_status.lamp_status = status_lamp;
  797. break;
  798. default:
  799. break;
  800. }
  801. }
  802. else
  803. {
  804. switch (lamp_num)
  805. {
  806. case 1:
  807. rt_pin_write(LAMP_SW, OFF);
  808. device_status.lamp_status = status_lamp;
  809. break;
  810. case 2:
  811. rt_pin_write(LAMP_1_SW, OFF);
  812. device_status.lamp1_status = status_lamp;
  813. break;
  814. case 3:
  815. rt_pin_write(LAMP_2_SW, OFF);
  816. device_status.lamp2_status = status_lamp;
  817. break;
  818. default:
  819. break;
  820. }
  821. }
  822. HMI_WRITE("sysTest.switchLamp.val=%d", device_status.lamp_status);
  823. return device_status.lamp_status;
  824. }
  825. // 震动电机
  826. /**
  827. * @brief 控制震动电机动作
  828. *
  829. * @param status_shake 指令
  830. * @param shake_sec 震动时间(秒)
  831. * @return uint8_t 执行后的状态
  832. */
  833. uint8_t ctr_shake(uint8_t status_shake, uint16_t shake_sec)
  834. {
  835. static rt_uint16_t shake_i = 0;
  836. if (device_status.dtype == dt_BZY && device_status.version_type == vt_BZY_JD)
  837. {
  838. return 0;
  839. }
  840. shake_i = atoi(device_status.power);
  841. LOG_I("震动电机待机电流:%d", shake_i);
  842. if (device_status.dtype == 7 && shake_sec != 0)
  843. DTU_Write("drop");
  844. rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
  845. if (status_shake == ON && device_status.shake_ws == 1)
  846. {
  847. rt_pin_write(SHAKE_SW, ON);
  848. if (device_status.dtype == 3)
  849. {
  850. while (shake_sec--)
  851. {
  852. rt_thread_delay(100);
  853. if (shake_sec == 20 && device_status.clear_status == 0 && device_status.work_status == 1 && atoi(device_status.power) - shake_i < 100 && shake_i != 0 && shake_i < 5000)
  854. {
  855. char *shake_warn = makeJson_Warn("电流不足", "震动电机");
  856. DTU_Write("%s", shake_warn);
  857. rt_free(shake_warn);
  858. }
  859. LOG_D("震动电机:%d", atoi(device_status.power));
  860. }
  861. }
  862. if (device_status.dtype == 7)
  863. rt_thread_delay(shake_sec * 1000);
  864. rt_pin_write(SHAKE_SW, OFF);
  865. HMI_WRITE("cangWei.switchShake.val=%d", 0);
  866. }
  867. else
  868. {
  869. rt_pin_write(SHAKE_SW, OFF);
  870. HMI_WRITE("cangWei.switchShake.val=%d", 0);
  871. }
  872. if (device_status.dtype == 7)
  873. HMI_WRITE("sysTest.switchDrop.val=%d", OFF);
  874. return status_shake;
  875. }
  876. // 补光
  877. /**
  878. * @brief 控制补光灯动作
  879. *
  880. * @param status_led 指令
  881. * @return uint8_t 执行后的状态
  882. */
  883. uint8_t ctr_led(uint8_t status_led)
  884. {
  885. rt_pin_mode(LED_SW, PIN_MODE_OUTPUT);
  886. if (device_status.version_type == 6)
  887. rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
  888. if (status_led == ON)
  889. {
  890. rt_pin_write(LED_SW, ON);
  891. if (device_status.version_type == 6)
  892. rt_pin_write(LED_P, ON);
  893. HMI_WRITE("sysTest.switchFill.val=%d", ON);
  894. }
  895. else if (status_led == OFF)
  896. {
  897. rt_pin_write(LED_SW, OFF);
  898. if (device_status.version_type == 6)
  899. rt_pin_write(LED_P, OFF);
  900. HMI_WRITE("sysTest.switchPhoto.val=%d", OFF);
  901. HMI_WRITE("sysTest.switchFill.val=%d", OFF);
  902. }
  903. return status_led;
  904. }
  905. /*************************************************
  906. Function: ctr_turn
  907. Description: 转盘驱动
  908. Calls:
  909. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  910. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  911. Input: v=0(复位) v=90转90度
  912. Output: NULL
  913. Return: NULL
  914. Others: NULL
  915. *************************************************/
  916. void ctr_turn(uint8_t v, uint8_t sta)
  917. {
  918. if (device_status.dtype == dt_BZY && device_status.version_type == vt_BZY_JD)
  919. {
  920. return;
  921. }
  922. DTU_Write("turn.mp3");
  923. LOG_I("================v===============:%d", v);
  924. rt_uint16_t turn_cnt = 0;
  925. rt_pin_mode(TURN_ZP_R, PIN_MODE_OUTPUT);
  926. rt_pin_mode(TURN_ZP_L, PIN_MODE_OUTPUT);
  927. rt_pin_mode(LIMIT_0, PIN_MODE_INPUT);
  928. rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
  929. // if(v==0&&rt_pin_read(LIMIT_0)==0) return; //如果在初始位置,则不再往下执行
  930. while (rt_pin_read(LIMIT_0) == 0 || rt_pin_read(LIMIT_90) == 0)
  931. {
  932. rt_pin_write(TURN_ZP_R, ON);
  933. rt_pin_write(TURN_ZP_L, OFF);
  934. // Motor_shake(ON,0);
  935. turn_cnt++;
  936. rt_thread_delay(100);
  937. if (turn_cnt == 1000)
  938. {
  939. turn_cnt = 0;
  940. rt_pin_write(TURN_ZP_R, OFF);
  941. rt_pin_write(TURN_ZP_L, OFF);
  942. // Motor_shake(OFF,0);
  943. char *turn_warn = makeJson_Warn("未检测到限位", "转盘");
  944. DTU_Write("%s", turn_warn);
  945. rt_free(turn_warn);
  946. break;
  947. }
  948. }
  949. turn_cnt = 0;
  950. while (v == 0 && rt_pin_read(LIMIT_0) == 1)
  951. {
  952. rt_pin_write(TURN_ZP_R, ON);
  953. rt_pin_write(TURN_ZP_L, OFF);
  954. Motor_shake(ON, 0);
  955. rt_thread_delay(200); // 10 to 100
  956. turn_cnt++;
  957. if (turn_cnt == 300) // 6000 to 600
  958. {
  959. turn_cnt = 0;
  960. // rt_pin_write(TURN_ZP_R, OFF);
  961. // rt_pin_write(TURN_ZP_L, OFF);
  962. // char *turn_warn =makeJson_Warn("超时", "转盘复位");
  963. // DTU_Write("%s",turn_warn);
  964. // rt_free(turn_warn);
  965. break;
  966. }
  967. }
  968. while (v == 0 && rt_pin_read(LIMIT_0) == 1)
  969. {
  970. rt_pin_write(TURN_ZP_R, ON);
  971. rt_pin_write(TURN_ZP_L, OFF);
  972. // Motor_shake(ON,0);
  973. rt_thread_delay(50); // 10 to 50
  974. turn_cnt++;
  975. if (turn_cnt == 10) // 6000 to 1200
  976. {
  977. turn_cnt = 0;
  978. rt_pin_write(TURN_ZP_R, OFF);
  979. rt_pin_write(TURN_ZP_L, OFF);
  980. // Motor_shake(OFF,0);
  981. char *turn_warn = makeJson_Warn("超时", "转盘复位");
  982. DTU_Write("%s", turn_warn);
  983. rt_free(turn_warn);
  984. break;
  985. }
  986. }
  987. turn_cnt = 0;
  988. while (v == 90 && rt_pin_read(LIMIT_90) == 1)
  989. {
  990. rt_pin_write(TURN_ZP_R, ON);
  991. rt_pin_write(TURN_ZP_L, OFF);
  992. // Motor_shake(ON,0);
  993. rt_thread_delay(200);
  994. turn_cnt++;
  995. if (turn_cnt == 150)
  996. {
  997. turn_cnt = 0;
  998. // rt_pin_write(TURN_ZP_R, OFF);
  999. // rt_pin_write(TURN_ZP_L, OFF);
  1000. // char *turn_warn =makeJson_Warn("超时", "转盘");
  1001. // DTU_Write(turn_warn);
  1002. // rt_free(turn_warn);
  1003. break;
  1004. }
  1005. }
  1006. while (v == 90 && rt_pin_read(LIMIT_90) == 1)
  1007. {
  1008. // rt_pin_write(TURN_ZP_R, ON);
  1009. // rt_pin_write(TURN_ZP_L, OFF);
  1010. Motor_shake(ON, 0);
  1011. rt_thread_delay(50);
  1012. turn_cnt++;
  1013. if (turn_cnt == 10)
  1014. {
  1015. turn_cnt = 0;
  1016. rt_pin_write(TURN_ZP_R, OFF);
  1017. rt_pin_write(TURN_ZP_L, OFF);
  1018. // Motor_shake(OFF,0);
  1019. char *turn_warn = makeJson_Warn("超时", "转盘");
  1020. DTU_Write(turn_warn);
  1021. rt_free(turn_warn);
  1022. break;
  1023. }
  1024. }
  1025. if (sta != 0)
  1026. {
  1027. // 保存位置
  1028. device_status.run_sta = sta;
  1029. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  1030. }
  1031. turn_cnt = 0;
  1032. rt_pin_write(TURN_ZP_R, OFF);
  1033. rt_pin_write(TURN_ZP_L, OFF);
  1034. Motor_shake(OFF, 0);
  1035. HMI_WRITE("cangWei.rotateFlag.val=0");
  1036. }
  1037. /*************************************************
  1038. Function: ctr_Motor_Driver
  1039. Description: 步进电机驱动
  1040. Calls:
  1041. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  1042. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  1043. Input: 50000000
  1044. Output: NULL
  1045. Return: shake_sec
  1046. Others: NULL
  1047. *************************************************/
  1048. void ctr_Motor_Driver(uint8_t EN, uint8_t DIR, rt_uint32_t pwm, rt_uint32_t time_out)
  1049. {
  1050. beep_init();
  1051. rt_pin_mode(LIMIT_UP, PIN_MODE_INPUT);
  1052. rt_pin_mode(LIMIT_DOWN, PIN_MODE_INPUT);
  1053. rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
  1054. rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
  1055. if (EN == 0)
  1056. {
  1057. rt_pin_write(Motor_Power, 0);
  1058. }
  1059. else
  1060. {
  1061. rt_pin_write(Motor_EN, EN);
  1062. }
  1063. rt_pin_write(Motor_DIR, DIR);
  1064. beep_set(pwm, pwm / 2); // 200kzh - 50%
  1065. while (DIR == 1 && rt_pin_read(LIMIT_DOWN) == 1)
  1066. {
  1067. if (time_out == 0)
  1068. {
  1069. break;
  1070. }
  1071. rt_thread_delay(50);
  1072. time_out--;
  1073. }
  1074. while (DIR == 0 && rt_pin_read(LIMIT_UP) == 1)
  1075. {
  1076. if (time_out == 0)
  1077. {
  1078. break;
  1079. }
  1080. rt_thread_delay(50);
  1081. time_out--;
  1082. }
  1083. rt_pin_write(Motor_EN, OFF);
  1084. if (device_status.autotakepic == 0)
  1085. ctr_lamp(OFF, 1);
  1086. beep_set(0, 0); // 200kzh - 50%
  1087. }
  1088. /*************************************************
  1089. Function: ctr_Petroleum_jelly
  1090. Description: 涂凡士林
  1091. Calls:
  1092. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  1093. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  1094. Input: NULL
  1095. Output: NULL
  1096. Return: NULL
  1097. Others: NULL
  1098. *************************************************/
  1099. void ctr_Petroleum_jelly(rt_uint32_t delay)
  1100. {
  1101. beep_init();
  1102. pwm_on(2, 50000);
  1103. rt_thread_delay(delay * 1000);
  1104. pwm_off(2, 0);
  1105. rt_thread_delay(1000);
  1106. pwm_on(3, 50000);
  1107. rt_thread_delay(delay * 1000);
  1108. pwm_off(3, 0);
  1109. device_status.fsl_sw = 0;
  1110. }
  1111. // 1.0转仓
  1112. void turnzp(void)
  1113. {
  1114. static uint16_t turn_timeout = 0;
  1115. // rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1116. // rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1117. rt_pin_mode(CLEAR_R_LIMIT, PIN_MODE_INPUT);
  1118. // rt_pin_write(CLEAR_R,OFF);
  1119. // rt_pin_write(CLEAR_L,OFF);
  1120. while (rt_pin_read(CLEAR_R_LIMIT) == 0)
  1121. {
  1122. rt_thread_delay(20);
  1123. while (rt_pin_read(CLEAR_R_LIMIT) == 0)
  1124. {
  1125. // rt_pin_write(CLEAR_R,ON);
  1126. // rt_pin_write(CLEAR_L,OFF);
  1127. Motor_Juandai(ON);
  1128. rt_thread_delay(50);
  1129. turn_timeout++;
  1130. if (turn_timeout == 600)
  1131. {
  1132. LOG_E("检测不到限位,电机强制停止");
  1133. char *ctr_zp_limit_warn = makeJson_Warn("电流不足/限位超时", "转盘电机");
  1134. DTU_Write("%s", ctr_zp_limit_warn);
  1135. rt_free(ctr_zp_limit_warn);
  1136. break;
  1137. }
  1138. }
  1139. break;
  1140. }
  1141. while (rt_pin_read(CLEAR_R_LIMIT) == 1)
  1142. {
  1143. rt_thread_delay(20);
  1144. while (rt_pin_read(CLEAR_R_LIMIT) == 1)
  1145. {
  1146. // rt_pin_write(CLEAR_R,ON);
  1147. // rt_pin_write(CLEAR_L,OFF);
  1148. Motor_Juandai(ON);
  1149. rt_thread_delay(50);
  1150. turn_timeout++;
  1151. if (turn_timeout == 600)
  1152. {
  1153. LOG_E("检测不到离开限位,电机或者限位开关异常,电机强制停止");
  1154. char *ctr_zp_limit_warn = makeJson_Warn("检测不到离开限位,电机未启动或者限位开关故障", "转盘电机");
  1155. DTU_Write("%s", ctr_zp_limit_warn);
  1156. rt_free(ctr_zp_limit_warn);
  1157. break;
  1158. }
  1159. }
  1160. break;
  1161. }
  1162. while (rt_pin_read(CLEAR_R_LIMIT) == 0)
  1163. {
  1164. rt_thread_delay(20);
  1165. if (rt_pin_read(CLEAR_R_LIMIT) == 0)
  1166. {
  1167. // rt_pin_write(CLEAR_R,OFF);
  1168. // rt_pin_write(CLEAR_L,OFF);
  1169. Motor_Juandai(OFF);
  1170. break;
  1171. }
  1172. else
  1173. {
  1174. break;
  1175. }
  1176. }
  1177. Motor_Juandai(OFF);
  1178. // rt_pin_write(CLEAR_R,OFF);
  1179. // rt_pin_write(CLEAR_L,OFF);
  1180. turn_timeout = 0;
  1181. HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
  1182. HMI_WRITE("sysTest.switchClear.val=%d", 0);
  1183. rt_thread_delay(1000);
  1184. }
  1185. // 清扫-常闭型限位开关
  1186. // 新结构使用推杆电机做清扫
  1187. uint8_t ctr_clear(uint16_t status_clear)
  1188. {
  1189. static uint16_t clear_num = 0;
  1190. #if PWM_EN == 0
  1191. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1192. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1193. #endif
  1194. rt_pin_mode(CLEAR_R_LIMIT, PIN_MODE_INPUT);
  1195. rt_pin_mode(CLEAR_L_LIMIT, PIN_MODE_INPUT);
  1196. /*************************************************************外接清扫
  1197. rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  1198. rt_pin_write(POWER_CLEAR,ON);
  1199. rt_thread_delay(1000*100);
  1200. rt_pin_write(POWER_CLEAR,OFF);
  1201. ************************************************************/
  1202. // 停止
  1203. #if PWM_EN == 0
  1204. rt_pin_write(CLEAR_R, OFF);
  1205. rt_pin_write(CLEAR_L, OFF);
  1206. #else
  1207. Motor_Qingsao_R_PWM(OFF);
  1208. Motor_Qingsao_L_PWM(OFF);
  1209. #endif
  1210. if (status_clear == OFF || Read_Real_Voltage() / 100 < 12)
  1211. return 0;
  1212. rt_thread_delay(100);
  1213. // 如果清扫位置在中间
  1214. while (rt_pin_read(CLEAR_R_LIMIT) == 0 && rt_pin_read(CLEAR_L_LIMIT) == 0)
  1215. {
  1216. #if PWM_EN == 0
  1217. rt_pin_write(CLEAR_R, ON);
  1218. rt_pin_write(CLEAR_L, OFF);
  1219. #else
  1220. Motor_Qingsao_R_PWM(ON);
  1221. Motor_Qingsao_L_PWM(OFF);
  1222. #endif
  1223. rt_thread_delay(50);
  1224. clear_num++;
  1225. // 已到达检测位置
  1226. if (rt_pin_read(CLEAR_L_LIMIT) == 1 || rt_pin_read(CLEAR_R_LIMIT) == 1)
  1227. {
  1228. #if PWM_EN == 0
  1229. rt_pin_write(CLEAR_R, ON);
  1230. rt_pin_write(CLEAR_L, ON);
  1231. #else
  1232. Motor_Qingsao_R_PWM(OFF);
  1233. Motor_Qingsao_L_PWM(OFF);
  1234. #endif
  1235. rt_thread_delay(2000);
  1236. break;
  1237. }
  1238. if (clear_num >= status_clear || atoi(device_status.power) > 2000 || (Read_Real_Voltage() / 100) < 12)
  1239. {
  1240. rt_kprintf("Clear Motor ERR:%d", atoi(device_status.power));
  1241. // DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  1242. #if PWM_EN == 0
  1243. rt_pin_write(CLEAR_R, ON);
  1244. rt_pin_write(CLEAR_L, ON);
  1245. #else
  1246. Motor_Qingsao_R_PWM(OFF);
  1247. Motor_Qingsao_L_PWM(OFF);
  1248. #endif
  1249. rt_free(makeJson_Warn("Clear Motor ERR", "device"));
  1250. if (Read_Real_Voltage() / 100 < 12)
  1251. {
  1252. HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
  1253. HMI_WRITE("sysTest.switchClear.val=%d", 0);
  1254. device_status.clear_status = 0;
  1255. return 0;
  1256. }
  1257. break;
  1258. }
  1259. }
  1260. clear_num = 0;
  1261. // 如果清扫位置在左侧
  1262. while (rt_pin_read(CLEAR_R_LIMIT) == 0)
  1263. {
  1264. #if PWM_EN == 0
  1265. rt_pin_write(CLEAR_R, ON);
  1266. rt_pin_write(CLEAR_L, OFF);
  1267. #else
  1268. Motor_Qingsao_R_PWM(ON);
  1269. Motor_Qingsao_L_PWM(OFF);
  1270. #endif
  1271. rt_thread_delay(50);
  1272. clear_num++;
  1273. if (clear_num >= status_clear || atoi(device_status.power) > 2000 || (Read_Real_Voltage() / 100) < 12)
  1274. {
  1275. rt_kprintf("Clear Motor ERR:%d", atoi(device_status.power));
  1276. // DTU_Write("%s",makeJson_Warn("Clear Motor ERR","device"));
  1277. #if PWM_EN == 0
  1278. rt_pin_write(CLEAR_R, ON);
  1279. rt_pin_write(CLEAR_L, ON);
  1280. #else
  1281. Motor_Qingsao_R_PWM(OFF);
  1282. Motor_Qingsao_L_PWM(OFF);
  1283. #endif
  1284. rt_free(makeJson_Warn("Clear Motor ERR", "device"));
  1285. if (Read_Real_Voltage() / 100 < 12)
  1286. {
  1287. HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
  1288. HMI_WRITE("sysTest.switchClear.val=%d", 0);
  1289. device_status.clear_status = 0;
  1290. return 0;
  1291. }
  1292. break;
  1293. }
  1294. }
  1295. clear_num = 0;
  1296. while (rt_pin_read(CLEAR_L_LIMIT) == 1 || rt_pin_read(CLEAR_R_LIMIT) == 1 || (Read_Real_Voltage() / 100) < 12)
  1297. {
  1298. #if PWM_EN == 0
  1299. rt_pin_write(CLEAR_R, ON);
  1300. rt_pin_write(CLEAR_L, ON);
  1301. #else
  1302. Motor_Qingsao_R_PWM(OFF);
  1303. Motor_Qingsao_L_PWM(OFF);
  1304. #endif
  1305. if (Read_Real_Voltage() / 100 < 12)
  1306. {
  1307. HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
  1308. HMI_WRITE("sysTest.switchClear.val=%d", 0);
  1309. device_status.clear_status = 0;
  1310. return 0;
  1311. }
  1312. rt_thread_delay(2000);
  1313. break;
  1314. }
  1315. while (rt_pin_read(CLEAR_L_LIMIT) == 0)
  1316. {
  1317. #if PWM_EN == 0
  1318. rt_pin_write(CLEAR_R, OFF);
  1319. rt_pin_write(CLEAR_L, ON);
  1320. #else
  1321. Motor_Qingsao_R_PWM(OFF);
  1322. Motor_Qingsao_L_PWM(ON);
  1323. #endif
  1324. rt_thread_delay(50);
  1325. clear_num++;
  1326. if (clear_num >= status_clear || atoi(device_status.power) > 2000 || (Read_Real_Voltage() / 100) < 12)
  1327. {
  1328. rt_kprintf("Clear Motor ERR:%d", atoi(device_status.power));
  1329. char *Clear_ERR = makeJson_Warn("Clear Motor ERR", "device");
  1330. // DTU_Write("%s",Clear_ERR);
  1331. #if PWM_EN == 0
  1332. rt_pin_write(CLEAR_R, ON);
  1333. rt_pin_write(CLEAR_L, ON);
  1334. #else
  1335. Motor_Qingsao_R_PWM(OFF);
  1336. Motor_Qingsao_L_PWM(OFF);
  1337. #endif
  1338. rt_free(Clear_ERR);
  1339. if (Read_Real_Voltage() / 100 < 12)
  1340. {
  1341. HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
  1342. HMI_WRITE("sysTest.switchClear.val=%d", 0);
  1343. device_status.clear_status = 0;
  1344. return 0;
  1345. }
  1346. break;
  1347. }
  1348. }
  1349. while (rt_pin_read(CLEAR_L_LIMIT) == 1 || rt_pin_read(CLEAR_R_LIMIT) == 1)
  1350. {
  1351. #if PWM_EN == 0
  1352. rt_pin_write(CLEAR_R, ON);
  1353. rt_pin_write(CLEAR_L, ON);
  1354. #else
  1355. Motor_Qingsao_R_PWM(OFF);
  1356. Motor_Qingsao_L_PWM(OFF);
  1357. #endif
  1358. rt_thread_delay(2000);
  1359. break;
  1360. }
  1361. while (rt_pin_read(CLEAR_L_LIMIT) == 1 && rt_pin_read(CLEAR_R_LIMIT) == 1)
  1362. {
  1363. #if PWM_EN == 0
  1364. rt_pin_write(CLEAR_R, ON);
  1365. rt_pin_write(CLEAR_L, ON);
  1366. #else
  1367. Motor_Qingsao_R_PWM(OFF);
  1368. Motor_Qingsao_L_PWM(OFF);
  1369. #endif
  1370. if (device_status.version_type == 41)
  1371. {
  1372. rt_kprintf("Clear Motor Limit Not Access:%d", atoi(device_status.power));
  1373. char *Clear_ERR = makeJson_Warn("Clear Motor Limit Not Access", "device");
  1374. // DTU_Write("%s",Clear_ERR);
  1375. rt_free(Clear_ERR);
  1376. }
  1377. return 0;
  1378. }
  1379. clear_num = 0;
  1380. rt_thread_delay(2000);
  1381. #if PWM_EN == 0
  1382. rt_pin_write(CLEAR_R, ON);
  1383. rt_pin_write(CLEAR_L, ON);
  1384. #else
  1385. Motor_Qingsao_R_PWM(OFF);
  1386. Motor_Qingsao_L_PWM(OFF);
  1387. #endif
  1388. HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
  1389. HMI_WRITE("sysTest.switchClear.val=%d", 0);
  1390. device_status.clear_status = 0;
  1391. return 1;
  1392. }
  1393. // 路由器供电
  1394. void ctr_router(uint8_t status_router)
  1395. {
  1396. rt_pin_mode(ROUTER, PIN_MODE_OUTPUT);
  1397. if (device_status.version_type == 6)
  1398. rt_pin_mode(ROUTER_P, PIN_MODE_OUTPUT);
  1399. // rt_pin_mode(POWER_CLEAR, PIN_MODE_OUTPUT);
  1400. if (status_router == ON)
  1401. {
  1402. rt_pin_write(ROUTER, ON);
  1403. //
  1404. #if LAMP_EN == 0
  1405. if (device_status.version_type == 6)
  1406. rt_pin_write(ROUTER_P, ON);
  1407. #endif
  1408. }
  1409. else
  1410. {
  1411. rt_pin_write(ROUTER, OFF);
  1412. //
  1413. #if LAMP_EN == 0
  1414. if (device_status.version_type == 6)
  1415. rt_pin_write(ROUTER_P, OFF);
  1416. #endif
  1417. }
  1418. }
  1419. // 清扫-推杆电机
  1420. void ctr_TG_Clear(uint16_t clear_timeout)
  1421. {
  1422. #if 0
  1423. int current_clear[200];
  1424. int16_t Electric_current = atoi(device_status.power); //获取电机运动前的电流
  1425. LOG_I("清扫电机待机:%d",Electric_current);
  1426. #endif
  1427. static uint16_t clear_count = 0;
  1428. clear_count = clear_timeout;
  1429. #if PWM_EN == 0
  1430. rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
  1431. rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
  1432. #endif
  1433. while (clear_count != 0)
  1434. {
  1435. #if PWM_EN == 0
  1436. rt_pin_write(CLEAR_R, ON);
  1437. rt_pin_write(CLEAR_L, OFF);
  1438. #else
  1439. Motor_Qingsao_R_PWM(ON);
  1440. Motor_Qingsao_L_PWM(OFF);
  1441. #endif
  1442. clear_count--;
  1443. rt_thread_delay(100);
  1444. }
  1445. #if PWM_EN == 0
  1446. rt_pin_write(CLEAR_R, ON);
  1447. rt_pin_write(CLEAR_L, ON);
  1448. #else
  1449. Motor_Qingsao_R_PWM(OFF);
  1450. Motor_Qingsao_L_PWM(OFF);
  1451. #endif
  1452. rt_thread_delay(3000);
  1453. clear_count = 0;
  1454. while (clear_timeout != clear_count)
  1455. {
  1456. #if PWM_EN == 0
  1457. rt_pin_write(CLEAR_R, OFF);
  1458. rt_pin_write(CLEAR_L, ON);
  1459. #else
  1460. Motor_Qingsao_R_PWM(OFF);
  1461. Motor_Qingsao_L_PWM(ON);
  1462. #endif
  1463. // if(clear_count<200)
  1464. // current_clear[clear_count] = atoi(device_status.power);
  1465. clear_count++;
  1466. rt_thread_delay(100);
  1467. }
  1468. #if PWM_EN == 0
  1469. rt_pin_write(CLEAR_R, ON);
  1470. rt_pin_write(CLEAR_L, ON);
  1471. #else
  1472. Motor_Qingsao_R_PWM(OFF);
  1473. Motor_Qingsao_L_PWM(OFF);
  1474. #endif
  1475. #if 0
  1476. bubblesort(current_clear,200);
  1477. if(current_clear[199]-Electric_current <100&&device_status.work_status==1&&Electric_current!=0&&Electric_current<5000)
  1478. {
  1479. LOG_E("清扫电机电流不足:%d!",current_clear[199]);
  1480. char *ctr_clear_warn = makeJson_Warn("电流不足","清扫电机");
  1481. DTU_Write("%s",ctr_clear_warn);
  1482. rt_free(ctr_clear_warn);
  1483. }
  1484. #endif
  1485. rt_thread_delay(2000);
  1486. device_status.clear_status = 0;
  1487. HMI_WRITE("cangWei.rotateFlag.val=%d", 0);
  1488. HMI_WRITE("sysTest.switchClear.val=%d", 0);
  1489. }
  1490. // DTU,RTU供电
  1491. void ctr_RTU_DTU(uint8_t status_rtu)
  1492. {
  1493. rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
  1494. if (status_rtu == ON)
  1495. {
  1496. rt_pin_write(RTU_DTU, ON);
  1497. }
  1498. else
  1499. {
  1500. LOG_W("RTU电源复位!!!");
  1501. rt_pin_write(RTU_DTU, OFF);
  1502. }
  1503. }
  1504. // 海康拍照
  1505. void Hk_Take_io(void)
  1506. {
  1507. rt_pin_mode(HK_TAKE, PIN_MODE_OUTPUT);
  1508. rt_pin_mode(HK_IO, PIN_MODE_OUTPUT);
  1509. rt_pin_write(HK_TAKE, 1);
  1510. rt_pin_write(HK_IO, 0);
  1511. if (device_status.dtype == 3)
  1512. Beep_Tip(1000);
  1513. if (device_status.dtype == 7)
  1514. rt_thread_mdelay(1000);
  1515. rt_pin_write(HK_TAKE, 0);
  1516. rt_pin_write(HK_IO, 1);
  1517. }
  1518. /**
  1519. * @brief 控制执行加热动作
  1520. *
  1521. * @param heat_time 加热时间(秒)
  1522. */
  1523. void calorstat(uint16_t heat_time)
  1524. {
  1525. // uint8_t heat_up_cnt = 0;
  1526. uint16_t n = 0;
  1527. uint16_t delay_heat = 60;
  1528. FlagStatus heat_flg = RESET;
  1529. device_status.heat_time_min = 0;
  1530. device_status.run_sta = device_status.heattem; // 初始化加热实时温度
  1531. ctr_Heat(ON);
  1532. // UpLoad_Data(); //开始加热时的第一条数据
  1533. // 恒温模式
  1534. for (n = 0; n < heat_time; n++)
  1535. {
  1536. if (device_status.heattem > device_status.heatvalue && heat_flg == RESET)
  1537. {
  1538. heat_flg = SET;
  1539. ctr_Heat(OFF);
  1540. while (delay_heat != 0)
  1541. {
  1542. delay_heat--;
  1543. rt_kprintf("正在恒温加热!!!:%d", delay_heat);
  1544. HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"", delay_heat);
  1545. rt_thread_delay(1000);
  1546. if (device_status.heattem > device_status.run_sta + 1)
  1547. {
  1548. device_status.run_sta = device_status.heattem;
  1549. }
  1550. }
  1551. delay_heat = 60;
  1552. // 跳出FOR循环
  1553. n = n + 60;
  1554. }
  1555. if (device_status.heattem < (device_status.heatvalue - 5) && heat_flg == SET)
  1556. {
  1557. device_status.run_sta = device_status.heattem;
  1558. ctr_Heat(ON);
  1559. }
  1560. else if (device_status.heattem >= device_status.heatvalue && heat_flg == SET)
  1561. {
  1562. // if(heat_up_cnt==0)
  1563. // {
  1564. // UpLoad_Data(); //加热到设定温度的数据
  1565. // heat_up_cnt = 1;
  1566. // }
  1567. device_status.run_sta = device_status.heattem;
  1568. ctr_Heat(OFF);
  1569. }
  1570. if ((n % 60) == 0)
  1571. {
  1572. device_status.heat_time_min = device_status.heat_time_min + 1;
  1573. // if(device_status.heat_time_min % 5 == 0)
  1574. // {
  1575. // UpLoad_Data(); //从加热开始每5分钟上传的数据
  1576. // }
  1577. }
  1578. // 如果触发异常退出加热
  1579. if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1)
  1580. {
  1581. rt_thread_delay(1000);
  1582. if (device_status.bat_status == 1)
  1583. {
  1584. rt_kprintf("============================触发异常退出加热==========================");
  1585. ctr_lamp(OFF, 1);
  1586. ctr_Heat(OFF);
  1587. break;
  1588. }
  1589. }
  1590. if (device_status.timeSwitch == 0 && device_status.sun_status == 1)
  1591. {
  1592. ctr_Heat(OFF);
  1593. rt_kprintf("异常退出!!!\n");
  1594. break;
  1595. }
  1596. rt_thread_delay(1000);
  1597. rt_kprintf("=======正在加热======:%d-%d\n", n, heat_time);
  1598. HMI_WRITE("workSta.g0.txt=\"正在加热!!!:%d-%d\"", n, heat_time);
  1599. }
  1600. ctr_Heat(OFF);
  1601. // UpLoad_Data(); //加热结束的数据
  1602. }
  1603. // 初始化所有控制驱动,关闭
  1604. void HardWare_Init(uint8_t boot)
  1605. {
  1606. Beep_Tip(200);
  1607. // 关闭上仓门
  1608. ctr_cangmen_up(OFF);
  1609. if (device_status.dtype == 3)
  1610. {
  1611. // 关闭下仓门电机
  1612. ctr_cangmen_down(OFF);
  1613. }
  1614. // 关闭镇流器
  1615. if (device_status.autotakepic == 0)
  1616. ctr_lamp(OFF, 1);
  1617. // 关闭震动电机
  1618. ctr_shake(OFF, 0);
  1619. // 关闭加热
  1620. ctr_Heat(OFF);
  1621. // 关闭补光灯
  1622. ctr_led(OFF);
  1623. // 关闭12V供电(海康相机,RTU)
  1624. ctr_photo(OFF);
  1625. }
  1626. // 拍照
  1627. void HK_TakePhoto(void)
  1628. {
  1629. // 打开补光灯
  1630. DTU_Write("takephoto.mp3");
  1631. rt_thread_delay(1000);
  1632. char *takephotojson = makeJson_takephoto();
  1633. DTU_Write("%s", takephotojson);
  1634. rt_free(takephotojson);
  1635. // 吸虫塔
  1636. if (device_status.version_type != 6)
  1637. {
  1638. ctr_led(ON);
  1639. if (device_status.version_type == 48)
  1640. {
  1641. rt_thread_delay(1000 * 60);
  1642. }
  1643. else
  1644. {
  1645. rt_thread_delay(1000 * 15);
  1646. }
  1647. }
  1648. // 触发海康相机拍照
  1649. Hk_Take_io();
  1650. if (device_status.version_type != 6)
  1651. {
  1652. rt_thread_delay(1000 * 45);
  1653. }
  1654. else
  1655. {
  1656. ctr_led(ON);
  1657. rt_thread_delay(1000 * 19);
  1658. }
  1659. ctr_led(OFF);
  1660. }
  1661. // 光控测试任务
  1662. void SunTest(void)
  1663. {
  1664. rt_uint16_t ui_timeout_l = 0;
  1665. // 未检测到光照,一秒扫描等待,超时30S
  1666. while (Read_Light_Voltage() < 500)
  1667. {
  1668. ui_timeout_l++;
  1669. rt_thread_delay(1000);
  1670. if (ui_timeout_l == 30)
  1671. break;
  1672. }
  1673. rt_thread_delay(3000);
  1674. if (Read_Light_Voltage() < 500)
  1675. {
  1676. device_status.sun_status = 0; // 光控状态
  1677. }
  1678. if (Read_Light_Voltage() > 500)
  1679. {
  1680. rt_thread_delay(1000);
  1681. }
  1682. rt_thread_delay(3000);
  1683. if (Read_Light_Voltage() > 500)
  1684. {
  1685. device_status.sun_status = 1;
  1686. ctr_lamp(OFF, 1);
  1687. }
  1688. HMI_WRITE("sysTest.switchSun.val=%d", 0);
  1689. device_status.sun_test = 0;
  1690. device_status.work_status = 0;
  1691. }
  1692. /*上电初始化*/
  1693. void ResetInit(void)
  1694. {
  1695. if (device_status.dtype == 7)
  1696. {
  1697. ctr_Motor_Driver(0, 0, 0, 0);
  1698. // 关闭电磁阀
  1699. ctr_shake(OFF, 0);
  1700. // 关闭加热
  1701. ctr_Heat(OFF);
  1702. // 关闭制冷
  1703. ctr_Cold(OFF);
  1704. // 关闭补光灯
  1705. ctr_led(OFF);
  1706. // 转盘复位
  1707. if (device_status.run_sta == 0)
  1708. ctr_turn(0, 0);
  1709. }
  1710. if (device_status.version_type != 6 && device_status.version_type != vt_BZY && device_status.version_type != vt_BZY_JD)
  1711. {
  1712. device_status.work_done = 1;
  1713. // 1.打开路由器供电
  1714. if (device_status.power_status == 1)
  1715. {
  1716. ctr_router(ON);
  1717. ctr_RTU_DTU(ON);
  1718. // 2.打开相机供电
  1719. ctr_photo(ON);
  1720. }
  1721. // 3.关闭镇流器
  1722. ctr_lamp(OFF, 1);
  1723. #if LAMP_EN == 1
  1724. ctr_lamp(OFF, 2);
  1725. ctr_lamp(OFF, 3);
  1726. #endif
  1727. // 4.关闭震动电机
  1728. ctr_shake(OFF, 0);
  1729. // 5.关闭加热
  1730. ctr_Heat(OFF);
  1731. // 6.关闭补光灯
  1732. ctr_led(OFF);
  1733. if (device_status.bat_status == 1 || atoi(device_status.fuse_voltage) < 1)
  1734. {
  1735. LOG_W("欠压!");
  1736. return;
  1737. }
  1738. // 7.关闭上仓门
  1739. device_status.ctr_up_motor = 2;
  1740. // while(device_status.ctr_up_motor!=0)
  1741. // {
  1742. // LOG_I("关闭上仓门...");
  1743. // rt_thread_delay(100);
  1744. // }
  1745. // 8.关闭下仓门
  1746. device_status.ctr_down_motor = 2;
  1747. while (device_status.ctr_down_motor != 0)
  1748. {
  1749. LOG_I("关闭下仓门....");
  1750. rt_thread_delay(100);
  1751. }
  1752. // 9.清扫
  1753. if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1)
  1754. {
  1755. LOG_W("异常退出!!!\n");
  1756. return;
  1757. }
  1758. #if LAMP_EN == 0
  1759. ctr_Fan_PUT(OFF);
  1760. ctr_Fan_IN(OFF);
  1761. #endif
  1762. if (device_status.version_type == 4 || device_status.version_type == 41)
  1763. {
  1764. device_status.clear_status = 1;
  1765. }
  1766. else if (device_status.version_type == 1)
  1767. {
  1768. turnzp();
  1769. }
  1770. rt_thread_delay(1000);
  1771. }
  1772. else if(device_status.version_type == vt_BZY_JD)
  1773. {
  1774. // 6.关闭补光灯
  1775. ctr_led(OFF);
  1776. }
  1777. else
  1778. {
  1779. if (device_status.power_status == 1)
  1780. {
  1781. // 1.打开路由器供电
  1782. ctr_router(ON);
  1783. ctr_RTU_DTU(ON);
  1784. // 2.打开相机供电
  1785. ctr_photo(ON);
  1786. }
  1787. // 5.关闭加热
  1788. // 6.关闭补光灯
  1789. ctr_led(OFF);
  1790. }
  1791. }
  1792. /*三色光源*/
  1793. void Led_Check(uint8_t tp)
  1794. {
  1795. if (tp == 3)
  1796. {
  1797. if (device_status.light_over_tim > 2 * 3600)
  1798. {
  1799. device_status.work_status = 1;
  1800. device_status.lamp_status = 1;
  1801. device_status.lamp1_status = 0;
  1802. device_status.lamp2_status = 0;
  1803. LOG_I("光控定时,计时中:光源1计数:%d", device_status.light_over_tim);
  1804. }
  1805. else if (device_status.light_over_tim > 3600 && device_status.light_over_tim < 7200)
  1806. {
  1807. device_status.work_status = 1;
  1808. device_status.lamp_status = 0;
  1809. device_status.lamp1_status = 1;
  1810. device_status.lamp2_status = 0;
  1811. LOG_I("光控定时,计时中:光源2计数:%d", device_status.light_over_tim);
  1812. }
  1813. else if (device_status.light_over_tim < 1 * 3600)
  1814. {
  1815. device_status.work_status = 1;
  1816. device_status.lamp_status = 0;
  1817. device_status.lamp1_status = 0;
  1818. device_status.lamp2_status = 1;
  1819. LOG_I("光控定时,计时中:光源3计数:%d", device_status.light_over_tim);
  1820. }
  1821. }
  1822. else if (tp == 6)
  1823. {
  1824. if (device_status.light_over_tim > 4 * 3600)
  1825. {
  1826. device_status.work_status = 1;
  1827. device_status.lamp_status = 1;
  1828. device_status.lamp1_status = 0;
  1829. device_status.lamp2_status = 0;
  1830. LOG_I("光控定时,计时中:光源1计数:%d", device_status.light_over_tim);
  1831. }
  1832. else if (device_status.light_over_tim < 14400 && device_status.light_over_tim > 7200)
  1833. {
  1834. device_status.work_status = 1;
  1835. device_status.lamp_status = 0;
  1836. device_status.lamp1_status = 1;
  1837. device_status.lamp2_status = 0;
  1838. LOG_I("光控定时,计时中:光源2计数:%d", device_status.light_over_tim);
  1839. }
  1840. else if (device_status.light_over_tim < 7200)
  1841. {
  1842. device_status.work_status = 1;
  1843. device_status.lamp_status = 0;
  1844. device_status.lamp1_status = 0;
  1845. device_status.lamp2_status = 1;
  1846. LOG_I("光控定时,计时中:光源3计数:%d", device_status.light_over_tim);
  1847. }
  1848. }
  1849. else if (tp == 9)
  1850. {
  1851. if (device_status.light_over_tim > 6 * 3600)
  1852. {
  1853. device_status.work_status = 1;
  1854. device_status.lamp_status = 1;
  1855. device_status.lamp1_status = 0;
  1856. device_status.lamp2_status = 0;
  1857. LOG_I("光控定时,计时中:光源1计数:%d", device_status.light_over_tim);
  1858. }
  1859. else if (device_status.light_over_tim < 6 * 3600 && device_status.light_over_tim > 3 * 3600)
  1860. {
  1861. device_status.work_status = 1;
  1862. device_status.lamp_status = 0;
  1863. device_status.lamp1_status = 1;
  1864. device_status.lamp2_status = 0;
  1865. LOG_I("光控定时,计时中:光源2计数:%d", device_status.light_over_tim);
  1866. }
  1867. else if (device_status.light_over_tim < 3 * 3600)
  1868. {
  1869. device_status.work_status = 1;
  1870. device_status.lamp_status = 0;
  1871. device_status.lamp1_status = 0;
  1872. device_status.lamp2_status = 1;
  1873. LOG_I("光控定时,计时中:光源3计数:%d", device_status.light_over_tim);
  1874. }
  1875. }
  1876. }
  1877. // 出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
  1878. void HardWare_Check(uint8_t boot)
  1879. {
  1880. if (boot == 0 && device_status.version_type != 6)
  1881. {
  1882. // 停止所有动作 -完成
  1883. HardWare_Init(boot);
  1884. }
  1885. else
  1886. {
  1887. // 停止所有动作
  1888. // 读取记录待机功耗(实测大概70mA)
  1889. //(需减去屏幕的功耗大概120mA)
  1890. // 动作上仓门,读取功率值保存
  1891. // 动作下仓门,读取功率值保存
  1892. // 动作清扫,读取功率值保存
  1893. // 打开镇流器,读取功率值保存
  1894. // 打开海康相机供电,读取功率值保存
  1895. // 打开补光灯,读取功率值保存
  1896. // 打开路由器/RTU供电,读取功率值保存
  1897. // 打开加热,读取功率值保存
  1898. }
  1899. }
  1900. // 工作状态检测
  1901. void WorkCheck(void)
  1902. {
  1903. uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
  1904. static int8_t log_en_cnt = -1;
  1905. // 雨控检测,温控检测,电池电压检测
  1906. while (device_status.ds == 1 && device_status.rain_status == 0 && device_status.temp_status == 0 && device_status.bat_status == 0)
  1907. {
  1908. // 工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
  1909. if (device_status.timeSwitch == 1)
  1910. {
  1911. LOG_I("***********时控*****************");
  1912. // 如果开始和结束是同一天
  1913. if (device_status.startBar < device_status.stopBar)
  1914. {
  1915. LOG_I("开始和结束是同一天");
  1916. time_t now;
  1917. time(&now);
  1918. static struct tm nowtime; // 现在
  1919. static struct tm starttime; // 开始
  1920. static struct tm endtime; // 结束
  1921. // 获取当前时间戳
  1922. nowtime = *localtime(&now);
  1923. nowtime.tm_hour = nowtime.tm_hour - 8;
  1924. // 获取定时开始的时间戳
  1925. starttime = *localtime(&now);
  1926. starttime.tm_hour = device_status.startBar - 8;
  1927. starttime.tm_min = 0;
  1928. starttime.tm_sec = 0;
  1929. // 获取定时结束的时间戳
  1930. endtime = *localtime(&now);
  1931. endtime.tm_hour = device_status.stopBar - 8;
  1932. endtime.tm_min = 0;
  1933. endtime.tm_sec = 0;
  1934. LOG_I("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***", mktime(&nowtime), mktime(&starttime), mktime(&endtime));
  1935. // 如果当前时间大于开始时间且小于结束时间,且没有开始工作
  1936. if ((difftime(mktime(&nowtime), mktime(&starttime)) >= 0) && (difftime(mktime(&nowtime), mktime(&endtime)) < 0))
  1937. {
  1938. LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
  1939. device_status.work_status = 1;
  1940. }
  1941. // 如果当前时间小于开始时间
  1942. else if (difftime(mktime(&nowtime), mktime(&starttime)) < 0)
  1943. {
  1944. LOG_I("当前时间小于开始时间,不工作!!!-%d-%d", mktime(&nowtime), mktime(&starttime));
  1945. device_status.work_status = 0;
  1946. }
  1947. // 当前时间大于结束时间
  1948. else
  1949. {
  1950. LOG_I("当前时间大于结束时间,不工作!!!-%d-%d", mktime(&nowtime), mktime(&starttime));
  1951. device_status.work_status = 0;
  1952. }
  1953. #if LAMP_EN == 1
  1954. // 如果当前时间超过20点,未到21点
  1955. if ((difftime(mktime(&nowtime), mktime(&starttime)) >= 0) && (difftime(mktime(&nowtime), mktime(&starttime) + 3600) < 0))
  1956. {
  1957. LOG_I("3led:20~21");
  1958. device_status.lamp_status = 1;
  1959. device_status.lamp1_status = 0;
  1960. device_status.lamp2_status = 0;
  1961. }
  1962. else if ((difftime(mktime(&nowtime), mktime(&starttime) + 3600) >= 0) && (difftime(mktime(&nowtime), mktime(&starttime) + 7200) < 0))
  1963. {
  1964. LOG_I("3led:21~22");
  1965. device_status.lamp1_status = 1;
  1966. device_status.lamp_status = 0;
  1967. device_status.lamp2_status = 0;
  1968. }
  1969. else if ((difftime(mktime(&nowtime), mktime(&starttime) + 7200) >= 0) && (difftime(mktime(&nowtime), mktime(&starttime) + 10800) < 0))
  1970. {
  1971. LOG_I("3led:22~23");
  1972. device_status.lamp2_status = 1;
  1973. device_status.lamp_status = 0;
  1974. device_status.lamp1_status = 0;
  1975. }
  1976. #endif
  1977. }
  1978. // 如果结束时间是第二天
  1979. else if (device_status.startBar > device_status.stopBar)
  1980. {
  1981. time_t now;
  1982. time(&now);
  1983. static struct tm nowtime; // 现在
  1984. static struct tm starttime; // 开始
  1985. static struct tm endtime; // 结束
  1986. // 获取当前时间戳
  1987. nowtime = *localtime(&now);
  1988. nowtime.tm_hour = nowtime.tm_hour - 8;
  1989. // 获取定时开始的时间戳
  1990. starttime = *localtime(&now);
  1991. starttime.tm_hour = device_status.startBar - 8;
  1992. starttime.tm_min = 0;
  1993. starttime.tm_sec = 0;
  1994. // 获取定时结束的时间戳
  1995. endtime = *localtime(&now);
  1996. endtime.tm_hour = device_status.stopBar - 8;
  1997. endtime.tm_min = 0;
  1998. endtime.tm_sec = 0;
  1999. LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!", mktime(&nowtime), mktime(&starttime), mktime(&endtime));
  2000. // 如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
  2001. if ((difftime(mktime(&nowtime), mktime(&starttime)) > 0))
  2002. {
  2003. // 获取定时结束的时间戳
  2004. endtime = *localtime(&now); // 将获取到的时间转换为时间戳
  2005. endtime.tm_hour = device_status.stopBar - 8; // 这里需减8用于时区转换
  2006. endtime.tm_min = 0;
  2007. endtime.tm_sec = 0;
  2008. device_status.work_status = 1;
  2009. LOG_I("当前前时间大于开始时间,且没有开始工作");
  2010. }
  2011. // 当前时间小于开始时间
  2012. else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
  2013. {
  2014. // 获取定时结束的时间戳
  2015. endtime = *localtime(&now); // 将获取到的时间转换为时间戳
  2016. endtime.tm_hour = device_status.stopBar - 8; // 这里需减8用于时区转换
  2017. endtime.tm_min = 0;
  2018. endtime.tm_sec = 0;
  2019. // 如果当前时间戳小于结束时间戳
  2020. if (difftime(mktime(&nowtime), mktime(&endtime)) < 0)
  2021. {
  2022. LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
  2023. device_status.work_status = 1;
  2024. }
  2025. else
  2026. {
  2027. LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
  2028. device_status.work_status = 0; // 不在工作时间,待机
  2029. }
  2030. }
  2031. }
  2032. }
  2033. else
  2034. {
  2035. LOG_I("光控定时模式!");
  2036. /*
  2037. time_t now;
  2038. time(&now);
  2039. static struct tm nowstamp;
  2040. nowstamp =*localtime(&now);
  2041. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  2042. static rt_uint32_t nowstamp_num = 0;
  2043. nowstamp_num = mktime(&nowstamp);
  2044. rt_kprintf("now stamp:%d\n",nowstamp_num);
  2045. */
  2046. if (device_status.sun_status == 0 && device_status.light_over_tim != 0)
  2047. {
  2048. device_status.light_over_tim--;
  2049. #if LAMP_EN == 1
  2050. Led_Check(device_status.sunBar);
  2051. #else
  2052. device_status.work_status = 1;
  2053. ;
  2054. LOG_I("光控定时,计时中>>>>>>>>>:%d", device_status.light_over_tim);
  2055. #endif
  2056. }
  2057. else
  2058. {
  2059. if (device_status.test_flag == 0)
  2060. {
  2061. ctr_lamp(OFF, 1);
  2062. #if LAMP_EN == 1
  2063. ctr_lamp(OFF, 2);
  2064. ctr_lamp(OFF, 3);
  2065. #endif
  2066. }
  2067. device_status.work_status = 0;
  2068. if (device_status.light_over_tim == 0 && device_status.sun_status == 1)
  2069. device_status.light_over_tim = device_status.sunBar * 3600;
  2070. LOG_I("光控中,白天:%d!!!", device_status.sun_status);
  2071. }
  2072. }
  2073. rt_thread_delay(1000);
  2074. }
  2075. if (chk_log_time)
  2076. {
  2077. LOG_I("雨控状态,温控状态,电压状态:%d-%d-%d", device_status.rain_status, device_status.temp_status, device_status.bat_status);
  2078. }
  2079. device_status.work_status = 0;
  2080. rt_thread_delay(1000);
  2081. }
  2082. /**
  2083. * @brief 孢子仪工作线程
  2084. *
  2085. */
  2086. void WorkTask_BZY(void)
  2087. {
  2088. if (device_status.ds == 1)
  2089. {
  2090. // 时间段判断
  2091. // 先判断第一个时间段
  2092. time_t now;
  2093. time(&now);
  2094. static struct tm now_stamp; // 现在
  2095. static struct tm cul_sh1_stamp; // 开始1
  2096. static struct tm cul_eh1_stamp; // 结束1
  2097. static struct tm cul_sh2_stamp; // 开始2
  2098. static struct tm cul_eh2_stamp; // 结束2
  2099. static struct tm cul_sh3_stamp; // 开始3
  2100. static struct tm cul_eh3_stamp; // 结束3
  2101. now_stamp = *localtime(&now);
  2102. // 获取定时开始的时间戳
  2103. cul_sh1_stamp = *localtime(&now);
  2104. cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2105. cul_sh1_stamp.tm_min = 0;
  2106. cul_sh1_stamp.tm_sec = 0;
  2107. cul_sh2_stamp = *localtime(&now);
  2108. cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2109. cul_sh2_stamp.tm_min = 0;
  2110. cul_sh2_stamp.tm_sec = 0;
  2111. cul_sh3_stamp = *localtime(&now);
  2112. cul_sh3_stamp.tm_hour = device_status.collecting_sh3;
  2113. cul_sh3_stamp.tm_min = 0;
  2114. cul_sh3_stamp.tm_sec = 0;
  2115. // 获取定时结束的时间戳
  2116. cul_eh1_stamp = *localtime(&now);
  2117. cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2118. cul_eh1_stamp.tm_min = 0;
  2119. cul_eh1_stamp.tm_sec = 0;
  2120. cul_eh2_stamp = *localtime(&now);
  2121. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2122. cul_eh2_stamp.tm_min = 0;
  2123. cul_eh2_stamp.tm_sec = 0;
  2124. cul_eh3_stamp = *localtime(&now);
  2125. cul_eh3_stamp.tm_hour = device_status.collecting_eh3;
  2126. cul_eh3_stamp.tm_min = 0;
  2127. cul_eh3_stamp.tm_sec = 0;
  2128. 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);
  2129. 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);
  2130. 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);
  2131. 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);
  2132. 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);
  2133. 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);
  2134. // 此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
  2135. // 当前时间戳小于第一段开始时间戳
  2136. if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
  2137. {
  2138. time_t now;
  2139. time(&now);
  2140. cul_sh1_stamp = *localtime(&now);
  2141. cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2142. cul_sh1_stamp.tm_min = 0;
  2143. cul_sh1_stamp.tm_sec = 0;
  2144. now_stamp = *localtime(&now);
  2145. 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);
  2146. 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);
  2147. LOG_D("run_sta:%d", device_status.run_sta);
  2148. }
  2149. // 当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
  2150. if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
  2151. {
  2152. time_t now;
  2153. time(&now);
  2154. cul_sh2_stamp = *localtime(&now);
  2155. cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2156. cul_sh2_stamp.tm_min = 0;
  2157. cul_sh2_stamp.tm_sec = 0;
  2158. now_stamp = *localtime(&now);
  2159. 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);
  2160. 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);
  2161. LOG_D("run_sta:%d", device_status.run_sta);
  2162. }
  2163. // 如果当前 时间戳大于开始时间戳并且小于 结束时间戳
  2164. if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
  2165. {
  2166. // 转盘到涂凡士林位置
  2167. if (device_status.run_sta == 0)
  2168. {
  2169. LOG_I("start to collect!!!");
  2170. DTU_Write("collect.mp3");
  2171. ctr_turn(90, 4);
  2172. rt_thread_delay(2000);
  2173. // 涂凡士林
  2174. ctr_Petroleum_jelly(10);
  2175. rt_thread_delay(5000);
  2176. }
  2177. /*转盘到采集位置*/
  2178. if (device_status.run_sta == 4)
  2179. ctr_turn(90, 1);
  2180. // 只有开始和结束时刻不同的时间段,才有效
  2181. if ((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0) || (difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0))
  2182. {
  2183. if ((difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0) && difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) > 0)
  2184. {
  2185. device_status.work_status = 1;
  2186. ctr_Collect_Fan(ON);
  2187. // 当前时间戳小于第一段结束时间戳
  2188. while (difftime(mktime(&cul_eh1_stamp), mktime(&now_stamp)) > 0)
  2189. {
  2190. time(&now);
  2191. now_stamp = *localtime(&now);
  2192. cul_eh1_stamp = *localtime(&now);
  2193. cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2194. cul_eh1_stamp.tm_min = 0;
  2195. cul_eh1_stamp.tm_sec = 0;
  2196. if (device_status.run_sta != 1)
  2197. break;
  2198. LOG_I("1===========采集风机启动,正在收集.....%d-%d", mktime(&now_stamp), mktime(&cul_eh1_stamp));
  2199. rt_thread_mdelay(10000);
  2200. }
  2201. }
  2202. else
  2203. {
  2204. device_status.work_status = 0;
  2205. ctr_Collect_Fan(OFF);
  2206. LOG_I("未到收集1时间!");
  2207. }
  2208. if (difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0 && difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) > 0)
  2209. {
  2210. device_status.work_status = 1;
  2211. ctr_Collect_Fan(ON);
  2212. while (difftime(mktime(&cul_eh2_stamp), mktime(&now_stamp)) > 0)
  2213. {
  2214. time(&now);
  2215. now_stamp = *localtime(&now);
  2216. cul_eh2_stamp = *localtime(&now);
  2217. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2218. cul_eh2_stamp.tm_min = 0;
  2219. cul_eh2_stamp.tm_sec = 0;
  2220. if (device_status.run_sta != 1)
  2221. break;
  2222. LOG_I("2===========采集风机启动,正在收集.....%d-%d", mktime(&now_stamp), mktime(&cul_eh2_stamp));
  2223. rt_thread_mdelay(10000);
  2224. }
  2225. }
  2226. else
  2227. {
  2228. device_status.work_status = 0;
  2229. ctr_Collect_Fan(OFF);
  2230. LOG_I("未到收集2时间!");
  2231. }
  2232. }
  2233. else
  2234. {
  2235. LOG_I("this collect time is 0s,The wait time cannot be negative!");
  2236. }
  2237. }
  2238. if (device_status.run_sta == 2)
  2239. {
  2240. ctr_Collect_Fan(OFF);
  2241. device_status.develop_flag = 1;
  2242. device_status.work_status = 2;
  2243. ctr_develop(); // 培养
  2244. ctr_turn(90, 3);
  2245. }
  2246. if (device_status.run_sta == 3)
  2247. {
  2248. ctr_Collect_Fan(OFF);
  2249. device_status.work_status = 3;
  2250. device_status.autotakepic = 1; // 对焦拍照
  2251. }
  2252. // 在培养之前再次确认时间戳
  2253. time(&now);
  2254. now_stamp = *localtime(&now);
  2255. cul_eh2_stamp = *localtime(&now);
  2256. cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2257. cul_eh2_stamp.tm_min = 0;
  2258. cul_eh2_stamp.tm_sec = 0;
  2259. // 当前时间戳大于收集结束时间戳并且run_sta==1
  2260. if (device_status.run_sta == 1 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) > 0)
  2261. {
  2262. ctr_Collect_Fan(OFF);
  2263. LOG_I("===============collect ok,turn to drop!!!");
  2264. device_status.develop_flag = 1;
  2265. device_status.work_status = 2; // 现在是培养
  2266. DTU_Write("develop.mp3");
  2267. if (device_status.run_sta == 1)
  2268. ctr_turn(90, 2); /*转盘到培养位置*/
  2269. rt_thread_delay(1000);
  2270. ctr_shake(ON, device_status.shake_sec);
  2271. rt_thread_delay(1000);
  2272. ctr_develop(); // 培养
  2273. if (device_status.run_sta == 2)
  2274. ctr_turn(90, 3); /*转盘到拍照位置*/
  2275. rt_thread_delay(1000);
  2276. device_status.work_status = 3; // 现在是拍照
  2277. device_status.autotakepic = 1; // 对焦拍照
  2278. while (device_status.autotakepic == 0)
  2279. {
  2280. rt_thread_delay(1000);
  2281. LOG_I("正在对焦拍照............");
  2282. }
  2283. device_status.work_status = 0; // 待机
  2284. DTU_Write("wait.mp3");
  2285. LOG_I("=====================work finished==================");
  2286. }
  2287. rt_thread_delay(1000);
  2288. }
  2289. device_status.work_status = 0; // 待机
  2290. LOG_W("==================!!!设备已待机!!!===================");
  2291. }
  2292. /*********************↓ 胶带结构的孢子仪主工作流程 ↓************************/
  2293. ///**
  2294. // * @brief 检查是否到工作时间段
  2295. // *
  2296. // * @return uint8_t 0-未到 / 已到:时间段编号(1-2-3)
  2297. // */
  2298. // static uint8_t Confirm_time_period(void)
  2299. //{
  2300. // static uint8_t once_print = 0;
  2301. //
  2302. // uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
  2303. // static int8_t log_en_cnt = -1;
  2304. //
  2305. // uint8_t time_period = 0;
  2306. //
  2307. // // 时间段判断
  2308. // // 先判断第一个时间段
  2309. // time_t now;
  2310. // time(&now);
  2311. // static struct tm now_stamp; // 现在
  2312. // static struct tm cul_sh1_stamp; // 开始1
  2313. // static struct tm cul_eh1_stamp; // 结束1
  2314. // static struct tm cul_sh2_stamp; // 开始2
  2315. // static struct tm cul_eh2_stamp; // 结束2
  2316. // static struct tm cul_sh3_stamp; // 开始3
  2317. // static struct tm cul_eh3_stamp; // 结束3
  2318. // now_stamp = *localtime(&now);
  2319. // // 获取定时开始的时间戳
  2320. // cul_sh1_stamp = *localtime(&now);
  2321. // cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2322. // cul_sh1_stamp.tm_min = 0;
  2323. // cul_sh1_stamp.tm_sec = 0;
  2324. // cul_sh2_stamp = *localtime(&now);
  2325. // cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2326. // cul_sh2_stamp.tm_min = 0;
  2327. // cul_sh2_stamp.tm_sec = 0;
  2328. // cul_sh3_stamp = *localtime(&now);
  2329. // cul_sh3_stamp.tm_hour = device_status.collecting_sh3;
  2330. // cul_sh3_stamp.tm_min = 0;
  2331. // cul_sh3_stamp.tm_sec = 0;
  2332. // // 获取定时结束的时间戳
  2333. // cul_eh1_stamp = *localtime(&now);
  2334. // cul_eh1_stamp.tm_hour = device_status.collecting_eh1;
  2335. // cul_eh1_stamp.tm_min = 0;
  2336. // cul_eh1_stamp.tm_sec = 0;
  2337. // cul_eh2_stamp = *localtime(&now);
  2338. // cul_eh2_stamp.tm_hour = device_status.collecting_eh2;
  2339. // cul_eh2_stamp.tm_min = 0;
  2340. // cul_eh2_stamp.tm_sec = 0;
  2341. // cul_eh3_stamp = *localtime(&now);
  2342. // cul_eh3_stamp.tm_hour = device_status.collecting_eh3;
  2343. // cul_eh3_stamp.tm_min = 0;
  2344. // cul_eh3_stamp.tm_sec = 0;
  2345. //
  2346. //
  2347. // if (once_print == 0)
  2348. // {
  2349. // 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);
  2350. // 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);
  2351. // 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);
  2352. // 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);
  2353. // 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);
  2354. // 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);
  2355. // once_print = 1;
  2356. // }
  2357. //
  2358. // // 此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
  2359. // // 当前时间戳小于第一段开始时间戳
  2360. // if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
  2361. // {
  2362. // time_t now;
  2363. // time(&now);
  2364. // cul_sh1_stamp = *localtime(&now);
  2365. // cul_sh1_stamp.tm_hour = device_status.collecting_sh1;
  2366. // cul_sh1_stamp.tm_min = 0;
  2367. // cul_sh1_stamp.tm_sec = 0;
  2368. // now_stamp = *localtime(&now);
  2369. //
  2370. // if (chk_log_time)
  2371. // {
  2372. // 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);
  2373. // 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);
  2374. // LOG_D("run_sta:%d", device_status.run_sta);
  2375. // }
  2376. //
  2377. // time_period = 0;
  2378. // }
  2379. // // 当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
  2380. // if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
  2381. // {
  2382. // time_t now;
  2383. // time(&now);
  2384. // cul_sh2_stamp = *localtime(&now);
  2385. // cul_sh2_stamp.tm_hour = device_status.collecting_sh2;
  2386. // cul_sh2_stamp.tm_min = 0;
  2387. // cul_sh2_stamp.tm_sec = 0;
  2388. // now_stamp = *localtime(&now);
  2389. // if (chk_log_time)
  2390. // {
  2391. // 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);
  2392. // 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);
  2393. // LOG_D("run_sta:%d", device_status.run_sta);
  2394. // log_en_cnt = 0;
  2395. // }
  2396. //
  2397. // time_period = 0;
  2398. // }
  2399. //
  2400. // // 如果当前 时间戳大于开始时间戳并且小于 结束时间戳
  2401. // if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) < 0)
  2402. // {
  2403. // time_period = 1;
  2404. // }
  2405. // else if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
  2406. // {
  2407. // time_period = 2;
  2408. // }
  2409. // else if (difftime(mktime(&now_stamp), mktime(&cul_sh3_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh3_stamp)) < 0)
  2410. // {
  2411. // time_period = 3;
  2412. // }
  2413. //
  2414. // return time_period;
  2415. //}
  2416. #define test_min 40
  2417. /**
  2418. * @brief 检查是否到工作时间段
  2419. *
  2420. * @return uint8_t 0-未到 / 已到:时间段编号(1-2-3)
  2421. */
  2422. static uint8_t Confirm_time_period(void)
  2423. {
  2424. static uint8_t once_print = 0;
  2425. uint8_t log_en_inr = LOG_INR * 3; // 打印log的速度 数值越小 打印越频繁
  2426. static int8_t log_en_cnt = -1;
  2427. uint8_t time_period = 0;
  2428. // 时间段判断
  2429. // 先判断第一个时间段
  2430. time_t now;
  2431. time(&now);
  2432. static struct tm now_stamp; // 现在
  2433. static struct tm cul_sh1_stamp; // 开始1
  2434. static struct tm cul_eh1_stamp; // 结束1
  2435. static struct tm cul_sh2_stamp; // 开始2
  2436. static struct tm cul_eh2_stamp; // 结束2
  2437. static struct tm cul_sh3_stamp; // 开始3
  2438. static struct tm cul_eh3_stamp; // 结束3
  2439. now_stamp = *localtime(&now);
  2440. // 获取定时开始的时间戳
  2441. cul_sh1_stamp = *localtime(&now);
  2442. cul_sh1_stamp.tm_min = device_status.collecting_sh1 + test_min;
  2443. //cul_sh1_stamp.tm_hour = 0;
  2444. cul_sh1_stamp.tm_sec = 0;
  2445. cul_sh2_stamp = *localtime(&now);
  2446. cul_sh2_stamp.tm_min = device_status.collecting_sh2 + test_min;
  2447. //cul_sh2_stamp.tm_hour = 0;
  2448. cul_sh2_stamp.tm_sec = 0;
  2449. cul_sh3_stamp = *localtime(&now);
  2450. cul_sh3_stamp.tm_min = device_status.collecting_sh3 + test_min;
  2451. //cul_sh3_stamp.tm_hour = 0;
  2452. cul_sh3_stamp.tm_sec = 0;
  2453. // 获取定时结束的时间戳
  2454. cul_eh1_stamp = *localtime(&now);
  2455. cul_eh1_stamp.tm_min = device_status.collecting_eh1 + test_min;
  2456. //cul_eh1_stamp.tm_hour = 0;
  2457. cul_eh1_stamp.tm_sec = 0;
  2458. cul_eh2_stamp = *localtime(&now);
  2459. cul_eh2_stamp.tm_min = device_status.collecting_eh2 + test_min;
  2460. //cul_eh2_stamp.tm_hour = 0;
  2461. cul_eh2_stamp.tm_sec = 0;
  2462. cul_eh3_stamp = *localtime(&now);
  2463. cul_eh3_stamp.tm_min = device_status.collecting_eh3 + test_min;
  2464. //cul_eh3_stamp.tm_hour = 0;
  2465. cul_eh3_stamp.tm_sec = 0;
  2466. if (once_print == 0 || chk_log_time)
  2467. {
  2468. rt_kprintf("\n\n");
  2469. 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);
  2470. LOG_I("结束时间1-%04d-%02d-%02d %02d:%02d:%02d\n", 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);
  2471. 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);
  2472. 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);
  2473. // 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);
  2474. // 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);
  2475. rt_kprintf("\n\n");
  2476. once_print = 1;
  2477. }
  2478. // 此处判断,一个一个时间段判断,判断当前时间是否大于开始时间:
  2479. // 当前时间戳小于第一段开始时间戳
  2480. if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) < 0)
  2481. {
  2482. if (chk_log_time)
  2483. {
  2484. uint32_t time_cache = cul_sh1_stamp.tm_hour * 3600 + cul_sh1_stamp.tm_min * 60 + cul_sh1_stamp.tm_sec;
  2485. uint32_t time_now = now_stamp.tm_hour * 3600 + now_stamp.tm_min * 60 + now_stamp.tm_sec;
  2486. uint32_t time_remainder = time_cache - time_now;
  2487. uint8_t hour = time_remainder / 3600;
  2488. uint8_t min = (time_remainder % 3600) / 60;
  2489. uint8_t sec = time_remainder % 60;
  2490. LOG_I(" ====== 未到收集时间 A :%04d-%02d-%02d %02d:%02d:%02d 剩余:%02d:%02d:%02d ====== run_sta %d",
  2491. cul_sh1_stamp.tm_year + 1900,
  2492. cul_sh1_stamp.tm_mon + 1,
  2493. cul_sh1_stamp.tm_mday,
  2494. cul_sh1_stamp.tm_hour,
  2495. cul_sh1_stamp.tm_min,
  2496. cul_sh1_stamp.tm_sec,
  2497. hour,
  2498. min,
  2499. sec,
  2500. device_status.run_sta);
  2501. }
  2502. time_period = 0;
  2503. }
  2504. // 当前时间戳小于第二段结束 时间戳并且大于第1段结束时间戳
  2505. if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) < 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) > 0)
  2506. {
  2507. if (chk_log_time)
  2508. {
  2509. uint32_t time_cache = cul_sh2_stamp.tm_hour * 3600 + cul_sh2_stamp.tm_min * 60 + cul_sh2_stamp.tm_sec;
  2510. uint32_t time_now = now_stamp.tm_hour * 3600 + now_stamp.tm_min * 60 + now_stamp.tm_sec;
  2511. uint32_t time_remainder = time_cache - time_now;
  2512. uint8_t hour = time_remainder / 3600;
  2513. uint8_t min = (time_remainder % 3600) / 60;
  2514. uint8_t sec = time_remainder % 60;
  2515. LOG_I(" ====== 未到收集时间 B :%04d-%02d-%02d %02d:%02d:%02d 剩余:%02d:%02d:%02d ====== run_sta %d",
  2516. cul_sh2_stamp.tm_year + 1900,
  2517. cul_sh2_stamp.tm_mon + 1,
  2518. cul_sh2_stamp.tm_mday,
  2519. cul_sh2_stamp.tm_hour,
  2520. cul_sh2_stamp.tm_min,
  2521. cul_sh2_stamp.tm_sec,
  2522. hour,
  2523. min,
  2524. sec,
  2525. device_status.run_sta);
  2526. }
  2527. time_period = 0;
  2528. }
  2529. // 如果当前 时间戳大于开始时间戳并且小于 结束时间戳
  2530. if (difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)) < 0)
  2531. {
  2532. time_period = 1;
  2533. }
  2534. else if (difftime(mktime(&now_stamp), mktime(&cul_sh2_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh2_stamp)) < 0)
  2535. {
  2536. time_period = 2;
  2537. }
  2538. else if (difftime(mktime(&now_stamp), mktime(&cul_sh3_stamp)) >= 0 && difftime(mktime(&now_stamp), mktime(&cul_eh3_stamp)) < 0)
  2539. {
  2540. time_period = 3;
  2541. }
  2542. // if (chk_log_time)
  2543. // rt_kprintf("time_period > %d %X %X\n", time_period, difftime(mktime(&now_stamp), mktime(&cul_sh1_stamp)), difftime(mktime(&now_stamp), mktime(&cul_eh1_stamp)));
  2544. return time_period;
  2545. }
  2546. /**
  2547. * @brief
  2548. *
  2549. * @param mot 电机选择
  2550. * @param limit1 限位1选择
  2551. * @param limit2 限位2选择(不需要的话填0)
  2552. * @param mct 电机操作选择
  2553. * @return Res_def 0-成功
  2554. */
  2555. Res_def Mtor_Control(Motor_type mot, Limit_type limit1, Limit_type limit2, Motor_Ctl_type mct, uint16_t timeout)
  2556. {
  2557. uint8_t res = res_OK;
  2558. uint16_t Motor_L, Motor_R, Lim1, Lim2 = LIMIT_0;
  2559. uint16_t wait_out = 0;
  2560. switch (mot) // 电机选型
  2561. {
  2562. case mot_ZP:
  2563. Motor_L = TURN_ZP_L;
  2564. Motor_R = TURN_ZP_R;
  2565. break;
  2566. default:
  2567. LOG_W("illegal Motor_type %d", mot);
  2568. return res_Verifi;
  2569. break;
  2570. }
  2571. switch (limit1) // 限位选型1
  2572. {
  2573. case lt_Angle_0:
  2574. Lim1 = LIMIT_0;
  2575. break;
  2576. case lt_Angle_90:
  2577. Lim1 = LIMIT_90;
  2578. break;
  2579. default:
  2580. LOG_W("illegal limit1_type %d", limit1);
  2581. return res_Verifi;
  2582. break;
  2583. }
  2584. if (limit2 != 0)
  2585. {
  2586. switch (limit2) // 限位选型2
  2587. {
  2588. case lt_Angle_0:
  2589. Lim2 = LIMIT_0;
  2590. rt_pin_mode(Lim2, PIN_MODE_INPUT);
  2591. break;
  2592. case lt_Angle_90:
  2593. Lim2 = LIMIT_90;
  2594. rt_pin_mode(Lim2, PIN_MODE_INPUT);
  2595. break;
  2596. default:
  2597. LOG_W("illegal limit2_type %d", limit2);
  2598. return res_Verifi;
  2599. break;
  2600. }
  2601. }
  2602. rt_pin_mode(Motor_L, PIN_MODE_OUTPUT);
  2603. rt_pin_mode(Motor_R, PIN_MODE_OUTPUT);
  2604. rt_pin_mode(Lim1, PIN_MODE_INPUT);
  2605. // 走出限位
  2606. while((rt_pin_read(Lim1) == 0) && (wait_out * 1000 < timeout))
  2607. {
  2608. switch (mct)
  2609. {
  2610. case mct_Foreward:
  2611. rt_pin_write(Motor_R, ON);
  2612. rt_pin_write(Motor_L, OFF);
  2613. break;
  2614. case mct_Reversal:
  2615. rt_pin_write(Motor_R, OFF);
  2616. rt_pin_write(Motor_L, ON);
  2617. break;
  2618. case mct_Stop:
  2619. rt_pin_write(Motor_R, OFF);
  2620. rt_pin_write(Motor_L, OFF);
  2621. break;
  2622. default:
  2623. LOG_W("illegal Motor_Ctl_type %d", mct);
  2624. return res_Verifi;
  2625. break;
  2626. }
  2627. wait_out++;
  2628. rt_thread_mdelay(1000);
  2629. rt_kprintf("wait exit limit %d/%d \n", wait_out , timeout / 1000);
  2630. }
  2631. // 参数校验完成 开始操作
  2632. switch (mct)
  2633. {
  2634. case mct_Foreward:
  2635. rt_pin_write(Motor_R, ON);
  2636. rt_pin_write(Motor_L, OFF);
  2637. break;
  2638. case mct_Reversal:
  2639. rt_pin_write(Motor_R, OFF);
  2640. rt_pin_write(Motor_L, ON);
  2641. break;
  2642. case mct_Stop:
  2643. rt_pin_write(Motor_R, OFF);
  2644. rt_pin_write(Motor_L, OFF);
  2645. break;
  2646. default:
  2647. LOG_W("illegal Motor_Ctl_type %d", mct);
  2648. return res_Verifi;
  2649. break;
  2650. }
  2651. if (mct == mct_Stop)
  2652. {
  2653. rt_thread_mdelay(10);
  2654. return res;
  2655. }
  2656. res = res_Timeout;
  2657. while ((wait_out * 100 < timeout) && (limit2 == 0))
  2658. {
  2659. switch (mct)
  2660. {
  2661. case mct_Foreward:
  2662. rt_pin_write(Motor_R, ON);
  2663. rt_pin_write(Motor_L, OFF);
  2664. break;
  2665. case mct_Reversal:
  2666. rt_pin_write(Motor_R, OFF);
  2667. rt_pin_write(Motor_L, ON);
  2668. break;
  2669. case mct_Stop:
  2670. rt_pin_write(Motor_R, OFF);
  2671. rt_pin_write(Motor_L, OFF);
  2672. break;
  2673. default:
  2674. LOG_W("illegal Motor_Ctl_type %d", mct);
  2675. return res_Verifi;
  2676. break;
  2677. }
  2678. if (rt_pin_read(Lim1) == 0)
  2679. {
  2680. // LOG_W("lim1 TIG");
  2681. res = res_OK;
  2682. break;
  2683. }
  2684. wait_out++;
  2685. rt_thread_mdelay(100);
  2686. }
  2687. while ((wait_out * 100 < timeout) && (limit2 != 0))
  2688. {
  2689. switch (mct)
  2690. {
  2691. case mct_Foreward:
  2692. rt_pin_write(Motor_R, ON);
  2693. rt_pin_write(Motor_L, OFF);
  2694. break;
  2695. case mct_Reversal:
  2696. rt_pin_write(Motor_R, OFF);
  2697. rt_pin_write(Motor_L, ON);
  2698. break;
  2699. case mct_Stop:
  2700. rt_pin_write(Motor_R, OFF);
  2701. rt_pin_write(Motor_L, OFF);
  2702. break;
  2703. default:
  2704. LOG_W("illegal Motor_Ctl_type %d", mct);
  2705. return res_Verifi;
  2706. break;
  2707. }
  2708. if (rt_pin_read(Lim1) == 0 || rt_pin_read(Lim2) == 0)
  2709. {
  2710. // LOG_W("lim1 or 2 TIG");
  2711. res = res_OK;
  2712. break;
  2713. }
  2714. wait_out++;
  2715. rt_thread_mdelay(100);
  2716. }
  2717. rt_pin_write(TURN_ZP_R, OFF);
  2718. rt_pin_write(TURN_ZP_L, OFF);
  2719. return res;
  2720. }
  2721. /**
  2722. * @brief 控制转盘电机
  2723. *
  2724. * @param mct 控制操作
  2725. * @return Res_def 执行结果
  2726. */
  2727. Res_def Mtor_Control_ZP(Motor_Ctl_type mct)
  2728. {
  2729. uint8_t res = Mtor_Control(mot_ZP, lt_Angle_0, 0, mct, 15000);
  2730. rt_kprintf("Mtor_Control %d - %d\n", mct, res);
  2731. return res;
  2732. }
  2733. /**
  2734. * @brief 限位预警消息
  2735. *
  2736. */
  2737. static void Report_Limit_Error(void)
  2738. {
  2739. char *turn_warn = makeJson_Warn("未检测到限位", "转盘");
  2740. DTU_Write("%s", turn_warn);
  2741. rt_free(turn_warn);
  2742. }
  2743. /**
  2744. * @brief 获取当前时间
  2745. *
  2746. * @param now_stamp 存放时间戳的指针
  2747. */
  2748. static void Get_now_time(struct tm *now_stamp)
  2749. {
  2750. time_t now;
  2751. time(&now);
  2752. *now_stamp = *localtime(&now);
  2753. }
  2754. /**
  2755. * @brief 检查是否处于工作时间段
  2756. *
  2757. * @param coll_ch 时间段通道
  2758. * @return Temporal_list 检查结果
  2759. */
  2760. static Temporal_list Check_Work_time_period(uint8_t coll_ch)
  2761. {
  2762. static struct tm now_stamp = {0}; // 现在
  2763. static struct tm cul_s_stamp = {0}; // 开始
  2764. static struct tm cul_e_stamp = {0}; // 结束
  2765. Get_now_time(&now_stamp);
  2766. Get_now_time(&cul_s_stamp);
  2767. Get_now_time(&cul_e_stamp);
  2768. switch (coll_ch)
  2769. {
  2770. case 1:
  2771. cul_s_stamp.tm_min = device_status.collecting_sh1 + test_min;
  2772. //cul_s_stamp.tm_hour = 0;
  2773. cul_s_stamp.tm_sec = 0;
  2774. cul_e_stamp.tm_min = device_status.collecting_eh1 + test_min;
  2775. //cul_e_stamp.tm_hour = 0;
  2776. cul_e_stamp.tm_sec = 0;
  2777. break;
  2778. case 2:
  2779. cul_s_stamp.tm_min = device_status.collecting_sh2 + test_min;
  2780. //cul_s_stamp.tm_hour = 0;
  2781. cul_s_stamp.tm_sec = 0;
  2782. cul_e_stamp.tm_min = device_status.collecting_eh2 + test_min;
  2783. //cul_e_stamp.tm_hour = 0;
  2784. cul_e_stamp.tm_sec = 0;
  2785. if (cul_s_stamp.tm_min == cul_e_stamp.tm_min) // 检查第二时间段是否有效
  2786. {
  2787. return tl_Error;
  2788. }
  2789. break;
  2790. default:
  2791. return tl_Verifi;
  2792. break;
  2793. }
  2794. if (difftime(mktime(&now_stamp), mktime(&cul_s_stamp)) >= 0 && // 大于开始时间
  2795. difftime(mktime(&now_stamp), mktime(&cul_e_stamp)) < 0) // 小于结束时间
  2796. {
  2797. return tl_Center;
  2798. }
  2799. if (difftime(mktime(&now_stamp), mktime(&cul_s_stamp)) < 0) // 小于开始时间
  2800. {
  2801. return tl_Front;
  2802. }
  2803. if (difftime(mktime(&now_stamp), mktime(&cul_e_stamp)) >= 0) // 大于结束时间
  2804. {
  2805. // rt_kprintf("now %02d:%02d:%02d start %02d:%02d:%02d end %02d:%02d:%02d\n" ,
  2806. // now_stamp.tm_hour,now_stamp.tm_min,now_stamp.tm_sec,
  2807. // cul_s_stamp.tm_hour,cul_s_stamp.tm_min,cul_s_stamp.tm_sec,
  2808. // cul_e_stamp.tm_hour,cul_e_stamp.tm_min,cul_e_stamp.tm_sec
  2809. // );
  2810. return tl_Back;
  2811. }
  2812. return tl_Verifi;
  2813. }
  2814. /**
  2815. * @brief 写工作运行状态
  2816. *
  2817. * @param sta 要写入的值
  2818. */
  2819. static void Set_run_sta(run_sta_list sta)
  2820. {
  2821. device_status.run_sta = sta;
  2822. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  2823. uint8_t check = 0;
  2824. ef_get_env_blob("run_sta", &check, sizeof(device_status.run_sta), NULL);
  2825. if (check != sta)
  2826. {
  2827. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  2828. }
  2829. rt_kprintf("Set_run_sta > %d \n" , check);
  2830. }
  2831. void Set_runsta_reset(void)
  2832. {
  2833. Set_run_sta(rs_RESET);
  2834. }
  2835. MSH_CMD_EXPORT(Set_runsta_reset , Set_runsta_reset);
  2836. /**
  2837. * @brief 读工作运行状态
  2838. *
  2839. * @return run_sta_list 读出的值
  2840. */
  2841. static run_sta_list Get_run_sta(void)
  2842. {
  2843. ef_get_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta), NULL);
  2844. return device_status.run_sta;
  2845. }
  2846. /**
  2847. * @brief 获取剩余工作时间
  2848. *
  2849. * @param coll_ch 工作时间段通道号
  2850. * @return uint8_t 百分比的值
  2851. */
  2852. static int8_t Get_remainder_time(uint8_t coll_ch)
  2853. {
  2854. static struct tm now_stamp = {0}; // 现在
  2855. static struct tm cul_s_stamp = {0}; // 开始
  2856. static struct tm cul_e_stamp = {0}; // 结束
  2857. uint32_t dividend = 0, divisor = 0, quotient = 0;
  2858. int8_t result = 0;
  2859. Get_now_time(&now_stamp);
  2860. Get_now_time(&cul_s_stamp);
  2861. Get_now_time(&cul_e_stamp);
  2862. switch (coll_ch)
  2863. {
  2864. case 1:
  2865. cul_s_stamp.tm_min = device_status.collecting_sh1 + test_min;
  2866. //cul_s_stamp.tm_hour = 0;
  2867. cul_s_stamp.tm_sec = 0;
  2868. cul_e_stamp.tm_min = device_status.collecting_eh1 + test_min;
  2869. //cul_e_stamp.tm_hour = 0;
  2870. cul_e_stamp.tm_sec = 0;
  2871. break;
  2872. case 2:
  2873. cul_s_stamp.tm_min = device_status.collecting_sh2 + test_min;
  2874. //cul_s_stamp.tm_hour = 0;
  2875. cul_s_stamp.tm_sec = 0;
  2876. cul_e_stamp.tm_min = device_status.collecting_eh2 + test_min;
  2877. //cul_e_stamp.tm_hour = 0;
  2878. cul_e_stamp.tm_sec = 0;
  2879. if (cul_s_stamp.tm_min == cul_e_stamp.tm_min) // 检查第二时间段是否有效
  2880. {
  2881. return -1;
  2882. }
  2883. break;
  2884. default:
  2885. return -1;
  2886. break;
  2887. }
  2888. dividend = (cul_e_stamp.tm_hour * 3600 + cul_e_stamp.tm_min * 60 + cul_e_stamp.tm_sec) - (cul_s_stamp.tm_hour * 3600 + cul_s_stamp.tm_min * 60 + cul_s_stamp.tm_sec);
  2889. divisor = (cul_e_stamp.tm_hour * 3600 + cul_e_stamp.tm_min * 60 + cul_e_stamp.tm_sec) - (now_stamp.tm_hour * 3600 + now_stamp.tm_min * 60 + now_stamp.tm_sec);
  2890. divisor *= 100;
  2891. quotient = divisor / dividend;
  2892. result = abs(100 - quotient);
  2893. return result;
  2894. }
  2895. /**
  2896. * @brief 孢子仪工作线程(胶带结构)
  2897. *
  2898. */
  2899. void WorkTask_BZY_JD(void)
  2900. {
  2901. uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
  2902. static int8_t log_en_cnt = -1;
  2903. /** 前置条件 **/
  2904. if (device_status.ds != 1) // 检查设备是否开机
  2905. {
  2906. device_status.work_status = 0;
  2907. if (chk_log_time)
  2908. {
  2909. LOG_I(" ==================!!!Device standby!!!===================");
  2910. }
  2911. return;
  2912. }
  2913. Get_run_sta();
  2914. uint8_t coll_ch = Confirm_time_period();
  2915. if ((coll_ch == 0) && (device_status.run_sta <= rs_COLL_B)) // 检查是否进入工作时间段
  2916. {
  2917. if (chk_log_time)
  2918. {
  2919. LOG_I(" ==================!!!Not entering working hours!!!===================");
  2920. }
  2921. return;
  2922. }
  2923. /** 前置条件 **/
  2924. /** 正式工作逻辑 **/
  2925. static int8_t coll_ch_recode = -1;
  2926. if(coll_ch_recode != coll_ch)
  2927. {
  2928. rt_kprintf(" WorkTask_BZY_JD work in coll_ch > %d\n\n", coll_ch);
  2929. coll_ch_recode = coll_ch;
  2930. }
  2931. switch (device_status.run_sta)
  2932. {
  2933. case rs_RESET: // 复位
  2934. LOG_E("STEP%d > Positioning of the turntable", rs_RESET);
  2935. if (Mtor_Control_ZP(mct_Foreward) == res_Timeout)
  2936. {
  2937. Report_Limit_Error();
  2938. }
  2939. Set_run_sta(rs_COLL_A);
  2940. break;
  2941. case rs_COLL_A: // 采集 A
  2942. rt_kprintf("coll_ch %d time_period %d\n" , coll_ch , Check_Work_time_period(coll_ch));
  2943. if (coll_ch != rs_COLL_A)
  2944. {
  2945. LOG_W("Verifi failed and jump to the next step > to %d",rs_COLL_B);
  2946. Set_run_sta(rs_COLL_B);
  2947. break;
  2948. }
  2949. if (Check_Work_time_period(coll_ch) == tl_Center)
  2950. {
  2951. DTU_Write("collect.mp3");
  2952. LOG_E("STEP%d > start to collect A", rs_COLL_A);
  2953. }
  2954. while (Check_Work_time_period(coll_ch) == tl_Front) // 等待到开始时间
  2955. {
  2956. if (chk_log_time)
  2957. {
  2958. LOG_I("wait for rs_COLL_A Start ");
  2959. }
  2960. rt_thread_mdelay(1000);
  2961. }
  2962. while (Check_Work_time_period(coll_ch) == tl_Center) // 开风机等结束
  2963. {
  2964. device_status.work_status = 1;
  2965. ctr_Collect_Fan(ON);
  2966. if (chk_log_time)
  2967. {
  2968. LOG_I(" Collecting A...%d/%%", Get_remainder_time(coll_ch));
  2969. }
  2970. rt_thread_mdelay(1000);
  2971. }
  2972. ctr_Collect_Fan(OFF);
  2973. Set_run_sta(rs_COLL_B);
  2974. break;
  2975. case rs_COLL_B: // 采集 B
  2976. rt_thread_mdelay(1000);
  2977. if(Check_Work_time_period(coll_ch) == tl_Front || coll_ch < rs_COLL_B || Get_remainder_time(coll_ch) == 1) // 等待到开始时间
  2978. {
  2979. if (chk_log_time)
  2980. {
  2981. LOG_I("wait for rs_COLL_B Start ");
  2982. }
  2983. rt_thread_mdelay(1000);
  2984. return;
  2985. }
  2986. if ((Check_Work_time_period(coll_ch) == tl_Error) || (coll_ch != rs_COLL_B))
  2987. {
  2988. LOG_W("Verifi failed and jump to the next step > to %d",rs_Press_Tape);
  2989. Set_run_sta(rs_Press_Tape);
  2990. break;
  2991. }
  2992. LOG_E("STEP%d > start to collect B", rs_COLL_B);
  2993. while (Check_Work_time_period(coll_ch) == tl_Center) // 开风机等结束
  2994. {
  2995. device_status.work_status = 1;
  2996. ctr_Collect_Fan(ON);
  2997. if (chk_log_time)
  2998. {
  2999. LOG_I(" Collecting B...%d/%%", Get_remainder_time(coll_ch));
  3000. }
  3001. rt_thread_mdelay(1000);
  3002. }
  3003. rt_kprintf("STEP2 Finsh > %d\n\n", Check_Work_time_period(coll_ch));
  3004. ctr_Collect_Fan(OFF);
  3005. Set_run_sta(rs_Press_Tape);
  3006. break;
  3007. case rs_Press_Tape: // 压带
  3008. LOG_E("STEP%d > Press_Tape", rs_Press_Tape);
  3009. ctr_Petroleum_jelly(10);
  3010. rt_thread_mdelay(500);
  3011. Set_run_sta(rs_Tape_Move);
  3012. break;
  3013. case rs_Tape_Move: // 转胶带
  3014. LOG_E("STEP%d > Positioning of the turntable", rs_Tape_Move);
  3015. if (Mtor_Control_ZP(mct_Foreward) == res_Timeout)
  3016. {
  3017. Report_Limit_Error();
  3018. }
  3019. Set_run_sta(rs_Take_Photo);
  3020. break;
  3021. case rs_Take_Photo: // 拍照
  3022. LOG_E("STEP%d > Take_Photo", rs_Take_Photo);
  3023. device_status.work_status = 3; // 现在是拍照
  3024. device_status.autotakepic = 1; // 对焦拍照
  3025. while (device_status.autotakepic == 1)
  3026. {
  3027. rt_thread_mdelay(5000);
  3028. LOG_I("正在对焦拍照............");
  3029. }
  3030. device_status.work_status = 0; // 待机
  3031. DTU_Write("wait.mp3");
  3032. LOG_I("=====================work finished==================");
  3033. Set_run_sta(rs_RESET);
  3034. break;
  3035. default:
  3036. Set_run_sta(rs_RESET);
  3037. break;
  3038. }
  3039. if (chk_log_time)
  3040. {
  3041. LOG_I(" Main working logic of turntable structure");
  3042. LOG_I(" Run Mode %d", device_status.run_sta);
  3043. }
  3044. /** 正式工作逻辑 **/
  3045. rt_thread_delay(1000);
  3046. }
  3047. void BZY_JD_AutoTest(void)
  3048. {
  3049. device_status.auto_test_sw = 1;
  3050. HMI_WRITE("sysTest.auto_flag.txt=\"Autotest\"");
  3051. // 转盘复位
  3052. LOG_I(" 1. 转盘复位!!!\n");
  3053. HMI_WRITE("sysTest.result.txt=\"一键测试1/6:转盘复位!\"");
  3054. rt_thread_mdelay(2000);
  3055. Mtor_Control_ZP(mct_Foreward);
  3056. LOG_I(" 2. 采集,打开风机!!!\n");
  3057. HMI_WRITE("sysTest.result.txt=\"一键测试2/6:采集,打开风机!\"");
  3058. ctr_Collect_Fan(ON);
  3059. rt_thread_mdelay(5000);
  3060. LOG_I(" 3. 采集结束,关闭风机!!\n");
  3061. HMI_WRITE("sysTest.result.txt=\"一键测试3/6:采集结束,关闭风机!\"");
  3062. rt_thread_mdelay(2000);
  3063. ctr_Collect_Fan(OFF);
  3064. LOG_I(" 4. 传送胶带!!!\n");
  3065. HMI_WRITE("sysTest.result.txt=\"一键测试4/6:传送胶带!\"");
  3066. Mtor_Control_ZP(mct_Foreward);
  3067. rt_thread_mdelay(2000);
  3068. LOG_I(" 5. 打开补光灯!!\n!");
  3069. HMI_WRITE("sysTest.result.txt=\"一键测试5/6:打开补光灯!\"");
  3070. rt_thread_delay(2000);
  3071. ctr_led(ON);
  3072. LOG_I(" 6. 开始拍照!!!\n");
  3073. HMI_WRITE("sysTest.result.txt=\"一键测试6/6:开始拍照!\"");
  3074. device_status.autotakepic = 1;
  3075. rt_thread_delay(2000);
  3076. device_status.auto_test_sw = 0;
  3077. HMI_WRITE("sysTest.auto_flag.txt=\"\"");
  3078. }
  3079. /*********************↑ 胶带结构的孢子仪主工作流程 ↑************************/
  3080. /**
  3081. * @brief 孢子仪工作线程V2
  3082. *
  3083. */
  3084. void WorkTask_BZYV2(void)
  3085. {
  3086. // 打开采集风机
  3087. ctr_Collect_Fan(ON);
  3088. // 打开胶带步进电机
  3089. // 等待采集结束
  3090. // 拍照
  3091. // 打开相机供电
  3092. // 打开补光灯
  3093. // 滑台归位
  3094. // 滑台启动
  3095. }
  3096. // 工作任务流程s
  3097. void WorkTask(void)
  3098. {
  3099. static int clt_time = 0; // 收集时间差秒数
  3100. static int heat_time = 0;
  3101. uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
  3102. static int8_t log_en_cnt = -1;
  3103. if (chk_log_time)
  3104. {
  3105. LOG_I("工作状态:%d", device_status.work_status);
  3106. LOG_I("开关机状态:%d", device_status.ds);
  3107. }
  3108. 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)
  3109. {
  3110. device_status.work_done = 0;
  3111. if (clt_time == 0)
  3112. {
  3113. #if 0
  3114. if(device_status.version_type==41&&atoi(device_status.power)<350)
  3115. {
  3116. LOG_W("相机电流不足!");
  3117. char *ctr_hk_p_warn = makeJson_Warn("电流不足", "相机");
  3118. DTU_Write("%s",ctr_hk_p_warn);
  3119. rt_free(ctr_hk_p_warn);
  3120. }
  3121. #endif
  3122. #if LAMP_EN == 0
  3123. ctr_Fan_PUT(ON);
  3124. #endif
  3125. DTU_Write("workstart.mp3");
  3126. }
  3127. // 1.打开灯管
  3128. #if LAMP_EN == 1
  3129. if (device_status.lamp_status == 1)
  3130. {
  3131. ctr_lamp(ON, 1);
  3132. ctr_lamp(OFF, 2);
  3133. ctr_lamp(OFF, 3);
  3134. }
  3135. else if (device_status.lamp1_status == 1)
  3136. {
  3137. ctr_lamp(OFF, 1);
  3138. ctr_lamp(ON, 2);
  3139. ctr_lamp(OFF, 3);
  3140. }
  3141. else if (device_status.lamp2_status == 1)
  3142. {
  3143. ctr_lamp(OFF, 1);
  3144. ctr_lamp(OFF, 2);
  3145. ctr_lamp(ON, 3);
  3146. }
  3147. #else
  3148. ctr_lamp(ON, 1);
  3149. #endif
  3150. LOG_I("打开灯管!!!");
  3151. #if 0
  3152. rt_thread_delay(2000);
  3153. if(atoi(device_status.power)<450)
  3154. {
  3155. LOG_I("Current is:%d",atoi(device_status.power));
  3156. if(atoi(device_status.power)>50&&atoi(device_status.power)<5000) //过滤电流检测芯片损坏导致电流异常
  3157. {
  3158. char* lamp_err_warn = makeJson_Warn("电流不足", "灯管");
  3159. DTU_Write("%s",lamp_err_warn);
  3160. rt_free(lamp_err_warn);
  3161. }
  3162. }
  3163. #endif
  3164. if (device_status.version_type != 5)
  3165. {
  3166. if (clt_time == 0)
  3167. {
  3168. rt_thread_delay(5000); // 待灯管启动再往下执行,否则会触发电机过流
  3169. // 2.打开上仓门
  3170. rt_kprintf("打开上仓门!!!\n");
  3171. device_status.ctr_up_motor = 1;
  3172. }
  3173. // 3.收集
  3174. clt_time = device_status.clt_time * 60;
  3175. while (clt_time != 1)
  3176. {
  3177. #if LAMP_EN == 0
  3178. ctr_Fan_IN(ON);
  3179. #endif
  3180. clt_time--;
  3181. rt_thread_delay(1000);
  3182. #if LAMP_EN == 0
  3183. if (clt_time % 30 == 0)
  3184. ctr_Fan_PUT(OFF);
  3185. #endif
  3186. rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n", device_status.clt_time, clt_time);
  3187. HMI_WRITE("workSta.g0.txt=\"正在收集.....剩余时间:%d分-%d秒\"", device_status.clt_time, clt_time);
  3188. // 如果触发异常
  3189. if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1)
  3190. {
  3191. ctr_lamp(OFF, 1);
  3192. #if LAMP_EN == 1
  3193. ctr_lamp(OFF, 2);
  3194. ctr_lamp(OFF, 3);
  3195. #endif
  3196. #if LAMP_EN == 0
  3197. ctr_Fan_IN(OFF);
  3198. #endif
  3199. rt_kprintf("异常退出!!!\n");
  3200. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  3201. break;
  3202. }
  3203. if (device_status.timeSwitch == 0 && device_status.sun_status == 1)
  3204. {
  3205. ctr_lamp(OFF, 1);
  3206. #if LAMP_EN == 1
  3207. ctr_lamp(OFF, 2);
  3208. ctr_lamp(OFF, 3);
  3209. #endif
  3210. #if LAMP_EN == 0
  3211. ctr_Fan_IN(OFF);
  3212. #endif
  3213. rt_kprintf("异常退出!!!\n");
  3214. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  3215. break;
  3216. }
  3217. }
  3218. clt_time = 1;
  3219. if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1)
  3220. {
  3221. ctr_lamp(OFF, 1);
  3222. #if LAMP_EN == 1
  3223. ctr_lamp(OFF, 2);
  3224. ctr_lamp(OFF, 3);
  3225. #endif
  3226. #if LAMP_EN == 0
  3227. ctr_Fan_IN(OFF);
  3228. #endif
  3229. rt_kprintf("异常退出!!!\n");
  3230. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  3231. break;
  3232. }
  3233. if (device_status.timeSwitch == 0 && device_status.sun_status == 1)
  3234. {
  3235. ctr_lamp(OFF, 1);
  3236. #if LAMP_EN == 1
  3237. ctr_lamp(OFF, 2);
  3238. ctr_lamp(OFF, 3);
  3239. #endif
  3240. #if LAMP_EN == 0
  3241. ctr_Fan_IN(OFF);
  3242. #endif
  3243. rt_kprintf("异常退出!!!\n");
  3244. HMI_WRITE("workSta.g0.txt=\"异常退出\"");
  3245. break;
  3246. }
  3247. #if LAMP_EN == 0
  3248. ctr_Fan_IN(OFF);
  3249. #endif
  3250. // 4.关闭上仓门
  3251. device_status.ctr_up_motor = 2;
  3252. rt_kprintf("关闭上仓门!!!\n");
  3253. HMI_WRITE("workSta.g0.txt=\"关闭上仓门!\"");
  3254. while (device_status.ctr_up_motor != 0)
  3255. {
  3256. rt_thread_delay(100);
  3257. LOG_I("等待上仓门关闭!!!");
  3258. }
  3259. // 5.加热
  3260. if (device_status.heat_sw == 0)
  3261. {
  3262. calorstat(device_status.heattime * 60);
  3263. }
  3264. else
  3265. {
  3266. heat_time = device_status.heattime * 60;
  3267. while (heat_time != 0)
  3268. {
  3269. heat_time--;
  3270. LOG_I("正在加热状态!!!");
  3271. rt_thread_delay(1000);
  3272. }
  3273. }
  3274. // 6.打开下仓门
  3275. if (device_status.rain_status == 0)
  3276. {
  3277. device_status.ctr_down_motor = 1;
  3278. }
  3279. else
  3280. {
  3281. device_status.ctr_down_motor = 2;
  3282. device_status.ctr_up_motor = 2;
  3283. }
  3284. // 待下仓门完全打开
  3285. while (device_status.ctr_down_motor != 0)
  3286. {
  3287. rt_thread_delay(100);
  3288. rt_kprintf("等待下仓门打开!!!\n");
  3289. HMI_WRITE("workSta.g0.txt=\"等待下仓门打开!\"");
  3290. }
  3291. rt_thread_delay(3000);
  3292. // 关闭下仓门
  3293. device_status.ctr_down_motor = 2;
  3294. while (device_status.ctr_down_motor != 0)
  3295. {
  3296. rt_thread_delay(100);
  3297. rt_kprintf("等待下仓门关闭!!!\n");
  3298. HMI_WRITE("workSta.g0.txt=\"等待下仓门关闭!\"");
  3299. }
  3300. // 2022-04-12add:
  3301. LOG_I("打开上仓门!!!");
  3302. HMI_WRITE("workSta.g0.txt=\"打开上仓门!\"");
  3303. device_status.ctr_up_motor = 1;
  3304. if (device_status.version_type == 4 || device_status.version_type == 41)
  3305. {
  3306. // 震动
  3307. ctr_shake(ON, device_status.shake_sec);
  3308. // 补光&&拍照
  3309. LOG_I("拍照!!!");
  3310. HMI_WRITE("workSta.g0.txt=\"拍照!\"");
  3311. HK_TakePhoto();
  3312. // 清扫
  3313. device_status.clear_status = 1;
  3314. // 清扫失效则使用震动
  3315. // ctr_shake(ON, 100);
  3316. }
  3317. }
  3318. else
  3319. {
  3320. // 打开高压
  3321. ctr_Heat(ON);
  3322. // 打开补光
  3323. ctr_led(ON);
  3324. LOG_I("打开补光!!");
  3325. rt_pin_mode(CLEAR_L_LIMIT, PIN_MODE_INPUT);
  3326. // 2.翻转清虫
  3327. while (rt_pin_read(CLEAR_L_LIMIT) == 1)
  3328. rt_thread_delay(20);
  3329. rt_thread_delay(500);
  3330. Hk_Take_io(); // 触发海康相机拍照
  3331. rt_thread_delay(500);
  3332. ctr_turnv5(); // 摆动清虫
  3333. LOG_I("摆动清虫!");
  3334. }
  3335. }
  3336. if (device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status == 1 || device_status.ds == 0)
  3337. {
  3338. if (chk_log_time)
  3339. {
  3340. rt_kprintf("-------------------not work--------------------\n");
  3341. }
  3342. device_status.work_status = 0;
  3343. }
  3344. // 工作结束
  3345. if (device_status.work_done == 0 && device_status.work_status == 0)
  3346. {
  3347. DTU_Write("workdone");
  3348. HMI_WRITE("workSta.g0.txt=\"工作任务已完成!\"");
  3349. ResetInit();
  3350. }
  3351. if (chk_log_time)
  3352. {
  3353. rt_kprintf(" ***not work-device status:%d\n", device_status.ds);
  3354. }
  3355. }
  3356. /* 入口函数-工作状态检测 */
  3357. /**
  3358. * @brief 工作状态检测线程服务函数
  3359. *
  3360. * @param parameter -
  3361. */
  3362. static void Work_status_thread_entry(void *parameter)
  3363. {
  3364. static uint16_t sun_status_num = 120;
  3365. // 如果是光控定时,进行光控监测的消抖
  3366. if (device_status.timeSwitch == 0 && device_status.sun_status == 0)
  3367. {
  3368. rt_kprintf("光控定时!!!\n");
  3369. while (sun_status_num != 0)
  3370. {
  3371. sun_status_num--;
  3372. rt_thread_delay(1000);
  3373. rt_kprintf("开机光控检测:%d\n", sun_status_num);
  3374. }
  3375. device_status.light_over_tim = device_status.sunBar * 3600;
  3376. device_status.test_flag = 0;
  3377. }
  3378. while (1)
  3379. {
  3380. WorkCheck();
  3381. }
  3382. }
  3383. /*入口函数-工作流程*/
  3384. /**
  3385. * @brief 工作流程线程服务函数
  3386. *
  3387. * @param parameter -
  3388. */
  3389. static void Work_Loop_thread_entry(void *parameter)
  3390. {
  3391. uint8_t log_en_inr = LOG_INR; // 打印log的速度 数值越小 打印越频繁
  3392. static int8_t log_en_cnt = -1;
  3393. rt_thread_delay(1000);
  3394. ResetInit();
  3395. while (1)
  3396. {
  3397. // rt_kprintf(" dtype = %d vtype = %d \n\n", device_status.dtype, device_status.version_type);
  3398. if (device_status.dtype == dt_BZY) // dtype分类 孢子仪
  3399. {
  3400. switch (device_status.version_type)
  3401. {
  3402. case vt_BZY:
  3403. {
  3404. WorkTask_BZY(); // 孢子仪转盘结构
  3405. }
  3406. break;
  3407. case vt_BZY_JD:
  3408. {
  3409. // if (chk_log_time)
  3410. // {
  3411. // LOG_I("WorkTask_BZY_JD");
  3412. // }
  3413. WorkTask_BZY_JD(); // 孢子仪胶带结构
  3414. }
  3415. break;
  3416. default:
  3417. WorkTask_BZY();
  3418. break;
  3419. }
  3420. }
  3421. else if (device_status.dtype == dt_CBD) // dtype分类 测报灯
  3422. {
  3423. switch (device_status.version_type)
  3424. {
  3425. case vt_XCT:
  3426. {
  3427. WorkTask_XCT();
  3428. }
  3429. break;
  3430. default:
  3431. WorkTask();
  3432. break;
  3433. }
  3434. }
  3435. rt_thread_delay(1000);
  3436. }
  3437. }
  3438. /*入口函数清扫*/
  3439. /**
  3440. * @brief 控制清扫线程服务函数
  3441. *
  3442. * @param parameter -
  3443. */
  3444. static void Control_Clear_thread_entry(void *parameter)
  3445. {
  3446. while (1)
  3447. {
  3448. #if ROBOT_EN == 1
  3449. ctr_Motor_Robot(ON);
  3450. rt_thread_delay(100);
  3451. #else
  3452. #if Color_EN == 1
  3453. /*复位*/
  3454. if (Read_Color_Key(KEY_RESET) == 1)
  3455. {
  3456. ctr_Color_board(RESET, 1200);
  3457. rt_thread_delay(5000);
  3458. }
  3459. #else
  3460. if (device_status.clear_status == 1)
  3461. {
  3462. if (ctr_clear(1200) == 0)
  3463. ctr_TG_Clear(400);
  3464. }
  3465. rt_thread_delay(100);
  3466. #endif
  3467. #endif
  3468. }
  3469. }
  3470. /*入口函数加热*/
  3471. /**
  3472. * @brief 控制加热线程服务函数
  3473. *
  3474. * @param parameter -
  3475. */
  3476. static void Control_Heat_thread_entry(void *parameter)
  3477. {
  3478. uint16_t var_clear = 0;
  3479. #if ROBOT_EN == 1
  3480. static uint8_t key_on = 0;
  3481. #else
  3482. #if Color_EN == 0
  3483. while (device_status.work_status == 0)
  3484. {
  3485. rt_thread_delay(1000);
  3486. }
  3487. #endif
  3488. #endif
  3489. while (1)
  3490. {
  3491. #if ROBOT_EN == 1
  3492. // 磁悬浮供电
  3493. // 监测磁悬浮限位位置`
  3494. LOG_D("Read 磁悬浮:%d", device_status.heattem);
  3495. // 等待10S
  3496. if (device_status.heattem < 30 && Read_Real_Voltage() / 100 > 12) // 磁悬浮处于关闭状态
  3497. {
  3498. key_on = 0;
  3499. // 发送触摸按钮信号
  3500. rt_pin_mode(EMS_Dir, PIN_MODE_OUTPUT);
  3501. rt_pin_write(EMS_Dir, 0);
  3502. rt_thread_delay(50);
  3503. rt_pin_write(EMS_Dir, 1);
  3504. }
  3505. else if (device_status.heattem < 30 && Read_Real_Voltage() / 100 < 12)
  3506. {
  3507. ctr_router(OFF);
  3508. }
  3509. if (device_status.heattem > 40)
  3510. {
  3511. key_on = 1;
  3512. rt_thread_delay(1000);
  3513. LOG_D("Read 磁悬浮已打开:%d", device_status.heattem);
  3514. }
  3515. // 磁悬浮供电
  3516. // 监测磁悬浮限位位置
  3517. // 根据位置确定是否 按下按钮+
  3518. if (Read_Real_Voltage() / 100 < 12 && key_on == 1)
  3519. {
  3520. key_on = 0;
  3521. rt_pin_mode(EMS_Dir, PIN_MODE_OUTPUT);
  3522. rt_pin_write(EMS_Dir, 0);
  3523. rt_thread_delay(50);
  3524. rt_pin_write(EMS_Dir, 1);
  3525. }
  3526. #else
  3527. #if Color_EN == 1
  3528. /*黄板归位*/
  3529. if (Read_Color_Key(KEY_BACK) == 1)
  3530. {
  3531. LOG_W("黄板归位!");
  3532. ctr_Color_board(CLOSE, 300);
  3533. rt_thread_delay(5000);
  3534. }
  3535. #else
  3536. if (device_status.work_status == 1 && device_status.heat_sw == 1)
  3537. {
  3538. ctr_lamp(ON, 1);
  3539. rt_thread_delay(10000);
  3540. calorstat(device_status.heattime * 60);
  3541. }
  3542. else
  3543. {
  3544. LOG_I("Not calorstat!");
  3545. }
  3546. if (device_status.work_status == 1 && device_status.version_type == 5)
  3547. {
  3548. var_clear++;
  3549. if (var_clear == 300)
  3550. {
  3551. var_clear = 0;
  3552. ctr_cangmen_down(ON);
  3553. rt_thread_mdelay(5000);
  3554. ctr_cangmen_down(OFF);
  3555. rt_thread_mdelay(500);
  3556. ctr_cangmen_down(ON);
  3557. rt_thread_mdelay(5000);
  3558. ctr_cangmen_down(OFF);
  3559. }
  3560. }
  3561. // //吸虫塔补光灯测试
  3562. // while(device_status.vol!=200)
  3563. // {
  3564. // if(var_led==0) ctr_led(ON);
  3565. // var_led++;
  3566. // if(var_led>10)
  3567. // {
  3568. // ctr_led(OFF);
  3569. // var_ledoff++;
  3570. // if(var_ledoff>10)
  3571. // {
  3572. // var_led = 0;
  3573. // var_ledoff = 0;
  3574. // ctr_led(ON);
  3575. // }
  3576. // }
  3577. // rt_thread_delay(1000);
  3578. // }
  3579. rt_thread_delay(1000);
  3580. #endif
  3581. #endif
  3582. }
  3583. }
  3584. /*清扫线程*/
  3585. /**
  3586. * @brief 创建用于控制清扫操作的线程
  3587. *
  3588. * @return int -
  3589. */
  3590. int Control_clear(void)
  3591. {
  3592. /* 创建线程*/
  3593. tid_ctr = rt_thread_create("Control_Clear_thread_entry",
  3594. Control_Clear_thread_entry, RT_NULL,
  3595. 2048, // 2048
  3596. 24, // 23
  3597. WORK_CHECK_THREAD_TIMESLICE); // 5
  3598. if (tid_ctr != RT_NULL)
  3599. {
  3600. rt_thread_startup(tid_ctr);
  3601. }
  3602. return 0;
  3603. }
  3604. /*恒温加热线程*/
  3605. /**
  3606. * @brief 创建用于恒温加热操作的线程
  3607. *
  3608. * @return int -
  3609. */
  3610. int Control_heat(void)
  3611. {
  3612. /* 创建线程*/
  3613. tid_heat = rt_thread_create("Control_Heat_thread_entry",
  3614. Control_Heat_thread_entry, RT_NULL,
  3615. 1024, // 2048
  3616. 25, // 23
  3617. WORK_CHECK_THREAD_TIMESLICE); // 5
  3618. if (tid_heat != RT_NULL)
  3619. {
  3620. rt_thread_startup(tid_heat);
  3621. }
  3622. return 0;
  3623. }
  3624. /* 创建线程 -工作状态检测*/
  3625. int Workstatus_check(void)
  3626. {
  3627. /* 创建线程*/
  3628. tid_wkstc = rt_thread_create("work_status_check_thread",
  3629. Work_status_thread_entry, RT_NULL,
  3630. WORK_CHECK_THREAD_STACK_SIZE, // 1024
  3631. WORK_CHECK_THREAD_PRIORITY, // 23
  3632. WORK_CHECK_THREAD_TIMESLICE); // 5
  3633. if (tid_wkstc != RT_NULL)
  3634. {
  3635. rt_thread_startup(tid_wkstc);
  3636. }
  3637. return 0;
  3638. }
  3639. /*工作流程线程*/
  3640. int Work_Loop_Task(void)
  3641. {
  3642. /* 创建线程*/
  3643. tid_workloop = rt_thread_create("work_loop_thread",
  3644. Work_Loop_thread_entry, RT_NULL,
  3645. WORK_LOOP_THREAD_STACK_SIZE, // 2048
  3646. WORK_LOOP_THREAD_PRIORITY, // 12
  3647. WORK_LOOP_THREAD_TIMESLICE); // 5
  3648. #if Color_EN == 0
  3649. if (tid_workloop != RT_NULL)
  3650. {
  3651. rt_thread_startup(tid_workloop);
  3652. }
  3653. #endif
  3654. return 0;
  3655. }
  3656. MSH_CMD_EXPORT(HardWare_Check, HardWare_Check<ON | OFF>);
  3657. MSH_CMD_EXPORT(ctr_lamp, ctr_lamp<ON | OFF>);
  3658. MSH_CMD_EXPORT(ctr_clear, ctr_clear<ON | OFF>);
  3659. MSH_CMD_EXPORT(ctr_led, sample : ctr_led<ON | OFF>);