uavcan: break the link between poll fd indexes and controls

this linkage was fragile and makes it harder to add new orb
subscriptions to the uavcan code
This commit is contained in:
Andrew Tridgell 2014-11-20 09:05:10 +11:00
parent 7cb613bb26
commit 2dae1bc542
2 changed files with 5 additions and 3 deletions

View File

@ -333,14 +333,12 @@ int UavcanNode::run()
} else {
// get controls for required topics
bool controls_updated = false;
unsigned poll_id = 1;
for (unsigned i = 0; i < NUM_ACTUATOR_CONTROL_GROUPS; i++) {
if (_control_subs[i] > 0) {
if (_poll_fds[poll_id].revents & POLLIN) {
if (_poll_fds[_poll_ids[i]].revents & POLLIN) {
controls_updated = true;
orb_copy(_control_topics[i], _control_subs[i], &_controls[i]);
}
poll_id++;
}
}
@ -474,6 +472,7 @@ UavcanNode::subscribe()
if (_control_subs[i] > 0) {
_poll_fds[_poll_fds_num].fd = _control_subs[i];
_poll_fds[_poll_fds_num].events = POLLIN;
_poll_ids[i] = _poll_fds_num;
_poll_fds_num++;
}
}

View File

@ -127,4 +127,7 @@ private:
orb_id_t _control_topics[NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN] = {};
pollfd _poll_fds[NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN + 1] = {}; ///< +1 for /dev/uavcan/busevent
unsigned _poll_fds_num = 0;
// index into _poll_fds for each _control_subs handle
uint8_t _poll_ids[NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN];
};