2021-01-14 04:22:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-03-09 08:01:43 +00:00
|
|
|
#include "SinglePortModule.h"
|
2021-01-14 04:22:59 +00:00
|
|
|
#include "concurrency/OSThread.h"
|
|
|
|
#include "configuration.h"
|
|
|
|
#include <Arduino.h>
|
2022-10-05 09:39:50 +00:00
|
|
|
#include "MeshModule.h"
|
|
|
|
#include "Router.h"
|
2021-01-14 04:22:59 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2022-12-22 16:25:15 +00:00
|
|
|
class SerialModule : public StreamAPI, private concurrency::OSThread
|
2021-01-14 04:22:59 +00:00
|
|
|
{
|
|
|
|
bool firstTime = 1;
|
2022-10-16 14:37:38 +00:00
|
|
|
unsigned long lastNmeaTime = millis();
|
|
|
|
char outbuf[90] = "";
|
2021-01-14 04:22:59 +00:00
|
|
|
|
|
|
|
public:
|
2022-02-27 10:21:02 +00:00
|
|
|
SerialModule();
|
2021-01-14 04:22:59 +00:00
|
|
|
|
|
|
|
protected:
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2022-12-22 16:25:15 +00:00
|
|
|
|
|
|
|
/// Check the current underlying physical link to see if the client is currently connected
|
|
|
|
virtual bool checkIsConnected() override;
|
2021-01-14 04:22:59 +00:00
|
|
|
};
|
|
|
|
|
2022-02-27 10:21:02 +00:00
|
|
|
extern SerialModule *serialModule;
|
2021-01-14 04:22:59 +00:00
|
|
|
|
|
|
|
/*
|
2022-02-27 10:21:02 +00:00
|
|
|
* Radio interface for SerialModule
|
2021-01-14 04:22:59 +00:00
|
|
|
*
|
|
|
|
*/
|
2022-10-05 09:39:50 +00:00
|
|
|
class SerialModuleRadio : public MeshModule
|
2021-01-14 04:22:59 +00:00
|
|
|
{
|
2022-01-24 07:00:14 +00:00
|
|
|
uint32_t lastRxID = 0;
|
2022-10-16 14:37:38 +00:00
|
|
|
char outbuf[90] = "";
|
2021-01-14 04:22:59 +00:00
|
|
|
|
|
|
|
public:
|
2022-02-27 10:21:02 +00:00
|
|
|
SerialModuleRadio();
|
2021-01-14 04:22:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send our payload into the mesh
|
|
|
|
*/
|
|
|
|
void sendPayload(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
|
|
|
|
|
|
|
protected:
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual MeshPacket *allocReply() override;
|
2021-01-14 04:22:59 +00:00
|
|
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
2021-09-23 01:42:09 +00:00
|
|
|
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it
|
2021-01-14 04:22:59 +00:00
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual ProcessMessage handleReceived(const MeshPacket &mp) override;
|
2022-10-05 09:39:50 +00:00
|
|
|
|
|
|
|
PortNum ourPortNum;
|
|
|
|
|
|
|
|
virtual bool wantPacket(const MeshPacket *p) override { return p->decoded.portnum == ourPortNum; }
|
|
|
|
|
|
|
|
MeshPacket *allocDataPacket()
|
|
|
|
{
|
|
|
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
|
|
|
MeshPacket *p = router->allocForSending();
|
|
|
|
p->decoded.portnum = ourPortNum;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2021-01-14 04:22:59 +00:00
|
|
|
};
|
|
|
|
|
2022-02-27 10:21:02 +00:00
|
|
|
extern SerialModuleRadio *serialModuleRadio;
|