Dear all,

I got a stupid problem but it's big for me though. Actually I modified the
OscilloscopeM.nc file to do some work that's simply
sending data to serial port. And the send data function is the
task void datapost(), while the value of data is set in the Timer.fired()
function, then the Timer.fired() function will call the datapost
function.

I know this is stupid, but I actually wanna write a function that is
sendData(char *data), then the sendData will call the datapost function.
But does it have to be command or event I really don't know. I didn't really
get into nesC. And moreover, and also the most important,
suppose we have a sendData(char *data), and I wanna use BlinkM.nc to send a
data to serial port by calling the sendData function
in OscilloscopeM.nc, what should I do? And I have post the modified
OscilloscopeM.nc file in the following, could you guys help me with this
please? Thanks in advanced.

includes OscopeMsg;


module OscilloscopeM
{
  provides interface StdControl;
  uses {
    interface Timer;
    interface Leds;
    interface StdControl as SensorControl;
    interface StdControl as CommControl;
    interface SendMsg as DataMsg;
    interface ReceiveMsg as ResetCounterMsg;
  }
}
implementation
{

  TOS_Msg msg;


  /**
   * Used to initialize this component.
   */
  command result_t StdControl.init() {
    call Leds.init();
    call Leds.yellowOff(); call Leds.redOff(); call Leds.greenOff();

    //turn on the sensors so that they can be read.
    call SensorControl.init();

    call CommControl.init();

    atomic {
    }

    dbg(DBG_BOOT, "OSCOPE initialized\n");
    return SUCCESS;
  }

   /**
   * Starts the SensorControl and CommControl components.
   * @return Always returns SUCCESS.
   */
  command result_t StdControl.start() {
    call SensorControl.start();
    call Timer.start(TIMER_REPEAT, 125);
    call CommControl.start();
    return SUCCESS;
  }

  /**
   * Stops the SensorControl and CommControl components.
   * @return Always returns SUCCESS.
   */
  command result_t StdControl.stop() {
    call SensorControl.stop();
    call Timer.stop();
    call CommControl.stop();
    return SUCCESS;
  }


  task void dataTask() {
    struct OscopeMsg *pack;
    atomic {
      pack = (struct OscopeMsg *)msg.data;
    }


    /* Try to send the packet. Note that this will return
     * failure immediately if the packet could not be queued for
     * transmission.
     */
    if (call DataMsg.send(TOS_UART_ADDR, sizeof(struct OscopeMsg),
                  &msg))
      {
    call Leds.yellowToggle();
      }
  }


    /**
   * Signalled when the clock ticks.
   * @return The result of calling ADC.getData().
   */
  event result_t Timer.fired() {
    struct OscopeMsg *pack;

     atomic {
     pack = (struct OscopeMsg *)msg.data;
     memcpy(pack->data,"Kennethchan",sizeof("Kennethchan"));
     //dbg(DBG_USR1, "\ndata_event,count=%s\n\n",pack->data);
     post dataTask();

    }
    return SUCCESS;
  }

    /**
   * Signalled when the previous packet has been sent.
   * @return Always returns SUCCESS.
   */
  event result_t DataMsg.sendDone(TOS_MsgPtr sent, result_t success) {
    return SUCCESS;
  }

   /**
   * Signalled when the reset message counter AM is received.
   * @return The free TOS_MsgPtr.
   */
  event TOS_MsgPtr ResetCounterMsg.receive(TOS_MsgPtr m) {
    atomic {
    }
    return m;
  }
}


-- 
Best wishes,
Kenneth Chan

------------------------
Wish you have a good day!
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to