260 likes | 351 Views
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
E N D
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.
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
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;
Returns SUCCESS Not used / Unimplemented MainControl.nc interface 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
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
Select phases to skip Parameters sent by GUI MainControlM.nc Data uint8_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 Round start and counter For sentry selection
Only called locally MainControlM.nc Functions command 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
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
PhaseTransitionTimer.fired() • STATE_CHAOS: roundCount++ call Configure.start()
Configure.SettingsReady() // only do the following once DynamicSettingDone = TRUE; state = STATE_INIT; post ReportTask(); ResetNodeStatus(); stop sub-component timers initParameters(settings); save and push settings down to components call PhaseTransitionTimer.start (TIMER_ONE_SHOT,1000 + call Random.rand()%1000);
PhaseTransitionTimer.fired() • STATE_INIT: call Configure.stop(); EnableSync(); sets master/slave for time sync call SysSyncControl.start();
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 );
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();
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); else state = CHAOS; call RoutingControl.init(); call PhaseTransitionTimer.start (TIMER_ONE_SHOT, 5000);
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);
PhaseTransitionTimer.fired() • STATE_BUILDBACKBONE: state = STATE_COMMITBACKBONE; post ReportTask(); call Backbone.commit(); call PhaseTransitionTimer.start (TIMER_ONE_SHOT, SHORT_PHASE_DELAY);
PhaseTransitionTimer.fired() • STATE_COMMITBACKBONE: state = STATE_SENTRYSEL; post ReportTask(); call Backbone.stop(); call SDNeighborTable.free(); call SentrySel.reset(); set non-leaves to be sentries if (!call TripWire.isTripWireBase()) call SentrySel.startSelection(sending_power..., PHASE_DELAY) call PhaseTransitionTimer.start (TIMER_ONE_SHOT, PHASE_DELAY);
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);
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);
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);
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();
task ReportTask call Leds.set(state) call Report.ReportNetworkStatus(state);