/********************************************************************
Copyright (C), 2006-2007, by Enoch.
FileName: SensorBoardApp.h
Author: Enoch
Version: 1.0.0.0
Date: 2006 09 01
Description: Hardware specific definitions for the MTS300/310.
*********************************************************************/
#define MTS310
#define FEATURE_SOUNDER 1
// Define SOUND_STATE_CHANGE one of two ways:
// One time sound at test init ==> FALSE
// Continuous beeping throughout ==> !sound_state
#define SOUND_STATE_CHANGE FALSE
//#define SOUND_STATE_CHANGE !sound_state
// crossbow sensor board id
#ifndef MTS310
#define SENSOR_BOARD_ID 0x83 //MTS300 sensor board id
#else
#define SENSOR_BOARD_ID 0x84 //MTS300 sensor board id
#endif
/********************************************************************
Copyright (C), 2006-2007, by Enoch.
FileName: TestSouder.h
Author: Enoch
Version: 1.0.0.0
Date: 2006 09 01
Description: Hardware specific definitions for the MTS300/310.
*********************************************************************/
enum
{
INITIAL_TIMER_RATE = 10,
INITIAL_TIMER_REAE_STEP = 8
};
enum
{
BASE_ADDRESS = 0
};
typedef struct SurgeMsg
{
uint8_t addr;
uint16_t seq;
uint16_t sound;
} __attribute__ ((packed))SurgeMsg;
enum
{
AM_SURGEMSG = 17
};
/********************************************************************
Copyright (C), 2006-2007, by Enoch.
FileName: TestSouder.nc
Author: Enoch
Version: 1.0.0.0
Date: 2006 09 01
Description: Components for testing the souder.
*********************************************************************/
includes SensorBoardApp;
includes TestSounder;
configuration TestSounder
{
// this module does not provide any interface
}
implementation
{
components Main, TestSounderM, TimerC, GenericComm as Comm, LedsC, MicC;
Main.StdControl -> TestSounderM;
Main.StdControl -> Comm;
TestSounderM.TimerSend -> TimerC.Timer[unique("timer")];
TestSounderM.SendSound -> Comm.SendMsg[AM_SURGEMSG];
TestSounderM.ReceiveSound -> Comm.ReceiveMsg[AM_SURGEMSG];
TestSounderM.UARTSend -> Comm.SendMsg[AM_SURGEMSG+2];
/* Mic Controller */
TestSounderM.MicControl -> MicC;
TestSounderM.Mic -> MicC;
TestSounderM.MicADC ->MicC;
TestSounderM.Leds -> LedsC;
TestSounderM.TimerSend -> TimerC.Timer[unique("Timer")];
}
/********************************************************************
Copyright (C), 2006-2007, by Eonch.
FileName: TestSouderM.nc
Author: Eonch
Version: 1.0.0.0
Date: 2006 09 01
Description: Implementation for testing the souder.
*********************************************************************/
includes sensorboard;
includes TestSounder;
module TestSounderM
{
provides
{
interface StdControl;
}
uses
{
interface SendMsg as SendSound;
interface ReceiveMsg as ReceiveSound;
interface SendMsg as UARTSend;
// Mic
interface StdControl as MicControl;
interface Mic;
interface ADC as MicADC;
interface Timer as TimerSend;
interface Leds;
}
}
implementation
{
TOS_Msg UARTSendData, MoteSendData;
uint16_t seq;
enum { START, BUSY, SOUND_DONE};
enum { SENSOR_ID = 0, PACKET_ID, NODE_ID=2, RSVD,
VREF=4, THERM =6, PHOTO = 8, MIC = 10,
ACCEL_X=12, ACCEL_Y=14, MAG_X=16, MAG_Y=18 };
command result_t StdControl.init()
{
seq = 0;
call Leds.init();
call MicControl.init();
call Mic.muxSel(1); // Set the mux so that raw microhpone output is selected
call Mic.gainAdjust(64); // Set the gain of the microphone.
return SUCCESS;
}
command result_t StdControl.start()
{
call Leds.redOn();
if (TOS_LOCAL_ADDRESS != BASE_ADDRESS)
{
seq = 0;
call MicControl.start();
call TimerSend.start(TIMER_REPEAT, INITIAL_TIMER_RATE);
call Leds.greenOn();
}
return SUCCESS;
}
command result_t StdControl.stop()
{
call TimerSend.stop();
return SUCCESS;
}
event result_t TimerSend.fired()
{
if (TOS_LOCAL_ADDRESS != BASE_ADDRESS)
{
call MicADC.getData();
}
return SUCCESS;
}
/****************************************************************************
* MicroPhone ADC data ready
*****************************************************************************/
async event result_t MicADC.dataReady(uint16_t data)
{
SurgeMsg* msg = (SurgeMsg *)MoteSendData.data;
// Data
atomic
{
msg->addr = TOS_LOCAL_ADDRESS;
}
msg->seq = ++seq;
msg->sound = data;
call SendSound.send(BASE_ADDRESS, sizeof(SurgeMsg), &MoteSendData);
call Leds.yellowToggle();
return SUCCESS;
}
event result_t SendSound.sendDone(TOS_MsgPtr msg, result_t success)
{
call Leds.greenToggle();
return SUCCESS;
}
// Motes Reciece Message
event TOS_MsgPtr ReceiveSound.receive(TOS_MsgPtr msgptr)
{
/* Mote 0 for UART */
if (TOS_LOCAL_ADDRESS == BASE_ADDRESS)
{
SurgeMsg* msg = (SurgeMsg *)msgptr->data;
SurgeMsg* uart_msg = (SurgeMsg *)UARTSendData.data;
if (((SurgeMsg*)msgptr->data)->addr == BASE_ADDRESS)
{
return msgptr;
}
uart_msg->addr = msg->addr;
uart_msg->sound = msg->sound;
uart_msg->seq = msg->seq;
/* Upstream the data */
call UARTSend.send(TOS_UART_ADDR, sizeof(SurgeMsg), &UARTSendData);
}
/* Node ID > 1 process */
else
{
}
return msgptr;
}
// UART Send Message
event result_t UARTSend.sendDone(TOS_MsgPtr msg, result_t success)
{
call Leds.yellowToggle();
return SUCCESS;
}
}
/********************************************************************
Copyright (C), 2006-2007, by Eonch.
FileName: Makefile
Author: Eonch
Version: 1.0.0.0
Date: 2006 09 01
Description: Implementation for testing the souder.
*********************************************************************/
# $Id: Makefile, v1.0 2006/09/01 By Enoch Exp $
XBOWROOT=%T/../contrib/xbow/tos
COMPONENT=TestSounder
SENSORBOARD=mts310
# For MICAZ
PFLAGS+= -I../../beta/tos/lib/CC2420Radio -I%T/lib/Broadcast -I%T/lib/Attributes
PFLAGS= -I$(XBOWROOT)/interfaces -I$(XBOWROOT)/system -I$(XBOWROOT)/platform/$(PLATFORM) -I$(XBOWROOT)/lib -I$(XBOWROOT)/sensorboards/$(SENSORBOARD)
include ../MakeXbowlocal
include ${TOSROOT}/tools/make/Makerules
0 评论:
发表评论