2021-01-31 17:12:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-12-06 15:56:38 +00:00
|
|
|
#include "ProtobufModule.h"
|
2021-01-31 17:12:01 +00:00
|
|
|
#include "concurrency/OSThread.h"
|
2021-11-29 03:34:35 +00:00
|
|
|
#include "mesh/generated/storeforward.pb.h"
|
|
|
|
|
2021-01-31 17:12:01 +00:00
|
|
|
#include "configuration.h"
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <functional>
|
|
|
|
|
2021-02-22 04:15:31 +00:00
|
|
|
struct PacketHistoryStruct {
|
|
|
|
uint32_t time;
|
|
|
|
uint32_t to;
|
2021-11-21 05:21:11 +00:00
|
|
|
uint32_t from;
|
2021-12-22 00:28:47 +00:00
|
|
|
uint8_t channel;
|
2021-02-25 04:27:21 +00:00
|
|
|
bool ack;
|
2021-11-21 05:21:11 +00:00
|
|
|
uint8_t payload[Constants_DATA_PAYLOAD_LEN];
|
|
|
|
pb_size_t payload_size;
|
2021-02-22 04:15:31 +00:00
|
|
|
};
|
|
|
|
|
2022-12-06 15:56:38 +00:00
|
|
|
class StoreForwardModule : private concurrency::OSThread, public ProtobufModule<StoreAndForward>
|
2021-01-31 17:12:01 +00:00
|
|
|
{
|
2021-11-23 01:47:42 +00:00
|
|
|
bool busy = 0;
|
2022-01-24 19:58:07 +00:00
|
|
|
uint32_t busyTo = 0;
|
|
|
|
char routerMessage[Constants_DATA_PAYLOAD_LEN] = {0};
|
2021-01-31 17:12:01 +00:00
|
|
|
|
2021-02-17 01:42:46 +00:00
|
|
|
uint32_t receivedRecord[50][2] = {{0}};
|
|
|
|
|
2022-01-24 19:58:07 +00:00
|
|
|
PacketHistoryStruct *packetHistory = 0;
|
2021-02-25 04:27:21 +00:00
|
|
|
uint32_t packetHistoryCurrent = 0;
|
2021-02-23 04:07:19 +00:00
|
|
|
|
2022-01-24 19:58:07 +00:00
|
|
|
PacketHistoryStruct *packetHistoryTXQueue = 0;
|
|
|
|
uint32_t packetHistoryTXQueue_size = 0;
|
2021-11-23 01:47:42 +00:00
|
|
|
uint32_t packetHistoryTXQueue_index = 0;
|
2021-11-21 22:43:47 +00:00
|
|
|
|
2022-12-06 15:56:38 +00:00
|
|
|
uint32_t packetTimeMax = 5000;
|
|
|
|
|
|
|
|
unsigned long lastHeartbeat = 0;
|
|
|
|
|
|
|
|
bool is_client = false;
|
|
|
|
bool is_server = false;
|
2021-11-21 22:43:47 +00:00
|
|
|
|
2021-01-31 17:12:01 +00:00
|
|
|
public:
|
2022-02-27 10:21:02 +00:00
|
|
|
StoreForwardModule();
|
2021-01-31 17:12:01 +00:00
|
|
|
|
2021-02-17 01:42:46 +00: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-21 05:21:11 +00:00
|
|
|
void historyAdd(const MeshPacket &mp);
|
2021-02-25 04:27:21 +00:00
|
|
|
void historyReport();
|
|
|
|
void historySend(uint32_t msAgo, uint32_t to);
|
2021-02-17 01:42:46 +00:00
|
|
|
|
2021-11-23 01:47:42 +00:00
|
|
|
uint32_t historyQueueCreate(uint32_t msAgo, uint32_t to);
|
|
|
|
|
2021-03-18 04:03:11 +00:00
|
|
|
/**
|
|
|
|
* Send our payload into the mesh
|
|
|
|
*/
|
2021-11-21 05:21:11 +00:00
|
|
|
void sendPayload(NodeNum dest = NODENUM_BROADCAST, uint32_t packetHistory_index = 0);
|
2021-11-21 22:43:47 +00:00
|
|
|
void sendMessage(NodeNum dest, char *str);
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual MeshPacket *allocReply() override;
|
2021-11-29 03:34:35 +00:00
|
|
|
/*
|
|
|
|
Override the wantPortnum method.
|
|
|
|
*/
|
2021-11-29 03:41:34 +00:00
|
|
|
virtual bool wantPortnum(PortNum p) { return true; };
|
2021-03-18 04:03:11 +00:00
|
|
|
|
2021-02-17 01:42:46 +00:00
|
|
|
private:
|
2021-11-21 22:43:47 +00:00
|
|
|
void populatePSRAM();
|
2021-02-17 01:42:46 +00:00
|
|
|
|
2021-12-04 06:20:15 +00: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.
|
|
|
|
|
2021-01-31 17:12:01 +00:00
|
|
|
protected:
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2021-03-18 04:03:11 +00:00
|
|
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
2021-11-18 17:36:39 +00:00
|
|
|
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for
|
|
|
|
it
|
2021-03-18 04:03:11 +00:00
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual ProcessMessage handleReceived(const MeshPacket &mp) override;
|
2022-12-06 15:56:38 +00:00
|
|
|
virtual bool handleReceivedProtobuf(const MeshPacket &mp, StoreAndForward *p);
|
2021-12-03 01:27:38 +00:00
|
|
|
|
2021-01-31 17:12:01 +00:00
|
|
|
};
|
|
|
|
|
2022-02-27 10:21:02 +00:00
|
|
|
extern StoreForwardModule *storeForwardModule;
|