static void usb_protocol(struct tec_pid_control *__tec)
{
int16_t idx = 0;
uint16_t curr[TEC_ADC_SUM] = {0};
float temp_f = 0.0;
uint8_t *ptr = (uint8_t *)&temp_f;
usb_cdc_handler *cdc = (usb_cdc_handler *)__tec->p_cdc_acm->dev.class_data[0];
if (USBD_CONFIGURED == __tec->p_cdc_acm->dev.cur_status){
if (0U == cdc_acm_check_ready(__tec->p_cdc_acm)){
cdc_acm_data_receive(__tec->p_cdc_acm);
}
else{
idx = get_header_cmd();
switch (idx){
case -1:
break;
case set_mode:
break;
case set_temp:
memcpy(ptr, &cdc->data[2], sizeof(float));
max5214_write(temp_conver_dac_value(temp_f));
cdc->data[0] = 0x55;
cdc->data[1] = 0x02;
cdc->data[3] = 0x01;
cdc->data[4] = 0x00;
cdc->data[5] = 0x00;
cdc->data[6] = crc_8_calculate(cdc->data, 6);
break;
case set_prop:
break;
case set_intg:
break;
case set_diff:
break;
case read_name:
memcpy(cdc->data, "temperature controller\n", sizeof("temperature controller\n"));
cdc->receive_length = sizeof("temperature controller\n") - 1;
break;
case read_vers:
memcpy(cdc->data, "V1.00.01\n", sizeof("V1.00.01\n"));
cdc->receive_length = sizeof("V1.00.01\n") - 1;
break;
case read_sn:
memcpy(cdc->data, "20210907002\n", sizeof("20210907002\n"));
cdc->receive_length = sizeof("20210907002\n") - 1;
break;
case read_data:
get_tec_current(__tec->p_adc->value, TEC_ADC_SUM, curr);
cdc->data[0] = 0x5a;
cdc->data[1] = 0x04;
memcpy(&cdc->data[2], (uint8_t *)&curr, 10);
cdc->data[12] = crc_8_calculate(cdc->data, 12);
cdc->receive_length = 13;
break;
default:
break;
}
cdc_acm_data_send(__tec->p_cdc_acm);
}
}
}
如图,发送什么有时候就会回什么,概率还很高,是我代码哪出问题了吗?希望有大神能指点一二。
|