/ bm_serial_messages.h
bm_serial_messages.h
1 #pragma once 2 3 #include <stdbool.h> 4 #include <stdint.h> 5 6 typedef enum { 7 BM_SERIAL_DEBUG = 0x00, 8 BM_SERIAL_ACK = 0x01, 9 10 BM_SERIAL_PUB = 0x02, 11 BM_SERIAL_SUB = 0x03, 12 BM_SERIAL_UNSUB = 0x04, 13 BM_SERIAL_LOG = 0x05, 14 BM_SERIAL_NET_MSG = 0x06, 15 BM_SERIAL_RTC_SET = 0x07, 16 BM_SERIAL_SELF_TEST = 0x08, 17 BM_SERIAL_NETWORK_INFO = 0x09, 18 BM_SERIAL_REBOOT_INFO = 0x0A, 19 20 BM_SERIAL_DFU_START = 0x30, 21 BM_SERIAL_DFU_CHUNK = 0x31, 22 BM_SERIAL_DFU_RESULT = 0x32, 23 24 BM_SERIAL_CFG_GET = 0x40, 25 BM_SERIAL_CFG_SET = 0x41, 26 BM_SERIAL_CFG_VALUE = 0x42, 27 BM_SERIAL_CFG_COMMIT = 0x43, 28 BM_SERIAL_CFG_STATUS_REQ = 0x44, 29 BM_SERIAL_CFG_STATUS_RESP = 0x45, 30 BM_SERIAL_CFG_DEL_REQ = 0x46, 31 BM_SERIAL_CFG_DEL_RESP = 0x47, 32 33 BM_SERIAL_DEVICE_INFO_REQ = 0x50, 34 BM_SERIAL_DEVICE_INFO_REPLY = 0x51, 35 BM_SERIAL_RESOURCE_REQ = 0x52, 36 BM_SERIAL_RESOURCE_REPLY = 0x53, 37 38 } bm_serial_message_t; 39 40 typedef struct { 41 uint8_t type; 42 uint8_t flags; 43 uint16_t crc16; 44 uint8_t payload[0]; 45 } __attribute__ ((packed)) bm_serial_packet_t; 46 47 typedef struct { 48 uint64_t node_id; 49 uint8_t type; 50 uint8_t version; 51 uint16_t topic_len; 52 uint8_t topic[0]; 53 // message goes after topic 54 // len not included since we get the total len from COBS 55 } __attribute__ ((packed)) bm_serial_pub_header_t; 56 57 typedef struct { 58 uint16_t topic_len; 59 uint8_t topic[0]; 60 } __attribute__ ((packed)) bm_serial_sub_unsub_header_t; 61 62 typedef struct { 63 uint64_t node_id; 64 65 // Will use later to signify if this should go out cellular/satellite or both 66 uint8_t flags; 67 uint8_t data[0]; 68 } __attribute__ ((packed)) bm_serial_net_msg_header_t; 69 70 typedef struct { 71 uint16_t year; 72 uint8_t month; 73 uint8_t day; 74 uint8_t hour; 75 uint8_t minute; 76 uint8_t second; 77 uint32_t us; 78 } __attribute__ ((packed)) bm_serial_time_t; 79 80 typedef struct { 81 // Can be used to determine time source and other things 82 uint32_t flags; 83 84 bm_serial_time_t time; 85 } __attribute__ ((packed)) bm_serial_rtc_t; 86 87 typedef struct { 88 // Node id of unit reporting test (leave blank for test request) 89 uint64_t node_id; 90 // Flags for self test result 91 uint32_t result; 92 } __attribute__ ((packed)) bm_serial_self_test_t; 93 94 // DFU BELOW HERE. 95 typedef struct { 96 // Node id of unit for update 97 uint64_t node_id; 98 // size of image to update 99 uint32_t image_size; 100 // size of chunks to send 101 uint16_t chunk_size; 102 // crc16 103 uint16_t crc16; 104 // major version 105 uint8_t major_ver; 106 // minor version 107 uint8_t minor_ver; 108 // filter for update 109 uint32_t filter_key; 110 // git hash 111 uint32_t gitSHA; 112 } __attribute__ ((packed)) bm_serial_dfu_start_t; 113 114 #define DFU_CHUNK_NAK_BITFLAG (1<<31) 115 typedef struct { 116 // offset from image start 117 uint32_t offset; 118 // data length 119 uint32_t length; 120 // data packet 121 uint8_t data[0]; 122 } __attribute__ ((packed)) bm_serial_dfu_chunk_t; 123 124 typedef struct { 125 // Node id of dfu unit 126 uint64_t node_id; 127 // success of dfu 128 bool success; 129 // Errors for dfu result 130 uint32_t dfu_status; 131 } __attribute__ ((packed)) bm_serial_dfu_finish_t; 132 133 typedef struct { 134 // Node id 135 uint64_t node_id; 136 // Reboot Reason 137 uint32_t reboot_reason; 138 // git hash 139 uint32_t gitSHA; 140 // reboot count 141 uint32_t reboot_count; 142 uint32_t pc; 143 uint32_t lr; 144 } __attribute__ ((packed)) bm_serial_reboot_info_t; 145 146 typedef struct { 147 // Node ID of the target node for which the request is being made. (Zeroed = all nodes) 148 uint64_t target_node_id; 149 } __attribute__((packed)) bm_serial_device_info_request_t; 150 151 typedef struct { 152 // Node ID of the responding node 153 uint64_t node_id; 154 155 // Vendor ID of the hardware module implementing the BM Node functions 156 uint16_t vendor_id; 157 158 // Product ID for the hardware module implementing the BM Node functions 159 uint16_t product_id; 160 161 // Factory-flashed unique serial number 162 uint8_t serial_num[16]; 163 164 // Last 4 bytes of git SHA 165 uint32_t git_sha; 166 167 // Major Version 168 uint8_t ver_major; 169 170 // Minor Version 171 uint8_t ver_minor; 172 173 // Revision/Patch Version 174 uint8_t ver_rev; 175 176 // Version of the product hardware (0 for don't care) 177 uint8_t ver_hw; 178 } __attribute__((packed)) bm_serial_device_info_t; 179 180 typedef struct { 181 bm_serial_device_info_t info; 182 183 // Length of the full version string 184 uint8_t ver_str_len; 185 186 // Length of device name 187 uint8_t dev_name_len; 188 189 // ver_str is immediately followed by dev_name_len 190 char strings[0]; 191 } __attribute__((packed)) bm_serial_device_info_reply_t; 192 193 typedef struct { 194 // Node ID of the target node for which the request is being made. (Zeroed = all nodes) 195 uint64_t target_node_id; 196 } __attribute__((packed)) bm_serial_resource_table_request_t; 197 198 typedef struct { 199 // Length of resource name 200 uint16_t resource_len; 201 // Name of resource 202 char resource[0]; 203 } __attribute__((packed)) bm_serial_resource_t; 204 205 typedef struct { 206 // Node ID of the responding node 207 uint64_t node_id; 208 209 // Number of published topics 210 uint16_t num_pubs; 211 212 // Number of subscribed topics 213 uint16_t num_subs; 214 215 // List containing information for all resource interests known about this node. 216 // The list is comprised of bcmp_resource_t structures that are ordered such that 217 // the published resources are listed first, followed by the subscribed resources. 218 // The list can be traversed using 0 to (num_pubs - 1) to access the published resources, 219 // and num_pubs to (num_pubs + num_subs - 1) to access the subscribed resources. 220 uint8_t resource_list[0]; 221 } __attribute__((packed)) bm_serial_resource_table_reply_t;