All,

Has anyone tried logging data in a MicaZ in TOS2 ? I experienced a problem
with the wrong read/write on flash on micaz. I tried making few applications
to detect the exact nature of the error. I tried this:

1. Periodically logging data in the flash of MicaZ.
2. Periodically reading last values and sending them over the radio to the
basestation

Result: I get first few values all correct. However when the second and
subsequent bunch of readings are sent they are preceded with quite a large
number of 0XFFFF readings(arbit readings). My read uses cookie information
to detect and stop reading further if the read and write pointer are at the
same position. I am not able to ascertain if it is the problem of the write
operation OR read operation.

The same piece of code runs perfectly fine on the telosb platform.
Previously, I thought that this might be due to contention in
read/write/radio operation. However, with the help of bools I seperated all
the operations to not to contend. But, still the problem persists.

I am pasting my code+output for your perusal.


implementation {

 uint16_t data = 0;
 uint16_t readings = 0;
 message_t pkt;
 bool busy = FALSE;
 bool logBusy = FALSE;

 task void sendTask();

 storage_cookie_t readCookie;
 storage_cookie_t writeCookie;

 #define SAMPLING_FREQUENCY 2333

 event void Boot.booted() {
     //call Init.init();
     call AMControl.start();
 }

 event void AMControl.startDone(error_t err) {
   if (err == SUCCESS) {
 call LogWrite.erase();
       }
      else {
        call AMControl.start();
         }
     }

 event void LogWrite.eraseDone(error_t result) {
  call Timer1.startPeriodic(SAMPLING_FREQUENCY);
  call Timer0.startPeriodic(TIMER_PERIOD_MILLI);
 }

 event void Timer1.fired()
  {
   //call Read.read();
readings++;
atomic {
if(!logBusy)
{
 logBusy = TRUE;
 call LogWrite.append(&readings, sizeof(readings));
}
}
  }

  event void LogWrite.appendDone(void *buf, storage_len_t len, bool
recordsLost, error_t result) {
         if(result == SUCCESS) {
            call LogWrite.sync();
            }
  }

event void LogWrite.syncDone(error_t result) {
     logBusy = FALSE;
        call Leds.led2Toggle();
 }

 event void Timer0.fired() {
  call Timer1.stop();
  atomic {
  if(!logBusy) {
   logBusy = TRUE;
   call LogRead.read(&data, sizeof(data));
  }
  }
 }

 event void LogRead.readDone(void* buf, storage_len_t len, error_t error) {
   if(error == SUCCESS) {
 call Leds.led1Toggle();
 post sendTask();
}
 }

 task void sendTask() {
  if (!busy) {
       SenseStoreRadioMsg* ssrpkt = (SenseStoreRadioMsg*)(call
Packet.getPayload(&pkt, NULL));
       ssrpkt->nodeid = TOS_NODE_ID;
       ssrpkt->payloadData = data;
       if(call AMSend.send(AM_BROADCAST_ADDR, &pkt,
sizeof(SenseStoreRadioMsg)) == SUCCESS) {
          busy = TRUE;
     }
   }
 }


 event void AMSend.sendDone(message_t* msg, error_t err) {
   if (&pkt == msg) {
     busy = FALSE;
  readCookie = call LogRead.currentOffset();
     writeCookie = call LogWrite.currentOffset();
    if(readCookie != writeCookie) {
  call LogRead.read(&data, sizeof(data));
 }
 else {
  logBusy = FALSE;
  call Timer1.startPeriodic(SAMPLING_FREQUENCY);
 }
   }
 }

 event void LogRead.seekDone(error_t error) {}
 event void AMControl.stopDone(error_t err) {}

}



*result when running Listen @ Basestation:*

Mayur [EMAIL PROTECTED] ~
$ java net.tinyos.tools.Listen -comm [EMAIL PROTECTED]:9002
00 FF FF FF FF 04 00 06 00 02 00 01
00 FF FF FF FF 04 00 06 00 02 00 02
00 FF FF FF FF 04 00 06 00 02 00 03
00 FF FF FF FF 04 00 06 00 02 00 04
00 FF FF FF FF 04 00 06 00 02 00 05
00 FF FF FF FF 04 00 06 00 02 00 06
00 FF FF FF FF 04 00 06 00 02 00 07
00 FF FF FF FF 04 00 06 00 02 00 08
00 FF FF FF FF 04 00 06 00 02 00 08
00 FF FF FF FF 04 00 06 00 02 00 09
00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 FF FF
:

:

:

00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 FF FF
00 FF FF FF FF 04 00 06 00 02 00 0A
00 FF FF FF FF 04 00 06 00 02 00 0B
00 FF FF FF FF 04 00 06 00 02 00 0C
00 FF FF FF FF 04 00 06 00 02 00 0D
00 FF FF FF FF 04 00 06 00 02 00 0E
00 FF FF FF FF 04 00 06 00 02 00 0F
00 FF FF FF FF 04 00 06 00 02 00 10
00 FF FF FF FF 04 00 06 00 02 00 10


Thanks in advance
Regards
--
Mayur Maheshwari([EMAIL PROTECTED])

"Karmanye Vadhikaraste Ma Phaleshu Kadachana,
Ma Karma Phala Hetur Bhurmatey Sangostva Akarmani"
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to