Hi!

Could anyone tell me whether the *sequence* of my calls to timer are allowable 
in TinyOS1? For some reason this code stalls while sending to the radio, i.e. 
sendone never gets called. 

This program gets info from the ADC and sends it to the radio. I want to use 
multiple one_shoot timers so I can eventually manipulate the timings between 
each call.

Thank you in advance

LV

includes MyMsg;

module ADCtoRadioM {
  provides interface StdControl;
  uses {
     interface Timer;
     interface SendMsg;
     interface Leds;
     interface ADC as InternalVoltage;
     interface ADC as ADCO;
     interface ADCControl;
  }
}

    implementation {

    enum {
      ADCVOLT, IVOLT, SEND 
    };
      
    norace uint16_t ivolt,adcvolt;
    norace int state;
    TOS_Msg m_msg;
    MyMsg* body;
     
    command result_t StdControl.init() {
        state = ADCVOLT;
        body->counter=0;
        call Leds.init();
        call ADCControl.init();
        call ADCControl.bindPort( TOS_ADC_ADC0_PORT, TOSH_ACTUAL_ADC_ADC0_PORT 
);
        return SUCCESS;
    }

    command result_t StdControl.start() {
        call Timer.start(TIMER_ONE_SHOT, 1000); //Starts the process in 1 ms
        return SUCCESS;
    }

    command result_t StdControl.stop() {
        return SUCCESS;
    }

  task void SendIt(){  
     if( call SendMsg.send( TOS_BCAST_ADDR, sizeof(MyMsg), &m_msg ) == SUCCESS 
) {
     call Leds.greenOn();
    }
  }    
    
  event result_t Timer.fired() {
  
    switch(state) {
    
        case ADCVOLT:
          call ADCO.getData();
          break;

        case IVOLT:
          call InternalVoltage.getData();
          break;

        case SEND:
          body = (MyMsg*)m_msg.data;
          body->counter++;    
          body->src = TOS_LOCAL_ADDRESS;
          post SendIt();
          break;

        default:
          call Timer.start(TIMER_ONE_SHOT, 1000);
        }

    return SUCCESS;
  }

    
  task void ShootIt(){
    call Timer.start(TIMER_ONE_SHOT, 1000);
  }

  async event result_t ADCO.dataReady(uint16_t adcdata)
  {
        body->val = adcdata;
        state = IVOLT;
        call Leds.redOn();
        post ShootIt();
        return SUCCESS;
  }

  async event result_t InternalVoltage.dataReady(uint16_t vdata)
  {
        body->battery = vdata;
        state = SEND;
        call Leds.redOff();            
        post ShootIt();
        return SUCCESS;
  }
  
  event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t success)
  {
        state = ADCVOLT;
        call Leds.greenOff();
        post ShootIt();    
        return SUCCESS;
  }
} 




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

Reply via email to