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

prototest: More arduinojson, ubjson, cbor

parent a07d2385
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include "prototest_global.cc.inc" #include "prototest_global.cc.inc"
#endif #endif
#ifdef PROTOTEST_ARDUINOJSON
char buf[256];
#endif
#ifdef PROTOTEST_XDR #ifdef PROTOTEST_XDR
char buf[256]; char buf[256];
#endif #endif
...@@ -99,11 +102,30 @@ void loop(void) ...@@ -99,11 +102,30 @@ void loop(void)
*/ */
#ifdef PROTOTEST_ARDUINOJSON #ifdef PROTOTEST_ARDUINOJSON
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; for (unsigned int i = 0; i < 128; i++) {
ArduinoJson::StaticJsonBuffer<200> jsonBuffer; buf[i] = 0;
ArduinoJson::JsonObject& root = jsonBuffer.parseObject(json); }
const char *sensor = root["sensor"];
kout << "sensor: " << sensor << endl; {
ArduinoJson::StaticJsonBuffer<200> jsonBuffer;
ArduinoJson::JsonObject& root = jsonBuffer.createObject();
root["sensor"] = "gps";
root["time"] = ts;
ArduinoJson::JsonArray& data = root.createNestedArray("data");
data.add(48.756080);
data.add(2.302038);
root.printTo(buf);
kout << "buf is " << buf << endl;
}
{
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
ArduinoJson::StaticJsonBuffer<200> jsonBuffer;
ArduinoJson::JsonObject& root = jsonBuffer.parseObject(json);
const char *sensor = root["sensor"];
kout << "sensor: " << sensor << endl;
}
#endif #endif
/* /*
...@@ -122,14 +144,28 @@ void loop(void) ...@@ -122,14 +144,28 @@ void loop(void)
{"time", ts}, {"time", ts},
{"data", {48.756080, 2.302038} } {"data", {48.756080, 2.302038} }
}; };
kout << js2.dump() << endl; kout << "string:" << js2.dump() << endl;
std::vector<std::uint8_t> v_cbor = nlohmann::json::to_cbor(js2); std::vector<std::uint8_t> v_cbor = nlohmann::json::to_cbor(js2);
kout << "CBOR vector is " << hex; kout << "CBOR:" << hex;
for (unsigned int i = 0; i < v_cbor.size(); i++) { for (unsigned int i = 0; i < v_cbor.size(); i++) {
kout << v_cbor[i] << " "; kout << v_cbor[i] << " ";
} }
kout << endl; kout << endl;
std::vector<std::uint8_t> v_msgpack = nlohmann::json::to_msgpack(js2);
kout << "MsgPack:" << hex;
for (unsigned int i = 0; i < v_msgpack.size(); i++) {
kout << v_msgpack[i] << " ";
}
kout << endl;
std::vector<std::uint8_t> v_ubjson = nlohmann::json::to_ubjson(js2);
kout << "UBJSON:" << hex;
for (unsigned int i = 0; i < v_ubjson.size(); i++) {
kout << v_ubjson[i] << " ";
}
kout << endl;
#endif #endif
/* /*
......
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