In general, any variable you define inside the implemenation
braces, but outside of a function, is "global" to the whole
module. Since tasks don't get arguments on their stack you
must use globals like this to pass data. So one fix for your
problem would be to copy buf and buflen to other 'global'
variables before posting the task that uses them.

However...

Since you are copying stuff anyway, and we don't know about the
greater scope of the "buf" that you are getting in dataReady,
you might as well define "rmspkt" as a global directly in your
module implementation, say, just before dataReady(), which it
appears from the code snippet that you have already done, and
do the copy in the async routine. Then, if all was copacetic,
post your Send task and hope for the best.

MS



John Griessen wrote:
I had some tested working code that I had the warning about
sync from async event.   It compiled and moved data though.

So I started reading about tasks and moved the code below from inside the async event to a task, and just posted the task inside the event.

Then I get undeclared first use of for buf and buflen....


What to do? The section on tasks seems to say there are no parameters, just use the variables in your component. So, do I need to copy buf and buflen to global variables before I can use them?

Instead of that, I could just let the event dataReady put data straight into global variables, but I run into snags I don't know how to fix...
The compiler says I am redefining the globals.  How do you let
an event like .dataReady put data into a global variable?

Thanks,

John Griessen

  async event void a2d12ch.dataReady(uint16_t *buf, uint16_t buflen)
  {
    post MoistureSensorsMsgSend();
  }

  task void MoistureSensorsMsgSend()
  {
MoistureSensorsMsg* rmspkt = (MoistureSensorsMsg*) (call AMSend.getPayload(&pkt)); //cast result of .getPayload to pointer of nx_struct MoistureSensorsMsg*
    rmspkt->nodeid = TOS_NODEID;
    rmspkt->timestamp = timestamp;
    call Leds.led1On();  //debug aid
    if ( buflen == 12 )   // 12 Adc values in a vector, len == 12
    {
      rmspkt->adc00 = buf[0];
      rmspkt->adc01 = buf[1];.
.
.
.
}



--
Platform: WinXP/Cygwin
TinyOS version: 1.x, Boomerang
Programmer: MIB510
Device(s): Mica2, MicaZ, Tmote
Sensor board: homebrew

_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to