state_mini.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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. data_send_to_pc(PC_CMD_REPORT_RESULT, (char *)&result, sizeof(test_result_struct));
  143. }
  144. }
  145. }
  146. }
  147. ProcessStateMachine_t * matchPid(unsigned char * part){
  148. if( 0 == memcmp(sysinf.psmMaster.card_param_info.pid, part, sizeof(sysinf.psmMaster.card_param_info.pid))){
  149. return &sysinf.psmMaster;
  150. }
  151. if( 0 == memcmp(sysinf.psmSlave.card_param_info.pid, part, sizeof(sysinf.psmSlave.card_param_info.pid))){
  152. return &sysinf.psmSlave;
  153. }
  154. return 0;
  155. }
  156. void updateData_next(unsigned int recdex,unsigned char * part)
  157. {
  158. ProcessStateMachine_t *psm = matchPid(part);
  159. if(psm){
  160. psm->cursendok = 1;
  161. if(psm->DataSendHeader != psm->DataSendLast){
  162. psm->sendconter++;
  163. Van_Device_Printf(VAN_LOG_WIFI,"send ok Header:%d sendconter:0x%x \n",psm->DataSendHeader, psm->sendconter);
  164. /*主模块又消息,更新头,发下一条*/
  165. psm->DataSendHeader++;
  166. if(psm->DataSendHeader == MAX_DATA_BUF_SIZE){
  167. psm->DataSendHeader = 0;
  168. }
  169. }
  170. }
  171. }
  172. void resetSampleData(ProcessStateMachine_t *psm){
  173. if(psm->sendTime){
  174. psm->sendTime--;
  175. if(psm->sendTime==0){
  176. psm->cursendok = 1;
  177. }
  178. }
  179. }
  180. void clean_reult_next(unsigned char * part)
  181. {
  182. ProcessStateMachine_t *psm = matchPid(part);
  183. if(psm){
  184. psm->updateresult = 0;
  185. psm->cursendok = 1;
  186. psm->controlword = result_move_card;
  187. }
  188. }
  189. /********************************************************************
  190. * uint8_t error_set(uint8_t error)
  191. *
  192. *描述:设置错误位,并上报主机,灯带显示
  193. *参数:error: 错误位
  194. *返回:错误码
  195. *其他:无
  196. ********************************************************************/
  197. uint8_t error_set(uint8_t error,uint8_t id)
  198. {
  199. if(error_info.error_code == error && error_info.id == id)
  200. return error;
  201. error_info.error_code = error;
  202. error_info.id = id;
  203. if(error_info.id == 0){
  204. sysinf.psmMaster.state = SW_Fault;
  205. Van_Device_Printf(VAN_LOG_ERROR, "error_set: %d %d %d\n", 0, error,sysinf.psmMaster.state);
  206. if(error == ERROR_SAMP_MOVE_CARD) //检测中拔卡,需等待60S才能消除
  207. {
  208. sysinf.psmMaster.error_delay = 60;
  209. }
  210. }else{
  211. sysinf.psmSlave.state = SW_Fault;
  212. Van_Device_Printf(VAN_LOG_ERROR, "error_set: %d %d %d\n", 1, error,sysinf.psmSlave.state);
  213. if(error == ERROR_SAMP_MOVE_CARD) //检测中拔卡,需等待60S才能消除
  214. {
  215. sysinf.psmSlave.error_delay = 60;
  216. }
  217. }
  218. sysinf.updateError = 1;
  219. memcpy(error_info.SN, &sysinf.SN, 7);
  220. error_info.SN[7] = 0;
  221. error_info.error_report = 1;
  222. data_send_to_pc(PC_CMD_REPORT_REEOR, (char*)&error_info, sizeof(str_error_info_t));
  223. // if(error != ERROR_MOTOR_FIALED){
  224. // sysinf.psmMaster.state = SW_Fault;
  225. // // mcu_ack_ctrl.re_send_card = ACK_TIMEOUT;
  226. // // Card_State_Send(HEAT_OFF); //降温至40°C,不开风扇
  227. // }
  228. return 0;
  229. }
  230. /********************************************************************
  231. * void error_clear()
  232. *
  233. *描述:清除错误
  234. *参数:error: 错误
  235. *返回:错误码
  236. *其他:无
  237. ********************************************************************/
  238. void error_clear(void)
  239. {
  240. error_info.error_code = 0;
  241. error_info.error_report = 0;
  242. beep_set(BEEP_MUTE);
  243. }
  244. void resend_error_update(void){
  245. if(sysinf.updateError == 1){
  246. data_send_to_pc(PC_CMD_REPORT_REEOR, (char*)&error_info, sizeof(str_error_info_t));
  247. }
  248. }
  249. void re_send_state(void){
  250. if(sysinf.updateSt == 1){
  251. stateinfDef st;
  252. st.amplifState =sysinf.amplifState;
  253. st.lysisState =sysinf.lysisState;
  254. memcpy(st.SN, &sysinf.SN, 7);
  255. data_send_to_pc(PC_CMD_UPDATESTATE, (char *)&st, sizeof(stateinfDef));
  256. }
  257. }
  258. void updateAmplifState(uint8_t newset,uint8_t id){
  259. if(id==0){
  260. if(sysinf.amplifState != newset){
  261. sysinf.amplifState = newset;
  262. if(newset == SYS_STATE_ERROR_HW){
  263. sysinf.lysisState = newset;
  264. #ifdef ONECHIP_MINI_ONE
  265. beep_set(BEEP_ERR_HW);
  266. #endif
  267. }else if(newset == SYS_STATE_ERROR_HM){
  268. beep_set(BEEP_ERR_HM);
  269. }
  270. sysinf.updateSt = 1;
  271. }
  272. }else{
  273. if(sysinf.lysisState != newset){
  274. sysinf.lysisState = newset;
  275. if(newset == SYS_STATE_ERROR_HW){
  276. sysinf.lysisState = newset;
  277. beep_set(BEEP_ERR_HW);
  278. }else if(newset == SYS_STATE_ERROR_HM){
  279. beep_set(BEEP_ERR_HM);
  280. }
  281. sysinf.updateSt = 1;
  282. }
  283. }
  284. }
  285. void updateLysisState(uint8_t newset){
  286. if(sysinf.lysisState != newset){
  287. sysinf.lysisState = newset;
  288. if(newset == SYS_STATE_ERROR_HW){
  289. sysinf.lysisState = newset;
  290. beep_set(BEEP_ERR_HW);
  291. }else if(newset == SYS_STATE_ERROR_HM){
  292. beep_set(BEEP_ERR_HM);
  293. }
  294. sysinf.updateSt = 1;
  295. }
  296. }
  297. void usr_state_machine(ProcessStateMachine_t *sts, heat_ctrl_def *heater)
  298. {
  299. sts->statusword = 0x0000;
  300. static uint8_t state = 0;
  301. //采样前,3秒发一次加热指令
  302. if((sts->state < SW_Chip_Id) && (sts->state != SW_Fault)){
  303. if (TrigStateCheck(sts) == CardON){
  304. if(sts->state == SW_Target_reached){
  305. error_set(ERROR_HEAT_INSERT_CARD,heater->number);
  306. }else {
  307. error_set(ERROR_NO_QRCODE,heater->number);
  308. }
  309. updateAmplifState(SYS_STATE_ERROR_HM,heater->number);
  310. }
  311. }
  312. switch (sts->state)
  313. {
  314. // 所有板卡准备自检,包含通道预加热
  315. case SW_Read_To_Board_Selftest:
  316. {
  317. if (is_command(sts->controlword, Board_Selftest_cmd))
  318. {
  319. sts->state = SW_Target_reached;
  320. sts->statusword |= SW_Target_reached;
  321. }
  322. } break;
  323. case SW_Fault:
  324. {
  325. // 没有预热完成前插卡检测
  326. // 采样没有完成,拔卡检测
  327. sts->sampleStart = 0;
  328. if(error_info.error_code < ERROR_SENSOR_SELF_CHECK && sts->error_delay == 0)
  329. {
  330. //拔卡消除故障
  331. if (TrigStateCheck(sts) == CardOFF)
  332. {
  333. sts->statusword |= SW_move_card;
  334. sts->state = SW_move_card;
  335. error_clear();
  336. memset(&sts->card_param_info, 0 , sizeof(str_card_param_info_t));
  337. }
  338. }
  339. // if(error_info.error_code == ERROR_SENSOR_CARD_CHECK){
  340. // if(check_first_zero() == 0){
  341. // sts->statusword |= SW_Chip_Id;
  342. // sts->state = SW_Chip_Id;
  343. // error_clear();
  344. // }
  345. // }
  346. }
  347. break;
  348. // 快速停止
  349. case SW_Quick_stop:
  350. {
  351. break;
  352. }
  353. // 获取温度,两通道加热
  354. // 等温度稳定后
  355. case SW_Target_reached:
  356. {
  357. if (heater->temp_stable_sta == 1)
  358. {
  359. sts->controlword = Target_reached_cmd;
  360. updateAmplifState(SYS_STATE_READY,heater->number);
  361. /*************lxx-add-20232.11.30****************/
  362. if (SensorSelfCheckPass(heater->number)==0)
  363. {
  364. updateAmplifState(SYS_STATE_ERROR_HW,heater->number);
  365. error_set(ERROR_SENSOR_SELF_CHECK,heater->number);
  366. }
  367. }
  368. if ((sysinf.skip_CheckOrRun & SKIP_HEATONCHECK_OK))
  369. {
  370. /*跳过温度判断*/
  371. sts->controlword = Target_reached_cmd;
  372. if (SensorSelfCheckPass(heater->number)==0)
  373. {
  374. error_set(ERROR_SENSOR_SELF_CHECK,heater->number);
  375. }
  376. heater->HeatState = SystemPreHeat;
  377. heater->temp_stable_sta = 0;
  378. updateAmplifState(SYS_STATE_READY,heater->number);
  379. }
  380. if (is_command(sts->controlword, Target_reached_cmd))
  381. {
  382. sts->statusword |= SW_Scan_Qrcode;
  383. sts->state = SW_Scan_Qrcode;
  384. sts->heat_timeout = 0;
  385. }
  386. }
  387. break;
  388. // 扫码
  389. case SW_Scan_Qrcode:
  390. {
  391. // if (scan_qrcode_done)
  392. // {
  393. // // calc_balance();
  394. // controlword = Scan_Qrcode_cmd;
  395. // }
  396. if (is_command(sts->controlword, Scan_Qrcode_cmd))
  397. {
  398. calc_balance(heater->number);
  399. sts->statusword |= SW_Chip_Id;
  400. sts->state = SW_Chip_Id;
  401. updateAmplifState(SYS_STATE_CHECK,heater->number);
  402. }
  403. if((sysinf.skip_CheckOrRun & SKIP_SCANQRCODE)){
  404. sts->statusword |= SW_Chip_Id;
  405. sts->state = SW_Chip_Id;
  406. updateAmplifState(SYS_STATE_CHECK,heater->number);
  407. }
  408. }
  409. break;
  410. // 插卡,通道检测
  411. case SW_Chip_Id:
  412. {
  413. if (TrigStateCheck(sts) == CardON)
  414. {
  415. Refresh_IWDG();
  416. HAL_Delay(1000);/*插卡后延时1s检测*/
  417. Refresh_IWDG();
  418. if(!(sysinf.skip_CheckOrRun & SKIP_CHECK_CARDINSERT)){
  419. if(check_first_zero(heater->number) == 1){
  420. error_set(ERROR_SENSOR_CARD_CHECK,heater->number);
  421. updateAmplifState(SYS_STATE_ERROR_HM,heater->number);
  422. break;
  423. }
  424. }
  425. {
  426. sts->controlword = Qrcode_publish_cmd;
  427. // mcu_ack_ctrl.re_send_card = ACK_TIMEOUT;
  428. // Card_State_Send(HEAT_ON);
  429. heater->HeatState = SysPreHeatUP;
  430. heater->timenum=0;
  431. g_heat_ctrl.temp_stable_sta=0;
  432. g_card_tick_s = 0;
  433. if (is_command(sts->controlword, Qrcode_publish_cmd))
  434. {
  435. sts->statusword |= SW_Sample_timeout;
  436. sts->state = SW_Sample_timeout;
  437. updateAmplifState(SYS_STATE_RUNING,heater->number);
  438. }
  439. };
  440. }
  441. }
  442. break;
  443. // 采样,30min定时
  444. case SW_Sample_timeout:
  445. {
  446. if(!(sysinf.skip_CheckOrRun & SKIP_CHECK_CARDREMOVE))
  447. if (TrigStateCheck(sts) == CardOFF){
  448. error_set(ERROR_SAMP_MOVE_CARD,heater->number);
  449. updateAmplifState(SYS_STATE_ERROR_HM,heater->number);
  450. }
  451. if(((heater->temp_stable_sta==2)||(sysinf.skip_CheckOrRun & SKIP_HEATONCHECK_OK))&& sts->sampleStart == 0)
  452. {
  453. // 启动定时器计时
  454. sts->sampleTimes = 0;
  455. sts->sampleStart = 1;
  456. sts->DataSendHeader = 0;
  457. sts->DataSendLast = 0;
  458. }
  459. if(sts->samp_flag == 1 && sts->sampleStart)
  460. {
  461. sts->samp_flag = 0;
  462. if (sts->sampleTimes == 0)
  463. {
  464. sample_first_zero(heater->number); //计算校零值
  465. // sts->samp_num = 0;
  466. sts->cursendok = 1;
  467. }
  468. else
  469. {
  470. sample_calibrate_calc(sts->sampleTimes,heater->number); //采样,前18组计算均值
  471. //输出原始数据
  472. }
  473. ColorSensor *pGroup = (heater->number == 0) ? CS : CS_Slave;
  474. 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));
  475. //上报采样数据
  476. // sample_send_rt_data();
  477. if(((sts->DataSendLast+ 1)%MAX_DATA_BUF_SIZE) != sts->DataSendHeader){
  478. for (int i = 0; i < CS_MAX; i++)
  479. {
  480. memcpy(&sts->DataBufRDR[sts->DataSendLast][i], &CS[i].RtR, 4);
  481. }
  482. sts->DataSendLast++;
  483. if(sts->DataSendLast == MAX_DATA_BUF_SIZE){
  484. sts->DataSendLast = 0;
  485. }
  486. }
  487. if (sts->sampleTimes == 19)
  488. {
  489. // sample_calc_avg_std(); //计算均值标准差
  490. }
  491. if (sts->sampleTimes > 19)
  492. {
  493. // sample_calc_tt(); //计算Tt
  494. }
  495. // if ((!(g_cfg.skip_CheckOrRun & SKIP_HEATONCHECK_OK) || g_cfg.skip_CheckOrRun & SKIP_FARSTRUN)){
  496. // }
  497. if (!(sysinf.skip_CheckOrRun & SKIP_FARSTRUN)){
  498. sts->sampleTimes++;
  499. }
  500. Van_Device_Printf(VAN_LOG_INFO,"SendLast:%d Times:%d \n",sts->DataSendLast,sts->sampleTimes);
  501. if (sts->sampleTimes >= sampleTotalTimes)
  502. {
  503. // sampleTimes = 0;
  504. if(0==(sysinf.skip_CheckOrRun & SKIP_FARSTRUN)){
  505. sts->sampleStart = 0;
  506. sts->controlword = result_report_cmd;
  507. }
  508. }
  509. }
  510. if (is_command(sts->controlword, result_report_cmd))
  511. {
  512. sts->statusword |= SW_result_report;
  513. sts->state = SW_result_report;
  514. sample_calc_result(heater->number);
  515. sts->updateresult = 1;
  516. }
  517. }
  518. break;
  519. // 计算,阈值范围,所有孔的结果(阴阳性、无效)
  520. // 结果上传&数据上传
  521. case SW_result_report:
  522. {
  523. if(0 == datasope_flag)
  524. {
  525. datasope_flag = 1;
  526. // 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值
  527. // 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); //均值
  528. // 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); //方差
  529. // 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); //校零值
  530. // 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); //结果
  531. // 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值
  532. // 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基值
  533. // 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
  534. // 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
  535. }
  536. // if(g_sys_tick > delay)
  537. // {
  538. // if (Devicenum == 0)
  539. // {
  540. // data_send_to_pc(PC_CMD_REPORT_RESULT, (char *)&result, sizeof(test_result_struct));
  541. // }
  542. // else
  543. // {
  544. // b2b_send_device(B2B_CMD_REQ_RESULT, (char *)&result, sizeof(test_result_struct),0);
  545. // }
  546. // delay = g_sys_tick + 10;
  547. // }
  548. if (is_command(sts->controlword, result_move_card))
  549. {
  550. sts->statusword |= SW_move_card;
  551. sts->state = SW_move_card;
  552. updateAmplifState(SYS_STATE_WORKEND,heater->number);
  553. beep_set(BEEP_WORKEND);
  554. }
  555. }
  556. break;
  557. case SW_move_card:
  558. {
  559. //等待拔卡进入下一次循环
  560. if (TrigStateCheck(sts) != CardON)
  561. {
  562. //跳转到等待扫码状态
  563. sts->statusword = SW_Target_reached;
  564. sts->state = SW_Target_reached;
  565. sts->sampleTimes = 0;
  566. sts->sampleStart = 0;
  567. g_heat_ctrl.temp_stable_sta = 0;
  568. datasope_flag = 0;
  569. sts->heat_timeout = 0;
  570. memset(&sts->card_param_info, 0 ,sizeof(sts->card_param_info));
  571. heater->HeatState = SystemPreHeat;
  572. heater->temp_stable_sta = 0;
  573. sts->controlword = Board_Selftest_cmd;
  574. updateAmplifState(SYS_STATE_PREPARE,heater->number);
  575. }
  576. }
  577. break;
  578. default:
  579. break;
  580. }
  581. switch (sts->state)
  582. {
  583. case SW_Read_To_Board_Selftest:
  584. sts->flags.selftest_allowed = 1;
  585. sts->flags.scan_qrcode_allowed = 0;
  586. sts->flags.pre_heat_enabled = 0;
  587. sts->flags.target_reached = 0;
  588. sts->flags.check_chipid_enabled = 0;
  589. sts->flags.qrcode_info_applied = 0;
  590. break;
  591. default:
  592. break;
  593. }
  594. if(state != sts->state)
  595. {
  596. state = sts->state;
  597. Van_Device_Printf(VAN_LOG_NOTICE,"\nstate:%d \n", state);
  598. }
  599. updateData(sts);
  600. }