[Firebug-cvs] fireboard/beta/fireworks/apps/Fireworks Fireworks.h,1.2,1.3 FireworksC.nc,1.1,1.2 Fire
Brought to you by:
doolin
From: Karthik D. <da...@us...> - 2005-07-21 06:32:20
|
Update of /cvsroot/firebug/fireboard/beta/fireworks/apps/Fireworks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23445 Modified Files: Fireworks.h FireworksC.nc FireworksM.nc Log Message: Almost finished the tinyos components for our fireworks! Things to be done are - - Complete SendDataMsg.send - Get paths set in makefile and compile - pad structures if need be to match TOS_Msg KAR. Index: FireworksC.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/fireworks/apps/Fireworks/FireworksC.nc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FireworksC.nc 21 Jul 2005 03:09:12 -0000 1.1 --- FireworksC.nc 21 Jul 2005 06:04:47 -0000 1.2 *************** *** 14,18 **** components Main , GenericComm, ! , ClockC , ADCC , CC1000RadioC --- 14,18 ---- components Main , GenericComm, ! , TimerC , ADCC , CC1000RadioC *************** *** 24,28 **** Main.StdControl -> FireworksM.StdControl; Main.StdControl -> DelugeC; ! Main.StdControl -> GenericComm.Control; Fireworks.SendPingMsg -> GenericComm.SendMsg[AM_PINGMSG]; --- 24,29 ---- Main.StdControl -> FireworksM.StdControl; Main.StdControl -> DelugeC; ! Main.StdControl -> GenericComm.Control; ! Main.StdControl -> TimerC.Control; Fireworks.SendPingMsg -> GenericComm.SendMsg[AM_PINGMSG]; *************** *** 32,35 **** Fireworks.CC1000Control -> CC1000RadioC; Fireworks.Leds -> LedsC; ! Fireworks.Clock -> ClockC; } --- 33,36 ---- Fireworks.CC1000Control -> CC1000RadioC; Fireworks.Leds -> LedsC; ! Fireworks.Timer -> TimerC.Timer[unique("Timer")]; } Index: Fireworks.h =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/fireworks/apps/Fireworks/Fireworks.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Fireworks.h 21 Jul 2005 03:08:27 -0000 1.2 --- Fireworks.h 21 Jul 2005 06:04:47 -0000 1.3 *************** *** 9,14 **** enum { AM_PINGMSG = 42, ! AM_DATAMSG = 43, ! AM_DATAREQUESTMSG = 44 }; --- 9,34 ---- enum { AM_PINGMSG = 42, ! AM_PINGREPLYMSG = 43, ! AM_DATAMSG = 44, ! AM_DATAREQUESTMSG = 45 ! }; ! ! enum { ! LOST = 0x00 ! }; ! ! /* LED count sequence. ! 1 - Red ! 2 - Green ! 4 - Yellow ! */ ! enum { ! CLEAR = 0x0, ! RCV_DR_MSG = 0x1, ! SND_P_MSG = 0x2, ! RCV_PR_MSG = 0x3, ! RCV_P_MSG = 0x4, ! SND_PR_MSG = 0x5, ! ERROR = 0x7 }; *************** *** 17,20 **** --- 37,41 ---- uint16_t source; uint16_t numNodes; + uint16_t numTrials; uint16_t numPowerLevels; uint16_t trialFrequency; *************** *** 32,33 **** --- 53,69 ---- typedef struct DataMsg DataMsg; + + struct PingMsg { + uint16_t source; + uint16_t seqno; + } ; + + typedef struct PingMsg PingMsg; + + struct PingReplyMsg { + uint16_t source; + uint16_t seqno; + uint16_t RSSI; + } ; + + typedef struct PingReplyMsg PingReplyMsg; Index: FireworksM.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/fireworks/apps/Fireworks/FireworksM.nc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FireworksM.nc 21 Jul 2005 02:30:44 -0000 1.1 --- FireworksM.nc 21 Jul 2005 06:04:47 -0000 1.2 *************** *** 13,17 **** uses interface SendMsg as SendDataMsg; uses interface ReceiveMsg as ReceiveDataRequestMsg; ! uses Clock; uses CC1000Control; uses interface Leds; --- 13,17 ---- uses interface SendMsg as SendDataMsg; uses interface ReceiveMsg as ReceiveDataRequestMsg; ! uses Timer; uses CC1000Control; uses interface Leds; *************** *** 20,34 **** implementation { ! uint16_t numTrials; ! uint16_t numNodes; ! uint16_t numPowerLevels; ! uint16_t trialFrequency; TOS_Msg msg; PingMsg *pMsg; DataMsg *dMsg; DataRequestMsg *drMsg; ! comman result_t StdControl.init() { atomic { } --- 20,64 ---- implementation { ! uint16_t nTrials; ! uint16_t nNodes; ! uint16_t nPowerLevels; ! uint16_t tFrequency; ! uint16_t seqno; ! uint8_t sendBusy; ! uint8_t taskBusy; ! uint8_t data[100][100]; ! uint16_t counter; ! uint16_t dest; TOS_Msg msg; PingMsg *pMsg; + PingReplyMsg *prMsg; DataMsg *dMsg; DataRequestMsg *drMsg; ! void blink(uint8_t seq) { ! if(seq&0x1) { ! call Leds.redOn(); ! } ! else { ! call Leds.redOff(); ! } ! ! if(seq&0x2) { ! call Leds.greenOn(); ! } ! else { ! call Leds.greenOff(); ! } ! ! if(seq&0x4) { ! call Leds.yellowOn(); ! } ! else { ! call Leds.yellowOff(); ! } ! } ! ! command result_t StdControl.init() { atomic { } *************** *** 38,61 **** command result_t StdControl.start() { ! call.Leds.redOff(); ! call Leds.greenOff(); ! call Leds.yellowOff(); ! return call Clock.setRate(TOS_I16PS, TOSS16PS); } command result_t StdControl.stop() { return SUCCESS; } event TOS_MsgPtr ReceiveDataRequestMsg.receive(TOS_MsgPtr m) { - call Leds.redToggle(); drMsg = (DataRequestMsg *) (&(m->data)); ! if( ! ! async event result_t ADC.dataReady(uint16_t rssi) { return SUCCESS; } } --- 68,222 ---- command result_t StdControl.start() { ! blink(CLEAR); ! seqno = 1; ! sendBusy = FALSE; ! taskBusy = FALSE; ! counter = 0; ! dest = 0; ! // return call Clock.setRate(TOS_I16PS, TOSS16PS); ! return SUCCESS; } command result_t StdControl.stop() { + call Timer.stop(); + return SUCCESS; + } + + event TOS_MsgPtr ReceivePingReplyMsg.receive(TOS_MsgPtr m) { + + prMsg = (PingReplyMsg *) &(m->data); + + if(TOS_LOCAL_ADDRESS == prMsg->source && seqno == prMsg->seqno) { + data[dest][counter] = prMsg->RSSI; + blink(RCV_PR_MSG); + taskBusy = FALSE; + + } + return SUCCESS; } event TOS_MsgPtr ReceiveDataRequestMsg.receive(TOS_MsgPtr m) { drMsg = (DataRequestMsg *) (&(m->data)); ! /* I am being asked to take measurements */ ! if(TOS_LOCAL_ADDRESS == drMsg->source) { ! blink(RCV_DR_MSG); ! nTrials = drMsg->numTrials; ! nNodes = drMsg->numNodes; ! nPowerLevels = drMsg->numPowerLevels; ! tFrequency = drMsg->trialFrequency; ! ! post takeMeasurements(); ! } ! } ! ! event result_t ReceivePingMsg.receive(TOS_MsgPtr m) { ! uint16_t source; ! ! if(TOS_LOCAL_ADDRESS == m->addr) { ! blink(RCV_P_MSG); ! pMsg = (PingMsg *) &(m->data); ! ! while(taskBusy); ! ! taskBusy = TRUE; ! post sendPingReply(pMsg->source, pMsg->seqno); ! } ! return SUCCESS; } + + task void sendPingReply(uint16_t src, uint16_t sq) { + prMsg = (PingReplyMsg *) &(msg.data); + + prMsg->source = src; + prMsg->seqno = sq; + + if(!sendBusy) { + sendBusy = TRUE; + if(!call SendPingReply.send(src, &msg)) { + sendBusy = FALSE; + blink(ERROR); + return; + } + else { + blink(SND_PR_MSG); + } + } + return; + } + + task void takeMeasurements() { + uint16_t trial; + /* The way we take measurements is that we ping the intended + node and he replies (if he receives the packet) with the + RSSI value. Once we send a ping, we start a timer. If the + timer expires, we assume that the node is out of range/unreachable */ + dest = 1; + for(dest=1; dest <= nNodes; dest++) { + counter = 0; + taskBusy = FALSE; + sendBusy = FALSE; + if(dest != TOS_LOCAL_ADDRESS) { + trial = 1; + while(trial <= nTrials) { + if(!taskBusy) { + trial ++; + taskBusy = TRUE; + post task sendPingMsg(dest); + } + } + } + } + + post sendData(); + } + + task void sendPingMsg(uint16_t d) { + pMsg = (PingMsg *) &(msg.data); + pMsg->source = TOS_LOCAL_ADDRESS; + pMsg->seqno = seqno++; + + if(!sendBusy) { + sendBusy = TRUE; + if(!call SendPingMsg.send(d, sizeof(PingMsg), pMsg)) { + sendBusy = FALSE; + blink(ERROR); + return; + } + else { + /* We have sent the msg. Set timer to fire after 3 seconds */ + blink(SND_P_MSG); + Timer.start(TIMER_ONE_SHOT, 3072); + counter++; + return; + } + } + + event result_t Timer.fired() { + /* This means that we have to time out, redo state and declare + this packet to have been lost */ + data[dest][counter]=LOST; + taskBusy = FALSE; + sendBusy = FALSE; + return SUCCESS; + } + + event result_t_MsgPtr SendPingMsg.sendDone(TOSMsg_Ptr m) { + sendBusy = FALSE; + return SUCCESS; + } + + event result_t_MsgPtr SendPingReplyMsg.sendDone(TOSMsg_Ptr m) { + sendBusy = FALSE; + return SUCCESS; + } + + event result_t_MsgPtr SendDataMsg.sendDone(TOSMsg_Ptr m) { + sendBusy = FALSE; + return SUCCESS; + } } |