state_mini.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * state_mini.h
  3. *
  4. * Created on: 2026年6月29日
  5. * Author: dell
  6. */
  7. #ifndef __STATE_MINI_H
  8. #define __STATE_MINI_H
  9. #define MAX_DATA_BUF_SIZE 36
  10. #define SystemChecking 0
  11. #define SystemOK 1
  12. #define SystemError 2
  13. #define SKIP_CHECK_CARDINSERT (1 << 0) //开始检测插卡正确
  14. #define SKIP_CHECK_CARDREMOVE (1 << 1) //运行过程中检测插卡拔卡
  15. #define SKIP_HEATONCHECK_OK (1 << 2) //跳过加热,不管加热状态
  16. #define SKIP_SAMPLIGHT_ACC (1 << 3) //上报加速
  17. #define SKIP_SCANQRCODE (1 << 4) //上报加速
  18. #define SKIP_FARSTRUN (1 << 5) //上报加速
  19. #define SKIP_SLAVEDATASCOP (1 << 6) //从模块datascop上报
  20. #define HEAT_OFF 0x00 //关加热
  21. #define HEAT_ON 0x01 //开加热
  22. #define HEAT_STOP 0x02 //停止加热
  23. #define FAN_ON 0x02 //启用风扇
  24. #define sampleTotalTimes 181
  25. typedef enum StatusWord
  26. {
  27. // 所有板卡准备自检,包含通道预加热
  28. SW_Read_To_Board_Selftest = -1,
  29. // 准备和PC握手
  30. SW_Ready_To_Shake_On = 0,
  31. // 故障
  32. SW_Fault = 1,
  33. // 获取温度,两通道通道加热
  34. SW_Switch_On_Pre_Heat = 8,
  35. // 快速停止
  36. SW_Quick_stop = 30,
  37. // 等温度稳定后
  38. SW_Target_reached = 10,
  39. // 等待扫码
  40. SW_Scan_Qrcode = 12,
  41. // 插卡,通道检测
  42. SW_Chip_Id = 14,
  43. // 条码信息匹配,下发
  44. SW_Qrcode_publish = 16,
  45. // 采样,30min定时
  46. SW_Sample_timeout = 18,
  47. // 计算,阈值范围,所有孔的结果(阴阳性、无效)
  48. // 结果上传&数据上传
  49. SW_result_report = 25,
  50. SW_move_card = 26, //拔卡,进入下一次流程循环
  51. SW_SystemError
  52. } StatusWord_t;
  53. // pc Controlword commands
  54. typedef enum Controlword
  55. {
  56. Board_Selftest_cmd,
  57. Hand_Shake_cmd,
  58. Scan_ready_Qrcode_cmd,
  59. Scan_Qrcode_cmd,
  60. Pre_Heat_cmd,
  61. Target_reached_cmd,
  62. Chip_Id_cmd,
  63. Qrcode_publish_cmd,
  64. Sample_timeout_cmd,
  65. result_report_cmd,
  66. result_move_card
  67. } Controlword_t;
  68. //故障码
  69. enum ERROR_CODE
  70. {
  71. ERROR_HEAT_INSERT_CARD = 101, //温度稳定前插卡
  72. ERROR_NO_QRCODE = 102, //未扫码就插卡
  73. ERROR_SAMP_MOVE_CARD = 103, //检测中拔卡
  74. ERROR_SENSOR_SELF_CHECK= 104, //光电自检失败
  75. ERROR_HEAT_SELF_CHECK= 105, //加热自检失败
  76. ERROR_MCU_LINK_TIMEOUT = 106, //mcut通讯超时
  77. ERROR_PRE_HEAT_TIMEOUT = 107, //预热超时
  78. ERROR_HEAT_TIMEOUT = 108, //加热超时
  79. ERROR_MOTOR_FIALED = 109, //电机
  80. ERROR_TUPE_MOVE = 110, //检测过程中拔试管
  81. ERROR_TUPE_EXIST = 111, //检测过程中拔试管
  82. ERROR_HEATFUC_EER = 112, //加热模块无反应
  83. ERROR_TEMPSENSOR_EER = 113, //温度传感器异常
  84. };
  85. typedef struct inner_action_flags_t
  86. {
  87. uint8_t selftest_allowed : 1;
  88. uint8_t scan_qrcode_allowed : 1;
  89. uint8_t pre_heat_enabled : 1;
  90. uint8_t target_reached : 1;
  91. uint8_t check_chipid_enabled : 1;
  92. uint8_t qrcode_info_applied : 1;
  93. } inner_action_flags_t;
  94. typedef struct
  95. {
  96. uint8_t Devicenum; //设备编号
  97. char card_num[10]; //卡盒编号
  98. uint8_t hole1_item; //孔1检测项目
  99. uint8_t hole1_item_result; //孔1检测项目结果
  100. uint8_t hole1_result; //孔1检测结果
  101. uint8_t hole1_Tt[2]; //孔1 Tt
  102. uint8_t hole2_item; //孔2检测项目
  103. uint8_t hole2_item_result; //孔2检测项目结果
  104. uint8_t hole2_result; //孔2检测结果
  105. uint8_t hole2_Tt[2] ; //孔2 Tt
  106. uint8_t hole3_item; //孔3检测项目
  107. uint8_t hole3_item_result; //孔3检测项目结果
  108. uint8_t hole3_result; //孔3检测结果
  109. uint8_t hole3_Tt[2]; //孔3 Tt
  110. uint8_t hole4_item; //孔4检测项目
  111. uint8_t hole4_item_result; //孔4检测项目结果
  112. uint8_t hole4_result; //孔4检测结果
  113. uint8_t hole4_Tt[2]; //孔4 Tt
  114. uint8_t hole5_item; //孔5检测项目
  115. uint8_t hole5_item_result; //孔5检测项目结果
  116. uint8_t hole5_result; //孔5检测结果
  117. uint8_t hole5_Tt[2]; //孔5 Tt
  118. uint8_t hole6_item; //孔6检测项目
  119. uint8_t hole6_item_result; //孔6检测项目结果
  120. uint8_t hole6_result; //孔6检测结果
  121. uint8_t hole6_Tt[2]; //孔6 Tt
  122. uint8_t hole7_item; //孔7检测项目
  123. uint8_t hole7_item_result; //孔7检测项目结果
  124. uint8_t hole7_result; //孔7检测结果
  125. uint8_t hole7_Tt[2]; //孔7 Tt
  126. uint8_t hole8_item; //孔8检测项目
  127. uint8_t hole8_item_result; //孔8检测项目结果
  128. uint8_t hole8_result; //孔8检测结果
  129. uint8_t hole8_Tt[2]; //孔8 Tt
  130. uint8_t hole9_item; //孔9检测项目
  131. uint8_t hole9_item_result; //孔9检测项目结果
  132. uint8_t hole9_result; //孔9检测结果
  133. uint8_t hole9_Tt[2]; //孔9 Tt
  134. uint8_t hole10_item; //孔10检测项目
  135. uint8_t hole10_item_result; //孔10检测项目结果
  136. uint8_t hole10_result; //孔10检测结果
  137. uint8_t hole10_Tt[2]; //孔10 Tt
  138. }test_result_struct;
  139. typedef struct str_error_info
  140. {
  141. uint8_t id; //板卡id
  142. uint8_t error_code; //错误码
  143. char SN[10];
  144. uint8_t error_report; //错误码
  145. } str_error_info_t;
  146. typedef struct str_hole_info
  147. {
  148. uint8_t item;
  149. uint8_t TtMax[2];
  150. uint8_t TtMin[2];
  151. } str_hole_info_t;
  152. //str_hole_info_t hole1,hole2,hole3,hole4,hole5,hole6,hole7,hole8,hole9,hole10;
  153. typedef struct str_card_param_info
  154. {
  155. char pid[10];
  156. uint8_t temp[2];
  157. struct str_hole_info hole_info[10];
  158. } str_card_param_info_t;
  159. typedef struct
  160. {
  161. uint8_t id; //设备编号
  162. uint8_t heat_state; //串口控制加热状态
  163. uint8_t temp_stable_sta; //串口控制加热状态
  164. float heater_temp; //加热体温度
  165. uint8_t fan_state; //风扇状态
  166. float heater_independent_temp;
  167. }heat_ctrl_struct;
  168. typedef struct //由于flash_write是按4字节写入,所以本结构体内部都按4字节定义和对齐
  169. {
  170. float presetTempVal; //拉升温度
  171. uint32_t presetTempTime; //拉升保持时间
  172. float setTempVal; //设定温度
  173. float holdTemp; //稳定温度
  174. float tempOffset; //温度补偿
  175. uint32_t preHeatTime; //上电预热时间,min
  176. float readyTemp; //就绪温度
  177. uint32_t log_level; //日志等级
  178. uint32_t skip_CheckOrRun; //插入光变化检测
  179. float adjtemp; //调整温度
  180. }CFG_PARAM_STRUCT;
  181. typedef struct ProcessStateMachine
  182. {
  183. StatusWord_t state;
  184. inner_action_flags_t flags;
  185. float DataBufRDR[MAX_DATA_BUF_SIZE][10];
  186. uint32_t DataSendHeader; //串口超时
  187. uint32_t DataSendLast; //串口超时
  188. unsigned int sendconter;
  189. unsigned int updateresult;
  190. unsigned int cursendok;
  191. unsigned int sendTime ;
  192. unsigned int sampleStart;
  193. unsigned int sampleTimes;
  194. unsigned int heat_timeout; //加热超时
  195. unsigned int scan_qrcode_done;
  196. unsigned int statusword;
  197. unsigned int controlword;
  198. str_card_param_info_t card_param_info;
  199. } ProcessStateMachine_t;
  200. void updateData_next(unsigned int recdex,unsigned char * part);
  201. void clean_reult_next(unsigned char * part);
  202. void resetSampleData(void);
  203. uint8_t error_set(uint8_t error);
  204. void error_clear(void);
  205. void usr_state_machine(ProcessStateMachine_t *sts);
  206. #endif