@@ -8,10 +8,16 @@ extern rtl_433_ESP rtl_433;
8
8
#endif
9
9
10
10
// Constructor
11
- RFConfiguration::RFConfiguration (RFReceiver& receiver) : iRFReceiver(receiver) {
11
+ RFConfiguration::RFConfiguration (RFReceiver& receiver) : iRFReceiver(receiver), whiteList( nullptr ), whiteListSize( 0 ), blackList( nullptr ), blackListSize( 0 ) {
12
12
reInit ();
13
13
}
14
14
15
+ // Destructor
16
+ RFConfiguration::~RFConfiguration () {
17
+ delete[] whiteList;
18
+ delete[] blackList;
19
+ }
20
+
15
21
// Getters and Setters
16
22
float RFConfiguration::getFrequency () const {
17
23
return frequency;
@@ -61,31 +67,17 @@ void RFConfiguration::setIgnoreBlacklist(bool ignore) {
61
67
ignoreBlacklist = ignore;
62
68
}
63
69
64
- const std::vector<uint64_t >& RFConfiguration::getWhiteList () const {
65
- return whiteList;
66
- }
67
-
68
- void RFConfiguration::setWhiteList (const std::vector<uint64_t >& list) {
69
- whiteList = list;
70
- }
71
-
72
- const std::vector<uint64_t >& RFConfiguration::getBlackList () const {
73
- return blackList;
74
- }
75
-
76
- void RFConfiguration::setBlackList (const std::vector<uint64_t >& list) {
77
- blackList = list;
78
- }
79
-
80
70
// Utility methods
81
71
void RFConfiguration::clearWhiteList () {
82
- whiteList.clear ();
83
- whiteList.shrink_to_fit ();
72
+ delete[] whiteList;
73
+ whiteList = nullptr ;
74
+ whiteListSize = 0 ;
84
75
}
85
76
86
77
void RFConfiguration::clearBlackList () {
87
- blackList.clear ();
88
- blackList.shrink_to_fit ();
78
+ delete[] blackList;
79
+ blackList = nullptr ;
80
+ blackListSize = 0 ;
89
81
}
90
82
91
83
/* *
@@ -106,10 +98,8 @@ void RFConfiguration::reInit() {
106
98
newOokThreshold = 0 ;
107
99
ignoreWhitelist = false ;
108
100
ignoreBlacklist = false ;
109
- whiteList.clear ();
110
- whiteList.shrink_to_fit ();
111
- blackList.clear ();
112
- blackList.shrink_to_fit ();
101
+ clearWhiteList ();
102
+ clearBlackList ();
113
103
}
114
104
115
105
/* *
@@ -359,13 +349,13 @@ void RFConfiguration::toJson(JsonObject& RFdata) {
359
349
360
350
// Add white-list vector to the JSON object
361
351
JsonArray whiteListArray = RFdata.createNestedArray (" white-list" );
362
- for (const auto & value : whiteList ) {
363
- whiteListArray.add (value );
352
+ for (size_t i = 0 ; i < whiteListSize; ++i ) {
353
+ whiteListArray.add (whiteList[i] );
364
354
}
365
355
// Add black-list vector to the JSON object
366
356
JsonArray blackListArray = RFdata.createNestedArray (" black-list" );
367
- for (const auto & value : blackList ) {
368
- blackListArray.add (value );
357
+ for (size_t i = 0 ; i < blackListSize; ++i ) {
358
+ blackListArray.add (blackList[i] );
369
359
}
370
360
}
371
361
@@ -385,8 +375,8 @@ bool RFConfiguration::inBlackList(uint64_t MQTTvalue) {
385
375
if (ignoreBlacklist) {
386
376
return false ;
387
377
}
388
- for (const auto & value : blackList ) {
389
- if (value == MQTTvalue) {
378
+ for (size_t i = 0 ; i < blackListSize; ++i ) {
379
+ if (blackList[i] == MQTTvalue) {
390
380
return true ;
391
381
}
392
382
}
@@ -405,11 +395,11 @@ bool RFConfiguration::inBlackList(uint64_t MQTTvalue) {
405
395
* @return false if the value is not in the whitelist.
406
396
*/
407
397
bool RFConfiguration::inWhiteList (uint64_t MQTTvalue) {
408
- if (ignoreWhitelist || whiteList. empty () ) {
398
+ if (ignoreWhitelist || whiteListSize == 0 ) {
409
399
return true ;
410
400
}
411
- for (const auto & value : whiteList ) {
412
- if (value == MQTTvalue) {
401
+ for (size_t i = 0 ; i < whiteListSize; ++i ) {
402
+ if (whiteList[i] == MQTTvalue) {
413
403
return true ;
414
404
}
415
405
}
@@ -467,10 +457,12 @@ bool RFConfiguration::commandSetWhiteorBlackList(JsonObject& RFdata, bool isWhit
467
457
if (value != NULL ) {
468
458
uint64_t MQTTvalue = strtoull (value, NULL , 10 );
469
459
if (isWhite) {
470
- whiteList.push_back (MQTTvalue);
460
+ whiteList = (uint64_t *)realloc (whiteList, (whiteListSize + 1 ) * sizeof (uint64_t ));
461
+ whiteList[whiteListSize++] = MQTTvalue;
471
462
Log.trace (F (" [RF] White list updated with value: %s" CR), value);
472
463
} else {
473
- blackList.push_back (MQTTvalue);
464
+ blackList = (uint64_t *)realloc (blackList, (blackListSize + 1 ) * sizeof (uint64_t ));
465
+ blackList[blackListSize++] = MQTTvalue;
474
466
Log.trace (F (" [RF] Black list updated with value: %s" CR), value);
475
467
}
476
468
} else {
0 commit comments