正確版本程序
- tinyos-2.x/apps/Oscilloscope
程序描述
- 節點週期性啓動傳感器採集數據,傳感器收集10個數據之後通過無線發送給基站節點;
- 無線開啓失敗或者採集數據失敗時切換LED0的狀態;節點成功發送數據時切換LED1的狀態;節點接收到消息時切換LED2的狀態。
Avrora運行程序
alias avrora=’java -jar avrora-beta-1.7.113.jar -colors=false -banner=false’;
SENSORBOARD=mts300 make mica2;
mv build/mica2/main.exe os.elf;
avrora -platform=mica2 -monitors=leds,packet -seconds=10 -simulation=sensor-network -nodecount=1 -sensor-data=”light”:0:. os.elf 。
運行結果分析(正確版本)
- 能正確發送傳感器採集的數據;
- LED0,LED1、LED2切換結果正確。
bug版本程序
- tinyos-2.x/apps/bm_Oscilloscope
程序修改的部分
- event void Timer.fired()事件中註釋掉數組索引置0操作;
- event void Read.readDone(error_t result, uint16_t data)事件中添加數組越界判斷操作:
if(reading >= NREADINGS) {
printf("Error:out of Bound, please check the index of the array!\n");
}
bug的顯現條件
- 傳感器採集的數據大於10
Bug症狀
- 只能發送一組(10個)傳感器採集的數據;
- LED1的狀態始終不切換,表示之後無法成功通過無線發送採集的數據;
- 運行net.tinyos.tools.PrintClient程序會顯示數組越界信息:Error:out of Bound, please check the index of the array!
注:PrintfClient程序的使用:
1、引入庫文件:#include “printf.h”
2、在makefile文件中引入:修改makefile爲:
COMPONENT=TestPrintfAppC
CFLAGS += -I$(TOSDIR)/lib/printf
include $(MAKERULES
3、通過-monitors=serial -port=2390綁定一個端口,並重新啓動一個Cygwin執行程序java net.tinyos.tools.PrintClient -comm network@localhost:2390