control.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-30 Administrator the first version
  9. */
  10. #ifndef APPLICATIONS_INC_CONTROL_H_
  11. #define APPLICATIONS_INC_CBD_CONTROL_H_
  12. #include <rtthread.h>
  13. #include <board.h>
  14. #include "stdio.h"
  15. #include <rtdevice.h>
  16. //定制相关//////////////////////////////////////////////////////
  17. #define LAMP_EN 0 //李新3灯管:0关闭,1打开
  18. #define PCB_V1 0 //1-旧PCB,0-新PCB(模块化)
  19. #define MATCH_DEVICE 0 //比赛设备
  20. #define SENSOR_EN 1 //温湿度:0关闭,1打开
  21. #define UART_TEST_EN 0 ///串口测试0-关闭,1-启用
  22. #define TG_MODULE 0 //推杆电机结构模块化控制
  23. #define DINGZHI_0722 0 //控制一个电机每天12点20工作12秒
  24. #define QINGSAO_IO 1 //调整清扫顺序20250801
  25. #if MATCH_DEVICE == 1
  26. #define LAMP_CURRENT 600
  27. #else
  28. #define LAMP_CURRENT 400
  29. #endif
  30. ////////////////////////////////////////////////////////////////
  31. #define VERSION_HK "1.0.0"
  32. extern rt_event_t event_485_play;
  33. /*********************************************************************/
  34. typedef struct _packed
  35. {
  36. uint8_t iSave; //存储标志位
  37. uint8_t dtype; //设备类型?7-孢子仪,3-测报灯
  38. /*孢子仪*/
  39. uint8_t run_sta; //转盘的位置:0原始;1收集;2培养;3拍照;4凡士林,其他-测试
  40. uint8_t cul_time; //培养时间
  41. uint8_t stay_time; //已培养时间
  42. uint8_t pre_temp; //培养仓温度
  43. uint8_t box_temp; //箱体温度
  44. uint8_t auto_test_sw; //一键测试 0-关 1-开
  45. uint8_t cold_status; //制冷状态 0-关 1-开
  46. uint8_t cold_sw; //制冷开关 0-关 1-开
  47. uint8_t wind_sw; //风机开关 0-关 1-开
  48. uint8_t collect_fan_status; //采集状态 0-关 1-开
  49. uint8_t autotakepic; //对焦拍照 0-关 1-开
  50. uint8_t develop_flag; //是否进入培养模式
  51. uint8_t cool_fan_status; //散热风机状态 0-停止 1-打开
  52. uint8_t fsl_sw; //凡士林开关:0-关,1-开
  53. uint8_t collecting_sh1; //采集开启1
  54. uint8_t collecting_eh1; //采集关闭1
  55. uint8_t collecting_sh2; //采集开启2
  56. uint8_t collecting_eh2; //采集关闭2
  57. uint8_t collecting_sh3; //采集开启3
  58. uint8_t collecting_eh3; //采集关闭3
  59. /*测报灯*/
  60. uint8_t heat_sw; //加热开关
  61. uint8_t photo_ws; //拍照
  62. uint8_t power_status; //电源
  63. uint8_t sun_test; //光控测测试标志位
  64. uint8_t heat_status; //加热状态 0-关 1-开
  65. uint8_t lamp_status; //灯管1状态 0-关 1-开
  66. uint8_t lamp1_status; //灯管2状态 0-关 1-开
  67. uint8_t lamp2_status; //灯管3状态 0-关 1-开
  68. uint8_t up_status; //上仓门状态 0-停止 1-打开 2-关闭
  69. uint8_t down_status; //下仓门状态 0-停止 1-打开 2-关闭
  70. uint8_t clear_status; //清扫状态 0-停止 1-开始
  71. uint8_t shake_ws; //震动 0-关 1-开
  72. uint8_t heatvalue; //加热设定温度
  73. uint8_t ctr_up_motor; //上仓门, 1打开,0关闭
  74. uint8_t ctr_down_motor; //下仓门, 1打开,0关闭
  75. uint8_t rain_status; //雨控 0-正常 1-欠压
  76. uint8_t temp_status; //温控 0-正常 1-温控
  77. uint8_t sun_status; //光控 0-正常 1-光控
  78. uint8_t lamp; //灯管状态 0-正常 1-异常
  79. uint8_t ds; //设备状态 0-关机 1-开机
  80. uint8_t work_status; //工作状态 0-待机 1-工作
  81. uint8_t work_done; //工作结束 1-正常 0-工作已结束
  82. uint8_t bat_status; //电压状态 0-正常 1-欠压
  83. uint8_t heattime; //加热时间
  84. uint8_t heat_time_min; //实时加热时间
  85. uint8_t clt_time; //收集时间
  86. uint8_t vol; //音量
  87. uint8_t refresh_num; //DTU数据刷新时间
  88. uint8_t refresh_timeout; //刷新超时时间
  89. uint8_t sunBar; //光控定时时间
  90. uint8_t startBar; //时控开始时间
  91. uint8_t stopBar; //时控结束时间
  92. uint8_t tph; //高温保护
  93. int8_t tpl; //低温保护
  94. uint8_t timeSwitch; //模式0光控,1时控
  95. uint8_t link_sta; //有线接入状态:0-未接入,1已接入
  96. uint8_t heattem; //加热仓温度(实时)
  97. uint8_t hmi_fresh; //是否启动屏幕
  98. uint8_t update_flag; //是否启动升级
  99. uint8_t photo_type; //相机类型,0-USB,1-海康,2-大华
  100. uint8_t version_type; //版本类型,1-转盘,4-海康,41-水稻,11-高空,48-4800
  101. uint8_t stop_in_bootloader; //进入bootloader模式 1
  102. uint8_t account_status; //卡状态
  103. uint8_t test_flag; //测试标志
  104. uint8_t sensor_485_sta; //485传感器
  105. uint8_t Power_Type; //供电类型
  106. uint8_t handle_bugger; //排虫模式,0推杆收回来是排虫,1推出去是收虫
  107. uint8_t collt_box_sta; //收虫仓状态
  108. uint8_t camsta; //拍照报警,0正常,1异常
  109. uint8_t heat_sta; //加热报警0-正常,1-异常
  110. uint8_t led_sta; //补光灯报警0-正常,1-异常
  111. uint8_t selfcheck_ws; //自检开关1-北大荒,2-标配
  112. uint8_t gps_inuse;
  113. uint8_t gps_view;
  114. uint8_t debug_ws; //调试开关,把调试信息上报到MQTT
  115. uint16_t dattim; //数据上传间隔
  116. uint16_t shake_sec; //震动时间
  117. uint16_t thsp; //息屏时间
  118. uint16_t C01; //故障码
  119. uint16_t route_off_t; //路由器断电时间
  120. rt_uint32_t num_updata; //
  121. rt_uint32_t rebootcnt; //启动次数
  122. rt_uint32_t light_over_tim; //光控定时差秒数,镇流器的结束时间
  123. rt_uint32_t data_plan; //流量套餐
  124. rt_uint32_t expiry_date; //到期时间
  125. int passWord; //初始密码
  126. double process;
  127. long photo_stamp; //采集时间戳
  128. const char *coll_time[10];
  129. char mqttcfg1[64]; //
  130. char mqttcfg2[64]; //
  131. char csq[8]; //信号强度
  132. char net[8]; //网络
  133. char sim[8]; //SIM卡
  134. char gps[8]; //定位状态
  135. char gps_state[8]; //定位类型
  136. char tempture[12]; //温度
  137. char humidity[12]; //湿度
  138. char driver[64]; //版本
  139. char driver_4g[64]; //4g版本
  140. char driver_bl[64]; //BL版本
  141. char driver_compile[64]; //BL编译时间
  142. char project[32]; //project,用于判断升级
  143. char lng[32]; //经度
  144. char lat[32]; //纬度
  145. char stamp[32]; //系统时间
  146. char fuse_voltage[32]; //保险丝电压
  147. char iccid[32]; //SIM卡ICCID
  148. char imei[32]; //IMEI,唯一ID
  149. char link_ip[32];
  150. char json_w_clock[128]; //修改时间
  151. char json_w_reset[128]; //
  152. char json_w_platform[128]; //
  153. char power[8]; //功率
  154. char heat_power[8]; //加热功率
  155. char voltage[6]; //电池电压
  156. char deviceId[32]; //bdh-设备编码
  157. char voltage_sun[8]; //太阳能板电压
  158. char qianming[128];
  159. char photolink[128]; //图片地址
  160. }Device_Status_typedef;
  161. typedef struct
  162. {
  163. char OP_24V_1[8]; //24V输出通道1负载电流
  164. char OP_24V_2[8]; //24V输出通道2负载电流
  165. char OP_24V_3[8]; //24V输出通道3负载电流
  166. char OP_24V_4[8]; //24V输出通道4负载电流
  167. char OP_12V_1[8];
  168. char OP_12V_2[8];
  169. char OP_5V_1[8];
  170. char OP_MOTOR_1[8];
  171. char OP_MOTOR_2[8];
  172. char OP_MOTOR_3[8];
  173. float VOLTAGE_5V;
  174. float VOLTAGE_12V;
  175. float VOLTAGE_3_3V;
  176. float MCU_T;
  177. uint16_t ADC_1; //ADC通道1数值
  178. uint16_t ADC_2; //ADC通道2数值
  179. uint16_t ADC_3; //ADC通道3数值
  180. uint8_t ADC1_STA; //ADC通道1检测结果,0通过,1失败
  181. uint8_t ADC2_STA; //ADC通道2检测结果,0通过,1失败
  182. uint8_t ADC3_STA; //ADC通道3检测结果,0通过,1失败
  183. uint8_t OP_24V_1_STA; //24V输出通道1检测结果,0通过,1失败
  184. uint8_t OP_24V_2_STA; //24V输出通道1检测结果,0通过,1失败
  185. uint8_t OP_24V_3_STA; //24V输出通道1检测结果,0通过,1失败
  186. uint8_t OP_24V_4_STA; //24V输出通道1检测结果,0通过,1失败
  187. uint8_t OP_12V_1_STA; //12V输出通道1检测结果,0通过,1失败
  188. uint8_t OP_12V_2_STA; //12V输出通道2检测结果,0通过,1失败
  189. uint8_t OP_5V_1_STA; //5V输出通道1检测结果,0通过,1失败
  190. uint8_t OP_MOTOR_1_STA; //电机驱动1检测结果,0通过,1失败
  191. uint8_t OP_MOTOR_2_STA; //电机驱动2检测结果,0通过,1失败
  192. uint8_t OP_MOTOR_3_STA; //电机驱动3检测结果,0通过,1失败
  193. uint8_t UATR_4_RX_STA;
  194. uint8_t UATR_4_TX_STA;
  195. uint8_t UATR_2_RX_STA;
  196. uint8_t UATR_2_TX_STA;
  197. uint8_t UART_485_STA;
  198. uint8_t VOLTAGE_24V_STA;
  199. uint8_t CURRENT_24V_STA;
  200. uint8_t FLASH_WRITE_STA;
  201. uint8_t FLASH_READ_STA;
  202. uint8_t IN_1_STA;
  203. uint8_t IN_2_STA;
  204. uint8_t IN_3_STA;
  205. uint8_t IN_4_STA;
  206. uint8_t VOLTAGE_5V_STA;
  207. uint8_t VOLTAGE_12V_STA;
  208. uint8_t VOLTAGE_3V3_STA;
  209. uint8_t MCU_TEMPTURE_STA;
  210. uint8_t RESULT; //自检结果,0-通过,1-失败
  211. uint8_t list_all; //检测总数
  212. uint8_t checked; //已检测
  213. }CheckResult;
  214. /************************************************/
  215. #define ON 1
  216. #define OFF 0
  217. #define LED0_PIN GET_PIN(B, 3)
  218. #define Beep GET_PIN(B, 4)
  219. #define OPEN 0x02
  220. #define CLOSE 0x03
  221. /************************************************/
  222. //光控
  223. #define LIGHT_PIN GET_PIN(C,0)
  224. //雨控
  225. #define RAIN_PIN GET_PIN(C,1)
  226. //加热
  227. #define Heat_Pin GET_PIN(B,12)
  228. //采集/上仓门
  229. #define Collect_fan_R GET_PIN(C, 5)
  230. #if PCB_V1 == 0
  231. #define Collect_fan_L GET_PIN(B, 6)
  232. #else
  233. #define Collect_fan_L GET_PIN(C, 4)
  234. #endif
  235. //下仓门
  236. #define C_DOWN_R GET_PIN(B,0)
  237. #define C_DOWN_L GET_PIN(B,1)
  238. //镇流器
  239. #define LAMP_SW GET_PIN(C,9)
  240. //震动电机
  241. #define SHAKE_SW GET_PIN(B,2)
  242. //补光
  243. #define LED_SW GET_PIN(A,15)
  244. //清扫
  245. #define CLEAR_R GET_PIN(C,7)
  246. #define CLEAR_L GET_PIN(C,8)
  247. //相机供电
  248. #define PHOTO GET_PIN(A,12)
  249. //路由器供电
  250. #define ROUTER GET_PIN(A,8)
  251. //RTU/DTU供电
  252. #define RTU_DTU GET_PIN(B,13)
  253. //海康相机拍照
  254. #define HK_TAKE GET_PIN(A,11)
  255. #define HK_IO GET_PIN(B,14) //备用触发拍照
  256. //清扫限位
  257. #define CLEAR_R_LIMIT GET_PIN(C,13)
  258. #define CLEAR_L_LIMIT GET_PIN(B,9)
  259. /*****************************4.0定制多光源*********************************/
  260. #define LAMP_1_SW GET_PIN(B,10)
  261. #define LAMP_2_SW GET_PIN(B,11)
  262. /***************************高空测报灯*************************/
  263. //上仓门电机限位
  264. #define CTR_UPC_LIMIT GET_PIN(B,9)
  265. //下仓门电机限位
  266. #define CTR_DWO_LIMIT GET_PIN(B,5)
  267. #define CTR_DWC_LIMIT GET_PIN(B,8)
  268. //雨控电机限位,控制排水和落虫
  269. #define CTR_RO_LIMIT GET_PIN(B,15)
  270. #define CTR_RC_LIMIT GET_PIN(C,6)
  271. /******************************吸虫塔*********************************/
  272. #define HK_5000W_P GET_PIN(B,12)
  273. #define ROUTER_P GET_PIN(B,10)
  274. #define LED_P GET_PIN(B,11)
  275. #define PC7_TIM3_CH 2 //pwm8
  276. #define PC8_TIM3_CH 3 //pwm8
  277. #define PB1_TIM3_CH 4 //pwm3
  278. #define MOTOR1_CTR_PIN GET_PIN(C,9) //吸虫电机IO
  279. #define MOTOR2_CTR_PIN GET_PIN(B,2) //吸附电机IO
  280. #define MOTOR_CR_PIN GET_PIN(C,7)
  281. #define MOTOR_CL_PIN GET_PIN(C,8)
  282. #define IO_IN1 GET_PIN(C,13) //限位1
  283. #define IO_IN2 GET_PIN(B,9) //限位2
  284. #define IO_IN3 GET_PIN(B,8) //限位3
  285. #define IO_IN4 GET_PIN(B,5) //限位4
  286. void ctr_JD_Clear(uint8_t shake_sw);
  287. uint8_t ctr_Motor_xichong(uint8_t status_ws);
  288. uint8_t ctr_Motor_xifu(uint8_t status_ws);
  289. uint8_t ctr_Camera_Power(uint8_t status_ws);
  290. /*****************************5.0测报灯******************************/
  291. #define GUANG_SHAN GET_PIN(C,13) //光栅
  292. #define MOTOR_86 GET_PIN(B,9) //85电机限位
  293. void ctr_Motor_Driver_Power(uint8_t status_ws);
  294. /*****************************孢子仪**********************************/
  295. //制冷
  296. #define Cold_Pin GET_PIN(B,11)
  297. //采集
  298. #define Collect_Fan GET_PIN(B,10)
  299. //转盘
  300. #define TURN_ZP_R GET_PIN(B,0)
  301. #define TURN_ZP_L GET_PIN(B,1)
  302. //转盘限位
  303. #define LIMIT_0 GET_PIN(C,13)
  304. #define LIMIT_90 GET_PIN(B,9)
  305. //散热
  306. #define Cool_Fan_R GET_PIN(C, 5)
  307. #define Cool_Fan_L GET_PIN(C, 4)
  308. //步进电机限位
  309. #define LIMIT_UP GET_PIN(B,8)
  310. #define LIMIT_DOWN GET_PIN(B,5)
  311. //步进电机驱动
  312. #define Motor_EN GET_PIN(B,14)
  313. #define Motor_DIR GET_PIN(B,15)
  314. void ctr_turn(uint8_t v,uint8_t sta);
  315. uint8_t ctr_Cold(uint8_t status_cold);
  316. uint8_t ctr_Cool_Fan(uint8_t status_cool); //散热风机
  317. uint8_t ctr_Collect_Fan(uint8_t status_collect); //采集风机
  318. void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_out); //步进电机
  319. void ctr_Petroleum_jelly(rt_uint32_t delay); //凡士林
  320. /*****************************定制4.0-2000W***************************************/
  321. #define FAN_P GET_PIN(B,10)
  322. #define FAN_I GET_PIN(B,11)
  323. uint8_t ctr_Fan_IN(uint8_t status_ws);
  324. uint8_t ctr_Fan_PUT(uint8_t status_ws);
  325. /***************************************************************/
  326. uint8_t ctr_Heat(uint8_t status_heat); //加热
  327. uint8_t ctr_cangmen_up(uint8_t status_up); //上仓门
  328. uint8_t ctr_cangmen_down(uint8_t status_down); //下仓门
  329. uint8_t ctr_lamp(uint8_t status_lamp,uint8_t lamp_num); //镇流器
  330. uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec); //震动
  331. uint8_t ctr_clear(uint16_t status_clear); //清扫
  332. void ctr_TG_Clear(uint16_t clear_timeout); //清扫2
  333. uint8_t ctr_led(uint8_t status_led); //补光灯
  334. void calorstat(uint16_t heat_time); //恒温
  335. void ctr_router(uint8_t status_router); //路由器
  336. void turnzp(void); //转仓
  337. void Hk_Take_io(void); //触发拍照
  338. void HK_TakePhoto(void); //拍照
  339. void ctr_photo(uint8_t status_photo);
  340. void ctr_RTU_DTU(uint8_t status_rtu);
  341. void HardWare_Init(uint8_t boot); //初始化
  342. void HardWare_Check(uint8_t boot); //自检
  343. void ResetInit(void); //上电复位
  344. void SunTest(void); //光控测试
  345. /*****************************************************/
  346. void ctr_Motor_OP_3(uint8_t sw);
  347. /***********************孢子仪****************************/
  348. void alarm_app_router(void);
  349. /***************************************************/
  350. //线程
  351. int Control_clear(void);
  352. int Workstatus_check(void);
  353. int Work_Loop_Task(void);
  354. int Control_Check(void);
  355. int thread_485_play(void);
  356. int thread_delete_workloop(void);
  357. int thread_restart_workloop(void);
  358. #endif /* APPLICATIONS_INC_CONTROL_H_ */