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.
|
template<typename OsModel_P, typename Radio_P = typename OsModel_P::Radio, typename Timer_P = typename OsModel_P::Timer, typename Clock_P = typename OsModel_P::Clock, typename Debug_P = typename OsModel_P::Debug>
class wiselib::Sensor< OsModel_P, Radio_P, Timer_P, Clock_P, Debug_P >
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
template<typename OsModel_P , typename Radio_P , typename Timer_P , typename Clock_P , typename Debug_P >
Find the distance to a given node, according to the current topology information.
- Parameters:
-
- Returns:
- the distance (in 'hops') to the given node, or INFINITE_DISTANCE if the node does not appear in the topology information.
template<typename OsModel_P , typename Radio_P , typename Timer_P , typename Clock_P , typename Debug_P >
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.
template<typename OsModel_P , typename Radio_P , typename Timer_P , typename Clock_P , typename Debug_P >
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.
template<typename OsModel_P , typename Radio_P , typename Timer_P , typename Clock_P , typename Debug_P >
nodeid_t Sensor::findLeader |
( |
| ) |
[protected] |
Find a leader for this sensor, based on the currently known topology.
- Returns:
- the nodeid of the selected leader. If no node can be this node's leader, then this node's ID is returned.
template<typename OsModel_P , typename Radio_P = typename OsModel_P::Radio, typename Timer_P = typename OsModel_P::Timer, typename Clock_P = typename OsModel_P::Clock, typename Debug_P = typename OsModel_P::Debug>
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.
- Parameters:
-
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 |
- Returns:
- ecSuccess on success, some other code on failure.
template<typename OsModel_P , typename Radio_P = typename OsModel_P::Radio, typename Timer_P = typename OsModel_P::Timer, typename Clock_P = typename OsModel_P::Clock, typename Debug_P = typename OsModel_P::Debug>
template<class T , void(T::*)(int) TMethod>
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)
- Returns:
- returns the internal call back object.
template<typename OsModel_P , typename Radio_P , typename Timer_P , typename Clock_P , typename Debug_P >
void Sensor::resetTopology |
( |
| ) |
[protected] |
Reset the local information about the topology, except for information about the 'self' sensor.
template<typename OsModel_P , typename Radio_P , typename Timer_P , typename Clock_P , typename Debug_P >
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).
- Returns:
- true if the message should be handled, false if it should be discarded.
template<typename OsModel_P , typename Radio_P , typename Timer_P , typename Clock_P , typename Debug_P >
Given topology information about another sensor, should this sensor become its leader or not.
- Parameters:
-
rec | the information about the other sensor |
- Returns:
- true if this sensor should become the leader, false if not.