Benchmark庫的建立01:數組越界bug

正確版本程序

  1. tinyos-2.x/apps/Oscilloscope

程序描述

  1. 節點週期性啓動傳感器採集數據,傳感器收集10個數據之後通過無線發送給基站節點;
  2. 無線開啓失敗或者採集數據失敗時切換LED0的狀態;節點成功發送數據時切換LED1的狀態;節點接收到消息時切換LED2的狀態。

Avrora運行程序

  1. alias avrora=’java -jar avrora-beta-1.7.113.jar -colors=false -banner=false’;

  2. SENSORBOARD=mts300 make mica2;

  3. mv build/mica2/main.exe os.elf;

  4. avrora -platform=mica2 -monitors=leds,packet -seconds=10 -simulation=sensor-network -nodecount=1 -sensor-data=”light”:0:. os.elf 。

運行結果分析(正確版本)

這裏寫圖片描述

  1. 能正確發送傳感器採集的數據;
  2. LED0,LED1、LED2切換結果正確。

bug版本程序

  1. tinyos-2.x/apps/bm_Oscilloscope

程序修改的部分

  1. event void Timer.fired()事件中註釋掉數組索引置0操作;
  2. 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的顯現條件

  1. 傳感器採集的數據大於10

Bug症狀
這裏寫圖片描述

  1. 只能發送一組(10個)傳感器採集的數據;
  2. LED1的狀態始終不切換,表示之後無法成功通過無線發送採集的數據;
  3. 運行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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章