12#include "BuildOptions.h"
14#include "utilities/LinkedQueue.hpp"
16#include "services/PacketService.h"
18#include "services/RoutingTableService.h"
20#include "services/PacketQueueService.h"
22#include "services/WiFiService.h"
102 void begin(
float freq = LM_BAND,
float bw = LM_BANDWIDTH, uint8_t sf = LM_LORASF, uint8_t cr = LM_CODING_RATE, uint8_t syncWord = LM_SYNC_WORD, int8_t power = LM_POWER, uint16_t preambleLength = LM_PREAMBLE_LENGTH);
136 [[deprecated(
"Use begin(...) instead. Will be deleted permanently in v0.0.6.")]]
137 void init(
void (*receiverFunction)(
void*));
163 void setFrequency(
float freq) { radio->setFrequency(freq); recalculateMaxTimeOnAir(); }
170 void setBandwidth(
float bw) { radio->setBandwidth(bw); recalculateMaxTimeOnAir(); }
184 void setCodingRate(uint8_t cr) { radio->setCodingRate(cr); recalculateMaxTimeOnAir(); }
193 void setOutputPower(int8_t power,
bool useRfo =
false) { radio->setOutputPower(power, useRfo); }
216 template <
typename T>
219 if (payloadSize == 0)
223 size_t payloadSizeInBytes = payloadSize *
sizeof(T);
226 DataPacket* dPacket = PacketService::createDataPacket(dst,
getLocalAddress(), DATA_P,
reinterpret_cast<uint8_t*
>(payload), payloadSizeInBytes);
229 setPackedForSend(
reinterpret_cast<Packet<uint8_t>*
>(dPacket), DEFAULT_PRIORITY);
250 template <
typename T>
252 sendReliablePacket(dst,
reinterpret_cast<uint8_t*
>(payload),
sizeof(T) * payloadSize);
277 ReceivedAppPackets->setInUse();
279 ReceivedAppPackets->releaseInUse();
289 template <
typename T>
388 LM_LinkedList<AppPacket<uint8_t>>* ReceivedAppPackets =
new LM_LinkedList<AppPacket<uint8_t>>();
390 LM_LinkedList<QueuePacket<Packet<uint8_t>>>* ReceivedPackets =
new LM_LinkedList<QueuePacket<Packet<uint8_t>>>();
392 LM_LinkedList<QueuePacket<Packet<uint8_t>>>* ToSendPackets =
new LM_LinkedList<QueuePacket<Packet<uint8_t>>>();
404 Module* genericModule;
410 TaskHandle_t Hello_TaskHandle =
nullptr;
417 TaskHandle_t ReceivePacket_TaskHandle =
nullptr;
424 TaskHandle_t ReceiveData_TaskHandle =
nullptr;
431 TaskHandle_t SendData_TaskHandle =
nullptr;
438 TaskHandle_t ReceiveAppData_TaskHandle =
nullptr;
444 TaskHandle_t PacketManager_TaskHandle =
nullptr;
446 static void onReceive(
void);
448 void receivingRoutine();
450 void initializeLoRa(
float freq,
float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength);
452 void initializeSchedulers();
455 [[deprecated(
"Create task and add it to the LoRaMesher using the function setReceiveAppDataTaskHandle(...). Will be deleted permanently in v0.0.6.")]]
456 void initializeReceivedUserDataTask(
void (*func)(
void*));
458 void sendHelloPacket();
460 void packetManager();
468 uint32_t receivedDataPacketsNum = 0;
469 void incReceivedDataPackets() { receivedDataPacketsNum++; }
471 uint32_t sendPacketsNum = 0;
472 void incSendPackets() { sendPacketsNum++; }
474 uint32_t receivedHelloPacketsNum = 0;
475 void incRecHelloPackets() { receivedHelloPacketsNum++; }
477 uint32_t sentHelloPacketsNum = 0;
478 void incSentHelloPackets() { sentHelloPacketsNum++; }
480 uint32_t receivedBroadcastPacketsNum = 0;
481 void incReceivedBroadcast() { receivedBroadcastPacketsNum++; }
483 uint32_t forwardedPacketsNum = 0;
484 void incForwardedPackets() { forwardedPacketsNum++; }
486 uint32_t dataPacketForMeNum = 0;
487 void incDataPacketForMe() { dataPacketForMeNum++; }
489 uint32_t receivedIAmViaNum = 0;
490 void incReceivedIAmVia() { receivedIAmViaNum++; }
492 uint32_t sendPacketDestinyUnreachableNum = 0;
493 void incDestinyUnreachable() { sendPacketDestinyUnreachableNum++; }
495 uint32_t receivedPacketNotForMeNum = 0;
496 void incReceivedNotForMe() { receivedPacketNotForMeNum++; }
503 void processPackets();
511 template <
typename T>
522 void setPackedForSend(Packet<uint8_t>* p, uint8_t priority) {
523 Log.traceln(F(
"Adding packet to Q_SP"));
524 QueuePacket<Packet<uint8_t>>* send = PacketQueueService::createQueuePacket(p, priority);
525 Log.traceln(F(
"Created packet to Q_SP"));
526 addToSendOrderedAndNotify(send);
535 void addToSendOrderedAndNotify(QueuePacket<Packet<uint8_t>>* qp);
542 void processDataPacket(QueuePacket<DataPacket>* pq);
549 void processDataPacketForMe(QueuePacket<DataPacket>* pq);
565 bool sendPacket(Packet<uint8_t>* p);
580 void sendStartSequencePackets(uint16_t destination, uint8_t seq_id, uint16_t num_packets);
591 QueuePacket<ControlPacket>* getStartSequencePacketQueue(uint16_t destination, uint8_t seq_id, uint16_t num_packets);
600 void sendAckPacket(uint16_t destination, uint8_t seq_id, uint16_t seq_num);
609 void sendLostPacket(uint16_t destination, uint8_t seq_id, uint16_t seq_num);
617 void printHeaderPacket(Packet<uint8_t>* p, String title);
626 bool processLargePayloadPacket(QueuePacket<ControlPacket>* pq);
635 void processSyncPacket(uint16_t source, uint8_t seq_id, uint16_t seq_num);
644 void addAck(uint16_t source, uint8_t seq_id, uint16_t seq_num);
650 uint8_t sequence_id = 0;
657 uint8_t getSequenceId();
663 void managerSendQueue();
669 void managerReceivedQueue();
675 struct sequencePacketConfig {
681 uint8_t firstAckReceived{0};
683 unsigned long timeout{0};;
684 uint8_t numberOfTimeouts{0};
687 sequencePacketConfig(uint8_t seq_id, uint16_t source, uint16_t number) : seq_id(seq_id), source(source), number(number) {};
694 struct listConfiguration {
695 sequencePacketConfig* config;
696 LM_LinkedList<QueuePacket<ControlPacket>>* list;
704 void actualizeRTT(listConfiguration* config);
715 void processLostPacket(uint16_t destination, uint8_t seq_id, uint16_t seq_num);
725 bool sendPacketSequence(listConfiguration* lstConfig, uint16_t seq_num);
732 void joinPacketsAndNotifyUser(listConfiguration* listConfig);
741 void addTimeout(LM_LinkedList<listConfiguration>* queue, uint8_t seq_id, uint16_t source);
748 void resetTimeout(sequencePacketConfig* configPacket);
755 void addTimeout(sequencePacketConfig* configPacket);
762 void clearLinkedList(listConfiguration* listConfig);
770 void findAndClearLinkedList(LM_LinkedList<listConfiguration>* queue, listConfiguration* listConfig);
780 listConfiguration* findSequenceList(LM_LinkedList<listConfiguration>* queue, uint8_t seq_id, uint16_t source);
788 LM_LinkedList<listConfiguration>* q_WSP =
new LM_LinkedList<listConfiguration>();
794 LM_LinkedList<listConfiguration>* q_WRP =
new LM_LinkedList<listConfiguration>();
800 uint32_t maxTimeOnAir = 0;
806 uint8_t preambleReceivedWhenSending = 0;
813 void waitBeforeSend(uint8_t repeatedDetectPreambles);
819 void recalculateMaxTimeOnAir();
Application packet, it is used to send the packet to the application layer.
Definition: AppPacket.h:11
LoRaMesher Library.
Definition: LoraMesher.h:28
uint32_t getForwardedPacketsNum()
Get the Received Broadcast Packets Num.
Definition: LoraMesher.h:349
size_t getSendQueueSize()
Get the Send Queue Size. Packets that are waiting to be send.
Definition: LoraMesher.cpp:709
uint32_t getSendPacketsNum()
Get the Send Packets Num.
Definition: LoraMesher.h:321
void sendReliablePacket(uint16_t dst, uint8_t *payload, uint32_t payloadSize)
Send the payload reliable. It will wait for an ACK back from the destination to send the next packet.
Definition: LoraMesher.cpp:513
uint32_t getReceivedDataPacketsNum()
Get the Received Data Packets Num.
Definition: LoraMesher.h:314
uint16_t getLocalAddress()
Get the Local Address.
Definition: LoraMesher.cpp:287
uint32_t getReceivedIAmViaNum()
Get the Received I Am Via Num.
Definition: LoraMesher.h:363
void setReceiveAppDataTaskHandle(TaskHandle_t ReceiveAppDataTaskHandle)
Set the Receive App Data Task Handle, every time a received packet for this node is detected,...
Definition: LoraMesher.h:200
void setCodingRate(uint8_t cr)
Sets LoRa coding rate denominator. Allowed values range from 5 to 8.
Definition: LoraMesher.h:184
static void deletePacket(AppPacket< T > *p)
Delete the packet from memory.
Definition: LoraMesher.h:290
uint32_t getReceivedNotForMe()
Get the Received Not For Me.
Definition: LoraMesher.h:377
static LoraMesher & getInstance()
Get the Instance of the LoRaMesher.
Definition: LoraMesher.h:36
LM_LinkedList< RouteNode > * routingTableList()
Routing table List.
Definition: LoraMesher.h:206
uint32_t getReceivedHelloPacketsNum()
Get the Received Hello Packets Num.
Definition: LoraMesher.h:328
void setOutputPower(int8_t power, bool useRfo=false)
Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA...
Definition: LoraMesher.h:193
void setFrequency(float freq)
Set the Frequency. Allowed values range from 137.0 MHz to 525.0 MHz.
Definition: LoraMesher.h:163
AppPacket< T > * getNextAppPacket()
Get the Next Application Packet.
Definition: LoraMesher.h:276
uint32_t getDestinyUnreachableNum()
Get the Destiny Unreachable Num.
Definition: LoraMesher.h:370
int routingTableSize()
Returns the routing table size.
Definition: LoraMesher.cpp:692
void begin(float freq=LM_BAND, float bw=LM_BANDWIDTH, uint8_t sf=LM_LORASF, uint8_t cr=LM_CODING_RATE, uint8_t syncWord=LM_SYNC_WORD, int8_t power=LM_POWER, uint16_t preambleLength=LM_PREAMBLE_LENGTH)
LoRaMesh initialization method.
Definition: LoraMesher.cpp:5
void init(void(*receiverFunction)(void *))
Initialize the LoraMesher object.
Definition: LoraMesher.cpp:13
void standby()
Standby LoRaMesher. Including tasks and reception and send packets.
Definition: LoraMesher.cpp:27
uint32_t getReceivedBroadcastPacketsNum()
Get the Received Broadcast Packets Num.
Definition: LoraMesher.h:342
void createPacketAndSend(uint16_t dst, T *payload, uint8_t payloadSize)
Create a Packet And Send it.
Definition: LoraMesher.h:217
~LoraMesher()
Destroy the LoraMesher.
Definition: LoraMesher.cpp:77
uint32_t getDataPacketsForMeNum()
Get the Data Packets For Me Num.
Definition: LoraMesher.h:356
void setSpreadingFactor(uint8_t sf)
Sets LoRa spreading factor. Allowed values range from 6 to 12.
Definition: LoraMesher.h:177
void start()
Start/Resume LoRaMesher. After calling begin(...) or standby() you can Start/resume the LoRaMesher....
Definition: LoraMesher.cpp:52
uint32_t getSentHelloPacketsNum()
Get the Sent Hello Packets Num.
Definition: LoraMesher.h:335
size_t getReceivedQueueSize()
Returns the number of packets inside the received packets queue.
Definition: LoraMesher.cpp:705
void sendReliable(uint16_t dst, T *payload, uint32_t payloadSize)
Send the payload reliable. It will wait for an ack of the destination.
Definition: LoraMesher.h:251
void setBandwidth(float bw)
Sets LoRa bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
Definition: LoraMesher.h:170
static LM_LinkedList< RouteNode > * routingTableList
Routing table List.
Definition: RoutingTableService.h:32