Fix the MSTP turnaround delay implementation. (#809)

The usleep() function takes microseconds, not milliseconds. So,
T_turnaround needs to be calculated in microseconds. If we don't do
this, at a baud rate of 9600, we end up waiting 4 microseconds instead
of 4 milliseconds, which goes against the rule.
This commit is contained in:
Sergey Nazaryev
2024-10-14 15:56:55 +03:00
committed by GitHub
parent b555e4a440
commit 2b58f5b122
2 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -399,7 +399,7 @@ void RS485_Send_Frame(
const uint8_t *buffer, /* frame to send (up to 501 bytes of data) */ const uint8_t *buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes) uint16_t nbytes)
{ /* number of bytes of data (up to 501) */ { /* number of bytes of data (up to 501) */
uint32_t turnaround_time = Tturnaround * 1000; uint32_t turnaround_time_usec = Tturnaround * 1000000UL;
uint32_t baud; uint32_t baud;
ssize_t written = 0; ssize_t written = 0;
int greska; int greska;
@@ -412,7 +412,7 @@ void RS485_Send_Frame(
baud = RS485_Get_Baud_Rate(); baud = RS485_Get_Baud_Rate();
/* sleeping for turnaround time is necessary to give other devices /* sleeping for turnaround time is necessary to give other devices
time to change from sending to receiving state. */ time to change from sending to receiving state. */
usleep(turnaround_time / baud); usleep(turnaround_time_usec / baud);
/* /*
On success, the number of bytes written are returned (zero On success, the number of bytes written are returned (zero
indicates nothing was written). On error, -1 is returned, and indicates nothing was written). On error, -1 is returned, and
@@ -438,7 +438,7 @@ void RS485_Send_Frame(
baud = RS485_Get_Port_Baud_Rate(mstp_port); baud = RS485_Get_Port_Baud_Rate(mstp_port);
/* sleeping for turnaround time is necessary to give other devices /* sleeping for turnaround time is necessary to give other devices
time to change from sending to receiving state. */ time to change from sending to receiving state. */
usleep(turnaround_time / baud); usleep(turnaround_time_usec / baud);
/* /*
On success, the number of bytes written are returned (zero On success, the number of bytes written are returned (zero
indicates nothing was written). On error, -1 is returned, and indicates nothing was written). On error, -1 is returned, and
+3 -3
View File
@@ -358,7 +358,7 @@ void RS485_Send_Frame(
const uint8_t *buffer, /* frame to send (up to 501 bytes of data) */ const uint8_t *buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes) uint16_t nbytes)
{ /* number of bytes of data (up to 501) */ { /* number of bytes of data (up to 501) */
uint32_t turnaround_time = Tturnaround * 1000; uint32_t turnaround_time_usec = Tturnaround * 1000000UL;
uint32_t baud; uint32_t baud;
ssize_t written = 0; ssize_t written = 0;
int greska; int greska;
@@ -371,7 +371,7 @@ void RS485_Send_Frame(
baud = RS485_Get_Baud_Rate(); baud = RS485_Get_Baud_Rate();
/* sleeping for turnaround time is necessary to give other devices /* sleeping for turnaround time is necessary to give other devices
time to change from sending to receiving state. */ time to change from sending to receiving state. */
usleep(turnaround_time / baud); usleep(turnaround_time_usec / baud);
/* /*
On success, the number of bytes written are returned (zero On success, the number of bytes written are returned (zero
indicates nothing was written). On error, -1 is returned, and indicates nothing was written). On error, -1 is returned, and
@@ -397,7 +397,7 @@ void RS485_Send_Frame(
baud = RS485_Get_Port_Baud_Rate(mstp_port); baud = RS485_Get_Port_Baud_Rate(mstp_port);
/* sleeping for turnaround time is necessary to give other devices /* sleeping for turnaround time is necessary to give other devices
time to change from sending to receiving state. */ time to change from sending to receiving state. */
usleep(turnaround_time / baud); usleep(turnaround_time_usec / baud);
/* /*
On success, the number of bytes written are returned (zero On success, the number of bytes written are returned (zero
indicates nothing was written). On error, -1 is returned, and indicates nothing was written). On error, -1 is returned, and