Skip to content

Commit

Permalink
Add implementations for breezy board and test board to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BillThePlatypus committed Jan 9, 2020
1 parent cf19795 commit 9d417d2
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 7 deletions.
2 changes: 1 addition & 1 deletion boards/airbourne/airbourne_board_config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(name);
const char *name_str;
const char *name_str = "Invalid Config";
switch(device)
{
case Configuration::SERIAL:
Expand Down
3 changes: 2 additions & 1 deletion boards/breezy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
22 changes: 20 additions & 2 deletions boards/breezy/breezy_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -110,6 +110,24 @@ void BreezyBoard::serial_flush()
return;
}

bool BreezyBoard::enable_device(device_t device, hardware_config_t configuration, const Params &params)
{
(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()
Expand Down
10 changes: 9 additions & 1 deletion boards/breezy/breezy_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -79,6 +81,7 @@ class BreezyBoard : public Board

bool new_imu_data_;
uint64_t imu_time_us_;
BreezyBoardConfigManager config_manager_;

public:
BreezyBoard();
Expand All @@ -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 &params) 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;
Expand Down
36 changes: 36 additions & 0 deletions boards/breezy/breezy_board_config_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "breezy_board_config_manager.h"
#include <cstring>

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<char*>(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<char*>(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<char*>(name), "Unsupported");
}

} // namespace rosflight_firmware
18 changes: 18 additions & 0 deletions boards/breezy/breezy_board_config_manager.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand Down
20 changes: 19 additions & 1 deletion test/test_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &params)
{
(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; }
Expand Down
9 changes: 8 additions & 1 deletion test/test_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "board.h"
#include "sensors.h"
#include "test_board_config_manager.h"

namespace rosflight_firmware
{
Expand All @@ -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
Expand All @@ -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 &params) 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() ;
Expand Down
37 changes: 37 additions & 0 deletions test/test_board_config_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "test_board_config_manager.h"
#include <cstring>
#include <string>

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<char*>(response.message), "Fail for testing");
return response;
}
strcpy(reinterpret_cast<char*>(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<int>(device));
strcpy(reinterpret_cast<char*>(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<int>(device)) + ","+std::to_string(static_cast<int>(config));
strcpy(reinterpret_cast<char*>(name), config_name.c_str());
}
}
18 changes: 18 additions & 0 deletions test/test_board_config_manager.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9d417d2

Please sign in to comment.