80 likes | 193 Views
Linear Routing. Sending Message . 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))
E N D
Sending Message 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; }
SimpleCmdMsg // SimpleCmd message structure typedef struct SimpleCmdMsg { int8_t seqno; int8_t action; uint16_t source; uint8_t hop_count; union { start_sense_args ss_args; read_log_args rl_args; uint8_t untyped_args[0]; } args; } SimpleCmdMsg; typedef struct IntMsg { uint16_t val; uint16_t src; } IntMsg;
SendCmd #define ADDR_OF_MOTE 0x0001 command result_t IntOutput.output(uint16_t value) { struct SimpleCmdMsg *message = (struct SimpleCmdMsg *)data.data; if (!pending) { pending = TRUE; message->action = value; atomic { message->source = TOS_LOCAL_ADDRESS; } if (call Send.send(ADDR_OF_MOTE, sizeof(SimpleCmdMsg ), &data)) { call Leds.greenOn(); return SUCCESS; } pending = FALSE; } return FAIL; } includes SimpleCmdMsg; configuration SendCmd { provides{ interface IntOutput; interface StdControl; } } implementation { components Main, SendCmdM, GenericComm as Comm, Cdata, LedsC; IntOutput = SendCmdM; StdControl= SendCmdM; Main.StdControl -> SendCmdM; Main.StdControl -> Cdata.StdControl; SendCmdM.Leds -> LedsC; SendCmdM.Send -> Comm.SendMsg[AM_SIMPLECMDMSG]; SendCmdM.SubControl -> Comm; Cdata.IntOutput ->SendCmdM; }
CData module Cdata { provides { interface StdControl; } uses { interface IntOutput; //This Interface is Provided by //SendCmdM } } command result_t StdControl.start() { if( call IntOutput.output (some_value) ) return SUCCESS; } //Here we can also write a method which can call IntOutput.output instead of doing it in Start()
Receive Data event TOS_MsgPtr ReceiveCmdMsg.receive(TOS_MsgPtr pmsg){ TOS_MsgPtr ret = msg; result_t retval; call Leds.greenToggle(); retval = call ProcessCmd.execute(pmsg) ; post forwarder(); : : } includes SimpleCmdMsg; configuration RecvCmd { provides interface ProcessCmd; } implementation { components Main, RecvCmdM, SendCmd, GenericComm as Comm, LedsC; Main.StdControl -> RecvCmdM; Main.StdControl -> SendCmd; RecvCmdM.Leds -> LedsC; ProcessCmd = RecvCmdM.ProcessCmd; RecvCmdM.CommControl -> Comm; RecvCmdM.ReceiveCmdMsg -> Comm.ReceiveMsg[AM_SIMPLECMDMSG]; RecvCmdM.IntOutput-> SendCmd; // we are doing this as we want to // forward it to other mote. }
ProcessCmd command result_t ProcessCmd.execute(TOS_MsgPtr pmsg) { pending =1; msg = pmsg; post cmdInterpret(); return SUCCESS; } task void forwarder() { struct SimpleCmdMsg * cmd = (struct SimpleCmdMsg *) msg->data; call IntOutput.output(cmd->action+1 ); } task void cmdInterpret() { struct SimpleCmdMsg * cmd = (struct SimpleCmdMsg *) msg->data; // do local packet modifications: update the hop count and packet source cmd->source = TOS_LOCAL_ADDRESS; // Execute the command switch (cmd->action) { case 1: call Leds.yellowOn(); break; : : } signal ProcessCmd.done(msg, SUCCESS); }
How to Assign Address to a mote? mib510=/dev/com# make mica2 install.<addr> //MakeXbowLocal DEFAULT_LOCAL_GROUP=125 //remove a comment from a line based on frequency of mote CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_433BAND_CHANNEL_00 We can send data between same groups only.