Terra customization: TinyOS Group Operations

In this page we present a customization, called TerraGrp, that uses the basic library of components, which includes the high-level abstractions for group management.

TerraGrp - Group Operations

The Terra customization, apart local sensors readings, provides an way to define by parameters multiple group of nodes. The "send" and "receive" events applies to a predefined group of nodes. Also includes some value aggregations for group of nodes. Table 4 presents the current TerraGrp events interface and Table 5 presents the functions interface.

The local operations comprises operations to read sensors and residual energy battery, define led's configuration and access input and output devices of the microcontroller. Terra encapsulates all these operations in a component called Local Operations providing them as output events. Timers, on the other hand, are handled directly by the Céu-T language with the await time command.

The SEND() command is a basic send command that reach all nodes in a group definition. If the field target is set to BROADCAST value, all nodes in the group will receive the message. On the other hand, if this field is set to a specific node identifier, only this node will receive the message (if the node is in the group definition). A SEND_DONE() event indicates that the send request was processed by the radio. The RECEIVE event returns a received message. Additionally, TerraGrp implements the SEND_BS() command that router a message to the root node.

The user must define the radio message data structure using pktype command and then create a message variable.


Table 3 - TerraGrp Events interface
Description Output event (emit) Input event (await)
Event identifier Argument type Returned type Event identifier Argument type
Set all three leds - The less three significative bits of the argument will set the leds. LEDS ubyte
Set LED0 - Argument can be ON, OFF, or TOGGLE. LED0 ubyte
Set LED1 - Argument can be ON, OFF, or TOGGLE. LED1 ubyte
Set LED2 - Argument can be ON, OFF, or TOGGLE. LED2 ubyte
Temperature Sensor - Requests and receives the sensor value. The received value is a 10bit reading from A/D converter. This is not the physical unit. REQ_TEMP void ushort TEMP void
Luminosity Sensor - Similar to the others sensors. REQ_PHOTO void ushort PHOTO void
Voltage Sensor - Similar to the others sensors. REQ_VOLTS void ushort VOLTS void
Custom event - This is a internal loopback event that allows to pass a integer value. The await command may define or not which value to wait. REQ_CUSTOM_A ubyte ubyte CUSTOM_A void or ubyte
Send radio message to the BaseStation node. The argument in the await event may be used to wait only a specific message type identifier. SEND_BS msgBS_t ubyte SENDBS_DONE void or ubyte
Send radio message to the group nodes. The argument in the await event may be used to wait only a specific message type identifier. SEND_GR msgGR_t ubyte SENDGR_DONE void or ubyte
Execute an aggregation value for a group nodes. The argument in the await event may be used to wait only a specific message type identifier./td> AGGREG aggreg_t aggDone_t AGGREG_DONE void or ubyte
Receive radio message from a group node- returns a radioMsg variable received by the radio. The argument in the await event may be used to wait only a specific message type identifier. msgGR_t REC_GR void or ubyte
Error trap - Indicates a internal errors like E_DIVZERO and E_IDXOVF, respectively division by zero and array index overflow. ubyte ERROR void or ubyte


Table 4 - TerraGrp functions interface
Description Returned type Function name arguments
Return the node identifier ushort getNodeId void
Return a 16bit random number ushort random void
Return the internal timer counter ulong getTime void
Initialize a Group data structure. Always returns SUCCESS. ubyte groupInit group_t grVar, ubyte ID1, ubyte ID2, ubyte nHops, ubyte status, ubyte elFlag, ushort leader
Initialize an Aggregation data structure. Always returns SUCCESS. ubyte aggregInit aggreg_t agVar, group_t grVar, ubyte sensorId, ubyte agOper, ubyte agComp, ulong refVal
Return the current parent node in the CTP routing tree ushort getParent void
Set the radio transmit power level. Always returns SUCCESS. ubyte setRFPower ubyte level

Table 6 - TerraGrp Constant definitions
Constant Value Description
SUCCESS 0 Indicates a Success operation
TRUE 1 A true value
FALSE 0 A false value
ON 1 Set LED ON
OFF 0 Set LED OFF
TOGGLE 2 Set LED with oposite value
BROADCAST 0xffff Define a broadcast message
E_DIVZERO 10 Error event - Division by zero
E_IDXOVF 11 Error event - Array index overflow
E_STKOVF 20 Error event - Stack overflow -- fatal
opLT 1 LT - "<" operation
opLTE 2 LTE - "<=" operation
opGT 3 GT - ">" operation
opGTE 4 GTE - "<=" operation
opEQ 5 EQ - "==" operation
opNEQ 6 NEQ - "!=" operation
fAVG 0 Aggreg Functions - Average
fSUM 1 Aggreg Functions - Summation
fAVG 0 Aggreg Functions - Average
fMAX 2 Aggreg Functions - Maximum value
fMIN 3 Aggreg Functions - Minimum value
SID_TEMP 1 Sensor IDs - Temperature
SID_PHOTO 2 Sensor IDs - Luminosity
SID_LEDS 3 Sensor IDs - Leds
SID_VOLT 1 Sensor IDs - Voltage
eACTIVE 1 Group Election Status - Node participate activitely.
ePASSIVE 3 Group Election Status - Node participate, but not vote to be a leader.
eOFF 3 Group Election Status - Node is disabled on the election procedure