【TestAppC.nc】
configuration TestAppC
{
}
implementation
{
components TestC, MainC;
components new TimerMilliC() as t0;
TestC.Boot -> MainC.Boot;
TestC.t0 -> t0;
}
【TestC.nc】
#include <printf.h>
module TestC
{
uses interface Boot;
uses interface Timer<TMilli> as t0;
}
implementation
{
uint8_t a = 250;
uint16_t b = 65530u; // 在数字后面加u表示unsigned, 可消除相关警告
uint32_t c = 4294967290u;
event void Boot.booted(void)
{
printf("Hello World!\n");
printfflush(); // 必须执行这个函数, 否则由于缓存, 发送的内容可能不能及时显示到屏幕上
call t0.startPeriodic(1000);
}
event void t0.fired(void)
{
printf("a=%u, b=%u, c=%lu\n", a, b, c);
printfflush();
a++;
b++;
c++;
}
}
【Makefile】
COMPONENT = TestAppC
CFLAGS += -I$(TOSDIR)/lib/printf
include $(MAKERULES)
【run.sh】
java net.tinyos.tools.PrintfClient -comm serial@/dev/ttyUSB0:telosb