Skip to content

Commit

Permalink
Part of theheraldproject#113. Protobuf assessment.
Browse files Browse the repository at this point in the history
Signed off by: Adam Fowler <[email protected]>
  • Loading branch information
adamfowleruk committed Jan 15, 2023
1 parent 98592fb commit f9e05e3
Show file tree
Hide file tree
Showing 38 changed files with 7,957 additions and 262 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Output
*.a
**/.DS_Store
**/build*
*/.vscode/.cortex-debug.*.json
*/.vscode/.cortex-debug.*.json
/herald/protobuf/generated/*
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"editor.quickSuggestions": {
"other": true
},
"nrf-connect.topdir": "${nrf-connect.sdk:1.9.1}",
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:1.9.1}",
"workbench.colorTheme": "Bluloco Light"
"nrf-connect.topdir": "${nrf-connect.sdk:2.1.0-rc2}",
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:2.1.0-rc2}",
"workbench.colorTheme": "Default Dark+"
}
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

#IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
add_definitions(-DHERALD_LOG_LEVEL=4)
#ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)

# ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)

# Ensure we test our Herald String
add_definitions("-DCONFIG_HERALD_NO_STD_STRING")
add_definitions("-DCONFIG_HERALD_NO_STD_STREAMS")



include(GNUInstallDirs)

Expand Down
4 changes: 2 additions & 2 deletions herald-mesh-modem/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"includePath": [
"${default}",
"${workspaceFolder}/../herald/include",
"/opt/nordic/ncs/v1.9.1/zephyr/include"
"/opt/nordic/ncs/v2.0.2/zephyr/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "/opt/nordic/ncs/v1.9.1/toolchain/bin/arm-none-eabi-gcc",
"compilerPath": "/opt/nordic/ncs/toolchains/v2.0.2/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-arm",
Expand Down
2 changes: 1 addition & 1 deletion herald-mesh-modem/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"device": "NRF52832_XXAA",
"serverpath": "C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe",
// "armToolchainPath": "${config:armToolchainPath}/bin", // Only works if you have installed GNU Arm embeeded toolchain external to NCS
"armToolchainPath": "${env:ZEPHYR_BASE}/../toolchain/opt/bin", // Works if ZEPHYR_BASE set (which needs to be for our CMake to run)
"armToolchainPath": "/opt/nordic/ncs/toolchains/v2.0.2/opt/zephyr-sdk/arm-zephyr-eabi/bin", // Works if ZEPHYR_BASE set (which needs to be for our CMake to run)
"rttConfig": {
"enabled": true,
"address": "auto",
Expand Down
14 changes: 8 additions & 6 deletions herald-mesh-modem/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,21 @@
"cmake.configureEnvironment": {
// "BOARD": "nrf52dk_nrf52832"
// "BOARD": "nrf52833dk_nrf52833"
"BOARD": "nrf52840dk_nrf52840"
"BOARD": "nrf52840dk_nrf52840",
// "BOARD": "nrf5340dk_nrf5340_cpuapp"
// ,"HERALD_ANALYSIS_ENABLED":"y"
// ,"HERALD_ANALYSIS_ENABLED":"y",
"Zephyr-sdk_DIR": "${nrf-connect.toolchain:2.0.2}/cmake"
},
"kconfig.zephyr.base": "${ZEPHYR_BASE}",
"kconfig.zephyr.base": "${nrf-connect.sdk:2.0.2}/zephyr",
"nrf-connect.applications": [
"${workspaceFolder}"
],
"kconfig.zephyr.board": {
"board": "nrf52840dk_nrf52840",
"arch": "arm",
"dir": "${ZEPHYR_BASE}/boards/arm/nrf52840dk_nrf52840"
"dir": "${nrf-connect.sdk:2.0.2}/zephyr/boards/arm/nrf52840dk_nrf52840"
},
"nrf-connect.topdir": "${nrf-connect.sdk:1.9.1}",
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:1.9.1}"
"nrf-connect.topdir": "${nrf-connect.sdk:2.0.2}",
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:2.0.2}",
"cmake.configureOnOpen": true
}
75 changes: 49 additions & 26 deletions herald-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.12)

find_package(Protobuf REQUIRED)

add_executable(herald-tests
# Test templates
test-templates.h
Expand All @@ -10,28 +12,28 @@ add_executable(herald-tests
#codecoverage-tests.cpp

# base data types
# allocatablearray-tests.cpp
# bytearrayprinter-tests.cpp
# memoryarena-tests.cpp
datatypes-tests.cpp
# base64string-tests.cpp
hexstring-tests.cpp
# datetime-tests.cpp
randomuuid-tests.cpp
# uint8-tests.cpp
# uint16-tests.cpp
# uint32-tests.cpp
# uint64-tests.cpp
# sha256-tests.cpp
# distribution-tests.cpp
# # allocatablearray-tests.cpp
# # bytearrayprinter-tests.cpp
# # memoryarena-tests.cpp
# datatypes-tests.cpp
# # base64string-tests.cpp
# hexstring-tests.cpp
# # datetime-tests.cpp
# randomuuid-tests.cpp
# # uint8-tests.cpp
# # uint16-tests.cpp
# # uint32-tests.cpp
# # uint64-tests.cpp
# # sha256-tests.cpp
# # distribution-tests.cpp

# Low level
# sensorlogger-tests.cpp
# errorcontactlog-tests.cpp
data-tests.cpp
# datatypesdataderived-tests.cpp
# blemacaddress-tests.cpp
# targetidentifier-tests.cpp
# # sensorlogger-tests.cpp
# # errorcontactlog-tests.cpp
# data-tests.cpp
# # datatypesdataderived-tests.cpp
# # blemacaddress-tests.cpp
# # targetidentifier-tests.cpp

# Low level cross platform
test-util.cpp
Expand All @@ -50,10 +52,13 @@ add_executable(herald-tests
# gaussian-tests.cpp

# high level
# advertparser-tests.cpp
# bledatabase-tests.cpp
# blecoordinator-tests.cpp
coordinator-tests.cpp
# # advertparser-tests.cpp
# # bledatabase-tests.cpp
# # blecoordinator-tests.cpp
# coordinator-tests.cpp

# Bluetooth Mesh
mesh-tests.cpp

# App level
# nordicuart-tests.cpp
Expand All @@ -66,15 +71,33 @@ add_executable(herald-tests
main.cpp
)

include_directories(${herald_SOURCE_DIR})
include_directories(
${herald_SOURCE_DIR}
${PROTOBUF_INCLUDE_DIRS}
)

# target_include_directories(herald-tests
# PUBLIC
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# $<INSTALL_INTERFACE:include>
# ${PROTOBUF_INCLUDE_DIRS}
# )

# set(THREADS_PREFER_PTHREAD_FLAG ON)
# find_package(Threads REQUIRED)

# Do this if you want to test string_utils stdlib replacements
# add_definitions(-DCONFIG_HERALD_NO_STD_STRING=y)
target_link_libraries(herald-tests PRIVATE
herald
# ${PROTOBUF_LIBRARIES}
/usr/local/lib/libprotobuf.a

# pthread
# ${PROTOBUF_LITE_LIBRARIES}
) # Threads::Threads

target_link_libraries(herald-tests PRIVATE herald) # Threads::Threads
# ${PROTOBUF_LIBRARIES}
# target_code_coverage(herald-tests AUTO EXTERNAL EXCLUDE *-tests.cpp test-*.h *ain.cpp *est-util.cpp *est-templates.h *atch.hpp /usr/include/**/*) # EXCLUDE ONLY WORKS WITH PATTERNS

if (WIN32)
Expand Down
37 changes: 37 additions & 0 deletions herald-tests/mesh-tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 Herald Project Contributors
// SPDX-License-Identifier: Apache-2.0
//

#include "catch.hpp"
#include "herald/herald.h"

#include <google/protobuf/arena.h>

using namespace herald::mesh;
using namespace herald::mesh::messages;
using namespace herald::datatype;

// [Who] As a system administrator
// [What] I need to issue commands to MESH devices from a central location
// [Value] In order to easily administer a large mesh device network

TEST_CASE("mesh-hello-command", "[mesh][command][hello]") {
SECTION("mesh-hello-command") {
// Test default hello command execution
google::protobuf::Arena arena;
// Create hello message
Hello* hello = google::protobuf::Arena::CreateMessage<Hello>(&arena);
hello->set_commandid(1234);
// Serialise to binary
std::string output;
bool outOk = hello->SerializeToString(&output);
REQUIRE(true == outOk);
// Deserialise from binary
Hello* helloIn = google::protobuf::Arena::CreateMessage<Hello>(&arena);
bool inOk = helloIn->ParseFromString(output);
REQUIRE(true == inOk);
// Ensure new message is the same
REQUIRE(1234 == hello->commandid());
REQUIRE(1234 == helloIn->commandid());
}
}
4 changes: 2 additions & 2 deletions herald-tests/test-templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "herald/herald.h"

#include <iostream>
#include <cstdio>

class BlankDevice : public herald::Device {
public:
Expand Down Expand Up @@ -46,7 +46,7 @@ struct DummyLoggingSink {

void log(const herald::data::String& sub,const herald::data::String& cat,herald::data::SensorLoggerLevel level, const herald::data::String& message) {
value = sub + "," + cat + "," + message;
std::cout << "DummyLoggingSink::log: " << value << std::endl;
printf("DummyLoggingSink::log: %s\n",value.c_str());
subsystem = sub;
category = cat;
}
Expand Down
8 changes: 4 additions & 4 deletions herald-venue-beacon/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"xutility": "cpp"
},
"cmake.configureEnvironment": {
"BOARD": "nrf52dk_nrf52832"
// "BOARD": "nrf52dk_nrf52832"
// "BOARD": "nrf52833dk_nrf52833"
// "BOARD": "nrf52840dk_nrf52840"
// "BOARD": "nrf52840dongle_nrf52840" // Maker Diary nrf52840mdk-dongle
"BOARD": "nrf52840dongle_nrf52840" // Maker Diary nrf52840mdk-dongle
// "BOARD": "nrf5340dk_nrf5340_cpuapp"
},
"nrf-connect.topdir": "${nrf-connect.sdk:1.9.1}",
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:1.9.1}",
"nrf-connect.topdir": "${nrf-connect.sdk:2.0.2}",
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:2.0.2}",
"nrf-connect.applications": [
"${workspaceFolder}"
]
Expand Down
34 changes: 22 additions & 12 deletions herald/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(CMAKE_CXX_EXTENSIONS ON)
include(GNUInstallDirs
)

find_package(Protobuf REQUIRED)

set(HERALD_BASE .)
include(herald.cmake)

Expand All @@ -32,9 +34,11 @@ else()
endif()
endif()

add_library(herald
${HERALD_HEADERS}
add_library(herald
${HERALD_HEADERS}
${HERALD_HEADERS_MESH}
${HERALD_SOURCES}
${HERALD_SOURCES_MESH}
${PLATFORM_SOURCES}
)

Expand All @@ -44,14 +48,15 @@ endif()

set_target_properties(herald PROPERTIES PUBLIC_HEADER "${HERALD_HEADERS}")

target_include_directories(herald
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
target_include_directories(herald
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${PROTOBUF_INCLUDE_DIRS}
)

if (MSVC)
target_link_libraries(herald Crypt32.lib Bcrypt.lib)
target_link_libraries(herald Crypt32.lib Bcrypt.lib ${PROTOBUF_LITE_LIBRARIES})
endif()

if(HERALD_TARGET STREQUAL zephyr)
Expand All @@ -75,16 +80,21 @@ if(HERALD_TARGET STREQUAL zephyr)
#set(CMAKE_CXX_FLAGS ${Z_CFLAGS} ${CXXFLAGS})
endif()


#target_compile_features(herald PRIVATE cxx_std_17)

add_compile_options(-Wl,-Wno-unused-function)
# target_compile_features(herald PRIVATE cxx_std_17)
# add_compile_options(-Wl,-Wno-unused-function)
add_compile_options(-Wl)

if(NOT (MSVC OR (HERALD_TARGET STREQUAL zephyr)) )
# Use the DEV location (not system location) to pick up OpenSSL v3
# see .vscode/settings.json for CMake path overrides
find_package(OpenSSL 3.0.2 REQUIRED)
target_link_libraries(herald OpenSSL::Crypto)
target_link_libraries(herald PUBLIC
OpenSSL::Crypto
# pthread
# ${PROTOBUF_LITE_LIBRARIES}
/usr/local/lib/libprotobuf.a
# ${PROTOBUF_LIBRARIES}
)
endif()

install(TARGETS herald
Expand Down
Loading

0 comments on commit f9e05e3

Please sign in to comment.