firmware/src/modules/SerialModule.h

75 lines
1.9 KiB
C
Raw Normal View History

2021-01-14 04:22:59 +00:00
#pragma once
2023-01-21 13:34:29 +00:00
#include "MeshModule.h"
#include "Router.h"
#include "SinglePortModule.h"
2021-01-14 04:22:59 +00:00
#include "concurrency/OSThread.h"
#include "configuration.h"
#include <Arduino.h>
#include <functional>
2022-12-28 14:31:04 +00:00
#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2)
class SerialModule : public StreamAPI, private concurrency::OSThread
2021-01-14 04:22:59 +00:00
{
bool firstTime = 1;
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-28 14:31:04 +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
*
*/
class SerialModuleRadio : public MeshModule
2021-01-14 04:22:59 +00:00
{
2022-01-24 07:00:14 +00:00
uint32_t lastRxID = 0;
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:
virtual meshtastic_MeshPacket *allocReply() override;
2021-01-14 04:22:59 +00:00
/** Called to handle a particular incoming message
2023-01-21 13:34:29 +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
*/
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
meshtastic_PortNum ourPortNum;
virtual bool wantPacket(const meshtastic_MeshPacket *p) override { return p->decoded.portnum == ourPortNum; }
meshtastic_MeshPacket *allocDataPacket()
{
// Update our local node info with our position (even if we don't decide to update anyone else)
meshtastic_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;
2022-12-28 14:31:04 +00:00
#endif