SenseToRfm SenseToInt.Timer -> TimerC; configuration SenseToRfm { // this module does not provide any interface } implementation { components Main, SenseToInt, IntToRfm, TimerC, Photo as Sensor; Main.StdControl -> SenseToInt; Main.StdControl -> IntToRfm; SenseToInt.Timer -> TimerC.Timer[unique("Timer")]; SenseToInt.Timer -> TimerC; SenseToInt.ADC -> Sensor; SenseToInt.ADCControl -> Sensor; SenseToInt.IntOutput -> IntToRfm; Main StdControl SenseToInt TimerControl ADCControl Timer ADC IntOutput TimerC Photo IntToRfm
Nested Configuration includes IntMsg; configuration IntToRfm { provides { interface IntOutput; interface StdControl; } implementation components IntToRfmM, GenericComm as Comm; IntOutput = IntToRfmM; StdControl = IntToRfmM; IntToRfmM.Send -> Comm.SendMsg[AM_INTMSG]; IntToRfmM.SubControl -> Comm; StdControl IntOutput IntToRfmM SubControl SendMsg[AM_INTMSG]; GenericComm
IntToRfm Module command result_t StdControl.start() includes IntMsg; { return call SubControl.start(); } command result_t StdControl.stop() { return call SubControl.stop(); } command result_t IntOutput.output(uint16_t value) { ... if (call Send.send(TOS_BCAST_ADDR, sizeof(IntMsg), &data) return SUCCESS; } event result_t Send.sendDone(TOS_MsgPtr msg, result_t success) includes IntMsg; module IntToRfmM { uses { interface StdControl as SubControl; interface SendMsg as Send; } provides { interface IntOutput; interface StdControl; implementation bool pending; struct TOS_Msg data; command result_t StdControl.init() { pending = FALSE; return call SubControl.init();
The Complete Application SenseToRfm generic comm IntToRfm AMStandard RadioCRCPacket UARTnoCRCPacket packet CRCfilter noCRCPacket Timer photo MicaHighSpeedRadioM ChannelMon phototemp RadioTiming SecDedEncode byte SW SPIByteFIFO RandomLFSR ADC HW UART ClockC bit SlavePin
Sending a Message User component provide structured msg storage bool pending; struct TOS_Msg data; command result_t IntOutput.output(uint16_t value) { IntMsg *message = (IntMsg *)data.data; if (!pending) { pending = TRUE; message->val = value; message->src = TOS_LOCAL_ADDRESS; if (call Send.send(TOS_BCAST_ADDR, sizeof(IntMsg), &data)) return SUCCESS; pending = FALSE; } return FAIL; destination length Refuses to accept command if buffer is still full or network refuses to accept send command User component provide structured msg storage
Send done Event Send done event fans out to all potential senders event result_t IntOutput.sendDone(TOS_MsgPtr msg, result_t success) { if (pending && msg == &data) { pending = FALSE; signal IntOutput.outputComplete(success); } return SUCCESS; Send done event fans out to all potential senders Use the event to schedule pending communication
RfmToLeds configuration RfmToLeds { } implementation { components Main, RfmToInt, IntToLeds; Main.StdControl -> IntToLeds.StdControl; Main.StdControl -> RfmToInt.StdControl; RfmToInt.IntOutput -> IntToLeds.IntOutput; Main StdControl IntToLeds StdControl IntOutput RfmToInt
RfmtoInt configuration RfmToInt { provides interface StdControl; uses interface IntOutput; } implementation { components RfmToIntM, GenericComm; IntOutput = RfmToIntM; StdControl = RfmToIntM; RfmToIntM.ReceiveIntMsg -> GenericComm.ReceiveMsg[AM_INTMSG]; RfmToIntM.CommControl -> GenericComm; IntOutput StdControl RfmToIntM CommControl ReceiveMsg GenericComm
RfmToIntM command result_t StdControl.stop() { return call CommControl.stop(); } event TOS_MsgPtr ReceiveIntMsg.receive(TOS_MsgPtr m) { IntMsg *message = (IntMsg *)m->data; call IntOutput.output(message->val); return m; event result_t IntOutput.outputComplete(result_t success) { return SUCCESS; module RfmToIntM { provides interface StdControl; uses { interface ReceiveMsg as ReceiveIntMsg; interface IntOutput; interface StdControl as CommControl; } implementation { command result_t StdControl.init() { return call CommControl.init(); command result_t StdControl.start() { return call CommControl.start();
IntToLeds configuration IntToLeds { provides interface IntOutput; provides interface StdControl; } implementation components IntToLedsM, LedsC; IntOutput = IntToLedsM.IntOutput; StdControl = IntToLedsM.StdControl; IntToLedsM.Leds -> LedsC.Leds;
Receive Event event TOS_MsgPtr ReceiveIntMsg.receive(TOS_MsgPtr m) { IntMsg *message = (IntMsg *)m->data; call IntOutput.output(message->val); return m; } Active message automatically dispatched to associated handler knows format, no run-time parsing performs action on message event Must return free buffer to the system typically the incoming buffer if processing complete
Exercise Distributed version of Blink Timer and BlinkM on one mote LedsC on another mote When timeout occurs, the first mote should send a command to the other mote to make the LED blink.