From 720827103340d42b95212e267416d00e31100537 Mon Sep 17 00:00:00 2001 From: Maxime COZZI Date: Fri, 24 May 2024 11:41:21 +0200 Subject: [PATCH 1/3] fix byte count and delay when writing on serial --- .../HAL/NATIVE/serial_network_hal.c | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/network/serial_network/HAL/NATIVE/serial_network_hal.c b/network/serial_network/HAL/NATIVE/serial_network_hal.c index 2696f2002..d66f281a0 100644 --- a/network/serial_network/HAL/NATIVE/serial_network_hal.c +++ b/network/serial_network/HAL/NATIVE/serial_network_hal.c @@ -329,32 +329,35 @@ void SerialHAL_Send(uint8_t *data, uint16_t size) LUOS_ASSERT(0); } #else - - // Check if the output buffer is full + // Check if the output buffer is full int bytes_in_buffer; + ssize_t totalBytesWritten = 0; ssize_t bytesWritten; ioctl(serial_port, TIOCOUTQ, &bytes_in_buffer); bytesWritten = write(serial_port, data, size); - if (bytesWritten < 0) + if (bytesWritten > 0) { - printf("Error writing to serial port\n"); - close(serial_port); - LUOS_ASSERT(0); + totalBytesWritten += bytesWritten; } - while (bytesWritten < size) + while (totalBytesWritten < size) { // Wait for the buffer to be empty usleep(1000); ioctl(serial_port, TIOCOUTQ, &bytes_in_buffer); - bytesWritten += write(serial_port, &data[bytesWritten], size - bytesWritten); + bytesWritten = write(serial_port, &data[bytesWritten], size - bytesWritten); if (bytesWritten < 0) { printf("Error writing to serial port\n"); close(serial_port); LUOS_ASSERT(0); } + else + { + usleep(1000); + totalBytesWritten += bytesWritten; + } } - LUOS_ASSERT(bytesWritten == size); + LUOS_ASSERT(totalBytesWritten == size); #endif Serial_TransmissionEnd(); } From 5357bf35ddf501f82c6871ace6988d49ff58e567 Mon Sep 17 00:00:00 2001 From: Maxime COZZI Date: Mon, 27 May 2024 13:28:53 +0200 Subject: [PATCH 2/3] remove useless delay --- network/serial_network/HAL/NATIVE/serial_network_hal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/network/serial_network/HAL/NATIVE/serial_network_hal.c b/network/serial_network/HAL/NATIVE/serial_network_hal.c index d66f281a0..36d70ffe0 100644 --- a/network/serial_network/HAL/NATIVE/serial_network_hal.c +++ b/network/serial_network/HAL/NATIVE/serial_network_hal.c @@ -353,7 +353,6 @@ void SerialHAL_Send(uint8_t *data, uint16_t size) } else { - usleep(1000); totalBytesWritten += bytesWritten; } } From 3d56f846ac81c05f15d7ec09e8209bb9f4d9a67f Mon Sep 17 00:00:00 2001 From: Maxime COZZI Date: Mon, 27 May 2024 14:36:53 +0200 Subject: [PATCH 3/3] fix comment format --- network/serial_network/HAL/NATIVE/serial_network_hal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/serial_network/HAL/NATIVE/serial_network_hal.c b/network/serial_network/HAL/NATIVE/serial_network_hal.c index 36d70ffe0..ccbb9be75 100644 --- a/network/serial_network/HAL/NATIVE/serial_network_hal.c +++ b/network/serial_network/HAL/NATIVE/serial_network_hal.c @@ -329,7 +329,7 @@ void SerialHAL_Send(uint8_t *data, uint16_t size) LUOS_ASSERT(0); } #else - // Check if the output buffer is full + // Check if the output buffer is full int bytes_in_buffer; ssize_t totalBytesWritten = 0; ssize_t bytesWritten;