19
TinyOS Tutorial Lesson 8 Data logging application

TinyOS Tutorial Lesson 8 Data logging application

Embed Size (px)

Citation preview

Page 1: TinyOS Tutorial Lesson 8 Data logging application

TinyOS TutorialLesson 8

Data logging application

Page 2: TinyOS Tutorial Lesson 8 Data logging application

Outline

Introduction The SenseLightToLog Application Logger component, interfaces, usage, and

limitations The Sensing interface SenseLightToLogM.nc

Page 3: TinyOS Tutorial Lesson 8 Data logging application

Introduction

SenseLightToLog

Sensor EEPROM

Page 4: TinyOS Tutorial Lesson 8 Data logging application

Introduction

SenseLightToLog

Sensor EEPROM

Page 5: TinyOS Tutorial Lesson 8 Data logging application

SenseLightToLog

SimpleCmd

START_SENSING READ_LOG

Page 6: TinyOS Tutorial Lesson 8 Data logging application

SenseLightToLog (cont.)

Logger

Main

StdControl

SenseLightToLogM

StdControl

ADCLeds

TimerC

Timer SubControl

Photo

SubControlLoggerWrite ADC

LoggerWrite

Comm

SubControl

SubControlTimer

LedsC

Leds

Sensing

Page 7: TinyOS Tutorial Lesson 8 Data logging application

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

Page 8: TinyOS Tutorial Lesson 8 Data logging application

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

Page 9: TinyOS Tutorial Lesson 8 Data logging application

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

Page 10: TinyOS Tutorial Lesson 8 Data logging application

Logging performance

high-frequency sampling

- ByteEEPROM

Page 11: TinyOS Tutorial Lesson 8 Data logging application

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 = 0head = 0currentBuffer = 0head = 7currentBuffer = 1head = 0

Page 12: TinyOS Tutorial Lesson 8 Data logging application

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; }}

Page 13: TinyOS Tutorial Lesson 8 Data logging application

SenseLightToLogM.nc(2/8)

implementation{

enum {

maxdata = 8 }; char head; uint8_t currentBuffer; int data[maxdata*2]; int *bufferPtr[2]; short nsamples;

Page 14: TinyOS Tutorial Lesson 8 Data logging application

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()); }

Page 15: TinyOS Tutorial Lesson 8 Data logging application

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;

}

Page 16: TinyOS Tutorial Lesson 8 Data logging application

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; }

Page 17: TinyOS Tutorial Lesson 8 Data logging application

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); }

Page 18: TinyOS Tutorial Lesson 8 Data logging application

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; }

Page 19: TinyOS Tutorial Lesson 8 Data logging application

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; } }