control.c 95 KB

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