configuration Sense { // this module does not provide any interface } implementation { components Main, SenseM, LedsC, TimerC, Temp, Sounder; Main.StdControl -> SenseM; Main.StdControl -> TimerC; Main.StdControl -> Sounder; SenseM.ADC -> Temp; SenseM.ADCControl -> Temp; SenseM.SounderControl -> Sounder; SenseM.Leds -> LedsC; SenseM.Timer -> TimerC.Timer[unique("Timer")]; }Here is the content of SenseM.nc for SenseSounder application.
Main.StdControl -> SenseM;
Main.StdControl -> TimerC;
Main.StdControl -> Sounder;
SenseM.ADC -> Temp;
SenseM.ADCControl -> Temp;
SenseM.SounderControl -> Sounder;
SenseM.Leds -> LedsC;
SenseM.Timer -> TimerC.Timer[unique("Timer")];
}
The SenseM.nc for SenseSounder is as follows:
module SenseM { provides { interface StdControl; } uses { interface Timer; interface ADC; interface StdControl as ADCControl; interface StdControl as SounderControl; interface Leds; } } implementation { // declare module static variables here /** * Module scoped method. Displays the lowest 3 bits to the LEDs, * with RED being the most significant and YELLOW being the least significant. * * @return returnsSUCCESS
**/ // display is module static function result_t display(uint16_t value) { /* code to be filled in here */ return SUCCESS; } /** * Initialize the component. Initialize ADCControl, Leds * * @return returnsSUCCESS
orFAILED
**/ // implement StdControl interface command result_t StdControl.init() { if (! call SounderControl.init()) return FAIL; return rcombine(call ADCControl.init(), call Leds.init()); } /** * Start the component. Start the clock. * * @return returnsSUCCESS
orFAILED
**/ command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, ); /* fill in the number here*/ } /** * Stop the component. Stop the clock. * * @return returnsSUCCESS
orFAILED
**/ command result_t StdControl.stop() { return call Timer.stop(); } /** * Read sensor data in response to theTimer.fired
event. * * @return The result of calling ADC.getData(). **/ event result_t Timer.fired() { return call ADC.getData(); } /** * Display the upper 3 bits of sensor reading to LEDs * in response to theADC.dataReady
event. * @return Always returnsSUCCESS
**/ // ADC data ready event handler async event result_t ADC.dataReady(uint16_t data) { display(data); return SUCCESS; } }