firmware/src/modules/SerialModule.h

65 lines
1.4 KiB
C
Raw Normal View History

2021-01-14 04:22:59 +00:00
#pragma once
#include "SinglePortModule.h"
2021-01-14 04:22:59 +00:00
#include "concurrency/OSThread.h"
#include "configuration.h"
#include <Arduino.h>
#include "MeshModule.h"
#include "Router.h"
2021-01-14 04:22:59 +00:00
#include <functional>
2022-02-27 10:21:02 +00:00
class SerialModule : private concurrency::OSThread
2021-01-14 04:22:59 +00:00
{
bool firstTime = 1;
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;
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
*
*/
class SerialModuleRadio : public MeshModule
2021-01-14 04:22:59 +00:00
{
2022-01-24 07:00:14 +00:00
uint32_t lastRxID = 0;
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
@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;
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;