設置 | 登錄 | 註冊

目前共有6篇帖子。

【程序】TinyOS中的printf語句的使用

1樓 巨大八爪鱼 2016-8-4 16:17
【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
2樓 巨大八爪鱼 2016-8-4 16:19
【命令】
編譯:make telosb
編譯並燒寫:make telosb install
查看串口輸出信息:./run.sh
(按Ctrl+C退出)
3樓 巨大八爪鱼 2016-8-4 16:20
【運行結果】
4樓 巨大八爪鱼 2016-8-4 16:24
程序每隔1秒鐘發送一次信息。
按下節點上的RESET按鈕後,可能因數據包突然中斷導致接收端輸出bad packet的信息,屬正常情況。
從運行結果可以看出,uint8_t的最大值為255,uint16_t的最大值為65535,uint32_t的最大值為4294967295。
如果編譯程序時出現unsigned的警告,在數字後面加上字母u可消除警告。
5樓 巨大八爪鱼 2016-8-4 17:29

將串口從虛擬機中拔出,然後在Windows環境下打開串口,可以發現每次接收到的數據很複雜,每次都接收到41位元組內容,並且字符串的開頭"a="從第10個字節處開始。
6樓 巨大八爪鱼 2016-8-4 17:44

內容轉換:

回覆帖子
內容:
用戶名: 您目前是匿名發表。
驗證碼:
看不清?換一張
©2010-2025 Purasbar Ver3.0 [手機版] [桌面版]
除非另有聲明,本站採用知識共享署名-相同方式共享 3.0 Unported許可協議進行許可。