mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-30 16:16:40 +08:00
null terminate usb string before parse
This commit is contained in:
@@ -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 */
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user