diff --git a/.idea/cmake.xml b/.idea/cmake.xml
deleted file mode 100644
index 818adc3f..00000000
--- a/.idea/cmake.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index e69de29b..f6038816 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/elastic-ai.runtime.enV5.iml b/.idea/elastic-ai.runtime.enV5.iml
index 55d612b0..1d148b93 100644
--- a/.idea/elastic-ai.runtime.enV5.iml
+++ b/.idea/elastic-ai.runtime.enV5.iml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/Unit_Tests.xml b/.idea/runConfigurations/Unit_Tests.xml
index 0c3de4f4..b2220add 100644
--- a/.idea/runConfigurations/Unit_Tests.xml
+++ b/.idea/runConfigurations/Unit_Tests.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/.idea/runConfigurations/all.xml b/.idea/runConfigurations/all.xml
index 384bdc63..12ca77e4 100644
--- a/.idea/runConfigurations/all.xml
+++ b/.idea/runConfigurations/all.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 26c10bf3..d6b3bff4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,69 +1,52 @@
cmake_minimum_required(VERSION 3.20...3.24)
-include(helpers.cmake)
+
+include(cmake/set_build_target.cmake)
+
+
+include(cmake/third_party_deps.cmake)
+
+add_pico_sdk("2.0.0")
+add_unity()
+add_cexception()
+add_runtime_c()
+
+
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
-# enable debug prints
if (DEBUG_OUTPUT)
add_definitions(-DDEBUG_MODE)
endif ()
-if (UNIT_TEST)
- message(NOTICE "INFO: Building for local machine")
-else ()
- message(NOTICE "INFO: Building for enV5 hardware (Type: ${CMAKE_BUILD_TYPE})")
- setupPicoSdk("2.0.0")
+
+
+if(NOT BUILDING_FOR_ELASTIC_NODE)
+ add_compile_options(-ftrapv) # abort execution on integer overflow
endif ()
project(enV5 C CXX ASM)
+pico_sdk_init()
-# enable test execution via CMake
-include(CTest)
+include(cmake/custom_targets.cmake)
+include(cmake/pico_targets.cmake)
-# include unit-test framework
-add_unity()
+include(CTest)
-# include required standard libs for testing
-
-if(UNIT_TEST)
- add_runtime_c()
- add_cexception()
- add_subdirectory(src/common)
- add_subdirectory(src/network/atCommands)
- add_subdirectory(src/network/config)
-
- # include dummies for local machine
- add_subdirectory(test/unit/dummies)
-
- # include our own libraries to test
- add_subdirectory(src/hal/enV5HwConfiguration)
- add_subdirectory(src/sensor/sht3x)
- add_subdirectory(src/sensor/adxl345b)
- add_subdirectory(src/sensor/pac193x)
- add_subdirectory(src/network/wifi)
- add_subdirectory(src/network/http)
- add_subdirectory(src/network/broker)
- add_subdirectory(src/fpga/fpgaConfigurationHandler)
- add_subdirectory(src/filesystem)
-
- # include unit-tests
- add_subdirectory(test/unit)
-else ()
- pico_sdk_init()
-
- if (TARGET tinyusb_device)
- # include required libraries
- add_basic_functionality()
- add_freertos_kernel()
-
- add_rp2040_hal()
- add_sensor_libraries()
-
- # include hardware tests
- add_subdirectory(test/hardware)
-
- add_dependency_graph()
- elseif (PICO_ON_DEVICE)
- message(WARNING "Not building Project, because TinyUSB submodule is not initialized in the SDK!")
- endif ()
+add_subdirectory(src)
+add_subdirectory(test/unit)
+add_subdirectory(test/unit/Adxl345b)
+add_subdirectory(test/unit/Pac193x)
+add_subdirectory(test/unit/FpgaConfigurationHandler)
+add_subdirectory(test/unit/Http)
+add_subdirectory(test/unit/Network)
+add_subdirectory(test/unit/MqttBroker)
+add_subdirectory(test/unit/Sht3x)
+add_subdirectory(test/hardware)
+
+add_freertos()
+
+if(BUILDING_FOR_ELASTIC_NODE AND NOT TARGET tinyusb_device)
+ message(WARNING "not building project, because tinyusb not initialized")
+else()
endif ()
+
diff --git a/CMakePresets.json b/CMakePresets.json
new file mode 100644
index 00000000..57878cf5
--- /dev/null
+++ b/CMakePresets.json
@@ -0,0 +1,76 @@
+{
+ "version": 6,
+ "cmakeMinimumRequired": {
+ "major": 3,
+ "minor": 20,
+ "patch": 0
+ },
+ "configurePresets": [
+ {
+ "name": "host",
+ "displayName": "Host Config",
+ "description": "Build for your host system (MacOs, Linux, Windows)",
+ "generator": "Ninja",
+ "binaryDir": "build/host/",
+ "cacheVariables": {
+ "ELASTIC_AI_TARGET": "HOST",
+ "CMAKE_BUILD_TYPE": "Release"
+ }
+ },
+ {
+ "name": "env5_rev2",
+ "displayName": "EnV5 Rev2",
+ "generator": "Ninja",
+ "binaryDir": "build/env5_rev2",
+ "cacheVariables": {
+ "ELASTIC_AI_TARGET": "ENV5_REV2",
+ "CMAKE_BUILD_TYPE": "Release"
+ }
+ },
+ {
+ "name": "env5_rev2_debug",
+ "displayName": "EnV5 Rev2 Debug",
+ "generator": "Ninja",
+ "binaryDir": "build/env5_rev2_debug",
+ "cacheVariables": {
+ "ELASTIC_AI_TARGET": "ENV5_REV2",
+ "CMAKE_BUILD_TYPE": "Debug",
+ "DEBUG_MODE": "ON"
+ }
+ }
+ ],
+ "buildPresets": [
+ {
+ "name": "host",
+ "configurePreset": "host",
+ "jobs": 4
+ },
+ {
+ "name": "env5_rev2",
+ "configurePreset": "env5_rev2",
+ "jobs": 6
+ },
+ {
+ "name": "unit_test",
+ "inherits": "host",
+ "targets": "all_unit_tests"
+ }
+ ],
+ "testPresets": [
+ {
+ "name": "unit_test",
+ "displayName": "Unit Tests",
+ "configurePreset": "host",
+ "output": {
+ "outputJUnitFile": "unit-test.junit",
+ "outputOnFailure": true
+ },
+ "filter": {
+ "include": {
+ "label": "unit"
+ }
+ }
+
+ }
+ ]
+}
\ No newline at end of file
diff --git a/cmake/Readme.adoc b/cmake/Readme.adoc
new file mode 100644
index 00000000..c6ca532c
--- /dev/null
+++ b/cmake/Readme.adoc
@@ -0,0 +1,49 @@
+== Cmake Scripts
+
+=== Encapsulated Libraries
+
+We want to have the following goals
+
+- fine-grained control over dependencies for flexibility and to facilitate link-time substitution
+- prevent access to header files of transitive dependencies, i.e., if you call a function defined in `libB` you have to explicitly depend on it. There should not be a way to include a header provided by `B` without declaring that explicit dependency. This way, we avoid hidden source code dependencies. And each module only sees the header files it actually needs.
+- for convenience, we want to have a target combines implementation and headers.
+
+We achieve these by (typically) defining four build targets for each of our modules. Assuming we want to define a new library `A` that performs a direct call to library `B`. Then we define
+
+`A__hdrs`:: providing access to all public header files of our module `A`, e.g.,
++
+[source, cmake]
+----
+add_library(A__hdrs INTERFACE)
+target_include_directories(A__hdrs INTERFACE include)
+----
+`A__impl`:: containing the implementation of `A`. This target needs access to the headers of its dependent modules, e.g.,
++
+[source, cmake]
+----
+add_library(A__impl A.c)
+target_link_libraries(A__impl PRIVATE B__hdrs)
+----
++
+`A`:: providing access to public headers for consuming targets (e.g., executables) and transitively providing dependent library implementations
+[source, cmake]
+----
+add_library(A INTERFACE)
+target_link_libraries(A INTERFACE A__impl A__hdrs)
+----
+
+Currently, the `elastic_ai_add_library` function provides most of this functionality. However, using it will prevent the IDE from automatically discovering your targets for the sake of jump-to-definition and auto-completion.
+
+=== Building HW Dependent Libs
+The build scripts will set a global variable `BUILDING_FOR_ELASTIC_NODE` to `true` iff we're building for an elastic node hardware.
+If you need to define a HW dependent lib, e.g., because it calls into the pico_sdk, you should ask for that flag and define the `__impl` as an empty interface target. E.g.,
+
+[source, cmake]
+----
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(A__impl A.c)
+ target_link_libraries(A__impl PRIVATE Pico::pico_runtime__hdrs)
+else()
+ add_library(A__impl INTERFACE)
+endif ()
+----
diff --git a/cmake/custom_targets.cmake b/cmake/custom_targets.cmake
index ddd84a40..ee732b6b 100644
--- a/cmake/custom_targets.cmake
+++ b/cmake/custom_targets.cmake
@@ -1,84 +1,14 @@
-################
-# Functions in here are supposed to help keeping consistent naming scheme and package structure
-# for different cmake targets.
-################
-
-function(elastic_ai_lib)
- # Takes the following parameters:
- #
- # NAME: the name of your library (withstand the urge to use 'lib' as a suffix!)
- # SOURCES: all the *.c files that need to be compiled for this library
- # DEPS: all libaries, that the current library depends on. These need to be specified via
- # the elastic_ai_lib function as well.
- #
- # We assume that public headers live inside an `include` directory in the package.
- #
- #
- # Will generate several different library targets:
- # 1. __hdrs : a pure INTERFACE library containing only the public headers of this
- # module. These hdr only libs will be automatically linked when defining a new lib that depends
- # on the current one.
- # 2. __nodeps : a library that contains the implementation in addition to 1, linking against all
- # all hdr libs of the specified dependencies.
- # 3. : a library carrying all transitive dependencies.
- #
- # If you need to link a lib A against a library B that was not defined as an elastic_ai_lib
- # you will want to do it like this in most cases:
- #
- # elastic_ai(NAME A SOURCES A.c)
- # target_link_libraries(A PRIVATE B)
- # target_include_directories(A__nodeps PRIVATE get_property(TARGET B INTERFACE_INCLUDE_DIRECTORY))
- set(oneValueArgs NAME)
- set(multiValueArgs SOURCES DEPS)
- cmake_parse_arguments(PARSE_ARGV 0 arg
- "${options}" "${oneValueArgs}" "${multiValueArgs}"
- )
- if(NOT ${arg_DEPS})
- set(arg_DEPS "")
- endif ()
- add_library(${arg_NAME}__hdrs INTERFACE)
- target_include_directories(${arg_NAME}__hdrs INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-
- add_library(${arg_NAME}__nodeps ${arg_SOURCES})
- target_include_directories(${arg_NAME}__nodeps PRIVATE ${CMAKE_CURRENT_LIST_DIR})
- set(hdrLibs "")
- foreach (lib ${DEPS})
- list(APPEND hdrLibs ${lib}__hdrs)
- endforeach ()
- target_link_libraries(${arg_NAME}__nodeps PUBLIC ${arg_NAME}__hdrs)
- target_link_libraries(${arg_NAME}__nodeps PRIVATE ${hdrLibs})
-
- add_library(${arg_NAME} INTERFACE)
- target_link_libraries(${arg_NAME} INTERFACE ${arg_NAME}__nodeps ${DEPS})
-endfunction()
-
-
-function(elastic_ai_unit_test)
- # Similar to elastic_ai_lib but defines a new unit test.
- # You only need to specify the LIB_UNDER_TEST.
- # The function will automatically try to compile a file with the same name, but
- # the prefix `Unittest` and link against the nodeps version of LIB_UNDER_TEST.
- # For flexibility you can specify additional libraries (MORE_LIBS) and
- # sources (MORE_SOURCES).
- set(oneValueArgs LIB_UNDER_TEST)
- set(multiValueArgs MORE_SOURCES MORE_LIBS)
- cmake_parse_arguments(PARSE_ARGV 0 arg
- "${options}" "${oneValueArgs}" "${multiValueArgs}"
- )
- if(NOT ${arg_MORE_SOURCES})
- set(arg__MORE_SOURCES "")
- endif ()
-
- if(NOT ${arg_MORE_LIBS})
- set(arg_MORE_LIBS "")
- endif ()
-
- if (NOT ${arg_DEPS})
- set(arg_DEPS "")
- endif ()
- add_executable(unit-test_${arg_LIB_UNDER_TEST} Unittest${arg_LIB_UNDER_TEST}.c)
- target_sources(unit-test_${arg_LIB_UNDER_TEST} PRIVATE ${arg_MORE_SOURCES})
- target_link_libraries(unit-test_${arg_LIB_UNDER_TEST} ${arg_LIB_UNDER_TEST}__nodeps unity)
- add_test(unit-test_${arg_LIB_UNDER_TEST} unit-test_${arg_LIB_UNDER_TEST})
- target_link_libraries(unit-test_${arg_LIB_UNDER_TEST} ${arg_MORE_LIBS})
-endfunction()
+function(create_enV5_executable target)
+ # enable usb output
+ pico_enable_stdio_usb(${target} 1)
+ # disable uart output
+ pico_enable_stdio_uart(${target} 0)
+ # create map/bin/hex/uf2 file etc.
+ pico_add_uf2_output(${target})
+ # # copy u2f files after build to out directory
+ # file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
+ # add_custom_command(TARGET ${target} POST_BUILD
+ # COMMAND ${CMAKE_COMMAND} -E copy
+ # ${CMAKE_BINARY_DIR}/${relative_path}/${target}.uf2
+ # ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}-Rev${REVISION}/${relative_path}/${target}.uf2)
+endfunction()
\ No newline at end of file
diff --git a/cmake/env5.cmake b/cmake/env5.cmake
new file mode 100644
index 00000000..fddd0ecc
--- /dev/null
+++ b/cmake/env5.cmake
@@ -0,0 +1,10 @@
+message("Building for env5")
+set(BUILDING_FOR_ELASTIC_NODE ON CACHE INTERNAL "we're building for elastic node")
+set(PICO_BOARD none)
+set(PICO_PLATFORM rp2040)
+
+if(${ELASTIC_AI_TARGET} EQUAL ENV5_REV1)
+ set(REVISION "1" CACHE INTERNAL "")
+else()
+ set(REVISION "2" CACHE INTERNAL "")
+endif ()
\ No newline at end of file
diff --git a/cmake/host.cmake b/cmake/host.cmake
new file mode 100644
index 00000000..5137714d
--- /dev/null
+++ b/cmake/host.cmake
@@ -0,0 +1,5 @@
+message("building for native host platform")
+set(BUILDING_FOR_ELASTIC_NODE OFF CACHE INTERNAL "we're building for elastic node")
+set(PICO_BOARD none)
+set(PICO_PLATFORM host)
+set(REVISION "1" CACHE INTERNAL "")
diff --git a/cmake/no_elastic_node.cmake b/cmake/no_elastic_node.cmake
new file mode 100644
index 00000000..a4d53763
--- /dev/null
+++ b/cmake/no_elastic_node.cmake
@@ -0,0 +1 @@
+set(NOT_ELASTIC_NODE INTERNAL "1" "we're not building for elastic node, but for the dev systems")
\ No newline at end of file
diff --git a/cmake/pico_sdk_import.cmake b/cmake/pico_sdk_import.cmake
new file mode 100644
index 00000000..087d4ce5
--- /dev/null
+++ b/cmake/pico_sdk_import.cmake
@@ -0,0 +1,86 @@
+# This is a copy of /external/pico_sdk_import.cmake
+
+# This can be dropped into an external project to help locate this SDK
+# It should be include()ed prior to project()
+
+if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
+ set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
+ message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
+endif ()
+
+if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
+ set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
+ message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
+endif ()
+
+if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
+ set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
+ message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
+endif ()
+
+if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
+ set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
+ message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
+endif ()
+
+if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
+ set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
+ message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
+endif()
+
+set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
+set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
+set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
+set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
+
+if (NOT PICO_SDK_PATH)
+ if (PICO_SDK_FETCH_FROM_GIT)
+ include(FetchContent)
+ set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
+ if (PICO_SDK_FETCH_FROM_GIT_PATH)
+ get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
+ endif ()
+ # GIT_SUBMODULES_RECURSE was added in 3.17
+ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
+ FetchContent_Declare(
+ pico_sdk
+ GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
+ GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
+ GIT_SUBMODULES_RECURSE FALSE
+ OVERRIDE_FIND_PACKAGE
+ )
+ else ()
+ FetchContent_Declare(
+ pico_sdk
+ GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
+ GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
+ OVERRIDE_FIND_PACKAGE
+ )
+ endif ()
+
+ if (NOT pico_sdk)
+ message("Downloading Raspberry Pi Pico SDK")
+ FetchContent_Populate(pico_sdk)
+ set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
+ endif ()
+ set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
+ else ()
+ message(FATAL_ERROR
+ "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
+ )
+ endif ()
+endif ()
+
+get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
+if (NOT EXISTS ${PICO_SDK_PATH})
+ message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
+endif ()
+
+set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
+if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
+ message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
+endif ()
+
+set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
+
+include(${PICO_SDK_INIT_CMAKE_FILE})
diff --git a/cmake/pico_targets.cmake b/cmake/pico_targets.cmake
new file mode 100644
index 00000000..f6925e4a
--- /dev/null
+++ b/cmake/pico_targets.cmake
@@ -0,0 +1,37 @@
+# expose the pico targets by creating aliases that match our naming scheme
+
+function(__add_pico_lib original)
+ if(NOT BUILDING_FOR_ELASTIC_NODE)
+ if(NOT TARGET pico_empty_lib)
+ add_library(pico_empty_lib INTERFACE)
+ endif ()
+ add_library(Pico::${original} ALIAS pico_empty_lib)
+ else ()
+ add_library(Pico::${original} ALIAS ${original})
+ endif ()
+endfunction()
+
+
+foreach (arg
+ pico_runtime
+ pico_util
+ pico_platform
+ pico_clib_interface
+ pico_time
+ pico_stdlib
+ pico_stdio
+ pico_bootrom
+ pico_stdio_usb
+ pico_sync
+ hardware_gpio
+ hardware_i2c
+ hardware_spi
+ hardware_timer
+ hardware_rtc
+ hardware_uart
+ hardware_irq
+ hardware_base
+ hardware_watchdog
+)
+ __add_pico_lib(${arg})
+endforeach ()
diff --git a/cmake/set_build_target.cmake b/cmake/set_build_target.cmake
new file mode 100644
index 00000000..b210c2e7
--- /dev/null
+++ b/cmake/set_build_target.cmake
@@ -0,0 +1,9 @@
+set(AVAILABLE_TARGETS HOST ENV5_REV1 ENV5_REV2)
+
+if(NOT (ELASTIC_AI_TARGET IN_LIST AVAILABLE_TARGETS))
+ message(FATAL_ERROR "You have to specify -DELASTIC_AI_TARGET= with being one of ${AVAILABLE_TARGETS}")
+elseif (${ELASTIC_AI_TARGET} STREQUAL HOST)
+ include(${CMAKE_CURRENT_LIST_DIR}/host.cmake)
+else ()
+ include(${CMAKE_CURRENT_LIST_DIR}/env5.cmake)
+endif ()
diff --git a/cmake/third_party_deps.cmake b/cmake/third_party_deps.cmake
new file mode 100644
index 00000000..8db6d14d
--- /dev/null
+++ b/cmake/third_party_deps.cmake
@@ -0,0 +1,102 @@
+include(FetchContent)
+
+
+# include pico-sdk
+macro(add_pico_sdk tag)
+ set(PICO_SDK_FETCH_FROM_GIT on)
+ set(PICO_SDK_FETCH_FROM_GIT_TAG ${tag})
+ set(PICOTOOL_FETCH_FROM_GIT_PATH ${CMAKE_SOURCE_DIR}/picotool)
+ include(pico_sdk_import.cmake)
+endmacro()
+
+
+function(add_cexception)
+ FetchContent_Declare(
+ cexception
+ GIT_REPOSITORY https://github.com/ThrowTheSwitch/CException.git
+ GIT_TAG v1.3.3
+ )
+ FetchContent_Populate(cexception)
+ add_library(CException__impl ${cexception_SOURCE_DIR}/lib/CException.c)
+ add_library(CException__hdrs INTERFACE)
+ target_include_directories(CException__hdrs INTERFACE ${cexception_SOURCE_DIR}/lib/)
+ add_library(CException INTERFACE)
+ target_link_libraries(CException INTERFACE CException__hdrs CException__impl)
+endfunction()
+
+function(add_unity)
+FetchContent_Declare(
+ unity
+ GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
+ GIT_TAG v2.5.2
+ OVERRIDE_FIND_PACKAGE
+)
+FetchContent_MakeAvailable(unity)
+ find_package(unity)
+endfunction()
+
+function(add_runtime_c)
+ FetchContent_Declare(
+ elastic_ai_runtime_c
+ GIT_REPOSITORY https://github.com/es-ude/elastic-ai.runtime.c.git
+ GIT_TAG v2.7.2
+ )
+ FetchContent_MakeAvailable(elastic_ai_runtime_c)
+ if (NOT topicMatcher__hdrs)
+ add_library( topicMatcher__hdrs INTERFACE)
+ target_include_directories(topicMatcher__hdrs INTERFACE
+ $
+ )
+ endif ()
+
+ if (NOT protocol__hdrs)
+ add_library( protocol__hdrs INTERFACE)
+ target_include_directories(protocol__hdrs INTERFACE
+ $
+ )
+ endif ()
+
+ function(make_impl target)
+ if (NOT TARGET ${target}__impl)
+ add_library(${target}__impl INTERFACE)
+ target_link_libraries(${target}__impl INTERFACE
+ ${target}
+ )
+ endif ()
+ endfunction()
+
+ make_impl(protocol)
+ make_impl(topicMatcher)
+ add_library(RuntimeC::Protocol ALIAS protocol__impl)
+ add_library(RuntimeC::Protocol__impl ALIAS protocol__impl)
+ add_library(RuntimeC::Protocol__hdrs ALIAS protocol__hdrs)
+ add_library(RuntimeC::TopicMatcher ALIAS topicMatcher__impl)
+ add_library(RuntimeC::TopicMatcher__hdrs ALIAS topicMatcher__hdrs)
+ add_library(RuntimeC::TopicMatcher__impl ALIAS topicMatcher__impl)
+endfunction()
+
+function(add_freertos)
+FetchContent_Declare(
+ freertos_kernel
+ GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
+ GIT_TAG V11.0.1
+)
+FetchContent_Populate(freertos_kernel)
+add_subdirectory(${freertos_kernel_SOURCE_DIR}/portable/ThirdParty/GCC/RP2040 FREERTOS_KERNEL)
+
+add_library(__freertos_kernel__hdrs INTERFACE)
+target_include_directories(__freertos_kernel__hdrs INTERFACE $)
+add_library(freeRtos::FreeRTOS-Kernel__hdrs ALIAS __freertos_kernel__hdrs)
+
+add_library(freeRtos::FreeRTOS-Kernel ALIAS FreeRTOS-Kernel)
+add_library(freeRtos::FreeRTOS-Kernel__impl ALIAS FreeRTOS-Kernel)
+
+
+add_library(__freertos_kernel_heap__hdrs INTERFACE)
+target_include_directories(__freertos_kernel_heap__hdrs INTERFACE $)
+add_library(freeRtos::FreeRTOS-Kernel-Heap3__hdrs ALIAS __freertos_kernel_heap__hdrs)
+
+add_library(freeRtos::FreeRTOS-Kernel-Heap3 ALIAS FreeRTOS-Kernel-Heap3)
+add_library(freeRtos::FreeRTOS-Kernel-Heap3__impl ALIAS FreeRTOS-Kernel-Heap3)
+endfunction()
+
diff --git a/enV5_init.cmake b/enV5_init.cmake
deleted file mode 100644
index 0e7724f3..00000000
--- a/enV5_init.cmake
+++ /dev/null
@@ -1,27 +0,0 @@
-include(${CMAKE_CURRENT_LIST_DIR}/helpers.cmake)
-
-function(enV5_init_unit_tests)
- # include unit-test framework
- add_unity()
-
- # include required standard libs for testing
- add_cexception()
- add_runtime_c()
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/common)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/network/atCommands)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/network/config)
-
- # include dummies for local machine
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/test/unit/dummies)
-endfunction()
-
-function(enV5_init)
- # include basic functionality for enV5
- add_basic_functionality()
-
- # add HAL for enV5
- add_rp2040_hal()
-
- # provide access to additional sensor libraries
- add_sensor_libraries()
-endfunction()
diff --git a/helpers.cmake b/helpers.cmake
deleted file mode 100644
index ca239e6a..00000000
--- a/helpers.cmake
+++ /dev/null
@@ -1,122 +0,0 @@
-include(FetchContent)
-
-macro(setupPicoSdk TAG)
- # include pico-sdk
- set(PICO_SDK_FETCH_FROM_GIT on)
- set(PICO_SDK_FETCH_FROM_GIT_TAG ${TAG})
- set(PICO_BOARD none)
- set(PICO_PLATFORM rp2040)
- set(PICOTOOL_FETCH_FROM_GIT_PATH ${CMAKE_SOURCE_DIR}/picotool)
- include(pico_sdk_import.cmake)
-endmacro()
-
-
-function(add_cexception)
- FetchContent_Declare(
- cexception
- GIT_REPOSITORY https://github.com/ThrowTheSwitch/CException.git
- GIT_TAG v1.3.3
- )
- FetchContent_Populate(cexception)
-
- add_library(CException INTERFACE)
- target_sources(CException INTERFACE ${cexception_SOURCE_DIR}/lib/CException.c)
- target_include_directories(CException INTERFACE ${cexception_SOURCE_DIR}/lib)
-endfunction()
-
-function(add_unity)
- FetchContent_Declare(
- unity
- GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
- GIT_TAG v2.5.2
- )
- FetchContent_Populate(unity)
-
- add_subdirectory(${unity_SOURCE_DIR})
-endfunction()
-
-function(add_runtime_c)
- FetchContent_Declare(
- elastic_ai_runtime_c
- GIT_REPOSITORY https://github.com/es-ude/elastic-ai.runtime.c.git
- GIT_TAG v2.7.2
- )
- FetchContent_Populate(elastic_ai_runtime_c)
-
- add_subdirectory(${elastic_ai_runtime_c_SOURCE_DIR})
-endfunction()
-
-function(add_freertos_kernel)
- FetchContent_Declare(
- freertos_kernel
- GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
- GIT_TAG V11.0.1
- )
- FetchContent_Populate(freertos_kernel)
-
- add_subdirectory(${freertos_kernel_SOURCE_DIR}/portable/ThirdParty/GCC/RP2040 FREERTOS_KERNEL)
-endfunction()
-
-function(add_rp2040_hal)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/hal)
-endfunction()
-
-function(add_basic_functionality)
- add_cexception()
- add_runtime_c()
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/common)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/rtos)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/network)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/flash)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/fpga)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/filesystem)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/usb_protocol)
-endfunction()
-
-function(add_sensor_libraries)
- add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/sensor)
-endfunction()
-
-function(create_enV5_executable target)
- # enable usb output
- pico_enable_stdio_usb(${target} 1)
- # disable uart output
- pico_enable_stdio_uart(${target} 0)
- # create map/bin/hex/uf2 file etc.
- pico_add_uf2_output(${target})
- # # copy u2f files after build to out directory
- # file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
- # add_custom_command(TARGET ${target} POST_BUILD
- # COMMAND ${CMAKE_COMMAND} -E copy
- # ${CMAKE_BINARY_DIR}/${relative_path}/${target}.uf2
- # ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}-Rev${REVISION}/${relative_path}/${target}.uf2)
-endfunction()
-
-function(add_dependency_graph)
- file(WRITE "${CMAKE_BINARY_DIR}/CMakeGraphVizOptions.cmake" "set(GRAPHVIZ_GENERATE_PER_TARGET FALSE)
- set(GRAPHVIZ_GENERATE_DEPENDERS FALSE)
- set(GRAPHVIZ_IGNORE_TARGETS
- \"Pioasm;ELF2UF2;cyw43.*;m;stub_*;cybt.*;cmsis.*;boot_.*;bs2_default.*;.*marker.*;hardware-test_*\")")
- file(WRITE "${CMAKE_BINARY_DIR}/test.sh" "
- perl -i -0pe 's/digraph[^}]*/START_REPLACEMENT/' enV5.dot
- perl -pi -e 's/.*\"[^\\\/\\\/\\n]*//g' enV5.dot
- perl -pi -e 's/\\\/\\\/ //g' enV5.dot
- perl -pi -e 's/[^ ]*(pico|hardware_|tinyusb)[^ \\n]*/pico_stdlib/g' enV5.dot
- perl -pi -e 's/FreeRTOS-Kernel[^ \\n]*/FreeRTOS_Kernel/g' enV5.dot
- perl -pi -e 's/\\\./_/g' enV5.dot
- perl -pi -e 's/->/ARROW_REPLECEMNT/g' enV5.dot
- perl -pi -e 's/-/_/g' enV5.dot
- perl -pi -e 's/ARROW_REPLECEMNT/->/g' enV5.dot
- perl -pi -e 's/node \\\[/digraph \"enV5\" {node [/g' enV5.dot
- perl -pi -e 's/pico_stdlib -> pico_stdlib//' enV5.dot
- perl -pi -e 's/FreeRTOS_Kernel -> FreeRTOS_Kernel//' enV5.dot
- perl -pi -e 's/START_REPLACEMENT}/strict digraph \"enV5\" {/' enV5.dot"
- )
- add_custom_target(graphviz ALL
- COMMAND ${CMAKE_COMMAND} "--graphviz=enV5.dot" .
- COMMAND bash test.sh
- COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_SOURCE_DIR}/documentation/pics"
- COMMAND dot -T png enV5.dot -o "${CMAKE_SOURCE_DIR}/documentation/pics/dependencies.png"
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
- )
-endfunction()
diff --git a/python_utils/elasticai/runtime/env5/usb/communication_base_protocol.py b/python_utils/elasticai/runtime/env5/usb/communication_base_protocol.py
index f30f60a6..f202fd37 100644
--- a/python_utils/elasticai/runtime/env5/usb/communication_base_protocol.py
+++ b/python_utils/elasticai/runtime/env5/usb/communication_base_protocol.py
@@ -178,13 +178,13 @@ def _receive(self) -> tuple[int, bytes]:
# calculate checksum on message
calculated_checksum = self.calculate_checksum(message)
-
+ self.logger.debug(f"received message {message}")
+ self.logger.debug(f"checksum {transmitted_checksum}")
if transmitted_checksum != calculated_checksum:
self.logger.debug("checksum wrong")
# If checksum not correct empty buffer and sent nack
- while self.serial.readable():
- self.serial.reset_input_buffer() # This might be problematic for timing. Maybe move it to other space
- time.sleep(0.1)
+ time.sleep(0.1)
+
self._send_nack()
else:
self.logger.debug("checksum correct")
diff --git a/python_utils/elasticai/runtime/env5/usb/test/test_user_remote_control.py b/python_utils/elasticai/runtime/env5/usb/test/test_user_remote_control.py
index 9eae1292..8f0d1fb1 100644
--- a/python_utils/elasticai/runtime/env5/usb/test/test_user_remote_control.py
+++ b/python_utils/elasticai/runtime/env5/usb/test/test_user_remote_control.py
@@ -1,4 +1,6 @@
+import logging
from pathlib import Path
+from sys import stdout
from serial import Serial
from serial.tools import list_ports
@@ -10,14 +12,16 @@
)
def get_pico_port():
- for c in list_ports.comports():
+ port_infos = list_ports.comports()
+ for c in port_infos:
if c.vid == 0x2e8a and c.pid == 0x000A:
return c.device
+ raise Exception(f"no port found in {[(c.device, c.name, c.vid, c.pid) for c in port_infos]}")
def test_user_remote_control():
-
- serial_port = get_pico_port()
+ serial_port = "/dev/cu.usbmodem101"
+ print(f"using port {serial_port}")
with Serial(serial_port) as serial_con:
echoserver_path = Path(echo_server[0])
@@ -27,7 +31,7 @@ def test_user_remote_control():
with open(echoserver_path, 'rb') as f:
echoserver_file = f.read()
binfile_address = 0
-
+ urcp.mcu_leds(False, True, False)
urcp.send_data_to_flash(binfile_address, echoserver_file)
data = b'\xDE\xAD\xBE\xEF'
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 00000000..769d5079
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_subdirectory(common)
+add_subdirectory(hal)
+add_subdirectory(flash)
+add_subdirectory(network)
+add_subdirectory(rtos)
+add_subdirectory(fpga)
+
+add_subdirectory(filesystem)
+add_subdirectory(usb_protocol)
+add_subdirectory(sensor)
\ No newline at end of file
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index ae0899cd..f3e84464 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -1,5 +1,10 @@
## provides helper macros to improve
## - print output
-add_library(common_lib INTERFACE)
-target_include_directories(common_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
+add_library(Common__hdrs INTERFACE)
+target_include_directories(Common__hdrs INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
+add_library(Common INTERFACE)
+target_link_libraries(Common INTERFACE Common__hdrs)
+if (DEBUG_MODE)
+ target_compile_definitions(Common__hdrs INTERFACE DEBUG_MODE=true)
+endif ()
diff --git a/src/filesystem/CMakeLists.txt b/src/filesystem/CMakeLists.txt
index 0838b717..4288fe1d 100644
--- a/src/filesystem/CMakeLists.txt
+++ b/src/filesystem/CMakeLists.txt
@@ -1,9 +1,6 @@
-add_library(filesystem_lib INTERFACE
- FileSystem.c)
-target_sources(filesystem_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/FileSystem.c)
-target_include_directories(filesystem_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_link_libraries(filesystem_lib INTERFACE
- common_lib
- spi_interface)
-
+add_library(FileSystem FileSystem.c)
+target_include_directories(FileSystem PUBLIC include)
+target_link_libraries(FileSystem PRIVATE
+ Common
+ Flash
+)
\ No newline at end of file
diff --git a/src/filesystem/FileSystem.c b/src/filesystem/FileSystem.c
index c147a93f..59d19a1e 100644
--- a/src/filesystem/FileSystem.c
+++ b/src/filesystem/FileSystem.c
@@ -5,7 +5,7 @@
#include "FileSystemInternal.h"
#include "Flash.h"
#include "math.h"
-#include "middleware.h"
+/*#include "middleware.h"*/
#include
#include
diff --git a/src/flash/CMakeLists.txt b/src/flash/CMakeLists.txt
index 37052c41..ba80fad9 100644
--- a/src/flash/CMakeLists.txt
+++ b/src/flash/CMakeLists.txt
@@ -1,7 +1,4 @@
-add_library(flash_lib INTERFACE)
-target_include_directories(flash_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(flash_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Flash.c)
-target_link_libraries(flash_lib INTERFACE
- common_lib
- spi_interface)
+add_library(Flash Flash.c)
+target_include_directories(Flash PUBLIC include)
+target_link_libraries(Flash PRIVATE Common Sleep)
+target_link_libraries(Flash PUBLIC Spi)
diff --git a/src/flash/Flash.c b/src/flash/Flash.c
index 4dc6bd29..373f39c6 100644
--- a/src/flash/Flash.c
+++ b/src/flash/Flash.c
@@ -12,12 +12,12 @@
#include
#include "Common.h"
-#include "Flash.h"
#include "FlashInternal.h"
-#include "FlashTypedefs.h"
#include "Sleep.h"
#include "Spi.h"
#include "SpiTypedefs.h"
+#include "include/Flash.h"
+#include "include/FlashTypedefs.h"
/* region PUBLIC HEADER FUNCTIONS */
void flashInit(flashConfiguration_t *flashConfig) {
diff --git a/src/fpga/CMakeLists.txt b/src/fpga/CMakeLists.txt
index 7363ee50..5a0d0ebd 100644
--- a/src/fpga/CMakeLists.txt
+++ b/src/fpga/CMakeLists.txt
@@ -1,3 +1,4 @@
add_subdirectory(fpgaConfigurationHandler)
add_subdirectory(middleware)
add_subdirectory(stub)
+
diff --git a/src/fpga/fpgaConfigurationHandler/CMakeLists.txt b/src/fpga/fpgaConfigurationHandler/CMakeLists.txt
index fb27d8ef..b5c52306 100644
--- a/src/fpga/fpgaConfigurationHandler/CMakeLists.txt
+++ b/src/fpga/fpgaConfigurationHandler/CMakeLists.txt
@@ -1,15 +1,34 @@
-add_library(fpga_configuration_handler INTERFACE)
-target_include_directories(fpga_configuration_handler INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(fpga_configuration_handler INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/FpgaConfigurationHandler.c
- ${CMAKE_CURRENT_LIST_DIR}/FpgaConfigurationHandlerHTTP.c
- ${CMAKE_CURRENT_LIST_DIR}/FpgaConfigurationHandlerUSB.c)
-target_link_libraries(fpga_configuration_handler INTERFACE
- common_lib
- pico_stdio
- flash_lib
- middleware_lib
- network_lib
- http_lib
- enV5_hw_configuration
+add_library(FpgaConfigurationHandler
+ FpgaConfigurationHandler.c
+ FpgaConfigurationHandlerHTTP.c
)
+
+target_include_directories(
+ FpgaConfigurationHandler
+ PUBLIC
+ include
+)
+
+
+target_link_libraries(FpgaConfigurationHandler PRIVATE
+ Common
+ Http
+ CException
+ EnV5HwConfiguration
+ Flash)
+
+
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(FpgaConfigurationHandlerUSB FpgaConfigurationHandlerUSB.c)
+ target_link_libraries(FpgaConfigurationHandlerUSB PRIVATE
+ Common
+ Http
+ CException
+ EnV5HwConfiguration
+ Flash
+ Pico::pico_stdio
+ Pico::pico_stdlib
+ Pico::pico_stdio_usb
+ FpgaConfigurationHandler
+ )
+endif ()
\ No newline at end of file
diff --git a/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandler.c b/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandler.c
index bf2a36fa..4b80b0fa 100644
--- a/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandler.c
+++ b/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandler.c
@@ -1,7 +1,5 @@
#define SOURCE_FILE "FPGA-CONFIGRATION-HANDLER-BASE"
-#include "FpgaConfigurationHandler.h"
-#include "Flash.h"
-#include "middleware.h"
+#include "include/FpgaConfigurationHandler.h"
void fpgaConfigurationHandlerInitialize() {}
diff --git a/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandlerHTTP.c b/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandlerHTTP.c
index a608fe4e..8e6652df 100644
--- a/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandlerHTTP.c
+++ b/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandlerHTTP.c
@@ -8,11 +8,10 @@
#include "CException.h"
#include "Common.h"
-#include "EnV5HwConfiguration.h"
#include "Flash.h"
-#include "FpgaConfigurationHandler.h"
#include "FpgaConfigurationHandlerInternal.h"
#include "HTTP.h"
+#include "include/FpgaConfigurationHandler.h"
/* region PUBLIC FUNCTION IMPLEMENTATIONS */
diff --git a/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandlerInternal.h b/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandlerInternal.h
index ac26fb0a..a0a3274e 100644
--- a/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandlerInternal.h
+++ b/src/fpga/fpgaConfigurationHandler/FpgaConfigurationHandlerInternal.h
@@ -3,8 +3,8 @@
#include
-#include "FpgaConfigurationHandler.h"
#include "HTTP.h"
+#include "include/FpgaConfigurationHandler.h"
/* region HTTP */
diff --git a/src/fpga/middleware/CMakeLists.txt b/src/fpga/middleware/CMakeLists.txt
index 34071f06..34a4cb96 100644
--- a/src/fpga/middleware/CMakeLists.txt
+++ b/src/fpga/middleware/CMakeLists.txt
@@ -1,9 +1,6 @@
-add_library(middleware_lib INTERFACE)
-target_include_directories(middleware_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(middleware_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/middleware.c)
-target_link_libraries(middleware_lib INTERFACE
- common_lib
- qxi_interface
- gpio_interface
- enV5_hw_controller)
+add_library(
+ Middleware middleware.c
+)
+target_include_directories(Middleware PUBLIC include)
+
+target_link_libraries(Middleware PRIVATE Common Qxi Gpio EnV5HwController)
\ No newline at end of file
diff --git a/src/fpga/stub/CMakeLists.txt b/src/fpga/stub/CMakeLists.txt
index 1660b803..3faa9c34 100644
--- a/src/fpga/stub/CMakeLists.txt
+++ b/src/fpga/stub/CMakeLists.txt
@@ -1,34 +1,7 @@
-## GENERIC STUB
-add_library(stub_lib INTERFACE)
-target_include_directories(stub_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(stub_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/stub.c)
-target_link_libraries(stub_lib INTERFACE
- common_lib
- sleep_interface
- middleware_lib)
+set(MIDDLEWARE_STUB_VERSION CACHE STRING "1" "use stub version 1, compatible with skeleton version 1")
+set(MIDDLEWARE_STUB_VERSION CACHE STRING "2" "use stub version 2, compatible with skeleton version 2")
-## STUB FOR SKELETON V1
-add_library(stub_v1_lib INTERFACE)
-target_include_directories(stub_v1_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/include
- ${CMAKE_CURRENT_LIST_DIR}/include_v1)
-target_sources(stub_v1_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/stub.c)
-target_link_libraries(stub_v1_lib INTERFACE
- common_lib
- sleep_interface
- middleware_lib)
-## STUB FOR SKELETON V2
-add_library(stub_v2_lib INTERFACE)
-target_include_directories(stub_v2_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/include
- ${CMAKE_CURRENT_LIST_DIR}/include_v2)
-target_sources(stub_v2_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/stub.c)
-target_link_libraries(stub_v2_lib INTERFACE
- common_lib
- sleep_interface
- middleware_lib)
+add_library(Stub stub.c)
+target_include_directories(Stub PUBLIC include include_v2)
+target_link_libraries(Stub Common Sleep Middleware)
\ No newline at end of file
diff --git a/src/hal/enV5HwConfiguration/CMakeLists.txt b/src/hal/enV5HwConfiguration/CMakeLists.txt
index 83550a32..a227a761 100644
--- a/src/hal/enV5HwConfiguration/CMakeLists.txt
+++ b/src/hal/enV5HwConfiguration/CMakeLists.txt
@@ -1,21 +1,21 @@
-add_library(enV5_hw_configuration INTERFACE
- revision01/EnV5HwConfiguration.h
- revision02/EnV5HwConfiguration.h)
-set(REVISION_FILEPATH ${REVISION} CACHE FILEPATH "Helpervariable needed for casting" FORCE)
+add_library(EnV5HwConfiguration INTERFACE)
+
+set(REVISION_FILEPATH ${REVISION} CACHE FILEPATH "Helper variable needed for casting" FORCE)
if(NOT DEFINED REVISION)
message(FATAL_ERROR "Missing hardware configuration")
elseif(${REVISION} STREQUAL "1")
- target_include_directories(enV5_hw_configuration INTERFACE ${CMAKE_CURRENT_LIST_DIR}/revision01)
+ target_include_directories(EnV5HwConfiguration INTERFACE ${CMAKE_CURRENT_LIST_DIR}/revision01)
elseif (${REVISION} STREQUAL "2")
- target_include_directories(enV5_hw_configuration INTERFACE ${CMAKE_CURRENT_LIST_DIR}/revision02)
+ target_include_directories(EnV5HwConfiguration INTERFACE ${CMAKE_CURRENT_LIST_DIR}/revision02)
elseif (IS_ABSOLUTE ${REVISION_FILEPATH})
if(${REVISION_FILEPATH} MATCHES "\\/EnV5HwConfiguration\\.h$")
- target_include_directories(enV5_hw_configuration INTERFACE REVISION_FILEPATH)
+ target_include_directories(EnV5HwConfiguration INTERFACE REVISION_FILEPATH)
else ()
message(FATAL_ERROR "Provided file needs to be named EnV5HwConfiguration.h: ${REVISION_FILEPATH}")
endif()
else()
message(FATAL_ERROR "Error in hardware configuration: ${REVISION}")
endif ()
+
diff --git a/src/hal/enV5HwController/CMakeLists.txt b/src/hal/enV5HwController/CMakeLists.txt
index 3bb23020..14b7b4cb 100644
--- a/src/hal/enV5HwController/CMakeLists.txt
+++ b/src/hal/enV5HwController/CMakeLists.txt
@@ -1,18 +1,14 @@
-add_library(enV5_hw_controller INTERFACE)
-target_include_directories(enV5_hw_controller INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(enV5_hw_controller INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/EnV5HwController.c
-)
-target_link_libraries(enV5_hw_controller INTERFACE
- common_lib
- enV5_hw_configuration
- gpio_interface
- i2c_interface
- spi_interface
- uart_interface
- sleep_interface
- flash_lib
- sensor_lib_adxl345b
- sensor_lib_pac193x
- sensor_lib_sht3x
-)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(EnV5HwController EnV5HwController.c)
+ target_include_directories(EnV5HwController PUBLIC include)
+ target_link_libraries(EnV5HwController PRIVATE
+ Common
+ EnV5HwConfiguration
+ Gpio
+ Sleep
+ )
+else()
+ add_library(EnV5HwController INTERFACE)
+ target_include_directories(EnV5HwController INTERFACE include)
+endif ()
+
diff --git a/src/hal/enV5HwController/EnV5HwController.c b/src/hal/enV5HwController/EnV5HwController.c
index c9d0c43d..1e8275fc 100644
--- a/src/hal/enV5HwController/EnV5HwController.c
+++ b/src/hal/enV5HwController/EnV5HwController.c
@@ -12,6 +12,8 @@ void env5HwControllerInit() {
env5HwControllerLedsInit();
env5HwControllerFpgaInit();
env5HwControllerFpgaPowersOff();
+
+ PRINT_DEBUG("enV5 Controller initialized.\n");
}
/* region LED */
diff --git a/src/hal/gpio/CMakeLists.txt b/src/hal/gpio/CMakeLists.txt
index 1b6c63b8..59f1f5b6 100644
--- a/src/hal/gpio/CMakeLists.txt
+++ b/src/hal/gpio/CMakeLists.txt
@@ -1,9 +1,10 @@
# Provides a Facade for the pico-sdk GPIO library
-add_library(gpio_interface INTERFACE)
-target_include_directories(gpio_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(gpio_interface INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Gpio.c)
-target_link_libraries(gpio_interface INTERFACE
- common_lib
- hardware_gpio)
+if (BUILDING_FOR_ELASTIC_NODE)
+ add_library(Gpio Gpio.c)
+ target_link_libraries(Gpio PRIVATE Common Pico::hardware_gpio Pico::pico_runtime)
+ target_include_directories(Gpio PUBLIC include)
+else ()
+ add_library(Gpio INTERFACE)
+ target_include_directories(Gpio INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/src/hal/gpio/Gpio.c b/src/hal/gpio/Gpio.c
index ed796d61..173a0cb1 100644
--- a/src/hal/gpio/Gpio.c
+++ b/src/hal/gpio/Gpio.c
@@ -1,8 +1,8 @@
#define SOURCE_FILE "GPIO-LIB"
-#include "Gpio.h"
+#include "include/Gpio.h"
-#include
+#include "hardware/gpio.h"
gpioErrorCode_t gpioInitPin(gpioPin_t pin, gpioDirection_t direction) {
gpio_init(pin);
diff --git a/src/hal/i2c/CMakeLists.txt b/src/hal/i2c/CMakeLists.txt
index 7e57f895..a64970fa 100644
--- a/src/hal/i2c/CMakeLists.txt
+++ b/src/hal/i2c/CMakeLists.txt
@@ -1,11 +1,10 @@
# Provides a Facade for the pico-sdk I2C library
-add_library(i2c_interface INTERFACE)
-target_include_directories(i2c_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(i2c_interface INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/I2c.c)
-target_link_libraries(i2c_interface INTERFACE
- common_lib
- gpio_interface
- hardware_i2c
-)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(I2c I2c.c)
+ target_link_libraries(I2c PRIVATE Common Gpio Pico::hardware_i2c Pico::pico_runtime)
+ target_include_directories(I2c PUBLIC include)
+else()
+ add_library(I2c INTERFACE)
+ target_include_directories(I2c INTERFACE include)
+endif ()
diff --git a/src/hal/i2c/I2c.c b/src/hal/i2c/I2c.c
index eadc74eb..cbc2571e 100644
--- a/src/hal/i2c/I2c.c
+++ b/src/hal/i2c/I2c.c
@@ -1,4 +1,4 @@
-#include "I2c.h"
+#include "include/I2c.h"
#include "Common.h"
#include "Gpio.h"
#include "I2cInternal.h"
diff --git a/src/hal/qxspi/CMakeLists.txt b/src/hal/qxspi/CMakeLists.txt
index 7c6a5a83..e96c1eb9 100644
--- a/src/hal/qxspi/CMakeLists.txt
+++ b/src/hal/qxspi/CMakeLists.txt
@@ -1,11 +1,12 @@
# Provides a Facade for the SPI library
# Placeholder -> Should later be replaced by real Quad SPI implementation
-add_library(qxi_interface INTERFACE)
-target_include_directories(qxi_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(qxi_interface INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Qxi.c)
-target_link_libraries(qxi_interface INTERFACE
- gpio_interface
- spi_interface
- hardware_spi)
\ No newline at end of file
+if (BUILDING_FOR_ELASTIC_NODE)
+ add_library(Qxi Qxi.c)
+ target_include_directories(Qxi PUBLIC include)
+ target_link_libraries(Qxi PRIVATE Gpio Spi)
+ target_link_libraries(Qxi PUBLIC Pico::hardware_spi Pico::pico_runtime )
+else ()
+ add_library(Qxi INTERFACE)
+ target_link_libraries(Qxi INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/src/hal/sleep/CMakeLists.txt b/src/hal/sleep/CMakeLists.txt
index 5b53383d..bf105a63 100644
--- a/src/hal/sleep/CMakeLists.txt
+++ b/src/hal/sleep/CMakeLists.txt
@@ -1,8 +1,14 @@
# Provides a Facade for the pico-sdk Time Library
-add_library(sleep_interface INTERFACE)
-target_sources(sleep_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Sleep.c)
-target_include_directories(sleep_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_link_libraries(sleep_interface INTERFACE
- common_lib
- pico_time)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(Sleep Sleep.c)
+ target_include_directories(Sleep PUBLIC include)
+ target_link_libraries(Sleep PRIVATE
+ Common
+ Pico::pico_time
+ Pico::pico_runtime
+ )
+else()
+ add_library(Sleep INTERFACE)
+ target_include_directories(Sleep INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/src/hal/spi/CMakeLists.txt b/src/hal/spi/CMakeLists.txt
index e0ad61c9..e543896a 100644
--- a/src/hal/spi/CMakeLists.txt
+++ b/src/hal/spi/CMakeLists.txt
@@ -1,10 +1,15 @@
# Provides a Facade for the pico-sdk SPI library
-add_library(spi_interface INTERFACE)
-target_include_directories(spi_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(spi_interface INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Spi.c)
-target_link_libraries(spi_interface INTERFACE
- common_lib
- gpio_interface
- hardware_spi)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(Spi Spi.c)
+ target_include_directories(Spi PUBLIC include)
+ target_link_libraries(Spi PRIVATE
+ Common
+ Gpio
+ Pico::hardware_spi
+ Pico::pico_runtime
+ )
+else()
+ add_library(Spi INTERFACE)
+ target_include_directories(Spi INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/src/hal/time/CMakeLists.txt b/src/hal/time/CMakeLists.txt
index 4ae1ac94..6ee03d05 100644
--- a/src/hal/time/CMakeLists.txt
+++ b/src/hal/time/CMakeLists.txt
@@ -1,11 +1,13 @@
-add_library(time_interface STATIC
- ${CMAKE_CURRENT_LIST_DIR}/Time.c
-)
-target_include_directories(time_interface PUBLIC
- ${CMAKE_CURRENT_LIST_DIR}/include
-)
-target_link_libraries(time_interface PRIVATE
- common_lib
- hardware_timer
- pico_runtime
-)
\ No newline at end of file
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(Time Time.c)
+
+ # IMPORTANT: This is an interface include because some host platforms are case insensitive
+ # (MacOS). On these we would include Time.h and pico sdk, which is linked as interface libs
+ # will include time.h. Due to case insensitivity pico would include our header instead of the
+ # pico one.
+ target_include_directories(Time INTERFACE include)
+ target_link_libraries(Time PRIVATE Common Pico::pico_time Pico::hardware_timer Pico::pico_runtime)
+else()
+ add_library(Time INTERFACE)
+ target_include_directories(Time INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/src/hal/time/Time.c b/src/hal/time/Time.c
index acd0e748..d8d5c0ba 100644
--- a/src/hal/time/Time.c
+++ b/src/hal/time/Time.c
@@ -4,7 +4,10 @@
#include "hardware/timer.h"
-#include "Time.h"
+/* IMPORTANT: We include as `include/Time.h` to avoid conflict with the pico `time.h`
+ * header on case-insensitive platforms (e.g., MacOS).
+ */
+#include "include/hal/Time.h"
uint64_t timeUs64(void) {
return time_us_64();
diff --git a/src/hal/uart/CMakeLists.txt b/src/hal/uart/CMakeLists.txt
index e7ee16ec..29e23831 100644
--- a/src/hal/uart/CMakeLists.txt
+++ b/src/hal/uart/CMakeLists.txt
@@ -1,9 +1,13 @@
-add_library(uart_interface INTERFACE)
-target_include_directories(uart_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(uart_interface INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Uart.c)
-target_link_libraries(uart_interface INTERFACE
- common_lib
- gpio_interface
- hardware_uart
- hardware_irq)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(Uart Uart.c)
+ target_include_directories(Uart PUBLIC include)
+ target_link_libraries(Uart PRIVATE
+ Common Gpio Pico::hardware_uart
+ Pico::hardware_irq
+ Pico::pico_runtime
+ EnV5HwConfiguration
+ )
+else()
+ add_library(Uart INTERFACE)
+ target_include_directories(Uart INTERFACE include)
+endif ()
diff --git a/src/hal/uart/Uart.c b/src/hal/uart/Uart.c
index df885664..fc78ef75 100644
--- a/src/hal/uart/Uart.c
+++ b/src/hal/uart/Uart.c
@@ -5,6 +5,7 @@
#include "Gpio.h"
#include "UartInternal.h"
+#include "EnV5HwConfiguration.h"
#include "hardware/irq.h"
#include "hardware/uart.h"
@@ -40,6 +41,7 @@ void uartInit(uartConfiguration_t *uartConfig) {
// Set up our UART with requested baud rate.
// The call will return the actual baud rate selected,
// which will be as close as possible to that requested
+ uartConfig->uartInstance = UART_MODULE;
uart_init(uartConfig->uartInstance, uartConfig->baudrate);
// Set UART flow control CTS/RTS, we don't want these, so turn them off
diff --git a/src/hal/uart/include/Uart.h b/src/hal/uart/include/Uart.h
index d585083c..ed6423ee 100644
--- a/src/hal/uart/include/Uart.h
+++ b/src/hal/uart/include/Uart.h
@@ -10,6 +10,7 @@ typedef struct uart_inst uart_inst_t;
typedef unsigned int uint;
enum uartParity { NoneParity = 0, OddParity = 1, EvenParity = 2 };
+
typedef enum uartParity uartParity_t;
//! We highly recommend using the "enV5_hw_configuration_rev_[x]" -library
diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt
index e9d4c83f..ab1de521 100644
--- a/src/network/CMakeLists.txt
+++ b/src/network/CMakeLists.txt
@@ -1,6 +1,6 @@
add_subdirectory(config)
add_subdirectory(atCommands)
add_subdirectory(esp)
-add_subdirectory(wifi)
add_subdirectory(http)
+add_subdirectory(wifi)
add_subdirectory(broker)
diff --git a/src/network/atCommands/CMakeLists.txt b/src/network/atCommands/CMakeLists.txt
index 17ffeb16..efb1062e 100644
--- a/src/network/atCommands/CMakeLists.txt
+++ b/src/network/atCommands/CMakeLists.txt
@@ -1,2 +1,2 @@
-add_library(at_commands INTERFACE)
-target_include_directories(at_commands INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
+add_library(AtCommands INTERFACE)
+target_include_directories(AtCommands INTERFACE include)
diff --git a/src/network/broker/CMakeLists.txt b/src/network/broker/CMakeLists.txt
index d96663c2..2e46dc45 100644
--- a/src/network/broker/CMakeLists.txt
+++ b/src/network/broker/CMakeLists.txt
@@ -1,16 +1,19 @@
-add_library(espBroker_lib INTERFACE)
-target_include_directories(espBroker_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(espBroker_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/MqttBroker.c)
-target_link_libraries(espBroker_lib INTERFACE
+add_library(MqttBroker MqttBroker.c)
+target_include_directories(MqttBroker PUBLIC include)
+target_link_libraries(MqttBroker PRIVATE
+ Common
+ Uart
+ AtCommands
+ Esp
+ Network
CException
- topicMatcher
- protocol
- common_lib
- uart_interface
- at_commands
- esp_lib
- network_lib
- m
- network_config)
+ RuntimeC::TopicMatcher
+ RuntimeC::Protocol
+)
+
+target_include_directories(MqttBroker PRIVATE
+ $)
+
+target_include_directories(MqttBroker PUBLIC
+ $
+)
diff --git a/src/network/broker/MqttBroker.c b/src/network/broker/MqttBroker.c
index 38d078df..094b3312 100644
--- a/src/network/broker/MqttBroker.c
+++ b/src/network/broker/MqttBroker.c
@@ -8,8 +8,8 @@
#include "CException.h"
#include "Common.h"
#include "Esp.h"
-#include "MqttBroker.h"
#include "MqttBrokerInternal.h"
+#include "include/MqttBroker.h"
// header from elastic-ai.runtime.c
#include "CommunicationEndpoint.h"
diff --git a/src/network/config/CMakeLists.txt b/src/network/config/CMakeLists.txt
index 4e2656bf..448aae83 100644
--- a/src/network/config/CMakeLists.txt
+++ b/src/network/config/CMakeLists.txt
@@ -7,9 +7,5 @@ mqttBrokerHost_t mqttHost = {.ip = \"0.0.0.0\", .port = \"1883\", .userID = \"\"
")
endif ()
-add_library(network_config INTERFACE)
-target_sources(network_config INTERFACE
- ${CMAKE_SOURCE_DIR}/NetworkConfig.c)
-target_link_libraries(network_config INTERFACE
- espBroker_lib
- network_lib)
+add_library(NetworkConfig ${CMAKE_SOURCE_DIR}/NetworkConfig.c)
+target_link_libraries(NetworkConfig PRIVATE MqttBroker Network)
diff --git a/src/network/esp/CMakeLists.txt b/src/network/esp/CMakeLists.txt
index 0b84ea07..e5be35eb 100644
--- a/src/network/esp/CMakeLists.txt
+++ b/src/network/esp/CMakeLists.txt
@@ -1,13 +1,20 @@
-add_library(esp_lib INTERFACE)
-target_include_directories(esp_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(esp_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Esp.c)
-target_link_libraries(esp_lib INTERFACE
- freeRtosUtils
- common_lib
- uart_interface
- at_commands
- enV5_hw_controller
- network_config
- hardware_uart
-)
\ No newline at end of file
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(Esp Esp.c)
+ target_include_directories(Esp PUBLIC include)
+ target_link_libraries(Esp PRIVATE
+ AtCommands
+ Common
+ EnV5HwConfiguration
+ freeRtosUtils
+ Uart
+ Sleep
+ Pico::pico_time
+ Pico::hardware_uart
+ Pico::pico_runtime
+
+
+ )
+else()
+ add_library(Esp INTERFACE)
+ target_include_directories(Esp INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/src/network/esp/Esp.c b/src/network/esp/Esp.c
index 0be12e7c..dc6b8a7c 100644
--- a/src/network/esp/Esp.c
+++ b/src/network/esp/Esp.c
@@ -1,16 +1,17 @@
#define SOURCE_FILE "ESP"
-#include
-
-#include "hardware/uart.h"
-
+#include "Esp.h"
#include "AtCommands.h"
#include "Common.h"
#include "EnV5HwConfiguration.h"
-#include "Esp.h"
#include "EspInternal.h"
#include "FreeRtosTaskWrapper.h"
+#include "Sleep.h"
#include "Uart.h"
+#include
+
+#include "hardware/uart.h"
+#include "pico/time.h"
/* region VARIABLES */
@@ -90,7 +91,9 @@ espErrorCode_t espSendCommand(char *cmd, char *expectedResponse, int timeoutMs)
// check for response
bool responseArrived = false;
+
freeRtosTaskWrapperTaskSleep(REFRESH_RESPOND_IN_MS / 2);
+
for (int delay = 0; delay < timeoutMs; delay += REFRESH_RESPOND_IN_MS) {
responseArrived = uartCorrectResponseArrived();
if (responseArrived) {
diff --git a/src/network/http/CMakeLists.txt b/src/network/http/CMakeLists.txt
index ce936380..0e76fc79 100644
--- a/src/network/http/CMakeLists.txt
+++ b/src/network/http/CMakeLists.txt
@@ -1,9 +1,3 @@
-add_library(http_lib INTERFACE)
-target_include_directories(http_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(http_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/HTTP.c)
-target_link_libraries(http_lib INTERFACE
- CException
- common_lib
- at_commands
- esp_lib)
+add_library(Http HTTP.c)
+target_include_directories(Http PUBLIC include)
+target_link_libraries(Http PRIVATE Common CException AtCommands Esp)
diff --git a/src/network/http/HTTP.c b/src/network/http/HTTP.c
index 9f08b122..a460d3e8 100644
--- a/src/network/http/HTTP.c
+++ b/src/network/http/HTTP.c
@@ -8,7 +8,7 @@
#include "AtCommands.h"
#include "Common.h"
#include "Esp.h"
-#include "HTTP.h"
+#include "include/HTTP.h"
HttpResponse_t *HTTPResponse = NULL;
volatile uint32_t httpCount = 0;
diff --git a/src/network/wifi/CMakeLists.txt b/src/network/wifi/CMakeLists.txt
index 954c0d72..db214b69 100644
--- a/src/network/wifi/CMakeLists.txt
+++ b/src/network/wifi/CMakeLists.txt
@@ -1,12 +1,12 @@
-add_library(network_lib INTERFACE)
-target_include_directories(network_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(network_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Network.c)
-target_link_libraries(network_lib INTERFACE
+
+add_library(Network Network.c)
+target_include_directories(Network PUBLIC include)
+target_link_libraries(Network PRIVATE
freeRtosUtils
- common_lib
- uart_interface
- at_commands
- esp_lib
- http_lib
- network_config)
+ Common
+ Uart
+ Esp
+ Http
+ NetworkConfig
+ AtCommands
+)
diff --git a/src/network/wifi/Network.c b/src/network/wifi/Network.c
index afffb61e..d7de9f83 100644
--- a/src/network/wifi/Network.c
+++ b/src/network/wifi/Network.c
@@ -8,7 +8,7 @@
#include "Esp.h"
#include "FreeRtosTaskWrapper.h"
#include "HTTP.h"
-#include "Network.h"
+#include "include/Network.h"
extern networkCredentials_t networkCredentials;
diff --git a/src/rtos/CMakeLists.txt b/src/rtos/CMakeLists.txt
index 3e8ba5aa..2c637646 100644
--- a/src/rtos/CMakeLists.txt
+++ b/src/rtos/CMakeLists.txt
@@ -1,12 +1,15 @@
-add_library(freeRtosUtils INTERFACE)
-target_include_directories(freeRtosUtils INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(freeRtosUtils INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/FreeRtosSMP.c
- ${CMAKE_CURRENT_LIST_DIR}/FreeRtosTaskWrapper.c
- ${CMAKE_CURRENT_LIST_DIR}/FreeRtosQueueWrapper.c
- ${CMAKE_CURRENT_LIST_DIR}/FreeRtosMutexWrapper.c)
-target_link_libraries(freeRtosUtils INTERFACE
- FreeRTOS-Kernel
- FreeRTOS-Kernel-Heap3
- common_lib
- sleep_interface)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(freeRtosUtils FreeRtosTaskWrapper.c FreeRtosSMP.c FreeRtosQueueWrapper.c FreeRtosMutexWrapper.c)
+ target_include_directories(freeRtosUtils PUBLIC include)
+ target_link_libraries(freeRtosUtils PRIVATE
+ Common
+ Sleep
+ Pico::pico_bootrom
+ Pico::pico_stdlib
+ Pico::hardware_base
+ freeRtos::FreeRTOS-Kernel
+ freeRtos::FreeRTOS-Kernel-Heap3)
+else()
+ add_library(freeRtosUtils INTERFACE)
+ target_include_directories(freeRtosUtils INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/src/rtos/FreeRtosMutexWrapper.c b/src/rtos/FreeRtosMutexWrapper.c
index 680748cb..6d57451e 100644
--- a/src/rtos/FreeRtosMutexWrapper.c
+++ b/src/rtos/FreeRtosMutexWrapper.c
@@ -1,9 +1,10 @@
-#include
-
-#include "Common.h"
#include "FreeRtosMutexWrapper.h"
+#include "Common.h"
+#include "FreeRTOS.h"
#include "FreeRtosTaskWrapper.h"
+#include
+
mutex_t freeRtosMutexWrapperCreate(void) {
mutex_t mutex = xSemaphoreCreateMutex();
if (NULL == mutex) {
diff --git a/src/rtos/FreeRtosTaskWrapper.c b/src/rtos/FreeRtosTaskWrapper.c
index 5636e5e9..5e0ecf93 100644
--- a/src/rtos/FreeRtosTaskWrapper.c
+++ b/src/rtos/FreeRtosTaskWrapper.c
@@ -33,6 +33,7 @@ void freeRtosTaskWrapperRegisterTask(TaskCodeFunc taskCode, const char *taskName
void freeRtosTaskWrapperTaskSleep(int timeInMs) {
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
sleep_for_ms(timeInMs);
+
} else {
// vTaskDelay does not support delaying less than typically 10ms
if (timeInMs < 10) {
diff --git a/src/sensor/adxl345b/Adxl345b.c b/src/sensor/adxl345b/Adxl345b.c
index adc09ee6..e74ec077 100644
--- a/src/sensor/adxl345b/Adxl345b.c
+++ b/src/sensor/adxl345b/Adxl345b.c
@@ -1,12 +1,12 @@
#define SOURCE_FILE "ADXL345B-LIB"
-#include "Adxl345b.h"
+#include "include/Adxl345b.h"
#include "Adxl345bInternal.h"
-#include "Adxl345bTypedefs.h"
#include "Common.h"
#include "I2c.h"
#include "Sleep.h"
#include "Time.h"
+#include "include/Adxl345bTypedefs.h"
/* region CONSTANTS */
diff --git a/src/sensor/adxl345b/Adxl345bInternal.h b/src/sensor/adxl345b/Adxl345bInternal.h
index bb9245ba..b8130c78 100644
--- a/src/sensor/adxl345b/Adxl345bInternal.h
+++ b/src/sensor/adxl345b/Adxl345bInternal.h
@@ -11,7 +11,7 @@
* Activity \b detection -> Can not be used due to unconnected interrupt pins\n
*/
-#include "Adxl345bTypedefs.h"
+#include "include/Adxl345bTypedefs.h"
#include
typedef struct adxl345bRangeSetting {
diff --git a/src/sensor/adxl345b/CMakeLists.txt b/src/sensor/adxl345b/CMakeLists.txt
index 257c919a..74d18898 100644
--- a/src/sensor/adxl345b/CMakeLists.txt
+++ b/src/sensor/adxl345b/CMakeLists.txt
@@ -1,19 +1,3 @@
-add_library(sensor_lib_adxl345b INTERFACE)
-target_include_directories(sensor_lib_adxl345b INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(sensor_lib_adxl345b INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Adxl345b.c)
-target_link_libraries(sensor_lib_adxl345b INTERFACE
- common_lib
- sleep_interface
- time_interface
- i2c_interface
-)
-
-add_library(sensor_lib_adxl345b__srcs STATIC )
-target_sources(sensor_lib_adxl345b__srcs PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Adxl345b.c)
-target_include_directories(sensor_lib_adxl345b__srcs PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
-target_include_directories(sensor_lib_adxl345b__srcs PRIVATE
- ${CMAKE_SOURCE_DIR}/src/hal/i2c/include
- ${CMAKE_SOURCE_DIR}/src/hal/sleep/include
- ${CMAKE_SOURCE_DIR}/src/hal/time/include
- ${CMAKE_SOURCE_DIR}/src/common/include)
+add_library(Adxl345b Adxl345b.c)
+target_include_directories(Adxl345b PUBLIC include)
+target_link_libraries(Adxl345b PRIVATE Common Sleep Time I2c)
diff --git a/src/sensor/bmi323/Bmi323.c b/src/sensor/bmi323/Bmi323.c
index e97832d6..6fc807dd 100644
--- a/src/sensor/bmi323/Bmi323.c
+++ b/src/sensor/bmi323/Bmi323.c
@@ -9,11 +9,11 @@
#include "CException.h"
-#include "Bmi323.h"
#include "Common.h"
#include "Sleep.h"
#include "Spi.h"
#include "SpiTypedefs.h"
+#include "include/Bmi323.h"
#include "bmi3.h"
#include "bmi323.h"
diff --git a/src/sensor/bmi323/CMakeLists.txt b/src/sensor/bmi323/CMakeLists.txt
index 48216fa7..0fb4bdf6 100644
--- a/src/sensor/bmi323/CMakeLists.txt
+++ b/src/sensor/bmi323/CMakeLists.txt
@@ -7,21 +7,30 @@ FetchContent_Declare(
)
FetchContent_Populate(bmi323)
-add_library(sensor_lib_bmi323 STATIC
+add_library(external_bmi323_bosch_lib
"${bmi323_SOURCE_DIR}/bmi3.c"
- "${bmi323_SOURCE_DIR}/bmi323.c"
- "${CMAKE_CURRENT_LIST_DIR}/Bmi323.c"
-)
-target_include_directories(sensor_lib_bmi323 PUBLIC
- "${bmi323_SOURCE_DIR}"
- "${CMAKE_CURRENT_LIST_DIR}/include"
-)
-target_link_libraries(sensor_lib_bmi323 PUBLIC
- pico_stdlib
- CException
-)
-target_link_libraries(sensor_lib_bmi323 PRIVATE
- sleep_interface
- gpio_interface
- spi_interface
-)
+ "${bmi323_SOURCE_DIR}/bmi323.c")
+
+target_include_directories(external_bmi323_bosch_lib PUBLIC "${bmi323_SOURCE_DIR}")
+
+
+
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(Bmi323 Bmi323.c)
+ target_include_directories(Bmi323 PUBLIC include)
+ target_link_libraries(Bmi323 PRIVATE
+ external_bmi323_bosch_lib
+ Common
+ Pico::pico_stdlib
+ CException
+ Sleep
+ Gpio
+ Spi
+ )
+else()
+ add_library(Bmi323 INTERFACE)
+ target_include_directories(Bmi323 INTERFACE include)
+endif ()
+
+target_link_libraries(Bmi323 INTERFACE external_bmi323_bosch_lib)
+
diff --git a/src/sensor/pac193x/CMakeLists.txt b/src/sensor/pac193x/CMakeLists.txt
index 25e8b081..bbdf8a08 100644
--- a/src/sensor/pac193x/CMakeLists.txt
+++ b/src/sensor/pac193x/CMakeLists.txt
@@ -1,9 +1,3 @@
-add_library(sensor_lib_pac193x INTERFACE)
-target_include_directories(sensor_lib_pac193x INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(sensor_lib_pac193x INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Pac193x.c)
-target_link_libraries(sensor_lib_pac193x INTERFACE
- common_lib
- sleep_interface
- gpio_interface
- i2c_interface)
+add_library(Pac193x Pac193x.c)
+target_include_directories(Pac193x PUBLIC include)
+target_link_libraries(Pac193x PRIVATE Common Sleep Gpio I2c)
diff --git a/src/sensor/pac193x/Pac193x.c b/src/sensor/pac193x/Pac193x.c
index 9582d09f..c71f7a51 100644
--- a/src/sensor/pac193x/Pac193x.c
+++ b/src/sensor/pac193x/Pac193x.c
@@ -6,10 +6,10 @@
#include "Common.h"
#include "Gpio.h"
#include "I2c.h"
-#include "Pac193x.h"
#include "Pac193xInternal.h"
-#include "Pac193xTypedefs.h"
#include "Sleep.h"
+#include "include/Pac193x.h"
+#include "include/Pac193xTypedefs.h"
/* Datasheet:
* https://ww1.microchip.com/downloads/en/DeviceDoc/PAC1931-Family-Data-Sheet-DS20005850E.pdf
diff --git a/src/sensor/sht3x/CMakeLists.txt b/src/sensor/sht3x/CMakeLists.txt
index 6379c50f..09cd8160 100644
--- a/src/sensor/sht3x/CMakeLists.txt
+++ b/src/sensor/sht3x/CMakeLists.txt
@@ -1,14 +1,3 @@
-add_library(sensor_lib_sht3x STATIC
- ${CMAKE_CURRENT_LIST_DIR}/Sht3x.c
-)
-target_include_directories(sensor_lib_sht3x PUBLIC
- ${CMAKE_CURRENT_LIST_DIR}/include
-)
-target_link_libraries(sensor_lib_sht3x PUBLIC
- pico_stdlib
- CException
-)
-target_link_libraries(sensor_lib_sht3x PRIVATE
- common_lib
- i2c_interface
-)
+add_library(Sht3x Sht3x.c)
+target_include_directories(Sht3x PUBLIC include)
+target_link_libraries(Sht3x PRIVATE Common CException I2c)
diff --git a/src/sensor/sht3x/Sht3x.c b/src/sensor/sht3x/Sht3x.c
index 0c121035..c40dc123 100644
--- a/src/sensor/sht3x/Sht3x.c
+++ b/src/sensor/sht3x/Sht3x.c
@@ -4,9 +4,9 @@
#include "Common.h"
#include "I2c.h"
-#include "Sht3x.h"
#include "Sht3xInternal.h"
-#include "Sht3xTypedefs.h"
+#include "include/Sht3x.h"
+#include "include/Sht3xTypedefs.h"
const uint16_t sht3xCrc8Polynomial = 0x31; //!< P(x) = x^8 + x^5 + x^4 + 1 = 0b00110001 = 0x31
const float sht3xDenominator = (1 << 16) - 1.0f; //!< 2^16 - 1 = 0b1111111111111111 = 0xFFFF
diff --git a/src/sensor/sht3x/Sht3xInternal.h b/src/sensor/sht3x/Sht3xInternal.h
index 02c55dd7..78fef80d 100644
--- a/src/sensor/sht3x/Sht3xInternal.h
+++ b/src/sensor/sht3x/Sht3xInternal.h
@@ -3,7 +3,7 @@
#include
-#include "Sht3xTypedefs.h"
+#include "include/Sht3xTypedefs.h"
/* region CONSTANTS */
diff --git a/src/usb_protocol/CMakeLists.txt b/src/usb_protocol/CMakeLists.txt
index 49f6d81b..46eef3bf 100644
--- a/src/usb_protocol/CMakeLists.txt
+++ b/src/usb_protocol/CMakeLists.txt
@@ -1,24 +1,18 @@
-add_library(usb-protocol STATIC
- ${CMAKE_CURRENT_LIST_DIR}/Protocol.c
- ${CMAKE_CURRENT_LIST_DIR}/DefaultCommands.c
- ${CMAKE_CURRENT_LIST_DIR}/Tools.c
-)
-target_include_directories(usb-protocol PUBLIC
- ${CMAKE_CURRENT_LIST_DIR}/include
-)
-target_link_directories(usb-protocol PRIVATE
- ${CMAKE_CURRENT_LIST_DIR}/internal
-)
-target_link_libraries(usb-protocol PUBLIC
- CException
-)
-target_link_libraries(usb-protocol PRIVATE
- enV5_hw_controller
- enV5_hw_configuration
- hardware_spi
- gpio_interface
- flash_lib
- middleware_lib
- stub_v2_lib
- sleep_interface
-)
\ No newline at end of file
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(UsbProtocol Protocol.c DefaultCommands.c Tools.c)
+ target_include_directories(UsbProtocol PUBLIC include)
+ target_link_libraries(UsbProtocol PRIVATE
+ EnV5HwController
+ EnV5HwConfiguration
+ CException
+ Pico::hardware_spi
+ Pico::pico_runtime
+ Gpio
+ Flash
+ Middleware
+ Stub
+ Sleep)
+else()
+ add_library(UsbProtocol INTERFACE)
+ target_include_directories(UsbProtocol INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/test/hardware/CMakeLists.txt b/test/hardware/CMakeLists.txt
index ea6271c1..cb574910 100644
--- a/test/hardware/CMakeLists.txt
+++ b/test/hardware/CMakeLists.txt
@@ -1,10 +1,13 @@
add_subdirectory(Helper)
add_subdirectory(TestFreeRTOS)
+add_subdirectory(Esp)
add_subdirectory(TestNetworking)
add_subdirectory(TestFlash)
add_subdirectory(TestConfiguration)
add_subdirectory(Sensors)
add_subdirectory(TestStub)
+add_subdirectory(TestFlowPrediction)
add_subdirectory(TestMiddleware)
add_subdirectory(TestFlashFileSystem)
-add_subdirectory(TestUsbProtocol)
\ No newline at end of file
+add_subdirectory(TestUsbProtocol)
+
diff --git a/test/hardware/Esp/CMakeLists.txt b/test/hardware/Esp/CMakeLists.txt
new file mode 100644
index 00000000..94ee7316
--- /dev/null
+++ b/test/hardware/Esp/CMakeLists.txt
@@ -0,0 +1,15 @@
+ add_executable(HardwareTestEsp HardwareTestEsp.c)
+ target_link_libraries(HardwareTestEsp PRIVATE
+ Pico::pico_stdlib
+ Pico::hardware_uart
+ Pico::hardware_gpio
+ )
+ create_env5_executable(HardwareTestEsp)
+
+ add_executable(HardwareTestEspWithUartLib HardwareTestEspWithUartLib.c)
+ target_link_libraries(HardwareTestEspWithUartLib PRIVATE
+ Uart
+ EnV5HwConfiguration
+ Pico::pico_stdlib
+ )
+ create_env5_executable(HardwareTestEspWithUartLib)
\ No newline at end of file
diff --git a/test/hardware/Esp/HardwareTestEsp.c b/test/hardware/Esp/HardwareTestEsp.c
new file mode 100644
index 00000000..4b10083f
--- /dev/null
+++ b/test/hardware/Esp/HardwareTestEsp.c
@@ -0,0 +1,69 @@
+#include "string.h"
+#include "pico/stdlib.h"
+#include "hardware/uart.h"
+#include "hardware/gpio.h"
+
+#include
+
+uart_inst_t* uartInstance = uart1;
+int baudrate = 115200;
+uint8_t dataBits = 8;
+uint8_t stopBits = 1;
+uint8_t txPin = 4;
+uint8_t rxPin = 5;
+
+#define bufferSize 32
+char buffer[bufferSize];
+int receivedChars = 0;
+bool espAnswered = false;
+
+void uartInitInternal() {
+ gpio_set_function(txPin, GPIO_FUNC_UART);
+ gpio_set_function(rxPin, GPIO_FUNC_UART);
+
+ uart_init(uartInstance, baudrate);
+ uart_set_hw_flow(uartInstance, false, false);
+
+ uart_set_format(uartInstance, dataBits, stopBits, UART_PARITY_NONE);
+ uart_set_fifo_enabled(uartInstance, true);
+}
+
+bool checkForOkFromEsp() {
+ while (uart_is_readable(uartInstance)) {
+ char receivedCharacter = uart_getc(uartInstance);
+ buffer[receivedChars] = receivedCharacter;
+
+ if (receivedChars < bufferSize - 1) {
+ buffer[receivedChars++] = receivedCharacter;
+ }
+
+ if (receivedCharacter == '\n') {
+ buffer[receivedChars] = '\0';
+ if (strstr(buffer, "OK") != NULL) {
+ return true;
+ }
+ memset(buffer, 0, sizeof(buffer));
+ receivedChars = 0;
+ }
+ }
+ return false;
+}
+
+int main() {
+ stdio_init_all();
+ while (!stdio_usb_connected()) {
+ }
+ uartInitInternal();
+ while (!espAnswered) {
+ uart_puts(uartInstance, "AT\r\n");
+ sleep_ms(1000);
+ if (checkForOkFromEsp()) {
+ espAnswered = true;
+ }
+ sleep_ms(1000);
+ printf("Buffer: %s\n", buffer);
+ sleep_ms(1000);
+ }
+ printf("ESP responded with OK!\n");
+}
+
diff --git a/test/hardware/Esp/HardwareTestEspWithUartLib.c b/test/hardware/Esp/HardwareTestEspWithUartLib.c
new file mode 100644
index 00000000..7a7eedef
--- /dev/null
+++ b/test/hardware/Esp/HardwareTestEspWithUartLib.c
@@ -0,0 +1,80 @@
+#include "Uart.h"
+#include "string.h"
+#include "pico/stdlib.h"
+#include "hardware/uart.h"
+#include "EnV5HwConfiguration.h"
+
+#include
+
+static uartConfiguration_t uartConfig;
+
+#define bufferSize 32
+char buffer[bufferSize];
+int receivedChars = 0;
+bool espAnswered = false;
+
+void uartInitInternal() {
+ uartConfig.uartInstance = UART_MODULE;
+ uartConfig.baudrate = UART_BAUDRATE;
+ uartConfig.dataBits = UART_DATA_BITS;
+ uartConfig.stopBits = UART_STOP_BITS;
+ uartConfig.txPin = UART_TX_PIN;
+ uartConfig.rxPin = UART_RX_PIN;
+ uartConfig.parity = UART_PARITY_NONE;
+}
+
+bool checkForOkFromEsp() {
+ while (uart_is_readable(uartConfig.uartInstance)) {
+ char receivedCharacter = uart_getc(uartConfig.uartInstance);
+ buffer[receivedChars] = receivedCharacter;
+
+ if (receivedChars < bufferSize - 1) {
+ buffer[receivedChars++] = receivedCharacter;
+ }
+
+ if (receivedCharacter == '\n') {
+ buffer[receivedChars] = '\0';
+ if (strstr(buffer, "OK") != NULL) {
+ return true;
+ }
+ memset(buffer, 0, sizeof(buffer));
+ receivedChars = 0;
+ }
+ }
+ return false;
+}
+
+int main() {
+ stdio_init_all();
+ while (!stdio_usb_connected()) {
+ }
+ sleep_ms(1000);
+ // use EnV5 Config for UART params
+ uartInitInternal();
+
+ // use our UART lib to initialize UART
+ uartInit(&uartConfig);
+ printf("Uart initialized.\n");
+
+ /*while (!espAnswered) {
+ uart_puts(uartConfig.uartInstance, "AT\r\n");
+ sleep_ms(1000);
+ if (checkForOkFromEsp()) {
+ espAnswered = true;
+ }
+ sleep_ms(1000);
+ printf("Buffer: %s\n", buffer);
+ sleep_ms(1000);
+ }*/
+
+ while (!uartCorrectResponseArrived()) {
+ uart_puts(uartConfig.uartInstance, "AT\r\n");
+ sleep_ms(1000);
+ printf("Buffer: %s\n", buffer);
+ printf("ESP answer not correct...\n");
+ printf("Trying again.\n");
+ sleep_ms(1000);
+ }
+
+ printf("ESP responded with OK!\n");
+}
\ No newline at end of file
diff --git a/test/hardware/Helper/CMakeLists.txt b/test/hardware/Helper/CMakeLists.txt
index b3d0c8e6..8616506c 100644
--- a/test/hardware/Helper/CMakeLists.txt
+++ b/test/hardware/Helper/CMakeLists.txt
@@ -1,12 +1,18 @@
-################## hardwareTestHelper ##################
-add_library(hardware-testHelper INTERFACE)
-target_sources(hardware-testHelper INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/HardwaretestHelper.c)
-target_include_directories(hardware-testHelper INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_link_libraries(hardware-testHelper INTERFACE
- common_lib
- pico_stdlib
- espBroker_lib
- network_lib
- freeRtosUtils)
-
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(HardwareTestHelper HardwareTestHelper.c)
+ target_include_directories(HardwareTestHelper PUBLIC include)
+ target_link_libraries(HardwareTestHelper PRIVATE
+ Common
+ Pico::pico_stdlib
+ Pico::pico_stdio_usb
+ Pico::pico_bootrom
+ MqttBroker
+ Network
+ freeRtosUtils
+ EnV5HwController
+ Esp
+ )
+else()
+ add_library(HardwareTestHelper INTERFACE)
+ target_include_directories(HardwareTestHelper INTERFACE include)
+endif ()
\ No newline at end of file
diff --git a/test/hardware/Helper/HardwaretestHelper.c b/test/hardware/Helper/HardwareTestHelper.c
similarity index 97%
rename from test/hardware/Helper/HardwaretestHelper.c
rename to test/hardware/Helper/HardwareTestHelper.c
index 904b948f..6ab46e69 100644
--- a/test/hardware/Helper/HardwaretestHelper.c
+++ b/test/hardware/Helper/HardwareTestHelper.c
@@ -1,6 +1,6 @@
#define SOURCE_FILE "TEST-HELPER"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "EnV5HwController.h"
#include "Esp.h"
#include "FreeRtosTaskWrapper.h"
diff --git a/test/hardware/Helper/include/HardwaretestHelper.h b/test/hardware/Helper/include/HardwareTestHelper.h
similarity index 100%
rename from test/hardware/Helper/include/HardwaretestHelper.h
rename to test/hardware/Helper/include/HardwareTestHelper.h
diff --git a/test/hardware/Sensors/CMakeLists.txt b/test/hardware/Sensors/CMakeLists.txt
index 69166ff9..4edae503 100644
--- a/test/hardware/Sensors/CMakeLists.txt
+++ b/test/hardware/Sensors/CMakeLists.txt
@@ -1,111 +1,97 @@
-##############################################
-## region hardware-test_sht3
-add_executable(hardware-test_sht3 HardwaretestSht3x.c)
-target_link_libraries(hardware-test_sht3
- pico_stdlib
- pico_stdio_usb
- pico_bootrom
- hardware_i2c
-
- common_lib
- enV5_hw_configuration
- enV5_hw_controller
- i2c_interface
- sensor_lib_sht3x)
-create_enV5_executable(hardware-test_sht3)
-##############################################
-## region hardware-test_adxl345b
-add_executable(hardware-test_adxl345b HardwaretestAdxl345b.c)
-target_link_libraries(hardware-test_adxl345b
- common_lib
- pico_stdlib
- pico_stdio_usb
- pico_bootrom
- pico_time
- i2c_interface
- sensor_lib_adxl345b)
-create_enV5_executable(hardware-test_adxl345b)
-## endregion hardware-test_adxl345b
-##############################################
-## hardware-test_pac193x
-add_executable(hardware-test_pac193x HardwaretestPac193x.c)
-target_link_libraries(hardware-test_pac193x
- common_lib
- pico_stdlib
- pico_stdio_usb
- pico_bootrom
- pico_time
- i2c_interface
- enV5_hw_configuration
- sensor_lib_pac193x)
-create_enV5_executable(hardware-test_pac193x)
-##############################################
-## hardware-test_pac193x_stream
-add_executable(hardware-test_pac193x_stream HardwaretestPac193xAccumulator.c)
-target_link_libraries(hardware-test_pac193x_stream
- common_lib
- pico_stdlib
- pico_stdio_usb
- pico_bootrom
- pico_time
- i2c_interface
- enV5_hw_configuration
- enV5_hw_controller
- sensor_lib_pac193x)
-create_enV5_executable(hardware-test_pac193x_stream)
-##############################################
-## hardware-test_dualpac193x
-add_executable(hardware-test_dualpac193x HardwaretestDualPac193x.c)
-target_link_libraries(hardware-test_dualpac193x
- common_lib
- pico_stdlib
- pico_stdio_usb
- pico_bootrom
- pico_time
- i2c_interface
- enV5_hw_configuration
- sensor_lib_pac193x)
-create_enV5_executable(hardware-test_dualpac193x)
-##############################################
-## hardware-test_pac193xbuffer
-add_executable(hardware-test_pac193xbuffer HardwaretestPac193xBuffer.c)
-target_link_libraries(hardware-test_pac193xbuffer
- common_lib
- pico_stdlib
- pico_stdio_usb
- pico_bootrom
- pico_time
- i2c_interface
- enV5_hw_configuration
- sensor_lib_pac193x)
-create_enV5_executable(hardware-test_pac193xbuffer)
-##############################################
-add_executable(hardware-test_bmi323 HardwaretestBmi323.c)
-target_link_libraries(hardware-test_bmi323
- pico_stdlib
- hardware_spi
-
- CException
-
- common_lib
- enV5_hw_configuration
- enV5_hw_controller
- spi_interface
- sleep_interface
- sensor_lib_bmi323
-)
-create_enV5_executable(hardware-test_bmi323)
-## hardware-stresstest_adxl345b
-add_executable(hardware-test_stressTest_adxl345b StressTestAdxl345b.c)
-target_link_libraries(hardware-test_stressTest_adxl345b
- common_lib
- pico_stdlib
- pico_stdio_usb
- pico_time
- freeRtosUtils
- espBroker_lib
- middleware_lib
- sensor_lib_adxl345b
- hardware-testHelper)
-create_enV5_executable(hardware-test_stressTest_adxl345b)
-##############################################
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_library(HWTestCommon INTERFACE)
+ target_link_libraries(HWTestCommon INTERFACE
+ I2c
+ Gpio
+ Sleep
+ Spi
+ Pico::pico_stdlib
+ Pico::pico_stdio
+ Pico::pico_stdio_usb
+ Pico::pico_time
+ Pico::pico_runtime
+ Pico::pico_bootrom
+ Pico::hardware_i2c
+ Pico::hardware_spi
+ EnV5HwController
+ Common
+ EnV5HwConfiguration
+ CException
+ )
+
+ add_executable(HardwareTestSht3x HardwareTestSht3x.c)
+ target_link_libraries(HardwareTestSht3x PRIVATE
+ Sht3x
+ HWTestCommon
+ )
+ create_env5_executable(HardwareTestSht3x)
+
+
+ add_executable(HardwareTestAdxl345b HardwareTestAdxl345b.c)
+ target_link_libraries(HardwareTestAdxl345b PRIVATE
+ Adxl345b
+ HWTestCommon
+ )
+ create_enV5_executable(HardwareTestAdxl345b)
+
+
+ add_executable(HardwareTestPac193x HardwareTestPac193x.c)
+ target_link_libraries(HardwareTestPac193x PRIVATE
+ Pac193x
+ HWTestCommon
+ )
+ create_enV5_executable(HardwareTestPac193x)
+
+
+ add_executable(HardwareTestPac193xAccumulator HardwareTestPac193xAccumulator.c)
+ target_link_libraries(HardwareTestPac193xAccumulator PRIVATE
+ Pac193x
+ HWTestCommon
+ )
+ create_enV5_executable(HardwareTestPac193xAccumulator)
+
+
+ add_executable(HardwareTestDualPac193x HardwareTestDualPac193x.c)
+ target_link_libraries(HardwareTestDualPac193x PRIVATE
+ Pac193x
+ HWTestCommon
+ )
+ create_enV5_executable(HardwareTestDualPac193x)
+
+
+ add_executable(HardwareTestPac193xBuffer HardwareTestPac193xBuffer.c)
+ target_link_libraries(HardwareTestPac193xBuffer PRIVATE
+ Pac193x
+ HWTestCommon
+ )
+ create_enV5_executable(HardwareTestPac193xBuffer)
+
+
+
+ add_executable(HardwareTestBmi323 HardwareTestBmi323.c)
+ target_link_libraries(HardwareTestBmi323 PRIVATE
+ Bmi323
+ HWTestCommon
+ )
+ create_enV5_executable(HardwareTestBmi323)
+
+
+ add_executable(StressTestAdxl345b StressTestAdxl345b.c)
+ target_link_libraries(StressTestAdxl345b PRIVATE
+ Adxl345b
+ Common
+ I2c
+ freeRtosUtils
+ HardwareTestHelper
+ EnV5HwController
+ Esp
+
+ Pico::pico_stdlib
+ Pico::pico_stdio
+ Pico::pico_bootrom
+ Pico::hardware_i2c
+ RuntimeC::Protocol
+ )
+ create_enV5_executable(StressTestAdxl345b)
+endif ()
+
diff --git a/test/hardware/Sensors/HardwaretestAdxl345b.c b/test/hardware/Sensors/HardwareTestAdxl345b.c
similarity index 98%
rename from test/hardware/Sensors/HardwaretestAdxl345b.c
rename to test/hardware/Sensors/HardwareTestAdxl345b.c
index ea7c5fe1..1df0ffa8 100644
--- a/test/hardware/Sensors/HardwaretestAdxl345b.c
+++ b/test/hardware/Sensors/HardwareTestAdxl345b.c
@@ -3,10 +3,9 @@
#include "Adxl345b.h"
#include "Common.h"
#include "I2c.h"
-#include
-#include
-#include
-#include
+#include "hardware/i2c.h"
+#include "pico/bootrom.h"
+#include "pico/stdio_usb.h"
/* region HELPER */
diff --git a/test/hardware/Sensors/HardwaretestBmi323.c b/test/hardware/Sensors/HardwareTestBmi323.c
similarity index 100%
rename from test/hardware/Sensors/HardwaretestBmi323.c
rename to test/hardware/Sensors/HardwareTestBmi323.c
diff --git a/test/hardware/Sensors/HardwaretestDualPac193x.c b/test/hardware/Sensors/HardwareTestDualPac193x.c
similarity index 100%
rename from test/hardware/Sensors/HardwaretestDualPac193x.c
rename to test/hardware/Sensors/HardwareTestDualPac193x.c
diff --git a/test/hardware/Sensors/HardwaretestPac193x.c b/test/hardware/Sensors/HardwareTestPac193x.c
similarity index 100%
rename from test/hardware/Sensors/HardwaretestPac193x.c
rename to test/hardware/Sensors/HardwareTestPac193x.c
diff --git a/test/hardware/Sensors/HardwaretestPac193xAccumulator.c b/test/hardware/Sensors/HardwareTestPac193xAccumulator.c
similarity index 100%
rename from test/hardware/Sensors/HardwaretestPac193xAccumulator.c
rename to test/hardware/Sensors/HardwareTestPac193xAccumulator.c
diff --git a/test/hardware/Sensors/HardwaretestPac193xBuffer.c b/test/hardware/Sensors/HardwareTestPac193xBuffer.c
similarity index 100%
rename from test/hardware/Sensors/HardwaretestPac193xBuffer.c
rename to test/hardware/Sensors/HardwareTestPac193xBuffer.c
diff --git a/test/hardware/Sensors/HardwaretestSht3x.c b/test/hardware/Sensors/HardwareTestSht3x.c
similarity index 97%
rename from test/hardware/Sensors/HardwaretestSht3x.c
rename to test/hardware/Sensors/HardwareTestSht3x.c
index 65861711..5d37bb3e 100644
--- a/test/hardware/Sensors/HardwaretestSht3x.c
+++ b/test/hardware/Sensors/HardwareTestSht3x.c
@@ -1,10 +1,10 @@
#define SOURCE_FILE "SHT3X-Test"
-#include "CException.h"
-#include "hardware/i2c.h"
-#include "pico/bootrom.h"
-#include "pico/stdio_usb.h"
+#include
+#include
+#include
+#include "CException.h"
#include "Common.h"
#include "EnV5HwConfiguration.h"
#include "EnV5HwController.h"
diff --git a/test/hardware/Sensors/StressTestAdxl345b.c b/test/hardware/Sensors/StressTestAdxl345b.c
index a2b73997..68e0e721 100644
--- a/test/hardware/Sensors/StressTestAdxl345b.c
+++ b/test/hardware/Sensors/StressTestAdxl345b.c
@@ -1,19 +1,18 @@
#define SOURCE_FILE "ADXL345-StressTest"
-
#include "Adxl345b.h"
#include "Common.h"
-#include "EnV5HwController.h"
-#include "Esp.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
#include "I2c.h"
-#include "Protocol.h"
-// pico-sdk headers
+#include "EnV5HwController.h"
+#include "Esp.h"
+#include "HardwareTestHelper.h"
+
+#include "Protocol.h"
+#include "pico/stdlib.h"
#include "hardware/i2c.h"
-#include "hardware/watchdog.h"
#include "pico/bootrom.h"
-#include "pico/stdlib.h"
+#include "pico/stdio_usb.h"
/* endregion HELPER*/
@@ -182,8 +181,8 @@ void publishTestData() {
void _Noreturn mqttTask(void) {
PRINT("=== STARTING TEST ===");
- connectToNetwork();
- // connectToMQTT();
+ // connectToNetwork();
+ // connectToMQTT();
uint64_t messageCounter = 0;
while (1) {
@@ -276,7 +275,7 @@ _Noreturn void t_stressTest_enterBootModeTask(void) {
}
// watchdog update needs to be performed frequent, otherwise the device will crash
- watchdog_update();
+ // watchdog_update();
freeRtosTaskWrapperTaskSleep(1000);
}
}
@@ -284,21 +283,21 @@ _Noreturn void t_stressTest_enterBootModeTask(void) {
// TODO: adxl_task mit MQTT_task testen
int main(void) {
+ // init stdio and esp
+ stdio_init_all();
+ PRINT("TEST");
// Did we crash last time -> reboot into boot rom mode
- if (watchdog_enable_caused_reboot()) {
+ /*if (watchdog_enable_caused_reboot()) {
reset_usb_boot(0, 0);
- }
+ }*/
env5HwControllerInit();
- // init stdio and esp
- stdio_init_all();
-
// das hier passiert vorher noch im Ballchallenge-Repo. Erkenne keinen Zusammenhang.
- // espInit();
+ espInit();
// initialize WiFi and MQTT broker
- // networkTryToConnectToNetworkUntilSuccessful(networkCredentials);
- // mqttBrokerConnectToBrokerUntilSuccessful(mqttHost, "eip://uni-due.de/es", "enV5");
+ connectToNetwork();
+ connectToMqttBroker();
// vor der init schlafen lassen um sicher zu stellen, dass pico nicht zu schnell ist und adxl zu
// langsam nach reboot
diff --git a/test/hardware/TestConfiguration/CMakeLists.txt b/test/hardware/TestConfiguration/CMakeLists.txt
index 6d7b77bc..ad1804cd 100644
--- a/test/hardware/TestConfiguration/CMakeLists.txt
+++ b/test/hardware/TestConfiguration/CMakeLists.txt
@@ -1,22 +1,30 @@
-add_executable(hardware-test_configUSB HardwaretestConfigureViaUSB.c)
-target_link_libraries(hardware-test_configUSB
- common_lib
- pico_stdlib
- spi_interface
- flash_lib
- sleep_interface
- enV5_hw_controller
- enV5_hw_configuration
- fpga_configuration_handler)
-create_enV5_executable(hardware-test_configUSB)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_executable(HardwareTestConfigureViaUSB HardwareTestConfigureViaUSB.c)
+ target_link_libraries(HardwareTestConfigureViaUSB PRIVATE
+ Common
+ EnV5HwConfiguration
+ EnV5HwController
+ FpgaConfigurationHandler
+ FpgaConfigurationHandlerUSB
+ Flash
+ Pico::pico_stdio
+ Pico::pico_stdlib
+ Pico::hardware_spi
+ )
+ create_enV5_executable(HardwareTestConfigureViaUSB)
-add_executable(hardware-test_configHTTP HardwaretestConfigureViaHTTP.c)
-target_link_libraries(hardware-test_configHTTP
- common_lib
- pico_stdlib
- spi_interface
- flash_lib
- enV5_hw_controller
- enV5_hw_configuration
- fpga_configuration_handler)
-create_enV5_executable(hardware-test_configHTTP)
+ add_executable(HardwareTestConfigureViaHTTP HardwareTestConfigureViaHTTP.c)
+ target_link_libraries(HardwareTestConfigureViaHTTP PRIVATE
+ Common
+ EnV5HwController
+ EnV5HwConfiguration
+ Esp
+ Network
+ Flash
+ FpgaConfigurationHandler
+ Pico::pico_stdlib
+ Pico::pico_stdio_usb
+ Pico::hardware_spi
+ )
+ create_enV5_executable(HardwareTestConfigureViaHTTP)
+endif()
\ No newline at end of file
diff --git a/test/hardware/TestConfiguration/HardwaretestConfigureViaHTTP.c b/test/hardware/TestConfiguration/HardwareTestConfigureViaHTTP.c
similarity index 97%
rename from test/hardware/TestConfiguration/HardwaretestConfigureViaHTTP.c
rename to test/hardware/TestConfiguration/HardwareTestConfigureViaHTTP.c
index 734cc999..5ed0b570 100644
--- a/test/hardware/TestConfiguration/HardwaretestConfigureViaHTTP.c
+++ b/test/hardware/TestConfiguration/HardwareTestConfigureViaHTTP.c
@@ -19,10 +19,6 @@
#include
#include
-#include "hardware/spi.h"
-#include "pico/stdio.h"
-#include "pico/stdlib.h"
-
#include "Common.h"
#include "EnV5HwConfiguration.h"
#include "EnV5HwController.h"
@@ -30,7 +26,11 @@
#include "Flash.h"
#include "FpgaConfigurationHandler.h"
#include "Network.h"
-#include "Spi.h"
+
+#include "pico/stdio_usb.h"
+#include "pico/stdlib.h"
+
+#include "hardware/spi.h"
spiConfiguration_t spiToFlashConfig = {.sckPin = FLASH_SPI_CLOCK,
.misoPin = FLASH_SPI_MISO,
@@ -55,17 +55,17 @@ uint32_t blinkSlow = 1;
size_t blinkSlowLength = 85540;
void initHardwareTest(void) {
+ stdio_init_all();
env5HwControllerInit();
env5HwControllerFpgaPowersOff();
initializeFlashConfig();
- // initialize the serial output
- stdio_init_all();
- while ((!stdio_usb_connected())) {
+ while (!stdio_usb_connected()) {
// wait for serial connection
}
- espInit(); // initilize Wi-Fi chip
+ espInit();
+
networkTryToConnectToNetworkUntilSuccessful();
fpgaConfigurationHandlerInitialize();
diff --git a/test/hardware/TestConfiguration/HardwaretestConfigureViaUSB.c b/test/hardware/TestConfiguration/HardwareTestConfigureViaUSB.c
similarity index 98%
rename from test/hardware/TestConfiguration/HardwaretestConfigureViaUSB.c
rename to test/hardware/TestConfiguration/HardwareTestConfigureViaUSB.c
index 3c9a5c51..e9187373 100644
--- a/test/hardware/TestConfiguration/HardwaretestConfigureViaUSB.c
+++ b/test/hardware/TestConfiguration/HardwareTestConfigureViaUSB.c
@@ -27,7 +27,6 @@
#include "EnV5HwController.h"
#include "Flash.h"
#include "FpgaConfigurationHandler.h"
-#include "Spi.h"
spiConfiguration_t spiToFlashConfig = {.sckPin = FLASH_SPI_CLOCK,
.misoPin = FLASH_SPI_MISO,
@@ -51,17 +50,15 @@ uint32_t blinkSlow = 1;
size_t blinkSlowLength = 85540;
void initHardwareTest(void) {
+ stdio_init_all();
env5HwControllerInit();
env5HwControllerFpgaPowersOff();
-
- // initialize the serial output
- stdio_init_all();
initializeFlashConfig();
+
while ((!stdio_usb_connected())) {
// wait for serial connection
}
- // initialize FPGA
fpgaConfigurationHandlerInitialize();
}
@@ -81,6 +78,7 @@ void downloadConfiguration(bool useFast) {
}
PRINT("Download Successful!");
}
+
void readConfiguration(bool useFast) {
size_t numberOfPages = 1, page = 0;
uint32_t startAddress;
diff --git a/test/hardware/TestFlash/CMakeLists.txt b/test/hardware/TestFlash/CMakeLists.txt
index d66886b7..02c1babe 100644
--- a/test/hardware/TestFlash/CMakeLists.txt
+++ b/test/hardware/TestFlash/CMakeLists.txt
@@ -1,23 +1,27 @@
-add_executable(hardware-test_flash HardwaretestFlash.c)
-target_link_libraries(hardware-test_flash
- common_lib
- pico_stdlib
- freeRtosUtils
- hardware_spi
- spi_interface
- enV5_hw_configuration
- enV5_hw_controller
- flash_lib)
-create_enV5_executable(hardware-test_flash)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_executable(HardwareTestFlash HardwareTestFlash.c)
+ target_link_libraries(HardwareTestFlash PRIVATE
+ EnV5HwConfiguration
+ Common
+ Spi
+ EnV5HwController
+ Flash
-add_executable(hardware-test_flash_read_config HardwareTestFlashReadConfiguration.c)
-target_link_libraries(hardware-test_flash_read_config
- common_lib
- pico_stdlib
- freeRtosUtils
- hardware_spi
- spi_interface
- enV5_hw_configuration
- enV5_hw_controller
- flash_lib)
-create_enV5_executable(hardware-test_flash_read_config)
+ Pico::pico_stdlib
+ Pico::hardware_spi
+ )
+ create_enV5_executable(HardwareTestFlash)
+
+ add_executable(HardwareTestFlashReadConfiguration HardwareTestFlashReadConfiguration.c)
+ target_link_libraries(HardwareTestFlashReadConfiguration
+ Common
+ Pico::pico_stdlib
+ Pico::hardware_spi
+ Spi
+ EnV5HwConfiguration
+ EnV5HwController
+ Flash
+ freeRtosUtils
+ )
+ create_enV5_executable(HardwareTestFlashReadConfiguration)
+endif()
\ No newline at end of file
diff --git a/test/hardware/TestFlash/HardwaretestFlash.c b/test/hardware/TestFlash/HardwareTestFlash.c
similarity index 92%
rename from test/hardware/TestFlash/HardwaretestFlash.c
rename to test/hardware/TestFlash/HardwareTestFlash.c
index 97f118e1..48dad7b5 100644
--- a/test/hardware/TestFlash/HardwaretestFlash.c
+++ b/test/hardware/TestFlash/HardwareTestFlash.c
@@ -1,20 +1,18 @@
#define SOURCE_FILE "FLASH-HWTEST"
-#include
-#include
-#include
-
-#include "hardware/spi.h"
-#include "pico/bootrom.h"
-#include "pico/stdio.h"
-#include "pico/stdlib.h"
-
#include "Common.h"
#include "EnV5HwConfiguration.h"
#include "EnV5HwController.h"
+
#include "Flash.h"
#include "Spi.h"
+#include "pico/stdlib.h"
+
+#include "hardware/spi.h"
+#include
+#include
+
spiConfiguration_t spiToFlashConfig = {.sckPin = FLASH_SPI_CLOCK,
.misoPin = FLASH_SPI_MISO,
.mosiPin = FLASH_SPI_MOSI,
@@ -134,6 +132,16 @@ _Noreturn void runTest(void) {
case 'b':
flashEraseAll(NULL);
break;
+
+ case 'p':
+ PRINT("Bytes per page: %i\n", flashGetBytesPerPage(&flashConfig));
+ break;
+ case 's':
+ PRINT("Bytes per Sector: %i\n", flashGetBytesPerSector(&flashConfig));
+ break;
+ case 't':
+ PRINT("Total number of bytes: %i\n", flashGetNumberOfBytes(&flashConfig));
+ break;
default:
PRINT("Waiting ...");
}
diff --git a/test/hardware/TestFlashFileSystem/CMakeLists.txt b/test/hardware/TestFlashFileSystem/CMakeLists.txt
index 2005a937..a0c9ae24 100644
--- a/test/hardware/TestFlashFileSystem/CMakeLists.txt
+++ b/test/hardware/TestFlashFileSystem/CMakeLists.txt
@@ -1,12 +1,26 @@
-add_executable(demo_file_system DemoFileSystem.c)
-target_link_libraries(demo_file_system
- common_lib
- pico_stdlib
- spi_interface
- flash_lib
- sleep_interface
- enV5_hw_controller
- enV5_hw_configuration
- fpga_configuration_handler
- filesystem_lib)
-create_enV5_executable(demo_file_system)
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_executable(HardwareTestFileSystem HardwareTestFileSystem.c)
+ target_link_libraries(HardwareTestFileSystem PRIVATE
+ FileSystem
+ FpgaConfigurationHandler
+ FpgaConfigurationHandlerUSB
+ EnV5HwConfiguration
+ Common
+ Spi
+ EnV5HwController
+ Flash
+
+
+ Esp
+ Network
+
+ Sleep
+
+
+
+ Pico::pico_stdlib
+ Pico::hardware_spi
+
+ )
+ create_enV5_executable(HardwareTestFileSystem)
+endif()
\ No newline at end of file
diff --git a/test/hardware/TestFlashFileSystem/DemoFileSystem.c b/test/hardware/TestFlashFileSystem/HardwareTestFileSystem.c
similarity index 94%
rename from test/hardware/TestFlashFileSystem/DemoFileSystem.c
rename to test/hardware/TestFlashFileSystem/HardwareTestFileSystem.c
index e9cf83b8..f9c35a18 100644
--- a/test/hardware/TestFlashFileSystem/DemoFileSystem.c
+++ b/test/hardware/TestFlashFileSystem/HardwareTestFileSystem.c
@@ -1,13 +1,5 @@
#define SOURCE_FILE "DEMO_FILESYSTEM"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
#include "Common.h"
#include "EnV5HwConfiguration.h"
#include "EnV5HwController.h"
@@ -16,10 +8,14 @@
#include "Flash.h"
#include "FpgaConfigurationHandler.h"
#include "Network.h"
+#include "Sleep.h"
+
#include "hardware/spi.h"
-#include "pico/stdio.h"
+#include "pico/bootrom.h"
#include "pico/stdlib.h"
+#include
+
spiConfiguration_t spiToFlashConfig = {.sckPin = FLASH_SPI_CLOCK,
.misoPin = FLASH_SPI_MISO,
.mosiPin = FLASH_SPI_MOSI,
@@ -46,8 +42,8 @@ void initDemo() {
stdio_init_all();
while (!stdio_usb_connected()) {}
- /*espInit();
- networkTryToConnectToNetworkUntilSuccessful();*/
+ espInit();
+ networkTryToConnectToNetworkUntilSuccessful();
flashInit(&flashConfig);
filesystemInit(&flashConfig, &filesystemConfiguration);
@@ -63,16 +59,11 @@ void downloadConfigurationHTTP(bool useFast) {
strcpy(url, baseUrl);
if (useFast) {
-
- /* region FUNCTIONS NEEDED FOR FILE SYSTEM */
int32_t nextFileSector =
filesystemFindFittingStartSector(&filesystemConfiguration, blinkFastLength);
if (nextFileSector < 0) {
return;
}
- // filesystemAddNewFileSystemEntry(&flashConfig, &filesystemConfiguration, blinkFastLength,
- // 1);
- /* end region */
strcat(url, "/getfast");
PRINT_DEBUG("URL: %s", url);
@@ -82,17 +73,17 @@ void downloadConfigurationHTTP(bool useFast) {
PRINT("Error 0x%02X occurred during download.", error);
return;
}
+ filesystemAddNewFileSystemEntry(&filesystemConfiguration, nextFileSector, blinkFastLength,
+ 1);
+ }
- } else {
-
- // region STUFF FOR FILE SYSTEM
+ else {
int32_t nextFileSector =
- filesystemFindFittingStartSector(&filesystemConfiguration, blinkFastLength);
+ filesystemFindFittingStartSector(&filesystemConfiguration, blinkSlowLength);
if (nextFileSector < 0) {
PRINT("Not enough space...\n Aborting...\n");
return;
}
- // endregion
strcat(url, "/getslow");
PRINT_DEBUG("URL: %s", url);
@@ -102,9 +93,10 @@ void downloadConfigurationHTTP(bool useFast) {
PRINT("Error 0x%02X occurred during download.", error);
return;
}
+ filesystemAddNewFileSystemEntry(&filesystemConfiguration, nextFileSector, blinkSlowLength,
+ 1);
}
PRINT("Download Successful!");
- // filesystemAddNewFileSystemEntry(&flashConfig, &filesystemConfiguration, blinkSlowLength, 1);
}
void downloadConfigurationUSB(bool useFast) {
diff --git a/test/hardware/TestFlowPrediction/CMakeLists.txt b/test/hardware/TestFlowPrediction/CMakeLists.txt
new file mode 100644
index 00000000..4990ef8e
--- /dev/null
+++ b/test/hardware/TestFlowPrediction/CMakeLists.txt
@@ -0,0 +1,15 @@
+if(BUILDING_FOR_ELASTIC_NODE)
+ add_executable(HardwareTestFlowPrediction HardwareTestFlowPrediction.c)
+ target_link_libraries(HardwareTestFlowPrediction PRIVATE
+ Common
+ Flash
+ FpgaConfigurationHandler
+ EnV5HwController
+ Middleware
+ EnV5HwConfiguration
+
+ Pico::hardware_spi
+ Pico::pico_stdlib
+ )
+ create_enV5_executable(HardwareTestFlowPrediction)
+endif()
\ No newline at end of file
diff --git a/test/hardware/TestFlowPrediction/HardwaretestStub.c b/test/hardware/TestFlowPrediction/HardwareTestFlowPrediction.c
similarity index 71%
rename from test/hardware/TestFlowPrediction/HardwaretestStub.c
rename to test/hardware/TestFlowPrediction/HardwareTestFlowPrediction.c
index 06eac4bd..b11e8f29 100644
--- a/test/hardware/TestFlowPrediction/HardwaretestStub.c
+++ b/test/hardware/TestFlowPrediction/HardwareTestFlowPrediction.c
@@ -16,10 +16,11 @@
#define SOURCE_FILE "HWTEST-MIDDLEWARE"
#include "Common.h"
+#include "EnV5HwConfiguration.h"
+#include "EnV5HwController.h"
#include "Flash.h"
#include "FpgaConfigurationHandler.h"
-#include "enV5HwController.h"
-#include "flow_prediction.h"
+/*#include "flow_prediction.h"*/
#include "middleware.h"
#include
@@ -28,9 +29,16 @@
#include
#include
-spiConfig_t spiConfiguration = {
- .spiInstance = spi0, .baudrate = 5000000, .misoPin = 0, .mosiPin = 3, .sckPin = 2};
-uint8_t csPin = 1;
+spiConfiguration_t spiToFlashConfig = {.sckPin = FLASH_SPI_CLOCK,
+ .misoPin = FLASH_SPI_MISO,
+ .mosiPin = FLASH_SPI_MOSI,
+ .baudrate = FLASH_SPI_BAUDRATE,
+ .spiInstance = FLASH_SPI_MODULE,
+ .csPin = FLASH_SPI_CS};
+
+flashConfiguration_t flashConfig = {
+ .spiConfiguration = &spiToFlashConfig,
+};
char baseUrl[] = "http://192.168.203.99:5000/getfast";
size_t configSize = 86116;
@@ -47,14 +55,14 @@ static void initHardware() {
middlewareInit();
// initialize the Flash and FPGA
- flashInit(&spiConfiguration, csPin);
- env5HwInit();
+ flashInit(&flashConfig);
+ env5HwControllerInit();
+ env5HwControllerFpgaPowersOff();
fpgaConfigurationHandlerInitialize();
- env5HwFpgaPowersOff();
}
static void loadConfigToFlash() {
fpgaConfigurationHandlerError_t error = fpgaConfigurationHandlerDownloadConfigurationViaHttp(
- baseUrl, configSize, sectorIdForConfig);
+ &flashConfig, baseUrl, configSize, sectorIdForConfig);
if (error != FPGA_RECONFIG_NO_ERROR) {
while (true) {
PRINT("Download failed!");
@@ -64,7 +72,7 @@ static void loadConfigToFlash() {
}
static void runTest() {
- env5HwFpgaPowersOn();
+ env5HwControllerFpgaPowersOn();
uint8_t data[] = {53, 49, 22, 53, 61, 35};
uint8_t ref_res[] = {38, 63};
@@ -72,9 +80,10 @@ static void runTest() {
for (int counter = 0; counter < 2; counter++) {
for (int i = 0; i < 3; i++) {
uint8_t offset = counter * 3;
- uint8_t return_val = (uint8_t)flow_prediction_predict(data + offset);
+ // TODO fix flow_prediction.h
+ /*uint8_t return_val = (uint8_t)flow_prediction_predict(data + offset);
- PRINT("Ture: %d, Predicted: %d", ref_res[counter], return_val);
+ PRINT("Ture: %d, Predicted: %d", ref_res[counter], return_val);*/
// if (return_val == counter + 1) {
// env5HwLedsAllOff();
// sleep_ms(500);
diff --git a/test/hardware/TestFreeRTOS/CMakeLists.txt b/test/hardware/TestFreeRTOS/CMakeLists.txt
index 33696d3c..7e7876bb 100644
--- a/test/hardware/TestFreeRTOS/CMakeLists.txt
+++ b/test/hardware/TestFreeRTOS/CMakeLists.txt
@@ -1,32 +1,41 @@
################## test_freeRTOSTask ##################
-add_executable(hardware-test_freeRTOSTask HardwaretestFreeRtosTask.c)
-target_link_libraries(hardware-test_freeRTOSTask
- pico_stdlib
- hardware_watchdog
- common_lib
- enV5_hw_controller
- enV5_hw_configuration
- gpio_interface
- freeRtosUtils)
-create_enV5_executable(hardware-test_freeRTOSTask)
+add_executable(HardwareTestFreeRtosTask HardwareTestFreeRtosTask.c)
+target_link_libraries(HardwareTestFreeRtosTask
+ Common
+ EnV5HwConfiguration
+ EnV5HwController
+ Gpio
+ freeRtosUtils
+ Pico::hardware_watchdog
+ Pico::pico_bootrom
+ Pico::pico_stdlib
+)
+create_enV5_executable(HardwareTestFreeRtosTask)
################## test_freeRTOSQueues ##################
-add_executable(hardware-test_freeRTOSQueues HardwaretestFreeRtosQueues.c)
-target_link_libraries(hardware-test_freeRTOSQueues
- pico_stdlib
- hardware_watchdog
- common_lib
- enV5_hw_controller
- freeRtosUtils)
-create_enV5_executable(hardware-test_freeRTOSQueues)
+add_executable(HardwareTestFreeRtosQueues HardwareTestFreeRtosQueues.c)
+target_link_libraries(HardwareTestFreeRtosQueues
+ Common
+ EnV5HwController
+ freeRtosUtils
+
+ freeRtos::FreeRTOS-Kernel
+ Pico::pico_stdlib
+ Pico::hardware_spi
+)
+create_enV5_executable(HardwareTestFreeRtosQueues)
################## test_SMP ##################
-add_executable(hardware-test_SMP HardwaretestSMP.c)
-target_link_libraries(hardware-test_SMP
- pico_stdlib
- hardware_watchdog
- common_lib
- enV5_hw_controller
- freeRtosUtils)
-target_compile_definitions(hardware-test_SMP PRIVATE DEBUG)
-create_enV5_executable(hardware-test_SMP)
+add_executable(HardwareTestSMP HardwareTestSMP.c)
+target_link_libraries(HardwareTestSMP
+ Common
+ EnV5HwController
+ freeRtosUtils
+
+ freeRtos::FreeRTOS-Kernel
+ Pico::pico_stdlib
+ Pico::pico_bootrom
+
+)
+target_compile_definitions(HardwareTestSMP PRIVATE DEBUG)
+create_enV5_executable(HardwareTestSMP)
diff --git a/test/hardware/TestFreeRTOS/HardwaretestFreeRtosQueues.c b/test/hardware/TestFreeRTOS/HardwareTestFreeRtosQueues.c
similarity index 100%
rename from test/hardware/TestFreeRTOS/HardwaretestFreeRtosQueues.c
rename to test/hardware/TestFreeRTOS/HardwareTestFreeRtosQueues.c
diff --git a/test/hardware/TestFreeRTOS/HardwaretestFreeRtosTask.c b/test/hardware/TestFreeRTOS/HardwareTestFreeRtosTask.c
similarity index 96%
rename from test/hardware/TestFreeRTOS/HardwaretestFreeRtosTask.c
rename to test/hardware/TestFreeRTOS/HardwareTestFreeRtosTask.c
index d6169710..3b436e82 100644
--- a/test/hardware/TestFreeRTOS/HardwaretestFreeRtosTask.c
+++ b/test/hardware/TestFreeRTOS/HardwareTestFreeRtosTask.c
@@ -19,7 +19,7 @@ _Noreturn void blinkLed1Task() {
PRINT_DEBUG("BLINK 1");
gpioSetPin(LED0_GPIO, GPIO_PIN_HIGH); // turn LED on
freeRtosTaskWrapperTaskSleep(1000);
- gpioSetPin(LED1_GPIO, GPIO_PIN_LOW); // turn LED off
+ gpioSetPin(LED0_GPIO, GPIO_PIN_LOW); // turn LED off
freeRtosTaskWrapperTaskSleep(1000);
}
}
diff --git a/test/hardware/TestFreeRTOS/HardwaretestSMP.c b/test/hardware/TestFreeRTOS/HardwareTestSMP.c
similarity index 97%
rename from test/hardware/TestFreeRTOS/HardwaretestSMP.c
rename to test/hardware/TestFreeRTOS/HardwareTestSMP.c
index 56076574..7c4c66e3 100644
--- a/test/hardware/TestFreeRTOS/HardwaretestSMP.c
+++ b/test/hardware/TestFreeRTOS/HardwareTestSMP.c
@@ -2,14 +2,17 @@
#include "Common.h"
#include "EnV5HwController.h"
-#include "FreeRTOS.h"
#include "FreeRtosTaskWrapper.h"
-#include "task.h"
#include "hardware/watchdog.h"
#include "pico/bootrom.h"
#include "pico/stdlib.h"
+// just here to make FreeRTOS happy
+#include "FreeRTOS.h"
+
+#include "task.h"
+
void initializeCommunication() {
// check if we crash last time -> reboot into boot rom mode
if (watchdog_enable_caused_reboot()) {
diff --git a/test/hardware/TestMiddleware/CMakeLists.txt b/test/hardware/TestMiddleware/CMakeLists.txt
index e4cf843c..787675d9 100644
--- a/test/hardware/TestMiddleware/CMakeLists.txt
+++ b/test/hardware/TestMiddleware/CMakeLists.txt
@@ -1,12 +1,17 @@
-add_executable(hardware-test_middleware HardwaretestMiddleware.c)
-target_link_libraries(hardware-test_middleware
- common_lib
- pico_stdlib
- hardware_spi
- network_lib
- esp_lib
- fpga_configuration_handler
- sleep_interface
- middleware_lib)
-target_compile_definitions(hardware-test_middleware PRIVATE DEBUG)
-create_enV5_executable(hardware-test_middleware)
+add_executable(HardwareTestMiddleware HardwareTestMiddleware.c)
+target_link_libraries(HardwareTestMiddleware
+ Common
+ EnV5HwConfiguration
+ EnV5HwController
+ Esp
+ Flash
+ FpgaConfigurationHandler
+ Http
+ Network
+ Middleware
+ Pico::pico_stdio
+ Pico::pico_stdlib
+ Pico::hardware_spi
+)
+target_compile_definitions(HardwareTestMiddleware PRIVATE DEBUG)
+create_enV5_executable(HardwareTestMiddleware)
diff --git a/test/hardware/TestMiddleware/HardwaretestMiddleware.c b/test/hardware/TestMiddleware/HardwareTestMiddleware.c
similarity index 99%
rename from test/hardware/TestMiddleware/HardwaretestMiddleware.c
rename to test/hardware/TestMiddleware/HardwareTestMiddleware.c
index 24690a48..2df1fb35 100644
--- a/test/hardware/TestMiddleware/HardwaretestMiddleware.c
+++ b/test/hardware/TestMiddleware/HardwareTestMiddleware.c
@@ -12,25 +12,23 @@
*/
#define SOURCE_FILE "MIDDLEWARE-HWTEST"
-
-#include
-#include
-
-#include "hardware/spi.h"
-#include "pico/stdio.h"
-#include "pico/stdio_usb.h"
-
#include "Common.h"
#include "EnV5HwConfiguration.h"
#include "EnV5HwController.h"
+
#include "Esp.h"
#include "Flash.h"
#include "FpgaConfigurationHandler.h"
#include "HTTP.h"
#include "Network.h"
-#include "Spi.h"
#include "middleware.h"
+#include "hardware/spi.h"
+#include "pico/stdio.h"
+#include "pico/stdio_usb.h"
+
+#include
+
char baseUrl[] = "http://192.168.178.24:5000/getconfig";
char lengthUrl[] = "http://192.168.178.24:5000/length";
uint32_t sectorIdForConfig = 1;
diff --git a/test/hardware/TestNetworking/CMakeLists.txt b/test/hardware/TestNetworking/CMakeLists.txt
index b4ad7232..e9a0a9e5 100644
--- a/test/hardware/TestNetworking/CMakeLists.txt
+++ b/test/hardware/TestNetworking/CMakeLists.txt
@@ -1,91 +1,114 @@
-################## test_network ##################
-add_executable(hardware-test_network HardwaretestNetwork.c)
-target_link_libraries(hardware-test_network
- common_lib
- pico_stdlib
- freeRtosUtils
- hardware-testHelper)
-target_compile_definitions(hardware-test_network PRIVATE DEBUG)
-create_enV5_executable(hardware-test_network)
-################## test_networkStrength ##################
-add_executable(hardware-test_checknetwork HardwaretestCheckNetwork.c)
-target_link_libraries(hardware-test_checknetwork
- common_lib
- pico_stdlib
- freeRtosUtils
- hardware-testHelper)
-target_compile_definitions(hardware-test_checknetwork PRIVATE DEBUG)
-create_enV5_executable(hardware-test_checknetwork)
-
-################## test_MqttKeepAlive ##################
-add_executable(hardware-test_MQTTKeepalive HardwaretestMqttKeepAlive.c)
-target_link_libraries(hardware-test_MQTTKeepalive
- common_lib
- pico_stdlib
- freeRtosUtils
- hardware-testHelper)
-target_compile_definitions(hardware-test_MQTTKeepalive PRIVATE DEBUG)
-create_enV5_executable(hardware-test_MQTTKeepalive)
-################## test_MQTTPublish ##################
-add_executable(hardware-test_MQTTPublish HardwaretestMqttPublish.c)
-target_link_libraries(hardware-test_MQTTPublish
- common_lib
- pico_stdlib
- freeRtosUtils
- hardware-testHelper)
-target_compile_definitions(hardware-test_MQTTPublish PRIVATE DEBUG)
-create_enV5_executable(hardware-test_MQTTPublish)
-################## test_MQTTSubscribe ##################
-# creates executable
-add_executable(hardware-test_MQTTSubscribe HardwaretestMqttSubscribe.c)
-target_link_libraries(hardware-test_MQTTSubscribe
- common_lib
- pico_stdlib
- espBroker_lib
- freeRtosUtils
- hardware-testHelper)
-target_compile_definitions(hardware-test_MQTTSubscribe PRIVATE DEBUG)
-create_enV5_executable(hardware-test_MQTTSubscribe)
-################## test_SubscribeUnsubscribe ##################
-add_executable(hardware-test_MQTTSubscribeUnsubscribe HardwaretestMqttSubscribeUnsubscribe.c)
-target_link_libraries(hardware-test_MQTTSubscribeUnsubscribe
- common_lib
- pico_stdlib
- freeRtosUtils
- hardware-testHelper)
-target_compile_definitions(hardware-test_MQTTSubscribeUnsubscribe PRIVATE DEBUG)
-create_enV5_executable(hardware-test_MQTTSubscribeUnsubscribe)
-################## test_MQTTPublishSubscribe ##################
-add_executable(hardware-test_MQTTPublishSubscribe HardwaretestMqttPublishSubscribe.c)
-target_link_libraries(hardware-test_MQTTPublishSubscribe
- common_lib
- pico_stdlib
- espBroker_lib
- freeRtosUtils
- hardware-testHelper)
-target_compile_definitions(hardware-test_MQTTPublishSubscribe PRIVATE DEBUG)
-create_enV5_executable(hardware-test_MQTTPublishSubscribe)
-
-################## test_Durability ##################
-add_executable(hardware-test_Durability HardwaretestDurability.c)
-target_link_libraries(hardware-test_Durability
- common_lib
- sensor_lib_pac193x
- hardware_i2c
- pico_stdlib
- freeRtosUtils
- hardware-testHelper)
-target_compile_definitions(hardware-test_Durability PRIVATE DEBUG)
-create_enV5_executable(hardware-test_Durability)
-
-################## test_HTTP ##################
-add_executable(hardware-test_HTTP HardwaretestHTTP.c)
-target_link_libraries(hardware-test_HTTP
- common_lib
- pico_stdlib
- freeRtosUtils
- network_lib
- http_lib
- hardware-testHelper)
-target_compile_definitions(hardware-test_HTTP PRIVATE DEBUG)
-create_enV5_executable(hardware-test_HTTP)
+if(BUILDING_FOR_ELASTIC_NODE)
+
+ add_library(NetworkTestCommon INTERFACE)
+ target_link_libraries(NetworkTestCommon INTERFACE
+ Common
+ freeRtosUtils
+ HardwareTestHelper
+ MqttBroker
+ Network
+ Pico::pico_stdlib
+ RuntimeC::Protocol
+ )
+
+
+ add_executable(HardwareTestNetwork HardwareTestNetwork.c)
+ target_link_libraries(HardwareTestNetwork PRIVATE
+ NetworkTestCommon
+ )
+ target_compile_definitions(HardwareTestNetwork PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestNetwork)
+
+
+ add_executable(HardwareTestCheckNetwork HardwareTestCheckNetwork.c)
+ target_link_libraries(HardwareTestCheckNetwork PRIVATE
+ NetworkTestCommon
+ )
+ target_compile_definitions(HardwareTestCheckNetwork PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestCheckNetwork)
+
+
+ add_executable(HardwareTestMqttKeepAlive HardwareTestMqttKeepAlive.c)
+ target_link_libraries(HardwareTestMqttKeepAlive PRIVATE
+ NetworkTestCommon
+ Sleep
+ )
+ target_compile_definitions(HardwareTestMqttKeepAlive PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestMqttKeepAlive)
+
+
+ add_executable(HardwareTestMqttPublish HardwareTestMqttPublish.c)
+ target_link_libraries(HardwareTestMqttPublish PRIVATE
+ NetworkTestCommon
+ )
+ target_compile_definitions(HardwareTestMqttPublish PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestMqttPublish)
+
+
+ add_executable(HardwareTestMqttSubscribe HardwareTestMqttSubscribe.c)
+ target_link_libraries(HardwareTestMqttSubscribe PRIVATE
+ NetworkTestCommon
+ Esp
+ )
+ target_compile_definitions(HardwareTestMqttSubscribe PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestMqttSubscribe)
+
+
+ add_executable(HardwareTestMqttSubscribeUnsubscribe HardwareTestMqttSubscribeUnsubscribe.c)
+ target_link_libraries(HardwareTestMqttSubscribeUnsubscribe PRIVATE
+ NetworkTestCommon
+ )
+ target_compile_definitions(HardwareTestMqttSubscribeUnsubscribe PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestMqttSubscribeUnsubscribe)
+
+
+ add_executable(HardwareTestMqttPublishSubscribe HardwareTestMqttPublishSubscribe.c)
+ target_link_libraries(HardwareTestMqttPublishSubscribe PRIVATE
+ NetworkTestCommon
+ Esp
+ )
+ target_compile_definitions(HardwareTestMqttPublishSubscribe PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestMqttPublishSubscribe)
+
+
+ add_executable(HardwareTestDurability HardwareTestDurability.c)
+ target_link_libraries(HardwareTestDurability PRIVATE
+ NetworkTestCommon
+ Pac193x
+ Esp
+ freeRtos::FreeRTOS-Kernel
+ Pico::hardware_i2c
+ )
+ target_compile_definitions(HardwareTestDurability PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestDurability)
+
+
+ add_executable(HardwareTestHTTP HardwareTestHTTP.c)
+ target_link_libraries(HardwareTestHTTP PRIVATE
+ NetworkTestCommon
+ Network
+ Http
+ CException
+ )
+ target_compile_definitions(HardwareTestHTTP PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestHTTP)
+
+
+ add_executable(HardwareTestPublishSensor HardwareTestPublishSensor.c)
+ target_link_libraries(HardwareTestPublishSensor PRIVATE
+ NetworkTestCommon
+ Adxl345b
+ Esp
+ Pac193x
+ Spi
+ Network
+ Http
+ EnV5HwController
+
+ Pico::hardware_i2c
+ Pico::hardware_spi
+ )
+ target_compile_definitions(HardwareTestPublishSensor PRIVATE DEBUG)
+ create_enV5_executable(HardwareTestPublishSensor)
+
+endif()
\ No newline at end of file
diff --git a/test/hardware/TestNetworking/HardwaretestCheckNetwork.c b/test/hardware/TestNetworking/HardwareTestCheckNetwork.c
similarity index 95%
rename from test/hardware/TestNetworking/HardwaretestCheckNetwork.c
rename to test/hardware/TestNetworking/HardwareTestCheckNetwork.c
index 8c5845e7..3232ac72 100644
--- a/test/hardware/TestNetworking/HardwaretestCheckNetwork.c
+++ b/test/hardware/TestNetworking/HardwareTestCheckNetwork.c
@@ -2,7 +2,7 @@
#include "Common.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "Network.h"
/*!
diff --git a/test/hardware/TestNetworking/HardwaretestDurability.c b/test/hardware/TestNetworking/HardwareTestDurability.c
similarity index 99%
rename from test/hardware/TestNetworking/HardwaretestDurability.c
rename to test/hardware/TestNetworking/HardwareTestDurability.c
index 71063c33..25ae9cfb 100644
--- a/test/hardware/TestNetworking/HardwaretestDurability.c
+++ b/test/hardware/TestNetworking/HardwareTestDurability.c
@@ -11,7 +11,7 @@
#include "Esp.h"
#include "FreeRtosQueueWrapper.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "MqttBroker.h"
#include "Pac193x.h"
#include "Protocol.h"
diff --git a/test/hardware/TestNetworking/HardwaretestHTTP.c b/test/hardware/TestNetworking/HardwareTestHTTP.c
similarity index 95%
rename from test/hardware/TestNetworking/HardwaretestHTTP.c
rename to test/hardware/TestNetworking/HardwareTestHTTP.c
index 51331619..81476a6e 100644
--- a/test/hardware/TestNetworking/HardwaretestHTTP.c
+++ b/test/hardware/TestNetworking/HardwareTestHTTP.c
@@ -7,7 +7,7 @@
#include "CException.h"
#include "Common.h"
#include "HTTP.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
void _Noreturn runTest(void) {
PRINT("=== STARTING TEST ===");
diff --git a/test/hardware/TestNetworking/HardwaretestMqttKeepAlive.c b/test/hardware/TestNetworking/HardwareTestMqttKeepAlive.c
similarity index 95%
rename from test/hardware/TestNetworking/HardwaretestMqttKeepAlive.c
rename to test/hardware/TestNetworking/HardwareTestMqttKeepAlive.c
index e1fa4cd9..37f0520c 100644
--- a/test/hardware/TestNetworking/HardwaretestMqttKeepAlive.c
+++ b/test/hardware/TestNetworking/HardwareTestMqttKeepAlive.c
@@ -7,7 +7,7 @@
*/
#include "Common.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "MqttBroker.h"
#include "Sleep.h"
diff --git a/test/hardware/TestNetworking/HardwaretestMqttPublish.c b/test/hardware/TestNetworking/HardwareTestMqttPublish.c
similarity index 96%
rename from test/hardware/TestNetworking/HardwaretestMqttPublish.c
rename to test/hardware/TestNetworking/HardwareTestMqttPublish.c
index d881d189..71fa72c5 100644
--- a/test/hardware/TestNetworking/HardwaretestMqttPublish.c
+++ b/test/hardware/TestNetworking/HardwareTestMqttPublish.c
@@ -2,7 +2,7 @@
#include "Common.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "MqttBroker.h"
#include "Protocol.h"
diff --git a/test/hardware/TestNetworking/HardwaretestMqttPublishSubscribe.c b/test/hardware/TestNetworking/HardwareTestMqttPublishSubscribe.c
similarity index 98%
rename from test/hardware/TestNetworking/HardwaretestMqttPublishSubscribe.c
rename to test/hardware/TestNetworking/HardwareTestMqttPublishSubscribe.c
index bb17c180..0c94d4cb 100644
--- a/test/hardware/TestNetworking/HardwaretestMqttPublishSubscribe.c
+++ b/test/hardware/TestNetworking/HardwareTestMqttPublishSubscribe.c
@@ -3,7 +3,7 @@
#include "Common.h"
#include "FreeRtosQueueWrapper.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "Protocol.h"
#include
diff --git a/test/hardware/TestNetworking/HardwaretestMqttSubscribe.c b/test/hardware/TestNetworking/HardwareTestMqttSubscribe.c
similarity index 98%
rename from test/hardware/TestNetworking/HardwaretestMqttSubscribe.c
rename to test/hardware/TestNetworking/HardwareTestMqttSubscribe.c
index d84222cb..0c85e5bb 100644
--- a/test/hardware/TestNetworking/HardwaretestMqttSubscribe.c
+++ b/test/hardware/TestNetworking/HardwareTestMqttSubscribe.c
@@ -3,7 +3,7 @@
#include "Common.h"
#include "FreeRtosQueueWrapper.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "MqttBroker.h"
#include "Protocol.h"
#include
diff --git a/test/hardware/TestNetworking/HardwaretestMqttSubscribeUnsubscribe.c b/test/hardware/TestNetworking/HardwareTestMqttSubscribeUnsubscribe.c
similarity index 96%
rename from test/hardware/TestNetworking/HardwaretestMqttSubscribeUnsubscribe.c
rename to test/hardware/TestNetworking/HardwareTestMqttSubscribeUnsubscribe.c
index e5ebef84..647d3b53 100644
--- a/test/hardware/TestNetworking/HardwaretestMqttSubscribeUnsubscribe.c
+++ b/test/hardware/TestNetworking/HardwareTestMqttSubscribeUnsubscribe.c
@@ -3,12 +3,10 @@
#include "Common.h"
#include "FreeRtosQueueWrapper.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "MqttBroker.h"
#include "Protocol.h"
-#include
#include
-#include
/*!
* Connects to Wi-Fi and MQTT Broker (Change in src/configuration.h).
diff --git a/test/hardware/TestNetworking/HardwaretestNetwork.c b/test/hardware/TestNetworking/HardwareTestNetwork.c
similarity index 95%
rename from test/hardware/TestNetworking/HardwaretestNetwork.c
rename to test/hardware/TestNetworking/HardwareTestNetwork.c
index 1b4bcf44..7009bb27 100644
--- a/test/hardware/TestNetworking/HardwaretestNetwork.c
+++ b/test/hardware/TestNetworking/HardwareTestNetwork.c
@@ -2,7 +2,7 @@
#include "Common.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "Network.h"
/*!
diff --git a/test/hardware/TestNetworking/HardwaretestPublishSensor.c b/test/hardware/TestNetworking/HardwareTestPublishSensor.c
similarity index 97%
rename from test/hardware/TestNetworking/HardwaretestPublishSensor.c
rename to test/hardware/TestNetworking/HardwareTestPublishSensor.c
index 8a7d3bc4..b8ddfe2d 100644
--- a/test/hardware/TestNetworking/HardwaretestPublishSensor.c
+++ b/test/hardware/TestNetworking/HardwareTestPublishSensor.c
@@ -1,13 +1,12 @@
#define SOURCE_FILE "MAIN"
// internal headers
-#include "../../../src/hal/enV5HwController/include/HwConfig.h"
#include "Adxl345b.h"
#include "Common.h"
#include "Esp.h"
#include "FreeRtosQueueWrapper.h"
#include "FreeRtosTaskWrapper.h"
-#include "HardwaretestHelper.h"
+#include "HardwareTestHelper.h"
#include "MqttBroker.h"
#include "Pac193x.h"
#include "Protocol.h"
@@ -24,6 +23,13 @@
#include
#include
+/* region SENSOR DEFINITION */
+adxl345bSensorConfiguration_t sensor = {
+ .i2c_slave_address = ADXL345B_I2C_ALTERNATE_ADDRESS,
+ .i2c_host = i2c1,
+};
+/* endregion SENSOR DEFINITION */
+
/* region POWER-SENSOR 1 */
static pac193xSensorConfiguration_t powersensor1 = {
@@ -95,7 +101,7 @@ void init(void) {
// initialize WiFi and MQTT broker
connectToNetwork();
- connectToMQTT();
+ connectToMqttBroker();
// initialize power sensors
pac193xErrorCode_t errorCode;
@@ -119,7 +125,7 @@ void init(void) {
}
i2c_set_baudrate(i2c1, 2000000);
- errorCode = adxl345bInit(i2cConfig.i2cInstance, ADXL345B_I2C_ALTERNATE_ADDRESS);
+ errorCode = adxl345bInit(sensor);
if (errorCode == ADXL345B_NO_ERROR) {
PRINT("Initialised ADXL345B.");
} else {
diff --git a/test/hardware/TestStub/CMakeLists.txt b/test/hardware/TestStub/CMakeLists.txt
index a1b70607..ce725143 100644
--- a/test/hardware/TestStub/CMakeLists.txt
+++ b/test/hardware/TestStub/CMakeLists.txt
@@ -1,42 +1,39 @@
## Test with HTTP Dummy Server
-add_executable(hardware-test_stub-v1 HardwaretestStub.c)
-target_link_libraries(hardware-test_stub-v1
- common_lib
- pico_stdlib
- hardware_spi
- flash_lib
- enV5_hw_controller
- sleep_interface
- fpga_configuration_handler
- stub_v1_lib)
-target_compile_definitions(hardware-test_stub-v1 PRIVATE DEBUG)
-create_enV5_executable(hardware-test_stub-v1)
+add_executable(HardwareTestStub HardwareTestStub.c)
+target_link_libraries(HardwareTestStub
+ Common
+ EnV5HwController
+ EnV5HwConfiguration
+ Esp
+ Flash
+ FpgaConfigurationHandler
+ Http
+ Network
+ Stub
-## Test with HTTP Dummy Server
-add_executable(hardware-test_stub-v2 HardwaretestStub.c)
-target_link_libraries(hardware-test_stub-v2
- common_lib
- pico_stdlib
- hardware_spi
- flash_lib
- enV5_hw_controller
- sleep_interface
- fpga_configuration_handler
- stub_v2_lib)
-target_compile_definitions(hardware-test_stub-v2 PRIVATE DEBUG)
-create_enV5_executable(hardware-test_stub-v2)
+ Pico::pico_stdlib
+ Pico::hardware_spi
+)
+target_compile_definitions(HardwareTestStub PRIVATE DEBUG)
+create_enV5_executable(HardwareTestStub)
## Test in combination with Monitor
-add_executable(hardware-test_echoServerOTA HardwaretestStubWithMonitor.c)
-target_link_libraries(hardware-test_echoServerOTA
- common_lib
- pico_stdlib
- hardware_spi
- flash_lib
- enV5_hw_controller
- fpga_configuration_handler
- middleware_lib
- espBroker_lib
- stub_v1_lib)
-target_compile_definitions(hardware-test_echoServerOTA PRIVATE DEBUG)
-create_enV5_executable(hardware-test_echoServerOTA)
+add_executable(HardwareTestStubWithMonitor HardwareTestStubWithMonitor.c)
+target_link_libraries(HardwareTestStubWithMonitor
+ Common
+ EnV5HwConfiguration
+ EnV5HwController
+ Esp
+ FpgaConfigurationHandler
+ freeRtosUtils
+ MqttBroker
+ Network
+ Middleware
+ Flash
+
+ freeRtos::FreeRTOS-Kernel
+ Pico::pico_stdlib
+ RuntimeC::Protocol
+)
+target_compile_definitions(HardwareTestStubWithMonitor PRIVATE DEBUG)
+create_enV5_executable(HardwareTestStubWithMonitor)
diff --git a/test/hardware/TestStub/HardwaretestStub.c b/test/hardware/TestStub/HardwareTestStub.c
similarity index 100%
rename from test/hardware/TestStub/HardwaretestStub.c
rename to test/hardware/TestStub/HardwareTestStub.c
diff --git a/test/hardware/TestStub/HardwaretestStubWithMonitor.c b/test/hardware/TestStub/HardwareTestStubWithMonitor.c
similarity index 99%
rename from test/hardware/TestStub/HardwaretestStubWithMonitor.c
rename to test/hardware/TestStub/HardwareTestStubWithMonitor.c
index d95f7c7f..a68e8283 100644
--- a/test/hardware/TestStub/HardwaretestStubWithMonitor.c
+++ b/test/hardware/TestStub/HardwareTestStubWithMonitor.c
@@ -20,7 +20,6 @@
#include "Protocol.h"
#include "middleware.h"
-#include
#include
#include
diff --git a/test/hardware/TestUsbProtocol/CMakeLists.txt b/test/hardware/TestUsbProtocol/CMakeLists.txt
index 5720372e..9fdfc50a 100644
--- a/test/hardware/TestUsbProtocol/CMakeLists.txt
+++ b/test/hardware/TestUsbProtocol/CMakeLists.txt
@@ -1,10 +1,17 @@
## Test USB-Protocol
-add_executable(hardware-test_usb-protocol HardwaretestUsbProtocol.c)
-target_link_libraries(hardware-test_usb-protocol
- pico_stdlib
+add_executable(HardwareTestUsbProtocol HardwareTestUsbProtocol.c)
+target_link_libraries(HardwareTestUsbProtocol
+ UsbProtocol
+ EnV5HwConfiguration
+ EnV5HwController
+ Flash
+ Gpio
+ Sleep
+
CException
- enV5_hw_controller
- usb-protocol
- common_lib
+
+ Pico::pico_stdlib
+ Pico::hardware_spi
+
)
-create_enV5_executable(hardware-test_usb-protocol)
+create_enV5_executable(HardwareTestUsbProtocol)
diff --git a/test/hardware/TestUsbProtocol/HardwaretestUsbProtocol.c b/test/hardware/TestUsbProtocol/HardwareTestUsbProtocol.c
similarity index 99%
rename from test/hardware/TestUsbProtocol/HardwaretestUsbProtocol.c
rename to test/hardware/TestUsbProtocol/HardwareTestUsbProtocol.c
index 7464adfd..5b12b921 100644
--- a/test/hardware/TestUsbProtocol/HardwaretestUsbProtocol.c
+++ b/test/hardware/TestUsbProtocol/HardwareTestUsbProtocol.c
@@ -1,16 +1,18 @@
#define SOURCE_FILE "HW-TEST_USB-PROTOCOL"
-#include "CException.h"
-#include "hardware/spi.h"
-#include "pico/stdlib.h"
+#include "UsbProtocolBase.h"
+#include "UsbProtocolCustomCommands.h"
#include "EnV5HwConfiguration.h"
#include "EnV5HwController.h"
#include "Flash.h"
#include "Gpio.h"
#include "Sleep.h"
-#include "UsbProtocolBase.h"
-#include "UsbProtocolCustomCommands.h"
+
+#include "CException.h"
+
+#include "hardware/spi.h"
+#include "pico/stdlib.h"
spiConfiguration_t spiToFlash = {.spiInstance = FLASH_SPI_MODULE,
.baudrate = FLASH_SPI_BAUDRATE,
diff --git a/test/unit/Adxl345b/CMakeLists.txt b/test/unit/Adxl345b/CMakeLists.txt
index f2479819..df9bc476 100644
--- a/test/unit/Adxl345b/CMakeLists.txt
+++ b/test/unit/Adxl345b/CMakeLists.txt
@@ -1,10 +1,18 @@
-add_executable(unit-test_Adxl345bNew UnittestAdxl345bNew.c)
-target_include_directories(unit-test_Adxl345bNew PRIVATE ${CMAKE_SOURCE_DIR}/src/hal/i2c/include
+add_library(sensor_lib_adxl345b__srcs INTERFACE)
+target_include_directories(sensor_lib_adxl345b__srcs INTERFACE
+ ${CMAKE_SOURCE_DIR}/src/hal/i2c/include
${CMAKE_SOURCE_DIR}/src/hal/time/include
${CMAKE_SOURCE_DIR}/src/hal/sleep/include
${CMAKE_SOURCE_DIR}/src/sensor/adxl345b/include
)
-target_link_libraries(unit-test_Adxl345bNew sensor_lib_adxl345b__srcs unity)
-
+target_link_libraries(sensor_lib_adxl345b__srcs INTERFACE
+ Common
+ Adxl345b
+ SleepDummy
+ TimeDummy
+ I2cDummy
+)
+add_executable(UnitTestAdxl345bNew UnitTestAdxl345bNew.c)
+target_link_libraries(UnitTestAdxl345bNew PRIVATE sensor_lib_adxl345b__srcs unity)
add_test(unit-test_Adxl345bNew unit-test_Adxl345bNew)
\ No newline at end of file
diff --git a/test/unit/Adxl345b/UnitTestAdxl345bNew.c b/test/unit/Adxl345b/UnitTestAdxl345bNew.c
new file mode 100644
index 00000000..11b9bb22
--- /dev/null
+++ b/test/unit/Adxl345b/UnitTestAdxl345bNew.c
@@ -0,0 +1,418 @@
+#include "Adxl345b.h"
+#include "I2c.h"
+#include "Sleep.h"
+#include "Time.h"
+#include "unity.h"
+
+adxl345bSensorConfiguration_t sensor;
+
+uint64_t timeUs64(void) {
+ return 1;
+}
+
+uint32_t timeUs32(void) {
+ return 1;
+}
+
+void sleep_for_ms(uint32_t msToSleep) {}
+
+void sleep_for_us(uint64_t usToSleep) {}
+
+i2cErrorCode_t i2cWriteError;
+
+i2cErrorCode_t i2cReadError;
+
+i2cErrorCode_t i2cWriteCommand(i2c_inst_t *hostAddress, uint8_t slaveAddress,
+ const uint8_t *commandBuffer, uint16_t sizeOfCommandBuffer) {
+ return i2cWriteError;
+}
+
+i2cErrorCode_t i2cReadData(i2c_inst_t *hostAddress, uint8_t slaveAddress, uint8_t *readBuffer,
+ uint8_t sizeOfReadBuffer) {
+ return i2cReadError;
+}
+
+void setUp(void) {
+ /* Default: Point to Pass */
+ i2cWriteError = I2C_NO_ERROR;
+ i2cReadError = I2C_NO_ERROR;
+ adxl345bChangeMeasurementRange(sensor, ADXL345B_2G_RANGE);
+}
+
+void tearDown(void) {}
+
+/* region adxl345bReadSerialNumber */
+
+void adxl345bReadSerialNumberGetSendCommandFail_errorIfHardwareFails(void) {
+ uint8_t serialNumber;
+ i2cWriteError = I2C_INIT_ERROR;
+ adxl345bErrorCode_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
+}
+
+void adxl345bReadSerialNumberGetSendCommandFail_errorIfAckMissing(void) {
+ uint8_t serialNumber;
+ i2cWriteError = I2C_ACK_ERROR;
+
+ adxl345bErrorCode_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
+}
+
+void adxl345bReadSerialNumberGetReceiveDataFail_errorIfHardwareFails(void) {
+ uint8_t serialNumber;
+ i2cReadError = I2C_INIT_ERROR;
+
+ adxl345bErrorCode_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void adxl345bReadSerialNumberGetReceiveDataFail_errorIfAckMissing(void) {
+ uint8_t serialNumber;
+ i2cReadError = I2C_ACK_ERROR;
+
+ adxl345bErrorCode_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void adxl345bReadSerialNumberReadSuccessful(void) {
+ uint8_t serialNumber;
+
+ uint8_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_NO_ERROR, errorCode);
+}
+
+// START HERE: does this test make sense?
+void adxl345bReadSerialNumberReadCorrectValue(void) {
+ uint8_t expected_serialNumber, actual_serialNumber;
+
+ /* fill expected with random generated */
+ expected_serialNumber = 0b10011111;
+
+ adxl345bReadSerialNumber(sensor, &actual_serialNumber);
+ TEST_ASSERT_EQUAL_UINT8(expected_serialNumber, actual_serialNumber);
+}
+
+/* endregion adxl345bReadSerialNumber */
+
+/* region adxl345bGetSingleMeasurement */
+
+void adxl345bGetSingleMeasurementGetSendCommandFail_errorIfHardwareFails(void) {
+ uint8_t rawData[6];
+ i2cWriteError = I2C_INIT_ERROR;
+
+ adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
+}
+
+void adxl345bGetSingleMeasurementGetSendCommandFail_errorIfAckMissing(void) {
+ uint8_t rawData[6];
+ i2cWriteError = I2C_ACK_ERROR;
+
+ adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
+}
+
+void adxl345bGetSingleMeasurementGetReceiveDataFail_errorIfHardwareFails(void) {
+ uint8_t rawData[6];
+ i2cReadError = I2C_INIT_ERROR;
+
+ adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void adxl345bGetSingleMeasurementGetReceiveDataFail_errorIfAckMissing(void) {
+ uint8_t rawData[6];
+ i2cReadError = I2C_ACK_ERROR;
+
+ adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void adxl345bGetSingleMeasurementReadSuccessful(void) {
+ uint8_t rawData[6];
+ adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_NO_ERROR, errorCode);
+}
+
+// void adxl345bGetSingleMeasurementReadCorrectValue(void) {
+// uint8_t sizeOfRawData = 6;
+// uint8_t rawData[sizeOfRawData];
+//
+// adxl345bGetSingleMeasurement(sensor, rawData);
+// for(int i = 0; i < sizeOfRawData; i ++){
+// TEST_ASSERT_EQUAL_UINT8(byteZero, rawData[i]);
+// }
+//
+// }
+
+/* endregion adxl345bGetSingleMeasurement */
+
+/* region adxl345bGetMultipleMeasurements */
+
+void adxl345bGetMultipleMeasurementsGetSendCommandFail_errorIfHardwareFails(void) {
+ uint32_t numberOfSamples = 1;
+ uint8_t *samples[numberOfSamples];
+
+ i2cWriteError = I2C_INIT_ERROR;
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
+}
+
+void adxl345bGetMultipleMeasurementsGetSendCommandFail_errorIfAckMissing(void) {
+ uint32_t numberOfSamples = 16;
+ uint8_t *samples[numberOfSamples];
+ i2cWriteError = I2C_ACK_ERROR;
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
+}
+
+void adxl345bGetMultipleMeasurementsGetReceiveDataFail_errorIfHardwareFails(void) {
+ uint32_t numberOfSamples = 32;
+ uint8_t *samples[numberOfSamples];
+ i2cReadError = I2C_INIT_ERROR;
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void adxl345bGetMultipleMeasurementsGetReceiveDataFail_errorIfAckMissing(void) {
+ uint32_t numberOfSamples = 33;
+ uint8_t *samples[numberOfSamples];
+ i2cReadError = I2C_ACK_ERROR;
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void adxl345bGetMultipleMeasurementsReadSuccessful(void) {
+ uint32_t numberOfSamples = 50;
+ uint8_t sizeOfRawData = 6;
+ uint8_t *samples[numberOfSamples];
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_NO_ERROR, errorCode);
+}
+
+// void adxl345bGetMultipleMeasurementsReadCorrectValues(void) {
+// /*generate Array for Data*/
+// uint8_t sizeOfRawData = 6;
+// uint32_t numberOfSamples = 5;
+// uint8_t *samples[numberOfSamples];
+//
+// /* change ReadCommands to generate expected raw data received from I2C*/
+// uint8_t expectedRawData = byteZero;
+// for(int readMode = 0; readMode < 3 ; readMode++) {
+// switch (readMode) {
+// case 0: //use default StreamMode
+// break;
+// case 1:
+// i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInFifoMode;
+// expectedRawData = byteOne;
+// break;
+// case 2:
+// i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInTriggerMode;
+// expectedRawData = byteTwo;
+// break;
+// }
+// adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
+//
+//
+// for (int i = 0; i < numberOfSamples; i++) {
+// for (int j = 0; j < sizeOfRawData; j++) {
+// TEST_ASSERT_EQUAL_UINT8(expectedRawData, samples[i][j]);
+// }
+// }
+// }
+// }
+
+/* endregion adxl345bGetMultipleMeasurements */
+
+/* region adxl345bGetMeasurementsForNSeconds */
+
+void adxl345bGetMeasurementsForNSecondsGetSendCommandFail_errorIfHardwareFails(void) {
+ uint32_t numberOfSamples = 50;
+ uint8_t sizeOfRawData = 6;
+ uint8_t samples[numberOfSamples * sizeOfRawData];
+ uint32_t seconds = 3;
+
+ i2cWriteError = I2C_INIT_ERROR;
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
+
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
+}
+
+void adxl345bGetMeasurementsForNSecondsGetSendCommandFail_errorIfAckMissing(void) {
+ uint32_t numberOfSamples = 16;
+ uint8_t sizeOfRawData = 6;
+ uint8_t samples[numberOfSamples * sizeOfRawData];
+ uint32_t seconds = 3;
+ i2cWriteError = I2C_ACK_ERROR;
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
+}
+
+void adxl345bGetMeasurementsForNSecondsGetReceiveDataFail_errorIfHardwareFails(void) {
+ uint32_t numberOfSamples = 32;
+ uint8_t sizeOfRawData = 6;
+ uint8_t samples[numberOfSamples * sizeOfRawData];
+ uint32_t seconds = 3;
+ i2cReadError = I2C_INIT_ERROR;
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void adxl345bGetMeasurementsForNSecondsGetReceiveDataFail_errorIfAckMissing(void) {
+ uint32_t numberOfSamples = 33;
+ uint8_t sizeOfRawData = 6;
+ uint8_t samples[numberOfSamples * sizeOfRawData];
+ uint32_t seconds = 3;
+ i2cReadError = I2C_ACK_ERROR;
+
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void adxl345bGetMeasurementsForNSecondsReadSuccessful(void) {
+ uint32_t numberOfSamples = 1;
+ uint8_t sizeOfRawData = 6;
+ uint32_t seconds = 3;
+ uint8_t samples[numberOfSamples * sizeOfRawData];
+ adxl345bErrorCode_t errorCode =
+ adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
+ TEST_ASSERT_EQUAL_UINT8(ADXL345B_NO_ERROR, errorCode);
+}
+
+// void adxl345bGetMeasurementsForNSecondsReadCorrectValues(void) {
+// /*generate Array for Data*/
+// uint8_t sizeOfRawData = 6;
+// uint32_t numberOfSamples = 5;
+// uint32_t seconds = 3;
+// uint8_t *samples[numberOfSamples];
+
+// /* change ReadCommands to generate expected raw data received from I2C*/
+// uint8_t expectedRawData = byteZero;
+// for(int readMode = 0; readMode < 3 ; readMode++) {
+// switch (readMode) {
+// case 0: //use default StreamMode
+// break;
+// case 1:
+// i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInFifoMode;
+// expectedRawData = byteOne;
+// break;
+// case 2:
+// i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInTriggerMode;
+// expectedRawData = byteTwo;
+// break;
+// }
+// adxl345bGetMeasurementsForNSeconds(sensor, samples, seconds, numberOfSamples);
+//
+//
+// for (int i = 0; i < numberOfSamples; i++) {
+// for (int j = 0; j < sizeOfRawData; j++) {
+// TEST_ASSERT_EQUAL_UINT8(expectedRawData, samples[i][j]);
+// }
+// }
+// }
+//}
+///* endregion adxl345bGetMeasurementsForNMilliseconds */
+//
+//
+//
+// void adxl345bConvertDataXYZCorrectValue(void) {
+// /* test assumes that 2G Full Range is the used Range */
+// i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInTriggerMode;
+//
+// float expected_xAxis = 0, expected_yAxis = 0, expected_zAxis = 0;
+// float actual_xAxis = 0, actual_yAxis = 0, actual_zAxis = 0;
+// const uint8_t MSB_MASK = 0b00000011;
+// const float SCALE_FACTOR_FOR_RANGE = 0.0043f;
+// /* only used lower 2 bits -> 2G Range consists of 10 Bit*/
+// uint8_t topByte = byteTwo & MSB_MASK;
+//
+// /* set rawData */
+// uint8_t sizeOfRawData = 6;
+// uint8_t rawData[sizeOfRawData];
+// for(int i = 0; i < sizeOfRawData; i ++){
+// rawData[i] = byteTwo;
+// }
+//
+// /* fill expected with random generated */
+// if (topByte <= (MSB_MASK >> 1)) {
+// /* CASE: positive value */
+// int rawValue = (int)(((uint16_t)(topByte & MSB_MASK) << 8) | (uint16_t)byteTwo);
+// float realValue = (float)rawValue * SCALE_FACTOR_FOR_RANGE;
+// expected_xAxis = expected_yAxis = expected_zAxis = realValue;
+// } else {
+// /* CASE: negative value
+// *
+// * 1. revert 10 bit two complement
+// * -> number-1 and Flip least 9 bits
+// * 2. convert to float value
+// * 3. multiply with (-1)
+// * 4. multiply with scale factor
+// */
+// uint16_t rawValue = ((uint16_t)(topByte & (MSB_MASK >> 1)) << 8) | (uint16_t)byteTwo;
+// rawValue = (rawValue - 0x0001) ^ (((MSB_MASK >> 1) << 8) | 0x00FF);
+// float realValue = (-1) * (float)rawValue * SCALE_FACTOR_FOR_RANGE;
+// expected_xAxis = expected_yAxis = expected_zAxis = realValue;
+// }
+// printf("actual vorher: %f %f %f ",actual_xAxis, actual_yAxis, actual_zAxis);
+//
+// adxl345bConvertDataXYZ(&actual_xAxis, &actual_yAxis, &actual_zAxis, rawData);
+// printf("actual nachher:%f %f %f ",actual_xAxis, actual_yAxis, actual_zAxis);
+// TEST_ASSERT_EQUAL_FLOAT(expected_xAxis, actual_xAxis);
+// TEST_ASSERT_EQUAL_FLOAT(expected_yAxis, actual_yAxis);
+// TEST_ASSERT_EQUAL_FLOAT(expected_zAxis, actual_zAxis);
+//}
+
+/* endregion */
+
+int main(void) {
+ UNITY_BEGIN();
+
+ RUN_TEST(adxl345bReadSerialNumberGetSendCommandFail_errorIfHardwareFails);
+ RUN_TEST(adxl345bReadSerialNumberGetSendCommandFail_errorIfAckMissing);
+ RUN_TEST(adxl345bReadSerialNumberGetReceiveDataFail_errorIfHardwareFails);
+ RUN_TEST(adxl345bReadSerialNumberGetReceiveDataFail_errorIfAckMissing);
+ RUN_TEST(adxl345bReadSerialNumberReadSuccessful);
+ RUN_TEST(adxl345bReadSerialNumberReadCorrectValue); // currently fails
+
+ RUN_TEST(adxl345bGetSingleMeasurementGetSendCommandFail_errorIfHardwareFails);
+ RUN_TEST(adxl345bGetSingleMeasurementGetSendCommandFail_errorIfAckMissing);
+ RUN_TEST(adxl345bGetSingleMeasurementGetReceiveDataFail_errorIfHardwareFails);
+ RUN_TEST(adxl345bGetSingleMeasurementGetReceiveDataFail_errorIfAckMissing);
+ // RUN_TEST(adxl345bGetSingleMeasurementReadSuccessful); //does not terminate
+ // RUN_TEST(adxl345bGetSingleMeasurementReadCorrectValue); //needs to be rewritten
+
+ RUN_TEST(adxl345bGetMultipleMeasurementsGetSendCommandFail_errorIfHardwareFails);
+ RUN_TEST(adxl345bGetMultipleMeasurementsGetSendCommandFail_errorIfAckMissing);
+ RUN_TEST(adxl345bGetMultipleMeasurementsGetReceiveDataFail_errorIfHardwareFails);
+ RUN_TEST(adxl345bGetMultipleMeasurementsGetReceiveDataFail_errorIfAckMissing);
+ // RUN_TEST(adxl345bGetMultipleMeasurementsReadSuccessful); //numerical error
+ // RUN_TEST(adxl345bGetMultipleMeasurementsReadCorrectValues); //needs to be rewritten
+
+ RUN_TEST(adxl345bGetMeasurementsForNSecondsGetSendCommandFail_errorIfHardwareFails);
+ RUN_TEST(adxl345bGetMeasurementsForNSecondsGetSendCommandFail_errorIfAckMissing);
+ RUN_TEST(adxl345bGetMeasurementsForNSecondsGetReceiveDataFail_errorIfHardwareFails);
+ RUN_TEST(adxl345bGetMeasurementsForNSecondsGetReceiveDataFail_errorIfAckMissing);
+ // RUN_TEST(adxl345bGetMeasurementsForNSecondsReadSuccessful); //does not terminate
+ // RUN_TEST(adxl345bGetMeasurementsForNSecondsReadCorrectValues); //needs to be rewritten
+
+ // RUN_TEST(adxl345bConvertDataXYZCorrectValue); //needs to be rewritten
+
+ return UNITY_END();
+}
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 5eb39a30..1d665797 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -1,79 +1,85 @@
##############################################
## region UNIT-TEST: unit-test_sht3
-add_executable(unit-test_sht3x ${CMAKE_CURRENT_LIST_DIR}/UnittestSht3x.c)
-target_link_libraries(unit-test_sht3x
- sensor_lib_sht3x
- i2c_interface
- unity)
-add_test(unit-test_sht3x unit-test_sht3x)
-## endregion
-##############################################
-## region UNIT-TEST: unit-test_adxl345b
-add_executable(unit-test_adxl345b ${CMAKE_CURRENT_LIST_DIR}/UnittestAdxl345b.c)
-target_link_libraries(unit-test_adxl345b
- sensor_lib_adxl345b
- time_interface
- unity)
-add_test(unit-test_adxl345b unit-test_adxl345b)
-## endregion
-##############################################
-## region UNIT-TEST: unit-test_pac193x
-add_executable(unit-test_pac193x ${CMAKE_CURRENT_LIST_DIR}/UnittestPac193x.c)
-target_link_libraries(unit-test_pac193x
- sensor_lib_pac193x
- unity)
-add_test(unit-test_pac193x unit-test_pac193x)
-## endregion
-##############################################
-## region UNIT-TEST: unit-test_network
-add_executable(unit-test_network ${CMAKE_CURRENT_LIST_DIR}/UnittestNetwork.c)
-target_link_libraries(unit-test_network
- network_config
- esp_lib
- network_lib
- unity
- CException)
-add_test(unit-test_network unit-test_network)
-## endregion
-##############################################
-## region UNIT-TEST: unit-test_mqtt
-add_executable(unit-test_mqtt ${CMAKE_CURRENT_LIST_DIR}/UnittestMqtt.c)
-target_link_libraries(unit-test_mqtt
- network_config
- esp_lib
- espBroker_lib
- unity
- CException)
-add_test(unit-test_mqtt unit-test_mqtt)
-## endregion
-##############################################
-## region UNIT-TEST: unit-test_http
-add_executable(unit-test_http ${CMAKE_CURRENT_LIST_DIR}/UnittestHTTP.c)
-target_link_libraries(unit-test_http
- http_lib
- unity
- CException)
-add_test(unit-test_http unit-test_http)
-## endregion
-##############################################
-## region UNIT-TEST: unit-test_fpgaConfigurationHandler
-# replace http lib with dummy
-get_target_property(FPGA_CONFIG_LIBS fpga_configuration_handler INTERFACE_LINK_LIBRARIES)
-list(REMOVE_ITEM FPGA_CONFIG_LIBS http_lib)
-list(APPEND FPGA_CONFIG_LIBS http_lib_dummy)
-set_property(TARGET fpga_configuration_handler PROPERTY INTERFACE_LINK_LIBRARIES ${FPGA_CONFIG_LIBS})
-# replace http lib with dummy
-get_target_property(NET_LIBS network_lib INTERFACE_LINK_LIBRARIES)
-list(REMOVE_ITEM NET_LIBS http_lib)
-list(APPEND NET_LIBS http_lib_dummy)
-set_property(TARGET network_lib PROPERTY INTERFACE_LINK_LIBRARIES ${NET_LIBS})
-# add test executable
-add_executable(unit-test_fpgaConfigurationHandler ${CMAKE_CURRENT_LIST_DIR}/UnittestFpgaConfigurationHandler.c)
-target_link_libraries(unit-test_fpgaConfigurationHandler
- http_lib_dummy
- flash_lib
- fpga_configuration_handler
- unity)
-add_test(unit-test_fpgaConfigurationHandler unit-test_fpgaConfigurationHandler)
-## endregion
-##############################################
+add_subdirectory(dummies)
+include(unit_test.cmake)
+
+add_library(UnitTestCommon INTERFACE)
+target_link_libraries(UnitTestCommon INTERFACE
+ CException
+ Common
+)
+
+add_elastic_ai_unit_test(
+ LIB_UNDER_TEST
+ Sht3x
+ MORE_LIBS
+ UnitTestCommon
+ I2cDummy
+)
+
+add_elastic_ai_unit_test(
+ LIB_UNDER_TEST
+ FpgaConfigurationHandler
+ MORE_LIBS
+ UnitTestCommon
+ FlashDummy
+ HttpDummy
+)
+
+
+add_elastic_ai_unit_test(
+ LIB_UNDER_TEST
+ Pac193x
+ MORE_LIBS
+ Common
+ I2cDummy
+ GpioDummy
+ SleepDummy
+)
+
+add_elastic_ai_unit_test(
+ LIB_UNDER_TEST
+ Network
+ MORE_LIBS
+ Common
+ HttpDummy
+ RtosDummy
+ EspDummy
+ CException
+ NetworkConfig
+)
+
+add_elastic_ai_unit_test(
+ LIB_UNDER_TEST
+ Http
+ MORE_LIBS
+ CException
+ Common
+ EspDummy
+)
+
+add_elastic_ai_unit_test(
+ LIB_UNDER_TEST
+ MqttBroker
+ MORE_LIBS
+ CException
+ Common
+ HttpDummy
+ EspDummy
+ topicMatcher
+ protocol
+ NetworkConfig
+ m
+)
+
+add_elastic_ai_unit_test(
+ LIB_UNDER_TEST
+ Adxl345b
+ MORE_LIBS
+ CException
+ Common
+ SleepDummy
+ I2cDummy
+ TimeDummy
+)
+
diff --git a/test/unit/FpgaConfigurationHandler/CMakeLists.txt b/test/unit/FpgaConfigurationHandler/CMakeLists.txt
new file mode 100644
index 00000000..44cd09f3
--- /dev/null
+++ b/test/unit/FpgaConfigurationHandler/CMakeLists.txt
@@ -0,0 +1,19 @@
+add_library(test_lib_fpga_config_handler__srcs INTERFACE)
+target_include_directories(test_lib_fpga_config_handler__srcs INTERFACE
+ ${CMAKE_CURRENT_LIST_DIR}/src/hal/common/include
+ ${CMAKE_CURRENT_LIST_DIR}/src/flash/include
+ ${CMAKE_CURRENT_LIST_DIR}/src/network/http/include
+)
+target_link_libraries(test_lib_fpga_config_handler__srcs INTERFACE
+ Common
+ FpgaConfigurationHandler
+ HttpDummy
+ FlashDummy
+)
+
+add_executable(UnitTestFpgaConfigurationHandlerNew UnitTestFpgaConfigurationHandler.c)
+target_link_libraries(UnitTestFpgaConfigurationHandlerNew PRIVATE
+ test_lib_fpga_config_handler__srcs
+ unity
+)
+add_test(UnitTestFpgaConfigurationHandlerNew UnitTestFpgaConfigurationHandlerNew)
\ No newline at end of file
diff --git a/test/unit/UnittestFpgaConfigurationHandler.c b/test/unit/FpgaConfigurationHandler/UnitTestFpgaConfigurationHandler.c
similarity index 100%
rename from test/unit/UnittestFpgaConfigurationHandler.c
rename to test/unit/FpgaConfigurationHandler/UnitTestFpgaConfigurationHandler.c
diff --git a/test/unit/Http/CMakeLists.txt b/test/unit/Http/CMakeLists.txt
new file mode 100644
index 00000000..63f514dc
--- /dev/null
+++ b/test/unit/Http/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_library(test_lib_http__srcs INTERFACE)
+target_include_directories(test_lib_http__srcs INTERFACE
+ ${CMAKE_CURRENT_LIST_DIR}/src/network/esp/include
+)
+target_link_libraries(test_lib_http__srcs INTERFACE
+ Http
+ EspDummy
+ CException
+)
+
+add_executable(UnitTestHttpNew UnitTestHttp.c)
+target_link_libraries(UnitTestHttpNew PRIVATE test_lib_http__srcs unity)
+add_test(UnitTestHttpNew UnitTestHttpNew)
\ No newline at end of file
diff --git a/test/unit/UnittestHTTP.c b/test/unit/Http/UnitTestHttp.c
similarity index 100%
rename from test/unit/UnittestHTTP.c
rename to test/unit/Http/UnitTestHttp.c
diff --git a/test/unit/MqttBroker/CMakeLists.txt b/test/unit/MqttBroker/CMakeLists.txt
new file mode 100644
index 00000000..250de9a0
--- /dev/null
+++ b/test/unit/MqttBroker/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_library(test_lib_mqtt_broker__srcs INTERFACE)
+target_include_directories(test_lib_mqtt_broker__srcs INTERFACE
+ ${CMAKE_CURRENT_LIST_DIR}/src/network/esp/include
+)
+target_link_libraries(test_lib_mqtt_broker__srcs INTERFACE
+ MqttBroker
+ EspDummy
+ CException
+ m
+)
+
+add_executable(UnitTestMqttBrokerNew UnitTestMqttBroker.c)
+target_link_libraries(UnitTestMqttBrokerNew PRIVATE test_lib_mqtt_broker__srcs unity)
+add_test(UnitTestMqttBrokerNew UnitTestMqttBrokerNew)
\ No newline at end of file
diff --git a/test/unit/UnittestMqtt.c b/test/unit/MqttBroker/UnitTestMqttBroker.c
similarity index 99%
rename from test/unit/UnittestMqtt.c
rename to test/unit/MqttBroker/UnitTestMqttBroker.c
index 6d7b563a..f44e269a 100644
--- a/test/unit/UnittestMqtt.c
+++ b/test/unit/MqttBroker/UnitTestMqttBroker.c
@@ -2,7 +2,6 @@
#include "Esp.h"
#include "EspUnitTest.h"
#include "MqttBroker.h"
-
#include "unity.h"
extern mqttBrokerHost_t mqttHost;
diff --git a/test/unit/Network/CMakeLists.txt b/test/unit/Network/CMakeLists.txt
new file mode 100644
index 00000000..690149fb
--- /dev/null
+++ b/test/unit/Network/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_library(test_lib_network__srcs INTERFACE)
+target_include_directories(test_lib_network__srcs INTERFACE
+ ${CMAKE_CURRENT_LIST_DIR}/src/network/esp/include
+ ${CMAKE_CURRENT_LIST_DIR}/src/rtos/include
+)
+target_link_libraries(test_lib_network__srcs INTERFACE
+ Network
+ RtosDummy
+ EspDummy
+
+)
+
+add_executable(UnitTestNetworkNew UnitTestNetwork.c)
+target_link_libraries(UnitTestNetworkNew PRIVATE test_lib_network__srcs unity)
+add_test(UnitTestNetworkNew UnitTestNetworkNew)
\ No newline at end of file
diff --git a/test/unit/UnittestNetwork.c b/test/unit/Network/UnitTestNetwork.c
similarity index 100%
rename from test/unit/UnittestNetwork.c
rename to test/unit/Network/UnitTestNetwork.c
diff --git a/test/unit/Pac193x/CMakeLists.txt b/test/unit/Pac193x/CMakeLists.txt
new file mode 100644
index 00000000..4c7060df
--- /dev/null
+++ b/test/unit/Pac193x/CMakeLists.txt
@@ -0,0 +1,19 @@
+add_library(sensor_lib_pac193x__srcs INTERFACE)
+target_include_directories(sensor_lib_pac193x__srcs INTERFACE
+ ${CMAKE_CURRENT_LIST_DIR}/src/common/include
+ ${CMAKE_CURRENT_LIST_DIR}/src/hal/i2c/include
+ ${CMAKE_CURRENT_LIST_DIR}/src/hal/sleep/include
+ ${CMAKE_CURRENT_LIST_DIR}/src/hal/gpio/include
+ ${CMAKE_CURRENT_LIST_DIR}/src/sensor/pac193x/include
+)
+target_link_libraries(sensor_lib_pac193x__srcs INTERFACE
+ Pac193x
+ Common
+ GpioDummy
+ I2cDummy
+ SleepDummy
+)
+
+add_executable(UnitTestPac193xNew UnitTestPac193x.c)
+target_link_libraries(UnitTestPac193xNew PRIVATE sensor_lib_pac193x__srcs unity)
+add_test(UnitTestPac193xNew UnitTestPac193xNew)
\ No newline at end of file
diff --git a/test/unit/UnittestPac193x.c b/test/unit/Pac193x/UnitTestPac193x.c
similarity index 99%
rename from test/unit/UnittestPac193x.c
rename to test/unit/Pac193x/UnitTestPac193x.c
index 7c2607a6..bbfa7c9c 100644
--- a/test/unit/UnittestPac193x.c
+++ b/test/unit/Pac193x/UnitTestPac193x.c
@@ -1,10 +1,9 @@
-#include "Common.h"
#include "I2cUnitTest.h"
#include "Pac193x.h"
+#include "unity.h"
#include
#include
-#include
/* region CONSTANTS */
@@ -48,7 +47,6 @@ void tearDown(void) {}
void pac193xGetSensorInfoReturnSendCommandErrorIfHardwareFails(void) {
pac193xSensorId_t info;
i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
-
pac193xErrorCode_t errorCode = pac193xGetSensorInfo(SENSOR, &info);
TEST_ASSERT_EQUAL_UINT8(PAC193X_SEND_COMMAND_ERROR, errorCode);
}
diff --git a/test/unit/Sht3x/CMakeLists.txt b/test/unit/Sht3x/CMakeLists.txt
new file mode 100644
index 00000000..81200178
--- /dev/null
+++ b/test/unit/Sht3x/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_library(sensor_lib_sht3x__srcs INTERFACE)
+target_include_directories(sensor_lib_sht3x__srcs INTERFACE
+ ${CMAKE_CURRENT_LIST_DIR}/src/hal/i2c
+)
+target_link_libraries(sensor_lib_sht3x__srcs INTERFACE
+ Sht3x
+ CException
+ I2cDummy
+
+)
+
+add_executable(UnitTestSht3xNew UnitTestSht3x.c)
+target_link_libraries(UnitTestSht3xNew PRIVATE sensor_lib_sht3x__srcs unity)
+add_test(UnitTestSht3xNew UnitTestSht3xNew)
\ No newline at end of file
diff --git a/test/unit/UnittestSht3x.c b/test/unit/Sht3x/UnitTestSht3x.c
similarity index 100%
rename from test/unit/UnittestSht3x.c
rename to test/unit/Sht3x/UnitTestSht3x.c
diff --git a/test/unit/Adxl345b/UnittestAdxl345bNew.c b/test/unit/UnitTestAdxl345b.c
similarity index 100%
rename from test/unit/Adxl345b/UnittestAdxl345bNew.c
rename to test/unit/UnitTestAdxl345b.c
diff --git a/test/unit/UnitTestFpgaConfigurationHandler.c b/test/unit/UnitTestFpgaConfigurationHandler.c
new file mode 100644
index 00000000..1b626573
--- /dev/null
+++ b/test/unit/UnitTestFpgaConfigurationHandler.c
@@ -0,0 +1,98 @@
+#define SOURCE_FILE "FPGA-CONFIG-UTEST"
+
+#include
+
+#include "unity.h"
+
+#include "Flash.h"
+#include "FlashUnitTest.h"
+#include "FpgaConfigurationHandler.h"
+#include "httpDummy.h"
+
+flashConfiguration_t flashConfiguration;
+
+char baseUrl[] = "http://test.me.domain";
+uint8_t urlRequestCounter;
+
+void HttpGetCheckUrl(const char *url, HttpResponse_t **data) {
+ char *expectedUrl = malloc(sizeof(baseUrl) + 33 * sizeof(char));
+ sprintf(expectedUrl, "%s?chunkNumber=%u&chunkMaxSize=%u", baseUrl, urlRequestCounter,
+ flashGetBytesPerPage(NULL));
+
+ HttpResponse_t *emptyResponse = malloc(sizeof(HttpResponse_t));
+ emptyResponse->length = 0;
+ emptyResponse->response = NULL;
+ *data = emptyResponse;
+
+ TEST_ASSERT_EQUAL_STRING(expectedUrl, url);
+ urlRequestCounter++;
+}
+void HttpGetReturnDummyChunk(const char *url, HttpResponse_t **data) {
+ uint8_t *dummyData = calloc(1, flashConfiguration.bytesPerPage);
+ dummyData[0] = urlRequestCounter;
+
+ HttpResponse_t *httpResponse = malloc(sizeof(HttpResponse_t));
+ httpResponse->length = flashConfiguration.bytesPerPage;
+ httpResponse->response = dummyData;
+
+ *data = httpResponse;
+ urlRequestCounter++;
+}
+
+static void checkFlashData(size_t iterations, size_t offset) {
+ for (size_t index = 0; index < iterations; index++) {
+ uint8_t readData;
+ data_t readBuffer = {.length = 1, .data = &readData};
+
+ flashReadData(&flashConfiguration,
+ (offset * flashGetBytesPerSector(NULL)) +
+ (flashGetBytesPerPage(NULL) * index),
+ &readBuffer);
+
+ TEST_ASSERT_EQUAL_UINT8(index, readData);
+ }
+}
+
+void setUp(void) {
+ flashConfiguration.spiConfiguration = NULL;
+ flashConfiguration.bytesPerPage = flashGetBytesPerPage(NULL);
+ flashConfiguration.bytesPerSector = flashGetBytesPerSector(NULL);
+
+ flashSetUpDummyStorage(2 * flashConfiguration.bytesPerSector);
+ urlRequestCounter = 0;
+}
+
+void tearDown(void) {
+ flashRemoveDummyStorage();
+}
+
+void test_downloadViaHttpUrlCorrect() {
+ size_t pages = 10;
+ httpGetFunctionToUse = HttpGetCheckUrl;
+ fpgaConfigurationHandlerDownloadConfigurationViaHttp(
+ &flashConfiguration, baseUrl, pages * flashConfiguration.bytesPerPage, 0);
+}
+void test_downloadViaHttpOrderCorrect() {
+ size_t pages = 15;
+ httpGetFunctionToUse = HttpGetReturnDummyChunk;
+ fpgaConfigurationHandlerDownloadConfigurationViaHttp(
+ &flashConfiguration, baseUrl, pages * flashConfiguration.bytesPerPage, 0);
+ checkFlashData(pages, 0x0000);
+}
+void test_downloadViaHttpIntoFollowingSector() {
+ size_t pages = 20;
+ httpGetFunctionToUse = HttpGetReturnDummyChunk;
+ fpgaConfigurationHandlerDownloadConfigurationViaHttp(
+ &flashConfiguration, baseUrl, pages * flashConfiguration.bytesPerPage, 1);
+ checkFlashData(pages, 0x0001);
+}
+
+int main() {
+ UNITY_BEGIN();
+
+ RUN_TEST(test_downloadViaHttpUrlCorrect);
+ RUN_TEST(test_downloadViaHttpOrderCorrect);
+ RUN_TEST(test_downloadViaHttpIntoFollowingSector);
+
+ return UNITY_END();
+}
diff --git a/test/unit/UnitTestHttp.c b/test/unit/UnitTestHttp.c
new file mode 100644
index 00000000..50eb25be
--- /dev/null
+++ b/test/unit/UnitTestHttp.c
@@ -0,0 +1,84 @@
+#include "Esp.h"
+#include "EspUnitTest.h"
+#include "HTTP.h"
+
+#include "CException.h"
+#include "unity.h"
+
+#include
+
+void setUp() {
+ ESPDUMMY_RETURN_CODE = ESP_WRONG_ANSWER_RECEIVED;
+}
+
+void tearDown() {}
+
+static char *generateString(int lengthOfString) {
+ char *generatedString = malloc(sizeof('a') * lengthOfString);
+ for (int i = 0; i < lengthOfString; i++) {
+ generatedString[i] = 'a';
+ }
+ return generatedString;
+}
+
+void test_HttpEmptyBufferReturnsOnNullInput(void) {
+ HttpResponse_t *testResponse = NULL;
+ HTTPCleanResponseBuffer(testResponse);
+ TEST_ABORT();
+}
+
+void test_HTTPConnectionFailedThrowsException(void) {
+ espStatus.ChipStatus = ESP_CHIP_NOT_OK;
+ espStatus.WIFIStatus = NOT_CONNECTED;
+
+ CEXCEPTION_T e;
+ Try {
+ HTTPGet(NULL, NULL);
+ TEST_FAIL_MESSAGE("Should have thrown HTTP_CONNECTION_FAILED!");
+ }
+ Catch(e) {
+ TEST_ASSERT_EQUAL(HTTP_CONNECTION_FAILED, e);
+ }
+}
+
+void test_HTTPURLtoLongThrowsException(void) {
+ espStatus.ChipStatus = ESP_CHIP_OK;
+ espStatus.WIFIStatus = CONNECTED;
+ char *url = generateString(257);
+
+ CEXCEPTION_T e;
+ Try {
+ HTTPGet(url, NULL);
+ TEST_FAIL_MESSAGE("Should have thrown HTTP_CONNECTION_FAILED!");
+ }
+ Catch(e) {
+ TEST_ASSERT_EQUAL(HTTP_URL_TO_LONG, e);
+ }
+}
+void test_HTTPwrongCommand(void) {
+ espStatus.ChipStatus = ESP_CHIP_OK;
+ espStatus.WIFIStatus = CONNECTED;
+ HttpResponse_t *ptr;
+ HttpResponse_t **data = &ptr;
+ char *url = generateString(256);
+
+ CEXCEPTION_T e;
+ Try {
+ HTTPGet(url, data);
+ TEST_FAIL_MESSAGE("Should have thrown HTTP_CONNECTION_FAILED!");
+ }
+ Catch(e) {
+ TEST_ASSERT_EQUAL(HTTP_WRONG_RESPONSE, e);
+ }
+}
+
+int main(void) {
+ UNITY_BEGIN();
+
+ RUN_TEST(test_HttpEmptyBufferReturnsOnNullInput);
+ RUN_TEST(test_HTTPConnectionFailedThrowsException);
+ RUN_TEST(test_HTTPURLtoLongThrowsException);
+ RUN_TEST(test_HTTPwrongCommand);
+
+ return UNITY_END();
+}
diff --git a/test/unit/UnitTestMqttBroker.c b/test/unit/UnitTestMqttBroker.c
new file mode 100644
index 00000000..f44e269a
--- /dev/null
+++ b/test/unit/UnitTestMqttBroker.c
@@ -0,0 +1,114 @@
+#include "CException.h"
+#include "Esp.h"
+#include "EspUnitTest.h"
+#include "MqttBroker.h"
+#include "unity.h"
+
+extern mqttBrokerHost_t mqttHost;
+
+void setUp(void) {
+ espStatus.ChipStatus = ESP_CHIP_OK;
+ espStatus.WIFIStatus = CONNECTED;
+ espStatus.MQTTStatus = NOT_CONNECTED;
+
+ ESPDUMMY_RETURN_CODE = ESP_NO_ERROR;
+}
+
+void tearDown(void) {}
+
+/* region Test Functions */
+
+void test_ConnectToMqttBrokerSuccessful(void) {
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.MQTTStatus);
+ CEXCEPTION_T exception_mqttBrokerConnectToBroker;
+ Try {
+ mqttBrokerConnectToBroker("testBroker", "testClient");
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.MQTTStatus);
+ TEST_PASS();
+ }
+ Catch(exception_mqttBrokerConnectToBroker) {
+ TEST_FAIL_MESSAGE("Some Error occurred which caused a CException");
+ }
+ TEST_FAIL_MESSAGE("Something went wrong");
+}
+
+void test_ConnectToMqttBrokerEspFailed(void) {
+ espStatus.ChipStatus = ESP_CHIP_NOT_OK;
+ TEST_ASSERT_EQUAL(ESP_CHIP_NOT_OK, espStatus.ChipStatus);
+ CEXCEPTION_T exception_mqttBrokerConnectToBroker;
+ Try {
+ mqttBrokerConnectToBroker("testBroker", "testClient");
+ TEST_FAIL_MESSAGE("Should have thrown MQTT_ESP_CHIP_FAILED");
+ }
+ Catch(exception_mqttBrokerConnectToBroker) {
+ TEST_ASSERT_EQUAL(MQTT_ESP_CHIP_FAILED, exception_mqttBrokerConnectToBroker);
+ }
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.MQTTStatus);
+}
+
+void test_ConnectToMqttBrokerNoWifi(void) {
+ espStatus.WIFIStatus = NOT_CONNECTED;
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+ CEXCEPTION_T exception_mqttBrokerConnectToBroker;
+ Try {
+ mqttBrokerConnectToBroker("testBroker", "testClient");
+ TEST_FAIL_MESSAGE("Should have thrown MQTT_WIFI_FAILED");
+ }
+ Catch(exception_mqttBrokerConnectToBroker) {
+ TEST_ASSERT_EQUAL(MQTT_WIFI_FAILED, exception_mqttBrokerConnectToBroker);
+ }
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.MQTTStatus);
+}
+
+void test_ConnectToMqttBrokerAlreadyConnected(void) {
+ espStatus.MQTTStatus = CONNECTED;
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.MQTTStatus);
+ CEXCEPTION_T exception_mqttBrokerConnectToBroker;
+ Try {
+ mqttBrokerConnectToBroker("testBroker", "testClient");
+ TEST_FAIL_MESSAGE("Should have thrown MQTT_ALREADY_CONNECTED");
+ }
+ Catch(exception_mqttBrokerConnectToBroker) {
+ TEST_ASSERT_EQUAL(MQTT_ALREADY_CONNECTED, exception_mqttBrokerConnectToBroker);
+ }
+}
+
+void test_ConnectToMqttBrokerSendCommandFailed(void) {
+ ESPDUMMY_RETURN_CODE = ESP_WRONG_ANSWER_RECEIVED;
+ CEXCEPTION_T exception_mqttBrokerConnectToBroker;
+ Try {
+ mqttBrokerConnectToBroker("testBroker", "testClient");
+ TEST_FAIL_MESSAGE("Should have thrown MQTT_ESP_WRONG_ANSWER");
+ }
+ Catch(exception_mqttBrokerConnectToBroker) {
+ TEST_ASSERT_EQUAL(MQTT_ESP_WRONG_ANSWER, exception_mqttBrokerConnectToBroker);
+ }
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.MQTTStatus);
+}
+
+void test_DisconnectMqttBroker() {
+ espStatus.MQTTStatus = CONNECTED;
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.MQTTStatus);
+ CEXCEPTION_T exception_mqttBrokerDisconnect;
+ Try {
+ mqttBrokerDisconnect(espStatus.MQTTStatus == CONNECTED);
+ }
+ Catch(exception_mqttBrokerDisconnect) {
+ TEST_FAIL_MESSAGE("Test did not work");
+ }
+}
+
+/* endregion */
+
+int main(void) {
+ UNITY_BEGIN();
+
+ RUN_TEST(test_ConnectToMqttBrokerSuccessful);
+ RUN_TEST(test_ConnectToMqttBrokerEspFailed);
+ RUN_TEST(test_ConnectToMqttBrokerNoWifi);
+ RUN_TEST(test_ConnectToMqttBrokerAlreadyConnected);
+ RUN_TEST(test_ConnectToMqttBrokerSendCommandFailed);
+ RUN_TEST(test_DisconnectMqttBroker);
+
+ return UNITY_END();
+}
diff --git a/test/unit/UnitTestNetwork.c b/test/unit/UnitTestNetwork.c
new file mode 100644
index 00000000..e2bbe6d7
--- /dev/null
+++ b/test/unit/UnitTestNetwork.c
@@ -0,0 +1,89 @@
+#include "Esp.h"
+#include "EspUnitTest.h"
+#include "Network.h"
+
+#include "unity.h"
+
+networkCredentials_t credentials = {.ssid = "SSID", .password = "password"};
+
+void setUp(void) {
+ espStatus.ChipStatus = ESP_CHIP_OK;
+ espStatus.WIFIStatus = NOT_CONNECTED;
+ espStatus.MQTTStatus = NOT_CONNECTED;
+
+ ESPDUMMY_RETURN_CODE = ESP_NO_ERROR;
+}
+
+void tearDown(void) {}
+
+/* region Test Functions */
+
+void testConnectToNetworkSuccessful(void) {
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+ networkErrorCode_t networkErrorCode = networkConnectToNetwork();
+ TEST_ASSERT_EQUAL(NETWORK_NO_ERROR, networkErrorCode);
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.WIFIStatus);
+}
+void testConnectToNetworkAlreadyConnected(void) {
+ espStatus.WIFIStatus = CONNECTED;
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.WIFIStatus);
+ networkErrorCode_t networkErrorCode = networkConnectToNetwork();
+ TEST_ASSERT_EQUAL(NETWORK_WIFI_ALREADY_CONNECTED, networkErrorCode);
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.WIFIStatus);
+}
+void testConnectToNetworkEspChipFailed(void) {
+ espStatus.ChipStatus = ESP_CHIP_NOT_OK;
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+ TEST_ASSERT_EQUAL(ESP_CHIP_NOT_OK, espStatus.ChipStatus);
+ networkErrorCode_t networkErrorCode = networkConnectToNetwork();
+ TEST_ASSERT_EQUAL(NETWORK_ESP_CHIP_FAILED, networkErrorCode);
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+}
+void testConnectToNetworkSendFailed(void) {
+ ESPDUMMY_RETURN_CODE = ESP_WRONG_ANSWER_RECEIVED;
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+ networkErrorCode_t networkErrorCode = networkConnectToNetwork();
+ TEST_ASSERT_EQUAL(NETWORK_ESTABLISH_CONNECTION_FAILED, networkErrorCode);
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+}
+
+void testDisconnectFromNetwork(void) {
+ espStatus.WIFIStatus = CONNECTED;
+ espStatus.MQTTStatus = CONNECTED;
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.WIFIStatus);
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.MQTTStatus);
+ networkDisconnectFromNetwork();
+ TEST_ASSERT_EQUAL(ESP_CHIP_OK, espStatus.ChipStatus);
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.MQTTStatus);
+}
+void testDisconnectFromNetworkTwice(void) {
+ espStatus.WIFIStatus = CONNECTED;
+ espStatus.MQTTStatus = CONNECTED;
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.WIFIStatus);
+ TEST_ASSERT_EQUAL(CONNECTED, espStatus.MQTTStatus);
+ networkDisconnectFromNetwork();
+ TEST_ASSERT_EQUAL(ESP_CHIP_OK, espStatus.ChipStatus);
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.MQTTStatus);
+ networkDisconnectFromNetwork();
+ TEST_ASSERT_EQUAL(ESP_CHIP_OK, espStatus.ChipStatus);
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.WIFIStatus);
+ TEST_ASSERT_EQUAL(NOT_CONNECTED, espStatus.MQTTStatus);
+}
+
+/* endregion */
+
+int main(void) {
+ UNITY_BEGIN();
+
+ RUN_TEST(testConnectToNetworkSuccessful);
+ RUN_TEST(testConnectToNetworkAlreadyConnected);
+ RUN_TEST(testConnectToNetworkEspChipFailed);
+ RUN_TEST(testConnectToNetworkSendFailed);
+
+ RUN_TEST(testDisconnectFromNetwork);
+ RUN_TEST(testDisconnectFromNetworkTwice);
+
+ return UNITY_END();
+}
diff --git a/test/unit/UnitTestPac193x.c b/test/unit/UnitTestPac193x.c
new file mode 100644
index 00000000..bbfa7c9c
--- /dev/null
+++ b/test/unit/UnitTestPac193x.c
@@ -0,0 +1,385 @@
+#include "I2cUnitTest.h"
+#include "Pac193x.h"
+
+#include "unity.h"
+#include
+#include
+
+/* region CONSTANTS */
+
+/*! Denominator for unipolar voltage measurement: 2^{16} = 65536 */
+static const float pac193xInternalUnipolarVoltageDenominator = (float)(1U << 16);
+
+/*! Denominator for unipolar power measurement: 2^{32} = 4294967296
+ *
+ * \Information This denominator is 2^{28} according to the datasheet,
+ * however testing has shown that 2^{32} is actually correct
+ */
+static const float pac193xInternalUnipolarPowerDenominator = (float)(1ULL << 32);
+
+/*! Denominator for energy measurement: 2^28 = 268435456 */
+static const float pac193xInternalEnergyDenominator = (float)(1ULL << 28);
+
+static pac193xSensorConfiguration_t SENSOR = {
+ .usedChannels = {.uint_channelsInUse = 0b00000010},
+ .rSense = {0, 0.82f, 0, 0},
+ .powerPin = -1,
+ .i2c_slave_address = 0x11,
+ .sampleRate = PAC193X_8_SAMPLES_PER_SEC,
+};
+
+static uint8_t usedChannelIndex = 1;
+
+/* endregion */
+
+void setUp(void) {
+ /* Default: Point to Pass */
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandPassForPac193x;
+ i2cUnittestReadCommand = i2cUnittestReadCommandPassForPac193x;
+
+ pac193xSetChannelsInUse(SENSOR);
+}
+
+void tearDown(void) {}
+
+/* region pac193x_GetSensorInfo */
+
+void pac193xGetSensorInfoReturnSendCommandErrorIfHardwareFails(void) {
+ pac193xSensorId_t info;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+ pac193xErrorCode_t errorCode = pac193xGetSensorInfo(SENSOR, &info);
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_SEND_COMMAND_ERROR, errorCode);
+}
+
+void pac193xGetSensorInfoReturnSendCommandErrorIfAckMissing(void) {
+ pac193xSensorId_t info;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ pac193xErrorCode_t errorCode = pac193xGetSensorInfo(SENSOR, &info);
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_SEND_COMMAND_ERROR, errorCode);
+}
+
+void pac193xGetSensorInfoReturnReceiveDataErrorIfHardwareFails(void) {
+ pac193xSensorId_t info;
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+
+ pac193xErrorCode_t errorCode = pac193xGetSensorInfo(SENSOR, &info);
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void pac193xGetSensorInfoReturnReceiveDataErrorIfAckMissing(void) {
+ pac193xSensorId_t info;
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+
+ pac193xErrorCode_t errorCode = pac193xGetSensorInfo(SENSOR, &info);
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void pac193xGetSensorInfoReadSuccessful(void) {
+ pac193xSensorId_t info;
+
+ pac193xErrorCode_t errorCode = pac193xGetSensorInfo(SENSOR, &info);
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_NO_ERROR, errorCode);
+}
+
+void pac193xGetSensorInfoReadCorrectValue(void) {
+ pac193xSensorId_t expectedInfo, actualInfo;
+
+ expectedInfo.product_id = byteZero;
+ expectedInfo.manufacturer_id = byteZero;
+ expectedInfo.revision_id = byteZero;
+
+ pac193xGetSensorInfo(SENSOR, &actualInfo);
+
+ TEST_ASSERT_EQUAL_UINT8(expectedInfo.product_id, actualInfo.product_id);
+ TEST_ASSERT_EQUAL_UINT8(expectedInfo.manufacturer_id, actualInfo.manufacturer_id);
+ TEST_ASSERT_EQUAL_UINT8(expectedInfo.revision_id, actualInfo.revision_id);
+}
+
+void pac193xMemoryNotPassedToGetSensorInfoRemainsUntouched(void) {
+ uint8_t memory[512];
+ pac193xSensorId_t info;
+
+ memset(memory, 0, 512);
+
+ pac193xGetSensorInfo(SENSOR, &info);
+
+ TEST_ASSERT_EACH_EQUAL_UINT8(0, memory, 512);
+}
+
+/* endregion */
+/* region pac193x_GetMeasurementForChannel */
+
+void testAssertUint64tEquals(void) {
+ uint64_t expected = 0x0000BEBEBEBEBEBE;
+ uint64_t actual = ((uint64_t)byteZero << 40) | ((uint64_t)byteZero << 32) |
+ ((uint64_t)byteZero << 24) | ((uint64_t)byteZero << 16) |
+ ((uint64_t)byteZero << 8) | (uint64_t)byteZero;
+
+ TEST_ASSERT_EQUAL_UINT64(expected, actual);
+}
+
+void pac193xGetMeasurementForChannelReturnSendCommandErrorIfHardwareFails(void) {
+ float result;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_VSOURCE, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_SEND_COMMAND_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReturnSendCommandErrorIfAckMissing(void) {
+ float result;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_VSOURCE, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_SEND_COMMAND_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReturnReceiveDataErrorIfHardwareFails(void) {
+ float result;
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_VSOURCE, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReturnReceiveDataErrorIfAckMissing(void) {
+ float result;
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_VSOURCE, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReturnInvalidChannelErrorIfChannelWrong(void) {
+ float result;
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, 0x10, PAC193X_VSOURCE, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_INVALID_CHANNEL, errorCode);
+}
+
+/* region V_SOURCE */
+void pac193xGetMeasurementForChannelReadSuccessfulValueVsource(void) {
+ float result;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_VSOURCE, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_NO_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReadCorrectValueVsource(void) {
+ float expectedValue = 0, actualValue = 0;
+
+ uint64_t expected_rawValue = ((uint64_t)byteZero << 8) | (uint64_t)byteZero;
+ expectedValue =
+ (32.0f * (((float)expected_rawValue) / pac193xInternalUnipolarVoltageDenominator));
+
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_VSOURCE, &actualValue);
+
+ TEST_ASSERT_EQUAL_FLOAT(expectedValue, actualValue);
+}
+/* endregion V_SOURCE */
+
+/* region V_SENSE */
+void pac193xGetMeasurementForChannelReadSuccessfulValueVsense(void) {
+ float result;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_VSENSE, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_NO_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReadCorrectValueVsense(void) {
+ float expectedValue = 0, actualValue = 0;
+
+ uint64_t expected_rawValue = ((uint64_t)byteZero << 8) | (uint64_t)byteZero;
+ expectedValue = 0.1f * ((float)expected_rawValue) / pac193xInternalUnipolarVoltageDenominator;
+
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_VSENSE, &actualValue);
+
+ TEST_ASSERT_EQUAL_FLOAT(expectedValue, actualValue);
+}
+/* endregion V_SENSE */
+
+/* region CURRENT */
+void pac193xGetMeasurementForChannelReadSuccessfulValueCurrent(void) {
+ float result;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_CURRENT, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_NO_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReadCorrectValueCurrent(void) {
+ float expectedValue = 0, actualValue = 0;
+
+ uint64_t expected_rawValue = ((uint64_t)byteZero << 8) | (uint64_t)byteZero;
+ float FSC = 0.1f / SENSOR.rSense[usedChannelIndex];
+ expectedValue = FSC * (((float)expected_rawValue) / pac193xInternalUnipolarVoltageDenominator);
+
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_CURRENT, &actualValue);
+
+ TEST_ASSERT_EQUAL_FLOAT(expectedValue, actualValue);
+}
+/* endregion CURRENT */
+
+/* region POWER */
+void pac193xGetMeasurementForChannelReadSuccessfulValuePower(void) {
+ float result;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_ENERGY, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_NO_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReadCorrectValuePower(void) {
+ float expectedValue = 0, actualValue = 0;
+
+ uint64_t rawValue = (((uint64_t)byteZero << 24) | ((uint64_t)byteZero << 16) |
+ ((uint64_t)byteZero << 8) | (uint64_t)byteZero);
+ float expectedRawValue = (float)rawValue;
+ float powerFSR = 3.2f / SENSOR.rSense[usedChannelIndex];
+ float pProp = expectedRawValue / pac193xInternalUnipolarPowerDenominator;
+ expectedValue = powerFSR * pProp;
+
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_POWER, &actualValue);
+
+ TEST_ASSERT_EQUAL_FLOAT(expectedValue, actualValue);
+}
+/* endregion POWER */
+
+/* region ENERGY */
+
+void pac193xGetMeasurementForChannelReadSuccessfulValueEnergy(void) {
+ float result;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_ENERGY, &result);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_NO_ERROR, errorCode);
+}
+
+void pac193xGetMeasurementForChannelReadCorrectValueEnergy(void) {
+ float expectedValue = 0, actualValue = 0;
+
+ uint64_t expected_rawValue =
+ (((uint64_t)byteZero << 40) | ((uint64_t)byteZero << 32) | (uint64_t)byteZero << 24) |
+ ((uint64_t)byteZero << 16) | ((uint64_t)byteZero << 8) | (uint64_t)byteZero;
+
+ float powerFSR = 3.2f / SENSOR.rSense[usedChannelIndex];
+ expectedValue = (float)expected_rawValue * powerFSR / (pac193xInternalEnergyDenominator * 8.0f);
+
+ pac193xGetMeasurementForChannel(SENSOR, PAC193X_CHANNEL02, PAC193X_ENERGY, &actualValue);
+
+ TEST_ASSERT_EQUAL_FLOAT(expectedValue, actualValue);
+}
+/* endregion ENERGY */
+
+/* endregion */
+/* region pac193x_GetAllMeasurementsForChannel */
+
+void pac193xGetAllMeasurementsForChannelReturnSendCommandErrorIfHardwareFails(void) {
+ pac193xMeasurements_t measurements;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementsForChannel(SENSOR, PAC193X_CHANNEL02, &measurements);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_SEND_COMMAND_ERROR, errorCode);
+}
+
+void pac193xGetAllMeasurementsForChannelReturnSendCommandErrorIfAckMissing(void) {
+ pac193xMeasurements_t measurements;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementsForChannel(SENSOR, PAC193X_CHANNEL02, &measurements);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_SEND_COMMAND_ERROR, errorCode);
+}
+
+void pac193xGetAllMeasurementsForChannelReturnReceiveDataErrorIfHardwareFails(void) {
+ pac193xMeasurements_t measurements;
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementsForChannel(SENSOR, PAC193X_CHANNEL02, &measurements);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void pac193xGetAllMeasurementsForChannelReturnReceiveDataErrorIfAckMissing(void) {
+ pac193xMeasurements_t measurements;
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementsForChannel(SENSOR, PAC193X_CHANNEL02, &measurements);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_RECEIVE_DATA_ERROR, errorCode);
+}
+
+void pac193xGetAllMeasurementsForChannelReadSuccessful(void) {
+ pac193xMeasurements_t measurements;
+
+ pac193xErrorCode_t errorCode =
+ pac193xGetMeasurementsForChannel(SENSOR, PAC193X_CHANNEL02, &measurements);
+
+ TEST_ASSERT_EQUAL_UINT8(PAC193X_NO_ERROR, errorCode);
+}
+
+/* endregion */
+
+int main(void) {
+ UNITY_BEGIN();
+
+ RUN_TEST(pac193xMemoryNotPassedToGetSensorInfoRemainsUntouched);
+ RUN_TEST(pac193xGetSensorInfoReturnSendCommandErrorIfHardwareFails);
+ RUN_TEST(pac193xGetSensorInfoReturnSendCommandErrorIfAckMissing);
+ RUN_TEST(pac193xGetSensorInfoReturnReceiveDataErrorIfHardwareFails);
+ RUN_TEST(pac193xGetSensorInfoReturnReceiveDataErrorIfAckMissing);
+ RUN_TEST(pac193xGetSensorInfoReadSuccessful);
+ RUN_TEST(pac193xGetSensorInfoReadCorrectValue);
+
+ RUN_TEST(pac193xGetMeasurementForChannelReturnSendCommandErrorIfHardwareFails);
+ RUN_TEST(pac193xGetMeasurementForChannelReturnSendCommandErrorIfAckMissing);
+ RUN_TEST(pac193xGetMeasurementForChannelReturnReceiveDataErrorIfHardwareFails);
+ RUN_TEST(pac193xGetMeasurementForChannelReturnReceiveDataErrorIfAckMissing);
+ RUN_TEST(pac193xGetMeasurementForChannelReturnInvalidChannelErrorIfChannelWrong);
+ RUN_TEST(pac193xGetMeasurementForChannelReadSuccessfulValueVsource);
+ RUN_TEST(pac193xGetMeasurementForChannelReadCorrectValueVsource);
+ RUN_TEST(pac193xGetMeasurementForChannelReadSuccessfulValueVsense);
+ RUN_TEST(pac193xGetMeasurementForChannelReadCorrectValueVsense);
+ RUN_TEST(pac193xGetMeasurementForChannelReadSuccessfulValueCurrent);
+ RUN_TEST(pac193xGetMeasurementForChannelReadCorrectValueCurrent);
+ RUN_TEST(pac193xGetMeasurementForChannelReadSuccessfulValuePower);
+ RUN_TEST(pac193xGetMeasurementForChannelReadCorrectValuePower);
+ RUN_TEST(pac193xGetMeasurementForChannelReadSuccessfulValueEnergy);
+ RUN_TEST(pac193xGetMeasurementForChannelReadCorrectValueEnergy);
+
+ RUN_TEST(testAssertUint64tEquals);
+
+ RUN_TEST(pac193xGetAllMeasurementsForChannelReturnSendCommandErrorIfHardwareFails);
+ RUN_TEST(pac193xGetAllMeasurementsForChannelReturnSendCommandErrorIfAckMissing);
+ RUN_TEST(pac193xGetAllMeasurementsForChannelReturnReceiveDataErrorIfHardwareFails);
+ RUN_TEST(pac193xGetAllMeasurementsForChannelReturnReceiveDataErrorIfAckMissing);
+ RUN_TEST(pac193xGetAllMeasurementsForChannelReadSuccessful);
+ UnityPrint("Not testing for correct values. Values generated by "
+ "pac193x_GetMeasurementForChannel(...) and have been tested before.");
+
+ return UNITY_END();
+}
diff --git a/test/unit/UnitTestSht3x.c b/test/unit/UnitTestSht3x.c
new file mode 100644
index 00000000..04b03264
--- /dev/null
+++ b/test/unit/UnitTestSht3x.c
@@ -0,0 +1,780 @@
+#include "CException.h"
+#include "I2cUnitTest.h"
+#include "Sht3x.h"
+#include "unity.h"
+
+static sht3xSensorConfiguration_t sensor;
+
+void setUp(void) {
+ /* Default: Point to Pass */
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandPassForSht3x;
+ i2cUnittestReadCommand = i2cUnittestReadCommandPassForSht3x;
+}
+
+void tearDown(void) {}
+
+/* region SHT3X_ReadStatusRegister */
+
+void sht3xReadStatusRegisterGetSendCommandFailErrorIfHardwareFails(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadStatusRegister(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadStatusRegisterGetSendCommandFailErrorIfAckMissing(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadStatusRegister(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadStatusRegisterGetReceiveDataFailErrorIfHardwareFails(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadStatusRegister(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadStatusRegisterGetReceiveDataFailErrorIfAckMissing(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadStatusRegister(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_RECEIVE_DATA_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadStatusRegisterGetChecksumFailError(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandProvokeChecksumFailForSht3x;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadStatusRegister(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_CHECKSUM_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadStatusRegisterReadSuccessful(void) {
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadStatusRegister(sensor);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+void sht3xReadStatusRegisterReadCorrectValue(void) {
+ /* fill expected with random generated */
+ sht3xStatusRegister_t expected_statusRegister = {.config = (byteZero << 8) | (byteOne & 0xFF)};
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xStatusRegister_t actual_statusRegister = sht3xReadStatusRegister(sensor);
+ TEST_ASSERT_EQUAL_UINT16(expected_statusRegister.config, actual_statusRegister.config);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+/* endregion*/
+/* region SHT3X_ReadSerialNumber */
+
+void sht3xReadSerialNumberGetSendCommandFailErrorIfHardwareFails(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadSerialNumber(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadSerialNumberGetSendCommandFailErrorIfAckMissing(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadSerialNumber(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadSerialNumberGetReceiveDataFailErrorIfHardwareFails(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadSerialNumber(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadSerialNumberGetReceiveDataFailErrorIfAckMissing(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadSerialNumber(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_RECEIVE_DATA_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadSerialNumberGetChecksumFailError(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandProvokeChecksumFailForSht3x;
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadSerialNumber(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_CHECKSUM_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadSerialNumberReadSuccessful(void) {
+ CEXCEPTION_T exception;
+
+ Try {
+ sht3xReadSerialNumber(sensor);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+void sht3xReadSerialNumberReadCorrectValue(void) {
+ /* fill expected with random generated */
+ uint32_t expected_serialNumber = (byteZero << 24) | (byteOne << 16) | (byteZero << 8) | byteOne;
+ CEXCEPTION_T exception;
+
+ Try {
+ uint32_t actual_serialNumber = sht3xReadSerialNumber(sensor);
+ TEST_ASSERT_EQUAL_UINT32(expected_serialNumber, actual_serialNumber);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+/* endregion */
+/* region SHT3X_GetTemperature */
+
+void sht3xGetTemperatureGetSendCommandFailErrorIfHardwareFails(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperature(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureGetSendCommandFailErrorIfAckMissing(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperature(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureGetReceiveDataFailErrorIfHardwareFails(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperature(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureGetChecksumFailError(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandProvokeChecksumFailForSht3x;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperature(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_CHECKSUM_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureGetReceiveDataFailErrorIfAckMissing(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperature(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_RECEIVE_DATA_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureReadSuccessful(void) {
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperature(sensor);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+void sht3xGetTemperatureReadCorrectValue(void) {
+ /* fill expected with random generated */
+ uint16_t expected_rawValue_temperature = (byteZero << 8) | byteOne;
+ float expected_temperature =
+ 175.0f * ((float)expected_rawValue_temperature / (65536.0f - 1)) - 45.0f;
+
+ CEXCEPTION_T exception;
+ Try {
+ float actual_temperature = sht3xGetTemperature(sensor);
+ TEST_ASSERT_EQUAL_FLOAT(expected_temperature, actual_temperature);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+/* endregion */
+/* region SHT3X_GetHumidity */
+
+void sht3xGetHumidityGetSendCommandFailErrorIfHardwareFails(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetHumidity(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetHumidityGetSendCommandFailErrorIfAckMissing(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetHumidity(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetHumidityGetReceiveDataFailErrorIfHardwareFails(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetHumidity(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetHumidityGetReceiveDataFailErrorIfAckMissing(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetHumidity(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_RECEIVE_DATA_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetHumidityGetChecksumFailError(void) {
+ i2cUnittestReadCommand = i2cUnittestReadCommandProvokeChecksumFailForSht3x;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetHumidity(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_CHECKSUM_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetHumidityReadSuccessful(void) {
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetHumidity(sensor);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+void sht3xGetHumidityReadCorrectValue(void) {
+ /* fill expected with random generated */
+ uint16_t expected_rawValue_humidity = (byteZero << 8) | byteOne;
+ float expected_humidity = 100.0f * ((float)expected_rawValue_humidity / (65536.0f - 1));
+
+ CEXCEPTION_T exception;
+ Try {
+ float actual_humidity = sht3xGetHumidity(sensor);
+ TEST_ASSERT_EQUAL_FLOAT(expected_humidity, actual_humidity);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+/* endregion */
+/* region SHT3X_GetTemperatureAndHumidity */
+
+void sht3xGetTemperatureAndHumidityGetSendCommandFailErrorIfHardwareFails(void) {
+ float temperature, humidity;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperatureAndHumidity(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureAndHumidityGetSendCommandFailErrorIfAckMissing(void) {
+ float temperature, humidity;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperatureAndHumidity(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureAndHumidityGetReceiveDataFailErrorIfHardwareFails(void) {
+ float temperature, humidity;
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperatureAndHumidity(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureAndHumidityGetReceiveDataFailErrorIfAckMissing(void) {
+ float temperature, humidity;
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperatureAndHumidity(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_RECEIVE_DATA_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureAndHumidityGetChecksumFailError(void) {
+ float temperature, humidity;
+ i2cUnittestReadCommand = i2cUnittestReadCommandProvokeChecksumFailForSht3x;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperatureAndHumidity(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_CHECKSUM_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xGetTemperatureAndHumidityReadSuccessful(void) {
+ float temperature, humidity;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperatureAndHumidity(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+void sht3xGetTemperatureAndHumidityReadCorrectValue(void) {
+ float expected_temperature, actual_temperature, expected_humidity, actual_humidity;
+
+ /* fill expected with random generated */
+ uint16_t expected_rawValue_humidity = (byteZero << 8) | byteOne;
+ expected_humidity = 100.0f * ((float)expected_rawValue_humidity / (65536.0f - 1));
+
+ uint16_t expected_rawValue_temperature = (byteZero << 8) | byteOne;
+ expected_temperature = 175.0f * ((float)expected_rawValue_temperature / (65536.0f - 1)) - 45.0f;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xGetTemperatureAndHumidity(sensor, &actual_temperature, &actual_humidity);
+ TEST_ASSERT_EQUAL_FLOAT(expected_temperature, actual_temperature);
+ TEST_ASSERT_EQUAL_FLOAT(expected_humidity, actual_humidity);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+/* endregion */
+/* region SHT3X_ReadMeasurementBuffer */
+
+void sht3xReadMeasurementBufferGetSendCommandFailErrorIfHardwareFails(void) {
+ float temperature, humidity;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xReadMeasurementBuffer(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadMeasurementBufferGetSendCommandFailErrorIfAckMissing(void) {
+ float temperature, humidity;
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xReadMeasurementBuffer(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadMeasurementBufferGetReceiveDataFailErrorIfHardwareFails(void) {
+ float temperature, humidity;
+ i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xReadMeasurementBuffer(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadMeasurementBufferGetReceiveDataFailErrorIfAckMissing(void) {
+ float temperature, humidity;
+ i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xReadMeasurementBuffer(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_RECEIVE_DATA_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadMeasurementBufferGetChecksumFailError(void) {
+ float temperature, humidity;
+ i2cUnittestReadCommand = i2cUnittestReadCommandProvokeChecksumFailForSht3x;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xReadMeasurementBuffer(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_CHECKSUM_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xReadMeasurementBufferReadSuccessful(void) {
+ float temperature, humidity;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xReadMeasurementBuffer(sensor, &temperature, &humidity);
+ }
+ Catch(exception) {
+ TEST_FAIL();
+ }
+}
+
+void sht3xReadMeasurementBufferReadCorrectValue(void) {
+ float expected_temperature, actual_temperature, expected_humidity, actual_humidity;
+
+ /* fill expected with random generated */
+ uint16_t expected_rawValue_humidity = (byteZero << 8) | byteOne;
+ expected_humidity = 100.0f * ((float)expected_rawValue_humidity / (65536.0f - 1));
+
+ uint16_t expected_rawValue_temperature = (byteZero << 8) | byteOne;
+ expected_temperature = 175.0f * ((float)expected_rawValue_temperature / (65536.0f - 1)) - 45.0f;
+
+ sht3xReadMeasurementBuffer(sensor, &actual_temperature, &actual_humidity);
+ TEST_ASSERT_EQUAL_FLOAT(expected_temperature, actual_temperature);
+ TEST_ASSERT_EQUAL_FLOAT(expected_humidity, actual_humidity);
+}
+
+/* endregion */
+/* region SHT3X_EnableHeater */
+
+void sht3xEnableHeaterGetSendCommandFailErrorIfHardwareFails(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xEnableHeater(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xEnableHeaterGetSendCommandFailErrorIfAckMissing(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xEnableHeater(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+/* endregion */
+/* region SHT3X_DisableHeater */
+
+void sht3xDisableHeaterGetSendCommandFailErrorIfHardwareFails(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xDisableHeater(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xDisableHeaterGetSendCommandFailErrorIfAckMissing(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xDisableHeater(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+/* endregion */
+/* region SHT3X_SoftReset */
+
+void sht3xSoftResetGetSendCommandFailErrorIfHardwareFails(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xSoftReset(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_HARDWARE_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+void sht3xSoftResetGetSendCommandFailErrorIfAckMissing(void) {
+ i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
+
+ CEXCEPTION_T exception;
+ Try {
+ sht3xSoftReset(sensor);
+ }
+ Catch(exception) {
+ TEST_ASSERT_EQUAL_UINT8(SHT3X_SEND_COMMAND_ERROR, exception);
+ return;
+ }
+ TEST_FAIL();
+}
+
+/* endregion */
+
+int main(void) {
+ UNITY_BEGIN();
+
+ RUN_TEST(sht3xReadStatusRegisterGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xReadStatusRegisterGetSendCommandFailErrorIfAckMissing);
+ RUN_TEST(sht3xReadStatusRegisterGetReceiveDataFailErrorIfHardwareFails);
+ RUN_TEST(sht3xReadStatusRegisterGetReceiveDataFailErrorIfAckMissing);
+ RUN_TEST(sht3xReadStatusRegisterGetChecksumFailError);
+ RUN_TEST(sht3xReadStatusRegisterReadSuccessful);
+ RUN_TEST(sht3xReadStatusRegisterReadCorrectValue);
+
+ RUN_TEST(sht3xReadSerialNumberGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xReadSerialNumberGetSendCommandFailErrorIfAckMissing);
+ RUN_TEST(sht3xReadSerialNumberGetReceiveDataFailErrorIfHardwareFails);
+ RUN_TEST(sht3xReadSerialNumberGetReceiveDataFailErrorIfAckMissing);
+ RUN_TEST(sht3xReadSerialNumberGetChecksumFailError);
+ RUN_TEST(sht3xReadSerialNumberReadSuccessful);
+ RUN_TEST(sht3xReadSerialNumberReadCorrectValue);
+
+ RUN_TEST(sht3xGetTemperatureGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xGetTemperatureGetSendCommandFailErrorIfAckMissing);
+ RUN_TEST(sht3xGetTemperatureGetReceiveDataFailErrorIfHardwareFails);
+ RUN_TEST(sht3xGetTemperatureGetReceiveDataFailErrorIfAckMissing);
+ RUN_TEST(sht3xGetTemperatureGetChecksumFailError);
+ RUN_TEST(sht3xGetTemperatureReadSuccessful);
+ RUN_TEST(sht3xGetTemperatureReadCorrectValue);
+
+ RUN_TEST(sht3xGetHumidityGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xGetHumidityGetSendCommandFailErrorIfAckMissing);
+ RUN_TEST(sht3xGetHumidityGetReceiveDataFailErrorIfHardwareFails);
+ RUN_TEST(sht3xGetHumidityGetReceiveDataFailErrorIfAckMissing);
+ RUN_TEST(sht3xGetHumidityGetChecksumFailError);
+ RUN_TEST(sht3xGetHumidityReadSuccessful);
+ RUN_TEST(sht3xGetHumidityReadCorrectValue);
+
+ RUN_TEST(sht3xGetTemperatureAndHumidityGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xGetTemperatureAndHumidityGetSendCommandFailErrorIfAckMissing);
+ RUN_TEST(sht3xGetTemperatureAndHumidityGetReceiveDataFailErrorIfHardwareFails);
+ RUN_TEST(sht3xGetTemperatureAndHumidityGetReceiveDataFailErrorIfAckMissing);
+ RUN_TEST(sht3xGetTemperatureAndHumidityGetChecksumFailError);
+ RUN_TEST(sht3xGetTemperatureAndHumidityReadSuccessful);
+ RUN_TEST(sht3xGetTemperatureAndHumidityReadCorrectValue);
+
+ RUN_TEST(sht3xReadMeasurementBufferGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xReadMeasurementBufferGetSendCommandFailErrorIfAckMissing);
+ RUN_TEST(sht3xReadMeasurementBufferGetReceiveDataFailErrorIfHardwareFails);
+ RUN_TEST(sht3xReadMeasurementBufferGetReceiveDataFailErrorIfAckMissing);
+ RUN_TEST(sht3xReadMeasurementBufferGetChecksumFailError);
+ RUN_TEST(sht3xReadMeasurementBufferReadSuccessful);
+ RUN_TEST(sht3xReadMeasurementBufferReadCorrectValue);
+
+ RUN_TEST(sht3xEnableHeaterGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xEnableHeaterGetSendCommandFailErrorIfAckMissing);
+
+ RUN_TEST(sht3xDisableHeaterGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xDisableHeaterGetSendCommandFailErrorIfAckMissing);
+
+ RUN_TEST(sht3xSoftResetGetSendCommandFailErrorIfHardwareFails);
+ RUN_TEST(sht3xSoftResetGetSendCommandFailErrorIfAckMissing);
+
+ return UNITY_END();
+}
diff --git a/test/unit/UnittestAdxl345b.c b/test/unit/UnittestAdxl345b.c
deleted file mode 100644
index 4f79b9bb..00000000
--- a/test/unit/UnittestAdxl345b.c
+++ /dev/null
@@ -1,416 +0,0 @@
-#include "Adxl345b.h"
-#include "I2cUnitTest.h"
-#include
-#include
-
-/*! JUST HERE TO SATISFY THE COMPILER
- *
- * @param i2cHost
- */
-
-adxl345bSensorConfiguration_t sensor;
-
-void setUp(void) {
- /* Default: Point to Pass */
- i2cUnittestWriteCommand = i2cUnittestWriteCommandPassForAdxl345b;
- i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInStreamMode;
-
- adxl345bChangeMeasurementRange(sensor, ADXL345B_2G_RANGE);
-}
-
-void tearDown(void) {}
-
-/* region adxl345bReadSerialNumber */
-
-void adxl345bReadSerialNumberGetSendCommandFail_errorIfHardwarFails(void) {
- uint8_t serialNumber;
- i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
-
- adxl345bErrorCode_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
-}
-
-void adxl345bReadSerialNumberGetSendCommandFail_errorIfAckMissing(void) {
- uint8_t serialNumber;
- i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
-
- adxl345bErrorCode_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
-}
-
-void adxl345bReadSerialNumberGetReceiveDataFail_errorIfHardwarFails(void) {
- uint8_t serialNumber;
- i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
-
- adxl345bErrorCode_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
-}
-
-void adxl345bReadSerialNumberGetReceiveDataFail_errorIfAckMissing(void) {
- uint8_t serialNumber;
- i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
-
- adxl345bErrorCode_t errorCode = adxl345bReadSerialNumber(sensor, &serialNumber);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
-}
-
-void adxl345bReadSerialNumberReadSuccessful(void) {
- uint8_t serialNumber;
-
- uint8_t err = adxl345bReadSerialNumber(sensor, &serialNumber);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_NO_ERROR, err);
-}
-
-void adxl345bReadSerialNumberReadCorrectValue(void) {
- uint8_t expected_serialNumber, actual_serialNumber;
-
- /* fill expected with random generated */
- expected_serialNumber = 0b10011111;
-
- adxl345bReadSerialNumber(sensor, &actual_serialNumber);
- TEST_ASSERT_EQUAL_UINT8(expected_serialNumber, actual_serialNumber);
-}
-
-/* endregion adxl345bReadSerialNumber */
-
-/* region adxl345bGetSingleMeasurement */
-
-void adxl345bGetSingleMeasurementGetSendCommandFail_errorIfHardwareFails(void) {
- uint8_t rawData[6];
- i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
-
- adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
-}
-
-void adxl345bGetSingleMeasurementGetSendCommandFail_errorIfAckMissing(void) {
- uint8_t rawData[6];
- i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
-
- adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
-}
-
-void adxl345bGetSingleMeasurementGetReceiveDataFail_errorIfHardwareFails(void) {
- uint8_t rawData[6];
- i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
-
- adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
-}
-
-void adxl345bGetSingleMeasurementGetReceiveDataFail_errorIfAckMissing(void) {
- uint8_t rawData[6];
- i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
-
- adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
-}
-
-void adxl345bGetSingleMeasurementReadSuccessful(void) {
- uint8_t rawData[6];
- adxl345bErrorCode_t errorCode = adxl345bGetSingleMeasurement(sensor, rawData);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_NO_ERROR, errorCode);
-}
-
-void adxl345bGetSingleMeasurementReadCorrectValue(void) {
- uint8_t sizeOfRawData = 6;
- uint8_t rawData[sizeOfRawData];
-
- adxl345bGetSingleMeasurement(sensor, rawData);
- for (int i = 0; i < sizeOfRawData; i++) {
- TEST_ASSERT_EQUAL_UINT8(byteZero, rawData[i]);
- }
-}
-/* endregion adxl345bGetSingleMeasurement */
-
-/* region adxl345bGetMultipleMeasurements */
-
-void adxl345bGetMultipleMeasurementsGetSendCommandFail_errorIfHardwareFails(void) {
- uint32_t numberOfSamples = 1;
- uint8_t *samples[numberOfSamples];
-
- i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
-
- adxl345bErrorCode_t errorCode =
- adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
-}
-
-void adxl345bGetMultipleMeasurementsGetSendCommandFail_errorIfAckMissing(void) {
- uint32_t numberOfSamples = 16;
- uint8_t *samples[numberOfSamples];
- i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
-
- adxl345bErrorCode_t errorCode =
- adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
-}
-
-void adxl345bGetMultipleMeasurementsGetReceiveDataFail_errorIfHardwareFails(void) {
- uint32_t numberOfSamples = 32;
- uint8_t *samples[numberOfSamples];
- i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
-
- adxl345bErrorCode_t errorCode =
- adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
-}
-
-void adxl345bGetMultipleMeasurementsGetReceiveDataFail_errorIfAckMissing(void) {
- uint32_t numberOfSamples = 33;
- uint8_t *samples[numberOfSamples];
- i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
-
- adxl345bErrorCode_t errorCode =
- adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
-}
-
-void adxl345bGetMultipleMeasurementsReadSuccessful(void) {
- uint32_t numberOfSamples = 50;
- uint8_t sizeOfRawData = 6;
- uint8_t **samples = malloc(numberOfSamples * sizeof(*samples));
- if (samples == NULL) {
- TEST_FAIL_MESSAGE("Memory allocation for sample-array failed");
- }
- for (int i = 0; i < numberOfSamples; i++) {
- samples[i] = malloc(sizeOfRawData * sizeof(*samples[i]));
-
- if (samples[i] == NULL) {
- TEST_FAIL_MESSAGE("Memory allocation for sample-data failed");
- }
- }
- adxl345bErrorCode_t errorCode =
- adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_NO_ERROR, errorCode);
- for (int i = 0; i < numberOfSamples; i++) {
- free(samples[i]);
- }
- free(samples);
-}
-
-void adxl345bGetMultipleMeasurementsReadCorrectValues(void) {
- /*generate Array for Data*/
-
- uint32_t numberOfSamples = 5;
- uint8_t sizeOfRawData = 6;
- uint8_t *samples[numberOfSamples * sizeOfRawData];
-
- /* change ReadCommands to generate expected raw data received from I2C*/
- uint8_t expectedRawData = byteZero;
- for (int readMode = 0; readMode < 3; readMode++) {
- switch (readMode) {
- case 0: // use default StreamMode
- break;
- case 1:
- i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInFifoMode;
- expectedRawData = byteOne;
- break;
- case 2:
- i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInTriggerMode;
- expectedRawData = byteTwo;
- break;
- }
- adxl345bGetMultipleMeasurements(sensor, samples, numberOfSamples);
-
- for (int i = 0; i < numberOfSamples; i += 6) {
- TEST_ASSERT_EQUAL_UINT8(expectedRawData, samples[i]);
- }
- }
-}
-
-/* endregion adxl345bGetMultipleMeasurements */
-
-/* region adxl345bGetMeasurementsForNSeconds */
-
-void adxl345bGetMeasurementsForNSecondsGetSendCommandFail_errorIfHardwareFails(void) {
- uint32_t numberOfSamples = 50;
- uint8_t sizeOfRawData = 6;
- uint8_t samples[numberOfSamples * sizeOfRawData];
- uint32_t seconds = 3;
-
- i2cUnittestWriteCommand = i2cUnittestWriteCommandHardwareDefect;
-
- adxl345bErrorCode_t errorCode =
- adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
-
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
-}
-
-void adxl345bGetMeasurementsForNSecondsGetSendCommandFail_errorIfAckMissing(void) {
- uint32_t numberOfSamples = 16;
- uint8_t sizeOfRawData = 6;
- uint8_t samples[numberOfSamples * sizeOfRawData];
- uint32_t seconds = 3;
- i2cUnittestWriteCommand = i2cUnittestWriteCommandAckMissing;
-
- adxl345bErrorCode_t errorCode =
- adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_SEND_COMMAND_ERROR, errorCode);
-}
-
-void adxl345bGetMeasurementsForNSecondsGetReceiveDataFail_errorIfHardwareFails(void) {
- uint32_t numberOfSamples = 32;
- uint8_t sizeOfRawData = 6;
- uint8_t samples[numberOfSamples * sizeOfRawData];
- uint32_t seconds = 3;
- i2cUnittestReadCommand = i2cUnittestReadCommandHardwareDefect;
-
- adxl345bErrorCode_t errorCode =
- adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
-}
-
-void adxl345bGetMeasurementsForNSecondsGetReceiveDataFail_errorIfAckMissing(void) {
- uint32_t numberOfSamples = 33;
- uint8_t sizeOfRawData = 6;
- uint8_t samples[numberOfSamples * sizeOfRawData];
- uint32_t seconds = 3;
- i2cUnittestReadCommand = i2cUnittestReadCommandAckMissing;
-
- adxl345bErrorCode_t errorCode =
- adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_RECEIVE_DATA_ERROR, errorCode);
-}
-
-void adxl345bGetMeasurementsForNSecondsReadSuccessful(void) {
- uint32_t numberOfSamples = 5000;
- uint8_t sizeOfRawData = 6;
- uint8_t samples[numberOfSamples * sizeOfRawData];
- uint32_t seconds = 1;
-
- for (int readMode = 0; readMode < 3; readMode++) {
- switch (readMode) {
- case 0: // use default StreamMode
- break;
- case 1:
- i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInFifoMode;
- break;
- case 2:
- i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInTriggerMode;
- break;
- }
- adxl345bErrorCode_t errorCode =
- adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
- TEST_ASSERT_EQUAL_UINT8(ADXL345B_NO_ERROR, errorCode);
- }
-}
-
-// 3 different tests
-void adxl345bGetMeasurementsForNSecondsReadCorrectValues(void) {
- /*generate Array for Data*/
-
- uint32_t numberOfSamples = 260;
- uint32_t seconds = 1;
- uint8_t sizeOfRawData = 6;
- uint8_t samples[numberOfSamples * sizeOfRawData];
-
- /* change ReadCommands to generate expected raw data received from I2C*/
- uint8_t expectedRawData = byteZero;
- for (int readMode = 0; readMode < 3; readMode++) {
- switch (readMode) {
- case 0: // use default StreamMode
- break;
- case 1: // use FifoMode
- i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInFifoMode;
- expectedRawData = byteOne;
- break;
- case 2: // use TriggerMode
- i2cUnittestReadCommand = i2cUnittestReadCommandPassForAdxl345bInTriggerMode;
- expectedRawData = byteTwo;
- break;
- }
- adxl345bGetMeasurementsForNMilliseconds(sensor, samples, seconds, &numberOfSamples);
-
- for (int i = 0; i < numberOfSamples; i += 6) {
- TEST_ASSERT_EQUAL_UINT8(expectedRawData, samples[i]);
- }
- }
-}
-/* endregion adxl345bGetMeasurementsForNSeconds */
-
-void adxl345bConvertDataXYZCorrectValue(void) {
- /* test assumes that 2G Full Range is the used Range */
-
- float expected_xAxis = byteOne, expected_yAxis = byteOne, expected_zAxis = byteOne;
- float actual_xAxis = byteOne, actual_yAxis = byteOne, actual_zAxis = byteOne;
- const uint8_t MSB_MASK = 0b00000011;
- const float SCALE_FACTOR_FOR_RANGE = 0.0043f;
- /* only used lower 2 bits -> 2G Range consists of 10 Bit*/
- uint8_t topByte = byteTwo & MSB_MASK;
-
- /* set rawData */
- uint8_t sizeOfRawData = 6;
- uint8_t rawData[sizeOfRawData];
- for (int i = 0; i < sizeOfRawData; i++) {
- rawData[i] = byteTwo;
- }
-
- /* fill expected with random generated */
- if (topByte <= (MSB_MASK >> 1)) {
- /* CASE: positive value */
- int rawValue = (int)(((uint16_t)(topByte & MSB_MASK) << 8) | (uint16_t)byteTwo);
- float realValue = (float)rawValue * SCALE_FACTOR_FOR_RANGE;
- expected_xAxis = expected_yAxis = expected_zAxis = realValue;
- } else {
- /* CASE: negative value
- *
- * 1. revert 10 bit two complement
- * -> number-1 and Flip least 9 bits
- * 2. convert to float value
- * 3. multiply with (-1)
- * 4. multiply with scale factor
- */
- uint16_t rawValue = ((uint16_t)(topByte & (MSB_MASK >> 1)) << 8) | (uint16_t)byteTwo;
- rawValue = (rawValue - 0x0001) ^ (((MSB_MASK >> 1) << 8) | 0x00FF);
- float realValue = (-1) * (float)rawValue * SCALE_FACTOR_FOR_RANGE;
- expected_xAxis = expected_yAxis = expected_zAxis = realValue;
- }
- printf("actual vorher: %f %f %f ", actual_xAxis, actual_yAxis, actual_zAxis);
-
- adxl345bConvertDataXYZ(&actual_xAxis, &actual_yAxis, &actual_zAxis, rawData);
- printf("actual nachher:%f %f %f ", actual_xAxis, actual_yAxis, actual_zAxis);
- TEST_ASSERT_EQUAL_FLOAT(expected_xAxis, actual_xAxis);
- TEST_ASSERT_EQUAL_FLOAT(expected_yAxis, actual_yAxis);
- TEST_ASSERT_EQUAL_FLOAT(expected_zAxis, actual_zAxis);
-}
-
-/* endregion */
-
-int main(void) {
- UNITY_BEGIN();
-
- RUN_TEST(adxl345bReadSerialNumberGetSendCommandFail_errorIfHardwarFails);
- RUN_TEST(adxl345bReadSerialNumberGetSendCommandFail_errorIfAckMissing);
- RUN_TEST(adxl345bReadSerialNumberGetReceiveDataFail_errorIfHardwarFails);
- RUN_TEST(adxl345bReadSerialNumberGetReceiveDataFail_errorIfAckMissing);
- RUN_TEST(adxl345bReadSerialNumberReadSuccessful);
- RUN_TEST(adxl345bReadSerialNumberReadCorrectValue);
-
- RUN_TEST(adxl345bGetSingleMeasurementGetSendCommandFail_errorIfHardwareFails);
- RUN_TEST(adxl345bGetSingleMeasurementGetSendCommandFail_errorIfAckMissing);
- RUN_TEST(adxl345bGetSingleMeasurementGetReceiveDataFail_errorIfHardwareFails);
- RUN_TEST(adxl345bGetSingleMeasurementGetReceiveDataFail_errorIfAckMissing);
- // RUN_TEST(adxl345bGetSingleMeasurementReadSuccessful); //does not terminate
- // RUN_TEST(adxl345bGetSingleMeasurementReadCorrectValue); //segfault
-
- // RUN_TEST(adxl345bGetMultipleMeasurementsGetSendCommandFail_errorIfHardwareFails);
- // //segfault RUN_TEST(adxl345bGetMultipleMeasurementsGetSendCommandFail_errorIfAckMissing);
- // //segfault
- // RUN_TEST(adxl345bGetMultipleMeasurementsGetReceiveDataFail_errorIfHardwareFails);
- // //segfault RUN_TEST(adxl345bGetMultipleMeasurementsGetReceiveDataFail_errorIfAckMissing);
- // //segfault RUN_TEST(adxl345bGetMultipleMeasurementsReadSuccessful); //segfault
- // RUN_TEST(adxl345bGetMultipleMeasurementsReadCorrectValues); //segfault
-
- RUN_TEST(adxl345bGetMeasurementsForNSecondsGetSendCommandFail_errorIfHardwareFails);
- RUN_TEST(adxl345bGetMeasurementsForNSecondsGetSendCommandFail_errorIfAckMissing);
- RUN_TEST(adxl345bGetMeasurementsForNSecondsGetReceiveDataFail_errorIfHardwareFails);
- RUN_TEST(adxl345bGetMeasurementsForNSecondsGetReceiveDataFail_errorIfAckMissing);
- RUN_TEST(adxl345bGetMeasurementsForNSecondsReadSuccessful);
- RUN_TEST(adxl345bGetMeasurementsForNSecondsReadCorrectValues);
-
- // RUN_TEST(adxl345bConvertDataXYZCorrectValue);
-
- return UNITY_END();
-}
diff --git a/test/unit/dummies/esp/CMakeLists.txt b/test/unit/dummies/esp/CMakeLists.txt
index 0067d6ba..47ab1d4c 100644
--- a/test/unit/dummies/esp/CMakeLists.txt
+++ b/test/unit/dummies/esp/CMakeLists.txt
@@ -1,7 +1,5 @@
-add_library(esp_lib INTERFACE)
-target_include_directories(esp_lib INTERFACE
- ${CMAKE_SOURCE_DIR}/src/network/esp/include
- ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(esp_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Esp.c)
-target_link_libraries(esp_lib INTERFACE
- common_lib)
+add_library(EspDummy Esp.c)
+target_include_directories(EspDummy PUBLIC include)
+target_link_libraries(EspDummy PRIVATE Common)
+target_link_libraries(EspDummy PUBLIC Esp)
+
diff --git a/test/unit/dummies/esp/Esp.c b/test/unit/dummies/esp/Esp.c
index bb9aed65..138249fc 100644
--- a/test/unit/dummies/esp/Esp.c
+++ b/test/unit/dummies/esp/Esp.c
@@ -1,5 +1,5 @@
#include "Esp.h"
-#include "EspUnitTest.h"
+#include "include/EspUnitTest.h"
#include
#include
diff --git a/test/unit/dummies/flash/CMakeLists.txt b/test/unit/dummies/flash/CMakeLists.txt
index 51fdfae9..e829ed49 100644
--- a/test/unit/dummies/flash/CMakeLists.txt
+++ b/test/unit/dummies/flash/CMakeLists.txt
@@ -1,8 +1,4 @@
-add_library(flash_lib INTERFACE)
-target_include_directories(flash_lib INTERFACE
- ${CMAKE_SOURCE_DIR}/src/flash/include
- ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(flash_lib INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Flash.c)
-target_link_libraries(flash_lib INTERFACE
- spi_interface)
+add_library(FlashDummy)
+target_sources(FlashDummy PRIVATE Flash.c)
+target_include_directories(FlashDummy PUBLIC include)
+target_link_libraries(FlashDummy PUBLIC Flash Common)
\ No newline at end of file
diff --git a/test/unit/dummies/gpio/CMakeLists.txt b/test/unit/dummies/gpio/CMakeLists.txt
index 74962b20..6e412f36 100644
--- a/test/unit/dummies/gpio/CMakeLists.txt
+++ b/test/unit/dummies/gpio/CMakeLists.txt
@@ -1,5 +1,4 @@
-add_library(gpio_interface INTERFACE)
-target_include_directories(gpio_interface INTERFACE ${CMAKE_SOURCE_DIR}/src/hal/gpio/include)
-target_sources(gpio_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Gpio.c)
-target_link_libraries(gpio_interface INTERFACE
- common_lib)
+add_library(GpioDummy Gpio.c)
+target_include_directories(GpioDummy PUBLIC include)
+target_link_libraries(GpioDummy PRIVATE Gpio)
+
diff --git a/test/unit/dummies/http/CMakeLists.txt b/test/unit/dummies/http/CMakeLists.txt
index 943887fd..d96f88ec 100644
--- a/test/unit/dummies/http/CMakeLists.txt
+++ b/test/unit/dummies/http/CMakeLists.txt
@@ -1,8 +1,4 @@
-add_library(http_lib_dummy INTERFACE)
-target_include_directories(http_lib_dummy INTERFACE
- ${CMAKE_SOURCE_DIR}/src/network/http/include
- ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(http_lib_dummy INTERFACE ${CMAKE_CURRENT_LIST_DIR}/HTTP.c)
-target_link_libraries(http_lib_dummy INTERFACE
- common_lib
- CException)
+add_library(HttpDummy HTTP.c)
+target_include_directories(HttpDummy PUBLIC include)
+target_link_libraries(HttpDummy PUBLIC Http)
+target_link_libraries(HttpDummy PRIVATE CException)
diff --git a/test/unit/dummies/http/HTTP.c b/test/unit/dummies/http/HTTP.c
index c0777119..0bf45f8d 100644
--- a/test/unit/dummies/http/HTTP.c
+++ b/test/unit/dummies/http/HTTP.c
@@ -1,8 +1,7 @@
#include "HTTP.h"
#include "CException.h"
-#include "httpDummy.h"
-#include
+#include "httpDummy.h"
#include
#include
diff --git a/test/unit/dummies/i2c/CMakeLists.txt b/test/unit/dummies/i2c/CMakeLists.txt
index 69d90118..19572e65 100644
--- a/test/unit/dummies/i2c/CMakeLists.txt
+++ b/test/unit/dummies/i2c/CMakeLists.txt
@@ -1,8 +1,3 @@
-add_library(i2c_interface INTERFACE)
-target_include_directories(i2c_interface INTERFACE
- ${CMAKE_SOURCE_DIR}/src/hal/i2c/include
- ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(i2c_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/I2c.c)
-target_link_libraries(i2c_interface INTERFACE
- common_lib
- gpio_interface)
+add_library(I2cDummy I2c.c)
+target_include_directories(I2cDummy PUBLIC include)
+target_link_libraries(I2cDummy PUBLIC I2c)
diff --git a/test/unit/dummies/pico/CMakeLists.txt b/test/unit/dummies/pico/CMakeLists.txt
index bfb172a2..6f9fcde8 100644
--- a/test/unit/dummies/pico/CMakeLists.txt
+++ b/test/unit/dummies/pico/CMakeLists.txt
@@ -1,6 +1,2 @@
-add_library(pico_stdio INTERFACE)
-target_include_directories(pico_stdio INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
-target_sources(pico_stdio INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/stdio.c)
-
-add_library(pico_stdlib INTERFACE)
\ No newline at end of file
+add_library(pico_stdlib_dummy stdio.c)
+target_include_directories(pico_stdlib_dummy PUBLIC include)
diff --git a/test/unit/dummies/rtos/CMakeLists.txt b/test/unit/dummies/rtos/CMakeLists.txt
index 39e76bdd..877a4fa0 100644
--- a/test/unit/dummies/rtos/CMakeLists.txt
+++ b/test/unit/dummies/rtos/CMakeLists.txt
@@ -1,7 +1,3 @@
-add_library(freeRtosUtils INTERFACE)
-target_sources(freeRtosUtils INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/FreeRtosTaskWrapper.c)
-target_include_directories(freeRtosUtils INTERFACE ${CMAKE_SOURCE_DIR}/src/rtos/include)
-target_link_libraries(freeRtosUtils INTERFACE
- common_lib
- sleep_interface)
+add_library(RtosDummy FreeRtosTaskWrapper.c)
+target_link_libraries(RtosDummy PUBLIC freeRtosUtils)
+target_link_libraries(RtosDummy PRIVATE Sleep Common)
\ No newline at end of file
diff --git a/test/unit/dummies/sleep/CMakeLists.txt b/test/unit/dummies/sleep/CMakeLists.txt
index f4bfbe8f..4be5443f 100644
--- a/test/unit/dummies/sleep/CMakeLists.txt
+++ b/test/unit/dummies/sleep/CMakeLists.txt
@@ -1,5 +1,5 @@
-add_library(sleep_interface INTERFACE)
-target_include_directories(sleep_interface INTERFACE ${CMAKE_SOURCE_DIR}/src/hal/sleep/include)
-target_sources(sleep_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Sleep.c)
-target_link_libraries(sleep_interface INTERFACE
- common_lib)
+
+add_library(SleepDummy Sleep.c)
+target_include_directories(SleepDummy PUBLIC include)
+target_link_libraries(SleepDummy PRIVATE Common)
+target_link_libraries(SleepDummy PUBLIC Sleep)
\ No newline at end of file
diff --git a/test/unit/dummies/time/CMakeLists.txt b/test/unit/dummies/time/CMakeLists.txt
index 3b229aa8..3e33049b 100644
--- a/test/unit/dummies/time/CMakeLists.txt
+++ b/test/unit/dummies/time/CMakeLists.txt
@@ -1,9 +1,3 @@
-add_library(time_interface STATIC
- ${CMAKE_CURRENT_LIST_DIR}/Time.c
-)
-target_include_directories(time_interface PUBLIC
- ${CMAKE_SOURCE_DIR}/src/hal/time/include
-)
-target_link_libraries(time_interface PRIVATE
- common_lib
-)
+add_library(TimeDummy Time.c)
+target_link_libraries(TimeDummy PUBLIC Time)
+target_link_libraries(TimeDummy PRIVATE Common)
\ No newline at end of file
diff --git a/test/unit/dummies/uart/CMakeLists.txt b/test/unit/dummies/uart/CMakeLists.txt
index 54629b93..61862311 100644
--- a/test/unit/dummies/uart/CMakeLists.txt
+++ b/test/unit/dummies/uart/CMakeLists.txt
@@ -1,6 +1,3 @@
-add_library(uart_interface INTERFACE)
-target_include_directories(uart_interface INTERFACE ${CMAKE_SOURCE_DIR}/src/hal/uart/include)
-target_sources(uart_interface INTERFACE
- ${CMAKE_CURRENT_LIST_DIR}/Uart.c)
-target_link_libraries(uart_interface INTERFACE
- common_lib)
+add_library(UartDummy Uart.c)
+target_link_libraries(UartDummy PUBLIC Uart)
+target_link_libraries(UartDummy PRIVATE Common)
\ No newline at end of file
diff --git a/test/unit/unit_test.cmake b/test/unit/unit_test.cmake
new file mode 100644
index 00000000..742e7b56
--- /dev/null
+++ b/test/unit/unit_test.cmake
@@ -0,0 +1,44 @@
+function(__register_target_as_unit_test target)
+ if(NOT TARGET all_unit_tests)
+ add_custom_target(all_unit_tests)
+ endif ()
+ add_dependencies(all_unit_tests ${target})
+
+ add_test(${target} ${target})
+ set_property(TEST ${target} PROPERTY LABELS unit)
+endfunction()
+
+function(add_elastic_ai_unit_test)
+ # You only need to specify the LIB_UNDER_TEST.
+ # The function will automatically try to compile a file with the same name, but
+ # the prefix `Unittest` and link against LIB_UNDER_TEST.
+ # For flexibility you can specify additional libraries (MORE_LIBS) and
+ # sources (MORE_SOURCES).
+ set(oneValueArgs LIB_UNDER_TEST)
+ set(multiValueArgs MORE_SOURCES MORE_LIBS)
+ cmake_parse_arguments(PARSE_ARGV 0 arg
+ "${options}" "${oneValueArgs}" "${multiValueArgs}"
+ )
+ string(CONCAT NAME "UnitTest" ${arg_LIB_UNDER_TEST})
+ if(NOT arg_MORE_SOURCES)
+ set(arg__MORE_SOURCES "")
+ endif ()
+
+ if(NOT arg_MORE_LIBS)
+ set(arg_MORE_LIBS "")
+ endif ()
+
+ if (NOT arg_DEPS)
+ set(arg_DEPS "")
+ endif ()
+
+
+ add_executable(${NAME} ${NAME}.c)
+ target_link_libraries(${NAME} PRIVATE
+ ${arg_LIB_UNDER_TEST}
+ unity::framework
+ ${arg_MORE_LIBS})
+ __register_target_as_unit_test(${NAME})
+
+endfunction()
+