From b29bcbbd4170416d937f0e299235b5c250063e4f Mon Sep 17 00:00:00 2001 From: Jm Date: Tue, 9 Feb 2021 21:59:00 -0800 Subject: [PATCH] #682 Exposing the actual radio center frequency to /static/report --- src/mesh/RadioInterface.cpp | 41 ++++++++++++++++++++++++++++---- src/mesh/RadioInterface.h | 23 ++++++++++++++++++ src/mesh/http/ContentHandler.cpp | 11 ++++++++- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index b1aa807b..01f3f791 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -209,6 +209,38 @@ unsigned long hash(const char *str) return hash; } +/** + * Save our frequency for later reuse. + */ +void RadioInterface::saveFreq(float freq) +{ + savedFreq = freq; +} + +/** + * Save our channel for later reuse. + */ +void RadioInterface::saveChannelNum(uint32_t channel_num) +{ + savedChannelNum = channel_num; +} + +/** + * Save our frequency for later reuse. + */ +float RadioInterface::getFreq() +{ + return savedFreq; +} + +/** + * Save our channel for later reuse. + */ +uint32_t RadioInterface::getChannelNum() +{ + return savedChannelNum; +} + /** * Pull our channel settings etc... from protobufs to the dumb interface settings */ @@ -261,18 +293,19 @@ void RadioInterface::applyModemConfig() assert(myRegion); // Should have been found in init // If user has manually specified a channel num, then use that, otherwise generate one by hashing the name - int channel_num = - (channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelName)) % myRegion->numChannels; + int channel_num = (channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelName)) % myRegion->numChannels; freq = myRegion->freq + myRegion->spacing * channel_num; - DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, channelSettings.modem_config, channel_num, - power); + DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, channelSettings.modem_config, channel_num, power); DEBUG_MSG("Radio myRegion->freq: %f\n", myRegion->freq); DEBUG_MSG("Radio myRegion->spacing: %f\n", myRegion->spacing); DEBUG_MSG("Radio myRegion->numChannels: %d\n", myRegion->numChannels); DEBUG_MSG("Radio channel_num: %d\n", channel_num); DEBUG_MSG("Radio frequency: %f\n", freq); DEBUG_MSG("Short packet time: %u msec\n", shortPacketMsec); + + saveChannelNum(channel_num); + saveFreq(freq); } /** diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 0d8c7b9b..1f4fb845 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -133,9 +133,22 @@ class RadioInterface uint32_t getPacketTime(MeshPacket *p); uint32_t getPacketTime(uint32_t totalPacketLen); + /** + * Get the channel we saved. + */ + uint32_t getChannelNum(); + + /** + * Get the frequency we saved. + */ + float getFreq(); + protected: int8_t power = 17; // Set by applyModemConfig() + float savedFreq; + uint32_t savedChannelNum; + /*** * given a packet set sendingPacket and decode the protobufs into radiobuf. Returns # of bytes to send (including the * PacketHeader & payload). @@ -157,6 +170,16 @@ class RadioInterface */ virtual void applyModemConfig(); + /** + * Save the frequency we selected for later reuse. + */ + virtual void saveFreq(float savedFreq); + + /** + * Save the chanel we selected for later reuse. + */ + virtual void saveChannelNum(uint32_t savedChannelNum); + private: /// Return 0 if sleep is okay int preflightSleepCb(void *unused = NULL) { return canSleep() ? 0 : 1; } diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 5f79702f..8535dd34 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -11,6 +11,7 @@ #include #include #include +#include "RadioLibInterface.h" #ifndef NO_ESP32 #include "esp_task_wdt.h" @@ -928,10 +929,18 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) res->printf("\"has_battery\": %s,\n", BoolToString(powerStatus->getHasBattery())); res->printf("\"has_usb\": %s,\n", BoolToString(powerStatus->getHasUSB())); res->printf("\"is_charging\": %s\n", BoolToString(powerStatus->getIsCharging())); - res->println("}"); + res->println("},"); + + res->println("\"radio\": {"); + res->printf("\"frequecy\": %f,\n", RadioLibInterface::instance->getFreq()); + res->printf("\"lora_channel\": %d\n", RadioLibInterface::instance->getChannelNum()); + res->println("},"); + res->println("},"); + + res->println("\"status\": \"ok\""); res->println("}"); }