2021-01-14 04:22:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-01-21 13:34:29 +00:00
|
|
|
#include "MeshModule.h"
|
|
|
|
#include "Router.h"
|
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>
|
|
|
|
#include <functional>
|
|
|
|
|
2023-02-24 08:53:25 +00:00
|
|
|
#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && \
|
|
|
|
!defined(CONFIG_IDF_TARGET_ESP32C3)
|
2022-12-28 14:31:04 +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-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
|
|
|
*
|
|
|
|
*/
|
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:
|
2023-01-21 17:22:19 +00:00
|
|
|
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
|
|
|
*/
|
2023-01-21 17:22:19 +00:00
|
|
|
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
|
2022-10-05 09:39:50 +00:00
|
|
|
|
2023-01-21 17:22:19 +00:00
|
|
|
meshtastic_PortNum ourPortNum;
|
2022-10-05 09:39:50 +00:00
|
|
|
|
2023-01-21 17:22:19 +00:00
|
|
|
virtual bool wantPacket(const meshtastic_MeshPacket *p) override { return p->decoded.portnum == ourPortNum; }
|
2022-10-05 09:39:50 +00:00
|
|
|
|
2023-01-21 17:22:19 +00:00
|
|
|
meshtastic_MeshPacket *allocDataPacket()
|
2022-10-05 09:39:50 +00:00
|
|
|
{
|
|
|
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
2023-01-21 17:22:19 +00:00
|
|
|
meshtastic_MeshPacket *p = router->allocForSending();
|
2022-10-05 09:39:50 +00:00
|
|
|
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
|