@@ -2093,6 +2093,7 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
20932093
20942094// attach a built-in or custom sensor to this manager
20952095int NodeManager::registerSensor (Sensor* sensor) {
2096+ if (sensor->getChildId () > MAX_SENSORS) return ;
20962097 #if DEBUG == 1
20972098 Serial.print (F (" REG I=" ));
20982099 Serial.print (sensor->getChildId ());
@@ -2115,12 +2116,14 @@ int NodeManager::registerSensor(Sensor* sensor) {
21152116
21162117// un-register a sensor to this manager
21172118void NodeManager::unRegisterSensor (int sensor_index) {
2119+ if (sensor_index > MAX_SENSORS) return ;
21182120 // unlink the pointer to this sensor
21192121 _sensors[sensor_index] == 0 ;
21202122}
21212123
21222124// return a sensor given its index
21232125Sensor* NodeManager::get (int child_id) {
2126+ if (child_id > MAX_SENSORS) return 0 ;
21242127 // return a pointer to the sensor from the given child_id
21252128 return _sensors[child_id];
21262129}
@@ -2130,6 +2133,7 @@ Sensor* NodeManager::getSensor(int child_id) {
21302133
21312134// assign a different child id to a sensor'
21322135bool NodeManager::renameSensor (int old_child_id, int new_child_id) {
2136+ if (old_child_id > MAX_SENSORS || new_child_id > MAX_SENSORS) return ;
21332137 // ensure the old id exists and the new is available
21342138 if (_sensors[old_child_id] == 0 || _sensors[new_child_id] != 0 ) return false ;
21352139 // assign the sensor to new id
@@ -2193,7 +2197,7 @@ void NodeManager::before() {
21932197 if (! _battery_internal_vcc && _battery_pin > -1 ) analogReference (INTERNAL);
21942198 #endif
21952199 // setup individual sensors
2196- for (int i = 0 ; i < 255 ; i++) {
2200+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
21972201 if (_sensors[i] == 0 ) continue ;
21982202 // call each sensor's setup()
21992203 _sensors[i]->before ();
@@ -2217,7 +2221,7 @@ void NodeManager::presentation() {
22172221 _process (" BATTERY" );
22182222 #endif
22192223 // present each sensor
2220- for (int i = 0 ; i < 255 ; i++) {
2224+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
22212225 if (_sensors[i] == 0 ) continue ;
22222226 // call each sensor's presentation()
22232227 if (_sleep_between_send > 0 ) sleep (_sleep_between_send);
@@ -2242,7 +2246,7 @@ void NodeManager::setup() {
22422246 _send (_msg.set (" STARTED" ));
22432247 #endif
22442248 // run setup for all the registered sensors
2245- for (int i = 0 ; i < 255 ; i++) {
2249+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
22462250 if (_sensors[i] == 0 ) continue ;
22472251 // call each sensor's setup()
22482252 _sensors[i]->setup ();
@@ -2261,7 +2265,7 @@ void NodeManager::loop() {
22612265 if (_auto_power_pins) powerOn ();
22622266 #endif
22632267 // run loop for all the registered sensors
2264- for (int i = 0 ; i < 255 ; i++) {
2268+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
22652269 // skip not configured sensors
22662270 if (_sensors[i] == 0 ) continue ;
22672271 // if waking up from an interrupt skip all the sensor without that interrupt configured
@@ -2296,7 +2300,7 @@ void NodeManager::receive(const MyMessage &message) {
22962300 _process (message.getString ());
22972301 }
22982302 // 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 ) {
23002304 #if POWER_MANAGER == 1
23012305 // turn on the pin powering all the sensors
23022306 if (_auto_power_pins) powerOn ();
@@ -2609,12 +2613,13 @@ void NodeManager::_present(int child_id, int type) {
26092613
26102614// return the next available child_id
26112615int NodeManager::_getAvailableChildId () {
2612- for (int i = 1 ; i < 255 ; i++) {
2616+ for (int i = 1 ; i <= MAX_SENSORS ; i++) {
26132617 if (i == CONFIGURATION_CHILD_ID) continue ;
26142618 if (i == BATTERY_CHILD_ID) continue ;
26152619 // empty place, return it
26162620 if (_sensors[i] == 0 ) return i;
26172621 }
2622+ return MAX_SENSORS;
26182623}
26192624
26202625// guess the initial value of a digital output based on the configured interrupt mode
0 commit comments