2021-01-26 19:16:08 +00:00
|
|
|
#pragma once
|
|
|
|
#include "system.h"
|
|
|
|
|
2021-05-08 16:10:34 +00:00
|
|
|
#define PKT_BUFSIZ 4000000
|
2021-05-03 22:44:39 +00:00
|
|
|
|
2021-01-26 19:16:08 +00:00
|
|
|
typedef enum {
|
2021-05-06 15:30:38 +00:00
|
|
|
MSG_ID_00_INIT,
|
2021-01-26 19:16:08 +00:00
|
|
|
MSG_ID_01_WELCOME,
|
|
|
|
MSG_ID_LIBRG_UPDATE,
|
2021-05-05 13:14:02 +00:00
|
|
|
MSG_ID_SEND_KEYSTATE,
|
2021-01-26 19:16:08 +00:00
|
|
|
MSG_ID_FORCE_UINT16 = UINT16_MAX,
|
|
|
|
} pkt_messages;
|
|
|
|
|
2021-05-03 19:53:28 +00:00
|
|
|
typedef struct pkt_header {
|
2021-01-26 19:16:08 +00:00
|
|
|
uint16_t id;
|
|
|
|
uint16_t sender;
|
2021-05-06 15:30:38 +00:00
|
|
|
uint16_t view_id;
|
2021-09-09 08:29:22 +00:00
|
|
|
uint16_t channel_id;
|
2021-01-26 19:16:08 +00:00
|
|
|
uint8_t *data;
|
|
|
|
uint32_t datalen;
|
2021-05-04 17:39:50 +00:00
|
|
|
int8_t is_reliable;
|
2021-01-26 19:16:08 +00:00
|
|
|
int8_t ok;
|
2021-05-06 15:30:38 +00:00
|
|
|
void* udata;
|
2021-01-26 19:16:08 +00:00
|
|
|
} pkt_header;
|
|
|
|
|
2021-05-03 19:53:28 +00:00
|
|
|
#define PKT_HANDLER_PROC(name) int32_t name(pkt_header *header)
|
|
|
|
typedef PKT_HANDLER_PROC(pkt_handler_proc);
|
|
|
|
|
2021-01-26 19:16:08 +00:00
|
|
|
typedef struct {
|
|
|
|
uint16_t id;
|
|
|
|
pkt_handler_proc *handler;
|
|
|
|
} pkt_handler;
|
|
|
|
|
2021-05-06 15:30:38 +00:00
|
|
|
int32_t pkt_header_encode(pkt_messages id, uint16_t view_id, void *data, size_t datalen);
|
2021-01-26 19:16:08 +00:00
|
|
|
int32_t pkt_header_decode(pkt_header *table, void *data, size_t datalen);
|
|
|
|
|
|
|
|
extern pkt_handler pkt_handlers[];
|
2021-05-03 22:44:39 +00:00
|
|
|
extern uint8_t pkt_buffer[];
|