mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-18 22:13:45 +02:00
Fix SerialManager not reading the entire message
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
|
||||
#define ECHO_UART_PORT_NUM (1)
|
||||
#define ECHO_UART_BAUD_RATE (115200)
|
||||
#define ECHO_TASK_STACK_SIZE (3072)
|
||||
|
||||
#define BUF_SIZE (1024)
|
||||
|
||||
@@ -21,16 +20,32 @@ void SerialManager::setup()
|
||||
usb_serial_jtag_driver_install(&usb_serial_jtag_config);
|
||||
// Configure a temporary buffer for the incoming data
|
||||
this->data = (uint8_t *)malloc(BUF_SIZE);
|
||||
this->temp_data = (uint8_t *)malloc(256);
|
||||
}
|
||||
|
||||
void SerialManager::try_receive()
|
||||
{
|
||||
int len = usb_serial_jtag_read_bytes(this->data, (BUF_SIZE - 1), 10000);
|
||||
if (len)
|
||||
int current_position = 0;
|
||||
int len = usb_serial_jtag_read_bytes(this->temp_data, 256, 1000 / 20);
|
||||
|
||||
// since we've got something on the serial port
|
||||
// we gotta keep reading until we've got the whole message
|
||||
while (len)
|
||||
{
|
||||
memcpy(this->data + current_position, this->temp_data, len);
|
||||
current_position += len;
|
||||
len = usb_serial_jtag_read_bytes(this->temp_data, 256, 1000 / 20);
|
||||
}
|
||||
|
||||
if (current_position)
|
||||
{
|
||||
// once we're done, we can terminate the string and reset the counter
|
||||
data[current_position] = '\0';
|
||||
current_position = 0;
|
||||
|
||||
auto result = this->commandManager->executeFromJson(std::string_view((const char *)this->data));
|
||||
auto resultMessage = result.getResult();
|
||||
usb_serial_jtag_write_bytes(resultMessage.c_str(), resultMessage.length(), 10000);
|
||||
usb_serial_jtag_write_bytes(resultMessage.c_str(), resultMessage.length(), 1000 / 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ private:
|
||||
QueueHandle_t serialQueue;
|
||||
std::shared_ptr<CommandManager> commandManager;
|
||||
uint8_t *data;
|
||||
uint8_t *temp_data;
|
||||
};
|
||||
|
||||
void HandleSerialManagerTask(void *pvParameters);
|
||||
|
||||
Reference in New Issue
Block a user