2021-01-17 15:59:48 -05:00
|
|
|
#pragma once
|
2023-01-18 08:56:47 -06:00
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
2022-05-01 14:26:05 -05:00
|
|
|
#include "NodeDB.h"
|
2022-05-07 20:31:21 +10:00
|
|
|
#include "ProtobufModule.h"
|
2021-02-21 16:46:46 -05:00
|
|
|
#include <OLEDDisplay.h>
|
|
|
|
|
#include <OLEDDisplayUi.h>
|
2021-01-17 15:59:48 -05:00
|
|
|
|
2023-01-21 18:22:19 +01:00
|
|
|
class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Telemetry>
|
2021-01-17 15:59:48 -05:00
|
|
|
{
|
|
|
|
|
public:
|
2022-03-27 14:55:35 +00:00
|
|
|
DeviceTelemetryModule()
|
2023-01-21 18:39:58 +01:00
|
|
|
: concurrency::OSThread("DeviceTelemetryModule"),
|
|
|
|
|
ProtobufModule("DeviceTelemetry", meshtastic_PortNum_TELEMETRY_APP, &meshtastic_Telemetry_msg)
|
2021-10-23 21:10:25 +02:00
|
|
|
{
|
2024-04-14 10:27:01 -05:00
|
|
|
uptimeWrapCount = 0;
|
|
|
|
|
uptimeLastMs = millis();
|
2023-02-11 13:56:52 +01:00
|
|
|
setIntervalFromNow(45 * 1000); // Wait until NodeInfo is sent
|
2021-02-22 21:00:41 -05:00
|
|
|
}
|
2022-03-27 14:55:35 +00:00
|
|
|
virtual bool wantUIFrame() { return false; }
|
2021-01-17 15:59:48 -05:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
|
|
|
|
*/
|
2023-01-21 18:22:19 +01:00
|
|
|
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override;
|
2023-08-01 16:18:10 -05:00
|
|
|
virtual meshtastic_MeshPacket *allocReply() override;
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2021-03-02 21:12:22 -05:00
|
|
|
/**
|
2022-02-26 20:52:22 -08:00
|
|
|
* Send our Telemetry into the mesh
|
2021-03-02 21:12:22 -05:00
|
|
|
*/
|
2022-10-11 10:21:30 -05:00
|
|
|
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool phoneOnly = false);
|
2021-10-23 21:10:25 +02:00
|
|
|
|
2024-04-14 10:27:01 -05:00
|
|
|
/**
|
|
|
|
|
* Get the uptime in seconds
|
|
|
|
|
* Loses some accuracy after 49 days, but that's fine
|
|
|
|
|
*/
|
|
|
|
|
uint32_t getUptimeSeconds() { return (0xFFFFFFFF / 1000) * uptimeWrapCount + (uptimeLastMs / 1000); }
|
|
|
|
|
|
2021-02-21 16:46:46 -05:00
|
|
|
private:
|
2023-08-01 16:18:10 -05:00
|
|
|
meshtastic_Telemetry getDeviceTelemetry();
|
2022-10-11 10:21:30 -05:00
|
|
|
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
|
|
|
|
|
uint32_t lastSentToMesh = 0;
|
2024-04-14 10:27:01 -05:00
|
|
|
|
|
|
|
|
void refreshUptime()
|
|
|
|
|
{
|
|
|
|
|
auto now = millis();
|
|
|
|
|
// If we wrapped around (~49 days), increment the wrap count
|
|
|
|
|
if (now < uptimeLastMs)
|
|
|
|
|
uptimeWrapCount++;
|
|
|
|
|
|
|
|
|
|
uptimeLastMs = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t uptimeWrapCount;
|
|
|
|
|
uint32_t uptimeLastMs;
|
2022-01-24 07:00:14 +00:00
|
|
|
};
|