2021-01-31 09:12:01 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "SinglePortPlugin.h"
|
|
|
|
|
#include "concurrency/OSThread.h"
|
2021-11-28 19:34:35 -08:00
|
|
|
#include "mesh/generated/storeforward.pb.h"
|
|
|
|
|
|
2021-01-31 09:12:01 -08:00
|
|
|
#include "configuration.h"
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
2021-02-21 20:15:31 -08:00
|
|
|
struct PacketHistoryStruct {
|
|
|
|
|
uint32_t time;
|
|
|
|
|
uint32_t to;
|
2021-11-20 21:21:11 -08:00
|
|
|
uint32_t from;
|
2021-02-24 20:27:21 -08:00
|
|
|
bool ack;
|
2021-11-20 21:21:11 -08:00
|
|
|
uint8_t payload[Constants_DATA_PAYLOAD_LEN];
|
|
|
|
|
pb_size_t payload_size;
|
2021-02-21 20:15:31 -08:00
|
|
|
};
|
|
|
|
|
|
2021-03-17 21:03:11 -07:00
|
|
|
class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThread
|
2021-01-31 09:12:01 -08:00
|
|
|
{
|
2021-11-22 17:47:42 -08:00
|
|
|
//bool firstTime = 1;
|
|
|
|
|
bool busy = 0;
|
|
|
|
|
uint32_t busyTo;
|
|
|
|
|
char routerMessage[80];
|
2021-01-31 09:12:01 -08:00
|
|
|
|
2021-02-16 17:42:46 -08:00
|
|
|
uint32_t receivedRecord[50][2] = {{0}};
|
|
|
|
|
|
2021-02-22 20:07:19 -08:00
|
|
|
PacketHistoryStruct *packetHistory;
|
2021-02-24 20:27:21 -08:00
|
|
|
uint32_t packetHistoryCurrent = 0;
|
2021-02-22 20:07:19 -08:00
|
|
|
|
2021-11-22 17:47:42 -08:00
|
|
|
PacketHistoryStruct *packetHistoryTXQueue;
|
|
|
|
|
uint32_t packetHistoryTXQueue_size;
|
|
|
|
|
uint32_t packetHistoryTXQueue_index = 0;
|
|
|
|
|
|
2021-11-21 14:43:47 -08:00
|
|
|
uint32_t packetTimeMax = 0;
|
|
|
|
|
|
|
|
|
|
|
2021-01-31 09:12:01 -08:00
|
|
|
public:
|
|
|
|
|
StoreForwardPlugin();
|
|
|
|
|
|
2021-02-16 17:42:46 -08:00
|
|
|
/**
|
|
|
|
|
Update our local reference of when we last saw that node.
|
|
|
|
|
@return 0 if we have never seen that node before otherwise return the last time we saw the node.
|
|
|
|
|
*/
|
2021-11-20 21:21:11 -08:00
|
|
|
void historyAdd(const MeshPacket &mp);
|
2021-02-24 20:27:21 -08:00
|
|
|
void historyReport();
|
|
|
|
|
void historySend(uint32_t msAgo, uint32_t to);
|
2021-02-16 17:42:46 -08:00
|
|
|
|
2021-11-22 17:47:42 -08:00
|
|
|
uint32_t historyQueueCreate(uint32_t msAgo, uint32_t to);
|
|
|
|
|
|
2021-03-17 21:03:11 -07:00
|
|
|
/**
|
|
|
|
|
* Send our payload into the mesh
|
|
|
|
|
*/
|
2021-11-20 21:21:11 -08:00
|
|
|
void sendPayload(NodeNum dest = NODENUM_BROADCAST, uint32_t packetHistory_index = 0);
|
2021-11-21 14:43:47 -08:00
|
|
|
void sendMessage(NodeNum dest, char *str);
|
2021-03-17 21:03:11 -07:00
|
|
|
virtual MeshPacket *allocReply();
|
2021-11-28 19:34:35 -08:00
|
|
|
/*
|
|
|
|
|
Override the wantPortnum method.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool wantPortnum(PortNum p) { return true; };
|
2021-03-17 21:03:11 -07:00
|
|
|
|
2021-02-16 17:42:46 -08:00
|
|
|
private:
|
2021-11-21 14:43:47 -08:00
|
|
|
void populatePSRAM();
|
2021-02-16 17:42:46 -08:00
|
|
|
|
2021-01-31 09:12:01 -08:00
|
|
|
protected:
|
|
|
|
|
virtual int32_t runOnce();
|
2021-03-17 21:03:11 -07:00
|
|
|
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
|
2021-11-18 09:36:39 -08:00
|
|
|
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for
|
|
|
|
|
it
|
2021-03-17 21:03:11 -07:00
|
|
|
*/
|
2021-09-23 04:42:09 +03:00
|
|
|
virtual ProcessMessage handleReceived(const MeshPacket &mp);
|
2021-01-31 09:12:01 -08:00
|
|
|
};
|
|
|
|
|
|
2021-11-20 21:35:13 -08:00
|
|
|
extern StoreForwardPlugin *storeForwardPlugin;
|