diff options
| author | info@mode42.com <info@mode42.com> | 2026-08-08 03:54:55 +0000 |
|---|---|---|
| committer | info@mode42.com <info@mode42.com> | 2026-08-08 03:54:55 +0000 |
| commit | 20cb29c2f8c5c87bc590896854a20b1473ceb358 (patch) | |
| tree | 2857f41513a56ad41af97b57362639298aa7f033 /include/hybbx/kiss.h | |
#2
Diffstat (limited to 'include/hybbx/kiss.h')
| -rw-r--r-- | include/hybbx/kiss.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/include/hybbx/kiss.h b/include/hybbx/kiss.h new file mode 100644 index 0000000..9cd378d --- /dev/null +++ b/include/hybbx/kiss.h @@ -0,0 +1,61 @@ +#ifndef HYBBX_KISS_H +#define HYBBX_KISS_H + +#include "hybbx/types.h" + +#include <stddef.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define HYBBX_KISS_FEND 0xC0u +#define HYBBX_KISS_FESC 0xDBu +#define HYBBX_KISS_TFEND 0xDCu +#define HYBBX_KISS_TFESC 0xDDu + +typedef enum hybbx_kiss_command { + HYBBX_KISS_CMD_DATA = 0x00, + HYBBX_KISS_CMD_TXDELAY = 0x01, + HYBBX_KISS_CMD_PERSIST = 0x02, + HYBBX_KISS_CMD_SLOTTIME = 0x03, + HYBBX_KISS_CMD_TXTAIL = 0x04, + HYBBX_KISS_CMD_FULLDUPLEX = 0x05, + HYBBX_KISS_CMD_SETHARDWARE = 0x06 +} hybbx_kiss_command_t; + +#define HYBBX_KISS_MAX_FRAME 2048 + +typedef void (*hybbx_kiss_frame_cb)(uint8_t port, const uint8_t *frame, + size_t len, void *userdata); + +typedef struct hybbx_kiss_decoder { + uint8_t buf[HYBBX_KISS_MAX_FRAME]; + size_t len; + int in_frame; + int escape; +} hybbx_kiss_decoder_t; + +void hybbx_kiss_decoder_init(hybbx_kiss_decoder_t *dec); + +/** + * Feed raw serial bytes; complete KISS frames invoke @p cb. + */ +void hybbx_kiss_decoder_feed(hybbx_kiss_decoder_t *dec, + const uint8_t *data, size_t len, + hybbx_kiss_frame_cb cb, void *userdata); + +/** + * Encode a KISS frame into @p out (must hold at least @p out_cap bytes). + * Returns encoded length or 0 on error. + */ +size_t hybbx_kiss_encode(uint8_t port, hybbx_kiss_command_t cmd, + const uint8_t *payload, size_t payload_len, + uint8_t *out, size_t out_cap); + +#ifdef __cplusplus +} +#endif + +#endif /* HYBBX_KISS_H */ |
