Skip to content
Snippets Groups Projects
Commit d8b578f4 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

import MPack. Does not work with embedded yet

parent 404f207f
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -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
......
......@@ -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"
......@@ -111,6 +114,38 @@ void loop(void)
kout << len << " bytes written" << endl;
}
#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
/*
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment