control.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 <rtdevice.h>
  15. // 定制相关//////////////////////////////////////////////////////
  16. #define LAMP_EN 0 // 李新3灯管:0关闭,1打开
  17. #define SENSOR_EN 1 // 温湿度:0关闭,1打开
  18. #define ROBOT_EN 0 // 机器人
  19. #define Color_EN 0 // 定制色诱
  20. #define BZYV2_EN 0 // 孢子仪2.0
  21. #define BOOT_ERR 1 // 1-新bootloader,0-旧bootloader()2023年9月份之前的设备升级需要设置为0
  22. ////////////////////////////////////////////////////////////////
  23. #if LAMP_EN == 1
  24. #define VERSION_HK "1.(3ledv6).41(HK)" // 4.0海康-三色光源
  25. #else
  26. #define VERSION_HK "1.51.41(HK)" // 4.0海康-1200W
  27. #endif
  28. #define VERSION_HK_4800W "" // 4.0海康-4800W
  29. #define VERSION_HK_2000W "1.48.4(2000W)" // 4.0水稻
  30. #define VERSION_ZP "1.43.1(ZP)" // 1.0转盘
  31. #define VERSION_GK "1.40.1(GK)" // 1.0高空
  32. #define VERSION_XCT "1.13.6(HK)" // 吸虫塔-海康
  33. #define VERSION_V5 "1.2.5(HK)" // 5.0
  34. #define VERSION_Robot "1.0(robot)" // 展厅机器人
  35. #define VERSION_BZY "2.6.A" // 孢子仪
  36. #define CompileTime rt_sprintf(device_status.driver_compile, "%s-%s", __DATE__, __TIME__) // 编译时间,每次更新代码修改
  37. /*********************************************************************/
  38. extern uint8_t CheckLogTime(int8_t *log_en_cnt , uint8_t log_en_inr);
  39. #define chk_log_time CheckLogTime(&log_en_cnt , log_en_inr) //检查是否打印log的宏定义
  40. /**
  41. * @brief dtype的编号 实际使用中直接填写名称代替编号
  42. *
  43. * 设备类型区分
  44. *
  45. */
  46. typedef enum
  47. {
  48. dt_CBD = 3, // 测报灯
  49. dt_BZY = 7 // 孢子仪
  50. } dtype_list;
  51. /**
  52. * @brief vtype的编号 实际使用中直接填写名称代替编号
  53. *
  54. * 版本号区分
  55. *
  56. */
  57. typedef enum
  58. {
  59. vt_ZP = 1, // 转盘
  60. vt_HK = 4, // 海康
  61. vt_XCT = 6, // 吸虫塔
  62. vt_BZY = 7, // 孢子仪
  63. vt_BZY_JD = 10, // 孢子仪 胶带结构 0x0A
  64. vt_GK = 11, // 高空
  65. vt_ROBOT = 30, // 海康机器人
  66. vt_SD = 41, // 水稻
  67. vt_4800 = 48 // 4800
  68. } vtype_list;
  69. /**
  70. * @brief run_sta的编号 实际使用中直接填写名称代替编号
  71. *
  72. * 主工作流程的状态
  73. */
  74. typedef enum
  75. {
  76. rs_RESET = 0x00 , // 起始状态/复位
  77. rs_COLL_A , // 开始收集A阶段
  78. rs_COLL_B , // 开始收集B阶段
  79. rs_Press_Tape , // 按压胶带
  80. rs_Tape_Move , // 运动到镜头下方
  81. rs_Take_Photo // 拍照
  82. } run_sta_list;
  83. /*
  84. 前:front - F
  85. 后:back - B
  86. 中:center - C
  87. */
  88. typedef enum
  89. {
  90. tl_Front = 0 , // 尚未到
  91. tl_Back , // 已超过
  92. tl_Center , // 处于时间段
  93. tl_Verifi , // 参数校验失败
  94. tl_Error // 无效时间段
  95. }
  96. Temporal_list; // 工作时间段的详细状态划分
  97. typedef enum
  98. {
  99. mct_Foreward = 0 , // 正转
  100. mct_Reversal , // 反转
  101. mct_Stop // 停止
  102. }Motor_Ctl_type; // 适用于电机端口的类型选择
  103. typedef enum
  104. {
  105. lt_Angle_0 = 1 , // 0度限位 对应LIMIT_0->PC13
  106. lt_Angle_90 , // 90 度限位 对应LIMIT_90->PB9
  107. }Limit_type; // 适用于限位开关的类型选择
  108. typedef enum
  109. {
  110. mot_ZP = 0 // 转盘电机
  111. }Motor_type; // 适用于电机端口的类型选择
  112. typedef enum
  113. {
  114. res_OK = 0 , // 执行成功
  115. res_Verifi , // 校验失败
  116. res_Error , // 执行失败
  117. res_Timeout // 超时
  118. } Res_def; // 适用于功能函数的返回值类型
  119. typedef struct _packed
  120. {
  121. uint8_t iSave; // 存储标志位
  122. uint8_t dtype; // 设备类型?7-孢子仪,3-测报灯
  123. /*孢子仪*/
  124. uint8_t run_sta; // 转盘的位置:0原始;1收集;2培养;3拍照;4凡士林,其他-测试
  125. uint8_t cul_time; // 培养时间
  126. uint8_t stay_time; // 已培养时间
  127. uint8_t pre_temp; // 培养仓温度
  128. uint8_t box_temp; // 箱体温度
  129. uint8_t auto_test_sw; // 一键测试 0-关 1-开
  130. uint8_t cold_status; // 制冷状态 0-关 1-开
  131. uint8_t cold_sw; // 制冷开关 0-关 1-开
  132. uint8_t wind_sw; // 风机开关 0-关 1-开
  133. uint8_t collect_fan_status; // 采集状态 0-关 1-开
  134. uint8_t autotakepic; // 对焦拍照 0-关 1-开
  135. uint8_t develop_flag; // 是否进入培养模式
  136. uint8_t cool_fan_status; // 散热风机状态 0-停止 1-打开
  137. uint8_t fsl_sw; // 凡士林开关:0-关,1-开
  138. uint8_t collecting_sh1; // 采集开启1
  139. uint8_t collecting_eh1; // 采集关闭1
  140. uint8_t collecting_sh2; // 采集开启2
  141. uint8_t collecting_eh2; // 采集关闭2
  142. uint8_t collecting_sh3; // 采集开启3
  143. uint8_t collecting_eh3; // 采集关闭3
  144. /*测报灯*/
  145. uint8_t heat_sw; // 加热开关
  146. uint8_t photo_ws; // 拍照
  147. uint8_t power_status; // 电源
  148. uint8_t sun_test; // 光控测测试标志位
  149. uint8_t heat_status; // 加热状态 0-关 1-开
  150. uint8_t lamp_status; // 灯管1状态 0-关 1-开
  151. uint8_t lamp1_status; // 灯管2状态 0-关 1-开
  152. uint8_t lamp2_status; // 灯管3状态 0-关 1-开
  153. uint8_t up_status; // 上仓门状态 0-停止 1-打开 2-关闭
  154. uint8_t down_status; // 下仓门状态 0-停止 1-打开 2-关闭
  155. uint8_t clear_status; // 清扫状态 0-停止 1-开始
  156. uint8_t shake_ws; // 震动 0-关 1-开
  157. uint8_t heatvalue; // 加热设定温度
  158. uint8_t ctr_up_motor; // 上仓门, 1打开,0关闭
  159. uint8_t ctr_down_motor; // 下仓门, 1打开,0关闭
  160. uint8_t rain_status; // 雨控 0-正常 1-欠压
  161. uint8_t temp_status; // 温控 0-正常 1-温控
  162. uint8_t sun_status; // 光控 0-正常 1-光控
  163. uint8_t ds; // 设备状态 0-关机 1-开机
  164. uint8_t work_status; // 工作状态 0-待机 1-工作
  165. uint8_t work_done; // 工作结束 1-正常 0-工作已结束
  166. uint8_t bat_status; // 电压状态 1-正常 0-欠压
  167. uint8_t heattime; // 加热时间
  168. uint8_t heat_time_min; // 实时加热时间
  169. uint8_t clt_time; // 收集时间
  170. uint8_t vol; // 音量
  171. uint8_t refresh_num; // DTU数据刷新时间
  172. uint8_t refresh_timeout; // 刷新超时时间
  173. uint8_t sunBar; // 光控定时时间
  174. uint8_t startBar; // 时控开始时间
  175. uint8_t stopBar; // 时控结束时间
  176. uint8_t tph; // 高温保护
  177. int8_t tpl; // 低温保护
  178. uint8_t timeSwitch; // 模式0光控,1时控
  179. uint8_t link_sta; // 有线接入状态:0-未接入,1已接入
  180. uint8_t heattem; // 加热仓温度(实时)
  181. uint8_t hmi_fresh; // 是否启动屏幕
  182. uint8_t update_flag; // 是否启动升级
  183. uint8_t photo_type; // 相机类型,0-USB,1-海康,2-大华
  184. uint8_t version_type; // 版本类型,1-转盘,4-海康,41-水稻,11-高空,48-4800,A-孢子仪
  185. uint8_t stop_in_bootloader; // 进入bootloader模式 1
  186. uint8_t account_status; // 卡状态
  187. uint8_t test_flag; // 测试标志
  188. uint8_t sensor_485_sta; // 485传感器
  189. #if BOOT_ERR == 1
  190. uint8_t gps_inuse;
  191. uint8_t gps_view;
  192. #endif
  193. uint16_t dattim; // 数据上传间隔
  194. uint16_t shake_sec; // 震动时间
  195. uint16_t thsp; // 息屏时间
  196. rt_uint32_t num_updata; //
  197. rt_uint32_t rebootcnt; // 启动次数
  198. rt_uint32_t light_over_tim; // 光控定时差秒数,镇流器的结束时间
  199. rt_uint32_t data_plan; // 流量套餐
  200. rt_uint32_t expiry_date; // 到期时间
  201. int passWord; // 初始密码
  202. const char *coll_time[10];
  203. char mqttcfg1[64]; //
  204. char mqttcfg2[64]; //
  205. char csq[8]; // 信号强度
  206. char net[8]; // 网络
  207. char sim[8]; // SIM卡
  208. char gps[8]; // 定位类型
  209. char gps_state[8]; // 定位类型
  210. char tempture[12]; // 温度
  211. char humidity[12]; // 湿度
  212. char driver[64]; // 版本
  213. char driver_4g[64]; // 4g版本
  214. char driver_bl[64]; // BL版本
  215. char driver_compile[64]; // BL编译时间
  216. char project[32]; // project,用于判断升级
  217. char lng[32]; // 经度
  218. char lat[32]; // 纬度
  219. char stamp[32]; // 系统时间
  220. char fuse_voltage[32]; // 保险丝电压
  221. char iccid[32]; // SIM卡ICCID
  222. char imei[32]; // IMEI,唯一ID
  223. char json_w_clock[128]; // 修改时间
  224. char json_w_reset[128]; //
  225. char json_w_platform[128]; //
  226. char power[8]; // 功率
  227. char voltage[8]; // 电池电压
  228. } Device_Status_typedef;
  229. /************************************************/
  230. #define ON 1
  231. #define OFF 0
  232. #define LED0_PIN GET_PIN(B, 3)
  233. #define Beep GET_PIN(B, 4)
  234. #define OPEN 0x02
  235. #define CLOSE 0x03
  236. /************************************************/
  237. // 光控
  238. #define LIGHT_PIN GET_PIN(C, 0)
  239. // 雨控
  240. #define RAIN_PIN GET_PIN(C, 1)
  241. // 加热
  242. #define Heat_Pin GET_PIN(B, 12)
  243. // 采集/上仓门
  244. #define Collect_fan_R GET_PIN(C, 5)
  245. #define Collect_fan_L GET_PIN(C, 4)
  246. // 下仓门
  247. #define C_DOWN_R GET_PIN(B, 0)
  248. #define C_DOWN_L GET_PIN(B, 1)
  249. // 镇流器
  250. #define LAMP_SW GET_PIN(C, 9)
  251. // 震动电机
  252. #define SHAKE_SW GET_PIN(B, 2)
  253. // 补光
  254. #define LED_SW GET_PIN(A, 15)
  255. // 清扫
  256. #define CLEAR_R GET_PIN(C, 7)
  257. #define CLEAR_L GET_PIN(C, 8)
  258. // 相机供电
  259. #define PHOTO GET_PIN(A, 12)
  260. // 路由器供电
  261. #define ROUTER GET_PIN(A, 8)
  262. // RTU/DTU供电
  263. #define RTU_DTU GET_PIN(B, 13)
  264. // 海康相机拍照
  265. #define HK_TAKE GET_PIN(A, 11)
  266. #define HK_IO GET_PIN(B, 14) // 备用触发拍照
  267. // 清扫限位
  268. #define CLEAR_R_LIMIT GET_PIN(C, 13)
  269. #define CLEAR_L_LIMIT GET_PIN(B, 9)
  270. /*****************************4.0定制多光源*********************************/
  271. #define LAMP_1_SW GET_PIN(B, 10)
  272. #define LAMP_2_SW GET_PIN(B, 11)
  273. /***************************高空测报灯*************************/
  274. // 上仓门电机限位
  275. #define CTR_UPO_LIMIT GET_PIN(C, 13)
  276. #define CTR_UPC_LIMIT GET_PIN(B, 9)
  277. // 下仓门电机限位
  278. #define CTR_DWO_LIMIT GET_PIN(B, 5)
  279. #define CTR_DWC_LIMIT GET_PIN(B, 8)
  280. // 雨控电机限位,控制排水和落虫
  281. #define CTR_RO_LIMIT GET_PIN(B, 15)
  282. #define CTR_RC_LIMIT GET_PIN(C, 6)
  283. /******************************吸虫塔*********************************/
  284. #define HK_5000W_P GET_PIN(B, 12)
  285. #define ROUTER_P GET_PIN(B, 10)
  286. #define LED_P GET_PIN(B, 11)
  287. #define PC7_TIM3_CH 2 // pwm8
  288. #define PC8_TIM3_CH 3 // pwm8
  289. #define PB1_TIM3_CH 4 // pwm3
  290. #define MOTOR1_CTR_PIN GET_PIN(C, 9) // 吸虫电机IO
  291. #define MOTOR2_CTR_PIN GET_PIN(B, 2) // 吸附电机IO
  292. #define MOTOR_CR_PIN GET_PIN(C, 7)
  293. #define MOTOR_CL_PIN GET_PIN(C, 8)
  294. #define MOTOR_C_LIMIT GET_PIN(C, 13) // 卷带限位
  295. void ctr_JD_Clear(uint8_t shake_sw);
  296. uint8_t ctr_Motor_xichong(uint8_t status_ws);
  297. uint8_t ctr_Motor_xifu(uint8_t status_ws);
  298. uint8_t ctr_Camera_Power(uint8_t status_ws);
  299. /*****************************5.0测报灯******************************/
  300. void ctr_turnv5(void);
  301. /*****************************孢子仪**********************************/
  302. // 制冷
  303. #define Cold_Pin GET_PIN(B, 11)
  304. // 采集
  305. #define Collect_Fan GET_PIN(B, 10)
  306. // 转盘
  307. #define TURN_ZP_R GET_PIN(B, 0)
  308. #define TURN_ZP_L GET_PIN(B, 1)
  309. // 转盘限位
  310. #define LIMIT_0 GET_PIN(C, 13)
  311. #define LIMIT_90 GET_PIN(B, 9)
  312. // 散热
  313. #define Cool_Fan_R GET_PIN(C, 5)
  314. #define Cool_Fan_L GET_PIN(C, 4)
  315. // 步进电机限位
  316. #define LIMIT_UP GET_PIN(B, 8)
  317. #define LIMIT_DOWN GET_PIN(B, 5)
  318. // 步进电机驱动
  319. #define Motor_EN GET_PIN(B, 14)
  320. #define Motor_DIR GET_PIN(B, 15)
  321. void ctr_turn(uint8_t v, uint8_t sta);
  322. uint8_t ctr_Cold(uint8_t status_cold);
  323. uint8_t ctr_Cool_Fan(uint8_t status_cool); // 散热风机
  324. uint8_t ctr_Collect_Fan(uint8_t status_collect); // 采集风机
  325. void ctr_Motor_Driver(uint8_t EN, uint8_t DIR, rt_uint32_t pwm, rt_uint32_t time_out); // 步进电机
  326. void ctr_Petroleum_jelly(rt_uint32_t delay); // 凡士林
  327. /*****************************定制4.0-2000W***************************************/
  328. #define FAN_P GET_PIN(B, 10)
  329. #define FAN_I GET_PIN(B, 11)
  330. uint8_t ctr_Fan_IN(uint8_t status_ws);
  331. uint8_t ctr_Fan_PUT(uint8_t status_ws);
  332. /*******************************定制展厅机器人************************************/
  333. #define LIMIT_OPEN GET_PIN(B, 8)
  334. #define LIMIT_CLOSE GET_PIN(B, 5)
  335. #define Motor_Power GET_PIN(B, 10) // 电机驱动供电
  336. #define Motor_Direction_Button GET_PIN(B, 9) // IO输入,检测按键状态,用于控制方向
  337. #define Motor_Direction_Ctr GET_PIN(B, 15) // IO输出,控制电机运动方向
  338. #define EMS_Dir GET_PIN(B, 14)
  339. void ctr_Motor_Robot(uint8_t status_ws);
  340. /****************************定制色诱***************************************************/
  341. #define LIMIT_RESET GET_PIN(C, 13)
  342. #define LIMIT_BOARD GET_PIN(B, 9)
  343. #define KEY_RESET GET_PIN(B, 8)
  344. #define KEY_BACK GET_PIN(B, 5)
  345. int ctr_Color_board(uint8_t forward, uint16_t time_board);
  346. /***************************************************************/
  347. /***************************************************************/
  348. uint8_t ctr_Heat(uint8_t status_heat); // 加热
  349. uint8_t ctr_cangmen_up(uint8_t status_up); // 上仓门
  350. uint8_t ctr_cangmen_down(uint8_t status_down); // 下仓门
  351. uint8_t ctr_lamp(uint8_t status_lamp, uint8_t lamp_num); // 镇流器
  352. uint8_t ctr_shake(uint8_t status_shake, uint16_t shake_sec); // 震动
  353. uint8_t ctr_clear(uint16_t status_clear); // 清扫
  354. void ctr_TG_Clear(uint16_t clear_timeout); // 清扫2
  355. uint8_t ctr_led(uint8_t status_led); // 补光灯
  356. void calorstat(uint16_t heat_time); // 恒温
  357. void ctr_router(uint8_t status_router); // 路由器
  358. void turnzp(void); // 转仓
  359. void Hk_Take_io(void); // 触发拍照
  360. void HK_TakePhoto(void); // 拍照
  361. void ctr_photo(uint8_t status_photo);
  362. void ctr_RTU_DTU(uint8_t status_rtu);
  363. void HardWare_Init(uint8_t boot); // 初始化
  364. void HardWare_Check(uint8_t boot); // 自检
  365. void ResetInit(void); // 上电复位
  366. void SunTest(void); // 光控测试
  367. /*****************************************************/
  368. void WorkTask_XCT(void);
  369. /****************************************************/
  370. void WorkCheck(void); // 工作检测
  371. void WorkTask(void); // 工作任务
  372. //
  373. /***********************孢子仪****************************/
  374. void BZY_JD_AutoTest(void); //孢子仪 一键测试
  375. /***************************************************/
  376. // 线程
  377. int Control_clear(void);
  378. int Workstatus_check(void);
  379. int Work_Loop_Task(void);
  380. int Control_heat(void);
  381. #endif /* APPLICATIONS_INC_CONTROL_H_ */