Add new commands and responses for RSSI, channel status, airtime, noise floor, statistics, battery, and sensors.

This commit is contained in:
ViezeVingertjes 2026-01-31 15:05:25 +01:00
parent c786cfe613
commit 1bcb52bab3
4 changed files with 294 additions and 32 deletions

View file

@ -2,6 +2,7 @@
#include <target.h>
#include <helpers/ArduinoHelpers.h>
#include <helpers/IdentityStore.h>
#include <CayenneLPP.h>
#include "KissModem.h"
#if defined(NRF52_PLATFORM)
@ -56,6 +57,42 @@ void onSetSyncWord(uint8_t sync_word) {
radio_set_sync_word(sync_word);
}
float onGetCurrentRssi() {
return radio_driver.getCurrentRSSI();
}
bool onIsChannelBusy() {
return radio_driver.isReceiving();
}
uint32_t onGetAirtime(uint8_t len) {
return radio_driver.getEstAirtimeFor(len);
}
int16_t onGetNoiseFloor() {
return radio_driver.getNoiseFloor();
}
void onGetStats(uint32_t* rx, uint32_t* tx, uint32_t* errors) {
*rx = radio_driver.getPacketsRecv();
*tx = radio_driver.getPacketsSent();
*errors = radio_driver.getPacketsRecvErrors();
}
uint16_t onGetBattery() {
return board.getBattMilliVolts();
}
uint8_t onGetSensors(uint8_t permissions, uint8_t* buffer, uint8_t max_len) {
CayenneLPP telemetry(max_len);
if (sensors.querySensors(permissions, telemetry)) {
uint8_t len = telemetry.getSize();
memcpy(buffer, telemetry.getBuffer(), len);
return len;
}
return 0;
}
void setup() {
board.begin();
@ -73,10 +110,19 @@ void setup() {
while (!Serial && millis() - start < 3000) delay(10);
delay(100);
sensors.begin();
modem = new KissModem(Serial, identity, rng);
modem->setRadioCallback(onSetRadio);
modem->setTxPowerCallback(onSetTxPower);
modem->setSyncWordCallback(onSetSyncWord);
modem->setGetCurrentRssiCallback(onGetCurrentRssi);
modem->setIsChannelBusyCallback(onIsChannelBusy);
modem->setGetAirtimeCallback(onGetAirtime);
modem->setGetNoiseFloorCallback(onGetNoiseFloor);
modem->setGetStatsCallback(onGetStats);
modem->setGetBatteryCallback(onGetBattery);
modem->setGetSensorsCallback(onGetSensors);
modem->begin();
}