Download Wireless Sensor Networks for Monitoring Cracks in Structures

Transcript
Wireless Sensor Networks for
Monitoring Cracks in Structures:
Source Code and Configuration
Files
Mathew P. Kotowsky
Contents
Chapter 1. MICA2-Based Wireless ACM Version 1 Software:
Modification of SenseLightToLog
1. MDA300Logger Directory
2. java Directory
1
2
27
Chapter 2. MICA2-Based Wireless ACM Version 2 Software:
Modification of XMDA300
1. xbow/apps/XMesh/XMDA300 directory
2. xbow/tos/sensorboards/mda300 directory
3. xbow/tos/sensorboards/mda300 directory
37
38
53
64
Chapter 3. MICA2-Based Wireless ACM Version 3 Software:
Modification Version 2 XMDA300: Shake ’n Wake
1. MICA2 Software
1.1. xbow/tos/XLib directory
1.2. xbow/apps/XMesh/XMDA300 directory
2. UC-7420 Software
2.1. xbow/beta/tools/src/xcmd directory
2.2. xbow/beta/tools/src/xcmd/apps directory
2.3. xbow/beta/tools/src/xlisten/boards directory
2.4. xbow/beta/tools/src/xlisten directory
77
78
78
81
97
97
107
113
120
Chapter 4. ēKo mote-based wireless ACPS software
1. CPA crack propagation pattern: cpa.xml
2. CPC crack propagation pattern: cpc.xml
133
134
137
i
CHAPTER 1
MICA2-Based Wireless ACM Version 1 Software:
Modification of SenseLightToLog
This appendix contains all software used to program the MICA2 motes
for Version 1 of the MICA2-based wireless ACM system. This appendix is organized by software directory and only the modified files are
included.
1
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
2
1. MDA300Logger Directory
MDA300Logger i s a s o f t w a r e a p p l i c a t i o n d e s i g n e d t o t a k e r e a d i n g s from a
Crossbow MDA300 s e n s o r board and s t o r e them on t h e EEPROM memory on a
Crossbow Mica 2 mote u n t i l such time a s t h e y a r e u p l o a d e d o v e r t h e r a d i o
by a PC r u n n i n g t h e B c a s t I n j e c t j a v a a p p l i c a t i o n .
I t s modular and
command−p r o c e s s i n g s t r u c t u r e a r e based on SenseLightToLog , and t h e r e f o r e
has a l l t h e same d e p e n d e n c i e s a s t h a t a p p l i c a t i o n , with t h e a d d i t i o n o f
t h e MDA300− s p e c i f i c d e p e n d e n c i e s t h a t a r e s p e c i f i e d i n each f i l e .
MDA300Logger a l s o u s e s a s l i g h t l y m o d i f i e d v e r s i o n o f t h e same d r i v e r
used f o r XSensorMDA300 .
MDA300Logger r e q u i r e s a t l e a s t one ’ remote ’ mote t o have t h e
MDA300Logger a p p l i c a t i o n i n s t a l l e d on i t , one ’ base ’ mote on a
programming board t o have TOSBase i n s t a l l e d on i t , and one PC c o n n e c t e d
t o t h e programming board ( e i t h e r d i r e c t l y o r v i a a network ) r u n n i n g t h e
m o d i f i e d v e r s i o n o f B c a s t I n j e c t i n o r d e r t o s t a r t and s t o p t h e t e s t and
u p lo a d data .
1. MDA300LOGGER DIRECTORY
COMPONENT=MDA300Logger
SENSORBOARD=mda300
PFLAGS= −I . . / . . / t o s / i n t e r f a c e s
\
−I . . / . . / t o s / system \
−I . . / . . / t o s / l i b \
−I . . / . . / t o s / s e n s o r b o a r d s / $ (SENSORBOARD) \
−I . . / . . / t o s / p l a t f o r m / mica2 \
PROGRAMMER EXTRA FLAGS = −v=2
i n c l u d e . . / MakeXbowlocal
i n c l u d e $ {TOSROOT}/ apps / M a k e r u l e s
3
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
4
/*
* This s o f t w a r e i s l a r g e l y based on s o f t w a r e w r i t t e n by t h e U n i v e r s i t y o f
* C a l i f o r n i a . As p e r t h e i m p l i e d l i c e n s e agreement , t h e o r i g i n a l c o p y r i g h t
* n o t i c e i s below .
*/
/*
* ” C o p y r i g h t ( c ) 2000 −2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a .
* All rights reserved .
*
* P e r m i s s i o n t o use , copy , modify , and d i s t r i b u t e t h i s s o f t w a r e and i t s
* documentation f o r any purpose , w i t h o u t f e e , and w i t h o u t w r i t t e n agreement i s
* h e r e b y g r a n t e d , p r o v i d e d t h a t t h e above c o p y r i g h t n o t i c e , t h e f o l l o w i n g
* two p a r a g r a p h s and t h e a u t h o r ap p ea r i n a l l c o p i e s o f t h i s s o f t w a r e .
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT , SPECIAL , INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER I S
* ON AN ”AS I S ” BASIS , AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS . ”
*
* C o p y r i g h t ( c ) 2002 −2003 I n t e l C o r p o r a t i o n
* All rights reserved .
*
* This f i l e i s d i s t r i b u t e d under t h e terms i n t h e a t t a c h e d INTEL−LICENSE
* f i l e . I f you do not f i n d t h e s e f i l e s , c o p i e s can be found by w r i t i n g t o
* I n t e l R e s e a r c h B e r k e l e y , 2150 S h a t t u c k Avenue , S u i t e 1 3 0 0 , B e r k e l e y , CA,
* 94704. Attention :
Int e l License Inquiry .
*/
/*
* MDA300Logger . nc i s based on SenseLightToLog . nc w r i t t e n by
* David C u l l e r and Su Ping − I n t e l R e s e a r c h B e r k e l e y Lab
* Date :
7/11/2002
*
* M o d i f i c a t i o n s by :
* Hasan Ozer and Mat Kotowsky − N o r t h w e s t e r n U n i v e r s i t y
* November , 2004
*
*/
i n c l u d e s sensorboardApp ;
c o n f i g u r a t i o n MDA300Logger {
provides i n t e r f a c e Sensing ;
}
implementation {
1. MDA300LOGGER DIRECTORY
components Main , MDA300LoggerM , SimpleCmd , LedsC , SamplerC ;
components GenericComm a s Comm, TimerC , Logger ;
components HPLPowerManagementM ;
Main . S t d C o n t r o l −>MDA300LoggerM ;
MDA300LoggerM . Leds −> LedsC ;
MDA300LoggerM . Timer −> TimerC . Timer [ u n i q u e ( ” Timer ” ) ] ;
MDA300LoggerM . LoggerWrite −> Logger . LoggerWrite ;
MDA300LoggerM . PowerEnable −> HPLPowerManagementM . Enable ;
MDA300LoggerM .Comm −> Comm;
MDA300LoggerM . Logger −> Logger ;
S e n s i n g = MDA300LoggerM . S e n s i n g ;
// Sampler Communication
MDA300LoggerM . S a m p l e r C o n t r o l −> SamplerC . S a m p l e r C o n t r o l ;
MDA300LoggerM . Sample −> SamplerC . Sample ;
// s u p p o r t f o r p l u g and p l a y
MDA300LoggerM . PlugPlay −> SamplerC . PlugPlay ;
}
5
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
6
/*
* This s o f t w a r e i s l a r g e l y based on s o f t w a r e w r i t t e n by t h e U n i v e r s i t y o f
* C a l i f o r n i a . As p e r t h e i m p l i e d l i c e n s e agreement , t h e o r i g i n a l c o p y r i g h t
* n o t i c e i s below .
*/
/*
* ” C o p y r i g h t ( c ) 2000 −2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a .
* All rights reserved .
*
* P e r m i s s i o n t o use , copy , modify , and d i s t r i b u t e t h i s s o f t w a r e and i t s
* documentation f o r any purpose , w i t h o u t f e e , and w i t h o u t w r i t t e n agreement i s
* h e r e b y g r a n t e d , p r o v i d e d t h a t t h e above c o p y r i g h t n o t i c e , t h e f o l l o w i n g
* two p a r a g r a p h s and t h e a u t h o r ap p ea r i n a l l c o p i e s o f t h i s s o f t w a r e .
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT , SPECIAL , INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER I S
* ON AN ”AS I S ” BASIS , AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS . ”
*
* C o p y r i g h t ( c ) 2002 −2003 I n t e l C o r p o r a t i o n
* All rights reserved .
*
* This f i l e i s d i s t r i b u t e d under t h e terms i n t h e a t t a c h e d INTEL−LICENSE
* f i l e . I f you do not f i n d t h e s e f i l e s , c o p i e s can be found by w r i t i n g t o
* I n t e l R e s e a r c h B e r k e l e y , 2150 S h a t t u c k Avenue , S u i t e 1 3 0 0 , B e r k e l e y , CA,
* 94704. Attention :
Int e l License Inquiry .
*/
/ **
* The MDA300Logger module i s d e s g i n e d t o t a k e r e a d i n g s from a Crossbow
* MDA300 s e n s o r board and s t o r e them i n t h e f l a s h memory o f a Mica2
* mote u n t i l such time a s t h e u s e r downloads t h e data o v e r t h e w i r e l e s s
* r a d i o u s i n g a j a v a a p p l i c a t i o n on a PC .
*/
includes sensorboard ;
module MDA300LoggerM {
provides i n t e r f a c e StdControl ;
provides i n t e r f a c e Sensing ;
uses {
interface
interface
interface
interface
S t d C o n t r o l a s Comm;
S t d C o n t r o l a s Logger ;
Leds ;
Timer a s Timer ;
1. MDA300LOGGER DIRECTORY
i n t e r f a c e LoggerWrite ;
i n t e r f a c e ProcessCmd a s CmdExecute ;
// Sampler Communication
i n t e r f a c e StdControl as SamplerControl ;
i n t e r f a c e Sample ;
i n t e r f a c e PowerManagement ;
// s u p p o r t f o r p l u g and p l a y
command r e s u l t t PlugPlay ( ) ;
command r e s u l t t PowerEnable ( ) ;
}
}
implementation
{
#d e f i n e ANALOG SAMPLING TIME
#d e f i n e MISC SAMPLING TIME
#d e f i n e READY TEMPERATURE 0 x01
#d e f i n e READY HUMIDITY
0 x02
0 x04
#d e f i n e READY BATTERY
#d e f i n e READY DATA
0 x08
#d e f i n e LINE READY
0x0F
#d e f i n e
#d e f i n e
#d e f i n e
#d e f i n e
#d e f i n e
10
15
TIME POS
0
SECS POS
2
SAMPLE POS
4
BATT POS
6
SCRATCH POS
7
#d e f i n e TEMP POS
#d e f i n e HUMID POS
#d e f i n e DATA POS
4
5
6
#d e f i n e RADIO TICK INTERVAL 30
// d e c l a r e module s t a t i c v a r i a b l e s h e r e
u i n t 1 6 t currentRow1 [ 8 ] ;
// c u r r e n t working row 1 o f l o g
u i n t 1 6 t currentRow2 [ 8 ] ;
// c u r r e n t working row 2 o f l o g
u i n t 1 6 t nullDataRow [ 8 ] ;
uint8 t lineStatus ;
s h o r t busy = 0 ;
unsigned i n t nsamples ;
// s a m p l e s l e f t
u n s i g n e d i n t t o t a l s a m p l e s ; // t o t a l s a m p l e s
int8 t record [ 2 5 ] ;
uint32 t time sec ;
uint32 t interval sec ;
unsigned i n t t i c k s = 0 ;
uint32 t secs = 0;
i n t r a d i o C o u n t e r = RADIO TICK INTERVAL ;
i n t rowWaiting = 0 ;
/ **
* I n i t i a l i z e the a p p l i c a t i o n .
7
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
8
* @return I n i t i a l i z a t i o n s t a t u s .
** /
command r e s u l t t S t d C o n t r o l . i n i t ( ) {
c a l l PowerEnable ( ) ;
c a l l SamplerControl . i n i t ( ) ;
c a l l Logger . i n i t ( ) ;
c a l l Comm. i n i t ( ) ;
r e t u r n SUCCESS ;
}
/ **
* I n s e r t a row t h a t i n d i c a t e s t h e b e g i n n i n g o f t h e t e s t
** /
task void writeNullTask ( ) {
c a l l LoggerWrite . append ( ( u i n t 8 t * ) &nullDataRow ) ;
}
/ **
* Start the a p p l i c a t i o n .
* @return S t a r t s t a t u s .
** /
command r e s u l t t S t d C o n t r o l . s t a r t ( ) {
int i ;
c a l l Leds . redOn ( ) ;
f o r ( i =0; i <8; i ++)
nullDataRow [ i ] = 0xFFFF ;
l i n e S t a t u s =0;
r e t u r n rcombine ( c a l l Logger . s t a r t ( ) , c a l l Comm. s t a r t ( ) ) ;
}
/ **
* Stop t h e a p p l i c a t i o n .
* @return Stop s t a t u s .
** /
command r e s u l t t S t d C o n t r o l . s t o p ( ) {
c a l l Logger . s t o p ( ) ;
r e t u r n c a l l Comm. s t o p ( ) ;
}
/ **
* This command b e l o n g s t o t h e <code>S e n s i n g </code> i n t e r f a c e .
* I t s t a r t s the timer to generate p e r i o d i c events .
*
* @return Always r e t u r n s <code>SUCCESS</code>
** /
command r e s u l t t S e n s i n g . s t a r t ( u n s i g n e d l o n g samples ,
unsigned long i n t e r v a l ,
u n s i g n e d l o n g time ) {
i f ( s a m p l e s == 0 )
{
r e t u r n SUCCESS ;
1. MDA300LOGGER DIRECTORY
}
c a l l Leds . r e d O f f ( ) ;
ticks = 0;
secs = 0;
c a l l LoggerWrite . r e s e t P o i n t e r ( ) ;
nsamples = samples ;
t o t a l s a m p l e s = samples ;
t i m e s e c = ( u i n t 3 2 t ) time ;
interval sec = ( uint32 t ) interval ;
i f ( i n t e r v a l s e c >= 3 0 ) // t i m e r w i l l f i r e e v e r y 30 s e c o n d s
c a l l Timer . s t a r t (TIMER REPEAT, 3 0 * 1 0 2 4 ) ;
e l s e // i n t e r v a l s e c < 3 0 , t i m e r w i l l f i r e once a s e c o n d
c a l l Timer . s t a r t (TIMER REPEAT, 1 0 2 4 ) ;
a to m i c {
nullDataRow [ TIME POS ] = t i m e s e c & 0xFFFF ;
nullDataRow [ TIME POS + 1 ] = ( t i m e s e c >> 1 6 ) & 0xFFFF ;
}
post writeNullTask ( ) ;
c a l l SamplerControl . s t a r t ( ) ;
c a l l SamplerControl . stop ( ) ;
r e t u r n SUCCESS ;
}
/ **
* This command b e l o n g s t o t h e <code>S e n s i n g </code> i n t e r f a c e .
* I t t u r n s e v e r y t h i n g o f f when t h e t e s t i s s t o p p e d
*
* @return Always r e t u r n s <code>SUCCESS</code>
** /
command r e s u l t t S e n s i n g . s t o p ( ) {
c a l l Timer . s t o p ( ) ;
s i g n a l S e n s i n g . done ( ) ;
r e t u r n SUCCESS ;
}
/ **
* Event h a n d l e r t o t h e <code>Timer . f i r e d </code> e v e n t .
* @return Always r e t u r n s <code>SUCCESS</code>
** /
e v e n t r e s u l t t Timer . f i r e d ( ) {
int i ;
i f ( i n t e r v a l s e c >= 3 0 ) // t i c k s a r e 30 s e c o n d s a p a r t
{
t i c k s += 3 0 ;
r a d i o C o u n t e r −−;
s e c s += 3 0 ;
i f ( r a d i o C o u n t e r == 0 )
9
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
10
c a l l Comm. s t o p ( ) ;
}
e l s e // i n t e r v a l s e c < 30 s o t i c k s a r e 1 s e c o n d a p a r t
{
t i c k s ++;
s e c s ++;
}
i f ( t i c k s < i n t e r v a l s e c ) / / we haven ’ t accumulated enough s e c o n d s
r e t u r n SUCCESS ;
ticks = 0;
f o r ( i =0; i < 7 ; i ++) // C l e a r c u r r e n t row
{
currentRow1 [ i ] = 0 ;
currentRow2 [ i ] = 0 ;
}
i f ( busy )
{
r e t u r n SUCCESS ;
}
i f ( n s a m p l e s== 0 ) {
c a l l Timer . s t o p ( ) ;
s i g n a l S e n s i n g . done ( ) ;
c a l l Leds . redOn ( ) ;
r e t u r n c a l l Comm. s t a r t ( ) ;
}
// Whenever t i c k s = i n t e r v a l , s t a r t s a m p l e r
c a l l Comm. s t a r t ( ) ;
// t u r n t h e r a d i o on w h i l e t a k i n g a sample
c a l l Leds . greenOn ( ) ;
r a d i o C o u n t e r = RADIO TICK INTERVAL ;
c a l l SamplerControl . s t a r t ( ) ;
i f (1){
a to m i c {
r e c o r d [ 1 4 ] = c a l l Sample . getSample (
0,
TEMPERATURE,
MISC SAMPLING TIME ,
SAMPLER DEFAULT ) ;
r e c o r d [ 1 5 ] = c a l l Sample . getSample (
0,
HUMIDITY,
MISC SAMPLING TIME ,
SAMPLER DEFAULT ) ;
1. MDA300LOGGER DIRECTORY
r e c o r d [ 1 6 ] = c a l l Sample . getSample (
0,
BATTERY,
MISC SAMPLING TIME ,
SAMPLER DEFAULT ) ;
r e c o r d [ 1 7 ] = c a l l Sample . getSample (
7,
ANALOG,
ANALOG SAMPLING TIME,
AVERAGE FOUR
| EXCITATION 25
| EXCITATION 33
| EXCITATION 50
| EXCITATION ALWAYS ON ) ;
busy = 1 ;
}
}
nsamples −−;
r e t u r n SUCCESS ;
}
/ **
* D e f a u l t e v e n t h a n d l e r t o t h e <code>S e n s i n g . done</code> e v e n t .
* @return Always r e t u r n s <code>SUCCESS</code>
** /
d e f a u l t e v e n t r e s u l t t S e n s i n g . done ( ) {
r e t u r n SUCCESS ;
}
t a s k v o i d writeRow1 ( ) {
a to m i c {
c a l l LoggerWrite . append ( ( u i n t 8 t * ) &currentRow1 ) ;
}
}
t a s k v o i d writeRow2 ( ) {
a to m i c {
c a l l LoggerWrite . append ( ( u i n t 8 t * ) &currentRow2 ) ;
rowWaiting = 0 ;
}
}
/ **
* Handle a s i n g l e dataReady e v e n t f o r a l l MDA300 data t y p e s .
*/
e v e n t r e s u l t t Sample . dataReady (
u i n t 8 t channel ,
u i n t 8 t channelType ,
u i n t 1 6 t data )
{
11
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
12
s w i t c h ( channelType ) {
c a s e ANALOG:
switch ( channel ) {
case 7:
a to m i c {
currentRow2 [ DATA POS ] = data ;
l i n e S t a t u s |= READY DATA;
}
break ;
default :
break ;
} // c a s e ANALOG ( c h a n n e l )
break ;
c a s e BATTERY:
a to m i c {
currentRow1 [ BATT POS ] = data ;
l i n e S t a t u s |= READY BATTERY;
}
break ;
c a s e HUMIDITY :
a to m i c {
currentRow2 [ HUMID POS ] = data ;
l i n e S t a t u s |= READY HUMIDITY ;
}
break ;
c a s e TEMPERATURE:
a to m i c {
currentRow2 [ TEMP POS ] = data ;
l i n e S t a t u s |= READY TEMPERATURE;
}
break ;
default :
break ;
}
// s w i t c h ( channelType )
i f ( l i n e S t a t u s == LINE READY)
{
lineStatus = 0;
a to m i c {
currentRow1 [ SAMPLE POS ] = ( u i n t 1 6 t ) n s a m p l e s ;
currentRow1 [ SAMPLE POS + 1 ] = ( u i n t 1 6 t ) t o t a l s a m p l e s ;
// currentRow1 [ SECS POS ] = ( u i n t 1 6 t ) s e c s ;
currentRow1 [ SECS POS ] = s e c s & 0xFFFF ;
currentRow2 [ SECS POS ] = currentRow1 [ SECS POS ] ;
currentRow1 [ SECS POS + 1 ] = ( s e c s >> 1 6 ) & 0xFFFF ;
currentRow2 [ SECS POS + 1 ] = currentRow1 [ SECS POS + 1 ] ;
currentRow1 [ SCRATCH POS ] = 0 x7777 ;
1. MDA300LOGGER DIRECTORY
currentRow1 [ TIME
currentRow2 [ TIME
currentRow1 [ TIME
currentRow2 [ TIME
13
POS ] = t i m e s e c & 0xFFFF ;
POS ] = currentRow1 [ TIME POS ] ;
POS + 1 ] = ( t i m e s e c >> 1 6 ) & 0xFFFF ;
POS + 1 ] = currentRow1 [ TIME POS + 1 ] ;
}
p o s t writeRow1 ( ) ;
rowWaiting =2;
}
r e t u r n SUCCESS ;
}
/ **
* Event h a n d l e r f o r t h e <code>LoggerWrite . writeDone </code> e v e n t .
* T o gg l e t h e y e l l o w LED i f s t a t u s i s t r u e .
*
* @return Always r e t u r n s <code>SUCCESS</code>
** /
e v e n t r e s u l t t LoggerWrite . writeDone ( r e s u l t t s t a t u s ) {
i f ( rowWaiting == 2 )
{
p o s t writeRow2 ( ) ;
}
i f ( rowWaiting == 0 )
{
busy = 0 ;
}
c a l l SamplerControl . stop ( ) ;
c a l l SamplerControl . i n i t ( ) ;
r e t u r n SUCCESS ;
}
/ **
* Event h a n d l e r t o t h e <code>CmdExecute . done</code> e v e n t . Do n o t h i n g .
* @return Always r e t u r n s <code>SUCCESS</code>
** /
e v e n t r e s u l t t CmdExecute . done ( TOS MsgPtr pmsg , r e s u l t t s t a t u s ) {
r e t u r n SUCCESS ;
}
}
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
14
/*
* This s o f t w a r e i s l a r g e l y based on s o f t w a r e w r i t t e n by t h e U n i v e r s i t y o f
* C a l i f o r n i a . As p e r t h e i m p l i e d l i c e n s e agreement , t h e o r i g i n a l c o p y r i g h t
* n o t i c e i s below .
*/
/*
* ” C o p y r i g h t ( c ) 2000 −2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a .
* All rights reserved .
*
* P e r m i s s i o n t o use , copy , modify , and d i s t r i b u t e t h i s s o f t w a r e and i t s
* documentation f o r any purpose , w i t h o u t f e e , and w i t h o u t w r i t t e n agreement i s
* h e r e b y g r a n t e d , p r o v i d e d t h a t t h e above c o p y r i g h t n o t i c e , t h e f o l l o w i n g
* two p a r a g r a p h s and t h e a u t h o r ap p ea r i n a l l c o p i e s o f t h i s s o f t w a r e .
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT , SPECIAL , INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER I S
* ON AN ”AS I S ” BASIS , AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS . ”
*
* C o p y r i g h t ( c ) 2002 −2003 I n t e l C o r p o r a t i o n
* All rights reserved .
*
* This f i l e i s d i s t r i b u t e d under t h e terms i n t h e a t t a c h e d INTEL−LICENSE
* f i l e . I f you do not f i n d t h e s e f i l e s , c o p i e s can be found by w r i t i n g t o
* I n t e l R e s e a r c h B e r k e l e y , 2150 S h a t t u c k Avenue , S u i t e 1 3 0 0 , B e r k e l e y , CA,
* 94704. Attention :
Int e l License Inquiry .
*/
/*
* This s o f t w a r e was s l i g h t l y m o d i f i e d by Hasan Ozer and Mat Kotowsky t o
* i n c l u d e a 3 rd i n t e g e r argument t o t h e s t a r t s e n s i n g command .
It
* r e m a i n s o t h e r w i s e unchanged from t h e o r i g i n a l U n i v e r s i t y o f
* C a l i f o r n i a s o f t w a r e . Contact : kotowsky@northwestern . edu
*/
/ ** C o n f i g u r a t i o n f o r SimpleCmd module .
*
*
*
*
*
*
*
*
*
Author / Contact : t i n y o s −h e l p@ m i l l e nn i u m . b e r k e l e y . edu
Description :
SimpleCmd module d e m o n s t r a t e s a s i m p l e command i n t e r p r e t e r f o r TinyOS
t u t o r i a l ( Lesson 8 in p a r t i c u l a r ) .
I t r e c e i v e s a command message from
i t s RF i n t e r f a c e , which t r i g g e r s a command i n t e r p r e t e r t a s k t o e x e c u t e
t h e command . When t h e command i s f i n i s h e d e x e c u t i n g , t h e component
1. MDA300LOGGER DIRECTORY
15
* s i g n a l s t h e upper l a y e r s with t h e r e c e i v e d message and t h e s t a t u s
* i n d i c a t i n g whether t h e message s h o u l d be f u r t h e r p r o c e s s e d .
*
* As a s i m p l e v e r s i o n ,
i t can o n l y i n t e r p r e t t h e f o l l w o i n g commands :
* Led on ( 1 ) , L e d o f f ( 2 ) , r a d i o q u i e t e r ( 3 ) , r a d i o l o u d e r ( 4 ) ,
* s t a r t s e n s i n g ( 5 ) , and r e a d l o g ( 6 ) . S t a r t s e n s i n g commands w i l l t r i g g e r
* t h e S e n s i n g . s t a r t i n t e r f a c e w h i l e r e a d l o g w i l l r e a d t h e EEPROM with a
* s p e c i f i c l o g l i n e and b r o a d c a s t t h e l i n e o v e r t h e r a d i o when r e a d i s
* done .
*/
i n c l u d e s SimpleCmdMsg ;
c o n f i g u r a t i o n SimpleCmd {
p r o v i d e s i n t e r f a c e ProcessCmd ;
}
implementation {
components Main , SimpleCmdM , MDA300Logger , Logger , TimerC ,
GenericComm a s Comm, PotC , LedsC ;
Main . S t d C o n t r o l −> SimpleCmdM ;
SimpleCmdM . Leds −> LedsC ;
ProcessCmd = SimpleCmdM . ProcessCmd ;
SimpleCmdM . CommControl −> Comm;
SimpleCmdM . ReceiveCmdMsg −> Comm. ReceiveMsg [AM SIMPLECMDMSG ] ;
SimpleCmdM . SendLogMsg −> Comm. SendMsg [AM LOGMSG ] ;
SimpleCmdM . LoggerRead −> Logger ;
SimpleCmdM . Pot −> PotC ;
SimpleCmdM . S e n s i n g −> MDA300Logger . S e n s i n g ;
SimpleCmdM . ReadTimer −> TimerC . Timer [ u n i q u e ( ” Timer ” ) ] ;
}
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
16
/*
* This s o f t w a r e i s l a r g e l y based on s o f t w a r e w r i t t e n by t h e U n i v e r s i t y o f
* C a l i f o r n i a . As p e r t h e i m p l i e d l i c e n s e agreement , t h e o r i g i n a l c o p y r i g h t
* n o t i c e i s below .
*/
/*
tab : 4
* ” C o p y r i g h t ( c ) 2000 −2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a .
* All rights reserved .
*
* P e r m i s s i o n t o use , copy , modify , and d i s t r i b u t e t h i s s o f t w a r e and i t s
* documentation f o r any purpose , w i t h o u t f e e , and w i t h o u t w r i t t e n agreement i s
* h e r e b y g r a n t e d , p r o v i d e d t h a t t h e above c o p y r i g h t n o t i c e , t h e f o l l o w i n g
* two p a r a g r a p h s and t h e a u t h o r ap p ea r i n a l l c o p i e s o f t h i s s o f t w a r e .
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT , SPECIAL , INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER I S
* ON AN ”AS I S ” BASIS , AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS . ”
*
* C o p y r i g h t ( c ) 2002 −2003 I n t e l C o r p o r a t i o n
* All rights reserved .
*
* This f i l e i s d i s t r i b u t e d under t h e terms i n t h e a t t a c h e d INTEL−LICENSE
* f i l e . I f you do not f i n d t h e s e f i l e s , c o p i e s can be found by w r i t i n g t o
* I n t e l R e s e a r c h B e r k e l e y , 2150 S h a t t u c k Avenue , S u i t e 1 3 0 0 , B e r k e l e y , CA,
* 94704. Attention :
Int e l License Inquiry .
*/
/ **
* D e f i n e s an i n t e r f a c e f o r a component t h a t s e n s e s data a t a c e r t a i n
* i n t e r v a l and s c a l e .
*/
i n t e r f a c e Sensing
{
/ **
* S t a r t s e n s i n g data .
* @param n sa m p le s The number o f s a m p l e s t o g a t h e r .
* @param i n t e r v a l s e c The i n t e r v a l ( i n msec ) a t which t o g a t h e r s a m p l e s .
*/
command r e s u l t t s t a r t ( u n s i g n e d l o n g nsamples ,
unsigned long i n t e r v a l s e c ,
unsigned long time sec ) ;
command r e s u l t t s t o p ( ) ;
1. MDA300LOGGER DIRECTORY
/ **
* S i g n a l l e d when s e n s i n g has c o m p l e t e d .
*/
e v e n t r e s u l t t done ( ) ;
}
17
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
18
/*
* This s o f t w a r e i s l a r g e l y based on s o f t w a r e w r i t t e n by t h e U n i v e r s i t y o f
* C a l i f o r n i a . As p e r t h e i m p l i e d l i c e n s e agreement , t h e o r i g i n a l c o p y r i g h t
* n o t i c e i s below .
*/
/*
tab : 4
* ” C o p y r i g h t ( c ) 2000 −2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a .
* All rights reserved .
*
* P e r m i s s i o n t o use , copy , modify , and d i s t r i b u t e t h i s s o f t w a r e and i t s
* documentation f o r any purpose , w i t h o u t f e e , and w i t h o u t w r i t t e n agreement i s
* h e r e b y g r a n t e d , p r o v i d e d t h a t t h e above c o p y r i g h t n o t i c e , t h e f o l l o w i n g
* two p a r a g r a p h s and t h e a u t h o r ap p ea r i n a l l c o p i e s o f t h i s s o f t w a r e .
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT , SPECIAL , INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER I S
* ON AN ”AS I S ” BASIS , AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS . ”
*
* C o p y r i g h t ( c ) 2002 −2003 I n t e l C o r p o r a t i o n
* All rights reserved .
*
* This f i l e i s d i s t r i b u t e d under t h e terms i n t h e a t t a c h e d INTEL−LICENSE
* f i l e . I f you do not f i n d t h e s e f i l e s , c o p i e s can be found by w r i t i n g t o
* I n t e l R e s e a r c h B e r k e l e y , 2150 S h a t t u c k Avenue , S u i t e 1 3 0 0 , B e r k e l e y , CA,
* 94704. Attention :
Int e l License Inquiry .
*/
/*
* This s o f t w a r e was s l i g h t l y m o d i f i e d by Hasan Ozer and Mat Kotowsky t o
* i n c l u d e a 3 rd i n t e g e r argument t o t h e s t a r t s e n s i n g command .
It
* r e m a i n s o t h e r w i s e unchanged from t h e o r i g i n a l U n i v e r s i t y o f
* C a l i f o r n i a s o f t w a r e . Contact : kotowsky@northwestern . edu
*/
/*
* Author :
*
* $\ Id$
*/
/ **
Robert Szewczyk , Su Ping
* @author Robert Szewczyk
* @author Su Ping
*/
1. MDA300LOGGER DIRECTORY
i n c l u d e s SimpleCmdMsg ;
/ **
*
* This i s an enhanced v e r s i o n o f SimpleCmd t h a t u n d e r s t a n d s t h e
* START SENSING and READ LOG commands .
** /
module SimpleCmdM {
provides {
i n t e r f a c e StdControl ;
i n t e r f a c e ProcessCmd ;
}
uses {
i n t e r f a c e Leds ;
i n t e r f a c e Pot ;
i n t e r f a c e ReceiveMsg a s ReceiveCmdMsg ;
i n t e r f a c e S t d C o n t r o l a s CommControl ;
i n t e r f a c e LoggerRead ;
i n t e r f a c e SendMsg a s SendLogMsg ;
i n t e r f a c e Sensing ;
i n t e r f a c e Timer a s ReadTimer ;
}
}
implementation
{
// d e c l a r e module s t a t i c v a r i a b l e s h e r e
TOS MsgPtr cur msg ;
// The c u r r e n t command message
// The c u r r e n t l o g message
TOS Msg l o g m s g ;
bool send pending ;
// TRUE i f a message send i s p e n d i n g
bool eeprom read pending ;
// TRUE i f an EEPROM r e a d i s p e n d i n g
TOS Msg b u f ;
// Fr e e b u f f e r f o r message r e c e p t i o n
int reads ;
i n t readAttempts ;
/ **
* This t a s k e v a l u a t e s a command and e x e c u t e s i t .
* S i g n a l s ProcessCmd . sendDone ( ) when t h e command has c o m p l e t e d .
* @return Return : None
** /
task void cmdInterpret ( ) {
s t r u c t LogMsg * lm ;
s t r u c t SimpleCmdMsg * cmd = ( s t r u c t SimpleCmdMsg * ) cur msg−>data ;
r e s u l t t s t a t u s = SUCCESS ;
// do l o c a l p a c k e t m o d i f i c a t i o n s :
// update t h e hop count and p a c k e t s o u r c e
cmd−>h o p c o u n t++;
cmd−>s o u r c e = TOS LOCAL ADDRESS ;
19
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
20
// Execute t h e command
s w i t c h ( cmd−>a c t i o n ) {
c a s e LED ON :
c a l l Leds . yellowOn ( ) ;
break ;
c a s e LED OFF :
c a l l Leds . y e l l o w O f f ( ) ;
break ;
c a s e RADIO QUIETER :
c a l l Pot . i n c r e a s e ( ) ;
break ;
c a s e RADIO LOUDER :
c a l l Pot . d e c r e a s e ( ) ;
break ;
c a s e START SENSING :
// I n i t i a l i z e t h e s e n s i n g component , and s t a r t r e a d i n g data from i t .
lm = ( s t r u c t LogMsg * ) ( l o g m s g . data ) ;
lm−>s o u r c e a d d r = TOS LOCAL ADDRESS ;
i f ( c a l l SendLogMsg . send (TOS BCAST ADDR, s i z e o f ( s t r u c t LogMsg ) , &l o g m s g ) ) {
s e n d p e n d i n g = TRUE;
}
c a l l S e n s i n g . s t a r t ( cmd−>a r g s . s s a r g s . nsamples ,
cmd−>a r g s . s s a r g s . i n t e r v a l ,
cmd−>a r g s . s s a r g s . t i m e s e c ) ;
c a l l LoggerRead . r e s e t P o i n t e r ( ) ;
break ;
c a s e READ LOG:
// Check i f t h e message i s meant f o r us , i f s o i s s u e a s p l i t phase c a l l
// t o t h e l o g g e r
// c a l l Leds . r e d O f f ( ) ;
// c a l l Leds . y e l l o w O f f ( ) ;
reads = 0;
readAttempts = 0 ;
c a l l Sensing . stop ( ) ;
i f ( ( cmd−>a r g s . r l a r g s . d e s t a d d r == TOS LOCAL ADDRESS) &&
( e e p r o m r e a d p e n d i n g == FALSE ) ) {
i f ( c a l l LoggerRead . readNext ( ( ( s t r u c t LogMsg * ) l o g m s g . data)−> l o g ) ) {
// c a l l Leds . yellowOn ( ) ;
e e p r o m r e a d p e n d i n g = TRUE;
}
c a l l ReadTimer . s t a r t (TIMER REPEAT, 1 0 0 ) ;
}
break ;
default :
s t a t u s = FAIL ;
}
s i g n a l ProcessCmd . done ( cur msg , s t a t u s ) ;
}
e v e n t r e s u l t t ReadTimer . f i r e d ( ) {
readAttempts++;
1. MDA300LOGGER DIRECTORY
21
i f ( readAttempts > 3 0 0 ) {
c a l l ReadTimer . s t o p ( ) ;
c a l l Leds . y e l l o w O f f ( ) ;
c a l l Leds . redOn ( ) ;
}
c a l l Leds . y e l l o w T o g g l e ( ) ;
i f ( ! ( eeprom read pending | | send pending )) {
i f ( c a l l LoggerRead . readNext ( ( ( s t r u c t LogMsg * ) l o g m s g . data)−> l o g ) ) {
e e p r o m r e a d p e n d i n g = TRUE;
}
}
r e t u r n SUCCESS ;
}
/ **
* S i g n a l l e d i n r e s p o n s e t o t h e e v e n t from <code>S e n s i n g . done</code >.
* @return Always r e t u r n s <code>SUCCESS</code>
** /
e v e n t r e s u l t t S e n s i n g . done ( ) {
c a l l Leds . y e l l o w O f f ( ) ;
r e t u r n SUCCESS ;
}
/ **
* I n i t i a l i z e the a p p l i c a t i o n .
* @return S u c c e s s o f component i n i t i a l i z a t i o n .
** /
command r e s u l t t S t d C o n t r o l . i n i t ( ) {
cur msg = &b u f ;
s e n d p e n d i n g = FALSE ;
e e p r o m r e a d p e n d i n g = FALSE ;
r e t u r n rcombine ( c a l l CommControl . i n i t ( ) , c a l l Leds . i n i t ( ) ) ;
}
/ **
* Start the a p p l i c a t i o n .
* @return Always r e t u r n s <code>SUCCESS</code>
** /
command r e s u l t t S t d C o n t r o l . s t a r t ( ) {
r e t u r n SUCCESS ;
}
/ **
* Stop t h e a p p l i c a t i o n .
* @return Always r e t u r n s <code>SUCCESS</code>
** /
command r e s u l t t S t d C o n t r o l . s t o p ( ) {
r e t u r n SUCCESS ;
}
/ **
* S i g n a l l e d when t h e l o g has c o m p l e t e d t h e r e a d i n g ,
* and now we ’ r e r e a d y t o send out t h e l o g message .
* @return Always r e t u r n s <code>SUCCESS</code>
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
22
** /
e v e n t r e s u l t t LoggerRead . readDone ( u i n t 8 t * packet , r e s u l t t s u c c e s s ) {
// Send message o n l y i f r e a d was s u c c e s s f u l
s t r u c t LogMsg * lm ;
i f ( s u c c e s s && e e p r o m r e a d p e n d i n g && ! s e n d p e n d i n g ) {
lm = ( s t r u c t LogMsg * ) ( l o g m s g . data ) ;
lm−>s o u r c e a d d r = TOS LOCAL ADDRESS ;
i f ( c a l l SendLogMsg . send (TOS BCAST ADDR, s i z e o f ( s t r u c t LogMsg ) , &l o g m s g ) ) {
// c a l l Leds . redOn ( ) ;
s e n d p e n d i n g = TRUE;
}
}
e e p r o m r e a d p e n d i n g = FALSE ;
// c a l l Leds . y e l l o w O f f ( ) ;
r e a d s ++;
i f ( ( readAttempts >= 1 0 0 ) | | ( r e a d s >= 1 0 0 ) ) {
c a l l ReadTimer . s t o p ( ) ;
c a l l Leds . y e l l o w O f f ( ) ;
c a l l Leds . redOn ( ) ;
}
r e t u r n SUCCESS ;
}
/ **
* Post a t a s k t o p r o c e s s t h e message i n ’ pmsg ’ .
* @return Always r e t u r n s <code>SUCCESS</code>
** /
command r e s u l t t ProcessCmd . e x e c u t e ( TOS MsgPtr pmsg ) {
cur msg = pmsg ;
post cmdInterpret ( ) ;
r e t u r n SUCCESS ;
}
/ **
* C a l l e d upon message r e c e i v e ; i n v o k e s ProcessCmd . e x e c u t e ( ) .
** /
e v e n t TOS MsgPtr ReceiveCmdMsg . r e c e i v e ( TOS MsgPtr pmsg ) {
result t retval ;
TOS MsgPtr r e t = cur msg ;
r e t v a l = c a l l ProcessCmd . e x e c u t e ( pmsg ) ;
i f ( r e t v a l==SUCCESS) {
return ret ;
} else {
r e t u r n pmsg ;
}
}
/ **
* D e f a u l t e v e n t h a n d l e r f o r <code>ProcessCmd . done</code >.
* @return The v a l u e o f ’ s t a t u s ’ .
** /
1. MDA300LOGGER DIRECTORY
23
d e f a u l t e v e n t r e s u l t t ProcessCmd . done ( TOS MsgPtr pmsg , r e s u l t t s t a t u s ) {
return status ;
}
/ **
* R e s e t s e n d p e n d i n g f l a g t o FALSE i n r e s p o n s e t o
* <code>SendLogMsg . sendDone</code >.
* @return The v a l u e o f ’ s t a t u s ’ .
** /
e v e n t r e s u l t t SendLogMsg . sendDone ( TOS MsgPtr pmsg , r e s u l t t s t a t u s ) {
// c a l l Leds . r e d O f f ( ) ;
s e n d p e n d i n g = FALSE ;
return status ;
}
} // end o f i m p l e m e n t a t i o n
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
24
/ * s e n s o r b o a r d . h − hardware s p e c i f i c
*/
// c r o s s b o w s e n s o r board i d
#d e f i n e SENSOR BOARD ID 0 x81
#d e f i n e NUM MSG1 BYTES ( 2 8 )
#d e f i n e NUM MSG2 BYTES ( 8 )
#d e f i n e NUM MSG3 BYTES ( 1 3 )
d e f i n i t i o n s f o r t h e MDA300
//MDA300 s e n s o r board i d
// b y t e s 2−29
// b y t e s 2−9
// b y t e s 2−13
// f o r m a t i s :
// b y t e 1 & 2 : ADC r e a d i n g i n b ig −e n d i a n f o r m a t
enum {
Sample Packet = 6 ,
};
enum {
RADIO TEST,
UART TEST
};
1. MDA300LOGGER DIRECTORY
25
/*
* This s o f t w a r e i s l a r g e l y based on s o f t w a r e w r i t t e n by t h e U n i v e r s i t y o f
* C a l i f o r n i a . As p e r t h e i m p l i e d l i c e n s e agreement , t h e o r i g i n a l c o p y r i g h t
* n o t i c e i s below .
*/
/*
tab : 4
* ” C o p y r i g h t ( c ) 2000 −2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a .
* All rights reserved .
*
* P e r m i s s i o n t o use , copy , modify , and d i s t r i b u t e t h i s s o f t w a r e and i t s
* documentation f o r any purpose , w i t h o u t f e e , and w i t h o u t w r i t t e n agreement i s
* h e r e b y g r a n t e d , p r o v i d e d t h a t t h e above c o p y r i g h t n o t i c e , t h e f o l l o w i n g
* two p a r a g r a p h s and t h e a u t h o r ap p ea r i n a l l c o p i e s o f t h i s s o f t w a r e .
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT , SPECIAL , INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER I S
* ON AN ”AS I S ” BASIS , AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS . ”
*
* C o p y r i g h t ( c ) 2002 −2003 I n t e l C o r p o r a t i o n
* All rights reserved .
*
* This f i l e i s d i s t r i b u t e d under t h e terms i n t h e a t t a c h e d INTEL−LICENSE
* f i l e . I f you do not f i n d t h e s e f i l e s , c o p i e s can be found by w r i t i n g t o
* I n t e l R e s e a r c h B e r k e l e y , 2150 S h a t t u c k Avenue , S u i t e 1 3 0 0 , B e r k e l e y , CA,
* 94704. Attention :
Int e l License Inquiry .
*/
/*
* F i l e Name : SimpleCmd . h
*
* Description :
* This h e a d e r f i l e d e f i n e s t h e AM SIMPLECMDMSG and AM LOGMSG message
* t y p e s f o r t h e SimpleCmd and MDA300Logger a p p l i c a t i o n s .
*/
/*
* This s o f t w a r e was s l i g h t l y m o d i f i e d by Hasan Ozer and Mat Kotowsky t o
* i n c l u d e a 3 rd i n t e g e r argument t o t h e s t a r t s e n s i n g command .
It
* r e m a i n s o t h e r w i s e unchanged from t h e o r i g i n a l U n i v e r s i t y o f
* C a l i f o r n i a s o f t w a r e . Contact : kotowsky@northwestern . edu
*/
enum {
AM SIMPLECMDMSG = 8 ,
AM LOGMSG=9
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
26
};
enum {
LED ON = 1 ,
LED OFF = 2 ,
RADIO QUIETER = 3 ,
RADIO LOUDER = 4 ,
START SENSING = 5 ,
READ LOG = 6
};
typedef struct {
i n t nsamples ;
uint32 t interval ;
uint32 t time sec ;
} start sense args ;
typedef struct {
uint16 t destaddr ;
} read log args ;
// SimpleCmd message s t r u c t u r e
t y p e d e f s t r u c t SimpleCmdMsg {
i n t 8 t seqno ;
int8 t action ;
uint16 t source ;
u i n t 8 t hop count ;
union {
start sense args ss args ;
read log args rl args ;
uint8 t untyped args [ 0 ] ;
} args ;
} SimpleCmdMsg ;
// Log message s t r u c t u r e
t y p e d e f s t r u c t LogMsg {
uint16 t sourceaddr ;
uint8 t log [ 1 6 ] ;
} LogMsg ;
2. JAVA DIRECTORY
27
2. java Directory
/*
* This s o f t w a r e i s l a r g e l y based on s o f t w a r e w r i t t e n by t h e U n i v e r s i t y o f
* C a l i f o r n i a . As p e r t h e i m p l i e d l i c e n s e agreement , t h e o r i g i n a l c o p y r i g h t
* n o t i c e i s below .
*/
/*
* ” C o p y r i g h t ( c ) 2000 −2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a .
* All rights reserved .
*
* P e r m i s s i o n t o use , copy , modify , and d i s t r i b u t e t h i s s o f t w a r e and i t s
* documentation f o r any purpose , w i t h o u t f e e , and w i t h o u t w r i t t e n agreement i s
* h e r e b y g r a n t e d , p r o v i d e d t h a t t h e above c o p y r i g h t n o t i c e , t h e f o l l o w i n g
* two p a r a g r a p h s and t h e a u t h o r ap p ea r i n a l l c o p i e s o f t h i s s o f t w a r e .
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT , SPECIAL , INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER I S
* ON AN ”AS I S ” BASIS , AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS . ”
*
* C o p y r i g h t ( c ) 2002 −2003 I n t e l C o r p o r a t i o n
* All rights reserved .
*
* This f i l e i s d i s t r i b u t e d under t h e terms i n t h e a t t a c h e d INTEL−LICENSE
* f i l e . I f you do not f i n d t h e s e f i l e s , c o p i e s can be found by w r i t i n g t o
* I n t e l R e s e a r c h B e r k e l e y , 2150 S h a t t u c k Avenue , S u i t e 1 3 0 0 , B e r k e l e y , CA,
* 94704. Attention :
Int e l License Inquiry .
*/
/ **
*
*
* @author <a h r e f =”m a i l t o : s z e w c z y k @ s o u r c e f o r g e . n e t”>Robert Szewczyk </a>
*/
/*
* M o d i f i e d by Hasan Ozer ( h−o z e r @ n o r t h w e s t e r n . edu ) and Mat Kotowsky
* ( kotowsky@northwestern . edu ) t o be used with t h e MDA300Logger p r o j e c t .
*/
package n e t . t i n y o s . t o o l s ;
i mp o rt n e t . t i n y o s . u t i l . * ;
i mp o rt j a v a . i o . * ;
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
28
i mp o rt j a v a . u t i l . P r o p e r t i e s ;
i mp o rt j a v a . u t i l . Date ;
i mp o rt n e t . t i n y o s . message . * ;
p u b l i c c l a s s B c a s t I n j e c t implements M e s s a g e L i s t e n e r {
s t a t i c P r o p e r t i e s p = new P r o p e r t i e s ( ) ;
p u b l i c s t a t i c f i n a l b y t e LED ON = 1 ;
p u b l i c s t a t i c f i n a l b y t e LED OFF = 2 ;
p u b l i c s t a t i c f i n a l b y t e RADIO LOUDER = 3 ;
p u b l i c s t a t i c f i n a l b y t e RADIO QUIETER = 4 ;
p u b l i c s t a t i c f i n a l b y t e START SENSING = 5 ;
p u b l i c s t a t i c f i n a l b y t e READ LOG = 6 ;
public boolean read log done = f a l s e ;
public boolean s t a r t s e n s i n g d o n e = f a l s e ;
p u b l i c boolean isRead = f a l s e ;
public static
f i n a l s h o r t TOS BCAST ADDR = ( s h o r t ) 0 x f f f f ;
p u b l i c s t a t i c S t r i n g outputFilename ;
p u b l i c s t a t i c double t ;
p u b l i c s t a t i c void usage ( ) {
System . e r r . p r i n t l n ( ” Usage : j a v a n e t . t i n y o s . t o o l s . B c a s t I n j e c t ”+
” <command> [ arguments ] ” ) ;
System . e r r . p r i n t l n ( ” \ t wh e re <command> and [ arguments ] can be one o f t h e f o l l o w i n g : ” ) ;
System . e r r . p r i n t l n ( ” \ t \ t l e d o n ” ) ;
System . e r r . p r i n t l n ( ” \ t \ t l e d o f f ” ) ;
System . e r r . p r i n t l n ( ” \ t \ t r a d i o l o u d e r ” ) ;
System . e r r . p r i n t l n ( ” \ t \ t r a d i o q u i e t e r ” ) ;
System . e r r . p r i n t l n ( ” \ t \ t s t a r t s e n s i n g [ n s a m p l e s i n t e r v a l s e c t i m e s e c ] ” ) ;
System . e r r . p r i n t l n ( ” \ t \ t r e a d l o g [ d e s t a d d r e s s ] ” ) ;
}
public s t a t i c void startSensingUsage ( ) {
System . e r r . p r i n t l n ( ” Usage : j a v a n e t . t i n y o s . t o o l s . B c a s t I n j e c t ”
+ ” s t a r t s e n s i n g [ num samples i n t e r v a l s e c t i m e s e c ] ” ) ;
}
p u b l i c s t a t i c v o i d readLogUsage ( ) {
System . e r r . p r i n t l n ( ” Usage : j a v a n e t . t i n y o s . t o o l s . B c a s t I n j e c t ” +
” read log [ dest address ] [ data file ] ” ) ;
}
p u b l i c s t a t i c byte restoreSequenceNo ( ) {
try {
F i l e I n p u t S t r e a m f i s = new F i l e I n p u t S t r e a m ( ” b c a s t . p r o p e r t i e s ” ) ;
p . load ( f i s ) ;
b y t e i = ( b y t e ) I n t e g e r . p a r s e I n t ( p . g e t P r o p e r t y ( ” sequenceNo ” , ” 1 ” ) ) ;
f i s . close ();
return i ;
} c a t c h ( IOException e ) {
2. JAVA DIRECTORY
29
p . s e t P r o p e r t y ( ” sequenceNo ” , ” 1 ” ) ;
return 1;
}
}
p u b l i c s t a t i c v o i d saveSequenceNo ( i n t i ) {
try {
F i l e O u t p u t S t r e a m f o s = new F i l e O u t p u t S t r e a m ( ” b c a s t . p r o p e r t i e s ” ) ;
p . s e t P r o p e r t y ( ” sequenceNo ” , I n t e g e r . t o S t r i n g ( i ) ) ;
p . s t o r e ( f o s , ”# P r o p e r t i e s f o r B c a s t I n j e c t \n ” ) ;
} c a t c h ( IOException e ) {
System . e r r . p r i n t l n ( ” E x c e p t i o n w h i l e s a v i n g s e q u e n c e number” + e ) ;
e . printStackTrace ( ) ;
}
}
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g v ) throws IOException {
S t r i n g cmd ;
b y t e sequenceNo = 0 ;
boolean r e a d l o g = f a l s e ;
boolean s t a r t s e n s i n g = f a l s e ;
i f ( argv . l e n g t h < 1) {
usage ( ) ;
System . e x i t ( − 1 ) ;
}
cmd = a r g v [ 0 ] ;
i f ( cmd . e q u a l s ( ” s t a r t s e n s i n g ” ) && a r g v . l e n g t h != 4 ) {
startSensingUsage ( ) ;
System . e x i t ( − 1 ) ;
} e l s e i f ( cmd . e q u a l s ( ” r e a d l o g ” ) && a r g v . l e n g t h != 3 ) {
readLogUsage ( ) ;
System . e x i t ( − 1 ) ;
}
SimpleCmdMsg p a c k e t = new SimpleCmdMsg ( ) ;
sequenceNo
packet . s e t
packet . set
packet . s e t
= restoreSequenceNo ( ) ;
s e q n o ( sequenceNo ) ;
hop count (( short ) 0 ) ;
source (0);
i f ( cmd . e q u a l s ( ” l e d o n ” ) ) {
p a c k e t . s e t a c t i o n (LED ON ) ;
} e l s e i f ( cmd . e q u a l s ( ” l e d o f f ” ) ) {
p a c k e t . s e t a c t i o n (LED OFF ) ;
} e l s e i f ( cmd . e q u a l s ( ” r a d i o l o u d e r ” ) ) {
p a c k e t . s e t a c t i o n (RADIO LOUDER ) ;
} e l s e i f ( cmd . e q u a l s ( ” r a d i o q u i e t e r ” ) ) {
p a c k e t . s e t a c t i o n (RADIO QUIETER ) ;
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
30
} e l s e i f ( cmd . e q u a l s ( ” s t a r t s e n s i n g ” ) ) {
p a c k e t . s e t a c t i o n (START SENSING ) ;
s h o r t nsamples = ( s h o r t ) I n t e g e r . p a r s e I n t ( argv [ 1 ] ) ;
long i n t e r v a l s e c = ( long ) I n t e g e r . p a r s e I n t ( argv [ 2 ] ) ;
i n t t i m e s e c = ( i n t ) I n t e g e r . p a r s e I n t ( argv [ 3 ] ) ;
packet . s e t a r g s s s a r g s n s a m p l e s ( nsamples ) ;
packet . s e t a r g s s s a r g s i n t e r v a l ( i n t e r v a l s e c ) ;
packet . s e t a r g s s s a r g s t i m e ( time sec ) ;
st art se ns ing = true ;
} e l s e i f ( cmd . e q u a l s ( ” r e a d l o g ” ) ) {
read log = true ;
p a c k e t . s e t a c t i o n (READ LOG ) ;
s h o r t address = ( s h o r t ) I n t e g e r . p a r s e I n t ( argv [ 1 ] ) ;
outputFilename = argv [ 2 ] ;
packet . s e t a r g s r l a r g s d e s t a d d r ( address ) ;
} else {
usage ( ) ;
System . e x i t ( − 1 ) ;
}
try {
System . e r r . p r i n t ( ” S e n d i n g p a y l o a d : ” ) ;
f o r ( i n t i = 0 ; i < p a c k e t . dataLength ( ) ; i ++) {
System . e r r . p r i n t ( I n t e g e r . t o H e x S t r i n g ( p a c k e t . dataGet ( ) [ i ] & 0 x f f )+ ” ” ) ;
}
System . e r r . p r i n t l n ( ) ;
MoteIF mote = new MoteIF ( P r i n t S t r e a m M e s s e n g e r . e r r ) ;
// Need t o w a i t f o r m e s s a g e s t o come back
B c a s t I n j e c t bc = n u l l ;
i f ( read log | | start sensing ) {
bc = new B c a s t I n j e c t ( ) ;
mote . r e g i s t e r L i s t e n e r ( new LogMsg ( ) , bc ) ;
}
mote . send (TOS BCAST ADDR, p a c k e t ) ;
if ( start sensing ) {
p . s e t P r o p e r t y ( ” putHeader ” , ” t r u e ” ) ;
s y n c h r o n i z e d ( bc ) {
i f ( bc . s t a r t s e n s i n g d o n e == f a l s e ) {
System . e r r . p r i n t l n ( ” Waiting f o r r e s p o n s e t o s t a r t s e n s i n g . . . ” ) ;
bc . w a i t ( 1 0 0 0 0 ) ;
}
System . e r r . p r i n t l n ( ” Done w a i t i n g f o r a c k s . ” ) ;
}
}
2. JAVA DIRECTORY
31
i f ( read log ) {
System . e r r . p r i n t l n ( ” Output f i l e i s ” + o u t p u t F i l e n a m e ) ;
s y n c h r o n i z e d ( bc ) {
bc . i s R e a d = t r u e ;
i f ( bc . r e a d l o g d o n e == f a l s e ) {
System . e r r . p r i n t l n ( ” Waiting f o r r e s p o n s e t o r e a d l o g . . . ” ) ;
bc . w a i t ( 1 0 0 0 0 ) ;
}
System . e r r . p r i n t l n ( ” Done w a i t i n g f o r data . ” ) ;
p . s e t P r o p e r t y ( ” putHeader ” , ” t r u e ” ) ;
}
}
saveSequenceNo ( sequenceNo +1);
System . e x i t ( 0 ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
p u b l i c v o i d m e s s a g e R e c e i v e d ( i n t d e s t a d d r , Message m) {
FileOutputStream f o s = n u l l ;
PrintWriter fileOut = null ;
FileOutputStream l o s = n u l l ;
P r i n t W r i t e r logOut = n u l l ;
try
{
l o s = new F i l e O u t p u t S t r e a m ( ” B c a s t I n j e c t . l o g ” , t r u e ) ;
logOut = new P r i n t W r i t e r ( l o s ) ;
logOut . p r i n t l n ( new Date ( ) ) ;
logOut . p r i n t l n (”−−−−−−−−”);
}
c a t c h ( IOException e )
{
System . e r r . p r i n t l n ( ” E r r o r o p e n i n g l o g f i l e ” + e ) ;
e . printStackTrace ( ) ;
}
i f ( isRead )
{
try
{
f o s = new F i l e O u t p u t S t r e a m ( outputFilename , t r u e ) ; // append
f i l e O u t = new P r i n t W r i t e r ( f o s ) ;
}
c a t c h ( IOException e )
{
System . e r r . p r i n t l n ( ” E r r o r w h i l e o p e n i n g o ut p u t f i l e : ” + e ) ;
e . printStackTrace ( ) ;
}
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
32
}
l o n g timestamp = 0 ;
S t r i n g [ ] dataRow = new S t r i n g [ 8 ] ;
String rawString = ””;
LogMsg lm = ( LogMsg ) m;
f o r ( i n t i = 0 ; i < 1 6 ; i ++) {
r a w S t r i n g +=
( lm . g e t E l e m e n t l o g ( i ) < 16? ”0” : ” ” )
+ Long . t o H e x S t r i n g ( lm . g e t E l e m e n t l o g ( i ) & 0 x f f )
+” ” ;
}
i f ( isRead )
{
i f ( p . g e t P r o p e r t y ( ” putHeader ” , ” t r u e ” ) . e q u a l s ( ” t r u e ” ) )
{
f i l e O u t . p r i n t l n ( new Date ( ) ) ;
f i l e O u t . p r i n t l n (”−−−−−−−−−−−−−−−−−”);
}
p . s e t P r o p e r t y ( ” putHeader ” , ” f a l s e ” ) ;
f i l e O u t . p r i n t l n ( rawString ) ;
fileOut . flush ();
try
{
fileOut . close ();
fos . close ();
}
c a t c h ( IOException e )
{
System . e r r . p r i n t l n ( ” E r r o r c l o s i n g t h e f i l e : ” + e ) ;
e . printStackTrace ( ) ;
}
}
i f ( ! isRead )
{
System . e r r . p r i n t l n ( ” Mote ” + lm . g e t s o u r c e a d d r ( ) + ” has s t a r t e d . ” ) ;
}
e l s e i f ( ( lm . g e t E l e m e n t l o g ( 5 ) & lm . g e t E l e m e n t l o g ( 7 ) ) == 0xFF )
// two ”random” p o s i t i o n s a r e FF
{
i n t i = 0 ; // p o s i t i o n o f timestamp
timestamp =0;
timestamp |= lm . g e t E l e m e n t l o g ( i +3) & 0xFF ;
timestamp <<= 8 ;
timestamp |= lm . g e t E l e m e n t l o g ( i +2) & 0xFF ;
timestamp <<= 8 ;
2. JAVA DIRECTORY
33
timestamp |= lm . g e t E l e m e n t l o g ( i +1) & 0xFF ;
timestamp <<= 8 ;
timestamp |= lm . g e t E l e m e n t l o g ( i ) & 0xFF ;
logOut . p r i n t l n ( ”New t e s t s t a r t a t ” + timestamp + ” ! ” ) ;
}
else
{
i n t lineType ;
i f ( ( lm . g e t E l e m e n t l o g ( 1 4 ) == 0 x77 ) & ( lm . g e t E l e m e n t l o g ( 1 5 ) == 0 x77 ) )
l i n e T y p e =1;
else
l i n e T y p e =2;
// System . e r r . p r i n t l n ( ” R e c e i v e d l o g message : ”+lm ) ;
logOut . p r i n t l n ( ”Raw l o g message ; ” + lm ) ;
logOut . p r i n t l n ( ” r e a d i n g a l i n e o f t y p e ” + l i n e T y p e ) ;
f o r ( i n t i = 0 ; i < lm . numElements log ( ) ; i +=2) {
int intVal = 0;
i n t V a l |= lm . g e t E l e m e n t l o g ( i +1) & 0xFF ;
i n t V a l <<= 8 ;
i n t V a l |= lm . g e t E l e m e n t l o g ( i ) & 0xFF ;
i f ( ( i == 8 ) && ( l i n e T y p e == 2 ) ) // t e m p e r a t u r e
{
t =(( i n t V a l * . 9 8 − 3 8 4 0 ) / 1 0 0 ) ;
logOut . p r i n t l n ( ” Temperature : ” + t ) ;
dataRow [ 1 ] = Double . t o S t r i n g ( t ) ;
}
else
i f ( ( i ==12) && ( l i n e T y p e ==1)) // b a t t e r y v o l t a g e
{
logOut . p r i n t l n ( ” B a t t e r y V o l t a g e : ” + i n t V a l * 1 0 ) ;
dataRow [ 2 ] = Double . t o S t r i n g ( i n t V a l * 1 0 ) ;
}
else
i f ( ( i ==10) && ( l i n e T y p e == 2 ) ) // humidity
{
i f ( t == 0 ) t = 2 5 ; // u s e t h i s a s a d e f a u l t v a l u e
double h ;
// temporary humidity v a l u e
h= 0 . 0 4 0 5 * i n t V a l − 4 − i n t V a l * i n t V a l * 0 . 0 0 0 0 0 2 8 ;
h= ( t −25) * ( 0 . 0 1 + 0 . 0 0 1 2 8 * i n t V a l ) + h ;
i f (h > 100) h = 100;
logOut . p r i n t l n ( ” Humidity : ” + h ) ;
dataRow [ 3 ] = Double . t o S t r i n g ( h ) ;
}
else
i f ( ( i ==12) && ( l i n e T y p e == 2 ) ) // data
{
logOut . p r i n t l n ( ” Data : ” + ( 1 2 5 0 0 * ( i n t V a l / 2 0 4 8 . 0 − 1 ) ) ) ;
1. MICA2-BASED WIRELESS ACM VERSION 1 SOFTWARE: MODIFICATION OF SENSELIGHTTOLOG
34
dataRow [ 4 ] = Double . t o S t r i n g ( ( 1 2 . 5 0 0 * ( i n t V a l / 2 0 4 8 . 0 − 1 ) ) ) ;
}
else
i f ( i ==4) // s e c o n d s i n t o t e s t
{
int secs = 0;
s e c s |= lm . g e t E l e m e n t l o g ( i +3) & 0xFF ;
s e c s <<= 8 ;
s e c s |= lm . g e t E l e m e n t l o g ( i +2) & 0xFF ;
s e c s <<= 8 ;
s e c s |= lm . g e t E l e m e n t l o g ( i +1) & 0xFF ;
s e c s <<= 8 ;
s e c s |= lm . g e t E l e m e n t l o g ( i ) & 0xFF ;
logOut . p r i n t l n ( ” s e c o n d s i n t o t e s t : ” + i n t V a l ) ;
dataRow [ 0 ] = I n t e g e r . t o S t r i n g ( i n t V a l ) ;
}
e l s e i f ( ( i ==8) && ( l i n e T y p e == 1 ) ) // s a m p l e s remaning
{
logOut . p r i n t l n ( i n t V a l + ” s a m p l e s ” ) ;
dataRow [ 6 ] = I n t e g e r . t o S t r i n g ( i n t V a l ) ;
}
e l s e i f ( ( i ==10) && ( l i n e T y p e == 1 ) ) // s a m p l e s
{
logOut . p r i n t l n ( i n t V a l + ” s a m p l e s t o t a l ” ) ;
dataRow [ 5 ] = I n t e g e r . t o S t r i n g ( i n t V a l ) ;
}
else
i f ( i ==0) // timestamp
{
timestamp =0;
timestamp |= lm . g e t E l e m e n t l o g ( i +3) & 0xFF ;
timestamp <<= 8 ;
timestamp |= lm . g e t E l e m e n t l o g ( i +2) & 0xFF ;
timestamp <<= 8 ;
timestamp |= lm . g e t E l e m e n t l o g ( i +1) & 0xFF ;
timestamp <<= 8 ;
timestamp |= lm . g e t E l e m e n t l o g ( i ) & 0xFF ;
logOut . p r i n t l n ( ” Time : ” + timestamp ) ;
dataRow [ 7 ] = Long . t o S t r i n g ( ( l o n g ) timestamp ) ;
}
} // end f o r
logOut . p r i n t l n (”−−−END−−−”);
logOut . p r i n t l n ( ) ;
logOut . f l u s h ( ) ;
try
{
los . close ();
logOut . c l o s e ( ) ;
}
c a t c h ( IOException e )
{
2. JAVA DIRECTORY
System . e r r . p r i n t l n ( ” E r r o r c l o s i n g l o g
e . printStackTrace ( ) ;
}
} // end l i n e t y p e e l s e
/*
synchronized ( t h i s ) {
read log done = true ;
this . notifyAll ();
}
*/
}
}
35
file ” + e );
CHAPTER 2
MICA2-Based Wireless ACM Version 2 Software:
Modification of XMDA300
This appendix contains all software used to program the MICA2 motes
for Version 2 of the MICA2-based wireless ACM system. This appendix is organized by software directory and only the modified files are
included.
37
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
38
1. xbow/apps/XMesh/XMDA300 directory
/*
*
tab : 4
IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING .
By
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
downloading , cop ying , i n s t a l l i n g o r u s i n g t h e s o f t w a r e you a g r e e t o
this license .
I f you do not a g r e e t o t h i s l i c e n s e , do not download ,
i n s t a l l , copy o r u s e t h e s o f t w a r e .
I n t e l Open S o u r c e L i c e n s e
C o p y r i g h t ( c ) 2002 I n t e l C o r p o r a t i o n
All rights reserved .
R e d i s t r i b u t i o n and u s e i n s o u r c e and b i n a r y forms , with o r w i t h o u t
modification , are permitted provided that the f o l l o w i n g c o n d i t i o n s are
met :
R e d i s t r i b u t i o n s o f s o u r c e code must r e t a i n t h e above c o p y r i g h t
n o t i c e , t h i s l i s t o f c o n d i t i o n s and t h e f o l l o w i n g d i s c l a i m e r .
R e d i s t r i b u t i o n s i n b i n a r y form must r e p r o d u c e t h e above c o p y r i g h t
n o t i c e , t h i s l i s t o f c o n d i t i o n s and t h e f o l l o w i n g d i s c l a i m e r i n t h e
documentation and / o r o t h e r m a t e r i a l s p r o v i d e d with t h e d i s t r i b u t i o n .
N e i t h e r t h e name o f t h e I n t e l C o r p o r a t i o n nor t h e names o f i t s
c o n t r i b u t o r s may be used t o e n d o r s e o r promote p r o d u c t s d e r i v e d from
t h i s software without s p e c i f i c p r i o r written permission .
THIS SOFTWARE I S PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
‘ ‘ AS IS ’ ’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE INTEL OR ITS
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT , INCIDENTAL, SPECIAL ,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE, DATA, OR
PROFITS ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY , WHETHER IN CONTRACT, STRICT LIABILITY , OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@author Leah Fera , Martin Turon , J a i d e v Prabhu
$ I d : XMDA300M. nc , v 1 . 4 2005/01/11 0 5 : 2 1 : 3 5 husq Exp $
/ ******************************************************************************
*
*
− T e s t s t h e MDA300 g e n e r a l p r o t o t y p i n g c a r d
*
( s e e Crossbow MTS S e r i e s User Manual )
*
− Read and c o n t r o l a l l MDA300 s i g n a l s :
*
ADC0, ADC1, ADC2, ADC3 , . . . ADC11 i n p u t s , DIO 0 −5 ,
*
c o u n t e r , b a t t e r y , humidity , temp
*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
* Output r e s u l t s t h r o u g h mica2 u a r t and r a d i o .
1. XBOW/APPS/XMESH/XMDA300 DIRECTORY
39
* Use x l i s t e n . e x e program t o view data from e i t h e r p o r t :
* u a r t : mount mica2 on mib510 with MDA300
*
( must be c o n n e c t e d o r now data i s r e a d )
*
c o n n e c t s e r i a l c a b l e t o PC
*
run x l i s t e n . e x e a t 57600 baud
* r a d i o : run mica2 with MDA300,
*
run a n o t h e r mica2 with TOSBASE
*
run x l i s t e n . e x e a t 56K baud
* LED : t h e l e d w i l l be g r e e n i f t h e MDA300 i s c o n n e c t e d t o t h e mica2 and
*
t h e program i s r u n n i n g ( and s e n d i n g out p a c k e t s ) .
Otherwise i t i s red .
*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
* Data p a c k e t s t r u c t u r e :
*
* PACKET #1 ( o f 4 )
* −−−−−−−−−−−−−−−−
* msg−>data [ 0 ] : s e n s o r id , MDA300 = 0 x81
* msg−>data [ 1 ] : p a c k e t number = 1
* msg−>data [ 2 ] : node i d
* msg−>data [ 3 ] : r e s e r v e d
* msg−>data [ 4 , 5 ] : a n a l o g adc data Ch . 0
* msg−>data [ 6 , 7 ] : a n a l o g adc data Ch . 1
* msg−>data [ 8 , 9 ] : a n a l o g adc data Ch . 2
* msg−>data [ 1 0 , 1 1 ] : a n a l o g adc data Ch . 3
* msg−>data [ 1 2 , 1 3 ] : a n a l o g adc data Ch . 4
* msg−>data [ 1 4 , 1 5 ] : a n a l o g adc data Ch . 5
* msg−>data [ 1 6 , 1 7 ] : a n a l o g adc data Ch . 6
*
* PACKET #2 ( o f 4 )
* −−−−−−−−−−−−−−−−
* msg−>data [ 0 ] : s e n s o r id , MDA300 = 0 x81
* msg−>data [ 1 ] : p a c k e t number = 2
* msg−>data [ 2 ] : node i d
* msg−>data [ 3 ] : r e s e r v e d
* msg−>data [ 4 , 5 ] : a n a l o g adc data Ch . 7
* msg−>data [ 6 , 7 ] : a n a l o g adc data Ch . 8
* msg−>data [ 8 , 9 ] : a n a l o g adc data Ch . 9
* msg−>data [ 1 0 , 1 1 ] : a n a l o g adc data Ch . 1 0
* msg−>data [ 1 2 , 1 3 ] : a n a l o g adc data Ch . 1 1
* msg−>data [ 1 4 , 1 5 ] : a n a l o g adc data Ch . 1 2
* msg−>data [ 1 6 , 1 7 ] : a n a l o g adc data Ch . 1 3
*
*
* PACKET #3 ( o f 4 )
* −−−−−−−−−−−−−−−−
* msg−>data [ 0 ] : s e n s o r id , MDA300 = 0 x81
* msg−>data [ 1 ] : p a c k e t number = 3
* msg−>data [ 2 ] : node i d
* msg−>data [ 3 ] : r e s e r v e d
* msg−>data [ 4 , 5 ] : d i g i t a l data Ch . 0
* msg−>data [ 6 , 7 ] : d i g i t a l data Ch . 1
* msg−>data [ 8 , 9 ] : d i g i t a l data Ch . 2
* msg−>data [ 1 0 , 1 1 ] : d i g i t a l data Ch . 3
* msg−>data [ 1 2 , 1 3 ] : d i g i t a l data Ch . 4
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
40
* msg−>data [ 1 4 , 1 5 ] : d i g i t a l data Ch . 5
*
* PACKET #4 ( o f 4 )
* −−−−−−−−−−−−−−−−
* msg−>data [ 0 ] : s e n s o r id , MDA300 = 0 x81
* msg−>data [ 1 ] : p a c k e t number = 4
* msg−>data [ 2 ] : node i d
* msg−>data [ 3 ] : r e s e r v e d
* msg−>data [ 4 , 5 ] : b a t t
* msg−>data [ 6 , 7 ] : hum
* msg−>data [ 8 , 9 ] : temp
* msg−>data [ 1 0 , 1 1 ] : c o u n t e r
* msg−>data [ 1 4 ] : m s g 4 s t a t u s ( debug )
*
*************************************************************************** /
// i n c l u d e s e n s o r b o a r d . h d e f i n i t i o n s from t o s /mda300 d i r e c t o r y
#i n c l u d e ” a p p F e a t u r e s . h”
i n c l u d e s XCommand ;
includes sensorboard ;
module XMDA300M
{
provides i n t e r f a c e StdControl ;
uses {
i n t e r f a c e Leds ;
i n t e r f a c e Send ;
i n t e r f a c e RouteControl ;
#i f d e f XMESHSYNC
i n t e r f a c e R e c e i v e a s DownTree ;
#e n d i f
i n t e r f a c e XCommand ;
// Sampler Communication
i n t e r f a c e StdControl as SamplerControl ;
i n t e r f a c e Sample ;
// Timer
i n t e r f a c e Timer ;
// r e l a y s
i n t e r f a c e Relay a s r e l a y n o r m a l l y c l o s e d ;
i n t e r f a c e Relay a s r e l a y n o r m a l l y o p e n ;
// s u p p o r t f o r p l u g and p l a y
command r e s u l t t PlugPlay ( ) ;
#i f FEATURE UART SEND
1. XBOW/APPS/XMESH/XMDA300 DIRECTORY
41
i n t e r f a c e SendMsg a s SendUART ;
command r e s u l t t PowerMgrEnable ( ) ;
command r e s u l t t PowerMgrDisable ( ) ;
#e n d i f
}
}
implementation
{
#d e f i n e ANALOG SAMPLING TIME
90
#d e f i n e DIGITAL SAMPLING TIME 100
110
#d e f i n e MISC SAMPLING TIME
#d e f i n e MPK RATE 30720 // f i r e t w i c e p e r minute
#d e f i n e MPK TICKS 36 // 18 m i n u te s between s a m p l e s
#d e f i n e MPK QUICK MESH COUNT 60 // MPK t a k e 60 s a m p l e s a t a h i g h s p e e d
// b e f o r e l o w e r i n g r a t e
#d e f i n e
#d e f i n e
#d e f i n e
#d e f i n e
ANALOG SEND FLAG
DIGITAL SEND FLAG
MISC SEND FLAG
ERR SEND FLAG
1
1
1
1
#d e f i n e PACKET FULL 0x1C1 // MPK Temp , Hum, Batt , ADC0
#i f 0
#d e f i n e PACKET FULL 0x1FF
#e n d i f
#d e f i n e MSG LEN
29
// e x c l u d e s TOS header , but i n c l u d e s xbow h e a d e r
enum {
PENDING = 0 ,
NO MSG = 1
};
enum {
MDA300 PACKET1 = 1 ,
MDA300 PACKET2 = 2 ,
MDA300 PACKET3 = 3 ,
MDA300 PACKET4 = 4 ,
MDA300 ERR PACKET = 0 x f 8
};
/ ******************************************************
enum {
SENSOR ID = 0 ,
PACKET ID,
NODE ID ,
RESERVED,
DATA START
} XPacketDataEnum ;
****************************************************** /
/ * Messages B u f f e r s * /
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
42
uint32 t
timer rate ;
bool
sleeping ;
bool sending packet ;
uint16 t
seqno ;
XDataMsg * tmppack ;
// a p p l i c a t i o n command s t a t e
TOS Msg p a c k e t ;
TOS Msg m s g s e n d b u f f e r ;
TOS MsgPtr m s g p t r ;
i n t packetCount = 0 ;
// MPK
int timerTicks = 0;
// MPK
i n t maxTicks = 2 ;
// MPK B r o a d c a s t e v e r y minute
// u n t i l quckMeshCount > MPK QUICK MESH COUNT
i n t quickMeshCount = 0 ;
// MPK
u i n t 1 6 t msg status , p k t f u l l ;
char t e s t ;
int8 t record [ 2 5 ] ;
s t a t i c void i n i t i a l i z e ( )
{
a to m i c
{
s l e e p i n g = FALSE ;
s e n d i n g p a c k e t = FALSE ;
// t i m e r r a t e = XSENSOR SAMPLE RATE ; // ORIGINAL LINE
t i m e r r a t e = MPK RATE;
// MPK
}
}
/ ****************************************************************************
* I n i t i a l i z e t h e component . I n i t i a l i z e Leds
*
**************************************************************************** /
command r e s u l t t S t d C o n t r o l . i n i t ( ) {
uint8 t i ;
c a l l Leds . i n i t ( ) ;
a to m i c {
m s g p t r = &m s g s e n d b u f f e r ;
// s e n d i n g p a c k e t = FALSE ;
}
msg status = 0;
p k t f u l l = PACKET FULL ;
MAKE BAT MONITOR OUTPUT ( ) ;
MAKE ADC INPUT ( ) ;
// e n a b l e v o l t a g e r e f power p i n a s o u tp u t
// e n a b l e ADC7 a s i n p u t
1. XBOW/APPS/XMESH/XMDA300 DIRECTORY
43
// u s a r t 1 i s a l s o c o n n e c t e d t o e x t e r n a l s e r i a l f l a s h
// s e t u s a r t 1 l i n e s t o c o r r e c t s t a t e
// TOSH MAKE FLASH SELECT OUTPUT ( ) ;
TOSH MAKE FLASH OUT OUTPUT ( ) ;
// t x ou t p ut
// u s a r t c l k
TOSH MAKE FLASH CLK OUTPUT ( ) ;
// TOSH SET FLASH SELECT PIN ( ) ;
c a l l SamplerControl . i n i t ( ) ;
initialize ();
r e t u r n SUCCESS ;
// r e t u r n rcombine ( c a l l S a m p l e r C o n t r o l . i n i t ( ) , c a l l CommControl . i n i t ( ) ) ;
}
/ ****************************************************************************
* S t a r t t h e component . S t a r t t h e c l o c k . Setup t i m e r and s a m p l i n g
*
**************************************************************************** /
command r e s u l t t S t d C o n t r o l . s t a r t ( ) {
c a l l SamplerControl . s t a r t ( ) ;
i f ( c a l l PlugPlay ( ) )
{
c a l l Timer . s t a r t (TIMER REPEAT, t i m e r r a t e ) ;
// c h a n n e l p a r a m e t e r e s a r e i r r e l e v e n t
r e c o r d [ 1 4 ] = c a l l Sample . getSample ( 0 ,
TEMPERATURE, MISC SAMPLING TIME ,SAMPLER DEFAULT ) ;
r e c o r d [ 1 5 ] = c a l l Sample . getSample ( 0 ,
HUMIDITY, MISC SAMPLING TIME ,SAMPLER DEFAULT ) ;
r e c o r d [ 1 6 ] = c a l l Sample . getSample ( 0 ,
BATTERY, MISC SAMPLING TIME ,SAMPLER DEFAULT ) ;
// s t a r t s a m p l i n g
c h a n n e l s . Channels 7−10 with a v e r a g i n g s i n c e
// t h e y a r e more p e r c i s e .
// h a n n e l s 3−6 make a c t i v e e x c i t a t i o n
/ * MPK
r e c o r d [ 0 ] = c a l l Sample . getSample ( 0 ,
ANALOG, ANALOG SAMPLING TIME,SAMPLER DEFAULT ) ;
r e c o r d [ 1 ] = c a l l Sample . getSample ( 1 ,
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
44
ANALOG, ANALOG SAMPLING TIME,SAMPLER DEFAULT ) ;
r e c o r d [ 2 ] = c a l l Sample . getSample ( 2 ,
ANALOG, ANALOG SAMPLING TIME,SAMPLER DEFAULT ) ;
MPK * /
/ * MPK
r e c o r d [ 3 ] = c a l l Sample . getSample ( 3 ,
ANALOG, ANALOG SAMPLING TIME,
SAMPLER DEFAULT | EXCITATION 33 | DELAY BEFORE MEASUREMENT) ;
r e c o r d [ 4 ] = c a l l Sample . getSample ( 4 ,
ANALOG, ANALOG SAMPLING TIME,SAMPLER DEFAULT ) ;
r e c o r d [ 5 ] = c a l l Sample . getSample ( 5 ,
ANALOG, ANALOG SAMPLING TIME,SAMPLER DEFAULT ) ;
r e c o r d [ 6 ] = c a l l Sample . getSample ( 6 ,
ANALOG, ANALOG SAMPLING TIME,SAMPLER DEFAULT ) ;
MPK * /
r e c o r d [ 7 ] = c a l l Sample . getSample ( 7 ,
ANALOG, ANALOG SAMPLING TIME,
AVERAGE FOUR | EXCITATION 25 | DELAY BEFORE MEASUREMENT ) ;
/ * MPK
r e c o r d [ 8 ] = c a l l Sample . getSample ( 8 ,
ANALOG, ANALOG SAMPLING TIME,AVERAGE FOUR | EXCITATION 25 ) ;
r e c o r d [ 9 ] = c a l l Sample . getSample ( 9 ,
ANALOG, ANALOG SAMPLING TIME,AVERAGE FOUR | EXCITATION 25 ) ;
MPK * /
/ * MPK
r e c o r d [ 1 0 ] = c a l l Sample . getSample ( 1 0 ,
ANALOG, ANALOG SAMPLING TIME,AVERAGE FOUR | EXCITATION 25 ) ;
r e c o r d [ 1 1 ] = c a l l Sample . getSample ( 1 1 ,
ANALOG, ANALOG SAMPLING TIME,SAMPLER DEFAULT ) ;
r e c o r d [ 1 2 ] = c a l l Sample . getSample ( 1 2 ,
ANALOG, ANALOG SAMPLING TIME,SAMPLER DEFAULT ) ;
r e c o r d [ 1 3 ] = c a l l Sample . getSample ( 1 3 ,
ANALOG, ANALOG SAMPLING TIME,
SAMPLER DEFAULT | EXCITATION 50 | EXCITATION ALWAYS ON ) ;
MPK * /
/*
// MPK
// d i g i t a l c h e n n e l s a s a c c u m u l a t i v e c o u n t e r
1. XBOW/APPS/XMESH/XMDA300 DIRECTORY
45
r e c o r d [ 1 7 ] = c a l l Sample . getSample ( 0 ,
DIGITAL , DIGITAL SAMPLING TIME ,
RESET ZERO AFTER READ | FALLING EDGE ) ;
r e c o r d [ 1 8 ] = c a l l Sample . getSample ( 1 ,
DIGITAL , DIGITAL SAMPLING TIME , RISING EDGE | EVENT) ;
r e c o r d [ 1 9 ] = c a l l Sample . getSample ( 2 ,
DIGITAL , DIGITAL SAMPLING TIME ,SAMPLER DEFAULT | EVENT) ;
r e c o r d [ 2 0 ] = c a l l Sample . getSample ( 3 ,
DIGITAL , DIGITAL SAMPLING TIME , FALLING EDGE ) ;
r e c o r d [ 2 1 ] = c a l l Sample . getSample ( 4 ,
DIGITAL , DIGITAL SAMPLING TIME , RISING EDGE ) ;
r e c o r d [ 2 2 ] = c a l l Sample . getSample ( 5 ,
DIGITAL , DIGITAL SAMPLING TIME , RISING EDGE | EEPROM TOTALIZER ) ;
// c o u n t e r c h a n n e l s f o r f r e q u e n c y measurement , w i l l r e s e t t o z e r o .
r e c o r d [ 2 3 ] = c a l l Sample . getSample ( 0 ,
COUNTER, MISC SAMPLING TIME ,
RESET ZERO AFTER READ | RISING EDGE ) ;
c a l l Leds . greenOn ( ) ;
MPK * /
}
else {
c a l l Leds . redOn ( ) ;
}
r e t u r n SUCCESS ;
}
/ ****************************************************************************
* Stop t h e component .
*
**************************************************************************** /
command r e s u l t t S t d C o n t r o l . s t o p ( ) {
c a l l SamplerControl . stop ( ) ;
r e t u r n SUCCESS ;
}
/ ****************************************************************************
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
46
* Task t o t r a n s m i t r a d i o message
* NOTE t h a t data p a y l o a d was a l r e a d y c o p i e d from t h e c o r r e s p o n d i n g UART p a c k e t
**************************************************************************** /
task void send radio msg ( )
{
uint8 t i ;
uint16 t
len ;
XDataMsg * data ;
i f ( sending packet )
return ;
a to m i c s e n d i n g p a c k e t=TRUE;
// F i l l t h e g i v e n data b u f f e r .
data = ( XDataMsg * ) c a l l Send . g e t B u f f e r ( msg ptr , &l e n ) ;
tmppack=(XDataMsg * ) p a c k e t . data ;
f o r ( i = 0 ; i <= s i z e o f ( XDataMsg) −1; i ++)
( ( u i n t 8 t * ) data ) [ i ] = ( ( u i n t 8 t * ) tmppack ) [ i ] ;
data−>xmeshHeader . p a c k e t i d = 6 ;
data−>xmeshHeader . b o a r d i d = SENSOR BOARD ID ;
= TOS LOCAL ADDRESS ;
data−>xmeshHeader . n o d e i d
data−>xmeshHeader . p a r e n t
= c a l l RouteControl . getParent ( ) ;
#i f FEATURE UART SEND
i f (TOS LOCAL ADDRESS != 0 ) {
c a l l Leds . yellowOn ( ) ;
c a l l PowerMgrDisable ( ) ;
TOSH uwait ( 1 0 0 0 ) ;
i f ( c a l l SendUART . send (TOS UART ADDR,
s i z e o f ( XDataMsg ) , m s g p t r ) != SUCCESS)
{
a to m i c s e n d i n g p a c k e t = FALSE ;
c a l l Leds . g r e e n T o g g l e ( ) ;
c a l l PowerMgrEnable ( ) ;
}
}
else
#e n d i f
{
// Send t h e RF p a c k e t !
c a l l Leds . yellowOn ( ) ;
i f ( c a l l Send . send ( msg ptr , s i z e o f ( XDataMsg ) ) != SUCCESS) {
a to m i c s e n d i n g p a c k e t = FALSE ;
c a l l Leds . yellowOn ( ) ;
c a l l Leds . g r e e n O f f ( ) ;
}
}
}
1. XBOW/APPS/XMESH/XMDA300 DIRECTORY
47
#i f FEATURE UART SEND
/ **
* Handle c o m p l e t i o n o f s e n t UART p a c k e t .
*
* @author
* @version
*/
Martin Turon
2004/7/21
mturon
Initial
revision
e v e n t r e s u l t t SendUART . sendDone ( TOS MsgPtr msg , r e s u l t t s u c c e s s )
{
//
i f ( msg−>addr == TOS UART ADDR) {
a to m i c m s g p t r = msg ;
msg ptr−>addr = TOS BCAST ADDR ;
i f ( c a l l Send . send ( msg ptr , s i z e o f ( XDataMsg ) ) != SUCCESS) {
a to m i c s e n d i n g p a c k e t = FALSE ;
c a l l Leds . y e l l o w O f f ( ) ;
}
i f (TOS LOCAL ADDRESS != 0 ) // n e v e r t u r n on power mgr f o r b a s e
c a l l PowerMgrEnable ( ) ;
//}
r e t u r n SUCCESS ;
}
#e n d i f
/ **
* Handle c o m p l e t i o n o f s e n t RF p a c k e t .
*
* @author
Martin Turon
* @version
2004/5/27
mturon
*/
Initial
revision
e v e n t r e s u l t t Send . sendDone ( TOS MsgPtr msg , r e s u l t t s u c c e s s )
{
a to m i c {
m s g p t r = msg ;
s e n d i n g p a c k e t = FALSE ;
}
c a l l Leds . y e l l o w O f f ( ) ;
#i f FEATURE UART SEND
i f (TOS LOCAL ADDRESS != 0 ) // n e v e r t u r n on power mgr f o r b a s e
c a l l PowerMgrEnable ( ) ;
#e n d i f
r e t u r n SUCCESS ;
}
/ **
* Handle a s i n g l e dataReady e v e n t f o r a l l MDA300 data t y p e s .
*
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
48
* @author
*
* @version
* @n
*/
Leah Fera , Martin Turon
2004/3/17
2004/4/1
leahfera
mturon
Intial revision
Improved s t a t e machine
event r e s u l t t
Sample . dataReady ( u i n t 8 t c h a n n e l , u i n t 8 t channelType , u i n t 1 6 t data )
{
uint8 t i ;
s w i t c h ( channelType ) {
c a s e ANALOG:
switch ( channel ) {
// MSG 1 : f i r s t p a r t o f a n a l o g c h a n n e l s (0 −6)
// c a s e 0 : // O r i g i n a l l i n e MPK
case 7:
// MPK j u s t cram ADC7 i n t o ADC0’ s s p o t
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . adc0 =data ;
a to m i c { m s g s t a t u s |=0 x01 ; }
break ;
case 1:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . adc1 =data ;
a to m i c { m s g s t a t u s |=0 x02 ; }
break ;
case 2:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . adc2 =data ;
a to m i c { m s g s t a t u s |=0 x04 ; }
break ;
default :
break ;
} // c a s e ANALOG ( c h a n n e l )
break ;
c a s e DIGITAL :
switch ( channel ) {
case 0:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . d i g 0=data ;
a to m i c { m s g s t a t u s |=0 x08 ; }
break ;
case 1:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . d i g 1=data ;
a to m i c { m s g s t a t u s |=0 x10 ; }
1. XBOW/APPS/XMESH/XMDA300 DIRECTORY
break ;
case 2:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . d i g 2=data ;
a to m i c { m s g s t a t u s |=0 x20 ; }
break ;
default :
break ;
} // c a s e DIGITAL ( c h a n n e l )
break ;
c a s e BATTERY:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . v r e f =data ;
a to m i c { m s g s t a t u s |=0 x40 ; }
break ;
c a s e HUMIDITY :
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . humid =data ;
a to m i c { m s g s t a t u s |=0 x80 ; }
break ;
c a s e TEMPERATURE:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . humtemp =data ;
a to m i c { m s g s t a t u s |=0 x100 ; }
break ;
default :
break ;
}
// s w i t c h ( channelType )
i f ( sending packet )
r e t u r n SUCCESS ;
i f ( m s g s t a t u s == p k t f u l l ) {
msg status = 0;
packetCount++;
// MPK
i f ( packetCount >= 3 )
// MPK
{
// MPK
c a l l SamplerControl . stop ( ) ;
// MPK
packetCount = 0 ;
// MPK
// g e t r i d o f t i m e r t i c k s accumulated
// w h i l e s a m p l i n g MPK
a to m i c { t i m e r T i c k s = 0 ; }
// MPK
}
// MPK
49
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
50
i f ( packetCount > 1 ) // MPK f i r s t ADC r e a d i n g a l w a y s i s bad
post send radio msg ( ) ;
}
r e t u r n SUCCESS ;
}
/ ****************************************************************************
* Timer F i r e d −
*
**************************************************************************** /
e v e n t r e s u l t t Timer . f i r e d ( ) {
MPK
i f ( sending packet )
r e t u r n SUCCESS ;
// don ’ t o v e r r u n b u f f e r s
i f ( t e s t != 0 ) {
t e s t =0;
call relay normally closed . toggle ( ) ;
c a l l Leds . greenOn ( ) ;
}
else
{
t e s t =1;
c a l l relay normally open . toggle ( ) ;
c a l l Leds . greenOn ( ) ;
}
/*
MPK * /
// MPK i f enough t i c k s , t u r n on t h e MDA300 and do a new
// MPK round o f getSample c a l l s
a to m i c { t i m e r T i c k s ++;}
// MPK
i f ( quickMeshCount > MPK QUICK MESH COUNT) / / MPK
{
// MPK
a to m i c { maxTicks = MPK TICKS ; } // MPK
}
// MPK
// MPK
// c a l l R o u t e C o n t r o l . manualUpdate ( ) ; // MPK
if
( ( t i m e r T i c k s < maxTicks ) && ( maxTicks > 0 ) )
r e t u r n SUCCESS ;
// MPK
// MPK
a to m i c { t i m e r T i c k s = 0 ; } // MPK
a to m i c { quickMeshCount++;} // MPK
c a l l S a m p l e r C o n t r o l . i n i t ( ) ; // MPK I s t h i s n e c e s s a r y ?
c a l l SamplerControl . s t a r t ( ) ;
// MPK
i f ( c a l l PlugPlay ( ) ) // MPK
{
// MPK
r e c o r d [ 1 4 ] = c a l l Sample . getSample ( 0 ,
TEMPERATURE, MISC SAMPLING TIME ,SAMPLER DEFAULT ) ;
r e c o r d [ 1 5 ] = c a l l Sample . getSample ( 0 ,
// MPK
1. XBOW/APPS/XMESH/XMDA300 DIRECTORY
51
HUMIDITY, MISC SAMPLING TIME ,SAMPLER DEFAULT ) ; // MPK
r e c o r d [ 1 6 ] = c a l l Sample . getSample ( 0 ,
BATTERY, MISC SAMPLING TIME ,SAMPLER DEFAULT ) ;
// MPK
r e c o r d [ 7 ] = c a l l Sample . getSample ( 7 ,
ANALOG, ANALOG SAMPLING TIME,
AVERAGE FOUR | EXCITATION 25 | DELAY BEFORE MEASUREMENT
);
// MPK
}
r e t u r n SUCCESS ;
}
/ **
* Handles a l l b r o a d c a s t command m e s s a g e s s e n t o v e r network .
*
* NOTE: B c a s t m e s s a g e s w i l l not be r e c e i v e d i f s e q n o i s not p r o p e r l y
*
s e t i n f i r s t two b y t e s o f data p a y l o a d .
Also , p a y l o a d i s
*
t h e r e m a i n i n g data a f t e r t h e r e q u i r e d s e q n o .
*
* @version
2004/10/5
mturon
I n i t i a l version
*/
e v e n t r e s u l t t XCommand . r e c e i v e d (XCommandOp * opcode ) {
s w i t c h ( opcode−>cmd ) {
c a s e XCOMMAND SET RATE:
// Change t h e data c o l l e c t i o n r a t e .
/ * MPK
t i m e r r a t e = opcode−>param . n e w r a t e ;
c a l l Timer . s t o p ( ) ;
c a l l Timer . s t a r t (TIMER REPEAT, t i m e r r a t e ) ;
MPK * /
a to m i c { maxTicks = opcode−>param . n e w r a t e ; } // MPK
a to m i c { t i m e r T i c k s = 0 ; }
// MPK
break ;
c a s e XCOMMAND SLEEP:
// Stop c o l l e c t i n g data , and go t o s l e e p .
s l e e p i n g = TRUE;
c a l l Timer . s t o p ( ) ;
c a l l Leds . s e t ( 0 ) ;
break ;
c a s e XCOMMANDWAKEUP:
// Wake up from s l e e p s t a t e .
i f ( sleeping ) {
initialize ();
c a l l Timer . s t a r t (TIMER REPEAT, t i m e r r a t e ) ;
s l e e p i n g = FALSE ;
}
break ;
c a s e XCOMMAND RESET:
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
52
// R e s e t t h e mote now .
break ;
c a s e XCOMMAND ACTUATE:
break ;
default :
break ;
}
r e t u r n SUCCESS ;
}
#i f d e f XMESHSYNC
t a s k v o i d SendPing ( ) {
XDataMsg * pReading ;
u i n t 1 6 t Len ;
( ( pReading = ( XDataMsg * ) c a l l Send . g e t B u f f e r ( msg ptr ,&Len ) ) ) {
pReading−>xmeshHeader . p a r e n t = c a l l R o u t e C o n t r o l . g e t P a r e n t ( ) ;
i f ( ( c a l l Send . send ( msg ptr , s i z e o f ( XDataMsg ) ) ) != SUCCESS)
a to m i c s e n d i n g p a c k e t = FALSE ;
}
if
}
e v e n t TOS MsgPtr DownTree . r e c e i v e ( TOS MsgPtr pMsg ,
v o i d * payload , u i n t 1 6 t payloadLen ) {
i f ( ! sending packet ) {
c a l l Leds . y e l l o w T o g g l e ( ) ;
a to m i c s e n d i n g p a c k e t = TRUE;
p o s t SendPing ( ) ;
// pMsg−>XXX) ;
}
r e t u r n pMsg ;
}
#e n d i f
}
2. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
53
2. xbow/tos/sensorboards/mda300 directory
/*
*
* C o p y r i g h t ( c ) 2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a . A l l
* rights reserved .
*
* R e d i s t r i b u t i o n and u s e i n s o u r c e and b i n a r y forms , with o r w i t h o u t
* modification , are permitted provided that the f o l l o w i n g c o n d i t i o n s
* a r e met :
*
* − R e d i s t r i b u t i o n s o f s o u r c e code must r e t a i n t h e above c o p y r i g h t
*
n o t i c e , t h i s l i s t o f c o n d i t i o n s and t h e f o l l o w i n g d i s c l a i m e r .
*
* − N e i t h e r t h e name o f t h e U n i v e r s i t y nor t h e names o f i t s
*
c o n t r i b u t o r s may be used t o e n d o r s e o r promote p r o d u c t s d e r i v e d
*
from t h i s s o f t w a r e w i t h o u t s p e c i f i c p r i o r w r i t t e n p e r m i s s i o n .
*
* THIS SOFTWARE I S PROVIDED BY THE REGENTS AND CONTRIBUTORS ‘ ‘ AS IS ’ ’
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT , INCIDENTAL, SPECIAL ,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE, DATA, OR
* PROFITS ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY , WHETHER IN CONTRACT, STRICT LIABILITY , OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* Authors :
Mohammad Rahimi mhr@cens . u c l a . edu
* History :
c r e a t e d 08/14/2003
* update a t 11/14/2003
*
*
* d r i v e r f o r ADS7828EB on mda300ca
*
*/
module IBADCM
{
provides {
i n t e r f a c e StdControl ;
i n t e r f a c e ADConvert [ u i n t 8 t p o r t ] ;
i n t e r f a c e SetParam [ u i n t 8 t p o r t ] ;
i n t e r f a c e Power a s EXCITATION25 ;
i n t e r f a c e Power a s EXCITATION33 ;
i n t e r f a c e Power a s EXCITATION50 ;
}
u s e s i n t e r f a c e I2CPacket ;
u s e s i n t e r f a c e Leds ;
uses i n t e r f a c e StdControl as I2CPacketControl ;
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
54
u s e s i n t e r f a c e Timer a s P o w e r S t a b a l i z i n g T i m e r ;
uses i n t e r f a c e StdControl as SwitchControl ;
u s e s i n t e r f a c e S w i tc h ;
}
implementation
{
enum {IDLE , PICK CHANNEL, GET SAMPLE, CONTINUE SAMPLE , START CONVERSION PROCESS} ;
#d e f i n e VOLTAGE STABLE TIME 50
//Time i t t a k e s f o r t h e s u p p l y v o l t a g e t o be s t a b l e enough
#d e f i n e MAX ANALOG CHNNELS 13
#d e f i n e MAX CHANNELS MAX ANALOG CHNNELS + 1
//The l a s t c h a n n e l i s not an a n a l o g c h a n n e l
// but we keep i t o n l y f o r t h e s a k e o f e x c i a t i o n .
/ * Note : we do not do a n y t h i n g i n s i d e a s y n c p a r t s o a l l p a r t s a r e s y n c h r o n o u s and
t h e r e i s no s y n c h r o n i z a t i o n h a za rd . Now ADC r u n s i n t h e round−r o b i n f a s h i n s o i t
i s f a i r .*/
char s t a t e ;
/* c u r r e n t s t a t e o f t h e i 2 c r e q u e s t */
uint16 t value ;
/ * v a l u e o f t h e i n c o m i n g ADC r e a d i n g * /
u i n t 8 t chan ;
u i n t 8 t param [MAX CHANNELS ] ;
/ * we r e s e r v e l a s t param f o r e x c i t a t i o n o f d i g i t a l c h a n n e l s * /
u i n t 1 6 t a d c b it m ap ;
i n t 8 t conversionNumber ;
// Note ” c o n d i t i o n ” s h o u l d be a g l o b a l v a r i a b l e . S i n c e I t i s p a s s e d by a d d r e s s t o I2CPacketM . n
// s h o u l d be v a l i d even out o f t h e s c o p e o f t h a t f u n c t i o n s i n c e I2CPacketM . nc u s e s i t by i t s
uint8 t condition ;
// s e t t h e c o n d i t i o n command b y t e .
// s e t
#d e f i n e
#d e f i n e
#d e f i n e
of bitwise
t e s t b i t ( var
s e t b i t ( var ,
c l r b i t ( var ,
functions
, bit )
( ( v a r ) & ( 1 <<( b i t ) ) )
bit )
( ( v a r ) |= ( 1 << ( b i t ) ) )
bit )
( ( v a r ) &= ˜ ( 1 << ( b i t ) ) )
//The e x c i t a t i o n c i r c u i t s
#d e f i n e FIVE VOLT ON ( ) TOSH SET PW5 PIN ( )
#d e f i n e FIVE VOLT OFF ( ) TOSH CLR PW5 PIN ( )
#d e f i n e THREE VOLT ON( ) TOSH SET PW3 PIN ( )
#d e f i n e THREE VOLT OFF( ) TOSH CLR PW3 PIN ( )
#d e f i n e TURN VOLTAGE BUFFER ON( ) TOSH SET PW2 PIN ( )
#d e f i n e TURN VOLTAGE BUFFER OFF( ) TOSH CLR PW2 PIN ( )
#d e f i n e VOLTAGE BOOSTER ON( ) TOSH CLR PW1 PIN ( )
#d e f i n e VOLTAGE BOOSTER OFF( ) TOSH SET PW1 PIN ( )
//The i n s t r u m e n t a t i o n a m p l i f i e r
#d e f i n e TURN AMPLIFIERS ON ( ) TOSH SET PW6 PIN ( )
#d e f i n e TURN AMPLIFIERS OFF ( ) TOSH CLR PW6 PIN ( )
// i f z e r o then r e t u r n z e r o and i f one no
2. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
/* d e c l a r e a t i o n o f f u n c t i o n c o n v e r t */
r e s u l t t convert ( ) ;
void s e t E x c i t a t i o n ( )
{
VOLTAGE BOOSTER ON ( ) ;
i f ( param [ chan ] & EXCITATION 25 ) TURN VOLTAGE BUFFER ON ( ) ;
i f ( param [ chan ] & EXCITATION 33 )
{
THREE VOLT ON ( ) ;
}
i f ( param [ chan ] & EXCITATION 50 )
{
FIVE VOLT ON ( ) ;
}
}
void r e s e t E x c i t a t i o n ( )
{
uint8 t i ;
u i n t 8 t f l a g 2 5 =0 , f l a g 3 3 =0 , f l a g 5 0 =0;
f o r ( i =0 ; i < MAX CHANNELS ; i ++)
{
i f ( param [ i ] & EXCITATION ALWAYS ON)
{
i f ( param [ i ] & EXCITATION 25 ) f l a g 2 5 =1;
i f ( param [ i ] & EXCITATION 33 ) f l a g 3 3 =1;
i f ( param [ i ] & EXCITATION 50 ) f l a g 5 0 =1;
}
}
i f ( f l a g 2 5 ==0) TURN VOLTAGE BUFFER OFF ( ) ;
i f ( f l a g 3 3 ==0) THREE VOLT OFF ( ) ;
i f ( f l a g 5 0 ==0) FIVE VOLT OFF ( ) ;
i f ( ! f l a g 2 5 && ! f l a g 3 3 && ! f l a g 5 0 )
{
VOLTAGE BOOSTER OFF ( ) ;
}
}
command v o i d EXCITATION25 . on ( )
{
param [MAX CHANNELS − 1 ] |= EXCITATION 25 ;
param [MAX CHANNELS − 1 ] |= EXCITATION ALWAYS ON ;
VOLTAGE BOOSTER ON ( ) ;
TURN VOLTAGE BUFFER ON ( ) ;
}
command v o i d EXCITATION25 . o f f ( )
{
param [MAX CHANNELS − 1 ] &= ! EXCITATION 25 ;
i f ( s t a t e == IDLE ) r e s e t E x c i t a t i o n ( ) ;
// o t h e r w i s e t h e f u c t i o n w i l l be c a l l e d a t t h e end o f c o n v e r s i o n
55
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
56
}
command v o i d EXCITATION33 . on ( )
{
param [MAX CHANNELS − 1 ] |= EXCITATION 33 ;
param [MAX CHANNELS − 1 ] |= EXCITATION ALWAYS ON ;
VOLTAGE BOOSTER ON ( ) ;
THREE VOLT ON ( ) ;
}
command v o i d EXCITATION33 . o f f ( )
{
param [MAX CHANNELS − 1 ] &= ! EXCITATION 33 ;
i f ( s t a t e == IDLE ) r e s e t E x c i t a t i o n ( ) ;
// o t h e r w i s e t h e f u c t i o n w i l l be c a l l e d a t t h e end o f c o n v e r s i o n
}
command v o i d EXCITATION50 . on ( )
{
param [MAX CHANNELS − 1 ] |= EXCITATION 50 ;
param [MAX CHANNELS − 1 ] |= EXCITATION ALWAYS ON ;
VOLTAGE BOOSTER ON ( ) ;
FIVE VOLT ON ( ) ;
}
command v o i d EXCITATION50 . o f f ( )
{
param [MAX CHANNELS−1] &= ! EXCITATION 50 ;
i f ( s t a t e == IDLE ) r e s e t E x c i t a t i o n ( ) ;
// o t h e r w i s e t h e f u c t i o n w i l l be c a l l e d a t t h e end o f c o n v e r s i o n
}
v o i d setNumberOfConversions ( )
{
conversionNumber = 1 ;
i f ( param [ chan ] & AVERAGE FOUR ) conversionNumber = 4 ;
i f ( param [ chan ] & AVERAGE EIGHT ) conversionNumber = 8 ;
i f ( param [ chan ] & AVERAGE SIXTEEN) conversionNumber = 1 6 ;
return ;
}
command r e s u l t t S t d C o n t r o l . i n i t ( ) {
int i ;
a to m i c {
s t a t e = IDLE ;
a dc b it m ap =0;
f o r ( i =0; i < MAX CHANNELS ; i ++) param [ i ]=0 x00 ;
}
c a l l I2CPacketControl . i n i t ( ) ;
c a l l SwitchControl . i n i t ( ) ;
TOSH MAKE PW2 OUTPUT ( ) ;
TOSH MAKE PW4 OUTPUT ( ) ;
TOSH MAKE PW5 OUTPUT ( ) ;
TOSH MAKE PW6 OUTPUT ( ) ;
TURN AMPLIFIERS OFF ( ) ;
VOLTAGE BOOSTER OFF ( ) ;
FIVE VOLT OFF ( ) ;
2. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
57
THREE VOLT OFF ( ) ;
TURN VOLTAGE BUFFER OFF ( ) ;
r e t u r n SUCCESS ;
}
command r e s u l t t S t d C o n t r o l . s t a r t ( ) {
c a l l SwitchControl . s t a r t ( ) ;
r e t u r n SUCCESS ;
}
command r e s u l t t S t d C o n t r o l . s t o p ( ) {
u i n t 8 t ADCaddress ;
// MPK
ADCaddress =8;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =12;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =9;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =13;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =10;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =14;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =11;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =15;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =0;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =1;
// MPK
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) ,
ADCaddress =2;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
0 x03 ) ;
// MPK
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
58
ADCaddress=(ADCaddress << 4 ) & 0 x f 0 ;
// MPK
ADCaddress=ADCaddress | 0 x03 ;
// MPK
c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& ADCaddress ) , 0 x03 ) ;
// MPK
TURN AMPLIFIERS OFF ( ) ;
// MPK
// MPK
VOLTAGE BOOSTER OFF ( ) ;
FIVE VOLT OFF ( ) ;
// MPK
THREE VOLT OFF ( ) ;
// MPK
TURN VOLTAGE BUFFER OFF ( ) ;
// MPK
c a l l SwitchControl . stop ( ) ;
r e t u r n SUCCESS ;
}
command r e s u l t t SetParam . setParam [ u i n t 8 t i d ] ( u i n t 8 t mode ) {
param [ i d ]=mode ;
r e t u r n SUCCESS ;
}
d e f a u l t e v e n t r e s u l t t ADConvert . dataReady [ u i n t 8 t i d ] ( u i n t 1 6 t data ) {
r e t u r n SUCCESS ;
}
task void adc get data ( )
{
u i n t 8 t myIndex ;
u i n t 8 t count ;
u i n t 1 6 t my bitmap ;
i f ( s t a t e != IDLE ) r e t u r n ; // That means t h e component i s busy i n a
// c o n v e r s i o n p r o c e s s . When c o n v e r s i o n done
// e i t h e r s u c c e s s f u l l o r f a i l i t i s
// g a u r a n t e e d t h a t t h i s t a s k w i l l be
// p o s t e d s o we can s a f e l y r e t u r n .
v a l u e =0;
s t a t e=START CONVERSION PROCESS ;
a to m i c { my bitmap = ad c b it m ap ; }
// i t g a u r a n t e e s a round r o b i n f a i r s c h e d u l i n g o f ADC c o n v e r s i o n s .
count =0;
myIndex=chan +1;
i f ( myIndex > MAX ANALOG CHNNELS) myIndex =0;
w h i l e ( ! t e s t b i t ( my bitmap , myIndex ) )
{
myIndex++;
i f ( myIndex > MAX ANALOG CHNNELS) myIndex =0;
count++;
i f ( count > MAX ANALOG CHNNELS) { s t a t e=IDLE ; r e t u r n ; }
// no one w a i t i n g f o r c o n v e r s i o n
}
chan=myIndex ;
setExcitation ();
2. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
59
setNumberOfConversions ( ) ;
// i f among t h e i n s t r u m e n t a t i o n c h a n n e l s we s e t t h e MUX
i f ( chan == 7 | | chan==8 | | chan==9 | | chan==10)
{
c h a r muxChannel ;
TURN AMPLIFIERS ON ( ) ;
s w i t c h ( chan ) {
default :
// s h o u l d n e v e r happen
case 7:
muxChannel = MUX CHANNEL SEVEN;
break ;
case 8:
muxChannel = MUX CHANNEL EIGHT;
break ;
case 9:
muxChannel = MUX CHANNEL NINE ;
break ;
case 10:
muxChannel = MUX CHANNEL TEN;
break ;
};
i f ( ( c a l l S w i tc h . s e t A l l ( muxChannel ) ) == FAIL )
{
// Can not s e l e c t c h a n n e l
s t a t e = IDLE ;
TURN AMPLIFIERS OFF ( ) ;
post adc get data ( ) ;
resetExcitation ();
}
}
else {
// I f t h e c o n v e r s i o n s happens f a s t t h e r e i s no need t o
// w a i t f o r s e t t l i n g o f t h e power supply ,
// n o t e t h a t power s u p p l y s h o u l d be s e t ON by u s e r u s i n g t h e e x c i t a t i o n command
i f ( param [ chan ] & DELAY BEFORE MEASUREMENT) {
c a l l P o w e r S t a b a l i z i n g T i m e r . s t a r t (TIMER ONE SHOT, VOLTAGE STABLE TIME ) ;
}
else {
convert ( ) ;
}
}
}
r e s u l t t convert () {
i f ( s t a t e == START CONVERSION PROCESS | | s t a t e == CONTINUE SAMPLE)
{
s t a t e = PICK CHANNEL ;
// f i g u r e out which c h a n n e l i s t o be s e t
s w i t c h ( chan ) {
default :
// s h o u l d n e v e r happen
case 0:
condition = 8;
break ;
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
60
case 1:
condition = 12;
break ;
case 2:
condition = 9;
break ;
case 3:
condition = 13;
break ;
case 4:
condition = 10;
break ;
case 5:
condition = 14;
break ;
case 6:
condition = 11;
break ;
case 7:
case 8:
case 9:
case 10:
// t h e s e c h a n n e l s a l l u s e ADC c h a n n e l 7 and m u l t i p l e x i t .
condition = 15;
break ;
case 11:
condition = 0;
break ;
case 12:
condition = 1;
break ;
case 13:
condition = 2;
break ;
}
}
// s h i f t t h e c h a n n e l and s i n g l e −ended i n p u t b i t s o v e r
c o n d i t i o n = ( c o n d i t i o n << 4 ) & 0 x f 0 ;
condition = condition | 0 x0f ;
// t e l l t h e ADC t o s t a r t c o n v e r t i n g
i f ( ( c a l l I2CPacket . w r i t e P a c k e t ( 1 , ( c h a r * )(& c o n d i t i o n ) , 0 x03 ) ) == FAIL )
{
s t a t e = IDLE ;
post adc get data ( ) ;
resetExcitation ();
r e t u r n FALSE ;
}
r e t u r n SUCCESS ;
TURN AMPLIFIERS OFF ( ) ;
}
// g e t a s i n g l e r e a d i n g from i d we
command r e s u l t t ADConvert . getData [ u i n t 8 t i d ] ( ) {
2. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
61
i f ( id >13) r e t u r n FAIL ;
// s h o u l d n e v e r happen u n l e s s w i r i n g i s wrong .
a to m i c {
s e t b i t ( adc bitmap , i d ) ;
}
post adc get data ( ) ;
r e t u r n SUCCESS ;
}
// S e t t i n g t h e MUX has been done .
e v e n t r e s u l t t S w it c h . s e t A l l D o n e ( b o o l r )
{
if (! r) {
s t a t e=IDLE ;
TURN AMPLIFIERS OFF ( ) ;
post adc get data ( ) ;
resetExcitation ();
r e t u r n FAIL ;
}
// I f t h e c o n v e r s i o n s happens f a s t t h e r e i s no need t o w a i t f o r s e t t l i n g o f
// t h e power supply , n o t e t h a t power s u p p l y s h o u l d be s e t ON by u s e r u s i n g
// t h e e x c i t a t i o n command
i f ( param [ chan ] & DELAY BEFORE MEASUREMENT) {
c a l l P o w e r S t a b a l i z i n g T i m e r . s t a r t (TIMER ONE SHOT, VOLTAGE STABLE TIME ) ;
r e t u r n SUCCESS ;
}
else {
return convert ( ) ;
}
r e t u r n SUCCESS ;
}
event r e s u l t t PowerStabalizingTimer . f i r e d ( ) {
return convert ( ) ;
}
/ * not y e t implemented * /
command r e s u l t t ADConvert . g e t C o n t i n u o u s D a t a [ u i n t 8 t i d ] ( ) {
r e t u r n FAIL ;
}
e v e n t r e s u l t t I2CPacket . readPacketDone ( c h a r l e n g t h , c h a r * data ) {
i f ( l e n g t h != 2 )
{
s t a t e = IDLE ;
TURN AMPLIFIERS OFF ( ) ;
a to m i c { c l r b i t ( adc bitmap , chan ) ; }
post adc get data ( ) ;
s i g n a l ADConvert . dataReady [ chan ] (ADC ERROR) ;
resetExcitation ();
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
62
r e t u r n FAIL ;
}
i f ( s t a t e == GET SAMPLE)
{
v a l u e += ( data [ 1 ] & 0 x f f ) + ( ( data [ 0 ] << 8 ) & 0 x 0 f 0 0 ) ;
conversionNumber −−;
// v a l u e = ( data [ 0 ] << 8 ) & 0 x 0 f 0 0 ;
// v a l u e += ( data [ 1 ] & 0 x f f ) ;
i f ( conversionNumber==0) {
s t a t e = IDLE ;
i f ( param [ chan ] & AVERAGE SIXTEEN)
v a l u e = ( ( v a l u e +8) >>4) & 0 x 0 f f f ;
// t h e a d d i t i o n i s f o r more p e r c i s i o n
e l s e i f ( param [ chan ] & AVERAGE EIGHT )
v a l u e = ( ( v a l u e +4) >>3) & 0 x 0 f f f ;
// t h e a d d i t i o n i s f o r more p e r c i s i o n
e l s e i f ( param [ chan ] & AVERAGE FOUR )
v a l u e = ( ( v a l u e +2) >>2) & 0 x 0 f f f ;
// t h e a d d i t i o n i s f o r more p e r c i s i o n
// e l s e { // do n o t h i n g s i n c e no a v e r a g i n g }
TURN AMPLIFIERS OFF ( ) ;
a to m i c { c l r b i t ( adc bitmap , chan ) ; }
post adc get data ( ) ;
s i g n a l ADConvert . dataReady [ chan ] ( v a l u e ) ;
resetExcitation ();
}
else {
s t a t e = CONTINUE SAMPLE ;
convert ( ) ;
}
}
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t I2CPacket . w r i t e P a c k e t D o n e ( b o o l r e s u l t ) {
if (! result )
{
s t a t e = IDLE ;
TURN AMPLIFIERS OFF ( ) ;
a to m i c { c l r b i t ( adc bitmap , chan ) ; }
post adc get data ( ) ;
s i g n a l ADConvert . dataReady [ chan ] (ADC ERROR) ;
resetExcitation ();
r e t u r n FAIL ;
}
i f ( s t a t e == PICK CHANNEL)
{
s t a t e = GET SAMPLE;
i f ( ( c a l l I2CPacket . r e a d P a c k e t ( 2 , 0 x03 ) ) == 0 )
{
// r e a d i n g from t h e bus f a i l e d
s t a t e = IDLE ;
post adc get data ( ) ;
resetExcitation ();
2. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
r e t u r n FAIL ;
}
}
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t S w it c h . getDone ( c h a r v a l )
{
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t S w it c h . setDone ( b o o l r )
{
r e t u r n SUCCESS ;
}
}
63
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
64
3. xbow/tos/sensorboards/mda300 directory
/*
*
* C o p y r i g h t ( c ) 2003 The Regents o f t h e U n i v e r s i t y o f C a l i f o r n i a . A l l
* rights reserved .
*
* R e d i s t r i b u t i o n and u s e i n s o u r c e and b i n a r y forms , with o r w i t h o u t
* modification , are permitted provided that the f o l l o w i n g c o n d i t i o n s
* a r e met :
*
* − R e d i s t r i b u t i o n s o f s o u r c e code must r e t a i n t h e above c o p y r i g h t
*
n o t i c e , t h i s l i s t o f c o n d i t i o n s and t h e f o l l o w i n g d i s c l a i m e r .
*
* − N e i t h e r t h e name o f t h e U n i v e r s i t y nor t h e names o f i t s
*
c o n t r i b u t o r s may be used t o e n d o r s e o r promote p r o d u c t s d e r i v e d
*
from t h i s s o f t w a r e w i t h o u t s p e c i f i c p r i o r w r i t t e n p e r m i s s i o n .
*
* THIS SOFTWARE I S PROVIDED BY THE REGENTS AND CONTRIBUTORS ‘ ‘ AS IS ’ ’
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT , INCIDENTAL, SPECIAL ,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE, DATA, OR
* PROFITS ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY , WHETHER IN CONTRACT, STRICT LIABILITY , OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* Authors :
Mohammad Rahimi mhr@cens . u c l a . edu
* History :
created
08/14/2003
* history :
m o d i f i e d 11/14/2003
*
*
*/
module SamplerM
{
provides i n t e r f a c e StdControl as SamplerControl ;
p r o v i d e s i n t e r f a c e Sample ;
p r o v i d e s command r e s u l t t PlugPlay ( ) ;
uses {
i n t e r f a c e Leds ;
i n t e r f a c e Timer a s SamplerTimer ;
// a n a l o g
interface
interface
interface
channels
S t d C o n t r o l a s IBADCcontrol ;
ADConvert a s ADC0 ;
ADConvert a s ADC1 ;
3. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
i n t e r f a c e ADConvert a s ADC2 ;
i n t e r f a c e ADConvert a s ADC3 ;
i n t e r f a c e ADConvert a s ADC4 ;
i n t e r f a c e ADConvert a s ADC5 ;
i n t e r f a c e ADConvert a s ADC6 ;
i n t e r f a c e ADConvert a s ADC7 ;
i n t e r f a c e ADConvert a s ADC8 ;
i n t e r f a c e ADConvert a s ADC9 ;
i n t e r f a c e ADConvert a s ADC10 ;
i n t e r f a c e ADConvert a s ADC11 ;
i n t e r f a c e ADConvert a s ADC12 ;
i n t e r f a c e ADConvert a s ADC13 ;
//ADC p a r a m e t e r s
i n t e r f a c e SetParam a s SetParam0 ;
i n t e r f a c e SetParam a s SetParam1 ;
i n t e r f a c e SetParam a s SetParam2 ;
i n t e r f a c e SetParam a s SetParam3 ;
i n t e r f a c e SetParam a s SetParam4 ;
i n t e r f a c e SetParam a s SetParam5 ;
i n t e r f a c e SetParam a s SetParam6 ;
i n t e r f a c e SetParam a s SetParam7 ;
i n t e r f a c e SetParam a s SetParam8 ;
i n t e r f a c e SetParam a s SetParam9 ;
i n t e r f a c e SetParam a s SetParam10 ;
i n t e r f a c e SetParam a s SetParam11 ;
i n t e r f a c e SetParam a s SetParam12 ;
i n t e r f a c e SetParam a s SetParam13 ;
// h e a l t h c h a n n e l s temp , humidity , v o l t a g e
i n t e r f a c e StdControl as BatteryControl ;
// i n t e r f a c e ADConvert a s B a t t e r y ;
i n t e r f a c e ADC a s B a t t e r y ;
i n t e r f a c e S t d C o n t r o l a s TempHumControl ;
i n t e r f a c e ADConvert a s Temp ;
i n t e r f a c e ADConvert a s Hum;
// d i g i t a l
interface
interface
interface
interface
interface
interface
interface
and r e l a y c h a n n e l s
StdControl as DioControl ;
Dio a s Dio0 ;
Dio a s Dio1 ;
Dio a s Dio2 ;
Dio a s Dio3 ;
Dio a s Dio4 ;
Dio a s Dio5 ;
// c o u n t e r c h a n n e l s
i n t e r f a c e StdControl as CounterControl ;
i n t e r f a c e Dio a s Counter ;
command r e s u l t t Plugged ( ) ;
}
}
65
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
66
implementation
{
#d e f i n e
#d e f i n e
#d e f i n e
#d e f i n e
SCHEDULER RESPONSE TIME 150
TIME SCALE 100
FLAG SET 1
FLAG NOT SET 0
// t h i s means we have r e s o l u t i o n o f 0 . 1 s e c
// f l a g f o r power s a v i n g
uint8 t flag25 , flag33 , flag50 ;
bool stopFlag ;
//MPK
// main data s t r u c t u r e 10 b y t e p e r r e c o r d e
s t r u c t SampleRecords {
u i n t 8 t channel ;
u i n t 8 t channelType ;
//
u i n t 8 t param ;
int16 t t i c ks l ef t ;
// used f o r k e e p i n g t h e m o n o s t a b l e t i m e r
// Sampling i n t e r v a l s e t by command above ,
int16 t sampling interval ;
// I t i s i n second , SampleRecord i n no u s e i f s e t t o z e r o .
} SampleRecord [MAX SAMPLERECORD ] ;
// c h e c k what i s t h e SampleRecords t h a t a r e a v i l a b l e and r e t u r n one t h a t i s a v a i l a b l e
s t a t i c i n l i n e int8 t get avilable SampleRecord ()
{
int8 t i ;
f o r ( i =0; i <MAX SAMPLERECORD; i ++)
i f ( SampleRecord [ i ] . s a m p l i n g i n t e r v a l == SAMPLE RECORD FREE )
return i ;
r e t u r n −1; // not a v a i l a b l e SampleRecord
}
// f i n d t h e n e x t c h a n n e l which s h o u l d be s e r v i c e d .
//
task
void next schedule (){
int8 t i ;
i n t 1 6 t min=SCHEDULER RESPONSE TIME ;
//minimum time t o ba c a l l e d .
// we s e t i t t o 15 Sec min s o t h a t i f a
// new s a m p l i n g r e q u e s t comes we r e p l y with 15 s e c d e l a y .
i f ( stopFlag )
//MPK
return ;
//MPK
f o r ( i =0; i <MAX SAMPLERECORD; i ++) // f i n d out any one who s h o u l d be s e r v i c e d b e f o r e n e x t 15
{
i f ( SampleRecord [ i ] . s a m p l i n g i n t e r v a l != SAMPLE RECORD FREE )
{
i f ( SampleRecord [ i ] . t i c k s l e f t < min ) min = SampleRecord [ i ] . t i c k s l e f t ;
}
}
f o r ( i =0; i <MAX SAMPLERECORD; i ++) // s e t t h e n e x t time a c c o r d i n g l y
3. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
67
{
i f ( SampleRecord [ i ] . s a m p l i n g i n t e r v a l != SAMPLE RECORD FREE )
{
SampleRecord [ i ] . t i c k s l e f t = SampleRecord [ i ] . t i c k s l e f t −min ;
}
}
min=min * TIME SCALE ;
// s i n c e t i m e r g e t s i n p u t i n m i l i s e c o n d and we g e t command i n 0 .
c a l l SamplerTimer . s t a r t (TIMER ONE SHOT , min ) ;
}
static
{
i n l i n e v o i d s e t p a r a m a n a l o g ( u i n t 8 t i , u i n t 8 t param )
s w i t c h ( SampleRecord [ i ] . c h a n n e l ) {
case 0:
c a l l SetParam0 . setParam ( param ) ;
break ;
case 1:
c a l l SetParam1 . setParam ( param ) ;
break ;
case 2:
c a l l SetParam2 . setParam ( param ) ;
break ;
case 3:
c a l l SetParam3 . setParam ( param ) ;
break ;
case 4:
c a l l SetParam4 . setParam ( param ) ;
break ;
case 5:
c a l l SetParam5 . setParam ( param ) ;
break ;
case 6:
c a l l SetParam6 . setParam ( param ) ;
break ;
case 7:
c a l l SetParam7 . setParam ( param ) ;
break ;
case 8:
c a l l SetParam8 . setParam ( param ) ;
break ;
case 9:
c a l l SetParam9 . setParam ( param ) ;
break ;
case 10:
c a l l SetParam10 . setParam ( param ) ;
break ;
case 11:
c a l l SetParam11 . setParam ( param ) ;
break ;
case 12:
c a l l SetParam12 . setParam ( param ) ;
break ;
case 13:
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
68
c a l l SetParam13 . setParam ( param ) ;
break ;
default :
}
return ;
}
static
{
i n l i n e v o i d s e t p a r a m d i g i t a l ( i n t 8 t i , u i n t 8 t param )
s w i t c h ( SampleRecord [ i ] . c h a n n e l ) {
case 0:
c a l l Dio0 . setparam ( param ) ;
break ;
case 1:
c a l l Dio1 . setparam ( param ) ;
break ;
case 2:
c a l l Dio2 . setparam ( param ) ;
break ;
case 3:
c a l l Dio3 . setparam ( param ) ;
break ;
case 4:
c a l l Dio4 . setparam ( param ) ;
break ;
case 5:
c a l l Dio5 . setparam ( param ) ;
break ;
default :
}
return ;
}
static
{
i n l i n e v o i d s e t p a r a m c o u n t e r ( i n t 8 t i , u i n t 8 t param )
c a l l Counter . setparam ( param ) ;
return ;
}
v o i d sampleRecord ( u i n t 8 t i )
{
i f ( SampleRecord [ i ] . channelType==ANALOG) {
s w i t c h ( SampleRecord [ i ] . c h a n n e l ) {
case 0:
c a l l ADC0 . getData ( ) ;
break ;
case 1:
c a l l ADC1 . getData ( ) ;
break ;
case 2:
c a l l ADC2 . getData ( ) ;
break ;
3. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
69
case 3:
c a l l ADC3 . getData ( ) ;
break ;
case 4:
c a l l ADC4 . getData ( ) ;
break ;
case 5:
c a l l ADC5 . getData ( ) ;
break ;
case 6:
c a l l ADC6 . getData ( ) ;
break ;
case 7:
c a l l ADC7 . getData ( ) ;
break ;
case 8:
c a l l ADC8 . getData ( ) ;
break ;
case 9:
c a l l ADC9 . getData ( ) ;
break ;
case 10:
c a l l ADC10 . getData ( ) ;
break ;
case 11:
c a l l ADC11 . getData ( ) ;
break ;
case 12:
c a l l ADC12 . getData ( ) ;
break ;
case 13:
c a l l ADC13 . getData ( ) ;
break ;
default :
}
return ;
}
i f ( SampleRecord [ i ] . channelType==BATTERY) {
c a l l B a t t e r y . getData ( ) ;
return ;
}
i f ( SampleRecord [ i ] . channelType==TEMPERATURE | | SampleRecord [ i ] . channelType==HUMIDITY
i f ( SampleRecord [ i ] . channelType==TEMPERATURE) c a l l Temp . getData ( ) ;
i f ( SampleRecord [ i ] . channelType==HUMIDITY) c a l l Hum. getData ( ) ;
return ;
}
i f ( SampleRecord [ i ] . channelType==DIGITAL) {
s w i t c h ( SampleRecord [ i ] . c h a n n e l ) {
case 0:
c a l l Dio0 . getData ( ) ;
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
70
break ;
case 1:
c a l l Dio1 . getData ( ) ;
break ;
case 2:
c a l l Dio2 . getData ( ) ;
break ;
case 3:
c a l l Dio3 . getData ( ) ;
break ;
case 4:
c a l l Dio4 . getData ( ) ;
break ;
case 5:
c a l l Dio5 . getData ( ) ;
break ;
default :
}
return ;
}
i f ( SampleRecord [ i ] . channelType==COUNTER) {
c a l l Counter . getData ( ) ;
return ;
}
return ;
}
command r e s u l t t S a m p l e r C o n t r o l . i n i t ( ) {
int i ;
c a l l CounterControl . i n i t ( ) ;
c a l l DioControl . i n i t ( ) ;
c a l l IBADCcontrol . i n i t ( ) ;
c a l l BatteryControl . i n i t ( ) ;
c a l l TempHumControl . i n i t ( ) ;
f o r ( i =0; i <MAX SAMPLERECORD; i ++){
SampleRecord [ i ] . s a m p l i n g i n t e r v a l=SAMPLE RECORD FREE;
SampleRecord [ i ] . t i c k s l e f t =0 x f f f f ;
}
a to m i c {
f l a g 2 5=FLAG NOT SET ;
f l a g 3 3=FLAG NOT SET ;
f l a g 5 0=FLAG NOT SET ;
}
r e t u r n SUCCESS ;
}
command r e s u l t t S a m p l e r C o n t r o l . s t a r t ( ) {
s t o p F l a g = FALSE ;
// MPK
c a l l CounterControl . s t a r t ( ) ;
c a l l DioControl . s t a r t ( ) ;
c a l l IBADCcontrol . s t a r t ( ) ;
c a l l BatteryControl . s t a r t ( ) ;
c a l l TempHumControl . s t a r t ( ) ;
3. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
71
c a l l CounterControl . s t a r t ( ) ;
// p o s t n e x t s c h e d u l e ( ) ;
next schedule ( ) ;
r e t u r n SUCCESS ;
}
command r e s u l t t S a m p l e r C o n t r o l . s t o p ( ) {
int i ;
// MPK
s t o p F l a g = TRUE;
// MPK
c a l l SamplerTimer . s t o p ( ) ;
// MPK
a to m i c {
// MPK
f o r ( i = 0 ; i < MAX SAMPLERECORD; i ++) // MPK
{
// MPK
c a l l Sample . s t o p ( i ) ;
// MPK
}
// MPK
}
// MPK
c a l l CounterControl . stop ( ) ;
c a l l DioControl . stop ( ) ;
c a l l IBADCcontrol . s t o p ( ) ;
c a l l BatteryControl . stop ( ) ;
c a l l TempHumControl . s t o p ( ) ;
r e t u r n SUCCESS ;
}
command r e s u l t t PlugPlay ( )
{
r e t u r n c a l l Plugged ( ) ;
}
e v e n t r e s u l t t SamplerTimer . f i r e d ( ) {
uint8 t i ;
// sample anyone which i s s up p o s e d t o be sampled
f o r ( i =0; i <MAX SAMPLERECORD; i ++)
{
i f ( SampleRecord [ i ] . s a m p l i n g i n t e r v a l != SAMPLE RECORD FREE )
{
i f ( SampleRecord [ i ] . t i c k s l e f t == 0 )
{
SampleRecord [ i ] . t i c k s l e f t = SampleRecord [ i ] . s a m p l i n g i n t e r v a l ;
sampleRecord ( i ) ;
}
}
}
//now s e e when t i m e r s h o u l d be f i r e d f o r new s a m p l e s
// p o s t n e x t s c h e d u l e ( ) ;
i f ( ! stopFlag )
//MPK
{
//MPK
next schedule ( ) ;
}
//MPK
r e t u r n SUCCESS ;
}
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
72
command r e s u l t t Sample . s e t d i g i t a l o u t p u t ( u i n t 8 t c h a n n e l , u i n t 8 t s t a t e )
{
}
command i n t 8 t Sample . getSample ( u i n t 8 t c h a n n e l , u i n t 8 t channelType , u i n t 1 6 t i n t e r v a l , u i n t 8
{
int8 t i ;
i=g e t a v i l a b l e S a m p l e R e c o r d ( ) ;
i f ( i ==−1) r e t u r n i ;
SampleRecord [ i ] . c h a n n e l=c h a n n e l ;
SampleRecord [ i ] . channelType=channelType ;
SampleRecord [ i ] . t i c k s l e f t =0;
// used f o r k e e p i n g t h e m o n o s t a b l e t i m e r
SampleRecord [ i ] . s a m p l i n g i n t e r v a l=i n t e r v a l ;
// Sampling i n t e r v a l s e t by command above ,
// SampleRecord i n no u s e i f s e t t o z e r o
// SampleRecord [ i ] . param=param ;
i f ( SampleRecord [ i ] . channelType == DIGITAL ) s e t p a r a m d i g i t a l ( i , param ) ;
i f ( SampleRecord [ i ] . channelType == COUNTER ) s e t p a r a m c o u n t e r ( i , param ) ;
i f ( SampleRecord [ i ] . channelType == ANALOG ) s e t p a r a m a n a l o g ( i , param ) ;
return i ;
}
command r e s u l t t Sample . reTask ( i n t 8 t r e c o r d , u i n t 1 6 t i n t e r v a l )
{
i f ( r e c o r d <0 | | r e c o r d >MAX SAMPLERECORD) r e t u r n FAIL ;
SampleRecord [ r e c o r d ] . s a m p l i n g i n t e r v a l=i n t e r v a l ;
r e t u r n SUCCESS ;
}
command r e s u l t t Sample . s t o p ( i n t 8 t r e c o r d )
{
i f ( r e c o r d <0 | | r e c o r d >MAX SAMPLERECORD) r e t u r n FAIL ;
i f ( SampleRecord [ r e c o r d ] . channelType == ANALOG ) s e t p a r a m a n a l o g ( r e c o r d , 0 ) ;
SampleRecord [ r e c o r d ] . s a m p l i n g i n t e r v a l= SAMPLE RECORD FREE;
r e t u r n SUCCESS ;
}
// MPK
d e f a u l t e v e n t r e s u l t t Sample . dataReady ( u i n t 8 t c h a n n e l , u i n t 8 t channelType , u i n t 1 6 t data )
{
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC0 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 0 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC1 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 1 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
3. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
}
e v e n t r e s u l t t ADC2 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 2 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC3 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 3 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC4 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 4 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC5 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 5 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC6 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 6 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC7 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 7 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC8 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 8 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC9 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 9 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC10 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 1 0 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC11 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 1 1 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC12 . dataReady ( u i n t 1 6 t data ) {
73
2. MICA2-BASED WIRELESS ACM VERSION 2 SOFTWARE: MODIFICATION OF XMDA300
74
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 1 2 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t ADC13 . dataReady ( u i n t 1 6 t data ) {
i f ( data != ADC ERROR) s i g n a l Sample . dataReady ( 1 3 ,ANALOG, data ) ;
r e t u r n SUCCESS ;
}
a s y n c e v e n t r e s u l t t B a t t e r y . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 0 ,BATTERY, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Temp . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 0 ,TEMPERATURE, data ) ; // data t y p e problem
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Hum. dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 0 ,HUMIDITY, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio0 . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 0 , DIGITAL , data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio1 . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 1 , DIGITAL , data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio2 . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 2 , DIGITAL , data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio3 . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 3 , DIGITAL , data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio4 . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 4 , DIGITAL , data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio5 . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 5 , DIGITAL , data ) ;
3. XBOW/TOS/SENSORBOARDS/MDA300 DIRECTORY
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio0 . d a t a O v e r f l o w ( ) {
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio1 . d a t a O v e r f l o w ( ) {
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio2 . d a t a O v e r f l o w ( ) {
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio3 . d a t a O v e r f l o w ( ) {
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio4 . d a t a O v e r f l o w ( ) {
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Dio5 . d a t a O v e r f l o w ( ) {
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Counter . dataReady ( u i n t 1 6 t data ) {
s i g n a l Sample . dataReady ( 0 ,COUNTER, data ) ;
r e t u r n SUCCESS ;
}
e v e n t r e s u l t t Counter . d a t a O v e r f l o w ( ) {
r e t u r n SUCCESS ;
}
}
75
CHAPTER 3
MICA2-Based Wireless ACM Version 3 Software:
Modification Version 2 XMDA300: Shake ’n
Wake
This appendix contains all software used to program the MICA2 motes
for Version 3 of the MICA2-based wireless ACM system. This appendix is organized by software directory and only the modified files are
included.
77
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
78
1. MICA2 Software
1.1. xbow/tos/XLib directory.
/ **
* P r o v i d e s a l i b r a r y module f o r h a n d l i n g b a s i c a p p l i c a t i o n m e s s a g e s f o r
* c o n t r o l l i n g a w i r e l e s s s e n s o r network .
*
* @file
XCommand . h
* @author
Martin Turon
* @version
2004/10/1
mturon
I n i t i a l version
*
* Summary o f XSensor commands :
*
r e s e t , s l e e p , wakeup
*
set / get ( rate ) ” heartbeat ”
*
s e t / g e t ( nodeid , group )
*
s e t / g e t ( r a d i o f r e q , band , power )
*
actuate ( device , s ta t e )
*
set / get ( c a l i b r a t i o n )
*
s e t / g e t ( mesh type , max r e s e n d )
*
* C o p y r i g h t ( c ) 2004 Crossbow Technology , I n c .
All rights reserved .
*
* $ I d : XCommand . h , v 1 . 2 2005/01/27 0 3 : 3 6 : 3 1 husq Exp $
*/
#d e f i n e INITIAL TIMER RATE
10000
enum {
// B a s i c i n s t r u c t i o n s :
XCOMMAND END = 0x0 ,
XCOMMAND NOP = 0x1 ,
XCOMMAND GET SERIALID,
// Power Management :
XCOMMAND RESET = 0 x10 ,
XCOMMAND SLEEP,
XCOMMANDWAKEUP,
// B a s i c update r a t e :
XCOMMAND SET RATE = 0 x20 ,
XCOMMAND GET RATE,
// MoteConfig Parameter s e t t i n g s :
XCOMMAND GET CONFIG = 0 x30 ,
XCOMMAND SET NODEID,
XCOMMAND SET GROUP,
XCOMMAND SET RF POWER,
XCOMMAND SET RF CHANNEL,
// A c t u a t i o n :
XCOMMAND ACTUATE = 0 x40 ,
// Update r a t e
// Return r a d i o f r e q and power
1. MICA2 SOFTWARE
79
// MPK
XCOMMAND SET TICKS = 0 x50 , //MPK
XCOMMAND SET QUICK,
//MPK
} XCommandOpcode ;
enum {
XCMD DEVICE LED GREEN,
XCMD DEVICE LED YELLOW,
XCMD DEVICE LED RED,
XCMD DEVICE LEDS,
XCMD DEVICE SOUNDER,
XCMD DEVICE RELAY1,
XCMD DEVICE RELAY2,
XCMD DEVICE RELAY3,
XCMD DEVICE POT
} XSensorSubDevice ;
// added pot l i n e t o above MPK
enum {
XCMD STATE OFF = 0 ,
XCMD STATE ON = 1 ,
XCMD STATE TOGGLE
} XSensorSubState ;
t y p e d e f s t r u c t XCommandOp {
uint16 t
cmd ;
// XCommandOpcode
union {
u i n t 3 2 t newrate ;
u i n t 1 6 t nodeid ;
group ;
uint8 t
uint8 t
rf power ;
uint8 t
rf channel ;
u i n t 8 t quick ;
//MPK
u i n t 1 6 t t i c k s ; //MPK
//! <
//! <
//! <
//! <
//! <
FOR
FOR
FOR
FOR
FOR
XCOMMAND SET RATE
XCOMMAND SET NODEID
XCOMMAND SET GROUP
XCOMMAND SET RF POWER
XCOMMAND SET RF CHANNEL
/ ** FOR XCOMMAND ACCTUATE * /
struct {
uint16 t device ;
//! < LEDS, sounder , r e l a y ,
uint16 t state ;
//! < o f f , on , t o g g l e , . . .
} actuate ;
} param ;
}
attribute
( ( packed ) ) XCommandOp ;
typedef struct
// u i n t 1 6 t
uint16 t
XCommandOp
}
attribute
...
XCommandMsg {
seq no ;
// +++ R e q u i r e d by l i b / B r o a d c a s t
dest ;
// +++ D e s i r e d d e s t i n a t i o n ( 0xFFFF f o r b r o a d c a s t ? )
inst [ 6 ] ;
( ( packed ) ) XCommandMsg ;
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
80
t y p e d e f s t r u c t XSensorHeader {
uint8 t
board id ;
// mica2 , mica2dot , micaz
uint8 t
p a c k e t i d ; // 1 : d e f a u l t s e r i a l i d msg
uint8 t
node id ;
uint8 t
rsvd ;
( ( packed ) ) XCmdDataHeader ;
} attribute
typedef st r u c t SerialIDData {
uint8 t id [ 8 ] ;
}
attribute
( ( packed ) ) S e r i a l I D D a t a ;
t y p e d e f s t r u c t XCmdDataMsg {
XCmdDataHeader xHeader ;
union {
// PData1
datap1 ;
SerialIDData sid ;
} xData ;
}
attribute
( ( packed ) ) XCmdDataMsg ;
#i f d e f i n e d (PLATFORM MICA2)
#d e f i n e MOTE BOARD ID 0 x60
#e n d i f
#i f d e f i n e d (PLATFORM MICA2DOT)
#d e f i n e MOTE BOARD ID 0 x61
#e n d i f
#i f d e f i n e d (PLATFORM MICAZ)
#d e f i n e MOTE BOARD ID 0 x62
#e n d i f
/*
enum {
AM XCOMMAND MSG = 4 8 ,
};
*/
//MTS300 s e n s o r board i d
//MTS300 s e n s o r board i d
//MTS300 s e n s o r board i d
1. MICA2 SOFTWARE
81
1.2. xbow/apps/XMesh/XMDA300 directory.
/*
*
tab : 4
IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING .
By
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
downloading , cop ying , i n s t a l l i n g o r u s i n g t h e s o f t w a r e you a g r e e t o
this license .
I f you do not a g r e e t o t h i s l i c e n s e , do not download ,
i n s t a l l , copy o r u s e t h e s o f t w a r e .
I n t e l Open S o u r c e L i c e n s e
C o p y r i g h t ( c ) 2002 I n t e l C o r p o r a t i o n
All rights reserved .
R e d i s t r i b u t i o n and u s e i n s o u r c e and b i n a r y forms , with o r w i t h o u t
modification , are permitted provided that the f o l l o w i n g c o n d i t i o n s are
met :
R e d i s t r i b u t i o n s o f s o u r c e code must r e t a i n t h e above c o p y r i g h t
n o t i c e , t h i s l i s t o f c o n d i t i o n s and t h e f o l l o w i n g d i s c l a i m e r .
R e d i s t r i b u t i o n s i n b i n a r y form must r e p r o d u c e t h e above c o p y r i g h t
n o t i c e , t h i s l i s t o f c o n d i t i o n s and t h e f o l l o w i n g d i s c l a i m e r i n t h e
documentation and / o r o t h e r m a t e r i a l s p r o v i d e d with t h e d i s t r i b u t i o n .
N e i t h e r t h e name o f t h e I n t e l C o r p o r a t i o n nor t h e names o f i t s
c o n t r i b u t o r s may be used t o e n d o r s e o r promote p r o d u c t s d e r i v e d from
t h i s software without s p e c i f i c p r i o r written permission .
THIS SOFTWARE I S PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
‘ ‘ AS IS ’ ’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE INTEL OR ITS
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT , INCIDENTAL, SPECIAL ,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE, DATA, OR
PROFITS ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY , WHETHER IN CONTRACT, STRICT LIABILITY , OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@author Leah Fera , Martin Turon , J a i d e v Prabhu
$ I d : XMDA300M. nc , v 1 . 4 2005/01/11 0 5 : 2 1 : 3 5 husq Exp $
/ ******************************************************************************
*
*
− T e s t s t h e MDA300 g e n e r a l p r o t o t y p i n g c a r d
*
( s e e Crossbow MTS S e r i e s User Manual )
*
− Read and c o n t r o l a l l MDA300 s i g n a l s :
*
ADC0, ADC1, ADC2, ADC3 , . . . ADC11 i n p u t s , DIO 0 −5 ,
*
c o u n t e r , b a t t e r y , humidity , temp
*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
* Output r e s u l t s t h r o u g h mica2 u a r t and r a d i o .
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
82
* Use x l i s t e n . e x e program t o view data from e i t h e r p o r t :
* u a r t : mount mica2 on mib510 with MDA300
*
( must be c o n n e c t e d o r now data i s r e a d )
*
c o n n e c t s e r i a l c a b l e t o PC
*
run x l i s t e n . e x e a t 57600 baud
* r a d i o : run mica2 with MDA300,
*
run a n o t h e r mica2 with TOSBASE
*
run x l i s t e n . e x e a t 56K baud
* LED : t h e l e d w i l l be g r e e n i f t h e MDA300 i s c o n n e c t e d t o t h e mica2 and
*
t h e program i s r u n n i n g ( and s e n d i n g out p a c k e t s ) .
Otherwise i t i s red .
*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
* Data p a c k e t s t r u c t u r e :
*
* PACKET #1 ( o f 4 )
* −−−−−−−−−−−−−−−−
* msg−>data [ 0 ] : s e n s o r id , MDA300 = 0 x81
* msg−>data [ 1 ] : p a c k e t number = 1
* msg−>data [ 2 ] : node i d
* msg−>data [ 3 ] : r e s e r v e d
* msg−>data [ 4 , 5 ] : a n a l o g adc data Ch . 0
* msg−>data [ 6 , 7 ] : a n a l o g adc data Ch . 1
* msg−>data [ 8 , 9 ] : a n a l o g adc data Ch . 2
* msg−>data [ 1 0 , 1 1 ] : a n a l o g adc data Ch . 3
* msg−>data [ 1 2 , 1 3 ] : a n a l o g adc data Ch . 4
* msg−>data [ 1 4 , 1 5 ] : a n a l o g adc data Ch . 5
* msg−>data [ 1 6 , 1 7 ] : a n a l o g adc data Ch . 6
*
* PACKET #2 ( o f 4 )
* −−−−−−−−−−−−−−−−
* msg−>data [ 0 ] : s e n s o r id , MDA300 = 0 x81
* msg−>data [ 1 ] : p a c k e t number = 2
* msg−>data [ 2 ] : node i d
* msg−>data [ 3 ] : r e s e r v e d
* msg−>data [ 4 , 5 ] : a n a l o g adc data Ch . 7
* msg−>data [ 6 , 7 ] : a n a l o g adc data Ch . 8
* msg−>data [ 8 , 9 ] : a n a l o g adc data Ch . 9
* msg−>data [ 1 0 , 1 1 ] : a n a l o g adc data Ch . 1 0
* msg−>data [ 1 2 , 1 3 ] : a n a l o g adc data Ch . 1 1
* msg−>data [ 1 4 , 1 5 ] : a n a l o g adc data Ch . 1 2
* msg−>data [ 1 6 , 1 7 ] : a n a l o g adc data Ch . 1 3
*
*
* PACKET #3 ( o f 4 )
* −−−−−−−−−−−−−−−−
* msg−>data [ 0 ] : s e n s o r id , MDA300 = 0 x81
* msg−>data [ 1 ] : p a c k e t number = 3
* msg−>data [ 2 ] : node i d
* msg−>data [ 3 ] : r e s e r v e d
* msg−>data [ 4 , 5 ] : d i g i t a l data Ch . 0
* msg−>data [ 6 , 7 ] : d i g i t a l data Ch . 1
* msg−>data [ 8 , 9 ] : d i g i t a l data Ch . 2
* msg−>data [ 1 0 , 1 1 ] : d i g i t a l data Ch . 3
* msg−>data [ 1 2 , 1 3 ] : d i g i t a l data Ch . 4
1. MICA2 SOFTWARE
83
* msg−>data [ 1 4 , 1 5 ] : d i g i t a l data Ch . 5
*
* PACKET #4 ( o f 4 )
* −−−−−−−−−−−−−−−−
* msg−>data [ 0 ] : s e n s o r id , MDA300 = 0 x81
* msg−>data [ 1 ] : p a c k e t number = 4
* msg−>data [ 2 ] : node i d
* msg−>data [ 3 ] : r e s e r v e d
* msg−>data [ 4 , 5 ] : b a t t
* msg−>data [ 6 , 7 ] : hum
* msg−>data [ 8 , 9 ] : temp
* msg−>data [ 1 0 , 1 1 ] : c o u n t e r
* msg−>data [ 1 4 ] : m s g 4 s t a t u s ( debug )
*
*************************************************************************** /
// i n c l u d e s e n s o r b o a r d . h d e f i n i t i o n s from t o s /mda300 d i r e c t o r y
#i n c l u d e ” a p p F e a t u r e s . h”
i n c l u d e s XCommand ;
includes sensorboard ;
module XMDA300M
{
provides i n t e r f a c e StdControl ;
uses {
i n t e r f a c e Leds ;
i n t e r f a c e Send ;
i n t e r f a c e RouteControl ;
#i f d e f XMESHSYNC
i n t e r f a c e R e c e i v e a s DownTree ;
#e n d i f
i n t e r f a c e XCommand ;
// Sampler Communication
i n t e r f a c e StdControl as SamplerControl ;
i n t e r f a c e Sample ;
// Timer
i n t e r f a c e Timer ;
// r e l a y s
i n t e r f a c e Relay a s r e l a y n o r m a l l y c l o s e d ;
i n t e r f a c e Relay a s r e l a y n o r m a l l y o p e n ;
// s u p p o r t f o r p l u g and p l a y
command r e s u l t t PlugPlay ( ) ;
#i f FEATURE UART SEND
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
84
i n t e r f a c e SendMsg a s SendUART ;
command r e s u l t t PowerMgrEnable ( ) ;
command r e s u l t t PowerMgrDisable ( ) ;
#e n d i f
}
}
implementation
{
#d e f i n e ANALOG SAMPLING TIME
90
#d e f i n e DIGITAL SAMPLING TIME 100
110
#d e f i n e MISC SAMPLING TIME
#d e f i n e MPK RATE 30720 // f i r e t w i c e p e r minute
#d e f i n e MPK TICKS 36 // 18 m i n u te s between s a m p l e s
#d e f i n e MPK QUICK MESH COUNT 60 // MPK t a k e 60 s a m p l e s a t a
// h i g h s p e e d b e f o r e l o w e r i n g r a t e
#d e f i n e
#d e f i n e
#d e f i n e
#d e f i n e
ANALOG SEND FLAG
DIGITAL SEND FLAG
MISC SEND FLAG
ERR SEND FLAG
1
1
1
1
#d e f i n e PACKET FULL 0x1C1 // MPK Temp , Hum, Batt , ADC0
#i f 0
#d e f i n e PACKET FULL 0x1FF
#e n d i f
#d e f i n e MSG LEN
29
// e x c l u d e s TOS header , but i n c l u d e s xbow h e a d e r
enum {
PENDING = 0 ,
NO MSG = 1
};
enum {
MDA300 PACKET1 = 1 ,
MDA300 PACKET2 = 2 ,
MDA300 PACKET3 = 3 ,
MDA300 PACKET4 = 4 ,
MDA300 ERR PACKET = 0 x f 8
};
/ ******************************************************
enum {
SENSOR ID = 0 ,
PACKET ID,
NODE ID ,
RESERVED,
DATA START
} XPacketDataEnum ;
****************************************************** /
/ * Messages B u f f e r s * /
1. MICA2 SOFTWARE
uint32 t
timer rate ;
bool
sleeping ;
bool sending packet ;
uint16 t
seqno ;
XDataMsg * tmppack ;
85
// a p p l i c a t i o n command s t a t e
TOS Msg p a c k e t ;
TOS Msg m s g s e n d b u f f e r ;
TOS MsgPtr m s g p t r ;
i n t packetCount = 0 ;
// MPK
int timerTicks = 0;
// MPK
i n t maxTicks = 2 ;
// MPK B r o a d c a s t e v e r y minute u n t i l
// quckMeshCount > MPK QUICK MESH COUNT
i n t quickMeshCount = 0 ;
// MPK
u i n t 1 6 t msg status , p k t f u l l ;
char t e s t ;
int8 t record [ 2 5 ] ;
s t a t i c void i n i t i a l i z e ( )
{
a to m i c
{
s l e e p i n g = FALSE ;
s e n d i n g p a c k e t = FALSE ;
// t i m e r r a t e = XSENSOR SAMPLE RATE ; // ORIGINAL LINE
t i m e r r a t e = MPK RATE;
// MPK
}
}
/ ****************************************************************************
* I n i t i a l i z e t h e component . I n i t i a l i z e Leds
*
**************************************************************************** /
command r e s u l t t S t d C o n t r o l . i n i t ( ) {
uint8 t i ;
// BEGIN MPK INT CODE
sei ();
EIMSK &= ˜ ( 1 << 6 ) ;
EICRB &= ˜ ( 0 x03 << 4 ) ;
EIMSK |= ( 1 << 6 ) ;
// END MPK INT CODE
//
//
//
//
c a l l Leds . i n i t ( ) ;
a to m i c {
m s g p t r = &m s g s e n d b u f f e r ;
Enable e x t e r n a l i n t e r r u p t s
d i s a b l e ext i n t 6
make i n t 6 low−l e v e l t r i g g e r e d
t u r n on e x t i n t 6
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
86
// s e n d i n g p a c k e t = FALSE ;
}
msg status = 0;
p k t f u l l = PACKET FULL ;
MAKE BAT MONITOR OUTPUT ( ) ;
MAKE ADC INPUT ( ) ;
// e n a b l e v o l t a g e r e f power p i n a s o u tp u t
// e n a b l e ADC7 a s i n p u t
// u s a r t 1 i s a l s o c o n n e c t e d t o e x t e r n a l s e r i a l f l a s h
// s e t u s a r t 1 l i n e s t o c o r r e c t s t a t e
// TOSH MAKE FLASH SELECT OUTPUT ( ) ;
TOSH MAKE FLASH OUT OUTPUT ( ) ;
// t x ou t p ut
// u s a r t c l k
TOSH MAKE FLASH CLK OUTPUT ( ) ;
// TOSH SET FLASH SELECT PIN ( ) ;
c a l l SamplerControl . i n i t ( ) ;
initialize ();
r e t u r n SUCCESS ;
// r e t u r n rcombine ( c a l l S a m p l e r C o n t r o l . i n i t ( ) , c a l l CommControl . i n i t ( ) ) ;
}
/ ****************************************************************************
* S t a r t t h e component . S t a r t t h e c l o c k . Setup t i m e r and s a m p l i n g
*
**************************************************************************** /
command r e s u l t t S t d C o n t r o l . s t a r t ( ) {
c a l l SamplerControl . s t a r t ( ) ;
i f ( c a l l PlugPlay ( ) )
{
c a l l Timer . s t a r t (TIMER REPEAT, t i m e r r a t e ) ;
// c h a n n e l p a r a m e t e r e s a r e i r r e l e v e n t
r e c o r d [ 1 4 ] = c a l l Sample . getSample ( 0 ,
TEMPERATURE,
MISC SAMPLING TIME ,
SAMPLER DEFAULT ) ;
r e c o r d [ 1 5 ] = c a l l Sample . getSample ( 0 ,
HUMIDITY,
MISC SAMPLING TIME ,
SAMPLER DEFAULT ) ;
r e c o r d [ 1 6 ] = c a l l Sample . getSample ( 0 ,
1. MICA2 SOFTWARE
BATTERY,
MISC SAMPLING TIME ,
SAMPLER DEFAULT ) ;
// s t a r t s a m p l i n g
c h a n n e l s . Channels 7−10 with a v e r a g i n g
// s i n c e t h e y a r e more p e r c i s e . c h a n n e l s 3−6 make a c t i v e e x c i t a t i o n
/ * MPK
r e c o r d [ 0 ] = c a l l Sample . getSample ( 0 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT ) ;
r e c o r d [ 1 ] = c a l l Sample . getSample ( 1 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT ) ;
r e c o r d [ 2 ] = c a l l Sample . getSample ( 2 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT ) ;
MPK * /
/ * MPK
r e c o r d [ 3 ] = c a l l Sample . getSample ( 3 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT | EXCITATION 33 | DELAY BEFORE MEASUREMENT) ;
r e c o r d [ 4 ] = c a l l Sample . getSample ( 4 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT ) ;
r e c o r d [ 5 ] = c a l l Sample . getSample ( 5 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT ) ;
r e c o r d [ 6 ] = c a l l Sample . getSample ( 6 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT ) ;
MPK * /
r e c o r d [ 7 ] = c a l l Sample . getSample ( 7 ,
ANALOG,
ANALOG SAMPLING TIME,
AVERAGE FOUR | EXCITATION 25 | DELAY BEFORE MEASUREMENT ) ;
/ * MPK
r e c o r d [ 8 ] = c a l l Sample . getSample ( 8 ,
87
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
88
ANALOG,
ANALOG SAMPLING TIME,
AVERAGE FOUR | EXCITATION 25 ) ;
r e c o r d [ 9 ] = c a l l Sample . getSample ( 9 ,
ANALOG,
ANALOG SAMPLING TIME,
AVERAGE FOUR | EXCITATION 25 ) ;
MPK * /
/ * MPK
r e c o r d [ 1 0 ] = c a l l Sample . getSample ( 1 0 ,
ANALOG,
ANALOG SAMPLING TIME,
AVERAGE FOUR | EXCITATION 25 ) ;
r e c o r d [ 1 1 ] = c a l l Sample . getSample ( 1 1 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT ) ;
r e c o r d [ 1 2 ] = c a l l Sample . getSample ( 1 2 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT ) ;
r e c o r d [ 1 3 ] = c a l l Sample . getSample ( 1 3 ,
ANALOG,
ANALOG SAMPLING TIME,
SAMPLER DEFAULT | EXCITATION 50 | EXCITATION ALWAYS ON ) ;
MPK * /
/*
// MPK
// d i g i t a l c h e n n e l s a s a c c u m u l a t i v e c o u n t e r
r e c o r d [ 1 7 ] = c a l l Sample . getSample ( 0 ,
DIGITAL ,
DIGITAL SAMPLING TIME ,
RESET ZERO AFTER READ | FALLING EDGE ) ;
r e c o r d [ 1 8 ] = c a l l Sample . getSample ( 1 ,
DIGITAL ,
DIGITAL SAMPLING TIME ,
RISING EDGE | EVENT) ;
r e c o r d [ 1 9 ] = c a l l Sample . getSample ( 2 ,
DIGITAL ,
DIGITAL SAMPLING TIME ,
SAMPLER DEFAULT | EVENT) ;
r e c o r d [ 2 0 ] = c a l l Sample . getSample ( 3 ,
DIGITAL ,
1. MICA2 SOFTWARE
89
DIGITAL SAMPLING TIME ,
FALLING EDGE ) ;
r e c o r d [ 2 1 ] = c a l l Sample . getSample ( 4 ,
DIGITAL ,
DIGITAL SAMPLING TIME ,
RISING EDGE ) ;
r e c o r d [ 2 2 ] = c a l l Sample . getSample ( 5 ,
DIGITAL ,
DIGITAL SAMPLING TIME ,
RISING EDGE | EEPROM TOTALIZER ) ;
// c o u n t e r c h a n n e l s f o r f r e q u e n c y measurement , w i l l r e s e t t o z e r o .
r e c o r d [ 2 3 ] = c a l l Sample . getSample ( 0 ,
COUNTER,
MISC SAMPLING TIME ,
RESET ZERO AFTER READ | RISING EDGE ) ;
c a l l Leds . greenOn ( ) ;
MPK * /
}
else {
c a l l Leds . redOn ( ) ;
}
r e t u r n SUCCESS ;
}
/ ****************************************************************************
* Stop t h e component .
*
**************************************************************************** /
command r e s u l t t S t d C o n t r o l . s t o p ( ) {
c a l l SamplerControl . stop ( ) ;
r e t u r n SUCCESS ;
}
/ ****************************************************************************
* Task t o t r a n s m i t r a d i o message
* NOTE t h a t data p a y l o a d was a l r e a d y c o p i e d from t h e c o r r e s p o n d i n g UART p a c k e t
**************************************************************************** /
task void send radio msg ( )
{
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
90
uint8 t i ;
uint16 t
len ;
XDataMsg * data ;
// BEGIN MPK INT CODE
EIMSK |= ( 1 << 6 ) ;
// t u r n on e x t i n t 6
// END MPK INT CODE
i f ( sending packet )
return ;
a to m i c s e n d i n g p a c k e t=TRUE;
// F i l l t h e g i v e n data b u f f e r .
data = ( XDataMsg * ) c a l l Send . g e t B u f f e r ( msg ptr , &l e n ) ;
tmppack=(XDataMsg * ) p a c k e t . data ;
f o r ( i = 0 ; i <= s i z e o f ( XDataMsg) −1; i ++)
( ( u i n t 8 t * ) data ) [ i ] = ( ( u i n t 8 t * ) tmppack ) [ i ] ;
data−>xmeshHeader . p a c k e t i d = 6 ;
data−>xmeshHeader . b o a r d i d = SENSOR BOARD ID ;
data−>xmeshHeader . n o d e i d
= TOS LOCAL ADDRESS ;
data−>xmeshHeader . p a r e n t
= c a l l RouteControl . getParent ( ) ;
#i f FEATURE UART SEND
i f (TOS LOCAL ADDRESS != 0 ) {
c a l l Leds . yellowOn ( ) ;
c a l l PowerMgrDisable ( ) ;
TOSH uwait ( 1 0 0 0 ) ;
i f ( c a l l SendUART . send (TOS UART ADDR, s i z e o f ( XDataMsg ) , m s g p t r ) != SUCCESS)
{
a to m i c s e n d i n g p a c k e t = FALSE ;
c a l l Leds . g r e e n T o g g l e ( ) ;
c a l l PowerMgrEnable ( ) ;
}
}
else
#e n d i f
{
// Send t h e RF p a c k e t !
c a l l Leds . yellowOn ( ) ;
i f ( c a l l Send . send ( msg ptr , s i z e o f ( XDataMsg ) ) != SUCCESS) {
a to m i c s e n d i n g p a c k e t = FALSE ;
c a l l Leds . yellowOn ( ) ;
c a l l Leds . g r e e n O f f ( ) ;
}
}
}
// BEGIN MPK INT CODE
TOSH SIGNAL(SIG INTERRUPT6)
{
1. MICA2 SOFTWARE
EIMSK &= ˜ ( 1 << 6 ) ;
post send radio msg ( ) ;
}
// END MPK INT CODE
91
// d i s a b l e e x t i n t 6
#i f FEATURE UART SEND
/ **
* Handle c o m p l e t i o n o f s e n t UART p a c k e t .
*
* @author
* @version
*/
Martin Turon
2004/7/21
mturon
Initial
revision
e v e n t r e s u l t t SendUART . sendDone ( TOS MsgPtr msg , r e s u l t t s u c c e s s )
{
//
i f ( msg−>addr == TOS UART ADDR) {
a to m i c m s g p t r = msg ;
msg ptr−>addr = TOS BCAST ADDR ;
i f ( c a l l Send . send ( msg ptr , s i z e o f ( XDataMsg ) ) != SUCCESS) {
a to m i c s e n d i n g p a c k e t = FALSE ;
c a l l Leds . y e l l o w O f f ( ) ;
}
i f (TOS LOCAL ADDRESS != 0 ) // n e v e r t u r n on power mgr f o r b a s e
c a l l PowerMgrEnable ( ) ;
//}
r e t u r n SUCCESS ;
}
#e n d i f
/ **
* Handle c o m p l e t i o n o f s e n t RF p a c k e t .
*
* @author
Martin Turon
* @version
2004/5/27
mturon
*/
Initial
revision
e v e n t r e s u l t t Send . sendDone ( TOS MsgPtr msg , r e s u l t t s u c c e s s )
{
a to m i c {
m s g p t r = msg ;
s e n d i n g p a c k e t = FALSE ;
}
c a l l Leds . y e l l o w O f f ( ) ;
#i f FEATURE UART SEND
i f (TOS LOCAL ADDRESS != 0 ) // n e v e r t u r n on power mgr f o r b a s e
c a l l PowerMgrEnable ( ) ;
#e n d i f
r e t u r n SUCCESS ;
}
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
92
/ **
* Handle a s i n g l e dataReady e v e n t f o r a l l MDA300 data t y p e s .
*
* @author
Leah Fera , Martin Turon
*
* @version
2004/3/17
leahfera
Intial revision
* @n
2004/4/1
mturon
Improved s t a t e machine
*/
event r e s u l t t
Sample . dataReady ( u i n t 8 t c h a n n e l , u i n t 8 t channelType , u i n t 1 6 t data )
{
uint8 t i ;
s w i t c h ( channelType ) {
c a s e ANALOG:
switch ( channel ) {
// MSG 1 : f i r s t p a r t o f a n a l o g c h a n n e l s (0 −6)
// c a s e 0 : // O r i g i n a l l i n e MPK
case 7:
// MPK j u s t cram ADC7 i n t o ADC0’ s s p o t
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . adc0 =data ;
a to m i c { m s g s t a t u s |=0 x01 ; }
break ;
case 1:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . adc1 =data ;
a to m i c { m s g s t a t u s |=0 x02 ; }
break ;
case 2:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . adc2 =data ;
a to m i c { m s g s t a t u s |=0 x04 ; }
break ;
default :
break ;
} // c a s e ANALOG ( c h a n n e l )
break ;
c a s e DIGITAL :
switch ( channel ) {
case 0:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . d i g 0=data ;
a to m i c { m s g s t a t u s |=0 x08 ; }
break ;
1. MICA2 SOFTWARE
case 1:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . d i g 1=data ;
a to m i c { m s g s t a t u s |=0 x10 ; }
break ;
case 2:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . d i g 2=data ;
a to m i c { m s g s t a t u s |=0 x20 ; }
break ;
default :
break ;
} // c a s e DIGITAL ( c h a n n e l )
break ;
c a s e BATTERY:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . v r e f =data ;
a to m i c { m s g s t a t u s |=0 x40 ; }
break ;
c a s e HUMIDITY :
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . humid =data ;
a to m i c { m s g s t a t u s |=0 x80 ; }
break ;
c a s e TEMPERATURE:
tmppack=(XDataMsg * ) p a c k e t . data ;
tmppack−>xData . datap6 . humtemp =data ;
a to m i c { m s g s t a t u s |=0 x100 ; }
break ;
default :
break ;
}
// s w i t c h ( channelType )
i f ( sending packet )
r e t u r n SUCCESS ;
i f ( m s g s t a t u s == p k t f u l l ) {
msg status = 0;
packetCount++;
// MPK
i f ( packetCount >= 3 )
// MPK
{
// MPK
c a l l SamplerControl . stop ( ) ;
// MPK
packetCount = 0 ;
// MPK
93
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
94
// g e t r i d o f t i m e r t i c k s accumulated w h i l e s a m p l i n g MPK
a to m i c { t i m e r T i c k s = 0 ; }
// MPK
}
// MPK
i f ( packetCount > 1 ) // MPK f i r s t ADC r e a d i n g a l w a y s i s bad
post send radio msg ( ) ;
}
r e t u r n SUCCESS ;
}
/ ****************************************************************************
* Timer F i r e d −
*
**************************************************************************** /
e v e n t r e s u l t t Timer . f i r e d ( ) {
MPK
i f ( sending packet )
r e t u r n SUCCESS ;
// don ’ t o v e r r u n b u f f e r s
i f ( t e s t != 0 ) {
t e s t =0;
call relay normally closed . toggle ( ) ;
c a l l Leds . greenOn ( ) ;
}
else
{
t e s t =1;
c a l l relay normally open . toggle ( ) ;
c a l l Leds . greenOn ( ) ;
}
/*
MPK * /
// MPK i f enough t i c k s , t u r n on t h e MDA300 and do a new
// MPK round o f getSample c a l l s
a to m i c { t i m e r T i c k s ++;}
// MPK
i f ( quickMeshCount > MPK QUICK MESH COUNT) / / MPK
{
// MPK
a to m i c { maxTicks = MPK TICKS ; } // MPK
}
// MPK
// MPK
// c a l l R o u t e C o n t r o l . manualUpdate ( ) ; // MPK
if
( ( t i m e r T i c k s < maxTicks ) && ( maxTicks > 0 ) )
r e t u r n SUCCESS ;
// MPK
// MPK
a to m i c { t i m e r T i c k s = 0 ; } // MPK
a to m i c { quickMeshCount++;} // MPK
c a l l S a m p l e r C o n t r o l . i n i t ( ) ; // MPK I s t h i s n e c e s s a r y ?
c a l l SamplerControl . s t a r t ( ) ;
// MPK
i f ( c a l l PlugPlay ( ) ) // MPK
{
// MPK
1. MICA2 SOFTWARE
95
r e c o r d [ 1 4 ] = c a l l Sample . getSample ( 0 ,
TEMPERATURE,
MISC SAMPLING TIME ,
SAMPLER DEFAULT ) ; // MPK
r e c o r d [ 1 5 ] = c a l l Sample . getSample ( 0 ,
HUMIDITY,
MISC SAMPLING TIME ,
SAMPLER DEFAULT ) ; // MPK
r e c o r d [ 1 6 ] = c a l l Sample . getSample ( 0 , BATTERY, MISC SAMPLING TIME ,SAMPLER DEFAULT ) ;
r e c o r d [ 7 ] = c a l l Sample . getSample ( 7 ,
ANALOG,
ANALOG SAMPLING TIME,AVERAGE FOUR |
EXCITATION 25 |
DELAY BEFORE MEASUREMENT ) ;
// MPK
}
r e t u r n SUCCESS ;
}
/ **
* Handles a l l b r o a d c a s t command m e s s a g e s s e n t o v e r network .
*
* NOTE: B c a s t m e s s a g e s w i l l not be r e c e i v e d i f s e q n o i s not p r o p e r l y
*
s e t i n f i r s t two b y t e s o f data p a y l o a d .
Also , p a y l o a d i s
*
t h e r e m a i n i n g data a f t e r t h e r e q u i r e d s e q n o .
*
* @version
2004/10/5
mturon
I n i t i a l version
*/
e v e n t r e s u l t t XCommand . r e c e i v e d (XCommandOp * opcode ) {
s w i t c h ( opcode−>cmd ) {
c a s e XCOMMAND SET RATE:
// Change t h e data c o l l e c t i o n r a t e .
/ * MPK
t i m e r r a t e = opcode−>param . n e w r a t e ;
c a l l Timer . s t o p ( ) ;
c a l l Timer . s t a r t (TIMER REPEAT, t i m e r r a t e ) ;
MPK * /
a to m i c { maxTicks = opcode−>param . n e w r a t e ; } // MPK
a to m i c { t i m e r T i c k s = 0 ; }
// MPK
break ;
c a s e XCOMMAND SLEEP:
// Stop c o l l e c t i n g data , and go t o s l e e p .
s l e e p i n g = TRUE;
c a l l Timer . s t o p ( ) ;
c a l l Leds . s e t ( 0 ) ;
break ;
c a s e XCOMMANDWAKEUP:
// Wake up from s l e e p s t a t e .
i f ( sleeping ) {
// MPK
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
96
initialize ();
c a l l Timer . s t a r t (TIMER REPEAT, t i m e r r a t e ) ;
s l e e p i n g = FALSE ;
}
break ;
c a s e XCOMMAND RESET:
// R e s e t t h e mote now .
break ;
c a s e XCOMMAND ACTUATE:
break ;
default :
break ;
}
r e t u r n SUCCESS ;
}
#i f d e f XMESHSYNC
t a s k v o i d SendPing ( ) {
XDataMsg * pReading ;
u i n t 1 6 t Len ;
( ( pReading = ( XDataMsg * ) c a l l Send . g e t B u f f e r ( msg ptr ,&Len ) ) ) {
pReading−>xmeshHeader . p a r e n t = c a l l R o u t e C o n t r o l . g e t P a r e n t ( ) ;
i f ( ( c a l l Send . send ( msg ptr , s i z e o f ( XDataMsg ) ) ) != SUCCESS)
a to m i c s e n d i n g p a c k e t = FALSE ;
}
if
}
e v e n t TOS MsgPtr DownTree . r e c e i v e ( TOS MsgPtr pMsg , v o i d * payload , u i n t 1 6 t payloadLen ) {
i f ( ! sending packet ) {
c a l l Leds . y e l l o w T o g g l e ( ) ;
a to m i c s e n d i n g p a c k e t = TRUE;
p o s t SendPing ( ) ;
// pMsg−>XXX) ;
}
r e t u r n pMsg ;
}
#e n d i f
}
2. UC-7420 SOFTWARE
97
2. UC-7420 Software
2.1. xbow/beta/tools/src/xcmd directory.
/ **
* Sends commands t o t h e s e r i a l p o r t t o c o n t r o l a w i r e l e s s s e n s o r network .
*
* @file
xcommand . c
* @author
Martin Turon
* @version
2004/10/3
mturon
I n i t i a l version
*
* C o p y r i g h t ( c ) 2004 Crossbow Technology , I n c .
All rights reserved .
*
* $ I d : xcommand . c , v 1 . 4 2004/11/11 0 1 : 0 0 : 5 1 mturon Exp $
*/
#i n c l u d e ”xcommand . h”
s t a t i c const char * g v e r s i o n =
” $ I d : xcommand . c , v 1 . 4 2004/11/11 0 1 : 0 0 : 5 1 mturon Exp $ ” ;
/ ** A s t r u c t u r e t o s t o r e p a r s e d p a r a m e t e r f l a g s . * /
t y p e d e f union {
unsigned f l a t ;
struct {
// o u tp u t
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
display options
display raw
display parsed
display cooked
export parsed
export cooked
log parsed
log cooked
display time
display ascii
display rsvd
// modes o f o p e r a t i o n
unsigned
display help
unsigned
display baud
u n s i g n e d mode debug
unsigned mode quiet
unsigned
mode version
unsigned mode socket
u n s i g n e d mode framing
} bits ;
struct {
u n s i g n e d s h o r t o ut p u t ;
u n s i g n e d s h o r t mode ;
} options ;
} s params ;
:
:
:
:
:
:
:
:
:
:
1;
1;
1;
1;
1;
1;
1;
1;
1;
7;
//! <
//! <
//! <
//! <
//! <
//! <
//! <
//! <
//! <
//! <
raw TOS p a c k e t s
p u l l out s e n s o r r e a d i n g s
convert to e n g i n e e r i n g u n i t s
o u tp u t comma d e l i m i t e d f i e l d s
o u tp u t comma d e l i m i t e d f i e l d s
l o g o ut p u t t o d a t a b a s e
l o g o ut p u t t o d a t a b a s e
d i s p l a y timestamp o f p a c k e t
d i s p l a y p a c k e t a s ASCII c h a r a c t e r s
pad f i r s t word f o r o u tp u t o p t i o n s
:
:
:
:
:
:
:
1;
1;
1;
1;
1;
1;
2;
//! <
//! <
//! <
//! <
//! <
//! <
baud was s e t by u s e r
debug s e r i a l p o r t
suppress headers
p r i n t v e r s i o n s o f a l l modules
connect to a s e r i a l forwarder
auto =0 , framed =1 , unframed=2
//! < one o ut p u t o p t i o n r e q u i r e d
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
98
/ ** A
static
static
static
v a r i a b l e to
s params
int
char *
s t o r e p a r s e d p a r a m e t e r f l a g s . */
g params ;
g ostream ;
//! < Handle o f o u tp u t stream
g command ;
g am type = AMTYPEXCOMMAND;
unsigned char
char *
g argument ;
int
unsigned
unsigned
unsigned
g
g
g
g
seq no
frame
group
dest
=
=
=
=
100;
0 x26 ;
0 xff ;
0xFFFF ;
//! < TOS AM t y p e o f command t o send
//! < B r o a d c a s t s e q u e n c e number
//! < P a c k e t i z e r s e q u e n c e number
//! < D e s t i n a t i o n n o d e i d ( 0xFFFF = a l l )
void xcommand print help ( ) {
printf (
”\ nUsage : xcommand <−?|v | q> command argument ”
”\n
<−s=d e v i c e > <−b=baud> <−i=s e r v e r : p o r t >”
”\n
<−n=nodeid> <−g=group> <−#=s e q n o >”
”\n
−? = d i s p l a y h e l p [ h e l p ] ”
”\n
−q = q u i e t mode ( s u p p r e s s h e a d e r s ) ”
”\n
−v = show v e r s i o n o f a l l modules ”
”\n
−b = s e t t h e b a u d r a t e [ baud=#|mica2 | mica2dot ] ”
”\n
−s = s e t s e r i a l p o r t d e v i c e [ d e v i c e=com1 ] ”
”\n
− i = i n t e r n e t s e r i a l f o r w a r d e r [ i n e t=h o s t : p o r t ] ”
”\n
−n = n o d e i d t o send command t o [ node=n o d e i d ] ”
”\n
−g = group t o send command o v e r [ group=g r o u p i d ] ”
”\n
−# = s e q u e n c e number o f command [#= s e q n o ] ”
”\n”
”\n
XCommand l i s t : ”
”\n
wake , s l e e p , r e s e t ”
//”\ n
s e t r a t e < i n t e r v a l i n m i l l i s e c >”
”\n
s e t r a t e < i n t e r v a l i n s e c o n d s >”
”\n
s e t l e d s <number from 0−7>”
”\n
s e t s o u n d <0= o f f |1= on>”
”\n
red on ,
red off ,
red toggle ”
”\n
green on , g r e e n o f f , g r e e n t o g g l e ”
”\n
yellow on , y e l l o w o f f , y e l l o w t o g g l e ”
”\n
s e t q u i c k <0= o f f |1= on>”
”\n
s e t t i c k s <i n t e g e r >”
”\n
s e t p o t <i n t e g e r >”
”\n\n”
);
}
/ **
*
*
*
*
*
*
E x t r a c t s command l i n e o p t i o n s and s e t s f l a g s i n t e r n a l l y .
@param
@param
argc
argv
@author
Martin Turon
Argument count
Argument v e c t o r
2. UC-7420 SOFTWARE
*
* @version
* @n
* @n
* @n
* @n
* @n
*/
2004/3/10
2004/3/12
2004/8/04
2004/8/22
2004/9/27
2004/9/29
mturon
mturon
mturon
mturon
mturon
mturon
99
Intial version
Added −b,− s ,−q,−x
Added − l [ v e r . 1 . 1 1 ]
Added − i [ v e r . 1 . 1 3 ]
Added −t [ v e r . 1 . 1 5 ]
Added −f ,−a [ v 1 . 1 6 ]
v o i d p a r s e a r g s ( i n t a r g c , c h a r ** a r g v )
{
// This v a l u e i s s e t i f /when t h e b i t f l a g
unsigned baudrate = 0 ;
char * server , * port ;
is set .
/ * d e f a u l t t o no params s e t * /
g params . f l a t = 0 ;
xpacket initialize ();
while ( argc ) {
i f ( ( a r g v [ a r g c ] ) && ( * a r g v [ a r g c ] == ’ − ’ ) ) {
switch ( argv [ argc ] [ 1 ] ) {
case ’? ’:
g params . b i t s . d i s p l a y h e l p = 1 ;
break ;
case ’q ’ :
g params . b i t s . m o d e q u i e t = 1 ;
break ;
case ’p ’ :
g params . b i t s . d i s p l a y p a r s e d = 1 ;
break ;
case ’ r ’ :
g params . b i t s . d i s p l a y r a w = 1 ;
break ;
case ’c ’ :
g params . b i t s . d i s p l a y c o o k e d = 1 ;
break ;
case ’ f ’ : {
switch ( argv [ argc ] [ 2 ] ) {
case ’= ’:
// s p e c i f y a r b i t r a r y o f f s e t
g params . b i t s . mode framing = a t o i ( a r g v [ a r g c ]+3)&3;
break ;
case ’a ’ :
// a u t o m a t i c d e f r a m i n g
g params . b i t s . mode framing = 0 ;
break ;
case ’0 ’:
case ’n ’ :
// assume no f r a m i n g
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
100
g params . b i t s . mode framing = 2 ;
break ;
case
’1 ’:
// f o r c e f r a m i n g
default :
g params . b i t s . mode framing = 1 ;
break ;
}
break ;
}
case ’b ’ :
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
baudrate = x s e r i a l s e t b a u d ( argv [ argc ] + 3 ) ;
g params . b i t s . d i s p l a y b a u d = 1 ;
}
break ;
case ’ s ’ :
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
x s e r i a l s e t d e v i c e ( argv [ argc ] + 3 ) ;
}
break ;
case ’a ’ :
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
g am type = a t o l ( a r g v [ a r g c ] + 3 ) ;
}
break ;
case ’g ’ :
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
g group = a t o i ( argv [ argc ] + 3 ) ;
}
break ;
case ’n ’ :
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
g d e s t = a t o i ( argv [ argc ] + 3 ) ;
}
break ;
case ’# ’:
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
g s e q n o = a t o i ( argv [ argc ] + 3 ) ;
}
break ;
case ’ t ’ :
g params . b i t s . d i s p l a y t i m e = 1 ;
break ;
case ’ i ’ :
2. UC-7420 SOFTWARE
101
g params . b i t s . m o d e s o c k e t = 1 ;
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
s e r v e r = argv [ argc ]+3;
port = s t r c h r ( server , ’ : ’ ) ;
i f ( port ) {
* p o r t++ = ’ \ 0 ’ ;
x s o c k e t s e t p o r t ( port ) ;
}
xsocket set server ( server );
}
break ;
case ’v ’ :
g params . b i t s . m o d e v e r s i o n = 1 ;
break ;
case ’d ’ :
g params . b i t s . mode debug = 1 ;
break ;
}
} else {
i f ( argv [ argc ] ) {
// p r o c e s s i n g arguments backwards , s o a l w a y s update command .
i f ( g command ) {
g argument = g command ;
}
g command = a r g v [ a r g c ] ;
}
}
a r g c −−;
}
if
( ! g params . b i t s . m o d e q u i e t ) {
// Summarize p a r a m e t e r s e t t i n g s
p r i n t f ( ” xcommand Ver:% s \n ” , g v e r s i o n ) ;
i f ( g params . b i t s . m o d e v e r s i o n )
xpacket print versions ();
p r i n t f ( ” Using params : ” ) ;
i f ( g params . b i t s . d i s p l a y h e l p )
p r i n t f ( ” [ help ] ” ) ;
i f ( g params . b i t s . d i s p l a y b a u d )
p r i n t f ( ” [ baud=0x%04x ] ” , b a u d r a t e ) ;
p r i n t f ( ” [ raw ] ” ) ;
i f ( g params . b i t s . d i s p l a y r a w )
i f ( g params . b i t s . d i s p l a y a s c i i )
printf (”[ ascii ] ”);
i f ( g params . b i t s . d i s p l a y p a r s e d ) p r i n t f ( ” [ p a r s e d ] ” ) ;
i f ( g params . b i t s . d i s p l a y c o o k e d ) p r i n t f ( ” [ cooked ] ” ) ;
i f ( g params . b i t s . e x p o r t p a r s e d )
p r i n t f ( ” [ export ] ” ) ;
i f ( g params . b i t s . d i s p l a y t i m e )
p r i n t f ( ” [ timed ] ” ) ;
i f ( g params . b i t s . e x p o r t c o o k e d )
p r i n t f ( ” [ convert ] ” ) ;
i f ( g params . b i t s . l o g c o o k e d )
printf (”[ logging ] ”);
i f ( g params . b i t s . mode framing==1) p r i n t f ( ” [ framed ] ” ) ;
i f ( g params . b i t s . mode framing==2) p r i n t f ( ” [ unframed ] ” ) ;
i f ( g params . b i t s . m o d e s o c k e t )
p r i n t f ( ” [ i n e t=%s :%u ] ” ,
xsocket get server () ,
xsocket get port ( ) ) ;
i f ( g params . b i t s . mode debug ) {
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
102
p r i n t f ( ” [ debug − s e r i a l dump ! ] \n ” ) ;
xserial port dump ( ) ;
}
p r i n t f (”\n ” ) ;
}
i f ( g params . b i t s . d i s p l a y h e l p ) {
xcommand print help ( ) ;
exit (0);
}
/ * D e f a u l t t o d i s p l a y i n g p a c k e t s a s raw , p a r s e d , and cooked . * /
i f ( g params . o p t i o n s . o ut p u t == 0 ) {
g params . b i t s . d i s p l a y r a w = 1 ;
g params . b i t s . d i s p l a y p a r s e d = 1 ;
g params . b i t s . d i s p l a y c o o k e d = 1 ;
}
/ * Stream i n i t i a l i z a t i o n * /
// S e t STDOUT and STDERR t o be l i n e b u f f e r e d , s o o ut p u t i s not d e l a y e d .
s e t l i n e b u f ( stdout ) ;
setlinebuf ( stderr );
i f ( g params . b i t s . m o d e s o c k e t ) {
g ostream = xsocket port open ( ) ;
} else {
g ostream = x s e r i a l p o r t o p e n ( ) ;
}
}
int xmain get verbose () {
r e t u r n ! g params . b i t s . m o d e q u i e t ;
}
/ **
* The main e n t r y p o i n t f o r t h e s e n s o r commander c o n s o l e a p p l i c a t i o n .
*
* @param
argc
Argument count
* @param
argv
Argument v e c t o r
*
* @author
Martin Turon
* @version
2004/10/3
mturon
Intial version
*/
i n t main ( i n t a r g c , c h a r ** a r g v )
{
int len = 0;
unsigned char b u f f e r [ 2 5 5 ] ;
p a r s e a r g s ( argc , argv ) ;
i f ( ! g command ) {
xcommand print help ( ) ;
2. UC-7420 SOFTWARE
103
exit (2);
}
i f ( ! x p a c k e t g e t a p p ( g am type ) ) {
p r i n t f ( ” e r r o r : No command t a b l e f o r AM t y p e : %d ” , g am type ) ;
exit (2);
}
XCmdBuilder cmd bldr = x p a c k e t g e t b u i l d e r ( g am type , g command ) ;
i f ( ! cmd bldr ) {
p r i n t f ( ” e r r o r : Command not found f o r AM t y p e %d : %s ” ,
g am type , g command ) ;
exit (2);
}
p r i n t f ( ” S e n d i n g (#%d ) %s %s : ” , g s e q n o , g command , g argument ) ;
l e n = x p a c k e t b u i l d c m d ( b u f f e r , cmd bldr , g params . b i t s . m o d e s o c k e t ) ;
xpacket print raw ( buffer , len ) ;
x s e r i a l p o r t w r i t e p a c k e t ( g ostream , b u f f e r , l e n ) ;
return 1;
}
//####################### User Manual F o l l o w s ##############################
/ **
@mainpage XCommand Documentation
@section version Version
$ I d : xcommand . c , v 1 . 4 2004/11/11 0 1 : 0 0 : 5 1 mturon Exp $
@ s e c t i o n u s a g e Usage
Usage : xcommand <−?|v | q> command argument
@n
<−s=d e v i c e > <−b=baud> <−i=s e r v e r : p o r t >
@n
<−n=nodeid> <−g=group> <−#=s e q n o > <−a=app AM type>
@n
−? = d i s p l a y h e l p [ h e l p ]
@n
−q = q u i e t mode ( s u p p r e s s h e a d e r s )
@n
−v = show v e r s i o n o f a l l modules
@n
−b = s e t t h e b a u d r a t e [ baud=#|mica2 | mica2dot ]
@n
−s = s e t s e r i a l p o r t d e v i c e [ d e v i c e=com1 ]
@n
− i = i n t e r n e t s e r i a l f o r w a r d e r [ i n e t=h o s t : p o r t ]
@n
−n = n o d e i d t o send command t o [ node=n o d e i d ]
@n
−g = group t o send command o v e r [ group=g r o u p i d ]
@n
−a = a p p l i c a t i o n o r AM t y p e o f command message [ app=t y p e ]
@n
−# = s e q u e n c e number o f command [#= s e q n o ]
@n
@n
XCommand l i s t :
@n
wake , s l e e p , r e s e t
@n
s e t r a t e <i n t e r v a l in m i l l i s e c >
@n
s e t l e d s <number from 0−7>
@n
s e t s o u n d <0= o f f |1= on>
@n
red on ,
red off ,
red toggle
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
104
@n
@n
@n
green on , g r e e n o f f , g r e e n t o g g l e
yellow on , y e l l o w o f f , y e l l o w t o g g l e
@ s e c t i o n params P a r a m e t e r s
@ s u b s e c t i o n h e l p −? [ h e l p ]
XCommand has many modes o f o p e r a t i o n t h a t can be c o n t r o l l e d by p a s s i n g command
l i n e p a r a m e t e r s . The c u r r e n t l i s t o f t h e s e command l i n e o p t i o n s and a b r i e f
u s a g e e x p l a n a t i o n i s a l w a y s a v a i l a b l e by p a s s i n g t h e −? f l a g .
@n
@n A d e t a i l e x p l a n a t i o n o f each command l i n e o p t i o n a s o f v e r s i o n 1 . 1 f o l l o w s .
@subsection v e r s i o n s
−v [ v e r s i o n s ]
D i s p l a y s c o m p l e t e v e r s i o n i n f o r m a t i o n f o r a l l s e n s o r b o a r d d e c o d i n g modules
w i t h i n xcommand .
@n $ xcmd −v
@n xcommand Ver : I d : xcommand . c , v 1 . 1 2004/10/07 1 9 : 3 3 : 1 3 mturon Exp
@n
f8 :
I d : cmd XMesh . c , v 1 . 4 2004/10/08 0 0 : 3 3 : 2 0 mturon Exp
@n
30:
I d : cmd XSensor . c , v 1 . 2 2004/10/07 2 3 : 1 4 : 2 5 mturon Exp
@n
12:
I d : cmd Surge . c , v 1 . 1 2004/10/07 1 9 : 3 3 : 1 3 mturon Exp
@n
08:
I d : cmd SimpleCmd . c , v 1 . 1 2004/10/07 1 9 : 3 3 : 1 3 mturon Exp
@ s u b s e c t i o n q u i e t −q [ q u i e t ]
This f l a g s u p p r e s s e s t h e s t a n d a r d xcommand h e a d e r which d i s p l a y s t h e
v e r s i o n s t r i n g and p a r a m e t e r s e l e c t i o n s .
@ s u b s e c t i o n baud −b=b a u d r a t e [ baud ]
This f l a g a l l o w s t h e u s e r t o s e t t h e baud r a t e o f t h e s e r i a l l i n e
c o n n e c t i o n . The d e f a u l t baud r a t e i s 57600 b i t s p e r s e c o n d which i s
c o m p a t i b l e with t h e Mica2 . The d e s i r e d b a u d r a t e must be p a s s e d a s a
number d i r e c t l y a f t e r t h e e q u a l s s i g n with no s p a c e s inbetween , i . e .
−b =19200. O p t i o n a l l y , a p r o d u c t name can be p a s s e d i n l i e u o f an a c t u a l
number and t h e p r o p e r baud w i l l be s e t , i . e . −b=mica2dot .
Valid product
names a r e :
mica2
mica2dot
( 5 7 6 0 0 baud )
( 1 9 2 0 0 baud )
@ s u b s e c t i o n s e r i a l −s=p o r t [ s e r i a l ]
This f l a g g i v e s t h e u s e r t h e a b i l i t y t o s p e c i f y which COM p o r t o r d e v i c e
xcommand s h o u l d u s e . The d e f a u l t p o r t i s / dev / t t y S 0 o r t h e UNIX
e q u i v a l e n t t o COM1. The g i v e n p o r t must be p a s s e d d i r e c t l y a f t e r t h e
2. UC-7420 SOFTWARE
105
e q u a l s s i g n with no s p a c e s , i . e . −s=com3 .
@ s u b s e c t i o n i n t e r n e t − i=hostname : p o r t [ i n e t ]
This f l a g t e l l s xcmd t o c o n n e c t v i a a s e r i a l f o r w a r d e r o v e r a TCP/ IP
internet socket .
S p e c i f y t h e hostname and p o r t t o c o n n e c t i n t h e
argument . The d e f a u l t hostname i s l o c a l h o s t , and t h e d e f a u l t p o r t 9 0 0 1 .
The keyword ’ mib600 ’ can be p a s s e d a s an a l i a s t o p o r t 10002 when
c o n n e c t i n g t o t h a t hardware d e v i c e . The hostname and p o r t must be p a s s e d
d i r e c t l y a f t e r t h e e q u a l s s i g n with no s p a c e s with a o p t i o n a l c o l o n
inbetween , i . e . − i=remote , − i = 1 0 . 1 . 1 . 1 : 9 0 0 0 , − i=mymib : mib600 , − i = : 9 0 0 2 ,
− i=l o c a l h o s t : 9 0 0 3 , o r − i=s t a r g a t e . xbow . com .
@ s u b s e c t i o n node
−n=n o d e i d [ node ]
This f l a g s p e c i f i e s which node t o send t h e message t o .
t h e b r o a d c a s t a d d r e s s i s used ( 0xFFFF ) .
When not p a s s e d ,
@ s u b s e c t i o n group −g=group [ group ]
This f l a g s p e c i f i e s which AM group i d t o send t h e message on .
Nodes
t y p i c a l l y i g n o r e m e s s a g e s f o r a group which t h e y have not been programmed
f o r , s o i t i s i m p o r t a n t t o p a s s t h e c o r r e c t group h e r e .
@subsection sequence
−#=s e q n o [ s e q u e n c e ]
This f l a g d e f i n e s t h e s e q u e n c e number t h a t w i l l be used f o r s e n d i n g t h e
command p a c k e t . The TinyOS B c a s t component u s e s t h e s e q u e n c e number t o
i n s u r e t h a t t h e same command doesn ’ t c y c l e t h r o u g h t h e network f o r e v e r .
Try and i n c r e m e n t t h i s number s y s t e m a t i c a l l y e v e r y t i m e a command message
i s sent .
@ s u b s e c t i o n a p p l i c a t i o n −a=am type [ app ]
This f l a g s p e c i f i e s which AM TOS t y p e t o send t h e message on . The AM t y p e
can be p a s s e d a s an i n t e g e r , o r a s an a p p l i c a t i o n name .
For example ,
Surge s e n d s commands on AM TYPE=18. To s e t t h e r a t e o f a Surge node , one
would u s e ‘ xcmd −a=18 s e t r a t e ‘ .
The d e f a u l t am type w i l l work f o r any
a p p l i c a t i o n t h a t u s e s t h e TinyOS XCommand component , such a s XSensor .
@ s e c t i o n params Commands
@ s u b s e c t i o n s l e e p [ XCommand ]
W i l l t e l l t h e mote t o s t o p c o l l e c t i n g data and go t o s l e e p .
@ s u b s e c t i o n wake [ XCommand ]
W i l l wake up a mote and r e s t a r t data a q u i s i t i o n from t h e s l e e p s t a t e .
@ s u b s e c t i o n s e t r a t e [ XCommand ]
The s e t r a t e command w i l l change t h e data a q u i s i t i o n duty c y c l e o f t h e
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
106
mote .
The f i r s t argument i s t h e new t i m e r i n t e r v a l i n m i l l i s e c o n d s .
@ s u b s e c t i o n s e t l e d s [ XCommand ]
The s e t l e d s command w i l l a c t u a t e a l l t h r e e LEDs o f a mote u s i n g t h e
f o l l o w i n g e n c o d i n g o f t h e f i r s t argument : b i t 1 = red , b i t 2 = g r e e n , b i t
3 = yellow .
P a s s i n g a 7 f o r i n s t a n c e w i l l t u r n a l l t h e LEDs on , w h i l e
p a s s i n g a 0 w i l l t u r n them a l l o f f .
@section b u i l d i n g Build Process
The s o u r c e code f o r t h e xcommand t o o l i s l o c a t e d a t : / opt / t i n y o s −1. x/ c o n t r i b /xbow/ t o o l s / s r c
@n@n
To b u i l d t h e t o o l , change t o t h e xcmd s o u r c e d i r e c t o r y and run ‘ make ‘ .
@n@n
To g e t t h e l a t e s t v e r s i o n o f t h e s o u r c e , change t o t h e xcmd s o u r c e
d i r e c t o r y and run ‘ c v s update ‘ .
@ s e c t i o n s e t u p Setup
Xcommand i s a command l i n e t o o l t h a t can be run from a cygwin s h e l l by
s i m p l y t y p i n g ‘ xcmd ‘ .
The e x e c u t a b l e n e e d s t o be i n your working path t o
u s e i t . A s i m p l e way t o add Xcommand t o your working path i s t o c r e a t e a
s o f t l i n k t o i t by r u n n i n g t h e f o l l o w i n g command :
@n$ l n −s / opt / t i n y o s −1. x/ c o n t r i b /xbow/ t o o l s / s r c /xcmd / u s r / l o c a l / b i n /xcmd
@n@n
You can u s e Xcommand t o a c t u a t e s u b d e v i c e s on a mote such a s t h e LEDs ,
sounder , o r r e l a y s . The commands can be s e n t t o e i t h e r one mote o v e r a
s e r i a l l i n k , o r a w i r e l e s s network o f motes .
I n both c o n f i g u r a t i o n s , you
need t o have a MIB510 board c o n n e c t e d v i a a s e r i a l c a b l e t o your PC .
@n@n
For a s i n g l e mote c o n f i g u r a t i o n , t h e mote must be programmed with a
XSensorMXX### a p p l i c a t i o n and p l u g g e d i n t o t h e MIB510 . The mote w i l l
l i s t e n f o r command p a c k e t s o v e r t h e UART and r a d i o whenever i t has power .
@n@n
For t h e network o f motes c o n f i g u r a t i o n , a b a s e s t a t i o n mote n e e d s t o be
programmed with TOSBase and p l u g g e d i n t o t h e MIB510 .
A l l o t h e r motes need
t o be i n s t a l l e d with an XSensorMXX## a p p l i c a t i o n and put w i t h i n r a n g e o f t h e
b a s e s t a t i o n o r a v a l i d m u l t i −hop p e e r . Take c a r e t o program a l l t h e motes
t o t h e same f r e q u e n c y and group i d .
*/
2. UC-7420 SOFTWARE
107
2.2. xbow/beta/tools/src/xcmd/apps directory.
/ **
* Handles g e n e r a t i n g and s e n d i n g commands t o c o n t r o l an XSensor a p p l i c a t i o n .
*
* @file
cmd XSensor . c
* @author
Martin Turon
* @version
2004/10/5
mturon
I n i t i a l version
*
* C o p y r i g h t ( c ) 2004 Crossbow Technology , I n c .
All rights reserved .
*
* $ I d : cmd XSensor . c , v 1 . 5 2005/02/02 0 5 : 4 7 : 4 0 husq Exp $
*/
#i n c l u d e ” . . / xcommand . h”
enum {
// B a s i c i n s t r u c t i o n s :
XCOMMAND END = 0x0 ,
XCOMMAND NOP = 0x1 ,
XCOMMAND GET SERIALID,
// Power Management :
XCOMMAND RESET = 0 x10 ,
XCOMMAND SLEEP,
XCOMMANDWAKEUP,
// B a s i c update r a t e :
XCOMMAND SET RATE = 0 x20 ,
XCOMMAND GET RATE,
// Update r a t e
// MoteConfig Parameter s e t t i n g s :
XCOMMAND GET CONFIG = 0 x30 ,
// Return r a d i o f r e q and power
XCOMMAND SET NODEID,
XCOMMAND SET GROUP,
XCOMMAND SET RF POWER,
XCOMMAND SET RF CHANNEL,
// A c t u a t i o n :
XCOMMAND ACTUATE = 0 x40 ,
} XCommandOpcode ;
enum {
XCMD DEVICE LED GREEN,
XCMD DEVICE LED YELLOW,
XCMD DEVICE LED RED,
XCMD DEVICE LEDS,
XCMD DEVICE SOUNDER,
XCMD DEVICE RELAY1,
XCMD DEVICE RELAY2,
XCMD DEVICE RELAY3,
XCMD DEVICE POT
} XSensorSubDevice ;
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
108
// added pot l i n e t o above MPK
enum {
XCMD STATE OFF = 0 ,
XCMD STATE ON = 1 ,
XCMD STATE TOGGLE
} XSensorSubState ;
t y p e d e f s t r u c t XCommandOp {
uint16 t
cmd ;
union {
u i n t 3 2 t newrate ;
u i n t 1 6 t nodeid ;
uint8 t
group ;
uint8 t
rf power ;
uint32 t rf channel ;
//! <
//! <
//! <
//! <
//! <
// XCommandOpcode
FOR
FOR
FOR
FOR
FOR
XCOMMAND SET RATE
XCOMMAND SET NODEID
XCOMMAND SET GROUP
XCOMMAND SET RF POWER
XCOMMAND SET RF CHANNEL
/ ** FOR XCOMMAND ACCTUATE * /
struct {
uint16 t device ;
//! < LEDS, sounder , r e l a y ,
uint16 t state ;
//! < o f f , on , t o g g l e , . . .
} actuate ;
} param ;
}
attribute
( ( packed ) ) XCommandOp ;
...
t y p e d e f s t r u c t XCommandMsg {
TOSMsgHeader t o s ;
uint16 t
seq no ;
//! < R e q u i r e d by l i b / B r o a d c a s t / Bc as t
dest ;
//! < D e s t i n a t i o n n o d e i d ( 0xFFFF f o r a l l )
uint16 t
XCommandOp
inst [ 1 ] ;
}
attribute
( ( packed ) ) XCommandMsg ;
void xcmd set header ( char * b u f f e r )
{
// F i l l i n TOS msg h e a d e r .
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
msg−>t o s . addr
= g dest ;
msg−>t o s . t y p e
= AMTYPEXCOMMAND;
msg−>t o s . group
= g group ;
msg−>t o s . l e n g t h = s i z e o f (XCommandMsg) − s i z e o f ( TOSMsgHeader ) ;
}
i n t x c m d b a s i c ( c h a r * b u f f e r , i n t opcode )
{
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
xcmd set header ( b u f f e r ) ;
// Data p a y l o a d
msg−>s e q n o
= g seq no ;
2. UC-7420 SOFTWARE
msg−>d e s t
= g dest ;
msg−>i n s t [ 0 ] . cmd = opcode ;
msg−>i n s t [ 0 ] . param . n e w r a t e = 0xCCCCCCCC;
r e t u r n s i z e o f (XCommandMsg ) ;
109
// F i l l unused i n known way
}
i n t xcmd actuate ( char * b u f f e r , i n t device , i n t s t a t e )
{
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
xcmd set header ( b u f f e r ) ;
// Data p a y l o a d
msg−>s e q n o
= g seq no ;
msg−>d e s t
= g dest ;
msg−>i n s t [ 0 ] . cmd = XCOMMAND ACTUATE;
msg−>i n s t [ 0 ] . param . a c t u a t e . d e v i c e = d e v i c e ;
msg−>i n s t [ 0 ] . param . a c t u a t e . s t a t e = s t a t e ;
r e t u r n s i z e o f (XCommandMsg ) ;
}
int
int
int
}
int
}
int
x c m d g e t s e r i a l i d ( c h a r * b u f f e r ) { r e t u r n x c m d b a s i c ( b u f f e r , XCOMMAND GET SERIALID ) ; }
x c m d g e t c o n f i g ( c h a r * b u f f e r ) { r e t u r n x c m d b a s i c ( b u f f e r , XCOMMAND GET CONFIG) ; }
x c m d r e s e t ( c h a r * b u f f e r ) { r e t u r n x c m d b a s i c ( b u f f e r , XCOMMAND RESET) ;
x c m d s l e e p ( c h a r * b u f f e r ) { r e t u r n x c m d b a s i c ( b u f f e r , XCOMMAND SLEEP) ;
xcmd wake ( c h a r * b u f f e r ) { r e t u r n x c m d b a s i c ( b u f f e r , XCOMMANDWAKEUP) ; }
i n t xcmd green off ( char * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED GREEN, 0 ) ;
}
i n t xcmd green on ( char * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED GREEN, 1 ) ;
}
i n t xcmd green toggle ( char * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED GREEN, 2 ) ;
}
i n t xcmd red off ( char * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED RED, 0 ) ;
}
i n t xcmd red on ( c h a r * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED RED, 1 ) ;
}
i n t xcmd red toggle ( char * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED RED, 2 ) ;
}
i n t xcmd yellow off ( char * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED YELLOW, 0 ) ;
}
i n t xcmd yellow on ( char * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED YELLOW, 1 ) ;
}
i n t xcmd yellow toggle ( char * b u f f e r ) {
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LED YELLOW, 2 ) ;
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
110
}
//MPK
i n t xcmd set pot ( char * b u f f e r ) {
i n t pot = 7 ;
i f ( g argument ) pot = a t o i ( g argument ) ;
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE POT, pot ) ;
}
i n t xcmd set leds ( char * b u f f e r ) {
int leds = 7;
// d e f a u l t t o a l l on .
i f ( g argument ) l e d s = a t o i ( g argument ) ;
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE LEDS, l e d s ) ;
}
i n t xcmd set sounder ( char * b u f f e r ) {
i n t sounder = 0 ;
// d e f a u l t t o o f f .
i f ( g argument ) s o u n d e r = a t o i ( g argument ) ;
r e t u r n x c m d a c t u a t e ( b u f f e r , XCMD DEVICE SOUNDER, s o u n d e r ) ;
}
u n s i g n e d x c m d s e t c o n f i g ( c h a r * b u f f e r , u n s i g n e d cmd , u n s i g n e d mask )
{
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
u n s i g n e d a r g = mask ;
// d e f a u l t t o maximum v a l u e
i f ( g argument ) a r g = a t o i ( g argument ) ;
a r g &= mask ;
xcmd set header ( b u f f e r ) ;
// Data p a y l o a d
msg−>s e q n o
= g seq no ;
msg−>d e s t
= g dest ;
msg−>i n s t [ 0 ] . cmd = cmd ;
return arg ;
}
i n t xcmd set rate ( char * b u f f e r )
{
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
u n s i g n e d a r g = x c m d s e t c o n f i g ( b u f f e r , XCOMMAND SET RATE, 0xFFFFFFFF ) ;
i f ( a r g == 0xFFFFFFFF) a r g = 5 0 0 0 ;
// i f ( a r g < 1 0 0 ) a r g = 1 0 0 ;
msg−>i n s t [ 0 ] . param . n e w r a t e = a r g ;
p r i n t f ( ” \ narg i s %08x\n ” , msg−>i n s t [ 0 ] . param . n e w r a t e ) ;
r e t u r n s i z e o f (XCommandMsg ) ;
}
i n t xcmd set nodeid ( char * b u f f e r )
{
2. UC-7420 SOFTWARE
111
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
u n s i g n e d a r g = x c m d s e t c o n f i g ( b u f f e r , XCOMMAND SET NODEID, 0xFFFF ) ;
msg−>i n s t [ 0 ] . param . n o d e i d = a r g ;
r e t u r n s i z e o f (XCommandMsg ) ;
}
i n t xcmd set group ( char * b u f f e r )
{
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
u n s i g n e d a r g = x c m d s e t c o n f i g ( b u f f e r , XCOMMAND SET GROUP, 0xFF ) ;
msg−>i n s t [ 0 ] . param . group = a r g ;
r e t u r n s i z e o f (XCommandMsg ) ;
}
i n t xcmd set rf power ( char * b u f f e r )
{
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
u n s i g n e d a r g = x c m d s e t c o n f i g ( b u f f e r , XCOMMAND SET RF POWER, 0xFF ) ;
msg−>i n s t [ 0 ] . param . r f p o w e r = a r g ;
r e t u r n s i z e o f (XCommandMsg ) ;
}
i n t x c m d s e t r f c h a n n e l ( char * b u f f e r )
{
XCommandMsg * msg = (XCommandMsg * ) b u f f e r ;
u n s i g n e d a r g = x c m d s e t c o n f i g ( b u f f e r , XCOMMAND SET RF CHANNEL, 0xFF ) ;
msg−>i n s t [ 0 ] . param . r f c h a n n e l = a r g ;
r e t u r n s i z e o f (XCommandMsg ) ;
}
extern i n t xmesh cmd light path ( char * b u f f e r ) ;
/ ** L i s t o f commands h a n d l e d by XSensor a p p l i c a t i o n s u s i n g XCommand . * /
XCmdHandler x s e n s o r c m d l i s t [ ] = {
{” g e t s e r i a l i d ” ,
xcmd get serialid } ,
{” g e t c o n f i g ” ,
xcmd get config } ,
// Power Management
{” r e s e t ” ,
xcmd reset } ,
{” wake ” ,
xcmd wake } ,
{” s l e e p ” ,
xcmd sleep } ,
// App C o n t r o l
{” s e t r a t e ” ,
xcmd set rate } ,
// Mote C o n f i g u r a t i o n
{” s e t n o d e i d ” ,
xcmd
{” s e t g r o u p ” ,
xcmd
{” s e t r f p o w e r ” ,
xcmd
{” s e t r f c h a n n e l ” , x c m d
// A c t u a t i o n
{” s e t s o u n d ” ,
set
set
set
set
nodeid } ,
group } ,
rf power } ,
rf channel } ,
xcmd set sounder } ,
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
112
{” s e t l e d s ” ,
{” g r e e n o n ” ,
{” g r e e n o f f ” ,
{” g r e e n t o g g l e ” ,
{” r e d o n ” ,
{” r e d o f f ” ,
{” r e d t o g g l e ” ,
{” y e l l o w o n ” ,
{” y e l l o w o f f ” ,
{” y e l l o w t o g g l e ” ,
xcmd
xcmd
xcmd
xcmd
xcmd
xcmd
xcmd
xcmd
xcmd
xcmd
set leds } ,
green on } ,
green off } ,
green toggle } ,
red on } ,
red off } ,
red toggle } ,
yellow on } ,
yellow off } ,
yellow toggle } ,
//MPK
{” s e t p o t ” ,
xcmd set pot } ,
// XMesh command h e r e f o r now . . .
{” l i g h t p a t h ” ,
xmesh cmd light path } ,
{NULL, NULL}
};
/ ** V a l i d r e f e r e n c e names f o r XSensor /XCommand from t h e command l i n e . * /
char * xsensor app keywords [ ] = {
” do ” , ”cmd ” , ”xcmd ” , ”xcommand ” , ”XCommand” ,
” s e n s o r ” , ” x s e n s o r ” , ” XSensor ” ,
NULL
};
XAppHandler x s e n s o r a p p d e s c =
{
AMTYPE XCOMMAND,
” $ I d : cmd XSensor . c , v 1 . 5 2005/02/02 0 5 : 4 7 : 4 0 husq Exp $ ” ,
xsensor cmd list ,
xsensor app keywords
};
void i n i t i a l i z e X S e n s o r ( ) {
x p a c k e t a d d t y p e (& x s e n s o r a p p d e s c ) ;
}
2. UC-7420 SOFTWARE
113
2.3. xbow/beta/tools/src/xlisten/boards directory.
/ **
* Handles c o n v e r s i o n t o e n g i n e e r i n g u n i t s o f mda300 p a c k e t s .
*
* @file
mda300 . c
* @author
Martin Turon
* @version
2004/3/23
mturon
I n i t i a l version
*
* C o p y r i g h t ( c ) 2004 Crossbow Technology , I n c .
All rights reserved .
*
* $ I d : mda300 . c , v 1 . 2 9 2005/01/29 0 0 : 4 7 : 4 1 mturon Exp $
*/
#i n c l u d e <math . h>
#i f d e f
arm
#i n c l u d e <s y s / t y p e s . h>
#e n d i f
#i n c l u d e ” . . / x s e n s o r s . h”
#i n c l u d e ” . . / timestamp / timestamp . h”
/ ** MDA300 XSensor p a c k e t 1 −− c o n t a i n s s i n g l e a n a l o g adc c h a n n e l s * /
typedef struct {
u i n t 1 6 t adc0 ;
u i n t 1 6 t adc1 ;
u i n t 1 6 t adc2 ;
u i n t 1 6 t adc3 ;
u i n t 1 6 t adc4 ;
u i n t 1 6 t adc5 ;
u i n t 1 6 t adc6 ;
} XSensorMDA300Data1 ;
/ ** MDA300 XSensor p a c k e t 2 −− c o n t a i n s p r e c i s i o n a n a l o g adc c h a n n e l s . * /
typedef struct {
u i n t 1 6 t adc7 ;
u i n t 1 6 t adc8 ;
u i n t 1 6 t adc9 ;
u i n t 1 6 t adc10 ;
u i n t 1 6 t adc11 ;
u i n t 1 6 t adc12 ;
u i n t 1 6 t adc13 ;
} XSensorMDA300Data2 ;
/ ** MDA300 XSensor p a c k e t 3 −− c o n t a i n s d i g i t a l c h a n n e l s . * /
typedef struct {
uint16 t digi0 ;
uint16 t digi1 ;
uint16 t digi2 ;
uint16 t digi3 ;
uint16 t digi4 ;
uint16 t digi5 ;
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
114
} XSensorMDA300Data3 ;
/ ** MDA300 XSensor p a c k e t 4 −− c o n t a i n s misc o t h e r s e n s o r data . * /
typedef struct {
uint16 t battery ;
XSensorSensirion s e n s i r i o n ;
uint16 t counter ;
} XSensorMDA300Data4 ;
/ ** MDA300 XSensor p a c k e t 5 −− c o n t a i n s MultiHop p a c k e t s . * /
typedef struct {
uint16 t seq no ;
u i n t 1 6 t adc0 ;
u i n t 1 6 t adc1 ;
u i n t 1 6 t adc2 ;
uint16 t battery ;
XSensorSensirion s e n s i r i o n ;
}
attribute
( ( packed ) ) XSensorMDA300Data5 ;
// pp : m u l t i h o p need o n l y t h e p a c k e t 6
t y p e d e f s t r u c t XSensorMDA300Data6 {
uint16 t vref ;
u i n t 1 6 t humid ;
u i n t 1 6 t humtemp ;
u i n t 1 6 t adc0 ;
u i n t 1 6 t adc1 ;
u i n t 1 6 t adc2 ;
uint16 t dig0 ;
uint16 t dig1 ;
uint16 t dig2 ;
}
attribute
( ( packed ) ) XSensorMDA300Data6 ;
e x t e r n XPacketHandler m d a 3 0 0 p a c k e t h a n d l e r ;
/ **
* MDA300 S p e c i f i c o u t p u t s o f raw r e a d i n g s w i t h i n a XSensor p a c k e t .
*
* @author
Martin Turon
*
* @version
2004/3/23
mturon
I n i t i a l version
*/
v o i d m d a 3 0 0 p r i n t r a w ( XbowSensorboardPacket * p a c k e t )
{
s w i t c h ( packet −>p a c k e t i d ) {
case 1: {
XSensorMDA300Data1 * data = ( XSensorMDA300Data1 * ) packet −>data ;
p r i n t f ( ” mda300 i d=%02x a0=%04x a1=%04x a2=%04x a3=%04x ”
” a4=%04x a5=%04x a6=%04x\n ” ,
packet −>n o d e i d , data−>adc0 , data−>adc1 ,
data−>adc2 , data−>adc3 , data−>adc4 ,
data−>adc5 , data−>adc6 ) ;
break ;
}
2. UC-7420 SOFTWARE
115
case 2: {
XSensorMDA300Data2 * data = ( XSensorMDA300Data2 * ) packet −>data ;
p r i n t f ( ” mda300 i d=%02x a7=%04x a8=%04x a9=%04x a10=%04x ”
” a11=%04x a12=%04x a13=%04x\n ” ,
packet −>n o d e i d , data−>adc7 , data−>adc8 ,
data−>adc9 , data−>adc10 , data−>adc11 ,
data−>adc12 , data−>adc13 ) ;
break ;
}
case 3: {
XSensorMDA300Data3 * data = ( XSensorMDA300Data3 * ) packet −>data ;
p r i n t f ( ” mda300 i d=%02x d1=%04x d2=%04x d3=%04x d4=%04x d5=%04x ” ,
packet −>n o d e i d , data−>d i g i 0 , data−>d i g i 1 ,
data−>d i g i 2 , data−>d i g i 3 , data−>d i g i 4 , data−>d i g i 5 ) ;
break ;
}
case 4: {
XSensorMDA300Data4 * data = ( XSensorMDA300Data4 * ) packet −>data ;
p r i n t f ( ” mda300 i d=%02x bat=%04x hum=%04x temp=%04x c n t r=%04x\n ” ,
packet −>n o d e i d , data−>b a t t e r y , data−>s e n s i r i o n . humidity ,
data−>s e n s i r i o n . t h e r m i s t o r , data−>c o u n t e r ) ;
break ;
}
case 5: {
XSensorMDA300Data5 * data = ( XSensorMDA300Data5 * ) packet −>data ;
p r i n t f ( ” mda300 i d=%02x bat=%04x hum=%04x temp=%04x ”
” e c h o1 0=%04x ec h o 20=%04x s o i l t e m p=%04x\n ” ,
packet −>n o d e i d , data−>b a t t e r y ,
data−>s e n s i r i o n . humidity , data−>s e n s i r i o n . t h e r m i s t o r ,
data−>adc0 , data−>adc1 , data−>adc2 ) ;
break ;
}
case 6: {
XSensorMDA300Data6 * data = ( XSensorMDA300Data6 * ) packet −>data ;
p r i n t f ( ” mda300 i d=%02x bat=%04x hum=%04x temp=%04x ”
” adc0=%04x adc1=%04x adc2=%04x\n”
” d i g 0=%04x d i g 1=%04x d i g 2=%04x\n ” ,
packet −>n o d e i d , data−>v r e f ,
data−>humid , data−>humtemp ,
data−>adc0 , data−>adc1 , data−>adc2 ,
data−>d i g 0 , data−>d i g 1 , data−>d i g 2 ) ;
break ;
}
default :
p r i n t f ( ” mda300 e r r o r : unknown p a c k e t i d (% i ) \ n ” , packet −>p a c k e t i d ) ;
}
}
/ ** MDA300 s p e c i f i c d i s p l a y o f c o n v e r t e d r e a d i n g s f o r p a c k e t 1 * /
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
116
v o i d m d a 3 0 0 p r i n t c o o k e d 1 ( XbowSensorboardPacket * p a c k e t )
{
p r i n t f ( ”MDA300 [ s e n s o r data c o n v e r t e d t o e n g i n e e r i n g u n i t s ] : \ n”
”
health :
node i d=%i p a c k e t=%i \n”
”
adc chan 0 : v o l t a g e=%i mV\n”
”
adc chan 1 : v o l t a g e=%i mV\n”
”
adc chan 2 : v o l t a g e=%i mV\n”
”
adc chan 3 : v o l t a g e=%i mV\n”
”
adc chan 4 : v o l t a g e=%i mV\n”
”
adc chan 5 : v o l t a g e=%i mV\n”
”
adc chan 6 : v o l t a g e=%i mV\n\n ” ,
packet −>n o d e i d , packet −>p a c k e t i d ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 0 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 1 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 2 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 3 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 4 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 5 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 6 ] ) ) ;
}
/ ** MDA300 s p e c i f i c d i s p l a y o f c o n v e r t e d r e a d i n g s
f o r p a c k e t 2 */
v o i d m d a 3 0 0 p r i n t c o o k e d 2 ( XbowSensorboardPacket * p a c k e t )
{
p r i n t f ( ”MDA300 [ s e n s o r data c o n v e r t e d t o e n g i n e e r i n g u n i t s ] : \ n”
”
health :
node i d=%i p a c k e t=%i \n”
”
adc chan 7 :
v o l t a g e=%i uV\n”
”
adc chan 8 :
v o l t a g e=%i uV\n”
”
adc chan 9 :
v o l t a g e=%i uV\n”
”
adc chan 1 0 : v o l t a g e=%i uV\n”
”
adc chan 1 1 : v o l t a g e=%i mV\n”
”
adc chan 1 2 : v o l t a g e=%i mV\n”
”
adc chan 1 3 : v o l t a g e=%i mV\n\n ” ,
packet −>n o d e i d , packet −>p a c k e t i d ,
x c o n v e r t a d c p r e c i s i o n ( packet −>data [ 0 ] ) ,
x c o n v e r t a d c p r e c i s i o n ( packet −>data [ 1 ] ) ,
x c o n v e r t a d c p r e c i s i o n ( packet −>data [ 2 ] ) ,
x c o n v e r t a d c p r e c i s i o n ( packet −>data [ 3 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 4 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 5 ] ) ,
x c o n v e r t a d c s i n g l e ( packet −>data [ 6 ] ) ) ;
}
/ ** MDA300 s p e c i f i c d i s p l a y o f c o n v e r t e d r e a d i n g s f o r p a c k e t 3 * /
v o i d m d a 3 0 0 p r i n t c o o k e d 3 ( XbowSensorboardPacket * p a c k e t )
{
p r i n t f ( ”MDA300 [ s e n s o r data c o n v e r t e d t o e n g i n e e r i n g u n i t s ] : \ n”
”
health :
node i d=%i p a c k e t=%i \n\n ” ,
packet −>n o d e i d , packet −>p a c k e t i d ) ;
}
/ ** MDA300 s p e c i f i c d i s p l a y o f c o n v e r t e d r e a d i n g s f o r p a c k e t 4 * /
v o i d m d a 3 0 0 p r i n t c o o k e d 4 ( XbowSensorboardPacket * p a c k e t )
2. UC-7420 SOFTWARE
117
{
XSensorMDA300Data4 * data = ( XSensorMDA300Data4 * ) packet −>data ;
p r i n t f ( ”MDA300 [ s e n s o r data c o n v e r t e d t o e n g i n e e r i n g u n i t s ] : \ n”
”
health :
node i d=%i p a c k e t=%i \n”
”
battery voltage :
=%i mV \n”
”
temperature :
=%0.2 f C \n”
”
humidity :
=%0.1 f %% \n\n ” ,
packet −>n o d e i d , packet −>p a c k e t i d ,
x c o n v e r t b a t t e r y m i c a 2 ( data−>b a t t e r y ) ,
x c o n v e r t s e n s i r i o n t e m p (&( data−>s e n s i r i o n ) ) ,
x c o n v e r t s e n s i r i o n h u m i d i t y (&( data−>s e n s i r i o n ) )
);
}
/ ** MDA300 s p e c i f i c d i s p l a y o f c o n v e r t e d r e a d i n g s f o r p a c k e t 5 * /
v o i d m d a 3 0 0 p r i n t c o o k e d 5 ( XbowSensorboardPacket * p a c k e t )
{
XSensorMDA300Data5 * data = ( XSensorMDA300Data5 * ) packet −>data ;
p r i n t f ( ”MDA300 [ s e n s o r data c o n v e r t e d t o e n g i n e e r i n g u n i t s ] : \ n”
”
health :
node i d=%i p a r e n t=%i b a t t e r y=%i mV s e q n o=%i \n”
”
e c h o1 0 : S o i l M o i s t u r e =%0.2 f %%\n”
”
e c h o2 0 : S o i l M o i s t u r e =%0.2 f %%\n”
”
s o i l temperature
=%0.2 f F\n”
”
temperature :
=%0.2 f C \n”
”
humidity :
=%0.1 f %% \n\n ” ,
packet −>n o d e i d , packet −>p a r e n t ,
x c o n v e r t b a t t e r y m i c a 2 ( data−>b a t t e r y ) , data−>s e q n o ,
x c o n v e r t e c h o 1 0 ( data−>adc0 ) ,
x c o n v e r t e c h o 2 0 ( data−>adc1 ) ,
x c o n v e r t s p e c t r u m s o i l t e m p ( data−>adc2 ) ,
x c o n v e r t s e n s i r i o n t e m p (&( data−>s e n s i r i o n ) ) ,
x c o n v e r t s e n s i r i o n h u m i d i t y (&( data−>s e n s i r i o n ) )
);
}
/ ** MDA300 s p e c i f i c d i s p l a y o f c o n v e r t e d r e a d i n g s f o r p a c k e t 5 * /
v o i d m d a 3 0 0 p r i n t c o o k e d 6 ( XbowSensorboardPacket * p a c k e t )
{
XSensorMDA300Data6 * data = ( XSensorMDA300Data6 * ) packet −>data ;
XSensorSensirion
xsensor ;
x s e n s o r . humidity=data−>humid ;
x s e n s o r . t h e r m i s t o r=data−>humtemp ;
c h a r t i m e s t r i n g [ TIMESTRING SIZE ] ;
Timestamp * time now = timestamp new ( ) ;
t i m e s t a m p g e t s t r i n g ( time now , t i m e s t r i n g ) ;
// p r i n t f (”% s ” , t i m e s t r i n g ) ;
t i m e s t a m p d e l e t e ( time now ) ;
i f ( x c o n v e r t b a t t e r y m i c a 2 ( data−>v r e f ) == 0 )
{
p r i n t f ( ”MDA300 − Cooked \n”
”\ tTime \ t \ t \ tID \ t P a r e n t \tTemp (C) \ t%%RH\ t \n”
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
118
” data \ t%s \ t%i \ t%i \ t %0.2 f \ t %0.1 f %\tIMPACT\n\n ” ,
timestring ,
packet −>n o d e i d ,
packet −>p a r e n t ,
x c o n v e r t s e n s i r i o n t e m p (&( x s e n s o r ) ) ,
x c o n v e r t s e n s i r i o n h u m i d i t y (&( x s e n s o r ) )
);
}
else
{
p r i n t f ( ”MDA300 − Cooked \n”
”\ tTime \ t \ t \ tID \ t P a r e n t \tTemp (C) \ t%%RH\ tBat (mV) \tADC7(mV) \ n”
” data \ t%s \ t%i \ t%i \ t %0.2 f \ t %0.1 f %\t%i \ t \ t %0.3 f \n\n ” ,
timestring ,
packet −>n o d e i d ,
packet −>p a r e n t ,
x c o n v e r t s e n s i r i o n t e m p (&( x s e n s o r ) ) ,
x c o n v e r t s e n s i r i o n h u m i d i t y (&( x s e n s o r ) ) ,
x c o n v e r t b a t t e r y m i c a 2 ( data−>v r e f ) ,
( f l o a t ) x c o n v e r t a d c p r e c i s i o n ( data−>adc0 ) / 1 0 0 0
);
}
/*
p r i n t f ( ”MDA300 [ s e n s o r data c o n v e r t e d t o e n g i n e e r i n g u n i t s ] : \ n”
”
health :
node i d=%i p a r e n t=%i b a t t e r y=%i mV\n”
”
e c h o1 0 : S o i l M o i s t u r e =%0.2 f %%\n”
”
e c h o2 0 : S o i l M o i s t u r e =%0.2 f %%\n”
”
s o i l temperature
=%0.2 f F\n”
”
temperature :
=%0.2 f C \n”
”
humidity :
=%0.1 f %% \n\n ” ,
packet −>n o d e i d , packet −>p a r e n t ,
x c o n v e r t b a t t e r y m i c a 2 ( data−>v r e f ) ,
x c o n v e r t e c h o 1 0 ( data−>adc0 ) ,
x c o n v e r t e c h o 2 0 ( data−>adc1 ) ,
x c o n v e r t s p e c t r u m s o i l t e m p ( data−>adc2 ) ,
x c o n v e r t s e n s i r i o n t e m p (&( x s e n s o r ) ) ,
x c o n v e r t s e n s i r i o n h u m i d i t y (&( x s e n s o r ) )
);
*/
}
/ ** MDA300 s p e c i f i c d i s p l a y o f c o n v e r t e d r e a d i n g s from an XSensor p a c k e t . * /
v o i d m d a 3 0 0 p r i n t c o o k e d ( XbowSensorboardPacket * p a c k e t )
{
s w i t c h ( packet −>p a c k e t i d ) {
case 1:
mda300 print cooked 1 ( packet ) ;
break ;
case 2:
2. UC-7420 SOFTWARE
119
mda300 print cooked 2 ( packet ) ;
break ;
case 3:
mda300 print cooked 3 ( packet ) ;
break ;
case 4:
mda300 print cooked 4 ( packet ) ;
break ;
case 5:
mda300 print cooked 5 ( packet ) ;
break ;
case 6:
mda300 print cooked 6 ( packet ) ;
break ;
default :
p r i n t f ( ”MDA300 E r r o r : unknown p a c k e t i d (% i ) \ n\n ” , packet −>p a c k e t i d ) ;
}
}
XPacketHandler m d a 3 0 0 p a c k e t h a n d l e r =
{
XTYPE MDA300,
” $ I d : mda300 . c , v 1 . 2 9 2005/01/29 0 0 : 4 7 : 4 1 mturon Exp $ ” ,
mda300 print raw ,
mda300 print cooked ,
mda300 print raw ,
mda300 print cooked ,
};
void m d a 3 0 0 i n i t i a l i z e ( ) {
x p a c k e t a d d t y p e (& m d a 3 0 0 p a c k e t h a n d l e r ) ;
}
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
120
2.4. xbow/beta/tools/src/xlisten directory.
# M a k e f i l e f o r x l i s t e n # $ I d : M a k e f i l e , v 1 . 2 4 2005/01/28 0 5 : 1 9 : 2 4 mturon Exp $
CC
ARMCC
LFLAGS
CFLAGS
=
=
=
=
gcc
arm−l i n u x −g c c
−lm
−O2 −Wall −Wno−f o r m a t
# Main x l i s t e n s o u r c e s
SRCS = x l i s t e n . c x p a c k e t . c x c o n v e r t . c
SRCS += x s e r i a l . c x s o c k e t . c
# Add Mote S e n s o r board s u p p o r t
SRCS += b o a r d s / mica2 . c b o a r d s / mica2dot . c b o a r d s / micaz . c
# Add Mote Data A q u i s i t i o n board s u p p o r t
SRCS += b o a r d s /mda300 . c
# Add Mica2 i n t e g r a t e d s e n s o r b o a r d s
SRCS += b o a r d s / msp410 . c
# Add s u p p o r t f o r ” v i r t u a l ” board t h a t X s e n s o r T u t o r i a l
# uses during Training seminar
# Add AM t y p e s
SRCS += amtypes / h e a l t h . c amtypes / s u r g e . c
SRCS += timestamp / timestamp . c
all : xlisten
x l i s t e n : $ (SRCS)
$ (CC) $ (CFLAGS) −o $@ $ (SRCS) $ (LFLAGS)
x l i s t e n −arm : $ (SRCS)
$ (ARMCC) −I $ (INCDIR) $ (CFLAGS) −o $@ $ (SRCS) −L$ ( LIBDIR ) $ (LFLAGS)
clean :
rm −f * . o b o a r d s / * . o x l i s t e n x l i s t e n −arm x l i s t e n . e x e
2. UC-7420 SOFTWARE
121
/ **
* L i s t e n s t o t h e s e r i a l p o r t , and o u t p u t s s e n s o r data i n human r e a d a b l e form .
*
* @file
xlisten . c
* @author
Martin Turon
* @version
2004/3/10
mturon
I n i t i a l version
*
* C o p y r i g h t ( c ) 2004 Crossbow Technology , I n c .
All rights reserved .
*
* $ I d : x l i s t e n . c , v 1 . 1 7 2004/11/18 0 4 : 4 5 : 1 0 mturon Exp $
*/
#i n c l u d e ” x s e n s o r s . h”
s t a t i c const char * g v e r s i o n =
” $ I d : x l i s t e n . c , v 1 . 1 7 2004/11/18 0 4 : 4 5 : 1 0 mturon Exp $ ” ;
/ ** A s t r u c t u r e t o s t o r e p a r s e d p a r a m e t e r f l a g s . * /
t y p e d e f union {
unsigned f l a t ;
struct {
// o u tp u t
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
display options
display raw
display parsed
display cooked
export parsed
export cooked
log parsed
log cooked
display time
display ascii
display rsvd
// modes o f o p e r a t i o n
unsigned
display help
unsigned
display baud
u n s i g n e d mode debug
unsigned mode quiet
unsigned
mode version
u n s i g n e d mode header
unsigned mode socket
unsigned mode sf
u n s i g n e d mode framing
} bits ;
struct {
u n s i g n e d s h o r t o ut p u t ;
u n s i g n e d s h o r t mode ;
} options ;
} s params ;
:
:
:
:
:
:
:
:
:
:
1;
1;
1;
1;
1;
1;
1;
1;
1;
7;
//! <
//! <
//! <
//! <
//! <
//! <
//! <
//! <
//! <
//! <
raw TOS p a c k e t s
p u l l out s e n s o r r e a d i n g s
convert to e n g i n e e r i n g u n i t s
o u tp u t comma d e l i m i t e d f i e l d s
o u tp u t comma d e l i m i t e d f i e l d s
l o g o ut p u t t o d a t a b a s e
l o g o ut p u t t o d a t a b a s e
d i s p l a y timestamp o f p a c k e t
d i s p l a y p a c k e t a s ASCII c h a r a c t e r s
pad f i r s t word f o r o u tp u t o p t i o n s
:
:
:
:
:
:
:
:
:
1;
1;
1;
1;
1;
1;
1;
1;
2;
//! <
//! <
//! <
//! <
//! <
//! <
//! <
//! <
baud was s e t by u s e r
debug s e r i a l p o r t
suppress headers
p r i n t v e r s i o n s o f a l l modules
u s e r u s i n g custom p a c k e t h e a d e r
connect to a s e r i a l socket
connect to a s e r i a l forwarder
auto =0 , framed =1 , unframed=2
//! < one o ut p u t o p t i o n r e q u i r e d
/ ** A v a r i a b l e t o s t o r e p a r s e d p a r a m e t e r f l a g s . * /
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
122
s t a t i c s params
static int
g params ;
g istream ;
//! < Handle o f i n p u t stream
/ **
* E x t r a c t s command l i n e o p t i o n s and s e t s f l a g s i n t e r n a l l y .
*
* @param
argc
Argument count
* @param
argv
Argument v e c t o r
*
* @author
Martin Turon
*
* @version
2004/3/10
mturon
Intial version
* @n
2004/3/12
mturon
Added −b,− s ,−q,−x
* @n
2004/8/04
mturon
Added − l [ v e r . 1 . 1 1 ]
* @n
2004/8/22
mturon
Added − i [ v e r . 1 . 1 3 ]
* @n
2004/9/27
mturon
Added −t [ v e r . 1 . 1 5 ]
* @n
2004/9/29
mturon
Added −f ,−a [ v 1 . 1 6 ]
*/
v o i d p a r s e a r g s ( i n t a r g c , c h a r ** a r g v )
{
// This v a l u e i s s e t i f /when t h e b i t f l a g
unsigned baudrate = 0 ;
char * server , * port ;
g params . f l a t = 0 ;
is set .
/ * d e f a u l t t o no params s e t * /
xpacket initialize ();
while ( argc ) {
i f ( ( a r g v [ a r g c ] ) && ( * a r g v [ a r g c ] == ’ − ’ ) ) {
switch ( argv [ argc ] [ 1 ] ) {
case ’? ’:
g params . b i t s . d i s p l a y h e l p = 1 ;
break ;
case ’q ’ :
g params . b i t s . m o d e q u i e t = 1 ;
break ;
case ’p ’ :
g params . b i t s . d i s p l a y p a r s e d = 1 ;
break ;
case ’ r ’ :
g params . b i t s . d i s p l a y r a w = 1 ;
break ;
case ’a ’ :
g params . b i t s . d i s p l a y a s c i i = 1 ;
break ;
case ’c ’ :
g params . b i t s . d i s p l a y c o o k e d = 1 ;
2. UC-7420 SOFTWARE
123
break ;
case ’x ’ :
switch ( argv [ argc ] [ 2 ] ) {
case ’c ’ :
g params . b i t s . e x p o r t c o o k e d = 1 ;
default :
case ’ r ’ :
g params . b i t s . e x p o r t p a r s e d = 1 ;
}
break ;
break ;
break ;
case ’ f ’ :
switch ( argv [ argc ] [ 2 ] ) {
case ’= ’:
// s p e c i f y a r b i t r a r y o f f s e t
g params . b i t s . mode framing = a t o i ( a r g v [ a r g c ]+3)&3;
break ;
case ’a ’ :
// a u t o m a t i c d e f r a m i n g
g params . b i t s . mode framing = 0 ;
break ;
case ’0 ’:
case ’n ’ :
// assume no f r a m i n g
g params . b i t s . mode framing = 2 ;
break ;
case
’1 ’:
// f o r c e f r a m i n g
default :
g params . b i t s . mode framing = 1 ;
break ;
}
break ;
c a s e ’w ’ :
case ’h ’ : {
i n t o f f s e t = XPACKET DATASTART MULTIHOP;
g params . b i t s . mode header = 1 ;
switch ( argv [ argc ] [ 2 ] ) {
case ’= ’:
// s p e c i f y a r b i t r a r y o f f s e t
o f f s e t = a t o i ( argv [ argc ] + 3 ) ;
break ;
case ’0 ’:
// d i r e c t u a r t ( no w i r e l e s s )
case ’1 ’:
// s i n g l e hop o f f s e t
o f f s e t = XPACKET DATASTART STANDARD;
break ;
}
xpacket set start ( offset );
break ;
}
case ’ l ’ :
g params . b i t s . l o g c o o k e d = 1 ;
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
124
}
break ;
case ’b ’ :
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
baudrate = x s e r i a l s e t b a u d ( argv [ argc ] + 3 ) ;
g params . b i t s . d i s p l a y b a u d = 1 ;
}
break ;
case ’ s ’ :
switch ( argv [ argc ] [ 2 ] ) {
case
’= ’:
x s e r i a l s e t d e v i c e ( argv [ argc ] + 3 ) ;
break ;
case ’ f ’ :
g params . b i t s . m o d e s f = 1 ;
g params . b i t s . m o d e s o c k e t = 1 ;
i f ( a r g v [ a r g c ] [ 3 ] == ’ = ’ ) {
s e r v e r = argv [ argc ]+4;
port = s t r c h r ( server , ’ : ’ ) ;
i f ( port ) {
* p o r t++ = ’ \ 0 ’ ;
x s o c k e t s e t p o r t ( port ) ;
}
xsocket set server ( server );
}
break ;
}
break ;
case ’ t ’ :
g params . b i t s . d i s p l a y t i m e = 1 ;
break ;
case ’ i ’ :
g params . b i t s . m o d e s f = 0 ;
g params . b i t s . m o d e s o c k e t = 1 ;
i f ( a r g v [ a r g c ] [ 2 ] == ’ = ’ ) {
s e r v e r = argv [ argc ]+3;
port = s t r c h r ( server , ’ : ’ ) ;
i f ( port ) {
* p o r t++ = ’ \ 0 ’ ;
x s o c k e t s e t p o r t ( port ) ;
}
xsocket set server ( server );
}
break ;
case ’v ’ :
g params . b i t s . m o d e v e r s i o n = 1 ;
break ;
2. UC-7420 SOFTWARE
125
case ’d ’ :
g params . b i t s . mode debug = 1 ;
break ;
}
}
a r g c −−;
}
if
( ! g params . b i t s . m o d e q u i e t ) {
// Summarize p a r a m e t e r s e t t i n g s
p r i n t f ( ” x l i s t e n Ver:% s \n ” , g v e r s i o n ) ;
xpacket print versions ();
i f ( g params . b i t s . m o d e v e r s i o n )
p r i n t f ( ” Using params : ” ) ;
i f ( g params . b i t s . d i s p l a y h e l p )
p r i n t f ( ” [ help ] ” ) ;
p r i n t f ( ” [ baud=0x%04x ] ” , b a u d r a t e ) ;
i f ( g params . b i t s . d i s p l a y b a u d )
i f ( g params . b i t s . d i s p l a y r a w )
p r i n t f ( ” [ raw ] ” ) ;
i f ( g params . b i t s . d i s p l a y a s c i i )
printf (”[ ascii ] ”);
i f ( g params . b i t s . d i s p l a y p a r s e d ) p r i n t f ( ” [ p a r s e d ] ” ) ;
i f ( g params . b i t s . d i s p l a y c o o k e d ) p r i n t f ( ” [ cooked ] ” ) ;
i f ( g params . b i t s . e x p o r t p a r s e d )
p r i n t f ( ” [ export ] ” ) ;
i f ( g params . b i t s . d i s p l a y t i m e )
p r i n t f ( ” [ timed ] ” ) ;
i f ( g params . b i t s . e x p o r t c o o k e d )
p r i n t f ( ” [ convert ] ” ) ;
i f ( g params . b i t s . l o g c o o k e d )
printf (”[ logging ] ”);
i f ( g params . b i t s . mode framing==1) p r i n t f ( ” [ framed ] ” ) ;
i f ( g params . b i t s . mode framing==2) p r i n t f ( ” [ unframed ] ” ) ;
i f ( g params . b i t s . mode header )
p r i n t f ( ” [ h e a d e r=%i ] ” ,
xpacket get start ());
i f ( g params . b i t s . m o d e s o c k e t )
p r i n t f ( ” [ i n e t=%s :%u ] ” ,
xsocket get server () ,
xsocket get port ( ) ) ;
i f ( g params . b i t s . mode debug ) {
p r i n t f ( ” [ debug − s e r i a l dump ! ] \n ” ) ;
xserial port dump ( ) ;
}
p r i n t f (”\n ” ) ;
}
i f ( g params . b i t s . d i s p l a y h e l p ) {
printf (
”\ nUsage : x l i s t e n <−?| r | p | c | x | l | d | v | q> <−l=t a b l e >”
”\n
<−s=d e v i c e > <−b=baud> <−i=s e r v e r : p o r t >”
”\n
−? = d i s p l a y h e l p [ h e l p ] ”
”\n
−r = raw d i s p l a y o f t o s p a c k e t s [ raw ] ”
”\n
−a = a s c i i d i s p l a y o f t o s p a c k e t s [ a s c i i ] ”
”\n
−p = p a r s e p a c k e t i n t o raw s e n s o r r e a d i n g s [ p a r s e d ] ”
”\n
−c = c o n v e r t data t o e n g i n e e r i n g u n i t s [ cooked ] ”
”\n
− l = l o g data t o d a t a b a s e o r f i l e [ l o g g e d ] ”
”\n
−x r = e x p o r t raw r e a d i n g s i n c s v s p r e a d s h e e t f o r m a t [ e x p o r t ] ”
”\n
−xc = e x p o r t cooked i n c s v s p r e a d s h e e t f o r m a t [ e x p o r t ] ”
”\n
−d = debug s e r i a l p o r t by dumping b y t e s [ debug ] ”
”\n
−b = s e t t h e b a u d r a t e [ baud=#|mica2 | mica2dot ] ”
”\n
−s = s e t s e r i a l p o r t d e v i c e [ d e v i c e=com1 ] ”
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
126
”\n
”\n
”\n
”\n
”\n
”\n
”\n
”\n”
−i
−s f
−f
−h
−t
−q
−v
=
=
=
=
=
=
=
u s e s o c k e t i n p u t [ i n e t=h o s t : p o r t ] ”
u s e s e r i a l f o r w a r d e r i n p u t [ i n e t=h o s t : p o r t ] ”
s p e c i f y f r a m i n g (0= auto |1= on |2= o f f ) ”
s p e c i f y h e a d e r s i z e [ h e a d e r=o f f s e t ] ”
d i s p l a y time p a c k e t was r e c e i v e d [ timed ] ”
q u i e t mode ( s u p p r e s s h e a d e r s ) ”
show v e r s i o n o f a l l modules ”
);
exit (0);
}
/ * D e f a u l t t o d i s p l a y i n g p a c k e t s a s raw , p a r s e d , and cooked . * /
i f ( g params . o p t i o n s . o ut p u t == 0 ) {
g params . b i t s . d i s p l a y r a w = 1 ;
g params . b i t s . d i s p l a y p a r s e d = 1 ;
g params . b i t s . d i s p l a y c o o k e d = 1 ;
}
/ * Stream i n i t i a l i z a t i o n * /
// S e t STDOUT and STDERR t o be l i n e b u f f e r e d , s o o ut p u t i s not d e l a y e d .
s e t l i n e b u f ( stdout ) ;
setlinebuf ( stderr );
i f ( g params . b i t s . m o d e s o c k e t ) {
g istream = xsocket port open ( ) ;
} else {
g istream = xserial port open ( ) ;
}
}
int xmain get verbose () {
r e t u r n ! g params . b i t s . m o d e q u i e t ;
}
/ **
* The main e n t r y p o i n t f o r t h e s e n s o r l i s t e n e r c o n s o l e a p p l i c a t i o n .
*
* @param
argc
Argument count
* @param
argv
Argument v e c t o r
*
* @author
Martin Turon
* @version
2004/3/10
mturon
Intial version
*/
i n t main ( i n t a r g c , c h a r ** a r g v )
{
int length ;
unsigned char b u f f e r [ 2 5 5 ] ;
p a r s e a r g s ( argc , argv ) ;
while (1) {
2. UC-7420 SOFTWARE
i f ( g params .
// S e r i a l
length =
} else {
// S e r i a l
length =
}
127
b i t s . mode sf ) {
forwarder read
xsocket read packet ( g istream , buffer ) ;
r e a d d i r e c t , o r o v e r s o c k e t ( mib600 )
x s e r i a l p o r t r e a d p a c k e t ( g istream , buffer ) ;
i f ( l e n g t h < XPACKET MIN SIZE)
continue ;
// i g n o r e p a t i a l p a c k e t s and p a c k e t i z e r frame end
if
i f ( g params . b i t s . d i s p l a y t i m e )
xpacket print time ( ) ;
i f ( g params . b i t s . d i s p l a y r a w )
xpacket print raw ( buffer , length ) ;
i f ( g params . b i t s . d i s p l a y a s c i i )
xpacket print ascii ( buffer , length ) ;
( ! g params . b i t s . m o d e s f )
x p a c k e t d e c o d e ( b u f f e r , l e n g t h , g params . b i t s . mode framing ) ;
i f ( g params . b i t s . d i s p l a y p a r s e d ) x p a c k e t p r i n t p a r s e d ( b u f f e r ) ;
i f ( g params . b i t s . e x p o r t p a r s e d )
xpacket export parsed ( buffer ) ;
i f ( g params . b i t s . e x p o r t c o o k e d )
xpacket export cooked ( buffer ) ;
i f ( g params . b i t s . l o g c o o k e d )
xpacket log cooked ( buffer ) ;
i f ( g params . b i t s . d i s p l a y c o o k e d ) x p a c k e t p r i n t c o o k e d ( b u f f e r ) ;
}
}
//####################### User Manual F o l l o w s ##############################
/ **
@mainpage X L i s t e n Documentation
@section version Version
$ I d : x l i s t e n . c , v 1 . 1 7 2004/11/18 0 4 : 4 5 : 1 0 mturon Exp $
@ s e c t i o n u s a g e Usage
Usage : x l i s t e n <−?| r | p | c | x | l | d | v | q> <−b=baud> <−s=d e v i c e > <−h=s i z e >
@n
@n
−? = d i s p l a y h e l p [ h e l p ]
@n
−r = raw d i s p l a y o f t o s p a c k e t s [ raw ]
@n
−p = p a r s e p a c k e t i n t o raw s e n s o r r e a d i n g s [ p a r s e d ]
@n
−x = e x p o r t r e a d i n g s i n c s v s p r e a d s h e e t f o r m a t [ e x p o r t ]
@n
−c = c o n v e r t data t o e n g i n e e r i n g u n i t s [ cooked ]
@n
−t = d i s p l a y time p a c k e t was r e c e i v e d [ timed ]
@n
−a = a s c i i d i s p l a y o f t o s p a c k e t s [ a s c i i ]
@n
− l = l o g data t o d a t a b a s e [ l o g g e d ]
@n
−d = debug s e r i a l p o r t by dumping b y t e s [ debug ]
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
128
@n
−b = s e t t h e b a u d r a t e [ baud=#|mica2 | mica2dot ]
@n
−s = s e t s e r i a l p o r t d e v i c e [ d e v i c e=com1 ]
@n
− i = u s e s o c k e t i n p u t [ i n e t=h o s t : p o r t ]
@n
− s f = u s e s e r i a l f o r w a r d e r i n p u t [ i n e t=h o s t : p o r t ]
@n
−h = s p e c i f y s i z e o f TOS msg h e a d e r [ h e a d e r=s i z e ]
@n
−v = d i s p l a y c o m p l e t e v e r s i o n i n f o r m a t i o n f o r a l l modules [ v e r s i o n ]
@n
−q = q u i e t mode ( s u p p r e s s h e a d e r s )
@n
@ s e c t i o n params P a r a m e t e r s
@ s u b s e c t i o n h e l p −? [ h e l p ]
X L i s t e n has many modes o f o p e r a t i o n t h a t can be c o n t r o l l e d by p a s s i n g command
l i n e p a r a m e t e r s . The c u r r e n t l i s t o f t h e s e command l i n e o p t i o n s and a b r i e f
u s a g e e x p l a n a t i o n i s a l w a y s a v a i l a b l e by p a s s i n g t h e −? f l a g .
@n
@n A d e t a i l e x p l a n a t i o n o f each command l i n e o p t i o n a s o f v e r s i o n 1 . 7 f o l l o w s .
@ s u b s e c t i o n baud −b=b a u d r a t e [ baud ]
This f l a g a l l o w s t h e u s e r t o s e t t h e baud r a t e o f t h e s e r i a l l i n e
c o n n e c t i o n . The d e f a u l t baud r a t e i s 57600 b i t s p e r s e c o n d which i s
c o m p a t i b l e with t h e Mica2 . The d e s i r e d b a u d r a t e must be p a s s e d a s a
number d i r e c t l y a f t e r t h e e q u a l s s i g n with no s p a c e s inbetween , i . e .
−b =19200. O p t i o n a l l y , a p r o d u c t name can be p a s s e d i n l i e u o f an a c t u a l
number and t h e p r o p e r baud w i l l be s e t , i . e . −b=mica2dot .
Valid product
names a r e :
mica2
mica2dot
( 5 7 6 0 0 baud )
( 1 9 2 0 0 baud )
@ s u b s e c t i o n s e r i a l −s=p o r t [ s e r i a l ]
This f l a g g i v e s t h e u s e r t h e a b i l i t y t o s p e c i f y which COM p o r t o r d e v i c e
x l i s t e n s h o u l d u s e . The d e f a u l t p o r t i s / dev / t t y S 0 o r t h e UNIX e q u i v a l e n t
t o COM1. The g i v e n p o r t must be p a s s e d d i r e c t l y a f t e r t h e e q u a l s s i g n
with no s p a c e s , i . e . −s=com3 .
@ s u b s e c t i o n i n t e r n e t − i=hostname : p o r t [ i n e t ]
This f l a g t e l l s x l i s t e n t o a t t a c h t o a v i r t u a l s e r i a l c o n n e c t i o n o v e r a
TCP/ IP i n t e r n e t s o c k e t .
S p e c i f y t h e hostname and p o r t t o c o n n e c t i n t h e
argument . The d e f a u l t hostname i s l o c a l h o s t , and t h e d e f a u l t p o r t 9 0 0 1 .
The keyword ’ mib600 ’ can be p a s s e d a s an a l i a s t o p o r t 10002 when
c o n n e c t i n g t o t h a t hardware d e v i c e . The hostname and p o r t must be p a s s e d
d i r e c t l y a f t e r t h e e q u a l s s i g n with no s p a c e s with a o p t i o n a l c o l o n
inbetween , i . e . − i=remote , − i = 1 0 . 1 . 1 . 1 : 9 0 0 0 , − i=mymib : mib600 , − i = : 9 0 0 2 ,
− i=l o c a l h o s t : 9 0 0 3 , o r − i=s t a r g a t e . xbow . com .
@ s u b s e c t i o n s e r i a l f o r w a r d e r − s f=hostname : p o r t [ i n e t ]
2. UC-7420 SOFTWARE
129
This f l a g t e l l s x l i s t e n t o a t t a c h t o a s e r i a l f o r w a r d e r c o n n e c t i o n o v e r a
TCP/ IP i n t e r n e t s o c k e t . The hostname and p o r t arguments a r e t h e same a s
t h e − i f l a g . The − s f f l a g t e l l s x l i s t e n t o s p e c i f i c a l l y u s e t h e TinyOS
s e r i a l forwarder protocol .
@ s u b s e c t i o n raw −r [ raw ]
Raw mode d i s p l a y s t h e a c t u a l TOS p a c k e t s a s a s e q u e n c e o f b y t e s a s s e e n
coming o v e r t h e s e r i a l l i n e .
Sample o u t pu t f o l l o w s :
$ x l i s t e n −r
@n
@n
@n
@n
@n
@n
@n
x l i s t e n Ver : I d : x l i s t e n . c , v 1 . 7 2004/03/23 0 0 : 5 2 : 2 8 mturon Exp
Using params : [ raw ]
/ dev / t t y S 0 i n p u t stream opened
7 e7e000033000000c8035f61d383036100000000e4510d610000000080070000d4b5f577
7 e00007d1d8101060029091e09ef082209e7080b09b40800000000000000000000000100
7 e00007d1d81020600f007de07da07d507c3064706540500000000000000000000000100
@subsection parsed
−p [ p a r s e d ]
Parsed mode a t t e m p t s t o i n t e r p r e t t h e r e s u l t s o f t h e i n c o m i n g TOS p a c k e t s
and d i s p l a y i n f o r m a t i o n a c c o r d i n g l y . The f i r s t s t a g e o f t h e p a r s i n g i s t o
l o o k f o r a v a l i d s e n s o r b o a r d i d f i e l d , and d i s p l a y t h e p a r t number .
The
n o d e i d o f t h e p a c k e t s e n d e r i s a l s o p u l l e d out and d i s p l a y e d .
Finally ,
raw s e n s o r r e a d i n g s a r e e x t r a c t e d and d i s p l a y e d with some d e s i g n a t i o n a s
t o t h e i r meaning :
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
$ x l i s t e n −p −b=mica2dot
x l i s t e n Ver : I d : x l i s t e n . c , v 1 . 7 2004/03/23 0 0 : 5 2 : 2 8 mturon Exp
Using params : [ baud=0x000e ] [ p a r s e d ]
/ dev / t t y S 0 i n p u t stream opened
mda500 i d =06 bat =00c1 thrm=0203 a2=019 c a3 =0149 a4=011d a5=012b
mda500 i d =06 bat =00c2 thrm=0203 a2=019d a3=014d a4=011 e a5 =0131
mda500 i d =06 bat =00c2 thrm=0204 a2 =0199 a3=014 c a4 =0125 a5=012a
mda500 i d =06 bat =00c2 thrm=0204 a2 =0198 a3 =0148 a4 =0122 a5 =0131
mda500 i d =06 bat =00c2 thrm=0203 a2=019 e a3=014 e a4 =0124 a5=012b
mda500 i d =06 bat =00c2 thrm=0204 a2=019d a3=014 c a4=011 f a5 =0135
mda500 i d =06 bat =00c2 thrm=0205 a2=019a a3=014 c a4=011 e a5 =0131
@ s u b s e c t i o n cooked
a6=011b
a6=011b
a6=011 f
a6=012d
a6=011 c
a6 =0133
a6=012d
−c [ cooked ]
Cooked mode a c t u a l l y c o n v e r t s t h e raw s e n s o r r e a d i n g s w i t h i n a g i v e n
packet into e n g i n e e r i n g u n i t s .
Sample o u t pu t f o l l o w s :
@n
@n
@n
@n
@n
@n
@n
@n
$ x l i s t e n −c −b=mica2dot
x l i s t e n Ver : I d : x l i s t e n . c , v 1 . 7 2004/03/23 0 0 : 5 2 : 2 8 mturon Exp
Using params : [ baud=0x000e ] [ cooked ]
/ dev / t t y S 0 i n p u t stream opened
MDA500 [ s e n s o r data c o n v e r t e d t o e n g i n e e r i n g u n i t s ] :
health :
node i d =6
battery :
v o l t s =3163 mv
t h e r m i s t o r : r e s i s t a n c e =10177 ohms , t e m p u r a t u r e =24.61 C
a7 =0147
a7 =0140
a7 =0147
a7 =0143
a7 =0143
a7=011d
a7=011 c
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
130
@n
@n
@n
@n
@n
@n
adc
adc
adc
adc
adc
adc
chan
chan
chan
chan
chan
chan
2:
3:
4:
5:
6:
7:
v o l t a g e =1258 mv
v o l t a g e =1001 mv
v o l t a g e =893 mv
v o l t a g e =939 mv
v o l t a g e =875 mv
v o l t a g e =850 mv
@ s u b s e c t i o n q u i e t −q [ q u i e t ]
This f l a g s u p p r e s s e s t h e s t a n d a r d x l i s t e n h e a d e r which d i s p l a y s t h e
v e r s i o n s t r i n g and p a r a m e t e r s e l e c t i o n s .
@subsection export
−x [ e x p o r t ]
Export mode d i s p l a y s raw adc v a l u e s a s comma d e l i m i t e d t e x t f o r u s e i n
s p r e a d s h e e t and data m a n i p u l a t i o n programs . The u s e r can p i p e t h e o u t pu t
o f x l i s t e n i n e x p o r t mode t o a f i l e and l o a d t h a t f i l e i n t o M i c r o s o f t E x c e l
to build charts of the information .
Sample o u tp u t f o l l o w s :
@n
@n
@n
@n
@n
@n
@n
$ x l i s t e n −b=mica2dot −q −x
51200 ,24323 ,54113 ,899 ,97 ,0 ,58368 ,3409
6 ,193 ,518 ,409 ,328 ,283 ,296 ,298
6 ,194 ,517 ,410 ,330 ,292 ,310 ,300
6 ,194 ,518 ,409 ,329 ,286 ,309 ,288
6 ,194 ,517 ,411 ,331 ,287 ,297 ,300
6 ,194 ,516 ,413 ,335 ,288 ,301 ,287
@ s u b s e c t i o n timed −t [ timed ]
D i s p l a y s t h e time a t which t h e p a c k e t was r e c e i v e d .
@n $ x l i s t e n −t
@n [ 2 0 0 4 / 0 9 / 2 9 1 0 : 2 4 : 2 9 ]
@n [ 2 0 0 4 / 0 9 / 2 9 1 0 : 3 6 : 5 7 ]
@ s u b s e c t i o n a s c i i −a [ a s c i i ]
D i s p l a y s t h e raw p a c k e t c o n t e n t s a s ASCII c h a r a c t e r s .
@subsection l o g g i n g −l [ logged ]
Logs i n c o m i n g r e a d i n g s t o a P o s t g r e s d a t a b a s e .
Default connection s e t t i n g s
a r e : s e r v e r=l o c a l h o s t , p o r t =5432 , u s e r=t e l e , p a s s=t i n y .
@subsection header
−h=s i z e [ h e a d e r ]
P a s s i n g t h e h e a d e r f l a g t e l l s x l i s t e n t o u s e a d i f f e r e n t o f f s e t when
p a r s i n g p a c k e t s t h a t a r e b e i n g f o r w a r d e d by TOSBase .
Generally t h i s f l a g
i s not r e q u i r e d a s x l i s t e n a u t o d e t e c t s t h e h e a d e r s i z e from t h e AM t y p e .
When t h i s f l a g i s p a s s e d a l l x l i s t e n w i l l assume a l l i n c o m i n g p a c k e t s have
a data p a y l o a d b e g i n i n g a f t e r t h e h e a d e r s i z e o f f s e t .
@subsection v e r s i o n s
−v [ v e r s i o n s ]
D i s p l a y s c o m p l e t e v e r s i o n i n f o r m a t i o n f o r a l l s e n s o r b o a r d d e c o d i n g modules
2. UC-7420 SOFTWARE
131
within x l i s t e n .
@n $
x l i s t e n −v
@n x l i s t e n Ver : I d : x l i s t e n . c , v 1 . 1 1 2004/08/04 2 1 : 0 6 : 4 1 mturon Exp
@n
8 7 : I d : mep401 . c , v 1 . 1 0 2004/08/04 2 1 : 0 6 : 4 1 mturon Exp
@n
8 6 : I d : mts400 . c , v 1 . 1 5 2004/08/04 2 1 : 0 6 : 4 1 husq Exp
@n
8 5 : I d : mts400 . c , v 1 . 1 5 2004/08/04 2 1 : 0 6 : 4 1 mturon Exp
@n
8 4 : I d : mts300 . c , v 1 . 1 4 2004/08/04 2 1 : 0 6 : 4 1 husq Exp
@n
8 3 : I d : mts300 . c , v 1 . 1 4 2004/08/04 2 1 : 0 6 : 4 1 mturon Exp
@n
8 2 : I d : mts101 . c , v 1 . 5 2004/08/04 2 1 : 0 6 : 4 1 husq Exp
@n
8 1 : I d : mda300 . c , v 1 . 4 2004/08/04 1 7 : 1 5 : 2 2 jdprabhu Exp
@n
8 0 : I d : mda500 . c , v 1 . 1 1 2004/08/04 2 1 : 0 6 : 4 1 husq Exp
@n
0 3 : I d : mep500 . c , v 1 . 3 2004/08/04 2 1 : 0 6 : 4 1 mturon Exp
@n
0 2 : I d : mts510 . c , v 1 . 6 2004/08/04 2 1 : 0 6 : 4 1 husq Exp
@n
0 1 : I d : mda500 . c , v 1 . 1 1 2004/08/04 2 1 : 0 6 : 4 1 abroad Exp
@ s u b s e c t i o n debug −d [ debug ]
This f l a g p u t s x l i s t e n i n a mode s o t h a t i t b e h a v e s e x a c t l y l i k e t h e
TinyOS raw l i s t e n t o o l ( t i n y o s −1. x/ t o o l s / s r c / r a w l i s t e n . c . )
All other
command l i n e o p t i o n s e x c e p t −b [ baud ] and −s [ s e r i a l ] w i l l be i g n o r e d .
This mode i s mainly used f o r c o m p a t i b i l i t y and d e b u g g i n g s e r i a l p o r t
issues .
I n d i v i d u a l b y t e s w i l l be d i s p l a y e d a s soon a s t h e y a r e r e a d from
t h e s e r i a l p o r t with no p o st −p r o c e s s i n g .
I n most c a s e s −r [ raw ] i s
e q u i v a l e n t and p r e f e r r e d t o u s i n g debug mode .
@ s u b s e c t i o n d i s p l a y D i s p l a y O p t io n s
The −r , −p , and −c f l a g s a r e c o n s i d e r e d d i s p l a y o p t i o n s .
These can be
p a s s e d i n v a r i o u s c o m b i n a t i o n s t o d i s p l a y m u l t i p l e v i e w s o f t h e same
p a c k e t a t once . The d e f a u l t d i s p l a y mode when x l i s t e n i s i n v o k e d with no
arguments i s −r . What f o l l o w s i s sample ou t p u t f o r a l l t h r e e d i s p l a y
o p t i o n s t u r n e d on a t once :
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
@n
$ x l i s t e n −b=mica2dot −r −p −c
x l i s t e n Ver : I d : x l i s t e n . c , v 1 . 7 2004/03/23 0 0 : 5 2 : 2 8 mturon Exp
Using params : [ baud=0x000e ] [ raw ] [ p a r s e d ] [ cooked ]
/ dev / t t y S 0 i n p u t stream opened
7 e7e000033000000c8035f61d383036100000000e4510d610000000080070000d4b5f577
7 e00007d1d01010600c200050293014401210135012f0122010000000000000000000100
mda500 i d =06 bat =00c2 thrm=0205 a2 =0193 a3 =0144 a4 =0121 a5 =0135 a6=012 f a7 =0122
MDA500 [ s e n s o r data c o n v e r t e d t o e n g i n e e r i n g u n i t s ] :
health :
node i d =6
battery :
v o l t s =3163 mv
t h e r m i s t o r : r e s i s t a n c e =10217 ohms , t e m p u r a t u r e =24.53 C
adc chan 2 : v o l t a g e =1246 mv
adc chan 3 : v o l t a g e =1001 mv
adc chan 4 : v o l t a g e =893 mv
adc chan 5 : v o l t a g e =955 mv
adc chan 6 : v o l t a g e =936 mv
adc chan 7 : v o l t a g e =896 mv
@section b u i l d i n g Build Process
3. MICA2-BASED WIRELESS ACM VERSION 3 SOFTWARE: MODIFICATION VERSION 2 XMDA300: SHAKE
132
The s o u r c e code f o r t h e x l i s t e n t o o l i s l o c a t e d a t :
/ opt / t i n y o s −1. x/ c o n t r i b /xbow/ t o o l s / s r c / x l i s t e n .
@n@n
To b u i l d t h e t o o l , change t o t h e x l i s t e n s o u r c e d i r e c t o r y and run ‘ make ‘ .
@n@n
To g e t t h e l a t e s t v e r s i o n o f t h e s o u r c e , change t o t h e x l i s t e n s o u r c e
d i r e c t o r y and run ‘ c v s update ‘ .
@ s e c t i o n s e t u p Setup
X L i s t e n i s a command l i n e t o o l t h a t can be run from a cygwin s h e l l by
simply typing ‘ x l i s t e n ‘ .
The e x e c u t a b l e n e e d s t o be i n your working path
t o u s e i t . A s i m p l e way t o add x l i s t e n t o your working path i s t o c r e a t e a
s o f t l i n k t o i t by r u n n i n g t h e f o l l o w i n g command :
@n$ l n −s / opt / t i n y o s −1. x/ c o n t r i b /xbow/ t o o l s / s r c / x l i s t e n / u s r / l o c a l / b i n / x l i s t e n
@n@n
You can u s e x l i s t e n t o r e a d s e n s o r data from e i t h e r one mote o v e r a s e r i a l
l i n k , o r a w i r e l e s s network o f motes .
I n both c o n f i g u r a t i o n s , you need t o
have a MIB510 board c o n n e c t e d v i a a s e r i a l c a b l e t o your PC.
@n@n
For a s i n g l e mote c o n f i g u r a t i o n , t h e mote must be programmed with a
XSensorMXX### a p p l i c a t i o n and p l u g g e d i n t o t h e MIB510 . The mote w i l l
stream p a c k e t s o v e r t h e UART whenever i t has power .
@n@n
For t h e network o f motes c o n f i g u r a t i o n , a b a s e s t a t i o n mote n e e d s t o be
programmed with TOSBase and p l u g g e d i n t o t h e MIB510 .
A l l o t h e r motes need
t o be i n s t a l l e d with an XSensorMXX## a p p l i c a t i o n and put w i t h i n r a n g e o f t h e
b a s e s t a t i o n o r a v a l i d m u l t i −hop p e e r .
X l i s t e n must then be run with t h e
−w f l a g t o p r o p e r l y p a r s e t h e w i r e l e s s p a c k e t s . Take c a r e t o program a l l
t h e motes t o t h e same f r e q u e n c y and group i d .
*/
CHAPTER 4
ēKo mote-based wireless ACPS software
This appendix contains the XML files that were created for use with
the CPA and CPC crack propagation patterns. They are placed on the
ēKo base station in the /usr/xbow/xserve/configxml directory
133
134
4. ēKo MOTE-BASED WIRELESS ACPS SOFTWARE
1. CPA crack propagation pattern: cpa.xml
<?xml v e r s i o n =”1.0” e n c o d i n g=”ISO−8859−1”?>
<!DOCTYPE X S e r v e C o n f i g SYSTEM ” . / x s e r v e c o n f i g . dtd”>
<XServeConfig>
<X F i e l d E x t r a c t o r name=”Vishay Crack P r o p a g a t i o n S e n s o r ( narrow s p a c i n g ) ” o r d e r =”3”>
<X F i e l d s >
<!−− Tos Hdr −−>
<XField name=”amType” b y t e o f f s e t =”2” l e n g t h =”1” t y p e=” u i n t 8 ”/>
<XField name=”group ” b y t e o f f s e t =”3” l e n g t h =”1” t y p e=” u i n t 8 ”/>
<!−− XMesh Hdr −−>
<XField name=”nodeId ” b y t e o f f s e t =”7” l e n g t h =”2” t y p e=”u i n t 1 6 ”
s p e c i a l t y p e =”n o d e i d ”/>
<XField name=” s o c k e t I d ” b y t e o f f s e t =”11” l e n g t h =”1” t y p e=” u i n t 8 ”/>
<!−− XSensor Hdr −−>
<XField name=”b o a r d I d ” b y t e o f f s e t =”12” l e n g t h =”1” t y p e=” u i n t 8 ”
s p e c i a l t y p e =” s e n s o r b o a r d i d ”/>
<XField name=”p a c k e t I d ” b y t e o f f s e t =”13” l e n g t h =”1” t y p e=” u i n t 8 ”/>
<XField name=”ParentID ” b y t e o f f s e t =”14” l e n g t h =”1” t y p e=”u i n t 1 6 ”/>
<!−− Data −−>
<XField name=”E1ReferenceADC ” b y t e o f f s e t =”16” l e n g t h =”2” t y p e=”u i n t 1 6 ”/>
<XField name=”E 1 E x c i t a t i o n V ” b y t e o f f s e t =”18” l e n g t h =”2” t y p e=”u i n t 1 6 ”>
<XConversion f u n c t i o n =”1.225 * 2 * x/y” r e t u r n t y p e =” f l o a t ”>
<XConvParam v a r i a b l e n a m e=”x” f i e l d n a m e =”E 1 E x c i t a t i o n V ” t y p e=” f l o a t ”/>
<XConvParam v a r i a b l e n a m e=”y” f i e l d n a m e =”E1ReferenceADC ” t y p e=” f l o a t ”/>
</XConversion>
</XField>
<!−− p o t e n t i o m e t e r c o n v e r s i o n − r e p o r t v o l t s −−>
<XField name=”RangeV” b y t e o f f s e t =”20” l e n g t h =”2” t y p e=”u i n t 1 6 ”>
<XConversion f u n c t i o n =”1.225 * x/ z ” r e t u r n t y p e =” f l o a t ”>
<XConvParam v a r i a b l e n a m e=”x” f i e l d n a m e =”RangeV” t y p e=” f l o a t ”/>
<XConvParam v a r i a b l e n a m e=”z ” f i e l d n a m e =”E1ReferenceADC ” t y p e=” f l o a t ”/>
</XConversion>
</XField>
</X F i e l d s >
<X F i l t e r >
<!−− LOGIC : SocketID==XSensorEKo AND BoardID ( S e n s o r I d ) AND PacketID==0 −−>
<XCondAnd>
<XCond name=”I s E q u a l ”>
<XFilterParam name=” f i e l d n a m e ” v a l u e=” s o c k e t I d ”/>
<XFilterParam name=” f i e l d v a l u e ” v a l u e =”0x34”/>
</XCond>
<XCond name=”I s E q u a l ”>
<XFilterParam name=” f i e l d n a m e ” v a l u e=”b o a r d I d ”/>
<XFilterParam name=” f i e l d v a l u e ” v a l u e =”162”/>
1. CPA CRACK PROPAGATION PATTERN: CPA.XML
135
</XCond>
<XCond name=”I s E q u a l ”>
<XFilterParam name=” f i e l d n a m e ” v a l u e=”p a c k e t I d ”/>
<XFilterParam name=” f i e l d v a l u e ” v a l u e =”0x0”/>
</XCond>
</XCondAnd>
</ X F i l t e r >
<XDataSinks>
<XDataSink name=”G e n e r i c P r i n t D a t a s i n k”>
<XDSParam name=” p r i n t s t r i n g ”
v a l u e=”Vishay Crack P r o p a g a t i o n
S e n s o r ( narrow
s p a c i n g )[% s :% s ] : \ n Parent :% s
PortID :% s \n RangeV:% s V
ExcitV :% s RefADC:% s ” />
<XDSParam name=” p r i n t f i e l d s ”
v a l u e=”boardId , p a c k e t I d , ParentID , nodeId , , RangeV , E1ExcitationV ,
E1ReferenceADC”/> </XDataSink>
<XDataSink name=”G e n e r i c F i l e D a t a s i n k”>
<XDSParam name=”r a w f i l e n a m e ”
v a l u e=”V i s h a y C r a c k P r o p a g a t i o n N a r r o w S p a c i n g R a w . c s v ”/>
<XDSParam name=” p a r s e d f i l e n a m e ”
v a l u e=”V i s h a y C r a c k P r o p a g a t i o n N a r r o w S p a c i n g P a r s e d . c s v ”/>
<XDSParam name=” c o n v e r t e d f i l e n a m e ”
v a l u e=”V i s h a y C r a c k P r o p a g a t i o n N a r r o w S p a c i n g C o n v e r t e d . c s v ”/>
<XDSParam name=”d e l i m ” v a l u e =”,”/>
<XDSParam name=”h e a d e r ” v a l u e=”y e s ”/>
<XDSParam name=”timestamp ”
v a l u e=”%m−%d−%Y %H:%M:%S”/>
<XDSParam name=”backup ” v a l u e=”y e s ”/>
</XDataSink>
<XDataSink name=”S e n s o r Log D a t a s i n k”> <XDSParam
name=” s e n s o r i d ” v a l u e =”162”/>
<XDSParam name=”tablename ”
v a l u e=” V i s h a y C r a c k P r o p a g a t i o n N a r r o w S p a c i n g s e n s o r r e s u l t s ”/>
<XDSParam name=”sensorname ” v a l u e=”Crack
P r o p a g a t i o n ( Narrow S p a c i n g )”/>
<XDSParam name=”c o l u m n i n f o ”
v a l u e=”f i e l d N a m e = nodeId ,
displayName = Node Id ,
d i s p l a y O r d e r = 1”/>
<XDSParam name=”c o l u m n i n f o ”
v a l u e=”f i e l d N a m e =
RangeV , displayName = RangeV ,
d i s p l a y O r d e r = 2 , unitName =
V o l t s , unitShortName = V,
s e n s o r T y p e = Volta ge ,
sensorMinValue = 0 ,
136
4. ēKo MOTE-BASED WIRELESS ACPS SOFTWARE
sensorMaxValue = 6”/> <XDSParam
name=”c o l u m n i n f o ”
v a l u e=”f i e l d N a m e =
E1ExcitationV , displayName =
Excitation , displayOrder =
3 , unitName = V o l t s ,
unitShortName = V, s e n s o r T y p e =
Vol tag e , s e n s o r M i n V a l u e = 0 ,
sensorMaxValue = 6”/>
</XDataSink>
</XDataSinks>
</X F i e l d E x t r a c t o r >
</XServeConfig>
2. CPC CRACK PROPAGATION PATTERN: CPC.XML
137
2. CPC crack propagation pattern: cpc.xml
<?xml v e r s i o n =”1.0” e n c o d i n g=”ISO−8859−1”?>
<!DOCTYPE X S e r v e C o n f i g SYSTEM ” . / x s e r v e c o n f i g . dtd”>
<XServeConfig>
<X F i e l d E x t r a c t o r name=”Vishay Crack P r o p a g a t i o n S e n s o r ( wide s p a c i n g ) ” o r d e r =”3”>
<X F i e l d s >
<!−− Tos Hdr −−>
<XField name=”amType” b y t e o f f s e t =”2” l e n g t h =”1” t y p e=” u i n t 8 ”/>
<XField name=”group ” b y t e o f f s e t =”3” l e n g t h =”1” t y p e=” u i n t 8 ”/>
<!−− XMesh Hdr −−>
<XField name=”nodeId ” b y t e o f f s e t =”7” l e n g t h =”2” t y p e=”u i n t 1 6 ”
s p e c i a l t y p e =”n o d e i d ”/>
<XField name=” s o c k e t I d ” b y t e o f f s e t =”11” l e n g t h =”1” t y p e=” u i n t 8 ”/>
<!−− XSensor Hdr −−>
<XField name=”b o a r d I d ” b y t e o f f s e t =”12” l e n g t h =”1” t y p e=” u i n t 8 ”
s p e c i a l t y p e =” s e n s o r b o a r d i d ”/>
<XField name=”p a c k e t I d ” b y t e o f f s e t =”13” l e n g t h =”1” t y p e=” u i n t 8 ”/>
<XField name=”ParentID ” b y t e o f f s e t =”14” l e n g t h =”1” t y p e=”u i n t 1 6 ”/>
<!−− Data −−>
<XField name=”E1ReferenceADC ” b y t e o f f s e t =”16” l e n g t h =”2” t y p e=”u i n t 1 6 ”/>
<XField name=”E 1 E x c i t a t i o n V ” b y t e o f f s e t =”18” l e n g t h =”2” t y p e=”u i n t 1 6 ”>
<XConversion f u n c t i o n =”1.225 * 2 * x/y” r e t u r n t y p e =” f l o a t ”>
<XConvParam v a r i a b l e n a m e=”x” f i e l d n a m e =”E 1 E x c i t a t i o n V ” t y p e=” f l o a t ”/>
<XConvParam v a r i a b l e n a m e=”y” f i e l d n a m e =”E1ReferenceADC ” t y p e=” f l o a t ”/>
</XConversion>
</XField>
<!−− p o t e n t i o m e t e r c o n v e r s i o n − r e p o r t v o l t s −−>
<XField name=”RangeV” b y t e o f f s e t =”20” l e n g t h =”2” t y p e=”u i n t 1 6 ”>
<XConversion f u n c t i o n =”1.225 * x/ z ” r e t u r n t y p e =” f l o a t ”>
<XConvParam v a r i a b l e n a m e=”x” f i e l d n a m e =”RangeV” t y p e=” f l o a t ”/>
<XConvParam v a r i a b l e n a m e=”z ” f i e l d n a m e =”E1ReferenceADC ” t y p e=” f l o a t ”/>
</XConversion>
</XField>
</X F i e l d s >
<X F i l t e r >
<!−− LOGIC : SocketID==XSensorEKo AND BoardID ( S e n s o r I d ) AND PacketID==0 −−>
<XCondAnd>
<XCond name=”I s E q u a l ”>
<XFilterParam name=” f i e l d n a m e ” v a l u e=” s o c k e t I d ”/>
<XFilterParam name=” f i e l d v a l u e ” v a l u e =”0x34”/>
</XCond>
<XCond name=”I s E q u a l ”>
<XFilterParam name=” f i e l d n a m e ” v a l u e=”b o a r d I d ”/>
<XFilterParam name=” f i e l d v a l u e ” v a l u e =”161”/>
138
4. ēKo MOTE-BASED WIRELESS ACPS SOFTWARE
</XCond>
<XCond name=”I s E q u a l ”>
<XFilterParam name=” f i e l d n a m e ” v a l u e=”p a c k e t I d ”/>
<XFilterParam name=” f i e l d v a l u e ” v a l u e =”0x0”/>
</XCond>
</XCondAnd>
</ X F i l t e r >
<XDataSinks>
<XDataSink name=”G e n e r i c P r i n t D a t a s i n k”>
<XDSParam name=” p r i n t s t r i n g ”
v a l u e=”Vishay Crack P r o p a g a t i o n
S e n s o r ( wide s p a c i n g )[% s :% s ] : \ n
Parent :% s PortID :% s \n RangeV:% s
V ExcitV :% s RefADC:% s ” />
<XDSParam name=” p r i n t f i e l d s ”
v a l u e=”boardId , p a c k e t I d , ParentID , nodeId , , RangeV , E1ExcitationV ,
E1ReferenceADC”/> </XDataSink>
<XDataSink name=”G e n e r i c F i l e D a t a s i n k”>
<XDSParam name=”r a w f i l e n a m e ”
v a l u e=”V i s h a y C r a c k P r o p a g a t i o n W i d e S p a c i n g R a w . c s v ”/>
<XDSParam name=” p a r s e d f i l e n a m e ”
v a l u e=”V i s h a y C r a c k P r o p a g a t i o n W i d e S p a c i n g P a r s e d . c s v ”/>
<XDSParam name=” c o n v e r t e d f i l e n a m e ”
v a l u e=”V i s h a y C r a c k P r o p a g a t i o n W i d e S p a c i n g C o n v e r t e d . c s v ”/>
<XDSParam name=”d e l i m ” v a l u e =”,”/>
<XDSParam name=”h e a d e r ” v a l u e=”y e s ”/>
<XDSParam name=”timestamp ”
v a l u e=”%m−%d−%Y %H:%M:%S”/>
<XDSParam name=”backup ” v a l u e=”y e s ”/>
</XDataSink>
<XDataSink name=”S e n s o r Log D a t a s i n k”> <XDSParam
name=” s e n s o r i d ” v a l u e =”161”/>
<XDSParam name=”tablename ”
v a l u e=” V i s h a y C r a c k P r o p a g a t i o n W i d e S p a c i n g s e n s o r r e s u l t s ”/>
<XDSParam name=”sensorname ” v a l u e=”Crack
P r o p a g a t i o n ( Wide S p a c i n g )”/>
<XDSParam name=”c o l u m n i n f o ”
v a l u e=”f i e l d N a m e = nodeId ,
displayName = Node Id ,
d i s p l a y O r d e r = 1”/>
<XDSParam name=”c o l u m n i n f o ”
v a l u e=”f i e l d N a m e =
RangeV , displayName = RangeV ,
d i s p l a y O r d e r = 2 , unitName =
V o l t s , unitShortName = V,
s e n s o r T y p e = Volta ge ,
sensorMinValue = 0 ,
sensorMaxValue = 6”/> <XDSParam
2. CPC CRACK PROPAGATION PATTERN: CPC.XML
name=”c o l u m n i n f o ”
v a l u e=”f i e l d N a m e =
E1ExcitationV , displayName =
Excitation , displayOrder =
3 , unitName = V o l t s ,
unitShortName = V, s e n s o r T y p e =
Vol tag e , s e n s o r M i n V a l u e = 0 ,
sensorMaxValue = 6”/>
</XDataSink>
</XDataSinks>
</X F i e l d E x t r a c t o r >
</XServeConfig>
139