Add option to monitor battery level

platformio 1.0.6
sh123 2022-12-18 00:01:33 +02:00
rodzic ff2f81d836
commit f74c0e4019
6 zmienionych plików z 58 dodań i 3 usunięć

Wyświetl plik

@ -104,3 +104,8 @@
#define CFG_PTT_PIN 12 // PTT pin
#define CFG_PTT_TX_DELAY_MS 50 // delay between relay switching ON and transmission startup
#define CFG_PTT_TX_TAIL_MS 10 // delay between stopping transmission and relay switching OFF
// Enable modem telemetry
#define CFG_TLM_ENABLE false // enable modem battery monitor
#define CFG_TLM_BAT_MON_PIN 36 // battery ADC pin
#define CFG_TLM_BAT_MON_CAL 0.37f // calibration coefficient

Wyświetl plik

@ -94,6 +94,11 @@ void initializeConfig(LoraPrs::Config &cfg) {
cfg.PttPin = CFG_PTT_PIN;
cfg.PttTxDelayMs = CFG_PTT_TX_DELAY_MS;
cfg.PttTxTailMs = CFG_PTT_TX_TAIL_MS;
// battery level monitor
cfg.TlmEnable = CFG_TLM_ENABLE;
cfg.TlmBatMonPin = CFG_TLM_BAT_MON_PIN;
cfg.TlmBatMonCal = CFG_TLM_BAT_MON_CAL;
}
LoraPrs::Service loraPrsService;

Wyświetl plik

@ -39,6 +39,7 @@ protected:
SetHardware = 0x06,
SignalReport = 0x07,
RebootRequested = 0x08,
Telemetry = 0x09,
NoCmd = 0x80
};
@ -77,7 +78,7 @@ protected:
private:
bool receiveByte(byte rxByte);
bool receiveByteRaw(byte rxByte);
bool receiveByteRaw(byte rxByte);
bool receiveByteKiss(byte rxByte);
void processData(byte rxByte);

Wyświetl plik

@ -75,6 +75,11 @@ struct Config
int PttPin; // esp pin to set high on transmit
int PttTxDelayMs; // ptt tx delay
int PttTxTailMs; // ptt tx tail
// enable modem telemetry
bool TlmEnable; // true - enable modem telemetry event
int TlmBatMonPin; // battery monitor pin
float TlmBatMonCal; // calibration coefficient
};
} // LoraPrs

Wyświetl plik

@ -87,6 +87,12 @@ void Service::setup(const Config &conf)
LOG_INFO("External PTT is enabled");
pinMode(config_.PttPin, OUTPUT);
}
// telemetry event
if (config_.TlmEnable) {
LOG_INFO("Telemetry event is enabled");
telemetryTimer_.every(CfgTelemetryPeriodMs, sendModemTelemetryTimer, this);
}
}
void Service::printConfig() {
@ -301,6 +307,11 @@ void Service::loop()
csmaSlotTimePrev_ = currentTime;
}
}
// timers
if (config_.TlmEnable) {
telemetryTimer_.tick();
}
delay(CfgPollDelayMs);
}
@ -455,6 +466,22 @@ void Service::sendSignalReportEvent(int rssi, float snr)
sendRigToSerial(Cmd::SignalReport, (const byte *)&signalReport, sizeof(SignalReport));
}
bool Service::sendModemTelemetryTimer(void *param)
{
((Service *)param)->sendModemTelemetry();
return true;
}
void Service::sendModemTelemetry()
{
float batVoltage = 2 * analogRead(config_.TlmBatMonPin) * (3.3 / 4096.0) + config_.TlmBatMonCal;
LOG_INFO("Battery voltage", batVoltage);
struct Telemetry telemetry;
telemetry.batteryVoltage = htobe16(100 * batVoltage);
sendRigToSerial(Cmd::Telemetry, (const byte *)&telemetry, sizeof(Telemetry));
}
bool Service::sendAx25PayloadToRig(const AX25::Payload &payload)
{
int bytesWritten;

Wyświetl plik

@ -1,4 +1,4 @@
#ifndef LORAPRS_SEVICE_H
#ifndef LORAPRS_SERVICE_H
#define LORAPRS_SERVICE_H
#include <Arduino.h>
@ -16,6 +16,7 @@
#include <WiFi.h>
#include <endian.h>
#include <arduino-timer.h>
#include "BluetoothSerial.h"
#include "ble_serial.h"
@ -54,6 +55,8 @@ private:
void onAprsisDataAvailable();
void sendSignalReportEvent(int rssi, float snr);
static bool sendModemTelemetryTimer(void *param);
void sendModemTelemetry();
void sendPeriodicBeacon();
void sendToAprsis(const String &aprsMessage);
bool sendAx25PayloadToRig(const AX25::Payload &payload);
@ -110,14 +113,20 @@ private:
int16_t rssi;
int16_t snr;
} __attribute__((packed));
struct Telemetry {
int16_t batteryVoltage;
} __attribute__((packed));
private:
const String CfgLoraprsVersion = "LoRAPRS 1.0.5";
const String CfgLoraprsVersion = "LoRAPRS 1.0.6";
// processor config
const int CfgConnRetryMs = 500; // connection retry delay, e.g. wifi
const int CfgPollDelayMs = 20; // main loop delay
const int CfgConnRetryMaxTimes = 10; // number of connection retries
const int CfgTelemetryPeriodMs = 30000; // how often to send telemetry event
static const int CfgMaxPacketSize = 256; // maximum packet size
static const int CfgRadioQueueSize = 1024; // radio queue size
@ -168,6 +177,9 @@ private:
std::shared_ptr<WiFiServer> kissServer_;
WiFiClient kissConnnection_;
bool isKissClientConnected_;
// modem telemetry
Timer<1> telemetryTimer_;
};
} // LoraPrs