summaryrefslogtreecommitdiff
path: root/src/app/prototest
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/prototest')
-rw-r--r--src/app/prototest/Makefile.inc4
-rw-r--r--src/app/prototest/main.cc137
2 files changed, 119 insertions, 22 deletions
diff --git a/src/app/prototest/Makefile.inc b/src/app/prototest/Makefile.inc
index 39d3053..00c576c 100644
--- a/src/app/prototest/Makefile.inc
+++ b/src/app/prototest/Makefile.inc
@@ -1,10 +1,10 @@
ifeq (${prototest_bench_energy}, 1)
- loop = 1
+ loop ?= 1
COMMON_FLAGS += -DPROTOTEST_BENCH_ENERGY
endif
ifeq (${prototest_bench_cycles}, 1)
- loop = 0
+ loop ?= 0
arch_drivers += ,counter
COMMON_FLAGS += -DPROTOTEST_BENCH_CYCLES
endif
diff --git a/src/app/prototest/main.cc b/src/app/prototest/main.cc
index fa172a3..0b5e5d3 100644
--- a/src/app/prototest/main.cc
+++ b/src/app/prototest/main.cc
@@ -1,6 +1,7 @@
#include "arch.h"
#include "driver/gpio.h"
#include "driver/stdout.h"
+//#include "driver/counter.h"
#ifdef PROTOTEST_ARDUINOJSON
#include "lib/ArduinoJson.h"
@@ -56,6 +57,7 @@ char buf[256];
void loop(void)
{
static uint16_t ts = 0;
+ uint32_t tmp;
#ifdef PROTOTEST_INCLUDE_LOCAL
#include "prototest_local.cc.inc"
@@ -65,18 +67,46 @@ void loop(void)
* XDR
*/
+
+kout << "{";
+kout << "\"data\":[";
+kout << "48.75608" << ",";
+kout << "2.302038";
+kout << "]" << ",";
+kout << "\"nesting\":[";
+kout << "[";
+kout << "1";
+kout << "]" << ",";
+kout << "[";
+kout << "2" << ",";
+kout << "2";
+kout << "]" << ",";
+kout << "{";
+kout << "\"foo\":{";
+kout << "\"hurr\":\"durr\"";
+kout << "}";
+kout << "}";
+kout << "]" << ",";
+kout << "\"sensor\":\"gps\"" << ",";
+kout << "\"time\":" << dec << ts;
+kout << "}" << endl;
+
+
#ifdef PROTOTEST_XDR
BufferOutput<XDRStream> foostream(buf);
XDRInput input(buf);
char test[] = "Obai World!";
+ //counter.start();
foostream << (uint32_t)123 << (int16_t)-2 << ts << (uint16_t)0 << (uint64_t)4294967296 << (uint16_t)0;
foostream.setNextArrayLen(3);
- foostream << fixed << "Hai";
+ foostream << variable << "Hai";
foostream.setNextArrayLen(sizeof(test));
foostream << variable << (char const *)test;
+ //tmp = counter.stop();
+ //kout << "XDR serialization took " << tmp << " >" << counter.overflowed << " cycles" << endl;
kout << "foostream is " << hex;
for (unsigned int i = 0; i < 64; i += 4) {
kout << (unsigned char)buf[i] << (unsigned char)buf[i+1];
@@ -107,15 +137,38 @@ void loop(void)
}
{
+ counter.start();
ArduinoJson::StaticJsonBuffer<200> jsonBuffer;
+
+ ArduinoJson::JsonObject& root = jsonBuffer.createObject();
+ ArduinoJson::JsonArray& rootl = root.createNestedArray("data");
+ rootl.add(48.75608);
+ rootl.add(2.302038);
+ ArduinoJson::JsonArray& rootl_ = root.createNestedArray("nesting");
+ ArduinoJson::JsonArray& rootl_l = rootl_.createNestedArray();
+ rootl_l.add(1);
+ ArduinoJson::JsonArray& rootl_l_ = rootl_.createNestedArray();
+ rootl_l_.add(2);
+ rootl_l_.add(2);
+ ArduinoJson::JsonObject& rootl_o = rootl_.createNestedObject();
+ ArduinoJson::JsonObject& rootl_oo = rootl_o.createNestedObject("foo");
+ rootl_oo["hurr"] = "durr";
+ root["sensor"] = "gps";
+ root["time"] = ts;
+
+
+/*
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);
+ tmp = counter.stop();
+ kout << "ArduinoJSON serialization took " << tmp << " >" << counter.overflowed << " cycles" << endl;
kout << "buf is " << buf << endl;
}
@@ -134,38 +187,39 @@ void loop(void)
#ifdef PROTOTEST_MODERNJSON
nlohmann::json js1;
+ js1["data"] = {48.756080, 2.302038};
+ js1["nesting"][0] = {1};
+ js1["nesting"][1] = {2, 2};
+ js1["nesting"][2]["foo"]["hurr"] = "durr";
js1["sensor"] = "gps";
js1["time"] = ts;
- js1["data"] = {48.756080, 2.302038};
- kout << js1.dump() << endl;
-
- nlohmann::json js2 = {
- {"sensor", "gps"},
- {"time", ts},
- {"data", {48.756080, 2.302038} }
- };
- kout << "string:" << js2.dump() << endl;
+ kout << "string:" << js1.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(js1);
kout << "CBOR:" << hex;
for (unsigned int i = 0; i < v_cbor.size(); i++) {
kout << v_cbor[i] << " ";
}
kout << endl;
- std::vector<std::uint8_t> v_msgpack = nlohmann::json::to_msgpack(js2);
+ std::vector<std::uint8_t> v_msgpack = nlohmann::json::to_msgpack(js1);
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);
+ std::vector<std::uint8_t> v_ubjson = nlohmann::json::to_ubjson(js1);
kout << "UBJSON:" << hex;
for (unsigned int i = 0; i < v_ubjson.size(); i++) {
kout << v_ubjson[i] << " ";
}
kout << endl;
+ kout << "UBJSON: " << hex;
+ for (unsigned int i = 0; i < v_ubjson.size(); i++) {
+ kout << (char)v_ubjson[i] << " ";
+ }
+ kout << endl;
#endif
/*
@@ -201,7 +255,10 @@ void loop(void)
mpack_writer_t writer;
mpack_writer_init(&writer, buf, sizeof(buf));
+ start = uptime.get_cycles();
mpack_start_map(&writer, 2);
+ stop = uptime.get_cycles();
+ kout << stop - start << endl;
mpack_write_cstr(&writer, "gps");
mpack_write_uint(&writer, ts);
mpack_start_array(&writer, 2);
@@ -227,24 +284,57 @@ void loop(void)
#ifdef PROTOTEST_UBJSON
- uint8_t buf[128];
- for (unsigned int i = 0; i < 128; i++) {
+ uint8_t buf[192];
+ for (unsigned int i = 0; i < sizeof(buf); i++) {
buf[i] = 0;
}
ubjw_context_t* ctx = ubjw_open_memory(buf, buf + sizeof(buf));
+ ubjw_begin_object(ctx, UBJ_MIXED, 0);
+ ubjw_write_key(ctx, "data");
+
+ ubjw_begin_array(ctx, UBJ_FLOAT32, 0);
+ ubjw_write_float64(ctx, 48.75608);
+ ubjw_write_float64(ctx, 2.302038);
+ ubjw_end(ctx);
+
+ ubjw_write_key(ctx, "nesting");
+ ubjw_begin_array(ctx, UBJ_MIXED, 0);
+
ubjw_begin_array(ctx, UBJ_MIXED, 0);
- ubjw_write_int16(ctx, ts);
- ubjw_write_string(ctx, "Noot Noot");
+ ubjw_write_integer(ctx, 1);
ubjw_end(ctx);
- kout << "ubjr_close_context: " << ubjw_close_context(ctx) << endl;
+ ubjw_begin_array(ctx, UBJ_MIXED, 0);
+ ubjw_write_integer(ctx, 2);
+ ubjw_write_integer(ctx, 2);
+ ubjw_end(ctx);
- kout << "ubjr is " << hex;
- for (unsigned int i = 0; i < 128; i++) {
+ ubjw_begin_object(ctx, UBJ_MIXED, 0);
+ ubjw_write_key(ctx, "foo");
+
+ ubjw_begin_object(ctx, UBJ_MIXED, 0);
+ ubjw_write_key(ctx, "hurr");
+ ubjw_write_string(ctx, "durr");
+ ubjw_end(ctx);
+ ubjw_end(ctx);
+ ubjw_end(ctx);
+
+ ubjw_write_key(ctx, "sensor");
+ ubjw_write_string(ctx, "gps");
+ ubjw_write_key(ctx, "time");
+ ubjw_write_integer(ctx, ts);
+
+ ubjw_end(ctx);
+
+ kout << "ubjw_close_context: " << ubjw_close_context(ctx) << endl;
+
+ kout << "ubjson is " << hex;
+ for (unsigned int i = 0; i < sizeof(buf); i++) {
kout << (uint8_t)buf[i];
}
kout << endl;
+ kout << "ubjson is " << (char*)buf << endl;
#endif
@@ -267,7 +357,14 @@ int main(void)
gpio.led_on(0);
kout << "Hello, World!" << endl;
+
+#if defined(PROTOTEST_BENCH_CYCLES) and (defined(MULTIPASS_ARCH_arduino_nano) or defined(MULTIPASS_ARCH_msp430fr5969lp))
+ while (1) {
+ loop();
+ }
+#else
arch.idle_loop();
+#endif
return 0;
}