@@ -2093,6 +2093,7 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
2093
2093
2094
2094
// attach a built-in or custom sensor to this manager
2095
2095
int NodeManager::registerSensor (Sensor* sensor) {
2096
+ if (sensor->getChildId () > MAX_SENSORS) return ;
2096
2097
#if DEBUG == 1
2097
2098
Serial.print (F (" REG I=" ));
2098
2099
Serial.print (sensor->getChildId ());
@@ -2115,12 +2116,14 @@ int NodeManager::registerSensor(Sensor* sensor) {
2115
2116
2116
2117
// un-register a sensor to this manager
2117
2118
void NodeManager::unRegisterSensor (int sensor_index) {
2119
+ if (sensor_index > MAX_SENSORS) return ;
2118
2120
// unlink the pointer to this sensor
2119
2121
_sensors[sensor_index] == 0 ;
2120
2122
}
2121
2123
2122
2124
// return a sensor given its index
2123
2125
Sensor* NodeManager::get (int child_id) {
2126
+ if (child_id > MAX_SENSORS) return 0 ;
2124
2127
// return a pointer to the sensor from the given child_id
2125
2128
return _sensors[child_id];
2126
2129
}
@@ -2130,6 +2133,7 @@ Sensor* NodeManager::getSensor(int child_id) {
2130
2133
2131
2134
// assign a different child id to a sensor'
2132
2135
bool NodeManager::renameSensor (int old_child_id, int new_child_id) {
2136
+ if (old_child_id > MAX_SENSORS || new_child_id > MAX_SENSORS) return ;
2133
2137
// ensure the old id exists and the new is available
2134
2138
if (_sensors[old_child_id] == 0 || _sensors[new_child_id] != 0 ) return false ;
2135
2139
// assign the sensor to new id
@@ -2193,7 +2197,7 @@ void NodeManager::before() {
2193
2197
if (! _battery_internal_vcc && _battery_pin > -1 ) analogReference (INTERNAL);
2194
2198
#endif
2195
2199
// setup individual sensors
2196
- for (int i = 0 ; i < 255 ; i++) {
2200
+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
2197
2201
if (_sensors[i] == 0 ) continue ;
2198
2202
// call each sensor's setup()
2199
2203
_sensors[i]->before ();
@@ -2217,7 +2221,7 @@ void NodeManager::presentation() {
2217
2221
_process (" BATTERY" );
2218
2222
#endif
2219
2223
// present each sensor
2220
- for (int i = 0 ; i < 255 ; i++) {
2224
+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
2221
2225
if (_sensors[i] == 0 ) continue ;
2222
2226
// call each sensor's presentation()
2223
2227
if (_sleep_between_send > 0 ) sleep (_sleep_between_send);
@@ -2242,7 +2246,7 @@ void NodeManager::setup() {
2242
2246
_send (_msg.set (" STARTED" ));
2243
2247
#endif
2244
2248
// run setup for all the registered sensors
2245
- for (int i = 0 ; i < 255 ; i++) {
2249
+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
2246
2250
if (_sensors[i] == 0 ) continue ;
2247
2251
// call each sensor's setup()
2248
2252
_sensors[i]->setup ();
@@ -2261,7 +2265,7 @@ void NodeManager::loop() {
2261
2265
if (_auto_power_pins) powerOn ();
2262
2266
#endif
2263
2267
// run loop for all the registered sensors
2264
- for (int i = 0 ; i < 255 ; i++) {
2268
+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
2265
2269
// skip not configured sensors
2266
2270
if (_sensors[i] == 0 ) continue ;
2267
2271
// if waking up from an interrupt skip all the sensor without that interrupt configured
@@ -2296,7 +2300,7 @@ void NodeManager::receive(const MyMessage &message) {
2296
2300
_process (message.getString ());
2297
2301
}
2298
2302
// dispatch the message to the registered sensor
2299
- else if (_sensors[message.sensor ] != 0 ) {
2303
+ else if (message. sensor <= MAX_SENSORS && _sensors[message.sensor ] != 0 ) {
2300
2304
#if POWER_MANAGER == 1
2301
2305
// turn on the pin powering all the sensors
2302
2306
if (_auto_power_pins) powerOn ();
@@ -2609,12 +2613,13 @@ void NodeManager::_present(int child_id, int type) {
2609
2613
2610
2614
// return the next available child_id
2611
2615
int NodeManager::_getAvailableChildId () {
2612
- for (int i = 1 ; i < 255 ; i++) {
2616
+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
2613
2617
if (i == CONFIGURATION_CHILD_ID) continue ;
2614
2618
if (i == BATTERY_CHILD_ID) continue ;
2615
2619
// empty place, return it
2616
2620
if (_sensors[i] == 0 ) return i;
2617
2621
}
2622
+ return MAX_SENSORS;
2618
2623
}
2619
2624
2620
2625
// guess the initial value of a digital output based on the configured interrupt mode
0 commit comments