[Firebug-cvs] fireboard/beta/fireworks/apps/MultihopLinkEstimator Makefile,NONE,1.1 MultihopLinkEsti
Brought to you by:
doolin
From: Karthik D. <da...@us...> - 2005-08-06 21:54:31
|
Update of /cvsroot/firebug/fireboard/beta/fireworks/apps/MultihopLinkEstimator In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5320 Added Files: Makefile MultihopLinkEstimator.h MultihopLinkEstimator.nc MultihopLinkEstimatorM.nc SurgeCmd.h Log Message: TinyOS components for MultihopLinkEstimator --- NEW FILE: MultihopLinkEstimator.nc --- // $Id: MultihopLinkEstimator.nc,v 1.1 2005/08/06 21:54:20 dantu Exp $ /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Copyright (c) 2002-2003 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, * 94704. Attention: Intel License Inquiry. */ /** * **/ includes MultihopLinkEstimator; includes SurgeCmd; includes MultiHop; configuration MultihopLinkEstimator { } implementation { components Main, MultihopLinkEstimatorM , TimerC , LedsC , DelugeC , DemoSensorC as Sensor , RandomLFSR , GenericComm as Comm , CC2420RadioC , LQIMultiHopRouter as multihopM ; Main.StdControl -> DelugeC; Main.StdControl -> TimerC; Main.StdControl -> Comm; Main.StdControl -> Sensor; Main.StdControl -> multihopM.StdControl; Main.StdControl -> MultihopLinkEstimatorM.StdControl; MultihopLinkEstimatorM.ADC -> Sensor; MultihopLinkEstimatorM.Timer -> TimerC.Timer[unique("Timer")]; MultihopLinkEstimatorM.LinkTimer -> TimerC.Timer[unique("Timer")]; MultihopLinkEstimatorM.Leds -> LedsC; // NoLeds; MultihopLinkEstimatorM.Random -> RandomLFSR; MultihopLinkEstimatorM.CC2420Control -> CC2420RadioC.CC2420Control; MultihopLinkEstimatorM.MacControl -> CC2420RadioC.MacControl; MultihopLinkEstimatorM.RouteControl -> multihopM; MultihopLinkEstimatorM.Send -> multihopM.Send[AM_SURGEMSG]; multihopM.ReceiveMsg[AM_SURGEMSG] -> Comm.ReceiveMsg[AM_SURGEMSG]; /* Additions for Link Estimation */ multihopM.ReceiveMsg[AM_LEMSG] -> Comm.ReceiveMsg[AM_LEMSG]; MultihopLinkEstimatorM.SendLinkEstimate -> multihopM.Send[AM_LEMSG]; MultihopLinkEstimatorM.ReceivePing -> Comm.ReceiveMsg[AM_PINGMSG]; MultihopLinkEstimatorM.SendPing -> Comm.SendMsg[AM_PINGMSG]; } --- NEW FILE: SurgeCmd.h --- // $Id: SurgeCmd.h,v 1.1 2005/08/06 21:54:20 dantu Exp $ /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Copyright (c) 2002-2003 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, * 94704. Attention: Intel License Inquiry. */ typedef struct SurgeCmdMsg { uint16_t type; union { // FOR SURGE_TYPE_SETRATE uint32_t newrate; // FOR SURGE_TYPE_FOCUS uint16_t focusaddr; } args; } SurgeCmdMsg; enum { AM_SURGECMDMSG = 18 }; --- NEW FILE: MultihopLinkEstimatorM.nc --- // $Id: MultihopLinkEstimatorM.nc,v 1.1 2005/08/06 21:54:20 dantu Exp $ /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Copyright (c) 2002-2003 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, * 94704. Attention: Intel License Inquiry. */ includes MultihopLinkEstimator; includes SurgeCmd; /* * Data gather application */ module MultihopLinkEstimatorM { provides { interface StdControl; } uses { interface ADC; interface Timer; interface Timer as LinkTimer; interface Leds; interface CC2420Control; interface MacControl; interface Send; interface RouteControl; interface Random; /* Addition for link estimation */ interface SendMsg as SendPing; interface Send as SendLinkEstimate; interface ReceiveMsg as ReceivePing; } } implementation { enum { TIMER_GETADC_COUNT = 1, // Timer ticks for ADC TIMER_CHIRP_COUNT = 10, // Timer on/off chirp count }; bool sleeping; // application command state bool focused; bool rebroadcast_adc_packet; TOS_Msg gMsgBuffer; norace uint16_t gSensorData; // protected by gfSendBusy flag uint32_t seqno; bool initTimer; bool gfSendBusy; int timer_rate; int timer_ticks; /* Additional global data for link estimation */ TOS_Msg pMsg; TOS_Msg leMsg; bool leSendBusy; bool pSendBusy; uint32_t pseqno; uint32_t leseqno; /*********************************************************************** * Initialization ***********************************************************************/ static void initialize() { timer_rate = INITIAL_TIMER_RATE; atomic gfSendBusy = FALSE; sleeping = FALSE; seqno = 0; initTimer = TRUE; rebroadcast_adc_packet = FALSE; focused = FALSE; /* Initialize link estimation data */ atomic pSendBusy = FALSE; atomic leSendBusy = FALSE; leseqno = 0; pseqno = 0; } task void SendData() { SurgeMsg *pReading; uint16_t Len; dbg(DBG_USR1, "MultihopLinkEstimatorM: Sending sensor reading\n"); if ((pReading = (SurgeMsg *)call Send.getBuffer(&gMsgBuffer,&Len)) != NULL) { pReading->type = SURGE_TYPE_SENSORREADING; pReading->parentaddr = call RouteControl.getParent(); pReading->reading = gSensorData; pReading->seq_no = seqno++; if ((call Send.send(&gMsgBuffer,sizeof(SurgeMsg))) != SUCCESS) atomic gfSendBusy = FALSE; } } task void sendPing() { PingMsg *pingMsg; uint16_t len; if((pingMsg = call Send.getBuffer(&pMsg, &len)) != NULL) { /* Build the ping packet */ pingMsg->seqno = ++pseqno; pingMsg->source = TOS_LOCAL_ADDRESS; #ifdef MHOP_LEDS call Leds.redOn(); #endif pSendBusy = TRUE; if(call SendPing.send(TOS_BCAST_ADDR, sizeof(PingMsg), &pMsg) != SUCCESS) { pSendBusy = FALSE; } } } task void sendLinkEstimate() { uint16_t len; if(call Send.getBuffer(&leMsg, &len) != NULL) { #ifdef MHOP_LEDS call Leds.yellowOn(); #endif leSendBusy = TRUE; if((call SendLinkEstimate.send(&leMsg, sizeof(LinkEstimatorMsg))) != SUCCESS) { leSendBusy = FALSE; } } } command result_t StdControl.init() { initialize(); return SUCCESS; } command result_t StdControl.start() { uint16_t randomtimer; call CC2420Control.SetRFPower(15); call MacControl.enableAck(); randomtimer = (call Random.rand() & 0xffff) + 1; call LinkTimer.start(TIMER_ONE_SHOT, randomtimer); randomtimer = (call Random.rand() & 0xfff) + 1; return call Timer.start(TIMER_ONE_SHOT, randomtimer); } command result_t StdControl.stop() { return call Timer.stop(); } /*********************************************************************** * Commands and events ***********************************************************************/ event result_t Timer.fired() { if (initTimer) { initTimer = FALSE; return call Timer.start(TIMER_REPEAT, timer_rate); } dbg(DBG_USR1, "MultihopLinkEstimatorM: Timer fired\n"); timer_ticks++; if (timer_ticks % TIMER_GETADC_COUNT == 0) { call ADC.getData(); } return SUCCESS; } event result_t LinkTimer.fired() { uint16_t rtimer; post sendPing(); /* Choose a random number between (1-4096)ms and add it to 10000. Basically, choose a random number between 10000-14096*/ rtimer = (call Random.rand() & 0x1fff) + 0x2710; call Timer.start(TIMER_ONE_SHOT, rtimer); return SUCCESS; } async event result_t ADC.dataReady(uint16_t data) { //SurgeMsg *pReading; //uint16_t Len; dbg(DBG_USR1, "MultihopLinkEstimatorM: Got ADC reading: 0x%x\n", data); atomic { if (!gfSendBusy) { gfSendBusy = TRUE; gSensorData = data; post SendData(); } } return SUCCESS; } /* Receive Ping Msg routine for LinkEstimation */ event TOS_MsgPtr ReceivePing.receive(TOS_MsgPtr m) { PingMsg *pingMsg = (PingMsg *) &(m->data); #ifdef MHOP_LEDS call Leds.greenToggle(); #endif /* Build the LinkEstimatorMsg */ atomic { LinkEstimatorMsg *le = (LinkEstimatorMsg *) &(leMsg.data); le->seqno = ++leseqno; le->source = pingMsg->source; le->dest = TOS_LOCAL_ADDRESS; le->RSSI = m->strength; le->LQI = m->lqi; le->source_seqno = pingMsg->seqno; post sendLinkEstimate(); } return m; } event result_t Send.sendDone(TOS_MsgPtr m, result_t success) { dbg(DBG_USR2, "MultihopLinkEstimatorM: output complete 0x%x\n", success); atomic gfSendBusy = FALSE; return SUCCESS; } event result_t SendPing.sendDone(TOS_MsgPtr m, result_t success) { dbg(DBG_USR2, "MultihopLinkEstimatorM: sent ping 0x%x\n", success); #ifdef MHOP_LEDS call Leds.redOff(); #endif atomic pSendBusy = FALSE; return SUCCESS; } event result_t SendLinkEstimate.sendDone(TOS_MsgPtr m, result_t success) { dbg(DBG_USR2, "MultihopLinkEstimatorM: sent ping 0x%x\n", success); #ifdef MHOP_LEDS call Leds.yellowOff(); #endif atomic leSendBusy = FALSE; return SUCCESS; } } --- NEW FILE: Makefile --- PFLAGS= -I%T/lib/MultiHopLQI -DSEND_QUEUE_SIZE=8 -DMHOP_LEDS PLATFORMS=telos telosa telosb tmote TINYOS_NP ?= BNP COMPONENT=MultihopLinkEstimator include ${TOSROOT}/tools/make/Makerules --- NEW FILE: MultihopLinkEstimator.h --- // $Id: MultihopLinkEstimator.h,v 1.1 2005/08/06 21:54:20 dantu Exp $ /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Copyright (c) 2002-2003 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, * 94704. Attention: Intel License Inquiry. */ /* Surge modified as MultihopLinkEstimator */ int INITIAL_TIMER_RATE = 2048; int FOCUS_TIMER_RATE = 1000; int FOCUS_NOTME_TIMER_RATE = 1000; enum { SURGE_TYPE_SENSORREADING = 0, SURGE_TYPE_ROOTBEACON = 1, SURGE_TYPE_SETRATE = 2, SURGE_TYPE_SLEEP = 3, SURGE_TYPE_WAKEUP = 4, SURGE_TYPE_FOCUS = 5, SURGE_TYPE_UNFOCUS = 6 }; typedef struct LinkEstimatorMsg { uint32_t seqno; uint16_t source; uint16_t dest; uint16_t RSSI; uint16_t LQI; uint32_t source_seqno; } LinkEstimatorMsg; typedef struct PingMsg { uint32_t seqno; uint16_t source; } PingMsg; typedef struct SurgeMsg { uint16_t type; uint16_t reading; uint16_t parentaddr; uint32_t seq_no; } SurgeMsg; enum { AM_SURGEMSG = 17, AM_LEMSG = 18, AM_PINGMSG = 19 }; |