MBot Software Library  v1.0
An API documentation to mbot_firmware repository
protocol.h
1 
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <stdlib.h>
14 #include <pico/binary_info.h>
15 #include <pico/stdlib.h>
16 #include <pico/stdio_usb.h>
17 #include <comms/common.h>
18 #include <string.h>
19 #include <search.h>
20 
21 #ifndef PROTOCOL_H
22 #define PROTOCOL_H
23 
24 #define MAX_RADIX_TOPICS 16
25 
26 typedef int (*Deserialize)(uint8_t* src, void* dest);
27 typedef int (*Serialize)(void* src, uint8_t* dest);
28 typedef void (*MsgCb)(void* data);
29 
30 typedef struct topic_registry_val{
31  uint16_t topic_id;
32  int32_t topic_data_len;
33  Deserialize deserialize_fn;
34  Serialize serialize_fn;
35  MsgCb cb_fn;
37 
38 typedef struct topic_registry_entry{
39  struct topic_registry_entry* left;
40  struct topic_registry_entry* right;
41  struct topic_registry_val* value;
43 
44 extern topic_registry_entry_t* topic_registry_root_node;
45 
46 int comms_init_protocol(void);
47 int comms_register_topic(uint16_t topic_id,
48  uint32_t topic_data_len,
49  Deserialize deserialize_fn,
50  Serialize serialize_fn,
51  MsgCb callback_fn);
52 int comms_get_topic_serializers(uint16_t topic_id, topic_registry_val_t* topic_reg_val);
53 int comms_generate_packet(uint16_t topic_id, void* topic_struct, uint8_t** packet_out, uint32_t* packet_len_out);
54 int comms_send_serial(uint8_t* packet_out, uint32_t packet_len);
55 int comms_write_topic_test(uint16_t topic_id, void* topic_struct);
56 int comms_write_topic(uint16_t topic_id, void* topic_struct);
57 
58 #endif
Definition: protocol.h:38
Definition: protocol.h:30