summaryrefslogtreecommitdiffstats
path: root/src/slip.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-06-21 03:04:54 +0200
committerLouis Burda <quent.burda@gmail.com>2023-06-21 03:20:09 +0200
commit4cb68fb41e7109f1f8c293b5ff08ae818f45cebe (patch)
tree7e3b1920cb51bb1f51af86f7fd9de12c1eed711b /src/slip.c
parente940cc8f0a57f04299bdc1b995981bab4c24f971 (diff)
downloadlibslip-c-master.tar.gz
libslip-c-master.zip
Add build.jst, fixup slip_init and add testHEADmaster
Diffstat (limited to 'src/slip.c')
-rw-r--r--src/slip.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/slip.c b/src/slip.c
index f25081d..920a801 100644
--- a/src/slip.c
+++ b/src/slip.c
@@ -37,8 +37,8 @@ slip_decode_inframe(struct slip *slip, uint8_t rx_byte)
if (rx_byte == slip->end) {
/* end of packet */
- slip->rx_packet(slip, slip->rx_packet_userdata,
- slip->rx_buf, slip->rx_index);
+ slip->rx_packet(slip, slip->rx_buf, slip->rx_index,
+ slip->rx_packet_userdata);
slip->rx_state = SLIPDEC_START_STATE;
} else if (rx_byte == slip->start) {
/* malformed packet */
@@ -65,16 +65,16 @@ slip_decode_escseq(struct slip *slip, uint8_t rx_byte)
int rc;
dec = slip->esc_dec[rx_byte];
- if (!slip->esc_active[dec]) {
- /* invalid contents, restart */
+ if (slip->esc_active[dec]) {
+ rc = slip_decode_store(slip, dec);
+ if (rc) return rc;
+ slip->rx_state = SLIPDEC_IN_FRAME_STATE;
+ } else {
+ /* invalid contents */
if (slip->rx_restart)
slip->rx_restart(slip, rx_byte);
slip->rx_state = SLIPDEC_START_STATE;
slip->rx_index = 0;
- } else {
- rc = slip_decode_store(slip, dec);
- if (rc) return rc;
- slip->rx_state = SLIPDEC_IN_FRAME_STATE;
}
return 0;
@@ -91,14 +91,14 @@ slip_init(struct slip *slip)
slip->rx_buflen = 0;
slip->rx_buf = NULL;
- if (slip->rx_packet) return -EINVAL;
- if (slip->realloc) return -EINVAL;
- if (slip->esc != slip->start) return -EINVAL;
- if (slip->esc != slip->end) return -EINVAL;
+ if (!slip->rx_packet) return -EINVAL;
+ if (!slip->realloc) return -EINVAL;
+ if (slip->esc == slip->start) return -EINVAL;
+ if (slip->esc == slip->end) return -EINVAL;
/* build decode table */
for (i = 0; i < 256; i++)
- slip->esc_dec[slip->esc_enc[i]] = i;
+ slip->esc_dec[slip->esc_enc[i]] = (uint8_t) i;
return 0;
}
@@ -181,7 +181,7 @@ slip_encode(struct slip *slip, uint8_t* out, size_t *outlen, size_t outcap,
if (pos >= end) return -ENOBUFS;
- *outlen = pos - out;
+ *outlen = (size_t) (pos - out);
return 0;
}