Read up on GenericComm.
But briefly, in a header file you assign arbitrary 16 bit message
identifiers and their associated data structures:
/** Message types
**/
enum
{
// Status Reply to Host (Send)
AM_ROBOSTATUSMSG = 10, // normal robot status
AM_ROBODATAMSG = 11, // dump of internal data tables
// Host Commands (Receive)
AM_ROBOCMDSTARTMSG = 32, // Start motion
AM_ROBOCMDSTOPMSG, // Stop immediately
AM_ROBOCMDSTATMSG, // Status: return current status
AM_ROBOCMDDATAMSG // Status: return internal data tables
};
Then in a config file you define a set of message handlers:
// Host commands to be received (from Radio or UART)
RoboMsgM.RCmdStartMsg -> GenericComm.ReceiveMsg[AM_ROBOCMDSTARTMSG];
RoboMsgM.RCmdStopMsg -> GenericComm.ReceiveMsg[AM_ROBOCMDSTOPMSG];
RoboMsgM.RCmdStatMsg -> GenericComm.ReceiveMsg[AM_ROBOCMDSTATMSG];
RoboMsgM.RCmdDataMsg -> GenericComm.ReceiveMsg[AM_ROBOCMDDATAMSG];
// Status replies to send
RoboMsgM.RStatusMsg -> GenericComm.SendMsg[AM_ROBOSTATUSMSG];
RoboMsgM.RDataMsg -> GenericComm.SendMsg[AM_ROBODATAMSG];
And in the code module (RoboMsg.nc in this case) you create the
methods for each:
/**
* Signalled when the Start Command AM is received.
* @return The free TOS_MsgPtr.
*/
event TOS_MsgPtr RCmdStartMsg.receive(TOS_MsgPtr m)
{
...
return m;
}
/** task to send StatusMsg
**/
task void messageTask()
{
...
call RStatusMsg.send( TosBaseId, sizeof(RoboStatusMsg), statmsgp );
}
MS
Peizhao Hu wrote:
Hi
I have three motes:
Mote(Base) - receive sensing data from Mote(Sensor) nodes and forward
them to PC.
Mote(Sensor) - sense temperature readings, and listen to Mote(Base) for
changing of sampling rate, etc; and listen to Mote(Reference) for
location reference points to calculate its current position.
Mote(Reference) - periodically broadcast its location.
So, how can I implement the Mote(Sensor) to receive two different
message types when they arrived?
My current TinyOS application is a modification of AntiTheft app, but
not sure how I can distinguish these different message types.
_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help