Upload
ellen-butler
View
215
Download
0
Embed Size (px)
Citation preview
TinyOS TutorialLesson 8
Data logging application
Outline
Introduction The SenseLightToLog Application Logger component, interfaces, usage, and
limitations The Sensing interface SenseLightToLogM.nc
Introduction
SenseLightToLog
Sensor EEPROM
Introduction
SenseLightToLog
Sensor EEPROM
SenseLightToLog
SimpleCmd
START_SENSING READ_LOG
SenseLightToLog (cont.)
Logger
Main
StdControl
SenseLightToLogM
StdControl
ADCLeds
TimerC
Timer SubControl
Photo
SubControlLoggerWrite ADC
LoggerWrite
Comm
SubControl
SubControlTimer
LedsC
Leds
Sensing
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
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
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
Logging performance
high-frequency sampling
- ByteEEPROM
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
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; }}
SenseLightToLogM.nc(2/8)
implementation{
enum {
maxdata = 8 }; char head; uint8_t currentBuffer; int data[maxdata*2]; int *bufferPtr[2]; short nsamples;
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()); }
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;
}
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; }
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); }
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; }
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; } }