diff --git a/CMakeLists.txt b/CMakeLists.txt index 11fdaf4b538c347f7de3a53718aafa5905fe31f0..85cd5f85a20dacfb33a6afa3b65eb42aa645eabf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,13 @@ add_executable(con_rig-entry src/entrypoints/ConRIG/con_rig-entry.cpp ${CON_RIG_ target_include_directories(con_rig-entry PRIVATE ${OBSW_INCLUDE_DIRS}) sbs_target(con_rig-entry stm32f429zi_con_rig) +add_executable(rovie-groundstation-entry + src/entrypoints/Groundstation/rovie-groundstation-entry.cpp + ${GROUNDSTATION_COMMON} ${GROUNDSTATION_ROVIE} +) +target_include_directories(rovie-groundstation-entry PRIVATE ${OBSW_INCLUDE_DIRS}) +sbs_target(rovie-groundstation-entry stm32f767zi_gemini_gs) + add_executable(nokia-groundstation-entry src/entrypoints/Groundstation/nokia-groundstation-entry.cpp ${GROUNDSTATION_COMMON} ${GROUNDSTATION_NOKIA} diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 31cc37817df31c90a24f2c721dcb7b5bb5b0c186..b6666423498661d6c05fcea04ef8beb15d52a8a4 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -106,6 +106,12 @@ set(PAYLOAD_COMPUTER src/boards/Payload/Wing/WingAlgorithm.cpp ) +set(GROUNDSTATION_ROVIE + src/boards/Groundstation/Rovie/Radio/Radio.cpp + src/boards/Groundstation/Rovie/Ports/Ethernet.cpp + src/boards/Groundstation/Rovie/Hub.cpp +) + set(GROUNDSTATION_NOKIA src/boards/Groundstation/Nokia/Radio/Radio.cpp src/boards/Groundstation/Nokia/Hub.cpp diff --git a/src/boards/Groundstation/Rovie/Buses.h b/src/boards/Groundstation/Rovie/Buses.h new file mode 100644 index 0000000000000000000000000000000000000000..34b13057ff99ffe2c0dfdd6cde1cd2e446e1d2e3 --- /dev/null +++ b/src/boards/Groundstation/Rovie/Buses.h @@ -0,0 +1,45 @@ +/* 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 <drivers/spi/SPIBus.h> + +#include <utils/ModuleManager/ModuleManager.hpp> + +#include "interfaces-impl/hwmapping.h" + +namespace GroundstationRovie +{ + +class Buses : public Boardcore::Module +{ +public: + Boardcore::SPIBus radio1_bus; + Boardcore::SPIBus ethernet_bus; + + Buses() : radio1_bus(MIOSIX_RADIO1_SPI), ethernet_bus(MIOSIX_ETHERNET_SPI) + { + } +}; + +} // namespace GroundstationRovie \ No newline at end of file diff --git a/src/boards/Groundstation/Rovie/Hub.cpp b/src/boards/Groundstation/Rovie/Hub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..50fa886a2f63ea81cdeb84df3f4f43bd22ed369d --- /dev/null +++ b/src/boards/Groundstation/Rovie/Hub.cpp @@ -0,0 +1,46 @@ +/* Copyright (c) 2024 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 "Hub.h" + +#include <Groundstation/Common/Config/GeneralConfig.h> +#include <Groundstation/Common/Ports/Serial.h> +#include <Groundstation/Rovie/Ports/Ethernet.h> +#include <Groundstation/Rovie/Radio/Radio.h> + +using namespace Groundstation; +using namespace GroundstationRovie; +using namespace Boardcore; + +void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) +{ + // Do nothing, do not allow for transmisison +} + +void Hub::dispatchIncomingMsg(const mavlink_message_t& msg) +{ + Serial* serial = ModuleManager::getInstance().get<Serial>(); + serial->sendMsg(msg); + + Ethernet* ethernet = ModuleManager::getInstance().get<Ethernet>(); + ethernet->sendMsg(msg); +} \ No newline at end of file diff --git a/src/boards/Groundstation/Rovie/Hub.h b/src/boards/Groundstation/Rovie/Hub.h new file mode 100644 index 0000000000000000000000000000000000000000..18b7531326a9469c9cb7b37d2b8995ab93879e3f --- /dev/null +++ b/src/boards/Groundstation/Rovie/Hub.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2024 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/HubBase.h> +#include <common/Mavlink.h> + +#include <utils/ModuleManager/ModuleManager.hpp> + +namespace GroundstationRovie +{ + +/** + * @brief Central hub connecting all outgoing and ingoing modules. + */ +class Hub : public Groundstation::HubBase +{ +public: + Hub() {} + + /** + * @brief Dispatch to the correct interface and outgoing packet (gs -> + * rocket). + */ + void dispatchOutgoingMsg(const mavlink_message_t& msg) override; + + /** + * @brief Dispatch to the correct interface and incoming packet (rocket -> + * gs). + */ + void dispatchIncomingMsg(const mavlink_message_t& msg) override; +}; + +} // namespace GroundstationRovie \ No newline at end of file diff --git a/src/boards/Groundstation/Rovie/Ports/Ethernet.cpp b/src/boards/Groundstation/Rovie/Ports/Ethernet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b242322bf5f41510caea0c0fc7c3438067bd547d --- /dev/null +++ b/src/boards/Groundstation/Rovie/Ports/Ethernet.cpp @@ -0,0 +1,51 @@ +/* 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/Rovie/Buses.h> +#include <interfaces-impl/hwmapping.h> + +using namespace Groundstation; +using namespace GroundstationRovie; +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); + + if (!EthernetBase::start(std::move(wiz5500))) + { + return false; + } + + return true; +} \ No newline at end of file diff --git a/src/boards/Groundstation/Rovie/Ports/Ethernet.h b/src/boards/Groundstation/Rovie/Ports/Ethernet.h new file mode 100644 index 0000000000000000000000000000000000000000..1aa1acdb919d529cf8f3562348338bf9828994ef --- /dev/null +++ b/src/boards/Groundstation/Rovie/Ports/Ethernet.h @@ -0,0 +1,38 @@ +/* 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 GroundstationRovie +{ + +class Ethernet : public Groundstation::EthernetBase, public Boardcore::Module +{ +public: + [[nodiscard]] bool start(); +}; + +} // namespace GroundstationRovie \ No newline at end of file diff --git a/src/boards/Groundstation/Rovie/Radio/Radio.cpp b/src/boards/Groundstation/Rovie/Radio/Radio.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd129e6bd73ccd3f369085c1708c8e43cf052d26 --- /dev/null +++ b/src/boards/Groundstation/Rovie/Radio/Radio.cpp @@ -0,0 +1,100 @@ +/* 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/Common/Ports/Serial.h> +#include <Groundstation/Rovie/Buses.h> +#include <Groundstation/Rovie/Hub.h> +#include <radio/SX1278/SX1278Frontends.h> + +using namespace Groundstation; +using namespace GroundstationRovie; +using namespace Boardcore; +using namespace miosix; + +void __attribute__((used)) MIOSIX_RADIO1_DIO0_IRQ() +{ + ModuleManager::getInstance().get<RadioRig>()->handleDioIRQ(); +} + +void __attribute__((used)) MIOSIX_RADIO1_DIO1_IRQ() +{ + ModuleManager::getInstance().get<RadioRig>()->handleDioIRQ(); +} + +void __attribute__((used)) MIOSIX_RADIO1_DIO3_IRQ() +{ + ModuleManager::getInstance().get<RadioRig>()->handleDioIRQ(); +} + +void RadioRig::handleDioIRQ() +{ + if (started) + { + sx1278->handleDioIRQ(); + } +} + +bool RadioRig::start() +{ +#ifdef SKYWARD_GS_MAIN_USE_BACKUP_RF + std::unique_ptr<SX1278::ISX1278Frontend> frontend = + std::make_unique<EbyteFrontend>(radio1::txen::getPin(), + radio1::rxen::getPin()); +#else + std::unique_ptr<SX1278::ISX1278Frontend> frontend = + std::make_unique<Skyward433Frontend>(); +#endif + + sx1278 = std::make_unique<SX1278Lora>( + ModuleManager::getInstance().get<Buses>()->radio1_bus, + radio1::cs::getPin(), radio1::dio0::getPin(), radio1::dio1::getPin(), + radio1::dio3::getPin(), SPI::ClockDivider::DIV_64, std::move(frontend)); + + // Configure the radio + if (sx1278->configure(Common::RIG_RADIO_CONFIG) != SX1278Lora::Error::NONE) + { + return false; + } + + auto mav_handler = [this](RadioMavDriver* channel, + const mavlink_message_t& msg) { handleMsg(msg); }; + + mav_driver = std::make_unique<RadioMavDriver>( + sx1278.get(), mav_handler, Groundstation::MAV_SLEEP_AFTER_SEND, + Groundstation::MAV_OUT_BUFFER_MAX_AGE); + + if (!mav_driver->start()) + { + return false; + } + + started = true; + return true; +} + +void RadioRig::handleMsg(const mavlink_message_t& msg) +{ + // Dispatch the message through the hub. + ModuleManager::getInstance().get<HubBase>()->dispatchIncomingMsg(msg); +} \ No newline at end of file diff --git a/src/boards/Groundstation/Rovie/Radio/Radio.h b/src/boards/Groundstation/Rovie/Radio/Radio.h new file mode 100644 index 0000000000000000000000000000000000000000..2e497210756c134a9d5a0a86852001258ce2259e --- /dev/null +++ b/src/boards/Groundstation/Rovie/Radio/Radio.h @@ -0,0 +1,63 @@ +/* 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> + +#include <atomic> + +namespace GroundstationRovie +{ + +using RadioMavDriver = + Boardcore::MavlinkDriver<Boardcore::SX1278Lora::MTU, + Groundstation::MAV_OUT_QUEUE_SIZE, + MAVLINK_MAX_DIALECT_PAYLOAD_SIZE>; + +class RadioRig : public Boardcore::Module +{ +public: + RadioRig() {} + + [[nodiscard]] bool start(); + + /** + * @brief Handle generic DIO irq. + */ + void handleDioIRQ(); + +private: + /** + * @brief Called internally when a message is received. + */ + void handleMsg(const mavlink_message_t& msg); + + std::atomic<bool> started{false}; + + // Objects are always destructed in reverse order, so keep them in this + // order + std::unique_ptr<Boardcore::SX1278Lora> sx1278; + std::unique_ptr<RadioMavDriver> mav_driver; +}; + +} // namespace GroundstationRovie \ No newline at end of file diff --git a/src/entrypoints/Groundstation/rovie-groundstation-entry.cpp b/src/entrypoints/Groundstation/rovie-groundstation-entry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a55d62d71681ea40e378e621131557d1991bddab --- /dev/null +++ b/src/entrypoints/Groundstation/rovie-groundstation-entry.cpp @@ -0,0 +1,110 @@ +/* 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 <Groundstation/Common/Ports/Serial.h> +#include <Groundstation/Rovie/Buses.h> +#include <Groundstation/Rovie/Hub.h> +#include <Groundstation/Rovie/Ports/Ethernet.h> +#include <Groundstation/Rovie/Radio/Radio.h> +#include <miosix.h> + +using namespace Groundstation; +using namespace GroundstationRovie; +using namespace Boardcore; +using namespace miosix; + +void idleLoop() +{ + while (1) + { + Thread::wait(); + } +} + +void errorLoop() +{ + while (1) + { + led1On(); + Thread::sleep(100); + led1Off(); + Thread::sleep(100); + } +} + +int main() +{ + ledOff(); + + Hub *hub = new Hub(); + Buses *buses = new Buses(); + Serial *serial = new Serial(); + Ethernet *ethernet = new Ethernet(); + RadioRig *radio_rig = new RadioRig(); + + ModuleManager &modules = ModuleManager::getInstance(); + + bool ok = true; + + ok &= modules.insert<HubBase>(hub); + ok &= modules.insert(buses); + ok &= modules.insert(serial); + ok &= modules.insert(ethernet); + ok &= modules.insert(radio_rig); + + // If insertion failed, stop right here + if (!ok) + { + printf("[error] Failed to insert all modules!\n"); + errorLoop(); + } + + // Ok now start them + + ok &= serial->start(); + if (!ok) + { + printf("[error] Failed to start serial!\n"); + } + + ok &= ethernet->start(); + if (!ok) + { + printf("[error] Failed to start ethernet!\n"); + } + + ok &= radio_rig->start(); + if (!ok) + { + printf("[error] Failed to start RIG radio!\n"); + } + + if (!ok) + { + errorLoop(); + } + + printf("All good!\n"); + led1On(); + idleLoop(); + return 0; +} \ No newline at end of file