Skip to content
Snippets Groups Projects
Commit 62c4fce6 authored by Davide Mor's avatar Davide Mor Committed by Emilio Corigliano
Browse files

[gs] Added Hub

parent 238d95e2
Branches
No related tags found
1 merge request!48[GS, ARP] New entrypoint for lyra_gs and ARP related things
...@@ -122,4 +122,5 @@ set(GS_COMPUTER ...@@ -122,4 +122,5 @@ set(GS_COMPUTER
src/boards/Gs/Ports/Serial.cpp src/boards/Gs/Ports/Serial.cpp
src/boards/Gs/Radio/Radio.cpp src/boards/Gs/Radio/Radio.cpp
src/boards/Gs/Radio/RadioStatus.cpp src/boards/Gs/Radio/RadioStatus.cpp
src/boards/Gs/Hub.cpp
) )
\ No newline at end of file
/* 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 "Hub.h"
#include <Gs/Radio/Radio.h>
#include <Gs/Radio/RadioStatus.h>
#include <Gs/Ports/Serial.h>
using namespace Gs;
using namespace Boardcore;
void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) {
RadioStatus *status = ModuleManager::getInstance().get<RadioStatus>();
// TODO: Dispatch to correct radio using mavlink ids
if (status->isMainRadioPresent())
{
RadioMain *radio = ModuleManager::getInstance().get<RadioMain>();
radio->sendMsg(msg);
}
if (status->isPayloadRadioPresent())
{
RadioPayload *radio = ModuleManager::getInstance().get<RadioPayload>();
radio->sendMsg(msg);
}
}
void Hub::dispatchIncomingMsg(const mavlink_message_t& msg) {
Serial* serial = ModuleManager::getInstance().get<Serial>();
serial->sendMsg(msg);
// TODO: Add UDP dispatch
}
\ No newline at end of file
/* 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 <utils/ModuleManager/ModuleManager.hpp>
#include <common/Mavlink.h>
namespace Gs {
/**
* @brief Central hub connecting all outgoing and ingoing modules.
*/
class Hub : public Boardcore::Module {
public:
Hub() {}
/**
* @brief Dispatch to the correct interface and outgoing packet (gs -> rocket).
*/
void dispatchOutgoingMsg(const mavlink_message_t& msg);
/**
* @brief Dispatch to the correct interface and incoming packet (rocket -> gs).
*/
void dispatchIncomingMsg(const mavlink_message_t& msg);
};
}
\ No newline at end of file
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "Serial.h" #include "Serial.h"
#include <Gs/Hub.h>
#include <Gs/Radio/Radio.h> #include <Gs/Radio/Radio.h>
#include <Gs/Radio/RadioStatus.h> #include <Gs/Radio/RadioStatus.h>
...@@ -47,24 +48,6 @@ void Serial::sendMsg(const mavlink_message_t &msg) ...@@ -47,24 +48,6 @@ void Serial::sendMsg(const mavlink_message_t &msg)
serial->writeBlock(msg_buf, msg_len, 0); serial->writeBlock(msg_buf, msg_len, 0);
} }
void Serial::handleMsg(const mavlink_message_t &msg)
{
// TODO:
RadioStatus *status = ModuleManager::getInstance().get<RadioStatus>();
if (status->isMainRadioPresent())
{
RadioMain *radio = ModuleManager::getInstance().get<RadioMain>();
radio->sendMsg(msg);
}
if (status->isPayloadRadioPresent())
{
RadioPayload *radio = ModuleManager::getInstance().get<RadioPayload>();
radio->sendMsg(msg);
}
}
void Serial::run() void Serial::run()
{ {
mavlink_message_t msg; mavlink_message_t msg;
...@@ -83,7 +66,9 @@ void Serial::run() ...@@ -83,7 +66,9 @@ void Serial::run()
if (parse_result == 1) if (parse_result == 1)
{ {
handleMsg(msg); // Dispatch the message through the hub.
ModuleManager::getInstance().get<Hub>()->dispatchOutgoingMsg(
msg);
} }
} }
} }
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
namespace Gs namespace Gs
{ {
/**
* @brief Class responsible for UART communication.
*/
class Serial : public Boardcore::Module, private Boardcore::ActiveObject class Serial : public Boardcore::Module, private Boardcore::ActiveObject
{ {
public: public:
...@@ -51,11 +54,6 @@ protected: ...@@ -51,11 +54,6 @@ protected:
void run() override; void run() override;
private: private:
/**
* @brief Called internally when a message is received.
*/
void handleMsg(const mavlink_message_t& msg);
miosix::FastMutex mutex; miosix::FastMutex mutex;
}; };
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <Gs/Ports/Serial.h> #include <Gs/Ports/Serial.h>
#include <Gs/Radio/RadioStatus.h> #include <Gs/Radio/RadioStatus.h>
#include <radio/SX1278/SX1278Frontends.h> #include <radio/SX1278/SX1278Frontends.h>
#include <Gs/Hub.h>
using namespace miosix; using namespace miosix;
using namespace Gs; using namespace Gs;
...@@ -173,10 +174,8 @@ bool RadioPayload::start() ...@@ -173,10 +174,8 @@ bool RadioPayload::start()
void RadioBase::handleMsg(const mavlink_message_t& msg) void RadioBase::handleMsg(const mavlink_message_t& msg)
{ {
// TODO: // Dispatch the message through the hub.
ModuleManager::getInstance().get<Hub>()->dispatchIncomingMsg(msg);
Serial* serial = ModuleManager::getInstance().get<Serial>();
serial->sendMsg(msg);
if (isEndOfTransmissionPacket(msg)) if (isEndOfTransmissionPacket(msg))
{ {
......
...@@ -27,12 +27,22 @@ ...@@ -27,12 +27,22 @@
namespace Gs namespace Gs
{ {
/**
* @brief Class responsible for keeping track of radio status and metrics.
*/
class RadioStatus : public Boardcore::Module class RadioStatus : public Boardcore::Module
{ {
public: public:
RadioStatus() {} RadioStatus() {}
/**
* @brief Check wether the main radio was found during boot.
*/
bool isMainRadioPresent(); bool isMainRadioPresent();
/**
* @brief Check wether the payload radio was found during boot.
*/
bool isPayloadRadioPresent(); bool isPayloadRadioPresent();
void setMainRadioPresent(bool present); void setMainRadioPresent(bool present);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment