Presentation is loading. Please wait.

Presentation is loading. Please wait.

TinyOS Tutorial Lesson 8 Data logging application.

Similar presentations


Presentation on theme: "TinyOS Tutorial Lesson 8 Data logging application."— Presentation transcript:

1 TinyOS Tutorial Lesson 8 Data logging application

2 Outline Introduction The SenseLightToLog Application Logger component, interfaces, usage, and limitations The Sensing interface SenseLightToLogM.nc

3 Introduction SenseLightToLog Sensor EEPROM

4 Introduction SenseLightToLog Sensor EEPROM

5 SenseLightToLog SimpleCmd START_SENSINGREAD_LOG

6 SenseLightToLog (cont.) Logger Main StdControl SenseLightToLogM StdControl ADC Leds TimerC Timer SubControl Photo SubControl LoggerWriteADC LoggerWrite Comm SubControl Timer LedsC Leds Sensing

7 Logger About the EEPROM on Mica/Mica/Mica2Dot:  512 kbyte  may be read and written in 16-byte blocks, called lines  split-phase operations treating the EEPROM as a circular buffer - by maintaining an internal pointer to the next EEPROM line does not read or write data at the beginning of the EEPROM

8 Logger - LoggerRead readNext(buffer) - Read the next line from the log read(line, buffer) - Read an arbitrary line from the log resetPointer() - Set the current line pointer to the beginning of the log setPointer(line) - Set the current line pointer to the given line

9 Logger - LoggerWrite append(buffer) - Append data to the log write(line, buffer) - Write data to the log at the given line resetPointer() - Set the current line pointer to the beginning of the log setPointer(line) - Set the current line pointer to the given line

10 Logging performance high-frequency sampling - ByteEEPROM

11 SenseLightToLogM 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 data[ maxdata * 2 ] (maxdata = 8) head bufferPtr[0] bufferPtr[1] buffer0 buffer1 currentBuffer = 0 head = 0 currentBuffer = 0 head = 7 currentBuffer = 1 head = 0

12 SenseLightToLogM.nc(1/8) module SenseLightToLogM { provides interface StdControl; provides interface Sensing; uses { interface ADC; interface StdControl as SubControl; interface Leds; interface Timer as Timer; interface LoggerWrite; interface ProcessCmd as CmdExecute; }

13 SenseLightToLogM.nc(2/8) implementation { enum { maxdata = 8 }; char head; uint8_t currentBuffer; int data[maxdata*2]; int *bufferPtr[2]; short nsamples;

14 SenseLightToLogM.nc(3/8) command result_t StdControl.init() { atomic { head = 0; currentBuffer = 0; bufferPtr[0] = &(data[0]); bufferPtr[1] = &(data[8]); } return rcombine(call SubControl.init(), call Leds.init()); }

15 SenseLightToLogM.nc(4/8) command result_t StdControl.start() { return call SubControl.start(); } command result_t StdControl.stop() { return call SubControl.stop(); } command result_t Sensing.start(int samples, int interval_ms) { nsamples = samples; call Timer.start(TIMER_REPEAT, interval_ms); return SUCCESS; }

16 SenseLightToLogM.nc(5/8) event result_t Timer.fired() { nsamples--; if (nsamples== 0) { call Timer.stop(); signal Sensing.done(); } call Leds.redToggle(); call ADC.getData(); return SUCCESS; }

17 SenseLightToLogM.nc(6/8) default event result_t Sensing.done() { return SUCCESS; } task void writeTask() { char* ptr; atomic { ptr = (char*)bufferPtr[currentBuffer]; currentBuffer ^= 0x01; } call LoggerWrite.append(ptr); }

18 SenseLightToLogM.nc(7/8) async event result_t ADC.dataReady(uint16_t this_data){ atomic { int p = head; bufferPtr[currentBuffer][p] = this_data; head = (p+1); if (head == maxdata) head = 0; if (head == 0) { post writeTask(); } return SUCCESS; }

19 SenseLightToLogM.nc(8/8) event result_t LoggerWrite.writeDone( result_t status ) { //if (status) call Leds.yellowOn(); return SUCCESS; } event result_t CmdExecute.done(TOS_MsgPtr pmsg, result_t status ) { return SUCCESS; }


Download ppt "TinyOS Tutorial Lesson 8 Data logging application."

Similar presentations


Ads by Google