diff --git a/CMakeLists.txt b/CMakeLists.txt index fc8e32c..a133231 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ add_executable(skl_tunnel radio/src/radio_hw_instance.cpp app/src/app_logging.cpp + app/src/app_transparent_client.cpp main.cpp syscalls.c ) diff --git a/app/include/app_settings.hpp b/app/include/app_settings.hpp new file mode 100644 index 0000000..c853d2b --- /dev/null +++ b/app/include/app_settings.hpp @@ -0,0 +1,25 @@ +// +// Created by erki on 14.07.22. +// + +#ifndef SKL_TUNNEL_APP_SETTINGS_HPP +#define SKL_TUNNEL_APP_SETTINGS_HPP + +#include + +namespace App +{ + +struct RadioSettings +{ + std::uint16_t short_address = 0x0230; + std::uint64_t long_address = 0x1222334455667788; + std::uint8_t channel = 11; + std::uint16_t pan_id = 0x0023; + std::int16_t tx_power_dbm = 0; + std::uint8_t retries = 3; +}; + +} + +#endif //SKL_TUNNEL_APP_SETTINGS_HPP diff --git a/app/include/app_transparent_client.hpp b/app/include/app_transparent_client.hpp new file mode 100644 index 0000000..65d07da --- /dev/null +++ b/app/include/app_transparent_client.hpp @@ -0,0 +1,35 @@ +// +// Created by erki on 13.07.22. +// + +#ifndef SKL_TUNNEL_APP_TRANSPARENT_CLIENT_HPP +#define SKL_TUNNEL_APP_TRANSPARENT_CLIENT_HPP + +#include "app_settings.hpp" + +namespace radio +{ +class HwInstance; +} + +namespace App +{ + +class TransparentClient +{ +public: + TransparentClient(const RadioSettings& initial_settings); + + void apply_settings(const RadioSettings& settings); + + TransparentClient(const TransparentClient&) = delete; + TransparentClient(TransparentClient&&) = delete; + TransparentClient& operator=(const TransparentClient&) = delete; + TransparentClient& operator=(TransparentClient&&) = delete; +private: + radio::HwInstance* m_radio; +}; + +} + +#endif //SKL_TUNNEL_APP_TRANSPARENT_CLIENT_HPP diff --git a/app/src/app_transparent_client.cpp b/app/src/app_transparent_client.cpp new file mode 100644 index 0000000..1a52da7 --- /dev/null +++ b/app/src/app_transparent_client.cpp @@ -0,0 +1,28 @@ +// +// Created by erki on 14.07.22. +// + +#include "radio_hw_instance.hpp" + +#include "app_transparent_client.hpp" + +namespace App +{ + +TransparentClient::TransparentClient(const RadioSettings& initial_settings) + : m_radio(radio::HwInstance::instance()) +{ + apply_settings(initial_settings); +} + +void TransparentClient::apply_settings(const RadioSettings& settings) +{ + m_radio->set_address_short(settings.short_address); + m_radio->set_address_long(settings.long_address); + m_radio->set_channel(settings.channel); + m_radio->set_pan_id(settings.pan_id); + m_radio->set_tx_power(settings.tx_power_dbm); + m_radio->set_max_retries(settings.retries); +} + +} diff --git a/main.cpp b/main.cpp index 1762ff0..20f7ca5 100644 --- a/main.cpp +++ b/main.cpp @@ -2,16 +2,20 @@ #include #include +#include #include "radio_hw_instance.hpp" #include "app_logging.hpp" #include "skullc_samd21_hal.hpp" +#include "app_transparent_client.hpp" namespace Hal = Peripherals::Hal::Samd; namespace { +Utility::StaticPointer m_app; + [[noreturn]] void m_faultHandler(const char* expression, const char* file, const int line) { SKULLC_LOG_FATAL("Expression failed: (%s), source: %s:%d", expression, file, line); @@ -34,9 +38,13 @@ int main() App::Logging::setup(); - radio::HwInstance* radio_hw = radio::HwInstance::instance(); SKULLC_LOG_DEBUG("Begin."); + const App::RadioSettings settings; + + m_app.setup(settings); + radio::HwInstance* radio_hw = radio::HwInstance::instance(); + /* Replace with your application code */ while (true) {