Wiselib
|
A sensor that takes part in leader election and clustering. More...
#include <BGU_Sensor.h>
Inherits wiselib::MessageDestination, and wiselib::MessageDestination.
Public Types | |
typedef OsModel_P | OsModel |
typedef Radio_P | Radio |
typedef Timer_P | Timer |
typedef Clock_P | Clock |
typedef Debug_P | Debug |
typedef Sensor< OsModel, Radio, Timer, Clock, Debug > | self_type |
typedef wiselib::Echo< Os, Os::TxRadio, Os::Timer, Os::Debug > | NeighborDiscovery |
typedef wiselib::vector_static < wiselib::OSMODEL, nodeid_t, 10 > | vector_static |
typedef self_type * | self_pointer_t |
typedef delegate1< void, int > | cluster_delegate_t |
typedef Radio::node_id_t | node_id_t |
typedef Radio::size_t | size_t |
typedef Radio::block_data_t | block_data_t |
typedef Timer::millis_t | millis_t |
typedef OsModel_P | OsModel |
typedef Radio_P | Radio |
typedef Timer_P | Timer |
typedef Clock_P | Clock |
typedef Debug_P | Debug |
typedef Sensor< OsModel, Radio, Timer, Clock, Debug > | self_type |
typedef wiselib::Echo< Os, Os::TxRadio, Os::Timer, Os::Debug > | NeighborDiscovery |
typedef wiselib::vector_static < wiselib::OSMODEL, nodeid_t, 10 > | vector_static |
typedef self_type * | self_pointer_t |
typedef Radio::node_id_t | node_id_t |
typedef Radio::size_t | size_t |
typedef Radio::block_data_t | block_data_t |
typedef Timer::millis_t | millis_t |
Public Member Functions | |
Sensor () | |
Constructor. | |
~Sensor () | |
Destructor. | |
error_code_t | init (typename Timer::self_pointer_t timer, typename Radio::self_pointer_t radio, MessageQueue *mqueue, Os::Debug::self_pointer_t debug, Os::Clock::self_pointer_t clock, NeighborDiscovery &neighbor_discovery) |
Initialize the sensor. | |
error_code_t | handle (TopologyMessage *msg) |
Handle a single incoming message. | |
nodeid_t | cluster_head () |
nodeid_t | parent () |
uint8_t | hops () |
nodeid_t | cluster_id () |
template<class T , void(T::*)(int) TMethod> | |
int | reg_changed_callback (T *obj_pnt) |
Register callbacks. | |
void | unreg_changed_callback (int idx) |
Unregister callbacks. | |
Sensor () | |
Constructor. | |
error_code_t | init (typename Timer::self_pointer_t timer, typename Radio::self_pointer_t radio, MessageQueue *mqueue, Os::Debug::self_pointer_t debug, Os::Clock::self_pointer_t clock, NeighborDiscovery &neighbor_discovery) |
Destructor. | |
error_code_t | handle (TopologyMessage *msg) |
nodeid_t | cluster_head () |
nodeid_t | parent () |
uint8_t | hops () |
nodeid_t | cluster_id () |
void | doWork (void *) |
void | doBlink (void *) |
bool | shouldAccept (Message *) |
uint8_t | distanceToNode (nodeid_t node) |
void | resetTopology () |
bool | shouldAssumeLeadership (const topology_record_t &) |
error_code_t | handleAllMessages () |
nodeid_t | findLeader () |
error_code_t | broadcastTopology () |
Protected Member Functions | |
void | doWork (void *) |
Update the local topology and elect a leader if needed. | |
void | doBlink (void *) |
Blink the sensor physical LED. | |
bool | shouldAccept (Message *msg) |
Check if a message received should be discarded. | |
void | resetTopology () |
Reset the local information about the topology, except for information about the 'self' sensor. | |
bool | shouldAssumeLeadership (const topology_record_t &rec) |
Given topology information about another sensor, should this sensor become its leader or not. | |
error_code_t | handleAllMessages () |
Handle all topology messages accumulated on this sensor's message queue. | |
nodeid_t | findLeader () |
Find a leader for this sensor, based on the currently known topology. | |
error_code_t | broadcastTopology () |
Send a message containing the topology information known by this node to all other nodes. | |
uint8_t | distanceToNode (nodeid_t node) |
Find the distance to a given node, according to the current topology information. | |
void | findMyNeighbors () |
void | scheduleWorkCallback () |
Schedule the next run of the doWork callback. | |
void | scheduleBlinkCallback () |
Schedule the next run of the doBlink callback. | |
void | calculateNewTopology () |
Calculate new topology from information in the Messages container. | |
bool | isNeighbor (nodeid_t other) |
Check if a given node is a direct neighbor. |
A sensor that takes part in leader election and clustering.
A sensor periodically accepts and sends topology update messages, and performs leader election according to the information contained in them and to the algorithm described in ftp://ftp.cs.bgu.ac.il/pub/people/dolev/60.pdf
typedef Radio::block_data_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::block_data_t |
typedef Radio::block_data_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::block_data_t |
typedef Clock_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Clock |
typedef Clock_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Clock |
typedef delegate1<void, int> wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::cluster_delegate_t |
typedef Debug_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Debug |
typedef Debug_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Debug |
typedef Timer::millis_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::millis_t |
typedef Timer::millis_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::millis_t |
typedef wiselib::Echo<Os, Os::TxRadio, Os::Timer, Os::Debug> wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::NeighborDiscovery |
typedef wiselib::Echo<Os, Os::TxRadio, Os::Timer, Os::Debug> wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::NeighborDiscovery |
typedef Radio::node_id_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::node_id_t |
typedef Radio::node_id_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::node_id_t |
typedef OsModel_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::OsModel |
typedef OsModel_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::OsModel |
typedef Radio_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Radio |
typedef Radio_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Radio |
typedef self_type* wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::self_pointer_t |
typedef self_type* wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::self_pointer_t |
typedef Sensor<OsModel, Radio, Timer, Clock, Debug> wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::self_type |
typedef Sensor<OsModel, Radio, Timer, Clock, Debug> wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::self_type |
typedef Radio::size_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::size_t |
typedef Radio::size_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::size_t |
typedef Timer_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Timer |
typedef Timer_P wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Timer |
typedef wiselib::vector_static<wiselib::OSMODEL, nodeid_t, 10> wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::vector_static |
typedef wiselib::vector_static<wiselib::OSMODEL, nodeid_t, 10> wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::vector_static |
wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Sensor | ( | ) | [inline] |
Constructor.
Actual initialization of a Sensor object is done in the init method
Sensor::~Sensor | ( | ) |
Destructor.
wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::Sensor | ( | ) | [inline] |
Constructor.
error_code_t Sensor::broadcastTopology | ( | ) | [protected] |
Send a message containing the topology information known by this node to all other nodes.
error_code_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::broadcastTopology | ( | ) |
void Sensor::calculateNewTopology | ( | ) | [protected] |
Calculate new topology from information in the Messages container.
nodeid_t Sensor::cluster_head | ( | ) |
nodeid_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::cluster_head | ( | ) |
nodeid_t Sensor::cluster_id | ( | ) |
nodeid_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::cluster_id | ( | ) |
uint8_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::distanceToNode | ( | nodeid_t | node | ) |
uint8_t Sensor::distanceToNode | ( | nodeid_t | node | ) | [protected] |
Find the distance to a given node, according to the current topology information.
node | the node to look for |
void Sensor::doBlink | ( | void * | ) | [protected] |
Blink the sensor physical LED.
This is a Timer callback, and so takes an unused parameter and returns nothing.
TODO turn the LED on/off according to _led_state.
TODO turn the LED on/off according to _led_state.
void wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::doBlink | ( | void * | ) |
void Sensor::doWork | ( | void * | ) | [protected] |
Update the local topology and elect a leader if needed.
This is a Timer callback, and so takes an unused parameter and returns nothing.
void wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::doWork | ( | void * | ) |
nodeid_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::findLeader | ( | ) |
nodeid_t Sensor::findLeader | ( | ) | [protected] |
Find a leader for this sensor, based on the currently known topology.
void Sensor::findMyNeighbors | ( | ) | [protected] |
error_code_t Sensor::handle | ( | TopologyMessage * | msg | ) | [virtual] |
Handle a single incoming message.
msg | the message to handle |
Implements wiselib::MessageDestination.
error_code_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::handle | ( | TopologyMessage * | msg | ) | [virtual] |
Implements wiselib::MessageDestination.
error_code_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::handleAllMessages | ( | ) |
error_code_t Sensor::handleAllMessages | ( | ) | [protected] |
Handle all topology messages accumulated on this sensor's message queue.
uint8_t Sensor::hops | ( | ) |
uint8_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::hops | ( | ) |
error_code_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::init | ( | typename Timer::self_pointer_t | timer, |
typename Radio::self_pointer_t | radio, | ||
MessageQueue * | mqueue, | ||
Os::Debug::self_pointer_t | debug, | ||
Os::Clock::self_pointer_t | clock, | ||
NeighborDiscovery & | neighbor_discovery | ||
) |
Initialize the sensor.
This method must be called exactly once, before any other method is used.
timer | The timer to use for periodic activities. |
radio | The radio for this sensor |
mqueue | A source of topology messages |
debug | A debug stream to use for debugging messages |
clock | The clock to use |
neighbor_discovery | The algorithm for discovering neighbors |
error_code_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::init | ( | typename Timer::self_pointer_t | timer, |
typename Radio::self_pointer_t | radio, | ||
MessageQueue * | mqueue, | ||
Os::Debug::self_pointer_t | debug, | ||
Os::Clock::self_pointer_t | clock, | ||
NeighborDiscovery & | neighbor_discovery | ||
) |
Destructor.
Initialization method.
bool Sensor::isNeighbor | ( | nodeid_t | other | ) | [protected] |
Check if a given node is a direct neighbor.
other | the nodeid to check |
nodeid_t wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::parent | ( | ) |
nodeid_t Sensor::parent | ( | ) |
int wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::reg_changed_callback | ( | T * | obj_pnt | ) | [inline] |
Register callbacks.
(notifys when something changes)
void wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::resetTopology | ( | ) |
void Sensor::resetTopology | ( | ) | [protected] |
Reset the local information about the topology, except for information about the 'self' sensor.
void wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::scheduleBlinkCallback | ( | ) | [inline, protected] |
Schedule the next run of the doBlink callback.
void wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::scheduleWorkCallback | ( | ) | [inline, protected] |
Schedule the next run of the doWork callback.
bool wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::shouldAccept | ( | Message * | ) |
bool Sensor::shouldAccept | ( | Message * | msg | ) | [protected] |
Check if a message received should be discarded.
The algorithm assumes that only messages from direct neighbors are received, so we discard any message that's received from a node that isn't a direct neighbor (distance=1).
bool Sensor::shouldAssumeLeadership | ( | const topology_record_t & | rec | ) | [protected] |
Given topology information about another sensor, should this sensor become its leader or not.
rec | the information about the other sensor |
bool wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::shouldAssumeLeadership | ( | const topology_record_t & | ) |
void wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >::unreg_changed_callback | ( | int | idx | ) | [inline] |
Unregister callbacks.