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

[Nokia] Changed to dependency manager

Now modules are managed by dependency manager instead of module manager
parent fde09464
Branches
No related tags found
No related merge requests found
...@@ -23,15 +23,14 @@ ...@@ -23,15 +23,14 @@
#pragma once #pragma once
#include <drivers/spi/SPIBus.h> #include <drivers/spi/SPIBus.h>
#include <utils/DependencyManager/DependencyManager.h>
#include <utils/ModuleManager/ModuleManager.hpp>
#include "interfaces-impl/hwmapping.h" #include "interfaces-impl/hwmapping.h"
namespace GroundstationNokia namespace GroundstationNokia
{ {
class Buses : public Boardcore::Module class Buses : public Boardcore::Injectable
{ {
public: public:
Boardcore::SPIBus radio_bus; Boardcore::SPIBus radio_bus;
......
...@@ -32,7 +32,7 @@ using namespace Boardcore; ...@@ -32,7 +32,7 @@ using namespace Boardcore;
void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg)
{ {
Radio* radio = ModuleManager::getInstance().get<Radio>(); Radio* radio = getModule<Radio>();
if (!radio->sendMsg(msg)) if (!radio->sendMsg(msg))
{ {
...@@ -42,6 +42,6 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) ...@@ -42,6 +42,6 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg)
void Hub::dispatchIncomingMsg(const mavlink_message_t& msg) void Hub::dispatchIncomingMsg(const mavlink_message_t& msg)
{ {
Serial* serial = ModuleManager::getInstance().get<Serial>(); Serial* serial = getModule<Serial>();
serial->sendMsg(msg); serial->sendMsg(msg);
} }
\ No newline at end of file
...@@ -23,9 +23,10 @@ ...@@ -23,9 +23,10 @@
#pragma once #pragma once
#include <Groundstation/Common/HubBase.h> #include <Groundstation/Common/HubBase.h>
#include <Groundstation/Common/Ports/Serial.h>
#include <Groundstation/Nokia/Radio/Radio.h>
#include <common/Mavlink.h> #include <common/Mavlink.h>
#include <utils/DependencyManager/DependencyManager.h>
#include <utils/ModuleManager/ModuleManager.hpp>
namespace GroundstationNokia namespace GroundstationNokia
{ {
...@@ -33,7 +34,9 @@ namespace GroundstationNokia ...@@ -33,7 +34,9 @@ namespace GroundstationNokia
/** /**
* @brief Central hub connecting all outgoing and ingoing modules. * @brief Central hub connecting all outgoing and ingoing modules.
*/ */
class Hub : public Groundstation::HubBase class Hub : public Boardcore::InjectableWithDeps<
Boardcore::InjectableBase<Groundstation::HubBase>, Radio,
Groundstation::Serial>
{ {
public: public:
Hub() {} Hub() {}
......
...@@ -37,19 +37,24 @@ using namespace miosix; ...@@ -37,19 +37,24 @@ using namespace miosix;
#define SX1278_DIO1_IRQ EXTI4_IRQHandlerImpl #define SX1278_DIO1_IRQ EXTI4_IRQHandlerImpl
#define SX1278_DIO3_IRQ EXTI11_IRQHandlerImpl #define SX1278_DIO3_IRQ EXTI11_IRQHandlerImpl
Radio* radioGlobal = nullptr;
void __attribute__((used)) SX1278_DIO0_IRQ() void __attribute__((used)) SX1278_DIO0_IRQ()
{ {
ModuleManager::getInstance().get<Radio>()->handleDioIRQ(); if (radioGlobal)
radioGlobal->handleDioIRQ();
} }
void __attribute__((used)) SX1278_DIO1_IRQ() void __attribute__((used)) SX1278_DIO1_IRQ()
{ {
ModuleManager::getInstance().get<Radio>()->handleDioIRQ(); if (radioGlobal)
radioGlobal->handleDioIRQ();
} }
void __attribute__((used)) SX1278_DIO3_IRQ() void __attribute__((used)) SX1278_DIO3_IRQ()
{ {
ModuleManager::getInstance().get<Radio>()->handleDioIRQ(); if (radioGlobal)
radioGlobal->handleDioIRQ();
} }
bool Radio::start() bool Radio::start()
...@@ -63,9 +68,7 @@ bool Radio::start() ...@@ -63,9 +68,7 @@ bool Radio::start()
std::unique_ptr<Boardcore::SX1278Fsk> sx1278 = std::unique_ptr<Boardcore::SX1278Fsk> sx1278 =
std::make_unique<Boardcore::SX1278Fsk>( std::make_unique<Boardcore::SX1278Fsk>(
ModuleManager::getInstance() getModule<GroundstationNokia::Buses>()->radio_bus,
.get<GroundstationNokia::Buses>()
->radio_bus,
peripherals::ra01::pc13::cs::getPin(), peripherals::ra01::pc13::cs::getPin(),
peripherals::ra01::pc13::dio0::getPin(), peripherals::ra01::pc13::dio0::getPin(),
peripherals::ra01::pc13::dio1::getPin(), peripherals::ra01::pc13::dio1::getPin(),
......
...@@ -23,11 +23,14 @@ ...@@ -23,11 +23,14 @@
#pragma once #pragma once
#include <Groundstation/Common/Radio/RadioBase.h> #include <Groundstation/Common/Radio/RadioBase.h>
#include <Groundstation/Nokia/Buses.h>
namespace GroundstationNokia namespace GroundstationNokia
{ {
class Radio : public Groundstation::RadioBase, public Boardcore::Module class Radio : public Boardcore::InjectableWithDeps<
Boardcore::InjectableBase<Groundstation::RadioBase>,
GroundstationNokia::Buses>
{ {
public: public:
[[nodiscard]] bool start(); [[nodiscard]] bool start();
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <Groundstation/Nokia/Hub.h> #include <Groundstation/Nokia/Hub.h>
#include <Groundstation/Nokia/Radio/Radio.h> #include <Groundstation/Nokia/Radio/Radio.h>
#include <miosix.h> #include <miosix.h>
#include <utils/DependencyManager/DependencyManager.h>
using namespace Groundstation; using namespace Groundstation;
using namespace GroundstationNokia; using namespace GroundstationNokia;
...@@ -48,14 +49,14 @@ int main() ...@@ -48,14 +49,14 @@ int main()
Radio *radio = new Radio(); Radio *radio = new Radio();
Serial *serial = new Serial(); Serial *serial = new Serial();
ModuleManager &modules = ModuleManager::getInstance(); DependencyManager manager;
bool ok = true; bool ok = true;
ok &= modules.insert<HubBase>(hub); ok &= manager.insert<HubBase>(hub);
ok &= modules.insert(buses); ok &= manager.insert(buses);
ok &= modules.insert(serial); ok &= manager.insert(serial);
ok &= modules.insert(radio); ok &= manager.insert(radio);
// If insertion failed, stop right here // If insertion failed, stop right here
if (!ok) if (!ok)
...@@ -64,6 +65,12 @@ int main() ...@@ -64,6 +65,12 @@ int main()
idleLoop(); idleLoop();
} }
if (!manager.inject())
{
printf("[error] Failed to inject the dependencies!\n");
idleLoop();
}
// Ok now start them // Ok now start them
ok &= serial->start(); ok &= serial->start();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment