state_mini.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. #include "onechip_include_header.h"
  2. #define CardON 1
  3. #define CardOFF 0
  4. uint32_t g_card_tick_s = 0; //插卡计时S
  5. uint8_t cardonsta = 0;
  6. int samp_time = 0;
  7. int samp_num = 0;
  8. uint8_t datasope_flag = 0;
  9. str_error_info_t error_info = {0}; //错误信息
  10. // test_result_struct result = {0};
  11. heat_ctrl_struct g_heat_ctrl = {0};
  12. uint8_t ckeck_sum(uint8_t *data, int size)
  13. {
  14. uint32_t sum = 0;
  15. for(int i = 0; i < size; i++)
  16. {
  17. sum += data[i];
  18. }
  19. return (sum & 0xFF);
  20. }
  21. float get_avg(float value[10])
  22. {
  23. float sum = 0;
  24. for(int i = 0; i < 10; i++)
  25. {
  26. sum += value[i];
  27. }
  28. sum /= 10;
  29. return sum;
  30. }
  31. float get_std_avg(float value[10])
  32. {
  33. float sum = 0;
  34. float avg = 0;
  35. avg = get_avg(value);
  36. for(int i = 0; i < 10; i++)
  37. {
  38. sum += (value[i] - avg) * (value[i] - avg);
  39. }
  40. sum = sqrtf(sum / 9) / avg;
  41. return sum;
  42. }
  43. float get_max_min(float value[10])
  44. {
  45. float max = 0;
  46. float min = 99999;
  47. for(int i = 0; i < 10; i++)
  48. {
  49. if(value[i] > max)
  50. max = value[i];
  51. if(value[i] < min)
  52. min = value[i];
  53. }
  54. return (max - min);
  55. }
  56. void DatascopeSend(int number,float value1,float value2, float value3, float value4, float value5,
  57. float value6,float value7,float value8,float value9,float value10,float value11)//date_scope 10ch driver
  58. {
  59. unsigned char SendCount;
  60. float temp;
  61. #ifdef ONECHIP_MINI_PLUS
  62. uint8_t DataScopeOutPutBuffer[60]; // Serial port send buffer
  63. *(uint32_t*)&DataScopeOutPutBuffer[0] = number;
  64. *(uint32_t*)&DataScopeOutPutBuffer[4] = *(uint32_t*)&value1;
  65. *(uint32_t*)&DataScopeOutPutBuffer[8] = *(uint32_t*)&value2;
  66. *(uint32_t*)&DataScopeOutPutBuffer[12] = *(uint32_t*)&value3;
  67. *(uint32_t*)&DataScopeOutPutBuffer[16] = *(uint32_t*)&value4;
  68. *(uint32_t*)&DataScopeOutPutBuffer[20] = *(uint32_t*)&value5;
  69. *(uint32_t*)&DataScopeOutPutBuffer[24] = *(uint32_t*)&value6;
  70. *(uint32_t*)&DataScopeOutPutBuffer[28] = *(uint32_t*)&value7;
  71. *(uint32_t*)&DataScopeOutPutBuffer[32] = *(uint32_t*)&value8;
  72. *(uint32_t*)&DataScopeOutPutBuffer[36] = *(uint32_t*)&value9;
  73. *(uint32_t*)&DataScopeOutPutBuffer[40] = *(uint32_t*)&value10;
  74. *(uint32_t*)&DataScopeOutPutBuffer[44] = *(uint32_t*)&value11; //时间
  75. temp = get_max_min((float*)DataScopeOutPutBuffer);
  76. *(uint32_t*)&DataScopeOutPutBuffer[48] = *(uint32_t*)&temp; //极差
  77. temp = get_std_avg((float*)DataScopeOutPutBuffer);
  78. *(uint32_t*)&DataScopeOutPutBuffer[52] = *(uint32_t*)&temp; //离散系数
  79. SendCount=56;
  80. DataScopeOutPutBuffer[SendCount] = ckeck_sum(DataScopeOutPutBuffer, SendCount);
  81. #else
  82. uint8_t DataScopeOutPutBuffer[56]; // Serial port send buffer
  83. *(uint32_t*)&DataScopeOutPutBuffer[0] = *(uint32_t*)&value1;
  84. *(uint32_t*)&DataScopeOutPutBuffer[4] = *(uint32_t*)&value2;
  85. *(uint32_t*)&DataScopeOutPutBuffer[8] = *(uint32_t*)&value3;
  86. *(uint32_t*)&DataScopeOutPutBuffer[12] = *(uint32_t*)&value4;
  87. *(uint32_t*)&DataScopeOutPutBuffer[16] = *(uint32_t*)&value5;
  88. *(uint32_t*)&DataScopeOutPutBuffer[20] = *(uint32_t*)&value6;
  89. *(uint32_t*)&DataScopeOutPutBuffer[24] = *(uint32_t*)&value7;
  90. *(uint32_t*)&DataScopeOutPutBuffer[28] = *(uint32_t*)&value8;
  91. *(uint32_t*)&DataScopeOutPutBuffer[32] = *(uint32_t*)&value9;
  92. *(uint32_t*)&DataScopeOutPutBuffer[36] = *(uint32_t*)&value10;
  93. *(uint32_t*)&DataScopeOutPutBuffer[40] = *(uint32_t*)&value11; //时间
  94. temp = get_max_min((float*)DataScopeOutPutBuffer);
  95. *(uint32_t*)&DataScopeOutPutBuffer[44] = *(uint32_t*)&temp; //极差
  96. temp = get_std_avg((float*)DataScopeOutPutBuffer);
  97. *(uint32_t*)&DataScopeOutPutBuffer[48] = *(uint32_t*)&temp; //离散系数
  98. SendCount=52;
  99. DataScopeOutPutBuffer[SendCount] = ckeck_sum(DataScopeOutPutBuffer, SendCount);
  100. #endif
  101. SendCount++;
  102. data_send_to_pc(PC_CMD_DATASCOPE,(char *)DataScopeOutPutBuffer,SendCount);
  103. }
  104. int TrigStateCheck(ProcessStateMachine_t *sts)
  105. {
  106. return (HAL_GPIO_ReadPin((GPIO_TypeDef *)sts->card_port,sts->card_pin)) ? 1 : 0; //
  107. }
  108. uint32_t get_master_st(float *temp,unsigned int *st) {
  109. *temp = sysinf.heaterMaster.pid.realtemp;
  110. *st = sysinf.psmMaster.state;
  111. return 0;
  112. }
  113. uint32_t get_slave_st(float *temp,unsigned int *st) {
  114. *temp = sysinf.heaterSlave.pid.realtemp;
  115. *st = sysinf.psmSlave.state;
  116. return 0;
  117. }
  118. uint8_t is_command(uint16_t controlword, Controlword_t command_to_check)
  119. {
  120. return (controlword) == command_to_check;
  121. }
  122. void updateData(ProcessStateMachine_t *psm)
  123. {
  124. if(psm->cursendok == 0){
  125. return;
  126. }
  127. if (check_to_pc_busy()){
  128. if(psm->DataSendHeader != psm->DataSendLast){
  129. /*1.5s 无应答,或者当前发送完成*/
  130. psm->cursendok = 0;
  131. psm->sendTime = 3;
  132. char data[55] = {0};
  133. memcpy(&data[1], psm->card_param_info.pid, 10);
  134. memcpy(&data[11],&psm->DataBufRDR[psm->DataSendHeader], 40);
  135. memcpy(&data[51],&psm->sendconter, 4);
  136. if(0 == data_send_to_pc(PC_CMD_DATA_UPLOAD, data, sizeof(data))){
  137. Van_Device_Printf(VAN_LOG_WIFI, "send Header:%d last:%d sendconter:0x%x \n",psm->DataSendHeader, psm->DataSendLast,psm->sendconter);
  138. }
  139. }else{
  140. /*无数据,有结果*/
  141. if(psm->updateresult){
  142. psm->cursendok = 0;
  143. psm->sendTime = 3;
  144. data_send_to_pc(PC_CMD_REPORT_RESULT, (char *)&psm->result, sizeof(test_result_struct));
  145. }
  146. }
  147. }
  148. }
  149. ProcessStateMachine_t * matchPid(unsigned char * part){
  150. if( 0 == memcmp(sysinf.psmMaster.card_param_info.pid, part, sizeof(sysinf.psmMaster.card_param_info.pid))){
  151. return &sysinf.psmMaster;
  152. }
  153. if( 0 == memcmp(sysinf.psmSlave.card_param_info.pid, part, sizeof(sysinf.psmSlave.card_param_info.pid))){
  154. return &sysinf.psmSlave;
  155. }
  156. return 0;
  157. }
  158. void updateData_next(unsigned int recdex,unsigned char * part)
  159. {
  160. ProcessStateMachine_t *psm = matchPid(part);
  161. if(psm){
  162. psm->cursendok = 1;
  163. if(psm->DataSendHeader != psm->DataSendLast){
  164. psm->sendconter++;
  165. Van_Device_Printf(VAN_LOG_WIFI,"send ok Header:%d sendconter:0x%x \n",psm->DataSendHeader, psm->sendconter);
  166. /*主模块又消息,更新头,发下一条*/
  167. psm->DataSendHeader++;
  168. if(psm->DataSendHeader == MAX_DATA_BUF_SIZE){
  169. psm->DataSendHeader = 0;
  170. }
  171. }
  172. }
  173. }
  174. void resetSampleData(ProcessStateMachine_t *psm){
  175. if(psm->sendTime){
  176. psm->sendTime--;
  177. if(psm->sendTime==0){
  178. psm->cursendok = 1;
  179. }
  180. }
  181. }
  182. void clean_reult_next(unsigned char * part)
  183. {
  184. ProcessStateMachine_t *psm = matchPid(part);
  185. if(psm){
  186. psm->updateresult = 0;
  187. psm->cursendok = 1;
  188. psm->controlword = result_move_card;
  189. }
  190. }
  191. /********************************************************************
  192. * uint8_t error_set(uint8_t error)
  193. *
  194. *描述:设置错误位,并上报主机,灯带显示
  195. *参数:error: 错误位
  196. *返回:错误码
  197. *其他:无
  198. ********************************************************************/
  199. uint8_t error_set(uint8_t error,uint8_t id)
  200. {
  201. if(error_info.error_code == error && error_info.id == id)
  202. return error;
  203. error_info.error_code = error;
  204. error_info.id = id;
  205. if(error_info.id == 0){
  206. sysinf.psmMaster.state = SW_Fault;
  207. Van_Device_Printf(VAN_LOG_ERROR, "error_set: %d %d %d\n", 0, error,sysinf.psmMaster.state);
  208. if(error == ERROR_SAMP_MOVE_CARD) //检测中拔卡,需等待60S才能消除
  209. {
  210. sysinf.psmMaster.error_delay = 60;
  211. }
  212. }else{
  213. sysinf.psmSlave.state = SW_Fault;
  214. Van_Device_Printf(VAN_LOG_ERROR, "error_set: %d %d %d\n", 1, error,sysinf.psmSlave.state);
  215. if(error == ERROR_SAMP_MOVE_CARD) //检测中拔卡,需等待60S才能消除
  216. {
  217. sysinf.psmSlave.error_delay = 60;
  218. }
  219. }
  220. sysinf.updateError = 1;
  221. memcpy(error_info.SN, &sysinf.SN, 7);
  222. error_info.SN[7] = 0;
  223. error_info.error_report = 1;
  224. data_send_to_pc(PC_CMD_REPORT_REEOR, (char*)&error_info, sizeof(str_error_info_t));
  225. // if(error != ERROR_MOTOR_FIALED){
  226. // sysinf.psmMaster.state = SW_Fault;
  227. // // mcu_ack_ctrl.re_send_card = ACK_TIMEOUT;
  228. // // Card_State_Send(HEAT_OFF); //降温至40°C,不开风扇
  229. // }
  230. return 0;
  231. }
  232. /********************************************************************
  233. * void error_clear()
  234. *
  235. *描述:清除错误
  236. *参数:error: 错误
  237. *返回:错误码
  238. *其他:无
  239. ********************************************************************/
  240. void error_clear(void)
  241. {
  242. error_info.error_code = 0;
  243. error_info.error_report = 0;
  244. beep_set(BEEP_MUTE);
  245. }
  246. void resend_error_update(void){
  247. if(sysinf.updateError == 1){
  248. data_send_to_pc(PC_CMD_REPORT_REEOR, (char*)&error_info, sizeof(str_error_info_t));
  249. }
  250. }
  251. void re_send_state(void){
  252. if(sysinf.updateSt == 1){
  253. stateinfDef st;
  254. st.amplifState =sysinf.amplifState;
  255. st.lysisState =sysinf.lysisState;
  256. memcpy(st.SN, &sysinf.SN, 7);
  257. data_send_to_pc(PC_CMD_UPDATESTATE, (char *)&st, sizeof(stateinfDef));
  258. }
  259. }
  260. void updateAmplifState(uint8_t newset,uint8_t id){
  261. if(id==0){
  262. if(sysinf.amplifState != newset){
  263. sysinf.amplifState = newset;
  264. if(newset == SYS_STATE_ERROR_HW){
  265. sysinf.lysisState = newset;
  266. #ifdef ONECHIP_MINI_ONE
  267. beep_set(BEEP_ERR_HW);
  268. #endif
  269. }else if(newset == SYS_STATE_ERROR_HM){
  270. beep_set(BEEP_ERR_HM);
  271. }
  272. sysinf.updateSt = 1;
  273. }
  274. }else{
  275. if(sysinf.lysisState != newset){
  276. sysinf.lysisState = newset;
  277. if(newset == SYS_STATE_ERROR_HW){
  278. sysinf.lysisState = newset;
  279. beep_set(BEEP_ERR_HW);
  280. }else if(newset == SYS_STATE_ERROR_HM){
  281. beep_set(BEEP_ERR_HM);
  282. }
  283. sysinf.updateSt = 1;
  284. }
  285. }
  286. }
  287. void updateLysisState(uint8_t newset){
  288. if(sysinf.lysisState != newset){
  289. sysinf.lysisState = newset;
  290. if(newset == SYS_STATE_ERROR_HW){
  291. sysinf.lysisState = newset;
  292. beep_set(BEEP_ERR_HW);
  293. }else if(newset == SYS_STATE_ERROR_HM){
  294. beep_set(BEEP_ERR_HM);
  295. }
  296. sysinf.updateSt = 1;
  297. }
  298. }
  299. void usr_state_machine(ProcessStateMachine_t *sts, heat_ctrl_def *heater)
  300. {
  301. sts->statusword = 0x0000;
  302. static uint8_t state = 0;
  303. //采样前,3秒发一次加热指令
  304. if((sts->state < SW_Chip_Id) && (sts->state != SW_Fault)){
  305. if (TrigStateCheck(sts) == CardON){
  306. if(sts->state == SW_Target_reached){
  307. error_set(ERROR_HEAT_INSERT_CARD,heater->number);
  308. }else {
  309. error_set(ERROR_NO_QRCODE,heater->number);
  310. }
  311. updateAmplifState(SYS_STATE_ERROR_HM,heater->number);
  312. }
  313. }
  314. switch (sts->state)
  315. {
  316. // 所有板卡准备自检,包含通道预加热
  317. case SW_Read_To_Board_Selftest:
  318. {
  319. if (is_command(sts->controlword, Board_Selftest_cmd))
  320. {
  321. sts->state = SW_Target_reached;
  322. sts->statusword |= SW_Target_reached;
  323. }
  324. } break;
  325. case SW_Fault:
  326. {
  327. // 没有预热完成前插卡检测
  328. // 采样没有完成,拔卡检测
  329. sts->sampleStart = 0;
  330. if(error_info.error_code < ERROR_SENSOR_SELF_CHECK && sts->error_delay == 0)
  331. {
  332. //拔卡消除故障
  333. if (TrigStateCheck(sts) == CardOFF)
  334. {
  335. sts->statusword |= SW_move_card;
  336. sts->state = SW_move_card;
  337. error_clear();
  338. memset(&sts->card_param_info, 0 , sizeof(str_card_param_info_t));
  339. }
  340. }
  341. // if(error_info.error_code == ERROR_SENSOR_CARD_CHECK){
  342. // if(check_first_zero() == 0){
  343. // sts->statusword |= SW_Chip_Id;
  344. // sts->state = SW_Chip_Id;
  345. // error_clear();
  346. // }
  347. // }
  348. }
  349. break;
  350. // 快速停止
  351. case SW_Quick_stop:
  352. {
  353. break;
  354. }
  355. // 获取温度,两通道加热
  356. // 等温度稳定后
  357. case SW_Target_reached:
  358. {
  359. if (heater->temp_stable_sta == 1)
  360. {
  361. sts->controlword = Target_reached_cmd;
  362. updateAmplifState(SYS_STATE_READY,heater->number);
  363. /*************lxx-add-20232.11.30****************/
  364. if (SensorSelfCheckPass(heater->number)==0)
  365. {
  366. updateAmplifState(SYS_STATE_ERROR_HW,heater->number);
  367. error_set(ERROR_SENSOR_SELF_CHECK,heater->number);
  368. }
  369. }
  370. if ((sysinf.skip_CheckOrRun & SKIP_HEATONCHECK_OK))
  371. {
  372. /*跳过温度判断*/
  373. sts->controlword = Target_reached_cmd;
  374. if (SensorSelfCheckPass(heater->number)==0)
  375. {
  376. error_set(ERROR_SENSOR_SELF_CHECK,heater->number);
  377. }
  378. heater->HeatState = SystemPreHeat;
  379. heater->temp_stable_sta = 0;
  380. updateAmplifState(SYS_STATE_READY,heater->number);
  381. }
  382. if (is_command(sts->controlword, Target_reached_cmd))
  383. {
  384. sts->statusword |= SW_Scan_Qrcode;
  385. sts->state = SW_Scan_Qrcode;
  386. sts->heat_timeout = 0;
  387. }
  388. }
  389. break;
  390. // 扫码
  391. case SW_Scan_Qrcode:
  392. {
  393. // if (scan_qrcode_done)
  394. // {
  395. // // calc_balance();
  396. // controlword = Scan_Qrcode_cmd;
  397. // }
  398. if (is_command(sts->controlword, Scan_Qrcode_cmd))
  399. {
  400. calc_balance(heater->number);
  401. sts->statusword |= SW_Chip_Id;
  402. sts->state = SW_Chip_Id;
  403. updateAmplifState(SYS_STATE_CHECK,heater->number);
  404. }
  405. if((sysinf.skip_CheckOrRun & SKIP_SCANQRCODE)){
  406. sts->statusword |= SW_Chip_Id;
  407. sts->state = SW_Chip_Id;
  408. updateAmplifState(SYS_STATE_CHECK,heater->number);
  409. }
  410. }
  411. break;
  412. // 插卡,通道检测
  413. case SW_Chip_Id:
  414. {
  415. if (TrigStateCheck(sts) == CardON)
  416. {
  417. Refresh_IWDG();
  418. HAL_Delay(1000);/*插卡后延时1s检测*/
  419. Refresh_IWDG();
  420. if(!(sysinf.skip_CheckOrRun & SKIP_CHECK_CARDINSERT)){
  421. if(check_first_zero(heater->number) == 1){
  422. error_set(ERROR_SENSOR_CARD_CHECK,heater->number);
  423. updateAmplifState(SYS_STATE_ERROR_HM,heater->number);
  424. break;
  425. }
  426. }
  427. {
  428. sts->controlword = Qrcode_publish_cmd;
  429. // mcu_ack_ctrl.re_send_card = ACK_TIMEOUT;
  430. // Card_State_Send(HEAT_ON);
  431. heater->HeatState = SysPreHeatUP;
  432. heater->timenum=0;
  433. g_heat_ctrl.temp_stable_sta=0;
  434. g_card_tick_s = 0;
  435. if (is_command(sts->controlword, Qrcode_publish_cmd))
  436. {
  437. sts->statusword |= SW_Sample_timeout;
  438. sts->state = SW_Sample_timeout;
  439. updateAmplifState(SYS_STATE_RUNING,heater->number);
  440. }
  441. };
  442. }
  443. }
  444. break;
  445. // 采样,30min定时
  446. case SW_Sample_timeout:
  447. {
  448. if(!(sysinf.skip_CheckOrRun & SKIP_CHECK_CARDREMOVE))
  449. if (TrigStateCheck(sts) == CardOFF){
  450. error_set(ERROR_SAMP_MOVE_CARD,heater->number);
  451. updateAmplifState(SYS_STATE_ERROR_HM,heater->number);
  452. }
  453. if(((heater->temp_stable_sta==2)||(sysinf.skip_CheckOrRun & SKIP_HEATONCHECK_OK))&& sts->sampleStart == 0)
  454. {
  455. // 启动定时器计时
  456. sts->sampleTimes = 0;
  457. sts->sampleStart = 1;
  458. sts->DataSendHeader = 0;
  459. sts->DataSendLast = 0;
  460. }
  461. if(sts->samp_flag == 1 && sts->sampleStart)
  462. {
  463. sts->samp_flag = 0;
  464. if (sts->sampleTimes == 0)
  465. {
  466. sample_first_zero(heater->number); //计算校零值
  467. // sts->samp_num = 0;
  468. sts->cursendok = 1;
  469. }
  470. else
  471. {
  472. sample_calibrate_calc(sts->sampleTimes,heater->number); //采样,前18组计算均值
  473. //输出原始数据
  474. }
  475. ColorSensor *pGroup = (heater->number == 0) ? CS : CS_Slave;
  476. DatascopeSend(heater->number,pGroup[0].RDR,pGroup[1].RDR,pGroup[2].RDR,pGroup[3].RDR,pGroup[4].RDR,pGroup[5].RDR,pGroup[6].RDR,pGroup[7].RDR,pGroup[8].RDR,pGroup[9].RDR,(sysinf.ms_conter/1000.0));
  477. //上报采样数据
  478. // sample_send_rt_data();
  479. if(((sts->DataSendLast+ 1)%MAX_DATA_BUF_SIZE) != sts->DataSendHeader){
  480. for (int i = 0; i < CS_MAX; i++)
  481. {
  482. memcpy(&sts->DataBufRDR[sts->DataSendLast][i], &CS[i].RtR, 4);
  483. }
  484. sts->DataSendLast++;
  485. if(sts->DataSendLast == MAX_DATA_BUF_SIZE){
  486. sts->DataSendLast = 0;
  487. }
  488. }
  489. if (sts->sampleTimes == 19)
  490. {
  491. // sample_calc_avg_std(); //计算均值标准差
  492. }
  493. if (sts->sampleTimes > 19)
  494. {
  495. // sample_calc_tt(); //计算Tt
  496. }
  497. // if ((!(g_cfg.skip_CheckOrRun & SKIP_HEATONCHECK_OK) || g_cfg.skip_CheckOrRun & SKIP_FARSTRUN)){
  498. // }
  499. if (!(sysinf.skip_CheckOrRun & SKIP_FARSTRUN)){
  500. sts->sampleTimes++;
  501. }
  502. Van_Device_Printf(VAN_LOG_INFO,"SendLast:%d Times:%d \n",sts->DataSendLast,sts->sampleTimes);
  503. if (sts->sampleTimes >= sampleTotalTimes)
  504. {
  505. // sampleTimes = 0;
  506. if(0==(sysinf.skip_CheckOrRun & SKIP_FARSTRUN)){
  507. sts->sampleStart = 0;
  508. sts->controlword = result_report_cmd;
  509. }
  510. }
  511. }
  512. if (is_command(sts->controlword, result_report_cmd))
  513. {
  514. sts->statusword |= SW_result_report;
  515. sts->state = SW_result_report;
  516. sample_calc_result(heater->number);
  517. sts->updateresult = 1;
  518. }
  519. }
  520. break;
  521. // 计算,阈值范围,所有孔的结果(阴阳性、无效)
  522. // 结果上传&数据上传
  523. case SW_result_report:
  524. {
  525. if(0 == datasope_flag)
  526. {
  527. datasope_flag = 1;
  528. // DatascopeSend(CS[0].Tt,CS[1].Tt,CS[2].Tt,CS[3].Tt,CS[4].Tt,CS[5].Tt,CS[6].Tt,CS[7].Tt,CS[8].Tt,CS[9].Tt, 101); //Tt值
  529. // DatascopeSend(CS[0].average,CS[1].average,CS[2].average,CS[3].average,CS[4].average,CS[5].average,CS[6].average,CS[7].average,CS[8].average,CS[9].average, 102); //均值
  530. // DatascopeSend(CS[0].STD,CS[1].STD,CS[2].STD,CS[3].STD,CS[4].STD,CS[5].STD,CS[6].STD,CS[7].STD,CS[8].STD,CS[9].STD, 103); //方差
  531. // DatascopeSend(CS[0].CDR, CS[1].CDR, CS[2].CDR, CS[3].CDR, CS[4].CDR, CS[5].CDR, CS[6].CDR, CS[7].CDR, CS[8].CDR, CS[9].CDR, 104); //校零值
  532. // DatascopeSend(CS[0].Result,CS[1].Result,CS[2].Result,CS[3].Result,CS[4].Result,CS[5].Result,CS[6].Result,CS[7].Result,CS[8].Result,CS[9].Result, 105); //结果
  533. // DatascopeSend(CS[0].gain, CS[1].gain, CS[2].gain, CS[3].gain, CS[4].gain, CS[5].gain, CS[6].gain, CS[7].gain, CS[8].gain, CS[9].gain, 106); //gain值
  534. // DatascopeSend(CS[0].RDC, CS[1].RDC, CS[2].RDC, CS[3].RDC, CS[4].RDC, CS[5].RDC, CS[6].RDC, CS[7].RDC, CS[8].RDC, CS[9].RDC, 107); //gain基值
  535. // DatascopeSend(CS[0].TtMax, CS[1].TtMax, CS[2].TtMax, CS[3].TtMax, CS[4].TtMax, CS[5].TtMax, CS[6].TtMax, CS[7].TtMax, CS[8].TtMax, CS[9].TtMax, 108); //TtMax
  536. // DatascopeSend(CS[0].TtMin, CS[1].TtMin, CS[2].TtMin, CS[3].TtMin, CS[4].TtMin, CS[5].TtMin, CS[6].TtMin, CS[7].TtMin, CS[8].TtMin, CS[9].TtMin, 109); //TtMin
  537. }
  538. // if(g_sys_tick > delay)
  539. // {
  540. // if (Devicenum == 0)
  541. // {
  542. // data_send_to_pc(PC_CMD_REPORT_RESULT, (char *)&result, sizeof(test_result_struct));
  543. // }
  544. // else
  545. // {
  546. // b2b_send_device(B2B_CMD_REQ_RESULT, (char *)&result, sizeof(test_result_struct),0);
  547. // }
  548. // delay = g_sys_tick + 10;
  549. // }
  550. if (is_command(sts->controlword, result_move_card))
  551. {
  552. sts->statusword |= SW_move_card;
  553. sts->state = SW_move_card;
  554. updateAmplifState(SYS_STATE_WORKEND,heater->number);
  555. beep_set(BEEP_WORKEND);
  556. }
  557. }
  558. break;
  559. case SW_move_card:
  560. {
  561. //等待拔卡进入下一次循环
  562. if (TrigStateCheck(sts) != CardON)
  563. {
  564. //跳转到等待扫码状态
  565. sts->statusword = SW_Target_reached;
  566. sts->state = SW_Target_reached;
  567. sts->sampleTimes = 0;
  568. sts->sampleStart = 0;
  569. g_heat_ctrl.temp_stable_sta = 0;
  570. datasope_flag = 0;
  571. sts->heat_timeout = 0;
  572. memset(&sts->card_param_info, 0 ,sizeof(sts->card_param_info));
  573. heater->HeatState = SystemPreHeat;
  574. heater->temp_stable_sta = 0;
  575. sts->controlword = Board_Selftest_cmd;
  576. updateAmplifState(SYS_STATE_PREPARE,heater->number);
  577. }
  578. }
  579. break;
  580. default:
  581. break;
  582. }
  583. switch (sts->state)
  584. {
  585. case SW_Read_To_Board_Selftest:
  586. sts->flags.selftest_allowed = 1;
  587. sts->flags.scan_qrcode_allowed = 0;
  588. sts->flags.pre_heat_enabled = 0;
  589. sts->flags.target_reached = 0;
  590. sts->flags.check_chipid_enabled = 0;
  591. sts->flags.qrcode_info_applied = 0;
  592. break;
  593. default:
  594. break;
  595. }
  596. if(state != sts->state)
  597. {
  598. state = sts->state;
  599. Van_Device_Printf(VAN_LOG_NOTICE,"\nstate:%d \n", state);
  600. }
  601. updateData(sts);
  602. }