Refactor RF Configuration Management (#2245)
- Introduced RFConfiguration class to encapsulate RF settings and operations. - Replaced direct usage of RFConfig structure with iRFConfig instance across multiple files. - Updated frequency handling in actuatorSomfy, gatewayPilight, gatewayRF, and gatewayRF2 to use iRFConfig. - Modified webUI to interact with iRFConfig for RF settings management. - Removed deprecated RFConfig structure and related functions. - Enhanced JSON handling for RF configuration loading and saving. - Improved logging for RF configuration operations.
This commit is contained in:
1 parent
401be5f10c
commit
c6b2aae965
12 files changed
+553
-206
No files matched your search
+22
-28
@@ -976,14 +976,13 @@ void handleBL() {
|
||||
bool update = false;
|
||||
|
||||
if (server.hasArg("save")) {
|
||||
|
||||
// Default BLE AES Key
|
||||
if (server.hasArg("bk")) {
|
||||
WEBtoSYS["ble_aes"] = server.arg("bk");
|
||||
update = true;
|
||||
}
|
||||
|
||||
// Split Custom BLE AES key pair string add to config
|
||||
// Split Custom BLE AES key pair string add to config
|
||||
if (server.hasArg("kp")) {
|
||||
String kp = server.arg("kp");
|
||||
while (kp.length() > 0) {
|
||||
@@ -997,7 +996,7 @@ void handleBL() {
|
||||
if (kp.indexOf(':') == 12) {
|
||||
WEBtoSYS["ble_aes_keys"][kp.substring(0, 12)] = kp.substring(13, 45);
|
||||
}
|
||||
kp = kp.substring(kpindex+1);
|
||||
kp = kp.substring(kpindex + 1);
|
||||
}
|
||||
}
|
||||
update = true;
|
||||
@@ -1013,7 +1012,7 @@ void handleBL() {
|
||||
}
|
||||
}
|
||||
|
||||
// Build BLE Key Pair string
|
||||
// Build BLE Key Pair string
|
||||
std::string aeskeysstring;
|
||||
JsonObject root = ble_aes_keys.as<JsonObject>();
|
||||
for (JsonPair kv : root) {
|
||||
@@ -1204,6 +1203,8 @@ void handleLA() {
|
||||
}
|
||||
# elif defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
|
||||
# include <map>
|
||||
|
||||
# include "rf/RFConfiguration.h"
|
||||
std::map<int, String> activeReceiverOptions = {
|
||||
{0, "Inactive"},
|
||||
# if defined(ZgatewayPilight) && !defined(ZradioSX127x)
|
||||
@@ -1220,16 +1221,7 @@ std::map<int, String> activeReceiverOptions = {
|
||||
# endif
|
||||
};
|
||||
|
||||
struct RFConfig_s {
|
||||
float frequency;
|
||||
int rssiThreshold;
|
||||
int newOokThreshold;
|
||||
int activeReceiver;
|
||||
};
|
||||
extern RFConfig_s RFConfig;
|
||||
|
||||
bool validFrequency(float mhz);
|
||||
void RFConfig_fromJson(JsonObject& RFdata);
|
||||
extern RFConfiguration iRFConfig;
|
||||
|
||||
bool isValidReceiver(int receiverId) {
|
||||
// Check if the receiverId exists in the activeReceiverOptions map
|
||||
@@ -1257,8 +1249,9 @@ String generateActiveReceiverOptions(int currentSelection) {
|
||||
* T: handleRF Arg: 3, dg=0
|
||||
* T: handleRF Arg: 4, ar=0
|
||||
* T: handleRF Arg: 4, save=
|
||||
*/
|
||||
|
||||
* TODO: need a review, it's a bit strance set the config in the iRFConfig attribute and then
|
||||
* setup a message and finally call the loadFromMessage
|
||||
*/
|
||||
void handleRF() {
|
||||
WEBUI_TRACE_LOG(F("handleRF: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
WEBUI_SECURE
|
||||
@@ -1273,9 +1266,10 @@ void handleRF() {
|
||||
if (server.hasArg("save")) {
|
||||
if (server.hasArg("rf")) {
|
||||
String freqStr = server.arg("rf");
|
||||
RFConfig.frequency = freqStr.toFloat();
|
||||
if (validFrequency(RFConfig.frequency)) {
|
||||
WEBtoRF["frequency"] = RFConfig.frequency;
|
||||
float freq = freqStr.toFloat();
|
||||
if (iRFConfig.validFrequency(freq)) {
|
||||
iRFConfig.setFrequency(freq);
|
||||
WEBtoRF["frequency"] = iRFConfig.getFrequency();
|
||||
update = true;
|
||||
} else {
|
||||
THEENGS_LOG_WARNING(F("[WebUI] Invalid Frequency" CR));
|
||||
@@ -1284,34 +1278,34 @@ void handleRF() {
|
||||
if (server.hasArg("ar")) {
|
||||
int selectedReceiver = server.arg("ar").toInt();
|
||||
if (isValidReceiver(selectedReceiver)) { // Assuming isValidReceiver is a validation function
|
||||
RFConfig.activeReceiver = selectedReceiver;
|
||||
WEBtoRF["activereceiver"] = RFConfig.activeReceiver;
|
||||
iRFConfig.setActiveReceiver(selectedReceiver);
|
||||
WEBtoRF["activereceiver"] = iRFConfig.getActiveReceiver();
|
||||
update = true;
|
||||
} else {
|
||||
THEENGS_LOG_WARNING(F("[WebUI] Invalid Active Receiver" CR));
|
||||
}
|
||||
}
|
||||
if (server.hasArg("oo")) {
|
||||
RFConfig.newOokThreshold = server.arg("oo").toInt();
|
||||
WEBtoRF["ookthreshold"] = RFConfig.newOokThreshold;
|
||||
iRFConfig.setNewOokThreshold(server.arg("oo").toInt());
|
||||
WEBtoRF["ookthreshold"] = iRFConfig.getNewOokThreshold();
|
||||
update = true;
|
||||
}
|
||||
if (server.hasArg("rs")) {
|
||||
RFConfig.rssiThreshold = server.arg("rs").toInt();
|
||||
WEBtoRF["rssithreshold"] = RFConfig.rssiThreshold;
|
||||
iRFConfig.setRssiThreshold(server.arg("rs").toInt());
|
||||
WEBtoRF["rssithreshold"] = iRFConfig.getRssiThreshold();
|
||||
update = true;
|
||||
}
|
||||
if (update) {
|
||||
THEENGS_LOG_NOTICE(F("[WebUI] Save data" CR));
|
||||
WEBtoRF["save"] = true;
|
||||
RFConfig_fromJson(WEBtoRF);
|
||||
iRFConfig.loadFromMessage(WEBtoRF);
|
||||
stateRFMeasures();
|
||||
THEENGS_LOG_TRACE(F("[WebUI] RFConfig end" CR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String activeReceiverHtml = generateActiveReceiverOptions(RFConfig.activeReceiver);
|
||||
String activeReceiverHtml = generateActiveReceiverOptions(iRFConfig.getActiveReceiver());
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
@@ -1322,7 +1316,7 @@ void handleRF() {
|
||||
response += String(script);
|
||||
response += String(style);
|
||||
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_rf_body, jsonChar, gateway_name, RFConfig.frequency, activeReceiverHtml.c_str());
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_rf_body, jsonChar, gateway_name, iRFConfig.getFrequency(), activeReceiverHtml.c_str());
|
||||
response += String(buffer);
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||
response += String(buffer);
|
||||
|
||||
Reference in new issue
Block a user