summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-05-12 15:20:39 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2021-05-12 15:20:39 +0200
commit391c7d4b846fd0565174fd8973f36b4047809361 (patch)
treea2a0dcc7101a19d20bfaba79f394c0fa4a491a9c
parent8277397f48445ef3539d241f3e64726c0ff1cb02 (diff)
add prototest app
-rw-r--r--src/app/prototest/Makefile.inc96
-rw-r--r--src/app/prototest/main.cc79
-rw-r--r--src/app/prototest/nanopb.proto179
3 files changed, 354 insertions, 0 deletions
diff --git a/src/app/prototest/Makefile.inc b/src/app/prototest/Makefile.inc
new file mode 100644
index 0000000..9537632
--- /dev/null
+++ b/src/app/prototest/Makefile.inc
@@ -0,0 +1,96 @@
+ifeq (${aspectc}, 1)
+ CXX_FLAGS += --Xweaver -asrc/app/prototest/prototest.ah --Xcompiler
+endif
+
+ifeq (${prototest_bench_energy}, 1)
+ loop ?= 1
+ COMMON_FLAGS += -DPROTOTEST_BENCH_ENERGY
+endif
+
+ifeq (${prototest_bench_cycles}, 1)
+ loop ?= 0
+ arch_drivers += ,counter
+ COMMON_FLAGS += -DPROTOTEST_BENCH_CYCLES
+endif
+
+ifneq (${prototest_include_global}, )
+ COMMON_FLAGS += -DPROTOTEST_INCLUDE_GLOBAL=${prototest_include_global}
+endif
+
+ifneq (${prototest_include_local}, )
+ COMMON_FLAGS += -DPROTOTEST_INCLUDE_LOCAL=${prototest_include_local}
+endif
+
+ifeq (${prototest_arduinojson}, 1)
+ COMMON_FLAGS += -DPROTOTEST_ARDUINOJSON
+endif
+
+ifeq (${prototest_binn}, 1)
+ COMMON_FLAGS += -DPROTOTEST_BINN
+ CXX_TARGETS += src/lib/binn.cc
+endif
+
+ifeq (${prototest_capnproto_c}, 1)
+ COMMON_FLAGS += -DPROTOTEST_CAPNPROTO_C
+ CXX_TARGETS += src/app/prototest/capnp_c_bench.capnp.cc
+ CXX_TARGETS += src/lib/capnp-c/capn.cc
+ CXX_TARGETS += src/lib/capnp-c/capn-malloc.cc
+ CXX_TARGETS += src/lib/capnp-c/capn-stream.cc
+ INCLUDES += -Iinclude/lib/capnp-c
+endif
+
+ifeq (${prototest_manualjson}, 1)
+ COMMON_FLAGS += -DPROTOTEST_MANUALJSON
+endif
+
+ifeq (${prototest_modernjson}, 1)
+ COMMON_FLAGS += -DPROTOTEST_MODERNJSON
+ ostream = 1
+endif
+
+ifeq (${prototest_mpack}, 1)
+ COMMON_FLAGS += -DPROTOTEST_MPACK
+ CXX_TARGETS += src/lib/mpack/mpack.cc
+ INCLUDES += -Iinclude/lib/mpack
+endif
+
+ifeq (${prototest_nanopb}, 1)
+ COMMON_FLAGS += -DPROTOTEST_NANOPB
+ CXX_TARGETS += src/app/prototest/nanopbbench.pb.cc src/lib/nanopb/pb_common.cc
+ CXX_TARGETS += src/lib/nanopb/pb_decode.cc src/lib/nanopb/pb_encode.cc
+ INCLUDES += -Iinclude/lib/nanopb
+endif
+
+ifeq (${prototest_ubjson}, 1)
+ COMMON_FLAGS += -DPROTOTEST_UBJSON
+ C_TARGETS += src/lib/ubjson/ubjr.c src/lib/ubjson/ubjw.c
+ INCLUDES += -Iinclude/lib/ubjson
+endif
+
+ifeq (${prototest_xdr}, 1)
+ COMMON_FLAGS += -DPROTOTEST_XDR
+ CXX_TARGETS += src/lib/xdr.cc
+endif
+
+ifeq (${prototest_xdr16}, 1)
+ COMMON_FLAGS += -DPROTOTEST_XDR16
+ CXX_TARGETS += src/lib/xdr16.cc
+endif
+
+# Don't try to make .capnp from .capnp.c
+%.capnp: ;
+
+# Don't try to make .proto from .proto.c
+%.proto: ;
+
+%.pb.cc: %.proto
+ ${QUIET}protoc --plugin=protoc-gen-nanopb=${HOME}/var/ess/protocol-modeling-netsys/nanopb/generator/protoc-gen-nanopb --nanopb_out=. src/app/prototest/nanopbbench.proto
+ ${QUIET}mv src/app/prototest/nanopbbench.pb.c src/app/prototest/nanopbbench.pb.cc
+ ${QUIET}cp src/app/prototest/nanopbbench.pb.cc /tmp
+ ${QUIET}sed -i 's!src/app/prototest/!!' src/app/prototest/nanopbbench.pb.cc
+ ${QUIET}sed -i 's!\#include "src/app/prototest/nanopb.pb.h"!!' src/app/prototest/nanopbbench.pb.h
+
+%.capnp.cc: %.capnp
+ ${QUIET}capnp compile -oc $<
+ ${QUIET}mv $<.c $<.cc
+ ${QUIET}cp $<.cc /tmp
diff --git a/src/app/prototest/main.cc b/src/app/prototest/main.cc
new file mode 100644
index 0000000..7fc897e
--- /dev/null
+++ b/src/app/prototest/main.cc
@@ -0,0 +1,79 @@
+#include "arch.h"
+#include "driver/gpio.h"
+#include "driver/stdout.h"
+
+#ifdef PROTOTEST_BENCH_CYCLES
+#include "driver/counter.h"
+#endif
+
+#ifdef PROTOTEST_ARDUINOJSON
+#include "lib/ArduinoJson.h"
+#endif
+#ifdef PROTOTEST_BINN
+#include "lib/binn.h"
+#endif
+#ifdef PROTOTEST_CAPNPROTO_C
+#include <capnp_c.h>
+#include "capnp_c_bench.capnp.h"
+#endif
+#ifdef PROTOTEST_MANUALJSON
+#include "object/stdbuf.h"
+#endif
+#ifdef PROTOTEST_MODERNJSON
+#include "lib/modernjson/json.h"
+#endif
+#ifdef PROTOTEST_MPACK
+#include "mpack.h"
+#endif
+#ifdef PROTOTEST_NANOPB
+#include <pb.h>
+#include "nanopbbench.pb.h"
+#include <pb_encode.h>
+#include <pb_decode.h>
+#endif
+#ifdef PROTOTEST_UBJSON
+#include "ubj.h"
+#endif
+#ifdef PROTOTEST_XDR
+#include "lib/xdr.h"
+#endif
+#ifdef PROTOTEST_XDR16
+#include "lib/xdr16.h"
+#endif
+
+#include <stdint.h>
+
+#ifdef PROTOTEST_INCLUDE_GLOBAL
+#include "prototest_global.cc.inc"
+#endif
+
+void loop(void)
+{
+ //static uint16_t ts = 0;
+ //ts++;
+
+#ifdef PROTOTEST_INCLUDE_LOCAL
+#include "prototest_local.cc.inc"
+#endif
+
+}
+
+int main(void)
+{
+ arch.setup();
+ gpio.setup();
+ kout.setup();
+
+ //gpio.led_on(0);
+ kout << "Hello, World!" << endl;
+
+#if defined(PROTOTEST_BENCH_CYCLES) and !defined(PROTOTEST_ARCH_esp8266)
+ while (1) {
+ loop();
+ }
+#else
+ arch.idle_loop();
+#endif
+
+ return 0;
+}
diff --git a/src/app/prototest/nanopb.proto b/src/app/prototest/nanopb.proto
new file mode 100644
index 0000000..c8067e3
--- /dev/null
+++ b/src/app/prototest/nanopb.proto
@@ -0,0 +1,179 @@
+// Custom options for defining:
+// - Maximum size of string/bytes
+// - Maximum number of elements in array
+//
+// These are used by nanopb to generate statically allocable structures
+// for memory-limited environments.
+
+syntax = "proto2";
+import "google/protobuf/descriptor.proto";
+
+option java_package = "fi.kapsi.koti.jpa.nanopb";
+
+enum FieldType {
+ FT_DEFAULT = 0; // Automatically decide field type, generate static field if possible.
+ FT_CALLBACK = 1; // Always generate a callback field.
+ FT_POINTER = 4; // Always generate a dynamically allocated field.
+ FT_STATIC = 2; // Generate a static field or raise an exception if not possible.
+ FT_IGNORE = 3; // Ignore the field completely.
+ FT_INLINE = 5; // Legacy option, use the separate 'fixed_length' option instead
+}
+
+enum IntSize {
+ IS_DEFAULT = 0; // Default, 32/64bit based on type in .proto
+ IS_8 = 8;
+ IS_16 = 16;
+ IS_32 = 32;
+ IS_64 = 64;
+}
+
+enum TypenameMangling {
+ M_NONE = 0; // Default, no typename mangling
+ M_STRIP_PACKAGE = 1; // Strip current package name
+ M_FLATTEN = 2; // Only use last path component
+ M_PACKAGE_INITIALS = 3; // Replace the package name by the initials
+}
+
+enum DescriptorSize {
+ DS_AUTO = 0; // Select minimal size based on field type
+ DS_1 = 1; // 1 word; up to 15 byte fields, no arrays
+ DS_2 = 2; // 2 words; up to 4095 byte fields, 4095 entry arrays
+ DS_4 = 4; // 4 words; up to 2^32-1 byte fields, 2^16-1 entry arrays
+ DS_8 = 8; // 8 words; up to 2^32-1 entry arrays
+}
+
+// This is the inner options message, which basically defines options for
+// a field. When it is used in message or file scope, it applies to all
+// fields.
+message NanoPBOptions {
+ // Allocated size for 'bytes' and 'string' fields.
+ // For string fields, this should include the space for null terminator.
+ optional int32 max_size = 1;
+
+ // Maximum length for 'string' fields. Setting this is equivalent
+ // to setting max_size to a value of length+1.
+ optional int32 max_length = 14;
+
+ // Allocated number of entries in arrays ('repeated' fields)
+ optional int32 max_count = 2;
+
+ // Size of integer fields. Can save some memory if you don't need
+ // full 32 bits for the value.
+ optional IntSize int_size = 7 [default = IS_DEFAULT];
+
+ // Force type of field (callback or static allocation)
+ optional FieldType type = 3 [default = FT_DEFAULT];
+
+ // Use long names for enums, i.e. EnumName_EnumValue.
+ optional bool long_names = 4 [default = true];
+
+ // Add 'packed' attribute to generated structs.
+ // Note: this cannot be used on CPUs that break on unaligned
+ // accesses to variables.
+ optional bool packed_struct = 5 [default = false];
+
+ // Add 'packed' attribute to generated enums.
+ optional bool packed_enum = 10 [default = false];
+
+ // Skip this message
+ optional bool skip_message = 6 [default = false];
+
+ // Generate oneof fields as normal optional fields instead of union.
+ optional bool no_unions = 8 [default = false];
+
+ // integer type tag for a message
+ optional uint32 msgid = 9;
+
+ // decode oneof as anonymous union
+ optional bool anonymous_oneof = 11 [default = false];
+
+ // Proto3 singular field does not generate a "has_" flag
+ optional bool proto3 = 12 [default = false];
+
+ // Force proto3 messages to have no "has_" flag.
+ // This was default behavior until nanopb-0.4.0.
+ optional bool proto3_singular_msgs = 21 [default = false];
+
+ // Generate an enum->string mapping function (can take up lots of space).
+ optional bool enum_to_string = 13 [default = false];
+
+ // Generate bytes arrays with fixed length
+ optional bool fixed_length = 15 [default = false];
+
+ // Generate repeated field with fixed count
+ optional bool fixed_count = 16 [default = false];
+
+ // Generate message-level callback that is called before decoding submessages.
+ // This can be used to set callback fields for submsgs inside oneofs.
+ optional bool submsg_callback = 22 [default = false];
+
+ // Shorten or remove package names from type names.
+ // This option applies only on the file level.
+ optional TypenameMangling mangle_names = 17 [default = M_NONE];
+
+ // Data type for storage associated with callback fields.
+ optional string callback_datatype = 18 [default = "pb_callback_t"];
+
+ // Callback function used for encoding and decoding.
+ // Prior to nanopb-0.4.0, the callback was specified in per-field pb_callback_t
+ // structure. This is still supported, but does not work inside e.g. oneof or pointer
+ // fields. Instead, a new method allows specifying a per-message callback that
+ // will be called for all callback fields in a message type.
+ optional string callback_function = 19 [default = "pb_default_field_callback"];
+
+ // Select the size of field descriptors. This option has to be defined
+ // for the whole message, not per-field. Usually automatic selection is
+ // ok, but if it results in compilation errors you can increase the field
+ // size here.
+ optional DescriptorSize descriptorsize = 20 [default = DS_AUTO];
+
+ // Set default value for has_ fields.
+ optional bool default_has = 23 [default = false];
+
+ // Extra files to include in generated `.pb.h`
+ repeated string include = 24;
+
+ // Automatic includes to exlude from generated `.pb.h`
+ // Same as nanopb_generator.py command line flag -x.
+ repeated string exclude = 26;
+
+ // Package name that applies only for nanopb.
+ optional string package = 25;
+
+ // Override type of the field in generated C code. Only to be used with related field types
+ optional google.protobuf.FieldDescriptorProto.Type type_override = 27;
+
+ // Due to historical reasons, nanopb orders fields in structs by their tag number
+ // instead of the order in .proto. Set this to false to keep the .proto order.
+ // The default value will probably change to false in nanopb-0.5.0.
+ optional bool sort_by_tag = 28 [default = true];
+}
+
+// Extensions to protoc 'Descriptor' type in order to define options
+// inside a .proto file.
+//
+// Protocol Buffers extension number registry
+// --------------------------------
+// Project: Nanopb
+// Contact: Petteri Aimonen <jpa@kapsi.fi>
+// Web site: http://kapsi.fi/~jpa/nanopb
+// Extensions: 1010 (all types)
+// --------------------------------
+
+extend google.protobuf.FileOptions {
+ optional NanoPBOptions nanopb_fileopt = 1010;
+}
+
+extend google.protobuf.MessageOptions {
+ optional NanoPBOptions nanopb_msgopt = 1010;
+}
+
+extend google.protobuf.EnumOptions {
+ optional NanoPBOptions nanopb_enumopt = 1010;
+}
+
+extend google.protobuf.FieldOptions {
+ optional NanoPBOptions nanopb = 1010;
+}
+
+