diff --git a/Makefile b/Makefile index d1295fe..518b8d5 100644 --- a/Makefile +++ b/Makefile @@ -24,4 +24,7 @@ nanopb_%: $(NANOPB_DIR)/proto/%.proto mv -f $@.c src run: - platformio run \ No newline at end of file + platformio run + +test: + g++ src/pb_common.c src/pb_decode.c src/pb_encode.c src/tm1638.pb.c test.cpp -o test -Isrc \ No newline at end of file diff --git a/nanopb b/nanopb index ef42265..7d4c880 160000 --- a/nanopb +++ b/nanopb @@ -1 +1 @@ -Subproject commit ef422656a57b3f472b192691a40f48d0d72f2927 +Subproject commit 7d4c8807af1fbef2ab79e3afa9f3e152694ac4d5 diff --git a/platformio.ini b/platformio.ini index 598567e..e6541b0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,4 +22,4 @@ platform = atmelavr framework = arduino board = uno targets = upload -upload_port = COM3 \ No newline at end of file +upload_port = COM4 \ No newline at end of file diff --git a/proto/tm1638.proto b/proto/tm1638.proto index b005dbf..bdf26e4 100644 --- a/proto/tm1638.proto +++ b/proto/tm1638.proto @@ -85,7 +85,7 @@ message SetDisplayToNumber { } message SetDisplayToString { - required string string = 1 [(nanopb).max_size = 40]; + required string string = 1; required int32 dots = 2; required int32 pos = 3; required bool has_font = 4; diff --git a/test.buffer b/test.buffer new file mode 100644 index 0000000..cab510a Binary files /dev/null and b/test.buffer differ diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..9cba2ac --- /dev/null +++ b/test.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +extern "C" { + #include "pb_decode.h" + #include "pb_encode.h" + #include "tm1638.pb.h" +} + +bool callbackFont(pb_istream_t *stream, const pb_field_t *field, void **arg) { + uint8_t buffer[256] = {0}; + int length = stream->bytes_left; + if (length > sizeof(buffer) - 1) { + return false; + } + if (!pb_read(stream, buffer, length)) { + return false; + } + memset(*arg, 0, sizeof(buffer)); + strncpy((char*) *arg, (char*) buffer, length); + return true; +} + +int main() { + FILE *fp = fopen("test.buffer", "r"); + + int packet_size = fgetc(fp); + uint8_t in_buffer[256]; + int bytes_read = fread((char*) in_buffer, 1, packet_size, fp); + if (bytes_read != packet_size) { + printf("length problem"); + return 1; + } + + pb_istream_t istream = pb_istream_from_buffer(in_buffer, bytes_read); + _tm1638_Command command; + command.setDisplayToString.string.funcs.decode = &callbackFont; + if (!pb_decode(&istream, tm1638_Command_fields, &command)) { + printf("decode problem"); + return 1; + } + + tm1638_SetDisplayToString setDisplayToString = command.setDisplayToString; + char dots = setDisplayToString.dots; + char pos = setDisplayToString.dots; + + printf("%s\n", setDisplayToString.string.arg); + return 0; +} \ No newline at end of file diff --git a/test.exe b/test.exe new file mode 100644 index 0000000..0e3f96a Binary files /dev/null and b/test.exe differ