Files
firmware/src/plugins/esp32/StoreForwardPlugin.h

84 lines
2.2 KiB
C
Raw Normal View History

#pragma once
#include "SinglePortPlugin.h"
#include "concurrency/OSThread.h"
2021-11-28 19:34:35 -08:00
#include "mesh/generated/storeforward.pb.h"
#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
{
// bool firstTime = 1;
bool busy = 0;
uint32_t busyTo;
char routerMessage[80];
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
PacketHistoryStruct *packetHistoryTXQueue;
uint32_t packetHistoryTXQueue_size;
uint32_t packetHistoryTXQueue_index = 0;
2021-11-21 14:43:47 -08:00
2021-12-06 21:01:18 -08:00
uint32_t packetTimeMax = 2000;
2021-11-21 14:43:47 -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
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
// S&F Defaults
uint32_t historyReturnMax = 250; // 250 records
uint32_t historyReturnWindow = 240; // 4 hours
uint32_t records = 0; // Calculated
bool heartbeat = false; // No heartbeat.
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
*/
virtual ProcessMessage handleReceived(const MeshPacket &mp);
2021-12-02 17:27:38 -08:00
virtual ProcessMessage handleReceivedProtobuf(const MeshPacket &mp, StoreAndForward *p);
};
2021-11-20 21:35:13 -08:00
extern StoreForwardPlugin *storeForwardPlugin;