senderm.nc

来自「主要用于无线传感网络的编写的书籍.对于初学者有着很大的用处」· NC 代码 · 共 75 行

NC
75
字号
module senderM {  provides {    interface StdControl;  }  uses {    interface SendMsg as tx;    interface ReceiveMsg as rx;    interface Leds as leds;    interface Timer as ledTimer;    interface Timer as timer;  }}implementation {#include "config.h"  TOS_Msg txBuf;  bool txPending;  command result_t StdControl.init() {    call leds.init();    txPending = false;    txBuf.data[0] = 0x1;    txBuf.data[1] = 0x2;    txBuf.data[2] = 0x3;    txBuf.data[3] = 0x4;    txBuf.length = 4;    return SUCCESS;  }  command result_t StdControl.start() {    call leds.redOn();    call leds.greenOn();    call leds.yellowOn();    call ledTimer.start(TIMER_ONE_SHOT, 500);    call timer.start(TIMER_REPEAT, 1500);    return SUCCESS;  }  command result_t StdControl.stop() {    return SUCCESS;  }    event result_t ledTimer.fired() {    call leds.redOff();    call leds.greenOff();    call leds.yellowOff();    return SUCCESS;  }  event result_t timer.fired() {    bool drop = true;    atomic {      if (!txPending) {        drop = false;        txPending = true;      }    }    if (drop) return SUCCESS;    call leds.greenOn();    call tx.send(TOS_UART_ADDR, txBuf.length, &txBuf);    return SUCCESS;  }  event result_t tx.sendDone(TOS_MsgPtr m, result_t success) {    atomic { txPending = false; }    call leds.greenOff();    return SUCCESS;  }  event TOS_MsgPtr rx.receive(TOS_MsgPtr m) {    call leds.yellowOn();    call ledTimer.start(TIMER_ONE_SHOT, 300);    return m;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?