mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-05 05:04:46 +00:00

Some checks are pending
CI / setup (check) (push) Waiting to run
CI / setup (esp32) (push) Waiting to run
CI / setup (esp32c3) (push) Waiting to run
CI / setup (esp32c6) (push) Waiting to run
CI / setup (esp32s3) (push) Waiting to run
CI / setup (nrf52840) (push) Waiting to run
CI / setup (rp2040) (push) Waiting to run
CI / setup (stm32) (push) Waiting to run
CI / check (push) Blocked by required conditions
CI / build-esp32 (push) Blocked by required conditions
CI / build-esp32-s3 (push) Blocked by required conditions
CI / build-esp32-c3 (push) Blocked by required conditions
CI / build-esp32-c6 (push) Blocked by required conditions
CI / build-nrf52 (push) Blocked by required conditions
CI / build-rpi2040 (push) Blocked by required conditions
CI / build-stm32 (push) Blocked by required conditions
CI / package-raspbian (push) Waiting to run
CI / package-raspbian-armv7l (push) Waiting to run
CI / package-native (push) Waiting to run
CI / build-debian-src (push) Waiting to run
CI / test-native (push) Waiting to run
CI / docker-debian-amd64 (push) Waiting to run
CI / docker-alpine-amd64 (push) Waiting to run
CI / docker-debian-arm64 (push) Waiting to run
CI / docker-debian-armv7 (push) Waiting to run
CI / after-checks (push) Blocked by required conditions
CI / gather-artifacts (esp32) (push) Blocked by required conditions
CI / gather-artifacts (esp32c3) (push) Blocked by required conditions
CI / gather-artifacts (esp32c6) (push) Blocked by required conditions
CI / gather-artifacts (esp32s3) (push) Blocked by required conditions
CI / gather-artifacts (nrf52840) (push) Blocked by required conditions
CI / gather-artifacts (rp2040) (push) Blocked by required conditions
CI / gather-artifacts (stm32) (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
CI / release-firmware (esp32) (push) Blocked by required conditions
CI / release-firmware (esp32c3) (push) Blocked by required conditions
CI / release-firmware (esp32c6) (push) Blocked by required conditions
CI / release-firmware (esp32s3) (push) Blocked by required conditions
CI / release-firmware (nrf52840) (push) Blocked by required conditions
CI / release-firmware (rp2040) (push) Blocked by required conditions
CI / release-firmware (stm32) (push) Blocked by required conditions
Flawfinder Scan / Flawfinder (push) Waiting to run
* Space out periodic broadcasts of modules automatically * Add warning for function usage --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
65 lines
2.4 KiB
C++
65 lines
2.4 KiB
C++
#pragma once
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
#include "NodeDB.h"
|
|
#include "ProtobufModule.h"
|
|
#include <OLEDDisplay.h>
|
|
#include <OLEDDisplayUi.h>
|
|
|
|
class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Telemetry>
|
|
{
|
|
CallbackObserver<DeviceTelemetryModule, const meshtastic::Status *> nodeStatusObserver =
|
|
CallbackObserver<DeviceTelemetryModule, const meshtastic::Status *>(this, &DeviceTelemetryModule::handleStatusUpdate);
|
|
|
|
public:
|
|
DeviceTelemetryModule()
|
|
: concurrency::OSThread("DeviceTelemetry"),
|
|
ProtobufModule("DeviceTelemetry", meshtastic_PortNum_TELEMETRY_APP, &meshtastic_Telemetry_msg)
|
|
{
|
|
uptimeWrapCount = 0;
|
|
uptimeLastMs = millis();
|
|
nodeStatusObserver.observe(&nodeStatus->onNewStatus);
|
|
setIntervalFromNow(setStartDelay()); // Wait until NodeInfo is sent
|
|
}
|
|
virtual bool wantUIFrame() { return false; }
|
|
|
|
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
|
|
*/
|
|
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override;
|
|
virtual meshtastic_MeshPacket *allocReply() override;
|
|
virtual int32_t runOnce() override;
|
|
/**
|
|
* Send our Telemetry into the mesh
|
|
*/
|
|
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool phoneOnly = false);
|
|
|
|
/**
|
|
* Get the uptime in seconds
|
|
* Loses some accuracy after 49 days, but that's fine
|
|
*/
|
|
uint32_t getUptimeSeconds() { return (0xFFFFFFFF / 1000) * uptimeWrapCount + (uptimeLastMs / 1000); }
|
|
|
|
private:
|
|
meshtastic_Telemetry getDeviceTelemetry();
|
|
meshtastic_Telemetry getLocalStatsTelemetry();
|
|
|
|
void sendLocalStatsToPhone();
|
|
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
|
|
uint32_t sendStatsToPhoneIntervalMs = 15 * SECONDS_IN_MINUTE * 1000; // Send stats to phone every 15 minutes
|
|
uint32_t lastSentStatsToPhone = 0;
|
|
uint32_t lastSentToMesh = 0;
|
|
|
|
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;
|
|
}; |