sensors: use only as many voters as there are sensors

This saves ~1.1KB of RAM for systems with only 1 sensor of each type.

If there are more sensors, they will be dynamically added, such that
failover still works.
This commit is contained in:
Beat Küng 2016-11-01 07:55:05 +01:00 committed by Lorenz Meier
parent 0f2b31b41e
commit 85cee9460f

View File

@ -212,7 +212,7 @@ private:
SensorData()
: last_best_vote(0),
subscription_count(0),
voter(SENSOR_COUNT_MAX),
voter(1),
last_failover_count(0)
{
for (unsigned i = 0; i < SENSOR_COUNT_MAX; i++) {
@ -2266,6 +2266,13 @@ Sensors::init_sensor_class(const struct orb_metadata *meta, SensorData &sensor_d
for (unsigned i = 0; i < group_count; i++) {
if (sensor_data.subscription[i] < 0) {
sensor_data.subscription[i] = orb_subscribe_multi(meta, i);
if (i > 0) {
/* the first always exists, but for each further sensor, add a new validator */
if (!sensor_data.voter.add_new_validator()) {
PX4_ERR("failed to add validator for sensor %s %i", meta->o_name, i);
}
}
}
int32_t priority;