aboutsummaryrefslogtreecommitdiff
path: root/shared/protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'shared/protocol.c')
-rw-r--r--shared/protocol.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/shared/protocol.c b/shared/protocol.c
new file mode 100644
index 0000000..474398a
--- /dev/null
+++ b/shared/protocol.c
@@ -0,0 +1,30 @@
+#include "protocol.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+size_t cd_cmd_sizeof(uint8_t data[CD_SERIAL_READ_BUFFER_SIZE], uint8_t data_length) {
+ cd_cmd_opcode_t opcode = data[0];
+ if (CD_CMD_HANDLERS_SIZE[opcode] > 0) return CD_CMD_HANDLERS_SIZE[opcode];
+
+ cd_s_bin *copy = cd_bin_s_alloc(data_length, data);
+ size_t length = (*CD_CMD_HANDLERS_SIZEOF[opcode])(copy);
+
+ free(copy);
+
+ return length;
+}
+
+#define CD_DYN_MEMBER_SIZEOF(struct_t, length_byte, trailing_type) \
+ sizeof(struct_t) + \
+ (data->bytes > length_byte ? (sizeof(trailing_type) * data->data[length_byte]) : 0)
+
+size_t cd_cmd_response_sizeof(cd_s_bin* data) {
+ (void) data; // unused variable TODO: implement this
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif