sown code review

26
SOWN Code Review Top-level Control

Upload: kanan

Post on 08-Feb-2016

30 views

Category:

Documents


2 download

DESCRIPTION

SOWN Code Review. Top-level Control. SOWN Configuration. SOWN.nc and MainControlC.nc specify wiring of components. SOWN. Main. MainControlC. BackboneC. TripWireM. TimeSyncC. RoutingC. SD. etc. MainControlC Wiring Details. SOWN Files. Makefile SOWN.nc SOWN configuration definition - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: SOWN Code Review

SOWN Code Review

Top-level Control

Page 2: SOWN Code Review

SOWN Configuration

• SOWN.nc and MainControlC.nc specify wiring of components

SOWN

MainControlC

RoutingC

TripWireM

etc.

Main

TimeSyncC

SD

BackboneC

Page 3: SOWN Code Review

MainControlC Wiring Details

Page 4: SOWN Code Review

SOWN Files• Makefile• SOWN.nc

– SOWN configuration definition• MainControl.h

– System states• MainControl.nc

– Interface definition• MainControlC.nc

– Wiring of components• MainControlM.nc

– Implementation of top-level state-machine

Page 5: SOWN Code Review

MainControl.h/* legitimate system phases/states */enum { STATE_CHAOS, STATE_INIT, STATE_SYSSYNC, STATE_LOCALIZE, STATE_DISCNEIGHBORS, STATE_BUILDBACKBONE, STATE_COMMITBACKBONE, STATE_SENTRYSEL, STATE_STATUS_REPORT, STATE_PM, STATE_TRACKING_PM,} NETWORK_STATES;

Page 6: SOWN Code Review

MainControl.ncinterface MainControl {

command result_t start();command result_t stop();command result_t setParameters (phaseDelay, PM_COUNT, SendPowerForSentrySelection, reportPeriod); command bool isSentry();command result_t getMySentry(*id);

command result_t getSentries(*sentries, *num_sentries);command result_t getNonsentries(*nonsentries_ptr, *num_nonsentries); event result_t ready (bool isReady);command result_t getNetworkStatus();

}

Delegated to SentrySelC

Returns SUCCESS

Not used / Unimplemented

Page 7: SOWN Code Review

MainControlC.nc

• Uses components:– MainControlM, BackboneC, ReportC, TimeSyncC, SD,

TripWireM, TimeUtilC, TimerC, SentryPmC, SentrySelC, RandomLFSR, LedsC, ResetC, LocalC, TrackingC, GenericBaseRecvC, RoutingC, ConfigureC, DebugC, GenericComm, RadioResetC, RadioModelC, XTestXnpM, XnpC, CC1000ControlM

• Wiring as shown previously

Page 8: SOWN Code Review

MainControlM.nc Datauint8_t state;

uint8_t phase_bits;bool DynamicSettingDone;bool GlobalTimeDone;

uint32_t round_start_time;uint16_t roundCount = 0;

uint8_t sending_power_for_sensing_radius;

uint32_t PHASE_DELAY;uint32_t REPORT_PERIOD;uint16_t PM_PHASE_COUNT;uint8_t SENTRY_SEND_POWER; uint32_t SYNC_DELAY;

State of network

Progress flags

Select phases to skip

Round start and counter

For sentry selection

Parameters sent by GUI

Page 9: SOWN Code Review

MainControlM.nc Functionscommand result_t StdControl.init()command result_t StdControl.start() command result_t StdControl.stop()

command result_t MainControl.start()event result_t Configure.SettingsReady(...)command result_t MainControl.setParameters(...)event result_t SysSync.GlobalTimeReady()event result_t PhaseTransitionTimer.fired()event uint8_t Backbone.GenericReceive(...)

event result_t PM.wakeup()event result_t PM.sleep()

NOP

Only called locally

Page 10: SOWN Code Review

Initialization

• StdControl.init()– Initialize Leds, Random, SysSyncControl, SDControl– Initialize module data

• StdControl.start()– Call Debug.start(), MainControl.start()

• MainControl.start()– Set STATE_CHAOS, radio power– Start 5s timer

Page 11: SOWN Code Review

MainControlM State Diagram

Page 12: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_CHAOS:roundCount++call Configure.start()

Page 13: SOWN Code Review

Configure.SettingsReady()// only do the following onceDynamicSettingDone = TRUE;state = STATE_INIT;post ReportTask();ResetNodeStatus();

stop sub-component timersinitParameters(settings);

save and push settings down to components call PhaseTransitionTimer.start (TIMER_ONE_SHOT,1000 +

call Random.rand()%1000);

Page 14: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_INIT:call Configure.stop();EnableSync();

sets master/slave for time synccall SysSyncControl.start();

Page 15: SOWN Code Review

SysSync.GlobalTimeReady()

GlobalTimeDone = TRUE;state = STATE_SYSSYNC;post ReportTask();get global time and compute delay until round start

(6 * GridX + 5s)call PhaseTransitionTimer.start2 (TIMER_ONE_SHOT,

round_start_time - now );

Page 16: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_SYSSYNC:state = STATE_LOCALIZE;post ReportTask();call SysSyncControl.stop();call Local.start( PHASE_DELAY>>2);call PhaseTransitionTimer.start (TIMER_ONE_SHOT,

PHASE_DELAY);

if (!call TripWire.isTripWireBase())call RoutingControl.init();

Page 17: SOWN Code Review

PhaseTransitionTimer.fired() • STATE_LOCALIZE:

call Local.stop();if (localized)

state = STATE_DISCNEIGHBORS;post ReportTask();call SDControl.start();call PhaseTransitionTimer.start (TIMER_ONE_SHOT, 2*PHASE_DELAY);

elsestate = CHAOS;call RoutingControl.init();call PhaseTransitionTimer.start (TIMER_ONE_SHOT, 5000);

Page 18: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_DISCNEIGHBORS:state = STATE_BUILDBACKBONE;post ReportTask();call SDControl.stop();if (call TripWire.isTripWireBase())

call SentrySel.setSentry(TRUE);call Backbone.build(BRODCAST_PERIOD);

call PhaseTransitionTimer.start (TIMER_ONE_SHOT, PHASE_DELAY);

Page 19: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_BUILDBACKBONE:state = STATE_COMMITBACKBONE;post ReportTask();call Backbone.commit();

call PhaseTransitionTimer.start (TIMER_ONE_SHOT, SHORT_PHASE_DELAY);

Page 20: SOWN Code Review

PhaseTransitionTimer.fired() • STATE_COMMITBACKBONE:

state = STATE_SENTRYSEL;post ReportTask();call Backbone.stop();call SDNeighborTable.free();call SentrySel.reset();set non-leaves to be sentriesif (!call TripWire.isTripWireBase())

call SentrySel.startSelection(sending_power..., PHASE_DELAY)

call PhaseTransitionTimer.start (TIMER_ONE_SHOT, PHASE_DELAY);

Page 21: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_SENTRYSEL:state = STATE_STATUS_REPORT;post ReportTask();call SentrySel.stopSelection();call Report.startReport(REPORT_PERIOD);

call PhaseTransitionTimer.start (TIMER_ONE_SHOT, 2 *

PHASE_DELAY);

Page 22: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_STATUS_REPORT:state = STATE_PM;post ReportTask();call Report.stopReport();call PM.enable(); call WakeupCom.EnablePowerM(TRUE);

call PhaseTransitionTimer.start (TIMER_ONE_SHOT, SHORT_PHASE_DELAY);

Page 23: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_STATUS_PM:state = STATE_TRACKING_PM;post ReportTask();call Tracking.init();call Tracking.start();

call PhaseTransitionTimer.start (TIMER_ONE_SHOT, PHASE_DELAY *

PM_PHASE_COUNT);

Page 24: SOWN Code Review

PhaseTransitionTimer.fired()

• STATE_STATUS_TRACKING_PM:state = STATE_CHAOS;post ReportTask();if (!call TripWire.isTripWireBase())

Reset.reset();else

call PhaseTransitionTimer.start (TIMER_ONE_SHOT, SHORT_PHASE_DELAY);

ResetNodeStatus();

Page 25: SOWN Code Review

task ReportTask

call Leds.set(state)call Report.ReportNetworkStatus(state);

Page 26: SOWN Code Review

MainControlM State Diagram