mirror of
https://github.com/tio/tio.git
synced 2026-05-01 23:07:58 +02:00
Rework rs485_parse_config()
Introduce proper sscanf() checks.
This commit is contained in:
parent
c4878a90d7
commit
9744fcafcf
1 changed files with 51 additions and 44 deletions
19
src/rs485.c
19
src/rs485.c
|
|
@ -57,17 +57,16 @@ void rs485_parse_config(const char *arg)
|
||||||
{
|
{
|
||||||
char keyname[31];
|
char keyname[31];
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
|
int match_count;
|
||||||
|
|
||||||
if (sscanf(token, "%30[^=]=%d", keyname, &value) != 2)
|
match_count = sscanf(token, "%30[^=]=%d", keyname, &value);
|
||||||
|
|
||||||
|
if (match_count == 2)
|
||||||
{
|
{
|
||||||
token_found = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp(keyname, "RTS_ON_SEND"))
|
if (!strcmp(keyname, "RTS_ON_SEND"))
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Set logical level for RTS pin equal to 1 when sending */
|
/* Set logical level for RTS pin equal to 1 when sending */
|
||||||
option.rs485_config_flags |= SER_RS485_RTS_ON_SEND;
|
option.rs485_config_flags |= SER_RS485_RTS_ON_SEND;
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +99,10 @@ void rs485_parse_config(const char *arg)
|
||||||
/* Set RTS delay after send */
|
/* Set RTS delay after send */
|
||||||
option.rs485_delay_rts_after_send = value;
|
option.rs485_delay_rts_after_send = value;
|
||||||
}
|
}
|
||||||
else if (!strcmp(keyname, "RX_DURING_TX"))
|
}
|
||||||
|
else if (match_count == 1)
|
||||||
|
{
|
||||||
|
if (!strcmp(keyname, "RX_DURING_TX"))
|
||||||
{
|
{
|
||||||
/* Receive data even while sending data */
|
/* Receive data even while sending data */
|
||||||
option.rs485_config_flags |= SER_RS485_RX_DURING_TX;
|
option.rs485_config_flags |= SER_RS485_RX_DURING_TX;
|
||||||
|
|
@ -111,6 +113,11 @@ void rs485_parse_config(const char *arg)
|
||||||
token_found = false;
|
token_found = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
token_found = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue