add TaskQueue and many other stuff :)

This commit is contained in:
Peter Buchegger 2021-01-04 23:10:23 +01:00
parent d29982a0c9
commit 33e766a5ac
26 changed files with 131 additions and 186 deletions

View file

@ -66,15 +66,10 @@ bool APRS_IS::sendMessage(const std::shared_ptr<APRSMessage> message)
{
return false;
}
_client.println(message->encode());
_client.println(message->encode() + "\n");
return true;
}
void APRS_IS::action(std::shared_ptr<APRSMessage> elem, int rssi, float snr)
{
sendMessage(elem);
}
int APRS_IS::available()
{
return _client.available();
@ -108,6 +103,5 @@ std::shared_ptr<APRSMessage> APRS_IS::getAPRSMessage()
}
std::shared_ptr<APRSMessage> msg = std::shared_ptr<APRSMessage>(new APRSMessage());
msg->decode(line);
emit(msg);
return msg;
}

View file

@ -2,11 +2,10 @@
#ifndef APRS_IS_Lib_h_
#define APRS_IS_Lib_h_
#include <SignalSlot.h>
#include <WiFi.h>
#include <APRS-Decoder.h>
class APRS_IS : public Signal1<const std::shared_ptr<APRSMessage>>, public Slot3<std::shared_ptr<APRSMessage>, int, float>
class APRS_IS
{
public:
APRS_IS(const String & user, const String & passcode, const String & tool_name, const String & version);
@ -18,7 +17,6 @@ public:
bool sendMessage(const String & message);
bool sendMessage(const std::shared_ptr<APRSMessage> message);
void action(std::shared_ptr<APRSMessage> msg, int rssi, float snr) override;
int available();

View file

@ -34,7 +34,6 @@ bool LoRa_APRS::checkMessage()
}
_LastReceivedMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
_LastReceivedMsg->decode(str);
emit(_LastReceivedMsg, packetRssi(), packetSnr());
return true;
}
@ -80,8 +79,3 @@ long LoRa_APRS::getTxFrequency() const
{
return _TxFrequency;
}
void LoRa_APRS::action(const std::shared_ptr<APRSMessage> elem)
{
sendMessage(elem);
}

View file

@ -5,7 +5,6 @@
#include <Arduino.h>
#include <LoRa.h>
#include <APRS-Decoder.h>
#include <SignalSlot.h>
#define LORA_RX_FREQUENCY (433775000)
#define LORA_TX_FREQUENCY (433900000)
@ -13,7 +12,7 @@
#define LORA_SIGNAL_BANDWIDTH (125E3)
#define LORA_CODING_RATE4 (5)
class LoRa_APRS : public LoRaClass, public Slot1<const std::shared_ptr<APRSMessage>>, public Signal3<std::shared_ptr<APRSMessage>, int, float>
class LoRa_APRS : public LoRaClass
{
public:
explicit LoRa_APRS(std::shared_ptr<BoardConfig> boardConfig);
@ -29,8 +28,6 @@ public:
void setTxFrequency(long frequency);
long getTxFrequency() const;
void action(const std::shared_ptr<APRSMessage> elem) override;
private:
std::shared_ptr<APRSMessage> _LastReceivedMsg;
long _RxFrequency;

View file

@ -1,116 +0,0 @@
#ifndef SIGNAL_SLOT_H_
#define SIGNAL_SLOT_H_
#include <list>
class Slot0
{
public:
virtual void action() = 0;
};
template <typename T>
class Slot1
{
public:
virtual void action(T elem1) = 0;
};
template <typename T, typename H>
class Slot2
{
public:
virtual void action(T elem1, H elem2) = 0;
};
template <typename T, typename H, typename K>
class Slot3
{
public:
virtual void action(T elem1, H elem2, K elem3) = 0;
};
class Signal0
{
public:
void emit()
{
for(Slot0 * slot: _slots)
{
slot->action();
}
}
void connectSlot(Slot0 * slot)
{
_slots.push_back(slot);
}
private:
std::list<Slot0 *> _slots;
};
template <typename T>
class Signal1
{
public:
void emit(T elem1)
{
for(Slot1<T> * slot: _slots)
{
slot->action(elem1);
}
}
void connectSlot(Slot1<T> * slot)
{
_slots.push_back(slot);
}
private:
std::list<Slot1<T> *> _slots;
};
template <typename T, typename H>
class Signal2
{
public:
void emit(T elem1, H elem2)
{
for(Slot2<T, H> * slot: _slots)
{
slot->action(elem1, elem2);
}
}
void connectSlot(Slot2<T, H> * slot)
{
_slots.push_back(slot);
}
private:
std::list<Slot2<T, H> *> _slots;
};
template <typename T, typename H, typename K>
class Signal3
{
public:
void emit(T elem1, H elem2, K elem3)
{
for(Slot3<T, H, K> * slot: _slots)
{
slot->action(elem1, elem2, elem3);
}
}
void connectSlot(Slot3<T, H, K> * slot)
{
_slots.push_back(slot);
}
private:
std::list<Slot3<T, H, K> *> _slots;
};
#endif

View file

@ -10,7 +10,7 @@ void TaskManager::addTask(std::shared_ptr<Task> task)
_tasks.push_back(task);
}
std::shared_ptr<Task> TaskManager::getTask(String & name)
std::shared_ptr<Task> TaskManager::getTask(const char * name)
{
for(std::shared_ptr<Task> & elem : _tasks)
{
@ -22,14 +22,14 @@ std::shared_ptr<Task> TaskManager::getTask(String & name)
return 0;
}
bool TaskManager::setup(std::shared_ptr<Configuration> config)
bool TaskManager::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
{
logPrintlnV("will setup all tasks...");
for(std::shared_ptr<Task> & elem : _tasks)
{
logPrintW("call setup from ");
logPrintlnW(elem->getName());
if(!elem->setup(config))
if(!elem->setup(config, boardConfig))
{
return false;
}

View file

@ -5,6 +5,9 @@
#include <memory>
#include <Arduino.h>
#include <configuration.h>
#include <BoardFinder.h>
#include "TaskQueue.h"
class Task
{
@ -15,7 +18,7 @@ public:
String getName() const { return _name; }
virtual bool setup(std::shared_ptr<Configuration> config) = 0;
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) = 0;
virtual bool loop(std::shared_ptr<Configuration> config) = 0;
private:
@ -25,17 +28,27 @@ private:
class TaskManager
{
public:
TaskManager();
static TaskManager & instance()
{
static TaskManager _instance;
return _instance;
}
~TaskManager() {}
void addTask(std::shared_ptr<Task> task);
std::shared_ptr<Task> getTask(String & name);
std::shared_ptr<Task> getTask(const char * name);
bool setup(std::shared_ptr<Configuration> config);
bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig);
bool loop(std::shared_ptr<Configuration> config);
private:
std::list<std::shared_ptr<Task>> _tasks;
TaskManager();
TaskManager(const TaskManager &);
TaskManager & operator = (const TaskManager &);
};
#endif

View file

@ -0,0 +1,33 @@
#ifndef TASK_QUEUE_H_
#define TASK_QUEUE_H_
#include <list>
template <typename T>
class TaskQueue
{
public:
TaskQueue() {}
void addElement(T elem)
{
_elements.push_back(elem);
}
T getElement()
{
T elem = _elements.front();
_elements.pop_front();
return elem;
}
bool empty() const
{
return _elements.empty();
}
private:
std::list<T> _elements;
};
#endif