Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix byte count and delay when writing on serial #489

Merged
merged 3 commits into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions network/serial_network/HAL/NATIVE/serial_network_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,32 +329,34 @@ void SerialHAL_Send(uint8_t *data, uint16_t size)
LUOS_ASSERT(0);
}
#else

// 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
{
totalBytesWritten += bytesWritten;
}
}
LUOS_ASSERT(bytesWritten == size);
LUOS_ASSERT(totalBytesWritten == size);
#endif
Serial_TransmissionEnd();
}
Expand Down
Loading