diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-11-13 11:18:00 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-11-13 11:18:00 +0100 |
commit | d8b578f42c5fbac101c77249c05939fd04d50722 (patch) | |
tree | a07e5287e38b3526757f4568231f8e81a5d581ad /src/app/prototest | |
parent | 404f207fa8bda5acaf09c3dbdae8aaf7cb639a29 (diff) |
import MPack. Does not work with embedded yet
Diffstat (limited to 'src/app/prototest')
-rw-r--r-- | src/app/prototest/Makefile.inc | 6 | ||||
-rw-r--r-- | src/app/prototest/main.cc | 35 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/app/prototest/Makefile.inc b/src/app/prototest/Makefile.inc index 3a9b4c3..a33e46f 100644 --- a/src/app/prototest/Makefile.inc +++ b/src/app/prototest/Makefile.inc @@ -8,6 +8,12 @@ ifeq (${prototest_modernjson}, 1) COMMON_FLAGS += -DPROTOTEST_MODERNJSON endif +ifeq (${prototest_mpack}, 1) + COMMON_FLAGS += -DPROTOTEST_MPACK + TARGETS += src/lib/mpack/mpack.cc + INCLUDES += -Iinclude/lib/mpack +endif + ifeq (${prototest_nanopb}, 1) COMMON_FLAGS += -DPROTOTEST_NANOPB TARGETS += src/app/prototest/nanopb.pb.cc src/lib/nanopb/pb_common.cc diff --git a/src/app/prototest/main.cc b/src/app/prototest/main.cc index fe33ae0..aebfaea 100644 --- a/src/app/prototest/main.cc +++ b/src/app/prototest/main.cc @@ -8,6 +8,9 @@ #ifdef PROTOTEST_MODERNJSON #include "lib/modernjson/json.h" #endif +#ifdef PROTOTEST_MPACK +#include "mpack.h" +#endif #ifdef PROTOTEST_NANOPB #include <pb.h> #include "nanopb.pb.h" @@ -114,6 +117,38 @@ void loop(void) #endif /* + * MPack + */ + +#ifdef PROTOTEST_MPACK + char buf[128]; + for (unsigned int i = 0; i < 128; i++) { + buf[i] = 0; + } + mpack_writer_t writer; + mpack_writer_init(&writer, buf, sizeof(buf)); + + mpack_start_map(&writer, 2); + mpack_write_cstr(&writer, "gps"); + mpack_write_uint(&writer, ts); + mpack_start_array(&writer, 2); + mpack_write_float(&writer, 48.756080); + mpack_write_float(&writer, 2.302038); + mpack_finish_array(&writer); + mpack_finish_map(&writer); + + if (mpack_writer_destroy(&writer) != mpack_ok) { + kout << "Encoding failed" << endl; + } + kout << "mpack is " << hex; + for (unsigned int i = 0; i < 128; i++) { + kout << (uint8_t)buf[i]; + } + kout << endl; + +#endif + + /* * Common */ |