** Pointers are the way to go... for passing back a lot of data at once.

Again, I've never used an MDA300, but if you're passing back only one piece
of data at a time, Michael's ADC example is a good one to follow.

David


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of David Moss
Sent: Wednesday, November 16, 2005 12:12 PM
To: 'Philippe Habib'; [email protected]
Subject: RE: [Tinyos-help] Events and data passing


I've never used an MDA300, but data passing techniques are used everywhere.

Here's one possible strategy:

First, setup your interface to the component that will allow other
components to read from the MDA300, here's an example:


//////////////////////////////////////////////////////
interface MDA300 {
 
  /** 
   * Request a read
   */
  command result_t read();

  /**
   * Here's the data to read, after some asynchronous time has passed to
   * perform the read.  Void because we don't care what happens on the other
end.
   */
  event void readDone(void *data, uint8_t len, result_t result);
}
//////////////////////////////////////////////////////



In the module that provides the interface (like the one you described you're
working on):

//////////////////////////////////////////////////////
module MDA300M {
  provides {
    interface MDA300;
    //... Etc.
  }
}

implementation {


  

  //... 

  command result_t MDA300.read() {
    // Storage for the data you read, just an example
    // DATA_TO_READ is the size of the reading 
    uint8_t data[DATA_TO_READ];

    // do whatever needs to be done to read the MDA300 here
    // into the data[] array.. Or wherever the data is stored the data. 
    // Don't copy it into the data[] array if it already exists in another
location.

    // ...
  
    // whenever it's done being read (usually into a separate function),
    // signal the event with the appropriate parameters:
    signal MDA300.readDone(&data, DATA_TO_READ, SUCCESS);
  }

  //...
}
//////////////////////////////////////////////////////



Now, your external component has issued the read() command, and the MDA300
module read the data and signaled an event.  The event itself provides a
pointer to the data that was read, the length of data read, and the result
(if applicable) stating whether or not the data is valid.  I made the
readDone event return void because my component doesn't care what other
components do with the data.  

So, on the components that would use your new MDA300 interface, you could
get the data like this:

//////////////////////////////////////////////////////
module UseMDA300 {
  uses {
    interface MDA300;
  }
}

implementation {
  //...

  // just an example.. Handle the data however you want.
  uint8_t storeReadingsHere[DATA_TO_READ];

  void someFunction() {
    // Gotta request a reading..
    call MDA300.read();
  }


  /**
   * Got a reading back - handle it however you need. 
   * In this case, I stored it to the array "storeReadingsHere" using memcpy
   */
  event void MDA300.readDone(void *data, uint8_t len, result_t result) {
    if(result) {
      memcpy(&storeReadingsHere, data, len);
    }
  }

  //...
}
//////////////////////////////////////////////////////

This should just give you a general idea of how you can handle returning
data from events that could take any length of time to complete.  If you
know that the reading will be done immediately when the read() function is
called, you don't even need an event to pass back the data.  In this case,
you can use a different strategy: modify the read() function itself to get
the data:

  /**
   * Read the data into a buffer pointed to by *data,
   * and return the number of bytes read
   * @param *data - the location of the empty buffer to store readings in
   * @param maxData - the maximum amount of data to read into the buffer
   * @return the amount of data read into the buffer
   */
  command uint8_t read(void *data, uint8_t maxData);



In this case, you don't need to return an event, but the actual MDA300
probably doesn't work like that. 

In general, pointers are the way to go.

Hope this helps,
David

 


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Michael
Schippling
Sent: Wednesday, November 16, 2005 11:42 AM
To: Philippe Habib
Cc: [email protected]
Subject: Re: [Tinyos-help] Events and data passing


events should only return SUCCESS or FAIL.
Stuffing the data into a global of some kind is the one true way,
because events are not called from a context that would
know what to do with a return value anyway...
Anything that uses the ADC dataReady() event would be a good example.
MS


Philippe Habib wrote:
> I am very new to TinyOS and I've got what may be very simple questions I
> hope I can get some guidance with.
> 
> I am working on a component that will read some data from an MDA300 board
> and will signal an event when the data is available.  The read will be
> caused by calling a read routine, which will signal the event when the
read
> is done.
> 
> What is the best way to get the data read back to the caller?  A global?
> Can an event return a value?  If the event returns a value, how is it
read?
> Is there an example of this somewhere?
> 
> Thank you.
> 
> 
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help


_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help


_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to