TinyOS 传感与单跳网络技术解析
1. 传感技术
在传感领域,我们主要探讨黑暗检测和传感器组件相关的内容。
1.1 黑暗检测
黑暗检测功能可以通过 DarkC 模块实现。以下是相关代码:
enum { DARK_INTERVAL = 256, DARK_THRESHOLD = 200 }; event void Boot.booted() { call TheftTimer.startPeriodic(DARK_INTERVAL); } event void TheftTimer.fired() { call Light.read(); // Initiate split - phase light sampling } /* Light sample completed. Check if it indicates theft */ event void Light.readDone(error_t ok, uint16_t val) { if (ok == SUCCESS && val < DARK_THRESHOLD) call Leds.led2On(); /* ALERT! ALERT! */ else call Leds.led2Off(); /* Don’t leave LED permanently on */ }DarkC 模块在启动事件中发起周期性的采样。每秒四次,TheftTimer.fired