diff --git a/CMakeLists.txt b/CMakeLists.txt index e2d327a3722185972d8ad0290231b19f793045fc..e3908bd85a891f8aeb2c0f98a0b088d05b692207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,47 +86,9 @@ add_executable(nokia-groundstation-entry target_include_directories(nokia-groundstation-entry PRIVATE ${OBSW_INCLUDE_DIRS}) sbs_target(nokia-groundstation-entry stm32f429zi_nokia) -add_executable(base-groundstation-entry - src/entrypoints/Groundstation/base-groundstation-entry.cpp - ${GROUNDSTATION_COMMON} ${GROUNDSTATION_BASE} -) -target_include_directories(base-groundstation-entry PRIVATE ${OBSW_INCLUDE_DIRS}) -sbs_target(base-groundstation-entry stm32f767zi_gemini_gs) - -add_executable(automated-antennas-entry - src/entrypoints/Groundstation/Automated/automated-antennas-entry.cpp - ${ANTENNAS} ${GROUNDSTATION_COMMON} ${GROUNDSTATION_AUTOMATED} -) -target_include_directories(automated-antennas-entry PRIVATE ${OBSW_INCLUDE_DIRS}) -sbs_target(automated-antennas-entry stm32f767zi_automated_antennas) - -add_executable(test-automated-radio - src/entrypoints/Groundstation/Automated/test-automated-radio.cpp - ${ANTENNAS} ${GROUNDSTATION_COMMON} ${GROUNDSTATION_AUTOMATED} -) -target_include_directories(test-automated-radio PRIVATE ${OBSW_INCLUDE_DIRS}) -# target_compile_definitions(test-automated-radio PRIVATE NO_SD_LOGGING) -sbs_target(test-automated-radio stm32f767zi_automated_antennas) - -add_executable(test-steps src/entrypoints/Groundstation/Automated/test-steps.cpp ${ANTENNAS}) -target_include_directories(test-steps PRIVATE ${OBSW_INCLUDE_DIRS}) -# target_compile_definitions(test-steps PRIVATE NO_SD_LOGGING) -sbs_target(test-steps stm32f767zi_automated_antennas) - -add_executable(test-actuators src/entrypoints/Groundstation/Automated/test-actuators.cpp - ${ANTENNAS} ${GROUNDSTATION_COMMON} ${GROUNDSTATION_AUTOMATED} -) -target_include_directories(test-actuators PRIVATE ${OBSW_INCLUDE_DIRS}) -# target_compile_definitions(test-actuators PRIVATE NO_SD_LOGGING) -sbs_target(test-actuators stm32f767zi_automated_antennas) - -# add_executable(test-smcontroller src/entrypoints/Groundstation/Automated/test-smcontroller.cpp ${GROUNDSTATION_COMMON}) -# target_include_directories(test-smcontroller PRIVATE ${OBSW_INCLUDE_DIRS}) -# sbs_target(test-smcontroller stm32f767zi_nucleo) - add_executable(lyra-gs-entry src/entrypoints/Groundstation/lyra-gs-entry.cpp - ${ANTENNAS} ${GROUNDSTATION_COMMON} ${GROUNDSTATION_AUTOMATED} ${GROUNDSTATION_BASE} + ${LYRA_GS} ${GROUNDSTATION_COMMON} ) target_include_directories(lyra-gs-entry PRIVATE ${OBSW_INCLUDE_DIRS}) sbs_target(lyra-gs-entry stm32f767zi_lyra_gs) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 033cb76256abdcc9b784be1acdebfc6535500ee4..da0f6041c7baedef9891ea0b83645b72e1c2d5f3 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -49,13 +49,6 @@ set(GROUNDSTATION_COMMON src/boards/Groundstation/Common/HubBase.cpp ) -set(GS_COMPUTER - src/boards/Gs/Ports/Serial.cpp - src/boards/Gs/Radio/Radio.cpp - src/boards/Gs/Radio/RadioStatus.cpp - src/boards/Gs/Hub.cpp -) - set(MOTOR_SOURCES src/boards/Motor/PersistentVars/PersistentVars.cpp src/boards/Motor/HIL/HIL.cpp @@ -113,28 +106,19 @@ set(PAYLOAD_COMPUTER src/boards/Payload/Wing/WingAlgorithm.cpp ) -set(GROUNDSTATION_BASE - src/boards/Groundstation/Base/Radio/Radio.cpp - src/boards/Groundstation/Base/Ports/Ethernet.cpp - src/boards/Groundstation/Base/BoardStatus.cpp - src/boards/Groundstation/Base/Hub.cpp -) - set(GROUNDSTATION_NOKIA src/boards/Groundstation/Nokia/Radio/Radio.cpp src/boards/Groundstation/Nokia/Hub.cpp ) -set(GROUNDSTATION_AUTOMATED - src/boards/Groundstation/Automated/BoardStatus.cpp - src/boards/Groundstation/Automated/Radio/Radio.cpp - src/boards/Groundstation/Automated/Ports/Ethernet.cpp +set (LYRA_GS + src/boards/Groundstation/LyraGS/Radio/Radio.cpp + src/boards/Groundstation/LyraGS/Ports/Ethernet.cpp + src/boards/Groundstation/LyraGS/BoardStatus.cpp + src/boards/Groundstation/LyraGS/Base/Hub.cpp src/boards/Groundstation/Automated/Hub.cpp src/boards/Groundstation/Automated/Leds/Leds.cpp src/boards/Groundstation/Automated/SMA/SMA.cpp -) - -set(ANTENNAS src/boards/Groundstation/Automated/Actuators/Actuators.cpp src/boards/Groundstation/Automated/Sensors/Sensors.cpp -) +) \ No newline at end of file diff --git a/src/boards/Groundstation/Automated/BoardStatus.cpp b/src/boards/Groundstation/Automated/BoardStatus.cpp deleted file mode 100644 index b937aebc390b2482ab35e97b1a78e0ad9544b79f..0000000000000000000000000000000000000000 --- a/src/boards/Groundstation/Automated/BoardStatus.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Davide Mor - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "BoardStatus.h" - -#include <Groundstation/Automated/Actuators/Actuators.h> -#include <Groundstation/Automated/Ports/Ethernet.h> -#include <Groundstation/Automated/Radio/Radio.h> -#include <Groundstation/Automated/SMA/SMA.h> -#include <Groundstation/Automated/Sensors/Sensors.h> -#include <Groundstation/Common/Config/GeneralConfig.h> -#include <Groundstation/Common/HubBase.h> -#include <common/Mavlink.h> -#include <drivers/timer/TimestampTimer.h> - -using namespace Antennas; -using namespace Boardcore; -using namespace Groundstation; - -bool BoardStatus::isMainRadioPresent() { return main_radio_present; } -bool BoardStatus::isEthernetPresent() { return ethernet_present; } - -bool BoardStatus::start() -{ - if (!ActiveObject::start()) - { - return false; - } - - return true; -} - -void BoardStatus::setMainRadioPresent(bool present) -{ - main_radio_present = present; -} - -void BoardStatus::setEthernetPresent(bool present) -{ - ethernet_present = present; -} - -void BoardStatus::run() -{ - while (!shouldStop()) - { - miosix::Thread::sleep(Groundstation::RADIO_STATUS_PERIOD); - ModuleManager &modules = ModuleManager::getInstance(); - - auto vn300 = modules.get<Sensors>()->getVN300LastSample(); - - Actuators *actuators = modules.get<Actuators>(); - SMA *sm = modules.get<SMA>(); - - AntennaAngles targetAngles = sm->getTargetAngles(); - - mavlink_arp_tm_t tm = {0}; - tm.timestamp = TimestampTimer::getTimestamp(); /*< [us] Timestamp*/ - tm.state = static_cast<uint8_t>(sm->getStatus().state); /*< State*/ - tm.yaw = vn300.yaw; /*< [deg] Current Yaw*/ - tm.pitch = vn300.pitch; /*< [deg] Current Pitch*/ - tm.roll = vn300.roll; /*< [deg] Current Roll*/ - tm.target_yaw = targetAngles.yaw; /*< [deg] Target Yaw*/ - tm.target_pitch = targetAngles.pitch; /*< [deg] Target Pitch*/ - tm.stepperX_pos = actuators->getCurrentDegPosition( - StepperList::STEPPER_X); /*< [deg] StepperX target pos*/ - tm.stepperX_delta = actuators->getDeltaAngleDeg( - StepperList::STEPPER_X); /*< [deg] StepperX target delta deg*/ - tm.stepperX_speed = actuators->getSpeed( - StepperList::STEPPER_X); /*< [rps] StepperX Speed*/ - tm.stepperY_pos = actuators->getCurrentDegPosition( - StepperList::STEPPER_Y); /*< [deg] StepperY target pos*/ - tm.stepperY_delta = actuators->getDeltaAngleDeg( - StepperList::STEPPER_Y); /*< [deg] StepperY target delta deg*/ - tm.stepperY_speed = actuators->getSpeed( - StepperList::STEPPER_Y); /*< [rps] StepperY Speed*/ - tm.gps_latitude = vn300.latitude; /*< [deg] Latitude*/ - tm.gps_longitude = vn300.longitude; /*< [deg] Longitude*/ - tm.gps_height = vn300.altitude; /*< [m] Altitude*/ - tm.gps_fix = vn300.fix_ins; /*< Wether the GPS has a FIX*/ - tm.log_number = - Logger::getInstance().getCurrentLogNumber(); /*< Log number*/ - - tm.battery_voltage = -420.0; - - if (main_radio_present) - { - tm.main_radio_present = 1; - - auto stats = - ModuleManager::getInstance().get<RadioMain>()->getStats(); - tm.main_packet_tx_error_count = stats.send_errors; - tm.main_tx_bitrate = main_tx_bitrate.update(stats.bits_tx_count); - tm.main_packet_rx_success_count = stats.packet_rx_success_count; - tm.main_packet_rx_drop_count = stats.packet_rx_drop_count; - tm.main_rx_bitrate = main_rx_bitrate.update(stats.bits_rx_count); - tm.main_rx_rssi = stats.rx_rssi; - - last_main_stats = stats; - } - - if (ethernet_present) - { - auto stats = - ModuleManager::getInstance().get<Ethernet>()->getState(); - - tm.ethernet_present = 1; - tm.ethernet_status = (stats.link_up ? 1 : 0) | - (stats.full_duplex ? 2 : 0) | - (stats.based_100mbps ? 4 : 0); - } - - mavlink_message_t msg; - mavlink_msg_arp_tm_encode(SysIDs::MAV_SYSID_ARP, - Groundstation::GS_COMPONENT_ID, &msg, &tm); - - ModuleManager::getInstance().get<HubBase>()->dispatchIncomingMsg(msg); - } -}; diff --git a/src/boards/Groundstation/Automated/BoardStatus.h b/src/boards/Groundstation/Automated/BoardStatus.h deleted file mode 100644 index 60d57a2c789eddc2c67af972e08a81d54c5bc911..0000000000000000000000000000000000000000 --- a/src/boards/Groundstation/Automated/BoardStatus.h +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Davide Mor - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include <ActiveObject.h> -#include <Groundstation/Common/Config/RadioConfig.h> -#include <Groundstation/Common/Radio/RadioBase.h> -#include <utils/collections/CircularBuffer.h> - -#include <utils/ModuleManager/ModuleManager.hpp> - -namespace Antennas -{ - -/** - * @brief Utility to calculate the bitrate - */ -template <unsigned int WINDOW_SIZE, unsigned int PERIOD> -class BitrateCalculator -{ -public: - BitrateCalculator() {} - - /** - * @brief Update the calculator, should be called every PERIOD ms - */ - uint16_t update(uint32_t sample) - { - if (window.isFull()) - { - uint32_t last = window.pop(); - window.put(sample); - - uint16_t delta = sample - last; - - // window size is in ms, we want the result in s - return delta * 1000 / WINDOW_SIZE; - } - else - { - window.put(sample); - return 0; - } - } - -private: - Boardcore::CircularBuffer<uint32_t, WINDOW_SIZE / PERIOD> window; -}; - -/** - * @brief Class responsible for keeping track of radio status and metrics. - */ -class BoardStatus : public Boardcore::Module, protected Boardcore::ActiveObject -{ -public: - BoardStatus() {} - - bool start(); - - /** - * @brief Check wether the main radio was found during boot. - */ - bool isMainRadioPresent(); - - /** - * @brief Check wether the ethernet was found during boot. - */ - bool isEthernetPresent(); - - void setMainRadioPresent(bool present); - void setEthernetPresent(bool present); - -protected: - void run() override; - - Groundstation::RadioStats last_main_stats = {0}; - - BitrateCalculator<Groundstation::RADIO_BITRATE_WINDOW_SIZE, - Groundstation::RADIO_STATUS_PERIOD> - main_tx_bitrate; - BitrateCalculator<Groundstation::RADIO_BITRATE_WINDOW_SIZE, - Groundstation::RADIO_STATUS_PERIOD> - main_rx_bitrate; - - bool main_radio_present = false; - bool ethernet_present = false; -}; - -} // namespace Antennas \ No newline at end of file diff --git a/src/boards/Groundstation/Automated/Buses.h b/src/boards/Groundstation/Automated/Buses.h deleted file mode 100644 index cf35a02e4bd2894ccda7b22e82fe87163f126c79..0000000000000000000000000000000000000000 --- a/src/boards/Groundstation/Automated/Buses.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Emilio Corigliano - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#pragma once - -#include <drivers/spi/SPIBus.h> -#include <drivers/usart/USART.h> - -#include <utils/ModuleManager/ModuleManager.hpp> - -namespace Antennas -{ - -class Buses : public Boardcore::Module -{ -public: - Boardcore::USART usart2; - Boardcore::USART uart4; - Boardcore::SPIBus radio_bus; - Boardcore::SPIBus ethernet_bus; - - Buses() - : usart2(USART2, 115200), uart4(UART4, 115200), radio_bus(SPI1), - ethernet_bus(SPI4) - { - } -}; -} // namespace Antennas \ No newline at end of file diff --git a/src/boards/Groundstation/Automated/Hub.cpp b/src/boards/Groundstation/Automated/Hub.cpp index 8f9f70d5e302b6bdcf7b2e1b044ba792c735e7c1..9e5399d69133b993236435a1cbf0f469cc04000a 100644 --- a/src/boards/Groundstation/Automated/Hub.cpp +++ b/src/boards/Groundstation/Automated/Hub.cpp @@ -23,12 +23,12 @@ #include "Hub.h" #include <Groundstation/Automated/Actuators/Actuators.h> -#include <Groundstation/Automated/BoardStatus.h> -#include <Groundstation/Automated/Ports/Ethernet.h> -#include <Groundstation/Automated/Radio/Radio.h> #include <Groundstation/Automated/SMA/SMA.h> #include <Groundstation/Common/Config/GeneralConfig.h> #include <Groundstation/Common/Ports/Serial.h> +#include <Groundstation/LyraGS/BoardStatus.h> +#include <Groundstation/LyraGS/Ports/Ethernet.h> +#include <Groundstation/LyraGS/Radio/Radio.h> #include <algorithms/NAS/NASState.h> #include <common/Events.h> #include <common/Mavlink.h> @@ -49,7 +49,7 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) bool send_ok = false; ModuleManager& modules = ModuleManager::getInstance(); - RadioMain* radio = modules.get<RadioMain>(); + LyraGS::RadioMain* radio = modules.get<LyraGS::RadioMain>(); if (msg.sysid == MAV_SYSID_ARP) { @@ -284,7 +284,8 @@ void Hub::dispatchIncomingMsg(const mavlink_message_t& msg) Logger::getInstance().log(gpsState); } - Ethernet* ethernet = ModuleManager::getInstance().get<Ethernet>(); + LyraGS::Ethernet* ethernet = + ModuleManager::getInstance().get<LyraGS::Ethernet>(); ethernet->sendMsg(msg); } diff --git a/src/boards/Groundstation/Automated/Radio/Radio.cpp b/src/boards/Groundstation/Automated/Radio/Radio.cpp deleted file mode 100644 index c652e9ea20846be6ebc1e149e39cbd0274e39ad5..0000000000000000000000000000000000000000 --- a/src/boards/Groundstation/Automated/Radio/Radio.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Davide Mor - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "Radio.h" - -#include <Groundstation/Automated/BoardStatus.h> -#include <Groundstation/Automated/Buses.h> -#include <Groundstation/Automated/Hub.h> -#include <Groundstation/Common/Ports/Serial.h> -#include <interfaces-impl/hwmapping.h> -#include <radio/SX1278/SX1278Frontends.h> - -using namespace Antennas; -using namespace Boardcore; -using namespace miosix; - -void __attribute__((used)) EXTI6_IRQHandlerImpl() -{ - ModuleManager::getInstance().get<RadioMain>()->handleDioIRQ(); -} - -void __attribute__((used)) EXTI4_IRQHandlerImpl() -{ - ModuleManager::getInstance().get<RadioMain>()->handleDioIRQ(); -} - -void __attribute__((used)) EXTI5_IRQHandlerImpl() -{ - ModuleManager::getInstance().get<RadioMain>()->handleDioIRQ(); -} - -namespace Antennas -{ - -bool RadioMain::start() -{ - std::unique_ptr<Boardcore::SX1278Fsk> sx1278; - - std::unique_ptr<SX1278::ISX1278Frontend> frontend; - - if (hasBackup) - frontend = std::make_unique<EbyteFrontend>(radio::txen::getPin(), - radio::rxen::getPin()); - else - frontend = std::make_unique<Skyward433Frontend>(); - - sx1278 = std::make_unique<Boardcore::SX1278Fsk>( - ModuleManager::getInstance().get<Antennas::Buses>()->radio_bus, - radio::cs::getPin(), radio::dio0::getPin(), radio::dio1::getPin(), - radio::dio3::getPin(), SPI::ClockDivider::DIV_64, std::move(frontend)); - - // First check if the device is even connected - bool present = sx1278->checkVersion(); - - ModuleManager::getInstance().get<BoardStatus>()->setMainRadioPresent( - present); - - if (present) - { - // Configure the radio - if (sx1278->configure(Common::MAIN_RADIO_CONFIG) != - SX1278Fsk::Error::NONE) - { - return false; - } - - // Initialize if only if present - if (!RadioBase::start(std::move(sx1278))) - { - return false; - } - } - - return true; -} - -} // namespace Antennas \ No newline at end of file diff --git a/src/boards/Groundstation/Automated/Radio/Radio.h b/src/boards/Groundstation/Automated/Radio/Radio.h deleted file mode 100644 index fbf76965629f7aa26c75052b8ca5b00cc71d8691..0000000000000000000000000000000000000000 --- a/src/boards/Groundstation/Automated/Radio/Radio.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Davide Mor - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include <Groundstation/Common/Radio/RadioBase.h> - -namespace Antennas -{ - -class RadioMain : public Groundstation::RadioBase, public Boardcore::Module -{ -public: - [[nodiscard]] bool start(); - - RadioMain(bool hasBackup, uint8_t ipConfig) - : hasBackup{hasBackup}, ipConfig{ipConfig} {}; - - RadioMain() : hasBackup{false}, ipConfig{0} {}; - -private: - bool hasBackup = false; - uint8_t ipConfig = 0; -}; - -} // namespace Antennas \ No newline at end of file diff --git a/src/boards/Groundstation/Automated/Sensors/Sensors.cpp b/src/boards/Groundstation/Automated/Sensors/Sensors.cpp index a049c3c3a0e87ee4a70410d8c572e745423ea799..8b1209533d4bc3159c8264de9b772e9f08c44031 100644 --- a/src/boards/Groundstation/Automated/Sensors/Sensors.cpp +++ b/src/boards/Groundstation/Automated/Sensors/Sensors.cpp @@ -54,7 +54,7 @@ bool Sensors::start() bool Sensors::vn300Init() { vn300 = new Boardcore::VN300( - ModuleManager::getInstance().get<Buses>()->usart2, 115200, + ModuleManager::getInstance().get<LyraGS::Buses>()->usart2, 115200, VN300Defs::SampleOptions::ARP, VNCommonSerial::CRCOptions::CRC_ENABLE_16); ///< TODO: see that CRC ///< behaves correctly diff --git a/src/boards/Groundstation/Automated/Sensors/Sensors.h b/src/boards/Groundstation/Automated/Sensors/Sensors.h index b73fda8e773987bc1ece8e59bcb9c978343e82a8..f2e399a9f0cd6ec22c51065c48efbd97d320353a 100644 --- a/src/boards/Groundstation/Automated/Sensors/Sensors.h +++ b/src/boards/Groundstation/Automated/Sensors/Sensors.h @@ -23,7 +23,7 @@ #include <utils/ModuleManager/ModuleManager.hpp> -#include "Groundstation/Automated/Buses.h" +#include "Groundstation/LyraGS/Buses.h" #include "sensors/SensorManager.h" #include "sensors/Vectornav/VN300/VN300.h" diff --git a/src/boards/Groundstation/Base/Ports/Ethernet.cpp b/src/boards/Groundstation/Base/Ports/Ethernet.cpp deleted file mode 100644 index 77102bdc1a30f11535e9c143f804716843167b77..0000000000000000000000000000000000000000 --- a/src/boards/Groundstation/Base/Ports/Ethernet.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Davide Mor - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "Ethernet.h" - -#include <Groundstation/Automated/Buses.h> -#include <interfaces-impl/hwmapping.h> - -using namespace Groundstation; -using namespace GroundstationBase; -using namespace Antennas; -using namespace Boardcore; -using namespace miosix; - -void __attribute__((used)) MIOSIX_ETHERNET_IRQ() -{ - ModuleManager::getInstance().get<Ethernet>()->handleINTn(); -} - -bool Ethernet::start() -{ - std::unique_ptr<Wiz5500> wiz5500 = std::make_unique<Wiz5500>( - ModuleManager::getInstance().get<Buses>()->ethernet_bus, - ethernet::cs::getPin(), ethernet::intr::getPin(), - SPI::ClockDivider::DIV_64); - - // First check if the device is even connected - bool present = wiz5500->checkVersion(); - - if (!present) - { - return false; - } - - if (!EthernetBase::start(std::move(wiz5500))) - { - return false; - } - - return true; -} diff --git a/src/boards/Groundstation/Base/Ports/Ethernet.h b/src/boards/Groundstation/Base/Ports/Ethernet.h deleted file mode 100644 index 4a8283b1915e0600dff19e94d191038b88d9274a..0000000000000000000000000000000000000000 --- a/src/boards/Groundstation/Base/Ports/Ethernet.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Davide Mor - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include <Groundstation/Common/Ports/EthernetBase.h> - -#include <utils/ModuleManager/ModuleManager.hpp> - -namespace GroundstationBase -{ - -class Ethernet : public Groundstation::EthernetBase, public Boardcore::Module -{ -public: - [[nodiscard]] bool start(); -}; - -} // namespace GroundstationBase \ No newline at end of file diff --git a/src/boards/Groundstation/DipReader.h b/src/boards/Groundstation/DipReader.h deleted file mode 100644 index ad6878677e8386935dfbd695a5dd7f0c5d2cfd17..0000000000000000000000000000000000000000 --- a/src/boards/Groundstation/DipReader.h +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (c) 2024 Skyward Experimental Rocketry - * Author: Nicolò Caruso - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <interfaces-impl/hwmapping.h> -#include <miosix.h> - -/** - * @brief Dip switch status for the GS board - */ -struct DipStatus -{ - bool isARP; - bool hasBackup; - uint8_t ipConfig; -}; - -/** - * @brief Dip switch driver to read the current status of the switch - */ -class DipReader -{ -public: - static DipStatus readDip() - { - DipStatus dipReading; - dipReading.ipConfig = 0; - - // Write to the shift register (CS == Not LD) - miosix::dipSwitch::sh::low(); - miosix::dipSwitch::clk::high(); - miosix::delayUs(100); - miosix::dipSwitch::clk::low(); - miosix::dipSwitch::sh::high(); - miosix::delayUs(5); - - // Read first register GS(0)/ARP(1) - dipReading.isARP = readBit(); - dipReading.hasBackup = readBit(); - dipReading.ipConfig |= readBit(); - dipReading.ipConfig |= readBit() << 1; - dipReading.ipConfig |= readBit() << 2; - dipReading.ipConfig |= readBit() << 3; - dipReading.ipConfig |= readBit() << 4; - dipReading.ipConfig |= readBit() << 5; - - return dipReading; - } - -private: - static bool readBit() - { - bool bit; - miosix::dipSwitch::clk::high(); - miosix::delayUs(5); - bit = miosix::dipSwitch::qh::value(); - miosix::delayUs(5); - miosix::dipSwitch::clk::low(); - miosix::delayUs(5); - return bit; - } -}; \ No newline at end of file diff --git a/src/boards/Groundstation/Base/Hub.cpp b/src/boards/Groundstation/LyraGS/Base/Hub.cpp similarity index 76% rename from src/boards/Groundstation/Base/Hub.cpp rename to src/boards/Groundstation/LyraGS/Base/Hub.cpp index 718433305cc579cc129502ab6cd8898453f26885..38fdaa65e181769bbe9d702ae65306df3aa4a3ed 100644 --- a/src/boards/Groundstation/Base/Hub.cpp +++ b/src/boards/Groundstation/LyraGS/Base/Hub.cpp @@ -22,11 +22,11 @@ #include "Hub.h" -#include <Groundstation/Base/BoardStatus.h> -#include <Groundstation/Base/Ports/Ethernet.h> -#include <Groundstation/Base/Radio/Radio.h> #include <Groundstation/Common/Config/GeneralConfig.h> #include <Groundstation/Common/Ports/Serial.h> +#include <Groundstation/LyraGS/BoardStatus.h> +#include <Groundstation/LyraGS/Ports/Ethernet.h> +#include <Groundstation/LyraGS/Radio/Radio.h> using namespace Groundstation; using namespace GroundstationBase; @@ -34,19 +34,22 @@ using namespace Boardcore; void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) { - BoardStatus* status = ModuleManager::getInstance().get<BoardStatus>(); + LyraGS::BoardStatus* status = + ModuleManager::getInstance().get<LyraGS::BoardStatus>(); bool send_ok = false; if (status->isMainRadioPresent() && msg.sysid == MAV_SYSID_MAIN) { - RadioMain* radio = ModuleManager::getInstance().get<RadioMain>(); + LyraGS::RadioMain* radio = + ModuleManager::getInstance().get<LyraGS::RadioMain>(); send_ok |= radio->sendMsg(msg); } if (status->isPayloadRadioPresent() && msg.sysid == MAV_SYSID_PAYLOAD) { - RadioPayload* radio = ModuleManager::getInstance().get<RadioPayload>(); + LyraGS::RadioPayload* radio = + ModuleManager::getInstance().get<LyraGS::RadioPayload>(); send_ok |= radio->sendMsg(msg); } @@ -61,14 +64,16 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) void Hub::dispatchIncomingMsg(const mavlink_message_t& msg) { - BoardStatus* status = ModuleManager::getInstance().get<BoardStatus>(); + LyraGS::BoardStatus* status = + ModuleManager::getInstance().get<LyraGS::BoardStatus>(); Serial* serial = ModuleManager::getInstance().get<Serial>(); serial->sendMsg(msg); if (status->isEthernetPresent()) { - Ethernet* ethernet = ModuleManager::getInstance().get<Ethernet>(); + LyraGS::Ethernet* ethernet = + ModuleManager::getInstance().get<LyraGS::Ethernet>(); ethernet->sendMsg(msg); } } \ No newline at end of file diff --git a/src/boards/Groundstation/Base/Hub.h b/src/boards/Groundstation/LyraGS/Base/Hub.h similarity index 100% rename from src/boards/Groundstation/Base/Hub.h rename to src/boards/Groundstation/LyraGS/Base/Hub.h diff --git a/src/boards/Groundstation/LyraGS/BoardStatus.cpp b/src/boards/Groundstation/LyraGS/BoardStatus.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b754a9aa0486d014f7b1b348207a67e945ed422 --- /dev/null +++ b/src/boards/Groundstation/LyraGS/BoardStatus.cpp @@ -0,0 +1,211 @@ +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Author: Nicolò Caruso + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "BoardStatus.h" + +#include <Groundstation/Automated/Actuators/Actuators.h> +#include <Groundstation/Automated/SMA/SMA.h> +#include <Groundstation/Automated/Sensors/Sensors.h> +#include <Groundstation/Common/Config/GeneralConfig.h> +#include <Groundstation/Common/HubBase.h> +#include <Groundstation/LyraGS/Ports/Ethernet.h> +#include <Groundstation/LyraGS/Radio/Radio.h> +#include <common/Mavlink.h> +#include <drivers/timer/TimestampTimer.h> + +using namespace Boardcore; +using namespace Groundstation; +using namespace LyraGS; + +bool BoardStatus::isMainRadioPresent() { return main_radio_present; } +bool BoardStatus::isPayloadRadioPresent() { return payload_radio_present; } +bool BoardStatus::isEthernetPresent() { return ethernet_present; } + +bool BoardStatus::start() +{ + if (!ActiveObject::start()) + { + return false; + } + + return true; +} + +void BoardStatus::setMainRadioPresent(bool present) +{ + main_radio_present = present; +} + +void BoardStatus::setPayloadRadioPresent(bool present) +{ + payload_radio_present = present; +} + +void BoardStatus::setEthernetPresent(bool present) +{ + ethernet_present = present; +} + +void BoardStatus::arpRoutine() +{ + using namespace Antennas; + + miosix::Thread::sleep(Groundstation::RADIO_STATUS_PERIOD); + ModuleManager &modules = ModuleManager::getInstance(); + + auto vn300 = modules.get<Sensors>()->getVN300LastSample(); + + Actuators *actuators = modules.get<Actuators>(); + SMA *sm = modules.get<SMA>(); + + AntennaAngles targetAngles = sm->getTargetAngles(); + + mavlink_arp_tm_t tm = {0}; + tm.timestamp = TimestampTimer::getTimestamp(); /*< [us] Timestamp*/ + tm.state = static_cast<uint8_t>(sm->getStatus().state); /*< State*/ + tm.yaw = vn300.yaw; /*< [deg] Current Yaw*/ + tm.pitch = vn300.pitch; /*< [deg] Current Pitch*/ + tm.roll = vn300.roll; /*< [deg] Current Roll*/ + tm.target_yaw = targetAngles.yaw; /*< [deg] Target Yaw*/ + tm.target_pitch = targetAngles.pitch; /*< [deg] Target Pitch*/ + tm.stepperX_pos = actuators->getCurrentDegPosition( + StepperList::STEPPER_X); /*< [deg] StepperX target pos*/ + tm.stepperX_delta = actuators->getDeltaAngleDeg( + StepperList::STEPPER_X); /*< [deg] StepperX target delta deg*/ + tm.stepperX_speed = + actuators->getSpeed(StepperList::STEPPER_X); /*< [rps] StepperX Speed*/ + tm.stepperY_pos = actuators->getCurrentDegPosition( + StepperList::STEPPER_Y); /*< [deg] StepperY target pos*/ + tm.stepperY_delta = actuators->getDeltaAngleDeg( + StepperList::STEPPER_Y); /*< [deg] StepperY target delta deg*/ + tm.stepperY_speed = + actuators->getSpeed(StepperList::STEPPER_Y); /*< [rps] StepperY Speed*/ + tm.gps_latitude = vn300.latitude; /*< [deg] Latitude*/ + tm.gps_longitude = vn300.longitude; /*< [deg] Longitude*/ + tm.gps_height = vn300.altitude; /*< [m] Altitude*/ + tm.gps_fix = vn300.fix_ins; /*< Wether the GPS has a FIX*/ + tm.log_number = + Logger::getInstance().getCurrentLogNumber(); /*< Log number*/ + + tm.battery_voltage = -420.0; + + if (main_radio_present) + { + tm.main_radio_present = 1; + + auto stats = ModuleManager::getInstance().get<RadioMain>()->getStats(); + tm.main_packet_tx_error_count = stats.send_errors; + tm.main_tx_bitrate = main_tx_bitrate.update(stats.bits_tx_count); + tm.main_packet_rx_success_count = stats.packet_rx_success_count; + tm.main_packet_rx_drop_count = stats.packet_rx_drop_count; + tm.main_rx_bitrate = main_rx_bitrate.update(stats.bits_rx_count); + tm.main_rx_rssi = stats.rx_rssi; + + last_main_stats = stats; + } + + if (ethernet_present) + { + auto stats = ModuleManager::getInstance().get<Ethernet>()->getState(); + + tm.ethernet_present = 1; + tm.ethernet_status = (stats.link_up ? 1 : 0) | + (stats.full_duplex ? 2 : 0) | + (stats.based_100mbps ? 4 : 0); + } + + mavlink_message_t msg; + mavlink_msg_arp_tm_encode(SysIDs::MAV_SYSID_ARP, + Groundstation::GS_COMPONENT_ID, &msg, &tm); + + ModuleManager::getInstance().get<HubBase>()->dispatchIncomingMsg(msg); +} + +void BoardStatus::GSRoutine() +{ + using namespace Groundstation; + + miosix::Thread::sleep(RADIO_STATUS_PERIOD); + + mavlink_receiver_tm_t tm = {0}; + tm.timestamp = TimestampTimer::getTimestamp(); + tm.battery_voltage = -420.0; + + if (main_radio_present) + { + tm.main_radio_present = 1; + + auto stats = ModuleManager::getInstance().get<RadioMain>()->getStats(); + tm.main_packet_tx_error_count = stats.send_errors; + tm.main_tx_bitrate = main_tx_bitrate.update(stats.bits_tx_count); + tm.main_packet_rx_success_count = stats.packet_rx_success_count; + tm.main_packet_rx_drop_count = stats.packet_rx_drop_count; + tm.main_rx_bitrate = main_rx_bitrate.update(stats.bits_rx_count); + tm.main_rx_rssi = stats.rx_rssi; + tm.main_rx_fei = stats.rx_fei; + + last_main_stats = stats; + } + + if (payload_radio_present) + { + tm.payload_radio_present = 1; + + auto stats = + ModuleManager::getInstance().get<RadioPayload>()->getStats(); + tm.payload_packet_tx_error_count = stats.send_errors; + tm.payload_tx_bitrate = payload_tx_bitrate.update(stats.bits_tx_count); + tm.payload_packet_rx_success_count = stats.packet_rx_success_count; + tm.payload_packet_rx_drop_count = stats.packet_rx_drop_count; + tm.payload_rx_bitrate = payload_rx_bitrate.update(stats.bits_rx_count); + tm.payload_rx_rssi = stats.rx_rssi; + tm.payload_rx_fei = stats.rx_fei; + + last_payload_stats = stats; + } + + if (ethernet_present) + { + auto stats = ModuleManager::getInstance().get<Ethernet>()->getState(); + + tm.ethernet_present = 1; + tm.ethernet_status = (stats.link_up ? 1 : 0) | + (stats.full_duplex ? 2 : 0) | + (stats.based_100mbps ? 4 : 0); + } + + mavlink_message_t msg; + mavlink_msg_receiver_tm_encode(GS_SYSTEM_ID, GS_COMPONENT_ID, &msg, &tm); + + ModuleManager::getInstance().get<HubBase>()->dispatchIncomingMsg(msg); +} + +void BoardStatus::run() +{ + while (!shouldStop()) + { + if (isArp) + arpRoutine(); + else + GSRoutine(); + } +} \ No newline at end of file diff --git a/src/boards/Groundstation/Base/BoardStatus.h b/src/boards/Groundstation/LyraGS/BoardStatus.h similarity index 93% rename from src/boards/Groundstation/Base/BoardStatus.h rename to src/boards/Groundstation/LyraGS/BoardStatus.h index c684a33193256e2fdde4041c28ce41c27820fbe9..10a14c4bf845c2d412812b0210ebf3dd99999083 100644 --- a/src/boards/Groundstation/Base/BoardStatus.h +++ b/src/boards/Groundstation/LyraGS/BoardStatus.h @@ -1,5 +1,5 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Davide Mor +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Author: Nicolò Caruso * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ #include <utils/ModuleManager/ModuleManager.hpp> -namespace GroundstationBase +namespace LyraGS { /** @@ -73,7 +73,7 @@ private: class BoardStatus : public Boardcore::Module, private Boardcore::ActiveObject { public: - BoardStatus() {} + explicit BoardStatus(bool isArp) : isArp{isArp} {} bool start(); @@ -97,6 +97,8 @@ public: void setEthernetPresent(bool present); private: + void arpRoutine(); + void GSRoutine(); void run() override; Groundstation::RadioStats last_main_stats = {0}; @@ -118,6 +120,7 @@ private: bool main_radio_present = false; bool payload_radio_present = false; bool ethernet_present = false; + bool isArp = false; }; -} // namespace GroundstationBase \ No newline at end of file +} // namespace LyraGS \ No newline at end of file diff --git a/src/boards/Groundstation/Base/Buses.h b/src/boards/Groundstation/LyraGS/Buses.h similarity index 76% rename from src/boards/Groundstation/Base/Buses.h rename to src/boards/Groundstation/LyraGS/Buses.h index e776148116ef7d9d5a8dd6da54ff568eb840ee23..ead43b9b116f86bb476c1eda5c5a2a4d5a45af41 100644 --- a/src/boards/Groundstation/Base/Buses.h +++ b/src/boards/Groundstation/LyraGS/Buses.h @@ -1,5 +1,5 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Davide Mor +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Author: Nicolò Caruso * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,12 +23,13 @@ #pragma once #include <drivers/spi/SPIBus.h> +#include <drivers/usart/USART.h> #include <utils/ModuleManager/ModuleManager.hpp> #include "interfaces-impl/hwmapping.h" -namespace GroundstationBase +namespace LyraGS { class Buses : public Boardcore::Module @@ -36,13 +37,16 @@ class Buses : public Boardcore::Module public: Boardcore::SPIBus radio1_bus; Boardcore::SPIBus radio2_bus; + Boardcore::USART usart2; + Boardcore::USART uart4; Boardcore::SPIBus ethernet_bus; Buses() - : radio1_bus(MIOSIX_RADIO1_SPI), radio2_bus(MIOSIX_RADIO2_SPI), - ethernet_bus(MIOSIX_ETHERNET_SPI) + : radio1_bus{MIOSIX_RADIO1_SPI}, radio2_bus{MIOSIX_RADIO2_SPI}, + usart2{USART2, 115200}, uart4{UART4, 115200}, ethernet_bus{ + MIOSIX_ETHERNET_SPI} { } }; -} // namespace GroundstationBase \ No newline at end of file +} // namespace LyraGS \ No newline at end of file diff --git a/src/boards/Groundstation/Automated/Ports/Ethernet.cpp b/src/boards/Groundstation/LyraGS/Ports/Ethernet.cpp similarity index 90% rename from src/boards/Groundstation/Automated/Ports/Ethernet.cpp rename to src/boards/Groundstation/LyraGS/Ports/Ethernet.cpp index 3636012af18b2b4896ec1d77b522783b71addf47..d11f24aa2fb69add4f189615558defcc811a3186 100644 --- a/src/boards/Groundstation/Automated/Ports/Ethernet.cpp +++ b/src/boards/Groundstation/LyraGS/Ports/Ethernet.cpp @@ -22,13 +22,13 @@ #include "Ethernet.h" -#include <Groundstation/Automated/Buses.h> +#include <Groundstation/LyraGS/Buses.h> #include <interfaces-impl/hwmapping.h> -using namespace Groundstation; -using namespace Antennas; using namespace Boardcore; -using namespace miosix; + +namespace LyraGS +{ void __attribute__((used)) MIOSIX_ETHERNET_IRQ() { @@ -39,7 +39,7 @@ bool Ethernet::start() { std::unique_ptr<Wiz5500> wiz5500 = std::make_unique<Wiz5500>( ModuleManager::getInstance().get<Buses>()->ethernet_bus, - ethernet::cs::getPin(), ethernet::intr::getPin(), + miosix::ethernet::cs::getPin(), miosix::ethernet::intr::getPin(), SPI::ClockDivider::DIV_64); // First check if the device is even connected @@ -57,3 +57,4 @@ bool Ethernet::start() return true; } +} // namespace LyraGS \ No newline at end of file diff --git a/src/boards/Groundstation/Automated/Ports/Ethernet.h b/src/boards/Groundstation/LyraGS/Ports/Ethernet.h similarity index 96% rename from src/boards/Groundstation/Automated/Ports/Ethernet.h rename to src/boards/Groundstation/LyraGS/Ports/Ethernet.h index a49803d78b93f4a8b40cb2ca15064ba3e04f75a6..5b372398ce13ddb178853a0e95b3f8988563ad94 100644 --- a/src/boards/Groundstation/Automated/Ports/Ethernet.h +++ b/src/boards/Groundstation/LyraGS/Ports/Ethernet.h @@ -26,7 +26,7 @@ #include <utils/ModuleManager/ModuleManager.hpp> -namespace Antennas +namespace LyraGS { class Ethernet : public Groundstation::EthernetBase, public Boardcore::Module @@ -35,4 +35,4 @@ public: [[nodiscard]] bool start(); }; -} // namespace Antennas +} // namespace LyraGS \ No newline at end of file diff --git a/src/boards/Groundstation/Base/Radio/Radio.cpp b/src/boards/Groundstation/LyraGS/Radio/Radio.cpp similarity index 90% rename from src/boards/Groundstation/Base/Radio/Radio.cpp rename to src/boards/Groundstation/LyraGS/Radio/Radio.cpp index d7c763f90794934f8680e238d38b9704b64a8a99..4780fcab966bd98c726b25206be8694891b9c320 100644 --- a/src/boards/Groundstation/Base/Radio/Radio.cpp +++ b/src/boards/Groundstation/LyraGS/Radio/Radio.cpp @@ -22,14 +22,15 @@ #include "Radio.h" -#include <Groundstation/Base/BoardStatus.h> -#include <Groundstation/Base/Buses.h> -#include <Groundstation/Base/Hub.h> +#include <Groundstation/Common/HubBase.h> #include <Groundstation/Common/Ports/Serial.h> +#include <Groundstation/LyraGS/BoardStatus.h> +#include <Groundstation/LyraGS/Buses.h> +#include <interfaces-impl/hwmapping.h> #include <radio/SX1278/SX1278Frontends.h> using namespace Groundstation; -using namespace GroundstationBase; +using namespace LyraGS; using namespace Boardcore; using namespace miosix; @@ -114,15 +115,12 @@ bool RadioPayload::start() frontend = std::make_unique<EbyteFrontend>(radio2::txen::getPin(), radio2::rxen::getPin()); else - { frontend = std::make_unique<Skyward433Frontend>(); - sx1278 = std::make_unique<Boardcore::SX1278Fsk>( - ModuleManager::getInstance().get<Buses>()->radio2_bus, - radio2::cs::getPin(), radio2::dio0::getPin(), - radio2::dio1::getPin(), radio2::dio3::getPin(), - SPI::ClockDivider::DIV_64, std::move(frontend)); - } + sx1278 = std::make_unique<Boardcore::SX1278Fsk>( + ModuleManager::getInstance().get<Buses>()->radio2_bus, + radio2::cs::getPin(), radio2::dio0::getPin(), radio2::dio1::getPin(), + radio2::dio3::getPin(), SPI::ClockDivider::DIV_64, std::move(frontend)); // First check if the device is even connected bool present = sx1278->checkVersion(); diff --git a/src/boards/Groundstation/Base/Radio/Radio.h b/src/boards/Groundstation/LyraGS/Radio/Radio.h similarity index 96% rename from src/boards/Groundstation/Base/Radio/Radio.h rename to src/boards/Groundstation/LyraGS/Radio/Radio.h index 9e488159641357278d7ecd66392fd2beb11578db..71e632add52458a67eca845cb245f788959d9ca8 100644 --- a/src/boards/Groundstation/Base/Radio/Radio.h +++ b/src/boards/Groundstation/LyraGS/Radio/Radio.h @@ -24,7 +24,7 @@ #include <Groundstation/Common/Radio/RadioBase.h> -namespace GroundstationBase +namespace LyraGS { class RadioMain : public Groundstation::RadioBase, public Boardcore::Module @@ -57,4 +57,4 @@ private: uint8_t ipConfig = 0; }; -} // namespace GroundstationBase \ No newline at end of file +} // namespace LyraGS \ No newline at end of file diff --git a/src/entrypoints/Groundstation/Automated/automated-antennas-entry.cpp b/src/entrypoints/Groundstation/Automated/automated-antennas-entry.cpp index 6194548a886962af4b3634118a8c0072028d5e02..15c5ed3ed2562f390fbfe632ba6eebf8b8110ef7 100644 --- a/src/entrypoints/Groundstation/Automated/automated-antennas-entry.cpp +++ b/src/entrypoints/Groundstation/Automated/automated-antennas-entry.cpp @@ -21,7 +21,6 @@ */ #include <Groundstation/Automated/Actuators/Actuators.h> -#include <Groundstation/Automated/BoardStatus.h> #include <Groundstation/Automated/Buses.h> #include <Groundstation/Automated/Hub.h> #include <Groundstation/Automated/Leds/Leds.h> @@ -30,6 +29,7 @@ #include <Groundstation/Automated/SMA/SMA.h> #include <Groundstation/Automated/Sensors/Sensors.h> #include <Groundstation/Common/Ports/Serial.h> +#include <Groundstation/LyraGS/BoardStatus.h> #include <common/Events.h> #include <diagnostic/PrintLogger.h> #include <events/EventBroker.h> diff --git a/src/entrypoints/Groundstation/Automated/test-automated-radio.cpp b/src/entrypoints/Groundstation/Automated/test-automated-radio.cpp index 7636d6b8550cc5ba970b6c518b5657e30635ab21..0924097e9701dd137db438926729d641ba5ce01f 100644 --- a/src/entrypoints/Groundstation/Automated/test-automated-radio.cpp +++ b/src/entrypoints/Groundstation/Automated/test-automated-radio.cpp @@ -20,11 +20,11 @@ * THE SOFTWARE. */ -#include <Groundstation/Automated/BoardStatus.h> #include <Groundstation/Automated/Buses.h> #include <Groundstation/Automated/Hub.h> #include <Groundstation/Automated/Radio/Radio.h> #include <Groundstation/Common/Ports/Serial.h> +#include <Groundstation/LyraGS/BoardStatus.h> #include <miosix.h> using namespace Groundstation; diff --git a/src/entrypoints/Groundstation/base-groundstation-entry.cpp b/src/entrypoints/Groundstation/base-groundstation-entry.cpp index 99b7374fcdf25f5f52de7378682f9f132abf8f4e..0546bdc8550d1095574548b51ad9fa48c378d5cd 100644 --- a/src/entrypoints/Groundstation/base-groundstation-entry.cpp +++ b/src/entrypoints/Groundstation/base-groundstation-entry.cpp @@ -20,16 +20,15 @@ * THE SOFTWARE. */ -#include <Groundstation/Base/BoardStatus.h> #include <Groundstation/Base/Buses.h> #include <Groundstation/Base/Hub.h> #include <Groundstation/Base/Ports/Ethernet.h> #include <Groundstation/Base/Radio/Radio.h> #include <Groundstation/Common/Ports/Serial.h> +#include <Groundstation/LyraGS/BoardStatus.h> #include <miosix.h> using namespace Groundstation; -using namespace GroundstationBase; using namespace Boardcore; using namespace miosix; diff --git a/src/entrypoints/Groundstation/lyra-gs-entry.cpp b/src/entrypoints/Groundstation/lyra-gs-entry.cpp index 8c07b784bfc1aff2d8feaf3ac3b92198c012dc22..7eaac70007084cd6484a96b1532157eaa70c0b26 100644 --- a/src/entrypoints/Groundstation/lyra-gs-entry.cpp +++ b/src/entrypoints/Groundstation/lyra-gs-entry.cpp @@ -21,23 +21,19 @@ */ #include <Groundstation/Automated/Actuators/Actuators.h> -#include <Groundstation/Automated/BoardStatus.h> -#include <Groundstation/Automated/Buses.h> #include <Groundstation/Automated/Hub.h> #include <Groundstation/Automated/Leds/Leds.h> -#include <Groundstation/Automated/Ports/Ethernet.h> -#include <Groundstation/Automated/Radio/Radio.h> #include <Groundstation/Automated/SMA/SMA.h> #include <Groundstation/Automated/Sensors/Sensors.h> -#include <Groundstation/Base/BoardStatus.h> -#include <Groundstation/Base/Buses.h> -#include <Groundstation/Base/Hub.h> -#include <Groundstation/Base/Ports/Ethernet.h> -#include <Groundstation/Base/Radio/Radio.h> #include <Groundstation/Common/Ports/Serial.h> -#include <Groundstation/DipReader.h> +#include <Groundstation/LyraGS/Base/Hub.h> +#include <Groundstation/LyraGS/BoardStatus.h> +#include <Groundstation/LyraGS/Buses.h> +#include <Groundstation/LyraGS/Ports/Ethernet.h> +#include <Groundstation/LyraGS/Radio/Radio.h> #include <common/Events.h> #include <diagnostic/PrintLogger.h> +#include <drivers/DipSwitch/DipSwitch.h> #include <events/EventBroker.h> #include <miosix.h> #include <scheduler/TaskScheduler.h> @@ -49,6 +45,7 @@ using namespace Boardcore; using namespace miosix; using namespace Groundstation; +using namespace LyraGS; void idleLoop() { @@ -100,27 +97,35 @@ int main() ledOff(); // Read dip switch configuration - DipStatus dipRead = DipReader::readDip(); + uint32_t microSecClk = 100; + GpioPin sh = dipSwitch::sh::getPin(); + GpioPin clk = dipSwitch::clk::getPin(); + GpioPin qh = dipSwitch::qh::getPin(); + + DipSwitch dip(sh, clk, qh, microSecClk); + DipStatus dipRead = dip.read(); // TODO: Pass to DependencyManager when rebased ModuleManager &modules = ModuleManager::getInstance(); PrintLogger logger = Logging::getLogger("lyra_gs"); + TaskScheduler *scheduler_low = new TaskScheduler(0); + TaskScheduler *scheduler_high = new TaskScheduler(); + Buses *buses = new Buses(); + Serial *serial = new Serial(); + RadioMain *radio_main = new LyraGS::RadioMain(); + BoardStatus *board_status = new BoardStatus(dipRead.isARP); + LyraGS::Ethernet *ethernet = new LyraGS::Ethernet(); + // ARP entry if (dipRead.isARP) { - TaskScheduler *scheduler_low = new TaskScheduler(0); - TaskScheduler *scheduler_high = new TaskScheduler(); - Antennas::Leds *leds = new Antennas::Leds(scheduler_low); - Antennas::Hub *hub = new Antennas::Hub(); - Antennas::Buses *buses = new Antennas::Buses(); - Serial *serial = new Serial(); - Antennas::RadioMain *radio_main = new Antennas::RadioMain(); - Antennas::BoardStatus *board_status = new Antennas::BoardStatus(); - Antennas::Actuators *actuators = new Antennas::Actuators(); - Antennas::Sensors *sensors = new Antennas::Sensors(); - Antennas::SMA *sma = new Antennas::SMA(scheduler_high); - Antennas::Ethernet *ethernet = new Antennas::Ethernet(); + + Antennas::Leds *leds = new Antennas::Leds(scheduler_low); + Antennas::Hub *hub = new Antennas::Hub(); + Antennas::Actuators *actuators = new Antennas::Actuators(); + Antennas::Sensors *sensors = new Antennas::Sensors(); + Antennas::SMA *sma = new Antennas::SMA(scheduler_high); bool ok = true; @@ -212,17 +217,8 @@ int main() // Groundstation entry else { - GroundstationBase::Hub *hub = new GroundstationBase::Hub(); - GroundstationBase::Buses *buses = new GroundstationBase::Buses(); - Serial *serial = new Serial(); - GroundstationBase::Ethernet *ethernet = - new GroundstationBase::Ethernet(); - GroundstationBase::RadioMain *radio_main = - new GroundstationBase::RadioMain(); - GroundstationBase::RadioPayload *radio_payload = - new GroundstationBase::RadioPayload(); - GroundstationBase::BoardStatus *board_status = - new GroundstationBase::BoardStatus(); + GroundstationBase::Hub *hub = new GroundstationBase::Hub(); + RadioPayload *radio_payload = new RadioPayload(); bool ok = true;