diff --git a/boards/airbourne/airbourne_board_config_manager.cpp b/boards/airbourne/airbourne_board_config_manager.cpp index ba2f2e7e..25deabfd 100644 --- a/boards/airbourne/airbourne_board_config_manager.cpp +++ b/boards/airbourne/airbourne_board_config_manager.cpp @@ -155,7 +155,7 @@ void AirbourneBoardConfigManager::get_device_name(device_t device, uint8_t (&nam void AirbourneBoardConfigManager::get_config_name(device_t device, hardware_config_t config, uint8_t (&name)[CONFIG_NAME_LENGTH]) { char *name_char = reinterpret_cast(name); - const char *name_str; + const char *name_str = "Invalid Config"; switch(device) { case Configuration::SERIAL: diff --git a/boards/breezy/Makefile b/boards/breezy/Makefile index de797f03..c64a2f69 100644 --- a/boards/breezy/Makefile +++ b/boards/breezy/Makefile @@ -72,7 +72,8 @@ STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c)) VPATH := $(VPATH):$(BOARD_DIR) BOARD_C_SRC = flash.c BOARD_CXX_SRC = breezy_board.cpp \ - main.cpp + main.cpp \ + breezy_board_config_manager.cpp # Hardware Driver Source Files BREEZY_SRC = drv_gpio.c \ diff --git a/boards/breezy/breezy_board.cpp b/boards/breezy/breezy_board.cpp index 9d8a9b0f..688cb202 100644 --- a/boards/breezy/breezy_board.cpp +++ b/boards/breezy/breezy_board.cpp @@ -81,9 +81,9 @@ void BreezyBoard::clock_delay(uint32_t milliseconds) // serial -void BreezyBoard::serial_init(uint32_t baud_rate, uint32_t dev) +void BreezyBoard::serial_init(uint32_t baud_rate, hardware_config_t configuration) { - (void)dev; + (void)configuration; Serial1 = uartOpen(USART1, NULL, baud_rate, MODE_RXTX); } @@ -110,6 +110,24 @@ void BreezyBoard::serial_flush() return; } +bool BreezyBoard::enable_device(device_t device, hardware_config_t configuration, const Params ¶ms) +{ + (void)device; + (void)configuration; + (void)params; + return true; +} + +void BreezyBoard::init_board_config_manager(ROSflight *rf) +{ + (void)rf; +} + +BreezyBoardConfigManager &BreezyBoard::get_board_config_manager() +{ + return config_manager_; +} + // sensors void BreezyBoard::sensors_init() diff --git a/boards/breezy/breezy_board.h b/boards/breezy/breezy_board.h index 9f1b3ec3..269b4c49 100644 --- a/boards/breezy/breezy_board.h +++ b/boards/breezy/breezy_board.h @@ -43,6 +43,8 @@ extern "C" #include "board.h" #include "sensors.h" +#include "configuration_enum.h" +#include "breezy_board_config_manager.h" namespace rosflight_firmware { @@ -79,6 +81,7 @@ class BreezyBoard : public Board bool new_imu_data_; uint64_t imu_time_us_; + BreezyBoardConfigManager config_manager_; public: BreezyBoard(); @@ -93,12 +96,17 @@ class BreezyBoard : public Board void clock_delay(uint32_t milliseconds) override; // serial - void serial_init(uint32_t baud_rate, uint32_t dev) override; + void serial_init(uint32_t baud_rate, hardware_config_t configuration) override; void serial_write(const uint8_t *src, size_t len) override; uint16_t serial_bytes_available() override; uint8_t serial_read() override; void serial_flush() override; + // hardware config + bool enable_device(device_t device, hardware_config_t configuration, const Params ¶ms) override; + void init_board_config_manager(ROSflight *rf) override; + BreezyBoardConfigManager & get_board_config_manager() override; + // sensors void sensors_init() override; uint16_t num_sensor_errors() override; diff --git a/boards/breezy/breezy_board_config_manager.cpp b/boards/breezy/breezy_board_config_manager.cpp new file mode 100644 index 00000000..b6be8570 --- /dev/null +++ b/boards/breezy/breezy_board_config_manager.cpp @@ -0,0 +1,36 @@ +#include "breezy_board_config_manager.h" +#include + +namespace rosflight_firmware +{ +hardware_config_t BreezyBoardConfigManager::get_max_config(device_t device) +{ + (void)device; + return 0; +} + +ConfigManager::config_response BreezyBoardConfigManager::check_config_change(device_t device, hardware_config_t config) +{ + (void)device; + (void)config; + ConfigManager::config_response response; + response.successful = false; + response.reboot_required = false; + strcpy(reinterpret_cast(response.message), "Feature unsupported on naze"); + return response; +} + +void BreezyBoardConfigManager::get_device_name(device_t device, uint8_t (&name)[20]) +{ + (void)device; + strcpy(reinterpret_cast(name), "Unsupported"); +} + +void BreezyBoardConfigManager::get_config_name(device_t device, hardware_config_t config, uint8_t (&name)[20]) +{ + (void)device; + (void)config; + strcpy(reinterpret_cast(name), "Unsupported"); +} + +} // namespace rosflight_firmware diff --git a/boards/breezy/breezy_board_config_manager.h b/boards/breezy/breezy_board_config_manager.h new file mode 100644 index 00000000..dcbd00ce --- /dev/null +++ b/boards/breezy/breezy_board_config_manager.h @@ -0,0 +1,18 @@ +#ifndef BREEZYBOARDCONFIGMANAGER_H +#define BREEZYBOARDCONFIGMANAGER_H + +#include "board_config_manager.h" + +namespace rosflight_firmware +{ +class BreezyBoardConfigManager : public BoardConfigManager +{ +public: + hardware_config_t get_max_config(device_t device) override; + ConfigManager::config_response check_config_change(device_t device, hardware_config_t config) override; + void get_device_name(device_t device, uint8_t (&name)[20]) override; + void get_config_name(device_t device, hardware_config_t config, uint8_t (&name)[20]) override; +}; +} // namespace rosflight_firmware + +#endif // BREEZYBOARDCONFIGMANAGER_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 57486408..2a90589e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -39,6 +39,8 @@ set(ROSFLIGHT_SRC ../src/command_manager.cpp ../src/rc.cpp ../src/mixer.cpp + ../src/memory_manager.cpp + ../src/config_manager.cpp ../comms/mavlink/mavlink.cpp ../lib/turbomath/turbomath.cpp ) @@ -51,6 +53,7 @@ add_executable(unit_tests common.cpp command_manager_test.cpp test_board.cpp + test_board_config_manager.cpp turbotrig_test.cpp state_machine_test.cpp command_manager_test.cpp diff --git a/test/test_board.cpp b/test/test_board.cpp index 9f8ba97c..c092ed80 100644 --- a/test/test_board.cpp +++ b/test/test_board.cpp @@ -77,12 +77,30 @@ uint64_t testBoard::clock_micros() { return time_us_; } void testBoard::clock_delay(uint32_t milliseconds) {} // serial -void testBoard::serial_init(uint32_t baud_rate, uint32_t dev) {} +void testBoard::serial_init(uint32_t baud_rate, hardware_config_t configuration) {} void testBoard::serial_write(const uint8_t *src, size_t len) {} uint16_t testBoard::serial_bytes_available() { return 0; } uint8_t testBoard::serial_read() { return 0; } void testBoard::serial_flush() {} +// Hardware config +bool testBoard::enable_device(device_t device, hardware_config_t configuration, const Params ¶ms) +{ + (void)device; + (void)configuration; + (void)params; + return true; +} + +void testBoard::init_board_config_manager(ROSflight *rf) +{ + (void)rf; +} + +TestBoardConfigManager &testBoard::get_board_config_manager() +{ + return config_manager_; +} // sensors void testBoard::sensors_init() {} uint16_t testBoard::num_sensor_errors() { return 0; } diff --git a/test/test_board.h b/test/test_board.h index 7649d9d7..6e824d04 100644 --- a/test/test_board.h +++ b/test/test_board.h @@ -34,6 +34,7 @@ #include "board.h" #include "sensors.h" +#include "test_board_config_manager.h" namespace rosflight_firmware { @@ -48,6 +49,7 @@ class testBoard : public Board float acc_[3] = {0, 0, 0}; float gyro_[3] = {0, 0, 0}; bool new_imu_ = false; + TestBoardConfigManager config_manager_; public: // setup @@ -60,12 +62,17 @@ class testBoard : public Board void clock_delay(uint32_t milliseconds) override; // serial - void serial_init(uint32_t baud_rate, uint32_t dev) override; + void serial_init(uint32_t baud_rate, hardware_config_t configuration) override; void serial_write(const uint8_t *src, size_t len) override; uint16_t serial_bytes_available() override; uint8_t serial_read() override; void serial_flush() override; +// Hardware config + bool enable_device(device_t device, hardware_config_t configuration, const Params ¶ms) override; + void init_board_config_manager(ROSflight *rf) override; + TestBoardConfigManager & get_board_config_manager() override; + // sensors void sensors_init() override; uint16_t num_sensor_errors() ; diff --git a/test/test_board_config_manager.cpp b/test/test_board_config_manager.cpp new file mode 100644 index 00000000..e11a9a73 --- /dev/null +++ b/test/test_board_config_manager.cpp @@ -0,0 +1,37 @@ +#include "test_board_config_manager.h" +#include +#include + +namespace rosflight_firmware +{ +hardware_config_t TestBoardConfigManager::get_max_config(device_t device) +{ + (void)device; + return 0; // This is not needed to test other software +} +ConfigManager::config_response TestBoardConfigManager::check_config_change(device_t device, hardware_config_t config) +{ + // A couple variations are given for testing + ConfigManager::config_response response; + response.successful = true; + response.reboot_required = true; + if(device == Configuration::SERIAL && config == 1) + { + response.successful = false; + strcpy(reinterpret_cast(response.message), "Fail for testing"); + return response; + } + strcpy(reinterpret_cast(response.message), "Succeed for testing"); + return response; +} +void TestBoardConfigManager::get_device_name(device_t device, uint8_t (&name)[20]) +{ + std::string device_name = "device #" + std::to_string(static_cast(device)); + strcpy(reinterpret_cast(name), device_name.c_str()); +} +void TestBoardConfigManager::get_config_name(device_t device, hardware_config_t config, uint8_t (&name)[20]) +{ + std::string config_name = "config " + std::to_string(static_cast(device)) + ","+std::to_string(static_cast(config)); + strcpy(reinterpret_cast(name), config_name.c_str()); +} +} diff --git a/test/test_board_config_manager.h b/test/test_board_config_manager.h new file mode 100644 index 00000000..d59e44c6 --- /dev/null +++ b/test/test_board_config_manager.h @@ -0,0 +1,18 @@ +#ifndef TESTBOARDCONFIGMANAGER_H +#define TESTBOARDCONFIGMANAGER_H + +#include "board_config_manager.h" + +namespace rosflight_firmware +{ +class TestBoardConfigManager : public BoardConfigManager +{ +public: + hardware_config_t get_max_config(device_t device) override; + ConfigManager::config_response check_config_change(device_t device, hardware_config_t config) override; + void get_device_name(device_t device, uint8_t (&name)[20]) override; + void get_config_name(device_t device, hardware_config_t config, uint8_t (&name)[20]) override; +}; + +} // rosflight_firmware +#endif // TESTBOARDCONFIGMANAGER_H