?? tempmonm.nc
字號:
/*
* TempMonM.nc - The implementation module for the TempMon application
*
* @author Geoff Martin
* @date 18th April 2004
* @version 1.0
*/
includes TempMon;
module TempMonM
{
provides
{
interface StdControl;
}
uses
{
interface Send;
interface ADC;
interface Timer;
interface GlobalTime;
interface StdControl as RouterControl;
interface StdControl as TimerControl;
interface StdControl as SyncControl;
interface StdControl as TempControl;
}
}
implementation
{
norace uint16_t sensorReading; // Holds current sensor reading
bool sendBusy; // Holds status of send
TOS_Msg mhMsg; // Message to use when sending data
/*---------------------------------------------------------------------
* Tasks
*---------------------------------------------------------------------*/
/*
* SendData - This task sends the current sensor reading over the network
*/
task void sendData()
{
uint16_t length;
TempMonMsg *pDataMsg = (TempMonMsg *) call Send.getBuffer(&mhMsg, &length);
// Don't send if already sending
if (sendBusy == TRUE)
{
return;
}
// Store data in message
pDataMsg->address = TOS_LOCAL_ADDRESS;
pDataMsg->timestamp = call GlobalTime.getGlobalTime();
pDataMsg->reading = sensorReading;
// Send data
if ((call Send.send(&mhMsg, sizeof(TempMonMsg))) == SUCCESS)
{
atomic sendBusy = TRUE;
dbg(DBG_TEMP, "TempMonM - Message sent successfully\n");
}
else
{
dbg(DBG_TEMP, "TempMonM - Message not sent\n");
}
}
/*---------------------------------------------------------------------
* Provided Interface Commands
*---------------------------------------------------------------------*/
/*
* StdControl
*/
command result_t StdControl.init()
{
sendBusy = FALSE;
sensorReading = 0;
call RouterControl.init();
call TimerControl.init();
call TempControl.init();
call SyncControl.init();
return SUCCESS;
}
command result_t StdControl.start()
{
call RouterControl.start();
call TimerControl.start();
call TempControl.start();
call SyncControl.start();
call ADC.getData(); // Get reading from the ADC
return call Timer.start(TIMER_REPEAT, TIMER_RATE);
}
command result_t StdControl.stop()
{
call RouterControl.stop();
call TimerControl.stop();
call TempControl.stop();
call SyncControl.stop();
return call Timer.stop();
}
/*---------------------------------------------------------------------
* Used Interface Events
*---------------------------------------------------------------------*/
/*
* Send
*/
// This event fires when sending is done
event result_t Send.sendDone(TOS_MsgPtr msg, result_t success)
{
atomic sendBusy = FALSE;
return SUCCESS;
}
/*
* ADC
*/
// This event fires when data is ready
async event result_t ADC.dataReady(uint16_t data)
{
dbg(DBG_TEMP, "TempMonM - Sensor reading taken from ADC\n");
atomic sensorReading = data;
return SUCCESS;
}
/*
* Timer
*/
// This event fires when the timer fires
event result_t Timer.fired()
{
call ADC.getData(); // Get reading from the ADC
// Send data if and only if the mote is syncronised to global time
if (call GlobalTime.isSynchronised() == SUCCESS)
{
post sendData();
}
return SUCCESS;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -