正确版本程序
- 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