control.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 SENSOR_EN 0 //温湿度:0关闭,1打开
  19. #define ROBOT_EN 0 //机器人
  20. #define Color_EN 0 //定制色诱
  21. #define BZYV2_EN 0 //孢子仪2.0
  22. ////////////////////////////////////////////////////////////////
  23. #define VERSION_BZY "2.1.0" //孢子仪
  24. /*********************************************************************/
  25. typedef struct _packed
  26. {
  27. uint8_t iSave; //存储标志位
  28. uint8_t dtype; //设备类型?7-孢子仪,3-测报灯
  29. /*孢子仪*/
  30. uint8_t run_sta; //转盘的位置:0原始;1收集;2培养;3拍照;4凡士林,其他-测试
  31. uint8_t cul_time; //培养时间
  32. uint8_t stay_time; //已培养时间
  33. uint8_t pre_temp; //培养仓温度
  34. uint8_t box_temp; //箱体温度
  35. uint8_t auto_test_sw; //一键测试 0-关 1-开
  36. uint8_t cold_status; //制冷状态 0-关 1-开
  37. uint8_t cold_sw; //制冷开关 0-关 1-开
  38. uint8_t wind_sw; //风机开关 0-关 1-开
  39. uint8_t collect_fan_status; //采集状态 0-关 1-开
  40. uint8_t autotakepic; //对焦拍照 0-关 1-开
  41. uint8_t develop_flag; //是否进入培养模式
  42. uint8_t cool_fan_status; //散热风机状态 0-停止 1-打开
  43. uint8_t fsl_sw; //凡士林开关:0-关,1-开
  44. uint8_t collecting_sh1; //采集开启1
  45. uint8_t collecting_eh1; //采集关闭1
  46. uint8_t collecting_sh2; //采集开启2
  47. uint8_t collecting_eh2; //采集关闭2
  48. uint8_t collecting_sh3; //采集开启3
  49. uint8_t collecting_eh3; //采集关闭3
  50. /*测报灯*/
  51. uint8_t heat_sw; //加热开关
  52. uint8_t photo_ws; //拍照
  53. uint8_t power_status; //电源
  54. uint8_t sun_test; //光控测测试标志位
  55. uint8_t heat_status; //加热状态 0-关 1-开
  56. uint8_t lamp_status; //灯管1状态 0-关 1-开
  57. uint8_t lamp1_status; //灯管2状态 0-关 1-开
  58. uint8_t lamp2_status; //灯管3状态 0-关 1-开
  59. uint8_t up_status; //上仓门状态 0-停止 1-打开 2-关闭
  60. uint8_t down_status; //下仓门状态 0-停止 1-打开 2-关闭
  61. uint8_t clear_status; //清扫状态 0-停止 1-开始
  62. uint8_t shake_ws; //震动 0-关 1-开
  63. uint8_t heatvalue; //加热设定温度
  64. uint8_t ctr_up_motor; //上仓门, 1打开,0关闭
  65. uint8_t ctr_down_motor; //下仓门, 1打开,0关闭
  66. uint8_t rain_status; //雨控 0-正常 1-欠压
  67. uint8_t temp_status; //温控 0-正常 1-温控
  68. uint8_t sun_status; //光控 0-正常 1-光控
  69. uint8_t ds; //设备状态 0-关机 1-开机
  70. uint8_t work_status; //工作状态 0-待机 1-工作
  71. uint8_t work_done; //工作结束 1-正常 0-工作已结束
  72. uint8_t bat_status; //电压状态 1-正常 0-欠压
  73. uint8_t heattime; //加热时间
  74. uint8_t heat_time_min; //实时加热时间
  75. uint8_t clt_time; //收集时间
  76. uint8_t vol; //音量
  77. uint8_t refresh_num; //DTU数据刷新时间
  78. uint8_t refresh_timeout; //刷新超时时间
  79. uint8_t sunBar; //光控定时时间
  80. uint8_t startBar; //时控开始时间
  81. uint8_t stopBar; //时控结束时间
  82. uint8_t tph; //高温保护
  83. int8_t tpl; //低温保护
  84. uint8_t timeSwitch; //模式0光控,1时控
  85. uint8_t link_sta; //有线接入状态:0-未接入,1已接入
  86. uint8_t heattem; //加热仓温度(实时)
  87. uint8_t hmi_fresh; //是否启动屏幕
  88. uint8_t update_flag; //是否启动升级
  89. uint8_t photo_type; //相机类型,0-USB,1-海康,2-大华
  90. uint8_t version_type; //版本类型,1-转盘,4-海康,41-水稻,11-高空,48-4800
  91. uint8_t stop_in_bootloader; //进入bootloader模式 1
  92. uint8_t account_status; //卡状态
  93. uint8_t test_flag; //测试标志
  94. uint8_t sensor_485_sta; //485传感器
  95. uint8_t Power_Type; //供电类型
  96. uint8_t handle_bugger; //排虫模式,0推杆收回来是排虫,1推出去是收虫
  97. uint8_t collt_box_sta; //收虫仓状态
  98. uint8_t camsta; //拍照报警,0正常,1异常
  99. uint8_t heat_sta; //加热报警0-正常,1-异常
  100. uint8_t led_sta; //补光灯报警0-正常,1-异常
  101. uint8_t selfcheck_ws; //自检开关1-北大荒,2-标配
  102. uint8_t step_focus;
  103. #if BOOT_ERR == 1
  104. uint8_t gps_inuse;
  105. uint8_t gps_view;
  106. #endif
  107. uint16_t dattim; //数据上传间隔
  108. uint16_t shake_sec; //震动时间
  109. uint16_t thsp; //息屏时间
  110. uint16_t C01; //故障码
  111. rt_uint32_t num_updata; //
  112. rt_uint32_t rebootcnt; //启动次数
  113. rt_uint32_t light_over_tim; //光控定时差秒数,镇流器的结束时间
  114. rt_uint32_t data_plan; //流量套餐
  115. rt_uint32_t expiry_date; //到期时间
  116. double focus_value;
  117. int passWord; //初始密码
  118. double process;
  119. long photo_stamp; //采集时间戳
  120. const char *coll_time[10];
  121. char mqttcfg1[64]; //
  122. char mqttcfg2[64]; //
  123. char csq[8]; //信号强度
  124. char net[8]; //网络
  125. char sim[8]; //SIM卡
  126. char gps[8]; //定位类型
  127. char gps_state[8]; //定位类型
  128. char tempture[12]; //温度
  129. char humidity[12]; //湿度
  130. char driver[64]; //版本
  131. char driver_4g[64]; //4g版本
  132. char driver_bl[64]; //BL版本
  133. char driver_compile[64]; //BL编译时间
  134. char project[32]; //project,用于判断升级
  135. char lng[32]; //经度
  136. char lat[32]; //纬度
  137. char stamp[32]; //系统时间
  138. char fuse_voltage[32]; //保险丝电压
  139. char iccid[32]; //SIM卡ICCID
  140. char imei[32]; //IMEI,唯一ID
  141. char json_w_clock[128]; //修改时间
  142. char json_w_reset[128]; //
  143. char json_w_platform[128]; //
  144. char power[8]; //功率
  145. char heat_power[8]; //加热功率
  146. char voltage[6]; //电池电压
  147. char deviceId[32]; //bdh-设备编码
  148. char voltage_sun[8]; //太阳能板电压
  149. char qianming[128];
  150. char photolink[128]; //图片地址
  151. }Device_Status_typedef;
  152. /**************滑台数据********************/
  153. typedef struct
  154. {
  155. uint32_t xdis; //x轴坐标移动距离
  156. uint32_t ydis;
  157. uint32_t zdis; //z轴坐标移动距离
  158. uint32_t pulse_period; //滑台的运动速度 1为最高
  159. uint16_t dxdis; //x轴坐标蛇形移动间距距离
  160. uint16_t dzdis; //z轴坐标蛇形移动间距距离
  161. uint8_t xdir; //x轴坐标移动方向
  162. uint8_t ydir; //y轴坐标移动方向
  163. uint8_t zdir; //z轴坐标移动方向
  164. uint8_t en_slide; //
  165. uint8_t zccwl_on; //z轴限位开关信号 高电平为触发限位
  166. uint8_t xccwl_on; //x轴限位开关信号 高电平为触发限位
  167. uint8_t stop_flag; //滑台停止标志位
  168. }Device_slide_typedef;
  169. /************************************************/
  170. #define ON 1
  171. #define OFF 0
  172. #define LED0_PIN GET_PIN(B, 3)
  173. #define Beep GET_PIN(B, 4)
  174. #define OPEN 0x02
  175. #define CLOSE 0x03
  176. /************************************************/
  177. //光控
  178. #define LIGHT_PIN GET_PIN(C,0)
  179. //雨控
  180. #define RAIN_PIN GET_PIN(C,1)
  181. //加热
  182. #define Heat_Pin GET_PIN(B,12)
  183. //采集/上仓门
  184. #define Collect_fan_R GET_PIN(C, 5)
  185. #define Collect_fan_L GET_PIN(B, 6)
  186. //下仓门
  187. #define C_DOWN_R GET_PIN(B,0)
  188. #define C_DOWN_L GET_PIN(B,1)
  189. //镇流器
  190. #define LAMP_SW GET_PIN(C,9)
  191. //震动电机
  192. #define SHAKE_SW GET_PIN(B,2)
  193. //补光
  194. #define LED_SW GET_PIN(A,15)
  195. //清扫
  196. #define CLEAR_R GET_PIN(C,7)
  197. #define CLEAR_L GET_PIN(C,8)
  198. //相机供电
  199. #define PHOTO GET_PIN(A,12)
  200. //路由器供电
  201. #define ROUTER GET_PIN(A,8)
  202. //RTU/DTU供电
  203. #define RTU_DTU GET_PIN(B,13)
  204. //海康相机拍照
  205. #define HK_TAKE GET_PIN(A,11)
  206. #define HK_IO GET_PIN(B,14) //备用触发拍照
  207. //清扫限位
  208. #define CLEAR_R_LIMIT GET_PIN(C,13)
  209. /*****************************4.0定制多光源*********************************/
  210. #define LAMP_1_SW GET_PIN(B,10)
  211. #define LAMP_2_SW GET_PIN(B,11)
  212. /***************************高空测报灯*************************/
  213. //上仓门电机限位
  214. #define CTR_UPO_LIMIT GET_PIN(C,13)
  215. //下仓门电机限位
  216. #define CTR_DWO_LIMIT GET_PIN(B,5)
  217. #define CTR_DWC_LIMIT GET_PIN(B,8)
  218. //雨控电机限位,控制排水和落虫
  219. #define CTR_RO_LIMIT GET_PIN(B,15)
  220. #define CTR_RC_LIMIT GET_PIN(C,6)
  221. /******************************吸虫塔*********************************/
  222. #define HK_5000W_P GET_PIN(B,12)
  223. #define ROUTER_P GET_PIN(B,10)
  224. #define LED_P GET_PIN(B,11)
  225. #define PC7_TIM3_CH 2 //pwm8
  226. #define PC8_TIM3_CH 3 //pwm8
  227. #define PB1_TIM3_CH 4 //pwm3
  228. #define MOTOR1_CTR_PIN GET_PIN(C,9) //吸虫电机IO
  229. #define MOTOR2_CTR_PIN GET_PIN(B,2) //吸附电机IO
  230. #define MOTOR_CR_PIN GET_PIN(C,7)
  231. #define MOTOR_CL_PIN GET_PIN(C,8)
  232. #define MOTOR_C_LIMIT GET_PIN(C,13) //卷带限位
  233. void ctr_JD_Clear(uint8_t shake_sw);
  234. uint8_t ctr_Motor_xichong(uint8_t status_ws);
  235. uint8_t ctr_Motor_xifu(uint8_t status_ws);
  236. uint8_t ctr_Camera_Power(uint8_t status_ws);
  237. /*****************************5.0测报灯******************************/
  238. void ctr_turnv5(void);
  239. /*****************************孢子仪**********************************/
  240. //制冷
  241. #define Cold_Pin GET_PIN(B,11)
  242. //采集
  243. #define Collect_Fan GET_PIN(B,10)
  244. //转盘
  245. #define TURN_ZP_R GET_PIN(B,0)
  246. #define TURN_ZP_L GET_PIN(B,1)
  247. //转盘限位
  248. #define LIMIT_0 GET_PIN(C,13)
  249. //散热
  250. #define Cool_Fan_R GET_PIN(C, 5)
  251. #define Cool_Fan_L GET_PIN(C, 4)
  252. //步进电机限位
  253. #define LIMIT_UP GET_PIN(B,8)
  254. #define LIMIT_DOWN GET_PIN(B,5)
  255. //步进电机驱动
  256. #define Motor_EN GET_PIN(B,14)
  257. #define Motor_DIR GET_PIN(B,15)
  258. void ctr_turn(uint8_t v,uint8_t sta);
  259. uint8_t ctr_Cold(uint8_t status_cold);
  260. uint8_t ctr_Cool_Fan(uint8_t status_cool); //散热风机
  261. uint8_t ctr_Collect_Fan(uint8_t status_collect); //采集风机
  262. void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_out); //步进电机
  263. void ctr_Petroleum_jelly(rt_uint32_t delay); //凡士林
  264. /*****************************定制4.0-2000W***************************************/
  265. #define FAN_P GET_PIN(B,10)
  266. #define FAN_I GET_PIN(B,11)
  267. uint8_t ctr_Fan_IN(uint8_t status_ws);
  268. uint8_t ctr_Fan_PUT(uint8_t status_ws);
  269. /***************************************************************/
  270. /***************************************************************/
  271. uint8_t ctr_Heat(uint8_t status_heat); //加热
  272. uint8_t ctr_cangmen_up(uint8_t status_up); //上仓门
  273. uint8_t ctr_cangmen_down(uint8_t status_down); //下仓门
  274. uint8_t ctr_lamp(uint8_t status_lamp,uint8_t lamp_num); //镇流器
  275. uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec); //震动
  276. uint8_t ctr_clear(uint16_t status_clear); //清扫
  277. void ctr_TG_Clear(uint16_t clear_timeout); //清扫2
  278. uint8_t ctr_led(uint8_t status_led); //补光灯
  279. void calorstat(uint16_t heat_time); //恒温
  280. void ctr_router(uint8_t status_router); //路由器
  281. void turnzp(void); //转仓
  282. void Hk_Take_io(void); //触发拍照
  283. void HK_TakePhoto(void); //拍照
  284. void ctr_photo(uint8_t status_photo);
  285. void ctr_RTU_DTU(uint8_t status_rtu);
  286. void HardWare_Init(uint8_t boot); //初始化
  287. void HardWare_Check(uint8_t boot); //自检
  288. void ResetInit(void); //上电复位
  289. void SunTest(void); //光控测试
  290. /*****************************************************/
  291. void WorkTask_XCT(void);
  292. /****************************************************/
  293. void WorkCheck(void); //工作检测
  294. void WorkTask(void); //工作任务
  295. //
  296. /***********************孢子仪2.0****************************/
  297. #define X_ 0
  298. #define Y_ 1
  299. #define Z_ 2
  300. #define Limit_Motor_X GET_PIN(C,13) //IO输入,X轴限位
  301. #define Limit_Motor_Z GET_PIN(B,9) //IO输入,Y轴限位
  302. #define Limit_Motor_Y GET_PIN(B,8) //IO输入,Z轴限位
  303. uint8_t ctr_swz(uint8_t status_swz); //z轴的电机开关控制
  304. uint32_t mapSpeed(int a1);
  305. uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint32_t pulse);
  306. void stop_move(void);
  307. void slidelock(); //电机移动完毕后上锁
  308. void turnlimit(void); //位移兼限位开关功能
  309. /***************************************************/
  310. //线程
  311. int Workstatus_check(void);
  312. int Work_Loop_Task(void);
  313. int slide_Fresh(void);
  314. int thread_delete_workloop(void);
  315. int thread_restart_workloop(void);
  316. #endif /* APPLICATIONS_INC_CONTROL_H_ */