[Tinyos-help] [HELP!] Matchbox cannot write

Li Zhao zhaol at cs.man.ac.uk
Tue Mar 17 22:49:55 PDT 2009


Hi all,

I am trying to use matchbox to write data in buffer into flash, while I got
some problem. If matchbox get ready, it will signal matchboxReady(). Then I
use FileDir.start() to initial the matchbox. However, I never get signalled
event FileDir.nextFile(). Plus, I used gdb mode and saw FileDir.start()
return SUCCESS. Here I attach my code, could anyone be kind enough to help
me out?

FlashTest.cn ---------- configuration file
includes SimpleStruct;
includes Matchbox;

configuration FlashTest {  }

implementation {
  components Main, FlashTestM, Matchbox;
  components NoDebug, LedsC;

  Main.StdControl -> FlashTestM;
  Main.StdControl -> Matchbox;

  FlashTestM.Leds -> LedsC;

  FlashTestM.FileRead -> Matchbox.FileRead[unique("FileRead")];
  FlashTestM.FileWrite -> Matchbox.FileWrite[unique("FileWrite")];
  FlashTestM.FileDir -> Matchbox.FileDir;

  Matchbox.ready -> FlashTestM.matchboxReady;
  Matchbox.Debug -> NoDebug;
}


FlashTestM.nc -------- module
includes SimpleStruct;

module FlashTestM {
   provides {
     interface StdControl;
     event result_t matchboxReady();
   }

   uses {
      interface StdControl as LoggerControl;
      interface Leds;

      interface FileRead;
      interface FileWrite;
      interface FileDir;
    }
}

implementation
{

   SimpleStruct buffer;            // circular initial buffer contains
original data
   SimpleStruct bufferRead;        // circular buffer which store read data

   /*******************************************************/
     //Initialize the application.
     //Input value into TEST buffer
     //@return Success of component initialization.
   /*******************************************************/
      command result_t StdControl.init() {
        return call Leds.init();
   }//StdControl.init()




   /*******************************************************/
     //Start the application.
     //Write into Matchbox
     //@param filename Name of file to open. Must not be stack allocated.
     //@param flags: open options, an or (|) of FS_Fxxx constants.<br>
     //<code>FS_FTRUNCATE</code> Truncate file if it exists<br>
     //<code>FS_FCREATE</code> Create file if it doesn't exist
     //@return
     //        SUCCESS: attempt proceeds, <code>opened</code> will be
signaled<br>
     //        FAIL: filesystem is busy, another file is already open for
writing,
   /*******************************************************/
    command result_t StdControl.start(){
      return SUCCESS;
    }//StdControl.start()




  /*******************************************************/
    //Stop the application.
    //@return Always returns <code>SUCCESS</code>
  /*******************************************************/
    command result_t StdControl.stop(){
      return SUCCESS;
    }//StdControl.stop()





  /*******************************************************/
    //Task to Creat File in Matchbox
  /*******************************************************/
  task void createFile(){
    if(call FileWrite.open("foo",FS_FCREATE)==SUCCESS){
      dbg(DBG_USR1,"STATE: Successfully opened file\n");
    }

    else{
      dbg(DBG_USR1,"STATE:Could not open file\n");
    }
  }



  /*******************************************************/
    //Signalled when FileDir found next file
  /*******************************************************/
  event result_t FileDir.nextFile(const char *filename, fileresult_t result)
{
    dbg(DBG_USR1,"STATE: Next file is '%s' with result:
%d\n",filename,result);

    if(result==FS_OK){
      if(call FileDir.readNext()==SUCCESS){
        dbg(DBG_USR1,"STATE: %d, Succesfully read next file\n");
      }
    }

    else if(result==FS_NO_MORE_FILES){
      post createFile();
    }

    return SUCCESS;
  }





  /*******************************************************/
    //Signalled when write opened, do append
  /*******************************************************/
  event result_t FileWrite.opened(filesize_t fileSize, fileresult_t result)
{
    dbg (DBG_USR1, "RESULT of FileWrite.open: %i\n", result);
    dbg (DBG_USR1, "SIZE of FileWrite.open: %i\n", fileSize);
    if (result == FS_OK) {
      uint8_t* ptr;
      ptr = (uint8_t *)bufferRead.log;
      call FileWrite.append(ptr, sizeof(buffer.log));    //actually write to
Matchbox
    }
    return result;
  } // FileWrite.opened




  /*******************************************************/
    //Signalled when Matchbox finished the open,call read
  /*******************************************************/
  event result_t FileRead.opened(fileresult_t result) {
    uint8_t* ptr;
    ptr = (uint8_t *)bufferRead.log;
    return call FileRead.read(ptr, sizeof(bufferRead.log));
  }




  /*******************************************************/
    //Signalled when Matchbox finish reading
    //call FileRead to close
    //display the result in the bufferRead
  /*******************************************************/
  event result_t FileRead.readDone(void *buf, filesize_t nRead,
                   fileresult_t result) {
    call FileRead.close();

    atomic {
      int i;
      for (i=0;i<sizeof(bufferRead.log);i++) {
          dbg (DBG_USR1, "Output: Value is %i\n", (int)bufferRead.log[i]);
          } // give initial value to the array
      } // atomic

    if (result) call Leds.greenToggle();

    return SUCCESS;
  }




  /*******************************************************/
    //Signalled when completed the writing to Matchbox,
    //Toggle the rea LED
    //call FileWrite to close
    //@return Always returns <code>SUCCESS</code>
  /*******************************************************/
  event result_t FileWrite.appended(void *buf, filesize_t nWritten,
                    fileresult_t result) {
    call FileWrite.close();
    return SUCCESS;
  }




  /*******************************************************/
    //Signalled when completed the close of writing,
    //Toggle the rea LED
    //call Matchbox to read
    //@return Always returns <code>SUCCESS</code>
  /*******************************************************/
  event result_t FileWrite.closed(fileresult_t result) {
    if (result) call Leds.redToggle();

    call FileRead.open("foo");
    return SUCCESS;
  }




  /*******************************************************/
    //signalled when matchbox finish the operations
    //Turn all LEDs to off
  /*******************************************************/
  event result_t matchboxReady() {
    call Leds.redOn();
    call Leds.greenOn();
    call Leds.yellowOn();

    buffer.sourceaddr = TOS_LOCAL_ADDRESS;
    buffer.destaddr = TOS_LOCAL_ADDRESS + 1;
    atomic {
      int i;

      dbg (DBG_USR1, "Input: Value is: ");
      for (i=0;i<sizeof(buffer.log);i++) {
        buffer.log[i] = (i*2);
          dbg (DBG_USR1, "%i\n", (int)buffer.log[i]);
      }//give initial value to the array
    }

    return call FileDir.start();
  }




  /*******************************************************/
    //Signalled when write to matchbox synced
    //@return always SUCCESS
  /*******************************************************/
  event result_t FileWrite.synced(fileresult_t result) {
    return SUCCESS;
  }

  event result_t FileRead.remaining(filesize_t n, fileresult_t result) {
      return SUCCESS;
  }

  event result_t FileWrite.reserved(filesize_t fileSize, fileresult_t
result) {
      return SUCCESS;
  }


} // end of implementation


Sorry for the long email, but I really need help. Looking forward to you
quick response.

-- 
Thanks
Li ZHAO
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20090318/35c6a53c/attachment-0001.htm 


More information about the Tinyos-help mailing list