diff options
-rw-r--r-- | firmware/src/data_link.c | 12 | ||||
-rw-r--r-- | firmware/src/data_link.h | 3 | ||||
-rw-r--r-- | firmware/src/main.c | 10 |
3 files changed, 24 insertions, 1 deletions
diff --git a/firmware/src/data_link.c b/firmware/src/data_link.c index a6d091a..330e973 100644 --- a/firmware/src/data_link.c +++ b/firmware/src/data_link.c @@ -1,7 +1,19 @@ +#include <string.h> #include <zephyr/drivers/uart.h> #include "data_link.h" +ssize_t dl_encode_frame(uint8_t *payload, size_t len, uint8_t *dst) { + // FIXME check for maximum size + + size_t flen = 8 + 8 + 2 + len + 4; + + memset(dst, 0, flen); + memcpy((void *)(dst + 18), payload, len); + + return flen; +} + void dl_send_frame(const struct device *const uart_dev, uint8_t *buffer, size_t len) { for (size_t i = 0; i < len; i++) { diff --git a/firmware/src/data_link.h b/firmware/src/data_link.h index d2a25a1..45f58dc 100644 --- a/firmware/src/data_link.h +++ b/firmware/src/data_link.h @@ -9,6 +9,9 @@ #define DL_SLIP_ESC_END 0xDC #define DL_SLIP_ESC_ESC 0xDD +#define DL_MAX_FRAME_SIZE 1500 + +ssize_t dl_encode_frame(uint8_t *payload, size_t len, uint8_t *dst); void dl_send_frame(const struct device *const uart_dev, uint8_t *buffer, size_t len); diff --git a/firmware/src/main.c b/firmware/src/main.c index e18cc77..8b31505 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -1,4 +1,5 @@ #include <stdbool.h> +#include <sys/types.h> #include <zephyr/device.h> #include <zephyr/drivers/uart.h> @@ -24,10 +25,17 @@ int main(void) } uint8_t payload[] = {0xDE, DL_SLIP_END, DL_SLIP_ESC, 0xAD}; + uint8_t frame[DL_MAX_FRAME_SIZE]; + + ssize_t flen = dl_encode_frame(payload, ARRAY_SIZE(payload), frame); + if (flen < 0) { + printk("Failed to encode frame"); + return 0; + } while (true) { k_sleep(K_MSEC(1000)); - dl_send_frame(uart_dev, payload, ARRAY_SIZE(payload)); + dl_send_frame(uart_dev, frame, flen); } return 0; |