Simplify patty_ax25_pton() state machine
Simplify patty_ax25_pton() state machine to remove the unnecessary ADDR_NONE state
This commit is contained in:
parent
eaa3a3a06a
commit
7041b73e0e
1 changed files with 2 additions and 13 deletions
15
src/ax25.c
15
src/ax25.c
|
@ -6,7 +6,6 @@
|
||||||
#include <patty/ax25.h>
|
#include <patty/ax25.h>
|
||||||
|
|
||||||
enum addr_state {
|
enum addr_state {
|
||||||
ADDR_NONE,
|
|
||||||
ADDR_CALLSIGN,
|
ADDR_CALLSIGN,
|
||||||
ADDR_SSID
|
ADDR_SSID
|
||||||
};
|
};
|
||||||
|
@ -21,7 +20,7 @@ int patty_ax25_pton(const char *callsign,
|
||||||
|
|
||||||
int ssid = 0;
|
int ssid = 0;
|
||||||
|
|
||||||
enum addr_state state = ADDR_NONE;
|
enum addr_state state = ADDR_CALLSIGN;
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
goto error_invalid_callsign;
|
goto error_invalid_callsign;
|
||||||
|
@ -33,16 +32,6 @@ int patty_ax25_pton(const char *callsign,
|
||||||
uint8_t c = callsign[i];
|
uint8_t c = callsign[i];
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case ADDR_NONE:
|
|
||||||
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')) {
|
|
||||||
state = ADDR_CALLSIGN;
|
|
||||||
addr->callsign[o++] = (c & 0x7f) << 1;
|
|
||||||
} else {
|
|
||||||
goto error_invalid_callsign;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ADDR_CALLSIGN:
|
case ADDR_CALLSIGN:
|
||||||
if (o > PATTY_AX25_CALLSIGN_LEN) {
|
if (o > PATTY_AX25_CALLSIGN_LEN) {
|
||||||
goto error_invalid_callsign;
|
goto error_invalid_callsign;
|
||||||
|
@ -59,7 +48,7 @@ int patty_ax25_pton(const char *callsign,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADDR_SSID:
|
case ADDR_SSID:
|
||||||
if (digits >= 2) {
|
if (digits == 2) {
|
||||||
goto error_invalid_callsign;
|
goto error_invalid_callsign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue