From d199b394f37c001ea8085aa6580bfb315e6557cb Mon Sep 17 00:00:00 2001 From: gtolle Date: Sat, 14 Apr 2007 00:31:29 +0000 Subject: [PATCH] Added a StdControl interface, and a top-level DisseminationC component. Added a set() command to the DisseminationValue interface that changes the locally stored value w/o disseminating it. --- tos/lib/net/DisseminationC.nc | 52 +++++++++++++++++++++++ tos/lib/net/DisseminationCache.nc | 3 +- tos/lib/net/DisseminationEngineImplP.nc | 56 ++++++++++++++++++------- tos/lib/net/DisseminationEngineP.nc | 11 +++-- tos/lib/net/DisseminationValue.nc | 9 ++++ tos/lib/net/DisseminatorC.nc | 4 +- tos/lib/net/DisseminatorP.nc | 21 ++++++++-- 7 files changed, 129 insertions(+), 27 deletions(-) create mode 100644 tos/lib/net/DisseminationC.nc diff --git a/tos/lib/net/DisseminationC.nc b/tos/lib/net/DisseminationC.nc new file mode 100644 index 00000000..1fb00403 --- /dev/null +++ b/tos/lib/net/DisseminationC.nc @@ -0,0 +1,52 @@ +#include + +/* + * Copyright (c) 2006 Arch Rock Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Arch Rock Corporation nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE + * + */ + +/** + * The DisseminationC component is the top-level interface to the + * dissemination protocol. StdControl controls all of the trickle + * timers used for all of the keys. + * + * See TEP118 - Dissemination for details. + * + * @author Gilman Tolle + * @version $Revision$ + */ + +configuration DisseminationC { + provides interface StdControl; +} +implementation { + components DisseminationEngineP; + StdControl = DisseminationEngineP; +} diff --git a/tos/lib/net/DisseminationCache.nc b/tos/lib/net/DisseminationCache.nc index 1c797d5e..290c7d1d 100644 --- a/tos/lib/net/DisseminationCache.nc +++ b/tos/lib/net/DisseminationCache.nc @@ -42,7 +42,8 @@ */ interface DisseminationCache { - event void init(); + event error_t start(); + event error_t stop(); command void* requestData( uint8_t* size ); command void storeData( void* data, uint8_t size, uint32_t seqno ); command uint32_t requestSeqno(); diff --git a/tos/lib/net/DisseminationEngineImplP.nc b/tos/lib/net/DisseminationEngineImplP.nc index 4bdd4a11..6ee3e366 100644 --- a/tos/lib/net/DisseminationEngineImplP.nc +++ b/tos/lib/net/DisseminationEngineImplP.nc @@ -43,11 +43,12 @@ */ module DisseminationEngineImplP { + provides interface StdControl; + uses { - interface Boot; - interface SplitControl as RadioControl; interface DisseminationCache[uint16_t key]; interface TrickleTimer[uint16_t key]; + interface StdControl as DisseminatorControl[uint16_t id]; interface AMSend; interface Receive; @@ -60,35 +61,55 @@ module DisseminationEngineImplP { } implementation { + enum { NUM_DISSEMINATORS = uniqueCount("DisseminationTimerC.TrickleTimer") }; + message_t m_buf; - bool m_bufBusy = TRUE; + bool m_running; + bool m_bufBusy; void sendProbe( uint16_t key ); void sendObject( uint16_t key ); - event void Boot.booted() { - call RadioControl.start(); + command error_t StdControl.start() { + uint8_t i; + for ( i = 0; i < NUM_DISSEMINATORS; i++ ) { + call DisseminatorControl.start[ i ](); + } + m_running = TRUE; + return SUCCESS; } - event void RadioControl.startDone( error_t err ) { - m_bufBusy = FALSE; + command error_t StdControl.stop() { + uint8_t i; + for ( i = 0; i < NUM_DISSEMINATORS; i++ ) { + call DisseminatorControl.stop[ i ](); + } + m_running = FALSE; + return SUCCESS; } - event void RadioControl.stopDone( error_t err ) {} - event void DisseminationCache.init[ uint16_t key ]() { - call TrickleTimer.start[ key ](); + event error_t DisseminationCache.start[ uint16_t key ]() { + error_t result = call TrickleTimer.start[ key ](); call TrickleTimer.reset[ key ](); + return result; + } + + event error_t DisseminationCache.stop[ uint16_t key ]() { + call TrickleTimer.stop[ key ](); + return SUCCESS; } event void DisseminationCache.newData[ uint16_t key ]() { + + if ( !m_running || m_bufBusy ) { return; } + sendObject( key ); call TrickleTimer.reset[ key ](); } event void TrickleTimer.fired[ uint16_t key ]() { - - if ( m_bufBusy ) { return; } + if ( !m_running || m_bufBusy ) { return; } sendObject( key ); } @@ -148,6 +169,8 @@ implementation { uint32_t incomingSeqno = dMsg->seqno; uint32_t currentSeqno = call DisseminationCache.requestSeqno[ key ](); + if ( !m_running ) { return msg; } + if ( currentSeqno == DISSEMINATION_SEQNO_UNKNOWN && incomingSeqno != DISSEMINATION_SEQNO_UNKNOWN ) { @@ -198,6 +221,8 @@ implementation { dissemination_probe_message_t* dpMsg = (dissemination_probe_message_t*) payload; + if ( !m_running ) { return msg; } + if ( call DisseminationCache.requestSeqno[ dpMsg->key ]() != DISSEMINATION_SEQNO_UNKNOWN ) { sendObject( dpMsg->key ); @@ -215,13 +240,16 @@ implementation { uint32_t seqno ) {} default command uint32_t - DisseminationCache.requestSeqno[uint16_t key]() { return 0; } + DisseminationCache.requestSeqno[uint16_t key]() { return DISSEMINATION_SEQNO_UNKNOWN; } - default command error_t TrickleTimer.start[uint16_t key]() { return SUCCESS; } + default command error_t TrickleTimer.start[uint16_t key]() { return FAIL; } default command void TrickleTimer.stop[uint16_t key]() { } default command void TrickleTimer.reset[uint16_t key]() { } default command void TrickleTimer.incrementCounter[uint16_t key]() { } + + default command error_t DisseminatorControl.start[uint16_t id]() { return FAIL; } + default command error_t DisseminatorControl.stop[uint16_t id]() { return FAIL; } } diff --git a/tos/lib/net/DisseminationEngineP.nc b/tos/lib/net/DisseminationEngineP.nc index 0314fc5d..f507a71c 100644 --- a/tos/lib/net/DisseminationEngineP.nc +++ b/tos/lib/net/DisseminationEngineP.nc @@ -45,21 +45,20 @@ */ configuration DisseminationEngineP { + provides interface StdControl; + uses { interface DisseminationCache[uint16_t key]; interface TrickleTimer[uint16_t key]; + interface StdControl as DisseminatorControl[uint16_t id]; } } implementation { components DisseminationEngineImplP; + StdControl = DisseminationEngineImplP; DisseminationCache = DisseminationEngineImplP; TrickleTimer = DisseminationEngineImplP; - - components MainC; - DisseminationEngineImplP.Boot -> MainC; - - components ActiveMessageC; - DisseminationEngineImplP.RadioControl -> ActiveMessageC; + DisseminatorControl = DisseminationEngineImplP; components new AMSenderC(AM_DISSEMINATION_MESSAGE) as DisseminationSendC; DisseminationEngineImplP.AMSend -> DisseminationSendC.AMSend; diff --git a/tos/lib/net/DisseminationValue.nc b/tos/lib/net/DisseminationValue.nc index 854d9ad1..27a5da46 100644 --- a/tos/lib/net/DisseminationValue.nc +++ b/tos/lib/net/DisseminationValue.nc @@ -46,6 +46,15 @@ interface DisseminationValue { */ command const t* get(); + /** + * Set the variable to a new value. The provider of this interface + * will copy the value from the pointer. NOTE: This command does + * not cause the new value to begin disseminating. It is intended to + * be used for setting default values. + */ + + command void set( const t* ); + /** * Signalled whenever variable may have changed. */ diff --git a/tos/lib/net/DisseminatorC.nc b/tos/lib/net/DisseminatorC.nc index 62783f69..3890a96d 100644 --- a/tos/lib/net/DisseminatorC.nc +++ b/tos/lib/net/DisseminatorC.nc @@ -59,11 +59,9 @@ implementation { DisseminationValue = DisseminatorP; DisseminationUpdate = DisseminatorP; - components MainC; - DisseminatorP.Boot -> MainC; - components DisseminationEngineP; DisseminationEngineP.DisseminationCache[key] -> DisseminatorP; + DisseminationEngineP.DisseminatorControl[TIMER_ID] -> DisseminatorP; components DisseminationTimerP; DisseminationEngineP.TrickleTimer[key] -> diff --git a/tos/lib/net/DisseminatorP.nc b/tos/lib/net/DisseminatorP.nc index 9b303175..1a628044 100644 --- a/tos/lib/net/DisseminatorP.nc +++ b/tos/lib/net/DisseminatorP.nc @@ -43,29 +43,44 @@ */ generic module DisseminatorP(typedef t) { + provides interface StdControl; + provides interface DisseminationValue; provides interface DisseminationUpdate; provides interface DisseminationCache; - uses interface Boot; uses interface Leds; } implementation { t valueCache; + bool m_running; // A sequence number is 32 bits. The top 16 bits are an incrementing // counter, while the bottom 16 bits are a unique node identifier. uint32_t seqno = DISSEMINATION_SEQNO_UNKNOWN; - event void Boot.booted() { - signal DisseminationCache.init(); + command error_t StdControl.start() { + error_t result = signal DisseminationCache.start(); + if ( result == SUCCESS ) { m_running = TRUE; } + return result; + } + + command error_t StdControl.stop() { + if ( !m_running ) { return EOFF; } + m_running = FALSE; + return signal DisseminationCache.stop(); } command const t* DisseminationValue.get() { return &valueCache; } + command void DisseminationValue.set( const t* val ) { + valueCache = *val; + } + command void DisseminationUpdate.change( t* newVal ) { + if ( !m_running ) { return; } memcpy( &valueCache, newVal, sizeof(t) ); /* Increment the counter and append the local node ID. */ seqno = seqno >> 16; -- 2.39.2