null terminate usb string before parse

This commit is contained in:
Oskar Weigl
2017-07-11 00:43:07 -07:00
parent 4ed65bcfca
commit c0a84367de
2 changed files with 7 additions and 0 deletions
+3
View File
@@ -146,6 +146,9 @@
#define CURRENT_MEAS_PERIOD ((float)(2*TIM_1_8_PERIOD_CLOCKS)/(float)TIM_1_8_CLOCK_HZ)
#define CURRENT_MEAS_HZ (TIM_1_8_CLOCK_HZ/(2*TIM_1_8_PERIOD_CLOCKS))
#define MACRO_MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MACRO_MIN(x, y) (((x) < (y)) ? (x) : (y))
/* USER CODE END Private defines */
/**
+4
View File
@@ -265,6 +265,10 @@ static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
//Append null termination at end of string
int null_idx = MACRO_MIN(*Len, APP_RX_DATA_SIZE-1);
Buf[null_idx] = 0;
motor_parse_cmd(Buf, *Len);
return (USBD_OK);