From 1e54994000d1c26e9cbd724b76da5ceb273f9cbb Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 18 Jun 2024 15:39:03 +0200 Subject: i2c reply kinda working --- lib/pbdrv/drv/arduino/mod.cpp | 4 ---- lib/pbdrv/mpack-config.h | 12 ++++++------ lib/pbdrv/pb-msg.c | 13 +++++++++++-- lib/pbdrv/pb-types.h | 3 --- 4 files changed, 17 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/pbdrv/drv/arduino/mod.cpp b/lib/pbdrv/drv/arduino/mod.cpp index 328c3c7..9130334 100644 --- a/lib/pbdrv/drv/arduino/mod.cpp +++ b/lib/pbdrv/drv/arduino/mod.cpp @@ -82,7 +82,3 @@ int main(void) { * puzzle modules are likely not using USB. */ -void pb_null_err(const char * from) { - Serial.println(from); -} - diff --git a/lib/pbdrv/mpack-config.h b/lib/pbdrv/mpack-config.h index 7e7d0b2..f040698 100644 --- a/lib/pbdrv/mpack-config.h +++ b/lib/pbdrv/mpack-config.h @@ -11,11 +11,11 @@ #define MPACK_REALLOC pb_realloc // more reasonable buffer size (all messages are small) -#define MPACK_BUFFER_SIZE 80 -#define MPACK_STACK_SIZE 80 -#define MPACK_PAGE_SIZE 80 +#define MPACK_BUFFER_SIZE 256 +#define MPACK_STACK_SIZE MPACK_BUFFER_SIZE +#define MPACK_PAGE_SIZE MPACK_BUFFER_SIZE -// // disable unused features (causes errors?) -// #define MPACK_NODE 0 -// #define MPACK_BUILDER 0 +// disable unused features (causes errors?) +#define MPACK_NODE 0 +#define MPACK_BUILDER 0 diff --git a/lib/pbdrv/pb-msg.c b/lib/pbdrv/pb-msg.c index ab3f5b2..8cf020c 100644 --- a/lib/pbdrv/pb-msg.c +++ b/lib/pbdrv/pb-msg.c @@ -3,17 +3,26 @@ #include "pb-msg.h" #include "pb-serial.h" #include "pb-mem.h" +#include "mpack-config.h" pb_buf_t pb_msg_write(const pb_msg_t * msg) { pb_buf_t buf = { 0 }; if (msg == NULL) return buf; + buf.data = pb_malloc(MPACK_BUFFER_SIZE); + if (buf.data == NULL) return buf; + mpack_writer_t writer; - mpack_writer_init_growable(&writer, &buf.data, &buf.size); + mpack_writer_init(&writer, buf.data, buf.size); pb_ser_w(&writer, msg); - mpack_writer_destroy(&writer); + buf.size = mpack_writer_buffer_used(&writer); + if (mpack_writer_destroy(&writer) != mpack_ok) { + pb_free(buf.data); + buf.data = NULL; + buf.size = 0; + } return buf; } diff --git a/lib/pbdrv/pb-types.h b/lib/pbdrv/pb-types.h index fab9028..4d085f9 100644 --- a/lib/pbdrv/pb-types.h +++ b/lib/pbdrv/pb-types.h @@ -75,9 +75,6 @@ typedef struct { size_t _magic_size; //!< [META] size of \p magic } pb_cmd_magic_t; -// DEBUG: remove -void pb_null_err(const char * from); - #ifdef __cplusplus } #endif -- cgit v1.2.3