Skip to content
Snippets Groups Projects
Commit 5fdd48c6 authored by Nicolò Caruso's avatar Nicolò Caruso Committed by Emilio Corigliano
Browse files

[GS] Using now serial on USART4

Now using USART4 for serial.
New class even if might not be good, will change to inherit from SerialTransciver.
parent 89a41124
Branches
Tags
1 merge request!48[GS, ARP] New entrypoint for lyra_gs and ARP related things
......@@ -122,4 +122,5 @@ set (LYRA_GS
src/boards/Groundstation/Automated/Actuators/Actuators.cpp
src/boards/Groundstation/Automated/Sensors/Sensors.cpp
src/boards/Groundstation/Automated/PinHandler/PinHandler.cpp
src/boards/Groundstation/LyraGS/Ports/SerialLyraGS.cpp
)
\ No newline at end of file
......@@ -25,9 +25,9 @@
#include <Groundstation/Automated/Actuators/Actuators.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/Ports/SerialLyraGS.h>
#include <Groundstation/LyraGS/Radio/Radio.h>
#include <algorithms/NAS/NASState.h>
#include <common/Events.h>
......@@ -240,7 +240,7 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg)
void Hub::dispatchIncomingMsg(const mavlink_message_t& msg)
{
Groundstation::Serial* serial = getModule<Groundstation::Serial>();
LyraGS::SerialLyraGS* serial = getModule<LyraGS::SerialLyraGS>();
#if !defined(NO_MAVLINK_ON_SERIAL)
serial->sendMsg(msg);
#else
......
......@@ -24,9 +24,9 @@
#include <Groundstation/Automated/SMA/SMA.h>
#include <Groundstation/Common/HubBase.h>
#include <Groundstation/Common/Ports/Serial.h>
#include <Groundstation/LyraGS/BoardStatus.h>
#include <Groundstation/LyraGS/Ports/Ethernet.h>
#include <Groundstation/LyraGS/Ports/SerialLyraGS.h>
#include <Groundstation/LyraGS/Radio/Radio.h>
#include <algorithms/NAS/NASState.h>
#include <common/Mavlink.h>
......@@ -47,7 +47,7 @@ namespace Antennas
*/
class Hub : public Boardcore::InjectableWithDeps<
Boardcore::InjectableBase<Groundstation::HubBase>, SMA,
LyraGS::RadioMain, Groundstation::Serial, LyraGS::EthernetGS>
LyraGS::RadioMain, LyraGS::SerialLyraGS, LyraGS::EthernetGS>
{
public:
/**
......
......@@ -23,9 +23,9 @@
#include "Hub.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/Ports/SerialLyraGS.h>
using namespace Groundstation;
using namespace GroundstationBase;
......@@ -63,7 +63,7 @@ void Hub::dispatchIncomingMsg(const mavlink_message_t& msg)
{
LyraGS::BoardStatus* status = getModule<LyraGS::BoardStatus>();
Serial* serial = getModule<Serial>();
SerialLyraGS* serial = getModule<SerialLyraGS>();
serial->sendMsg(msg);
if (status->isEthernetPresent())
......
......@@ -23,8 +23,8 @@
#pragma once
#include <Groundstation/Common/HubBase.h>
#include <Groundstation/Common/Ports/Serial.h>
#include <Groundstation/LyraGS/Ports/Ethernet.h>
#include <Groundstation/LyraGS/Ports/SerialLyraGS.h>
#include <common/Mavlink.h>
#include <utils/DependencyManager/DependencyManager.h>
......@@ -36,7 +36,7 @@ namespace GroundstationBase
class Hub : public Boardcore::InjectableWithDeps<
Boardcore::InjectableBase<Groundstation::HubBase>,
LyraGS::BoardStatus, LyraGS::RadioMain, LyraGS::RadioPayload,
Groundstation::Serial, LyraGS::EthernetGS>
LyraGS::SerialLyraGS, LyraGS::EthernetGS>
{
public:
/**
......
......@@ -30,7 +30,6 @@
namespace LyraGS
{
class Buses : public Boardcore::Injectable
{
public:
......
/* 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 "SerialLyraGS.h"
using namespace Groundstation;
using namespace LyraGS;
bool SerialLyraGS::start()
{
auto mav_handler = [this](SerialMavDriver* channel,
const mavlink_message_t& msg) { handleMsg(msg); };
mav_driver = std::make_unique<SerialMavDriver>(this, mav_handler, 0, 10);
if (!mav_driver->start())
{
return false;
}
return true;
}
void SerialLyraGS::sendMsg(const mavlink_message_t& msg)
{
if (mav_driver && mav_driver->isStarted())
{
mav_driver->enqueueMsg(msg);
}
}
void SerialLyraGS::handleMsg(const mavlink_message_t& msg)
{
// Dispatch the message through the hub.
getModule<HubBase>()->dispatchOutgoingMsg(msg);
}
ssize_t SerialLyraGS::receive(uint8_t* pkt, size_t max_len)
{
Boardcore::USART& serial = getModule<Buses>()->uart4;
size_t bytesRead = 0;
bool result = serial.readBlocking(pkt, max_len, bytesRead);
return result ? bytesRead : 0;
}
bool SerialLyraGS::send(uint8_t* pkt, size_t len)
{
Boardcore::USART& serial = getModule<Buses>()->uart4;
serial.write(pkt, len);
return true;
}
\ 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 <ActiveObject.h>
#include <Groundstation/Common/Ports/EthernetBase.h>
#include <Groundstation/Common/Ports/Serial.h>
#include <Groundstation/LyraGS/BoardStatus.h>
#include <Groundstation/LyraGS/Buses.h>
#include <common/Mavlink.h>
#include <drivers/usart/USART.h>
#include <filesystem/console/console_device.h>
#include <radio/MavlinkDriver/MavlinkDriver.h>
#include <utils/DependencyManager/DependencyManager.h>
#include <memory>
namespace LyraGS
{
using SerialMavDriver =
Boardcore::MavlinkDriver<1024, 10, MAVLINK_MAX_DIALECT_PAYLOAD_SIZE>;
/**
* @brief Class responsible for UART communication.
*/
class SerialLyraGS : public Boardcore::InjectableWithDeps<
Boardcore::InjectableBase<Groundstation::Serial>,
Buses, Groundstation::HubBase>
{
public:
SerialLyraGS() {}
/**
* @brief Initialize the serial module.
*/
[[nodiscard]] bool start();
/**
* @brief Send a mavlink message through this port.
*/
void sendMsg(const mavlink_message_t& msg);
private:
/**
* @brief Called internally when a message is received.
*/
void handleMsg(const mavlink_message_t& msg);
ssize_t receive(uint8_t* pkt, size_t max_len) override;
bool send(uint8_t* pkt, size_t len) override;
miosix::FastMutex mutex;
std::unique_ptr<SerialMavDriver> mav_driver;
};
} // namespace LyraGS
\ No newline at end of file
......@@ -26,11 +26,11 @@
#include <Groundstation/Automated/PinHandler/PinHandler.h>
#include <Groundstation/Automated/SMA/SMA.h>
#include <Groundstation/Automated/Sensors/Sensors.h>
#include <Groundstation/Common/Ports/Serial.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/Ports/SerialLyraGS.h>
#include <Groundstation/LyraGS/Radio/Radio.h>
#include <common/Events.h>
#include <diagnostic/PrintLogger.h>
......@@ -138,7 +138,7 @@ int main()
TaskScheduler *scheduler_low = new TaskScheduler(0);
TaskScheduler *scheduler_high = new TaskScheduler();
Buses *buses = new Buses();
Serial *serial = new Serial();
SerialLyraGS *serial = new SerialLyraGS();
LyraGS::RadioMain *radio_main =
new LyraGS::RadioMain(dipRead.mainHasBackup, dipRead.mainTXenable);
LyraGS::BoardStatus *board_status = new LyraGS::BoardStatus(dipRead.isARP);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment