이제 부터 공부의 속력을 내기 위해 요약 해석 할 예정입니다.

속도가 넘 안나네요.

Interfaces,Commands,and Events

Lesson1의 경험으로 인터페이스를 사용하는 컴포넌트는 인터페이스의 command를 실행 할 수 있으며, 역으로 이벤트는 받아서 처리 해야 한다는걸 알 수 있게 되었습니다. 그럼 BlinkC가 사용 하는 인터페이스를 분석 하도록 하겠습니다. BlinkC가 사용 하는 인터페이스는 Timer,Leds,Boot가 있습니다.

tos/interfaces/Boot.nc:
interface Boot {
  event void booted();
}

tos/interfaces/Leds.nc:
interface Leds {

  /**
   * Turn LED n on, off, or toggle its present state.
   */
  async command void led0On();
  async command void led0Off();
  async command void led0Toggle();

  async command void led1On();
  async command void led1Off();
  async command void led1Toggle();

  async command void led2On();
  async command void led2Off();
  async command void led2Toggle();

  /**
   * Get/Set the current LED settings as a bitmask. Each bit corresponds to
   * whether an LED is on; bit 0 is LED 0, bit 1 is LED 1, etc.
   */
  async command uint8_t get();
  async command void set(uint8_t val);
 
}

tos/interfaces/Timer.nc:
interface Timer
{
  // basic interface
  command void startPeriodic( uint32_t dt );
  command void startOneShot( uint32_t dt );
  command void stop();
  event void fired();

  // extended interface omitted (all commands)
}

Looking over the interfaces for Boot, Leds, and Timer, we can see that since BlinkC uses those interfaces it must implement handlers for the Boot.booted() event, and the Timer.fired() event. The Leds interface signature does not include any events, so BlinkC need not implement any in order to call the Leds commands. Here, again, is BlinkC's implementation of Boot.booted():


apps/Blink/BlinkC.nc:
  event void Boot.booted()
  {
    call Timer0.startPeriodic( 250 );
    call Timer1.startPeriodic( 500 );
    call Timer2.startPeriodic( 1000 );
  }

그럼 여기서 BlinkC가 꼭 구현해야 하는 이벤트는 어떤것이 있을까요? 위에서 보면 알 수 있으시겠지만.
여기서 구현해야 하는 Event는 Boot.booted() Timer.fired() 이벤트가 있습니다.그럼 BlinkC가 구현 하고 있는 Boot.booted() 이벤트를 보도록 하죠.

apps/Blink/BlinkC.nc:
  event void Boot.booted()
  {
    call Timer0.startPeriodic( 250 );
    call Timer1.startPeriodic( 500 );
    call Timer2.startPeriodic( 1000 );
  }

BlinkC는 세개의 타이머 객체를 사용하고 있으며, booted() 이벤트는 세개를 시작 시키는 역활을 하고 있습니다. startPeriodic 은 타이머를 시작 시키며, ()안의 숫자는 MillicSecond를 의미합니다.(<TMilli> 객체 생성시 결정) ()안의 숫자와 객체 생성시 정해진 단위로 타이머는 발생됩니다.

call이란 키워드는 command를 실행 할때 쓰며, 역으로 이벤트 전달시에는 signal을 사용합니다. 일단 BlinkC에는 없으니 넘어가도록 하겠습니다.

 event void Timer0.fired()
  {
    dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string());
    call Leds.led0Toggle();
  }
 
  event void Timer1.fired()
  {
    dbg("BlinkC", "Timer 1 fired @ %s \n", sim_time_string());
    call Leds.led1Toggle();
  }
 
  event void Timer2.fired()
  {
    dbg("BlinkC", "Timer 2 fired @ %s.\n", sim_time_string());
    call Leds.led2Toggle();
  }

앞에서 언급 한것 처럼 이벤트의 처리는 사용자에서 하도록 되어있으므로 위와 같이 BlinkC에서 Timer.fired() 이벤트를 처리 해야 합니다. 그리고 함수의 선언은 interface.function 식으로 구분을 확실히 해야 합니다.

, .