Refactor KissModem to integrate radio and sensor management directly, removing callback dependencies.

This commit is contained in:
ViezeVingertjes 2026-01-31 15:08:25 +01:00
parent 1bcb52bab3
commit 240b5ea1e3
3 changed files with 20 additions and 88 deletions

View file

@ -2,7 +2,6 @@
#include <target.h>
#include <helpers/ArduinoHelpers.h>
#include <helpers/IdentityStore.h>
#include <CayenneLPP.h>
#include "KissModem.h"
#if defined(NRF52_PLATFORM)
@ -61,38 +60,12 @@ 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();
@ -112,17 +85,12 @@ void setup() {
sensors.begin();
modem = new KissModem(Serial, identity, rng);
modem = new KissModem(Serial, identity, rng, radio_driver, board, sensors);
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();
}