diff options
Diffstat (limited to 'proto/puzbusv1.c')
-rw-r--r-- | proto/puzbusv1.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/proto/puzbusv1.c b/proto/puzbusv1.c index 9d1335e..3ff7c63 100644 --- a/proto/puzbusv1.c +++ b/proto/puzbusv1.c @@ -1,13 +1,32 @@ #include <mpack.h> +#include <stdio.h> #include "puzbusv1.h" int pb_read(struct pb_msg* target, char* buf, size_t buf_sz) { mpack_reader_t reader; + printf("read %lu bytes...\n", buf_sz); + + mpack_reader_init_data(&reader, buf, buf_sz); + + uint16_t address = mpack_expect_u16(&reader); + char data_buf[80]; + size_t data_size = mpack_expect_bin_buf(&reader, data_buf, sizeof(data_buf)); + + printf("0x%02x\n", address); + printf("\"%.*s\"\n", data_size, data_buf); return 0; } -void pb_free(struct pb_msg* msg); +int pb_write(struct pb_msg* target, char** buf, size_t* buf_sz) { + mpack_writer_t writer; + mpack_writer_init_growable(&writer, buf, buf_sz); + mpack_write_u16(&writer, target->addr); + mpack_write_bin(&writer, target->data, target->length); + + // finish writing + return mpack_writer_destroy(&writer) == mpack_ok; +} |