2026-01-31 14:55:51 -06:00
|
|
|
#pragma once
|
|
|
|
|
#if !MESHTASTIC_EXCLUDE_STATUS
|
|
|
|
|
#include "SinglePortModule.h"
|
|
|
|
|
#include "configuration.h"
|
2026-02-01 17:27:59 -06:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2026-01-31 14:55:51 -06:00
|
|
|
|
|
|
|
|
class StatusMessageModule : public SinglePortModule, private concurrency::OSThread
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/** Constructor
|
|
|
|
|
* name is for debugging output
|
|
|
|
|
*/
|
|
|
|
|
StatusMessageModule()
|
|
|
|
|
: SinglePortModule("statusMessage", meshtastic_PortNum_NODE_STATUS_APP), concurrency::OSThread("StatusMessage")
|
|
|
|
|
{
|
|
|
|
|
if (moduleConfig.has_statusmessage && moduleConfig.statusmessage.node_status[0] != '\0') {
|
|
|
|
|
this->setInterval(2 * 60 * 1000);
|
|
|
|
|
} else {
|
|
|
|
|
this->setInterval(1000 * 12 * 60 * 60);
|
|
|
|
|
}
|
|
|
|
|
// TODO: If we have a string, set the initial delay (15 minutes maybe)
|
2026-02-01 17:27:59 -06:00
|
|
|
|
2026-02-02 12:00:42 -06:00
|
|
|
// Keep vector from reallocating as we fill up to MAX_RECENT_STATUSMESSAGES
|
|
|
|
|
recentReceived.reserve(MAX_RECENT_STATUSMESSAGES);
|
2026-01-31 14:55:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual int32_t runOnce() override;
|
|
|
|
|
|
2026-02-01 17:27:59 -06:00
|
|
|
struct RecentStatus {
|
|
|
|
|
uint32_t fromNodeId; // mp.from
|
|
|
|
|
std::string statusText; // incomingMessage.status
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const std::vector<RecentStatus> &getRecentReceived() const { return recentReceived; }
|
|
|
|
|
|
2026-01-31 14:55:51 -06:00
|
|
|
protected:
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
*/
|
|
|
|
|
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
|
|
|
|
|
|
|
|
|
|
private:
|
2026-02-03 07:43:45 -06:00
|
|
|
static constexpr size_t MAX_RECENT_STATUSMESSAGES = 5;
|
2026-02-01 17:27:59 -06:00
|
|
|
std::vector<RecentStatus> recentReceived;
|
2026-01-31 14:55:51 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern StatusMessageModule *statusMessageModule;
|
|
|
|
|
#endif
|