@@ -8,14 +8,12 @@ extern rtl_433_ESP rtl_433;
88#endif
99
1010// Constructor
11- RFConfiguration::RFConfiguration (RFReceiver& receiver) : iRFReceiver(receiver), whiteList( nullptr ), whiteListSize( 0 ), blackList( nullptr ), blackListSize( 0 ) {
11+ RFConfiguration::RFConfiguration (RFReceiver& receiver) : iRFReceiver(receiver) {
1212 reInit ();
1313}
1414
1515// Destructor
1616RFConfiguration::~RFConfiguration () {
17- delete[] whiteList;
18- delete[] blackList;
1917}
2018
2119// Getters and Setters
@@ -51,35 +49,6 @@ void RFConfiguration::setActiveReceiver(int receiver) {
5149 activeReceiver = receiver;
5250}
5351
54- bool RFConfiguration::isWhitelistIgnored () const {
55- return ignoreWhitelist;
56- }
57-
58- void RFConfiguration::setIgnoreWhitelist (bool ignore) {
59- ignoreWhitelist = ignore;
60- }
61-
62- bool RFConfiguration::isBlacklistIgnored () const {
63- return ignoreBlacklist;
64- }
65-
66- void RFConfiguration::setIgnoreBlacklist (bool ignore) {
67- ignoreBlacklist = ignore;
68- }
69-
70- // Utility methods
71- void RFConfiguration::clearWhiteList () {
72- delete[] whiteList;
73- whiteList = nullptr ;
74- whiteListSize = 0 ;
75- }
76-
77- void RFConfiguration::clearBlackList () {
78- delete[] blackList;
79- blackList = nullptr ;
80- blackListSize = 0 ;
81- }
82-
8352/* *
8453 * @brief Initializes the RFConfiguration with default values.
8554 *
@@ -96,10 +65,6 @@ void RFConfiguration::reInit() {
9665 activeReceiver = ACTIVE_RECEIVER;
9766 rssiThreshold = 0 ;
9867 newOokThreshold = 0 ;
99- ignoreWhitelist = false ;
100- ignoreBlacklist = false ;
101- clearWhiteList ();
102- clearBlackList ();
10368}
10469
10570/* *
@@ -272,14 +237,7 @@ void RFConfiguration::loadFromMessage(JsonObject& RFdata) {
272237 */
273238void RFConfiguration::fromJson (JsonObject& RFdata) {
274239 bool success = false ;
275- if (RFdata.containsKey (" white-list" )) {
276- success = commandSetWhiteorBlackList (RFdata, true );
277- Log.notice (F (" RF white-list updated" CR));
278- }
279- if (RFdata.containsKey (" black-list" )) {
280- success = commandSetWhiteorBlackList (RFdata, false );
281- Log.notice (F (" RF black-list updated" CR));
282- }
240+
283241 if (RFdata.containsKey (" frequency" ) && validFrequency (RFdata[" frequency" ])) {
284242 Config_update (RFdata, " frequency" , frequency);
285243 Log.notice (F (" RF Receive mhz: %F" CR), frequency);
@@ -344,66 +302,11 @@ void RFConfiguration::toJson(JsonObject& RFdata) {
344302 RFdata[" rssithreshold" ] = rssiThreshold;
345303 RFdata[" ookthreshold" ] = newOokThreshold;
346304 RFdata[" active" ] = activeReceiver;
347- RFdata[" ignoreWhitelist" ] = ignoreWhitelist;
348- RFdata[" ignoreBlacklist" ] = ignoreBlacklist;
349305
350306 // Add white-list vector to the JSON object
351307 JsonArray whiteListArray = RFdata.createNestedArray (" white-list" );
352- for (size_t i = 0 ; i < whiteListSize; ++i) {
353- whiteListArray.add (whiteList[i]);
354- }
355308 // Add black-list vector to the JSON object
356309 JsonArray blackListArray = RFdata.createNestedArray (" black-list" );
357- for (size_t i = 0 ; i < blackListSize; ++i) {
358- blackListArray.add (blackList[i]);
359- }
360- }
361-
362- /* *
363- * @brief Checks if a given MQTT value is present in the blacklist.
364- *
365- * This function determines whether the specified MQTT value is included
366- * in the blacklist defined in the If the `ignoreBlacklist`
367- * flag in RFConfiguration is set to true, the function will always return false,
368- * effectively bypassing the blacklist check.
369- *
370- * @param MQTTvalue The MQTT value to check against the blacklist.
371- * @return true if the MQTT value is in the blacklist and the blacklist
372- * check is not ignored; false otherwise.
373- */
374- bool RFConfiguration::inBlackList (uint64_t MQTTvalue) {
375- if (ignoreBlacklist) {
376- return false ;
377- }
378- for (size_t i = 0 ; i < blackListSize; ++i) {
379- if (blackList[i] == MQTTvalue) {
380- return true ;
381- }
382- }
383- return false ;
384- }
385-
386- /* *
387- * @brief Checks if a given MQTT value is in the whitelist.
388- *
389- * This function determines whether the specified MQTT value is present
390- * in the whitelist. If the whitelist is disabled (via the `ignoreWhitelist`
391- * flag) or is empty, the function will always return true.
392- *
393- * @param MQTTvalue The MQTT value to check against the whitelist.
394- * @return true if the whitelist is disabled, empty, or the value is found in the whitelist.
395- * @return false if the value is not in the whitelist.
396- */
397- bool RFConfiguration::inWhiteList (uint64_t MQTTvalue) {
398- if (ignoreWhitelist || whiteListSize == 0 ) {
399- return true ;
400- }
401- for (size_t i = 0 ; i < whiteListSize; ++i) {
402- if (whiteList[i] == MQTTvalue) {
403- return true ;
404- }
405- }
406- return false ;
407310}
408311
409312/* *
@@ -427,48 +330,3 @@ bool RFConfiguration::validFrequency(float mhz) {
427330 return true ;
428331 return false ;
429332}
430-
431- /* *
432- * @brief Updates the white or black list of RF devices.
433- *
434- * This function updates the white or black list of RF devices based on the provided JSON object.
435- * It iterates through the list of devices and creates or updates them in the system.
436- *
437- * @param RFdata The JSON object containing the RF data.
438- * @param isWhite A boolean indicating whether to update the white list (true) or black list (false).
439- * @return true if the update was successful, false otherwise.
440- */
441- bool RFConfiguration::commandSetWhiteorBlackList (JsonObject& RFdata, bool isWhite) {
442- Log.trace (F (" RF update WorB" CR));
443- const char * jsonKey = isWhite ? " white-list" : " black-list" ;
444-
445- int size = RFdata[jsonKey].size ();
446- if (size == 0 )
447- return false ;
448-
449- if (isWhite) {
450- clearWhiteList ();
451- } else {
452- clearBlackList ();
453- }
454-
455- for (int i = 0 ; i < size; i++) {
456- const char * value = RFdata[jsonKey][i];
457- if (value != NULL ) {
458- uint64_t MQTTvalue = strtoull (value, NULL , 10 );
459- if (isWhite) {
460- whiteList = (uint64_t *)realloc (whiteList, (whiteListSize + 1 ) * sizeof (uint64_t ));
461- whiteList[whiteListSize++] = MQTTvalue;
462- Log.trace (F (" [RF] White list updated with value: %s" CR), value);
463- } else {
464- blackList = (uint64_t *)realloc (blackList, (blackListSize + 1 ) * sizeof (uint64_t ));
465- blackList[blackListSize++] = MQTTvalue;
466- Log.trace (F (" [RF] Black list updated with value: %s" CR), value);
467- }
468- } else {
469- Log.error (F (" [RF] Error updating WorB: NULL value" CR));
470- return false ;
471- }
472- }
473- return true ;
474- }
0 commit comments