0

我正在编译以下代码(在微尘上)。我有以下错误:

第 174 行:函数“startTimers”的隐式声明

请你帮助我好吗?

这是我的代码。

#include "Timer.h"
#include "Oscilloscope.h"

   module Oscilloscope2C @safe(){
      uses {
      interface Boot;
      interface SplitControl as RadioControl;
       interface AMSend;
       interface Receive;
        //interface Timer<TMilli>;
      interface Timer<TMilli> as Timer0;
      interface Timer<TMilli> as Timer1;
      interface Timer<TMilli> as Timer2;
      //interface Read<uint16_t>;
       interface Leds;
       interface Read<uint16_t> as TempRead;
       interface Read<uint16_t> as HumidtyRead;
       interface Read<uint16_t> as LightRead;
       //interface Read<uint16_t> as VoltageRead;    

      }
     }
     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 suppressCountChange;

   // Use LEDs to report various status issues.
   void report_problem() { call Leds.led0Toggle(); }
   void report_sent() { call Leds.led1Toggle(); }
   void report_received() { call Leds.led2Toggle(); }

   event void Boot.booted() {

  //local.interval = DEFAULT_INTERVAL;
  //local.id = TOS_NODE_ID;
   if (call RadioControl.start() != SUCCESS)
       report_problem();
    }

    event void Timer0.fired(){
      //dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string());
       //call Leds.led0Toggle();
       if (reading == NREADINGS){
        if (!sendBusy && sizeof local <= call AMSend.maxPayloadLength()){
          memcpy(call AMSend.getPayload(&sendBuf, sizeof(local)), &local, sizeof local);
        if (call AMSend.send(AM_BROADCAST_ADDR, &sendBuf, sizeof local) == SUCCESS)
           sendBusy = TRUE;
        }
        if (!sendBusy)
           report_problem();
           reading = 0;

         if (!suppressCountChange)
            local.count++;
             suppressCountChange = FALSE;
         }
         if (call TempRead.read() != SUCCESS)
             report_problem();
       }

       event void Timer1.fired(){
          //dbg("BlinkC", "Timer 1 fired @ %s \n", sim_time_string());
           //call Leds.led1Toggle();
           if (reading == NREADINGS){
              if (!sendBusy && sizeof local <= call AMSend.maxPayloadLength()){
                 memcpy(call AMSend.getPayload(&sendBuf, sizeof(local)), &local, sizeof local);
                 if (call AMSend.send(AM_BROADCAST_ADDR, &sendBuf, sizeof local) == SUCCESS)
                   sendBusy = TRUE;
                 }
                 if (!sendBusy)
                   report_problem();
                   reading = 0;

                if (!suppressCountChange)
                   local.count++;
                    suppressCountChange = FALSE;
                  }
                  if (call HumidtyRead.read() != SUCCESS)
                       report_problem();
                  //}
            }

             event void Timer2.fired(){
                 //dbg("BlinkC", "Timer 2 fired @ %s.\n", sim_time_string());
                 //call Leds.led2Toggle();
                  if (reading == NREADINGS){
                  if (!sendBusy && sizeof local <= call AMSend.maxPayloadLength()){
                  memcpy(call AMSend.getPayload(&sendBuf, sizeof(local)), &local, sizeof local);
                 if (call AMSend.send(AM_BROADCAST_ADDR, &sendBuf, sizeof local) == SUCCESS)
                 sendBusy = TRUE;
                 }
                 if (!sendBusy)
                   report_problem();
                   reading = 0;

                  if (!suppressCountChange)
                     local.count++;
                     suppressCountChange = FALSE;
                  }
                  if (call LightRead.read() != SUCCESS)
                     report_problem();
           //}
        }



        event void TempRead.readDone(error_t result, uint16_t data) {
             //int32_t Temp;
              if (result != SUCCESS){
              data = 0xffff;
              report_problem();
         }
         if (reading < NREADINGS) 
             local.readings[reading++] = data;
              //Temp=-3960+(int32_t)data; 
              //if(Temp>=3000){ 
              //remplacer par buzzer
              //call Leds.led1On(); 
              //call Leds.led2Off(); 
           // }
           //else{ 
          //call Leds.led2On(); 
          //call Leds.led1Off(); 
         //} 
         }//end TempRead

       event void HumidtyRead.readDone(error_t result, uint16_t data) {
     //int32_t Humidity;
     //int32_t RH;
     //int32_t Temp;
     //int32_t Temp_25;
      if (result != SUCCESS){
     data = 0xffff;
     report_problem();
      }
      if (reading < NREADINGS) 
         local.readings[reading++] = data;
         //Humidity=-2.0468+0.0367*(int32_t)data-0.0000015955*((int32_t)data*(int32_t)data);
         //Temp= 0.01*data -39.60;
         //Temp_25 =  Temp-25;
         //RH = Temp_25*(0.01+0.00008*(int32_t)data)+Humidity;
          //if (RH > 100) report_problem();
 }//end HumidityRead

  event void LightRead.readDone(error_t result, uint16_t data) {
  //int32_t Light;
      if (result != SUCCESS){
     data = 0xffff;
     report_problem();
      }
      if (reading < NREADINGS) 
      local.readings[reading++] = data;
  }//end LightRead


 event void RadioControl.startDone(error_t error) {
    startTimers();
} 
event void RadioControl.stopDone(error_t error) {
 }

void startTimers() {
    //call Timer.startPeriodic(local.interval);
    call Timer0.startPeriodic(250);
    call Timer1.startPeriodic(500);
    call Timer2.startPeriodic(1000);
reading = 0;
  }


event void AMSend.sendDone(message_t* msg, error_t error) {
if (error == SUCCESS)
  report_sent();
else
  report_problem();

   sendBusy = FALSE;
}


 event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) {
oscilloscope_t *omsg = payload;

report_received();

/* If we receive a newer version, update our interval. 
   If we hear from a future count, jump ahead but suppress our own change
*/
if (omsg->version > local.version)
  {
local.version = omsg->version;
local.interval = omsg->interval;
startTimers();
  }
if (omsg->count > local.count)
  {
local.count = omsg->count;
suppressCountChange = TRUE;
  }

  return msg;
 }

    /*
    void startTimer() {
       call Timer.startPeriodic(local.interval);
      reading = 0;
    }

    event void RadioControl.startDone(error_t error) {
       startTimer();
    }

   event void RadioControl.stopDone(error_t error) {}

   event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){
   oscilloscope_t *omsg = payload;

      report_received();

   if (omsg->version > local.version){
     local.version = omsg->version;
     local.interval = omsg->interval;
startTimer();
  }
if (omsg->count > local.count)
  {
local.count = omsg->count;
suppressCountChange = TRUE;
  }

return msg;
}


event void Timer.fired() {
   if (reading == NREADINGS){
    if (!sendBusy && sizeof local <= call AMSend.maxPayloadLength()){
    // Don't need to check for null because we've already checked length
      // above
    memcpy(call AMSend.getPayload(&sendBuf, sizeof(local)), &local, sizeof local);
    if (call AMSend.send(AM_BROADCAST_ADDR, &sendBuf, sizeof local) == SUCCESS)
      sendBusy = TRUE;
     }
    if (!sendBusy)
      report_problem();

    reading = 0;

    if (!suppressCountChange)
      local.count++;
    suppressCountChange = FALSE;
  }
  // if (call Read.read() != SUCCESS)
   //   report_problem();
   if (call TempRead.read() != SUCCESS)
       report_problem();
    if (call HumidityRead.read() != SUCCESS)
       report_problem();
    if (call LightRead.read() != SUCCESS)
        report_problem();
        }

   event void AMSend.sendDone(message_t* msg, error_t error) {
     if (error == SUCCESS)
        report_sent();
     else
        report_problem();

    sendBusy = FALSE;
  }

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

    event void TempRead.readDone(error_t result, uint16_t data) {
       int32_t Temp;
      if (result != SUCCESS){
        data = 0xffff;
       report_problem();
      }
      if (reading < NREADINGS) 
         local.readings[reading++] = data;
          Temp=-3960+(int32_t)data; 
           if(Temp>=3000){ 
           //remplacer par buzzer
           call Leds.led1On(); 
           call Leds.led2Off(); 
      }else{ 
          call Leds.led2On(); 
           call Leds.led1Off(); 
      } 
    }

   event void HumidityRead.readDone(error_t result, uint16_t data) {
       int32_t Humidity;
       int32_t RH;
        int32_t Temp;
       int32_t Temp_25;
      if (result != SUCCESS){
        data = 0xffff;
         report_problem();
       }
if (reading < NREADINGS) 
  local.readings[reading++] = data;
 Humidity=-2.0468+0.0367*(int32_t)data-0.0000015955*((int32_t)data*(int32_t)data);
 Temp= 0.01*data -39.60;
 Temp_25 =  Temp-25;
 RH = Temp_25*(0.01+0.00008*(int32_t)data)+Humidity;
 if (RH > 100) report_problem();
  }

   event void LightRead.readDone(error_t result, uint16_t data) {
       int32_t Light;
     if (result != SUCCESS){
        data = 0xffff;
        report_problem();
      }
       if (reading < NREADINGS) 
         local.readings[reading++] = data;
   }

    event void VoltageRead.readDone(error_t result, uint16_t data) {
      if (result != SUCCESS){
       data = 0xffff;
       report_problem();
       }
      if (reading < NREADINGS) 
        local.readings[reading++] = data;
      }
     */
    }

非常感谢您的帮助!

汤姆

4

1 回答 1

0

该函数在声明和定义之前startTimers被调用。RadioControl.startDone在代码中使用它之前,只需将其定义startTimers更高。

于 2015-09-10T10:58:14.787 回答