Hi guys,
I have a problem with the following code, I've modified the oscilloscope code, 
cut the timer and some other counters.
I'd like to read from the ADC on demand. it seems to work but when i send the 
command from the java interface i it send me back the value read before;

I.e.:

this is the correct cycle of operation of the mote:

-Boot;
-activation of the radio;

when a cmd of type 2 (to read) arrives it should:

-toggle leds;
-read from ADC;
-send a message with actual value to radio;

well, all works right but the value i receive in the message is an old one..
I hope to be clear, some one could help me?
Thanx in advance

Alessandro

################## CODE SNIPPET ##############################

#include "Oscilloscope.h"

module OscilloscopeC
{
 uses {
   interface Boot;
   interface SplitControl as RadioControl;
   interface AMSend;
   interface Receive;
   //interface Timer<TMilli>;
   interface Read<uint16_t>;
   interface Leds;
 }
}
implementation
{
 message_t sendbuf;
 bool sendbusy;

 /* Current local state - interval, version and accumulated readings */
 oscilloscope_t local;

 uint8_t reading; /* 0 to NREADINGS */

 /* When we head an Oscilloscope message, we check it's sample count. If
    it's ahead of ours, we "jump" forwards (set our count to the received
    count). However, we must then suppress our next count increment. This
    is a very simple form of "time" synchronization (for an abstract
    notion of time). */
 bool suppress_count_change;

 void report_problem() {  // problemi -> Led Rosso
call Leds.led0On(); }

 event void Boot.booted() {
   local.interval = DEFAULT_INTERVAL;
   local.id = TOS_NODE_ID;
   reading = 0;
   if (call RadioControl.start() != SUCCESS)
     report_problem();
 }

 event void RadioControl.startDone(error_t error) { // faccio partire la radio 
e poi rimango in attesa del pacchetto di start
 }

 event void RadioControl.stopDone(error_t error) {
 }

 event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) {
   oscilloscope_t *omsg = payload;
if (omsg->cmd == 0) // toggle leds to show a stop signal
           {
              call Leds.led0On();
              call Leds.led1Off();
call Leds.led2Off(); return msg;
           }
        if (omsg->cmd == 2) // read ADC and send radio msg
           {
              call Leds.led0Off();
              call Leds.led1On();
              call Leds.led2On();
if (call Read.read() == SUCCESS) { // if (!sendbusy && sizeof local <= call AMSend.maxPayloadLength()) // {
                           memcpy(call AMSend.getPayload(&sendbuf), &local, 
sizeof local);
                           if (call AMSend.send(0, &sendbuf, sizeof local) == 
SUCCESS)
                              {
                               sendbusy = TRUE;
                              }
                           else {
                 //      }
                 //  if (!sendbusy)
                      report_problem();
                      }
                   reading = 0;
                   return msg;
               }
               return msg;
           }
 }

 event void AMSend.sendDone(message_t* msg, error_t error) {
   if (error != SUCCESS)
     report_problem();
   sendbusy = FALSE;
 }

 event void Read.readDone(error_t result, uint16_t data) {
   if (result != SUCCESS)
     {
        data = 0xffff;
        report_problem();
     }
   else {
        call Leds.led0Off();
       call Leds.led2Off();
     }
   local.readings[reading++] = data;
 }
}



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Scanned with Copfilter Version 0.84beta2 (ProxSMTP 1.6)
AntiVirus: ClamAV 0.91.2-exp/4659 - Thu Nov  1 17:24:40 2007
AntiVirus: F-PROT 4.6.7 Engine version: 3.16.15
SIGN.DEF 31 Oct07 - SIGN2.DEF 31 Oct07 - MACRO.DEF 31 Oct07
by Markus Madlener @ http://www.copfilter.org


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Scanned with Copfilter Version 0.84beta2 (ProxSMTP 1.6)
AntiVirus: ClamAV 0.91.2-exp/4659 - Thu Nov  1 17:24:40 2007
AntiVirus: F-PROT 4.6.7 Engine version: 3.16.15
SIGN.DEF 31 Oct07 - SIGN2.DEF 31 Oct07 - MACRO.DEF 31 Oct07
by Markus Madlener @ http://www.copfilter.org
begin:vcard
fn:Alessandro Turella
n:Turella;Alessandro
org:Veneta Engineering S.r.l.;Direzione
adr:;;Via Lovanio 8/10;Verona;VR;37135;Italia
email;internet:[EMAIL PROTECTED]
title;quoted-printable:Responsabile Qualit=C3=A0
tel;work:045 820 09 48
tel;fax:045 820 19 82
tel;cell:347 96 96 057
x-mozilla-html:TRUE
url:http://www.venetaengineering.it
version:2.1
end:vcard

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

Reply via email to