Hello everyone,
I'm trying to use TinyOS 2.1.1 (on Ubuntu 9.10) and Micaz motes to develop
and application which would ideally
1 - Sample a sensor (Accelerometer, in this case) for a specified duration
of time.
2 - Store readings to the log (the Micaz flash chip) concurrently.
3 - After the specified duration of time, read data from the log and
transmit this data in the form of messages (configured to transmit to serial
port here).
While the sampling of the accelerometer does take place, as can be seen from
the readings (displayed using MsgReader) in the first few messages, the
first message received is the (0x8)th. It then skips messages arbitrarily
(to my novice programming mind, anyway) before finally settling at the
(0x3b)th message. It then keeps receiving what looks like the message 0x3b
over and over and over again. Could anybody shed some light on this; why do
the messages get skipped?
Also, I've programmed so that the sampling mode should begin once the end of
the log is reached (by checking to see if the 'length' argument in
LogRead.readDone() is == 0). This does not happen either. It does not loop
back to the sampling mode (I think that I've tested up to message 0x6xxx ).
Can somebody see anything that indicates why?
Thanks in advance.
Kushal
My code and output have been attached for your perusal:
*Code*
*
*
module VoltageMonitorStreamC @safe(){
uses {
interface Leds;
interface Boot;
interface AMSend;
interface Timer<TMilli> as Timer0;
interface Timer<TMilli> as Timer1;
interface Packet;
interface ReadStream<uint16_t>;
interface SplitControl as RadioControl;
interface LogWrite;
interface LogRead;
}
}
implementation {
message_t packet;
bool locked = FALSE;
bool proceed = TRUE;
uint16_t voltageSamples[11];
uint16_t samplesRead[11];
uint16_t i;
uint16_t counter = 0;
event void Boot.booted() {
call RadioControl.start();
}
event void RadioControl.startDone(error_t err) {
if (err == SUCCESS) {
call LogWrite.erase();
}
else {
call RadioControl.start();
}
}
event void RadioControl.stopDone(error_t err) {}
event void LogWrite.eraseDone(error_t error) {
call Timer0.startOneShot(2000);
call Timer1.startOneShot(35);
}
event void Timer1.fired() {
call ReadStream.postBuffer(voltageSamples, sizeof(voltageSamples));
call ReadStream.postBuffer(samplesRead, sizeof(samplesRead));
if (proceed) {
call ReadStream.read(1);
}
}
event void ReadStream.bufferDone(error_t result, uint16_t* buf, uint16_t
count){
if (result == 0) {
call Leds.led0Toggle();
}
call LogWrite.append(buf, count);
}
event void LogWrite.appendDone(void* buf, storage_len_t len, bool
recordsLost, error_t error) {
call Timer1.startOneShot(35);
}
event void LogWrite.syncDone(error_t error){
}
event void Timer0.fired() {
proceed = FALSE;
call Timer1.stop();
call LogRead.read(&samplesRead, sizeof (samplesRead));
}
event void LogRead.readDone(void* buf, storage_len_t len, error_t err) {
if (err == 0) {
call Leds.led2Toggle();
}
locked=FALSE;
if (locked) {
return;
}
else {
voltage_monitor_stream_t* vms;
vms = (voltage_monitor_stream_t*)call Packet.getPayload(&packet,
sizeof(voltage_monitor_stream_t));
if (vms == NULL) {
return;
}
for (i=0; i<11; i++) vms->Sample[i] = samplesRead[i];
vms->error = err;
vms->MsgNo = counter++;
if (call AMSend.send(AM_BROADCAST_ADDR, &packet,
sizeof(voltage_monitor_stream_t)) == SUCCESS) {
locked = TRUE;
}
}
if (len = 0) {
call Leds.led0Toggle();
call Timer0.startOneShot(2000); //2000
call Timer1.startOneShot(35); //35,100
}
else {
call LogRead.read(&samplesRead, sizeof (samplesRead));
}
}
event void ReadStream.readDone(error_t result, uint32_t
SamplingPeriod){}//call Leds.led0Toggle();
event void AMSend.sendDone(message_t* bufPtr, error_t error) {
if (error == 0) {
call Leds.led1Toggle();
}
if (&packet == bufPtr) {
locked = FALSE;
}
}
event void LogRead.seekDone(error_t error){}
}
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*Output*
serial@/dev/ttyUSB0:57600: resynchronising
1312497365370: Message <VoltageMonitorStreamMsg>
[Sample=0x1aa 0x1ac 0x1ac 0x1af 0x1ae 0x1af 0x1af 0x1b0 0x1b0 0x1b2 ]
[error=0x0]
[MsgNo=0x8]
1312497365392: Message <VoltageMonitorStreamMsg>
[Sample=0x1c9 0x1cd 0x1cd 0x1cf 0x1cf 0x1cf 0x1cf 0x1d1 0x1d1 0x1cf ]
[error=0x0]
[MsgNo=0x13]
1312497365400: Message <VoltageMonitorStreamMsg>
[Sample=0x1c6 0x1c6 0x1c7 0x1c7 0x1c7 0x1c7 0x1c7 0x1c7 0x1c7 0x1c7 ]
[error=0x0]
[MsgNo=0x16]
1312497365416: Message <VoltageMonitorStreamMsg>
[Sample=0x1b8 0x1b0 0x1b0 0x1b2 0x1b1 0x1aa 0x1aa 0x1ab 0x1ac 0x1ae ]
[error=0x0]
[MsgNo=0x21]
1312497365421: Message <VoltageMonitorStreamMsg>
[Sample=0x1b7 0x1c1 0x1c1 0x1c5 0x1c5 0x1cc 0x1cd 0x1cd 0x1cd 0x1ce ]
[error=0x0]
[MsgNo=0x2a]
1312497365429: Message <VoltageMonitorStreamMsg>
[Sample=0x1d3 0x1d3 0x1d2 0x1d3 0x1d3 0x1d3 0x1d3 0x1d3 0x1d3 0x1d3 ]
[error=0x0]
[MsgNo=0x2d]
1312497365439: Message <VoltageMonitorStreamMsg>
[Sample=0x1ca 0x1c9 0x1ca 0x1cb 0x1cb 0x1bc 0x1bb 0x1bc 0x1bc 0x1b1 ]
[error=0x0]
[MsgNo=0x38]
1312497367399: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x3b]
1312497369350: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x3c]
1312497371304: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x3d]
1312497373257: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x3e]
1312497375224: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x3f]
1312497377163: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x40]
1312497379116: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x41]
1312497381069: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x42]
1312497383024: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x43]
1312497384976: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x44]
1312497386932: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x45]
1312497388887: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x46]
1312497390847: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x47]
1312497392791: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x48]
1312497394748: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x49]
1312497396697: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x4a]
1312497398648: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x4b]
1312497400604: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x4c]
1312497402555: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x4d]
1312497404507: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x4e]
1312497406463: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x4f]
1312497408415: Message <VoltageMonitorStreamMsg>
[Sample=0x16 0x0 0x1af 0x1af 0x1af 0x1af 0x1af 0x1af 0x1b0 0x1b0 ]
[error=0x0]
[MsgNo=0x50]
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help