generic_xbow.h
1 /********************************************************************
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  ********************************************************************/
18 /*********************************************************************
19  * TinyOS data structures.
20  * Portions borrowed from the TinyOS project (http://www.tinyos.net),
21  * distributed according to the Intel Open Source License.
22  *********************************************************************/
23 /***************************************************************************
24  * Desc: Driver for generic Crossbow WSN nodes
25  * Author: Adrian Jimenez Gonzalez, Jose Manuel Sanchez Matamoros
26  * Date: 15 Aug 2011
27  **************************************************************************/
28 
29 #ifndef _GENERIC_XBOW_TYPES_H
30 #define _GENERIC_XBOW_TYPES_H
31 
32 #define DEFAULT_GENERICXBOW_PORT "/dev/ttyUSB0"
33 #define DEFAULT_GENERICXBOW_PLATFORM "telosb"
34 #define DEFAULT_GENERICXBOW_OS "tos2x"
35 
36 #ifndef UNIQUE_TIMER
37 #define UNIQUE_TIMER unique("Timer")
38 #endif
39 
40 #define FIXED_UPDATE_INTERVAL 20
41 
42 #define STATIC_DELAY 40
43 
44 #define MAX_PAYLOAD 42
45 #define MAX_TOS_PAYLOAD 35
46 #define MAX_TRANSP_SIZE 100
47 
48 #define WSN_PLAYER_HEADER_COUNT 4
49 
50 #include <cstdio>
51 #include <iostream>
52 #include "mote/MoteIF.h"
53 
54 using namespace mote;
55 using namespace std;
56 
57 enum { MICA2DOT, MICA2, MICAZ, IRIS, TELOS, TELOSB, TMOTE, EYES, INTELMOTE2 };
58 
59 // AM for different message interface
60 enum{
61  AM_MOTE_MESSAGE = 10, // Node to pc messages
62  AM_BASE_MESSAGE = 11, // Node to base messages
63  AM_PLAYER_TO_WSN = 11, // PC to Node messages
64 };
65 
66 // appID for different message origins
67 enum{
68  ID_MOBILE_DATA = 1, // Mobile node message appId
69  ID_HEALTH = 2, // Health message appId
70  ID_FIXED_DATA = 3, // Fixed node message appId
71 };
72 
74 
75 // XMesh header.
76 typedef struct {
77  uint16_t orig;
78  uint16_t source;
79  uint16_t seq;
80  uint8_t appId;
81 } __attribute__ ((packed)) XMeshHeader;
82 
84 
85 // Health message
86 typedef struct {
87  XMeshHeader header;
88  uint16_t id;
89  uint16_t parent_id;
90 } __attribute__((packed)) HealthMsg;
91 
92 // Beacon message
93 typedef struct {
94  uint8_t type;
95  uint8_t node_id;
96  uint8_t sender_id; // RSSI sender
97  uint16_t rssi;
98  uint16_t stamp;
99  uint32_t timelow;
100  uint32_t timehigh;
101  float x;
102  float y;
103  float z;
104 } __attribute__((packed)) RSSIBeaconMsg;
105 
106 typedef struct {
107  uint8_t type;
108  uint16_t id;
109  uint16_t parent_id;
110  float x;
111  float y;
112  float z;
113  uint8_t status;
114 
115 } __attribute__((packed)) PositionMsg;
116 
117 
118 // Individual sensor description
119 typedef struct {
120  uint8_t type;
121  int16_t value;
122 } __attribute__((packed)) sensor_t;
123 
124 // Sensor or Alarm message
125 typedef struct {
126  uint8_t type;
127  uint16_t id;
128  uint16_t parent_id;
129  uint8_t sensor_count;
130  sensor_t *sensor;
131 } __attribute__((packed)) SensorMsg;
132 
133 // User defined data message
134 typedef struct {
135  uint8_t type;
136  uint16_t id;
137  uint16_t parent_id;
138  uint8_t data_size;
139  uint8_t *data;
140 } __attribute__((packed)) UserDataMsg;
141 
142 // Request Message
143 typedef struct {
144  uint8_t type;
145  uint16_t id;
146  uint16_t parent_id;
147  uint8_t request;
148  uint8_t parameters_size;
149  uint8_t *parameters;
150 } __attribute__((packed)) RequestMsg;
151 
152 // Command Message
153 typedef struct {
154  uint8_t type;
155  uint16_t id;
156  uint16_t parent_id;
157  uint8_t command;
158  uint8_t parameters_size;
159  uint8_t *parameters;
160 } __attribute__((packed)) CommandMsg;
161 
162 #endif
#define PLAYER_MSG5(level, msg, a, b, c, d, e)
Error message macros.
Definition: error.h:109
#define PLAYER_WARN1(msg, a)
Error message macros.
Definition: error.h:89
#define PLAYER_COOPOBJECT_MSG_COMMAND
Data subtypes
Definition: player_interfaces.h:5400
#define PLAYER_MSG1(level, msg, a)
Error message macros.
Definition: error.h:105
#define PLAYER_MSG3(level, msg, a, b, c)
Error message macros.
Definition: error.h:107
#define PLAYER_COOPOBJECT_ORIGIN_MOTE
Data subtypes
Definition: player_interfaces.h:5389
uint32_t intensities_count
Number of intensity readings.
Definition: player_interfaces.h:5056
TinyOS generic message.
Definition: MoteProtocol.h:202
#define PLAYER_GPS_DATA_STATE
Data: state (PLAYER_GPS_DATA_STATE)
Definition: player_interfaces.h:1834
uint8_t type
Type of the user defined message.
Definition: player_interfaces.h:5505
#define PLAYER_COOPOBJECT_MSG_REQUEST
Data subtypes
Definition: player_interfaces.h:5399
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:158
A rectangular bounding box, used to define the size of an object.
Definition: player.h:253
double ReadFloat(int section, const char *name, double value)
Read a floating point (double) value.
uint8_t * parameters
The comand info not previously included.
Definition: player_interfaces.h:5545
#define PLAYER_COOPOBJECT_DATA_HEALTH
Data subtypes
Definition: player_interfaces.h:5349
Data: intensity scan (PLAYER_RANGER_DATA_INTNS)
Definition: player_interfaces.h:5053
Definition: player_interfaces.h:5473
#define PLAYER_COOPOBJECT_MSG_SENSOR
Data subtypes
Definition: player_interfaces.h:5397
double ReadTupleLength(int section, const char *name, int index, double value)
Read a length from a tuple (includes units conversion)
Generic message header.
Definition: player.h:160
Device configuration request (PLAYER_RANGER_REQ_GET_CONFIG)
Definition: player_interfaces.h:4983
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:657
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:663
#define PLAYER_RANGER_DATA_INTNS
Data subtype: intensity scan.
Definition: player_interfaces.h:4955
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
#define PLAYER_RANGER_REQ_GET_CONFIG
Request/reply subtype: get configuration.
Definition: player_interfaces.h:4976
double max_angle
End angle of scans [rad].
Definition: player_interfaces.h:4988
virtual void Main(void)=0
Main method for driver thread.
uint32_t parameters_count
Size of the request message parameters (in bytes)
Definition: player_interfaces.h:5524
double min_angle
Start angle of scans [rad].
Definition: player_interfaces.h:4986
#define PLAYER_RANGER_DATA_RANGE
Data subtype: range scan.
Definition: player_interfaces.h:4949
#define PLAYER_MSG4(level, msg, a, b, c, d)
Error message macros.
Definition: error.h:108
int ReadInt(int section, const char *name, int value)
Read an integer value.
#define PLAYER_COOPOBJECT_MSG_HEALTH
Data subtypes
Definition: player_interfaces.h:5394
This class provides serial-port-ready access to the mote.
Definition: MoteIF.h:82
#define PLAYER_COOPOBJECT_DATA_ALARM
Data subtypes
Definition: player_interfaces.h:5358
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:94
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:111
uint32_t ranges_count
Number of range readings.
Definition: player_interfaces.h:5027
uint32_t data_count
Size of the undefined message (in bytes)
Definition: player_interfaces.h:5507
#define PLAYER_COOPOBJECT_REQ_STANDARD
Request subtypes:
Definition: player_interfaces.h:5382
#define PLAYER_WARN2(msg, a, b)
Error message macros.
Definition: error.h:90
uint8_t request
Type of the request.
Definition: player_interfaces.h:5522
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
bool ReadBool(int section, const char *name, bool value)
Read a boolean value (one of: yes, no, true, false, 1, 0)
#define PLAYER_COOPOBJECT_MSG_POSITION
Data subtypes
Definition: player_interfaces.h:5395
Data and Request/reply: Get geometry.
Definition: player_interfaces.h:5005
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:105
Data (PLAYER_COOPOBJECT_DATA_USERDEFINED)
Definition: player_interfaces.h:5501
uint32_t parameters_count
Size of the data of the message (in bytes)
Definition: player_interfaces.h:5543
uint8_t * parameters
Request message parameters
Definition: player_interfaces.h:5526
#define PLAYER_COOPOBJECT_CMD_DATA
Data subtypes
Definition: player_interfaces.h:5376
double ReadTupleAngle(int section, const char *name, int index, double value)
Read an angle form a tuple (includes units conversion)
#define PLAYER_COOPOBJECT_DATA_REQUEST
Data subtypes
Definition: player_interfaces.h:5364
Data: range scan (PLAYER_RANGER_DATA_RANGE)
Definition: player_interfaces.h:5024
#define PLAYER_COOPOBJECT_ORIGIN_MOBILEBASE
Data subtypes
Definition: player_interfaces.h:5388
#define PLAYER_COOPOBJECT_DATA_COMMAND
Data subtypes
Definition: player_interfaces.h:5367
#define PLAYER_MSG6(level, msg, a, b, c, d, e, f)
Error message macros.
Definition: error.h:110
Class for loading configuration file information.
Definition: configfile.h:195
#define PLAYER_COOPOBJECT_DATA_USERDEFINED
Data subtypes
Definition: player_interfaces.h:5361
#define PLAYER_CAPABILITIES_REQ
Capability request message type.
Definition: player.h:396
An autopointer for the message queue.
Definition: message.h:72
uint32_t data_count
Number of sensors included.
Definition: player_interfaces.h:5491
Data (PLAYER_COOPOBJECT_DATA_RSSI)
Definition: player_interfaces.h:5441
Data: state (PLAYER_GPS_DATA_STATE)
Definition: player_interfaces.h:1841
double * intensities
Intensity readings.
Definition: player_interfaces.h:5058
uint8_t origin
0 for fixed from base, 1 for mobile from base, 2 for mote-interface, 3 for Robot
Definition: player_interfaces.h:5431
#define PLAYER_ERROR1(msg, a)
Error message macros.
Definition: error.h:81
A pose in space.
Definition: player.h:227
#define PLAYER_COOPOBJECT_DATA_RSSI
Data subtypes
Definition: player_interfaces.h:5352
double range_res
Range resolution [m].
Definition: player_interfaces.h:4997
#define PLAYER_COOPOBJECT_CMD_STANDARD
Command subtypes:
Definition: player_interfaces.h:5373
#define PLAYER_COOPOBJECT_MSG_ALARM
Data subtypes
Definition: player_interfaces.h:5398
uint8_t command
Command.
Definition: player_interfaces.h:5540
Command: send command from robot to any or all WSN nodes or viceversa
Definition: player_interfaces.h:5535
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:80
#define PLAYER_COOPOBJECT_ORIGIN_STATICBASE
Constants to define the different origins.
Definition: player_interfaces.h:5387
Base class for drivers which oeprate with a thread.
Definition: driver.h:551
Data (PLAYER_COOPOBJECT_DATA_HEALTH)
Definition: player_interfaces.h:5428
Messages between wsn and a robot.
Definition: er.h:86
player_coopobject_sensor_t * data
The node sensors measurements.
Definition: player_interfaces.h:5493
double max_range
Maximum range [m].
Definition: player_interfaces.h:4995
Definition: MoteException.h:45
uint16_t id
The ID of the CO.
Definition: player_interfaces.h:5433
uint16_t parent_id
The ID of the CO parent (if existing).
Definition: player_interfaces.h:5435
#define PLAYER_WARN(msg)
Warning message macros.
Definition: error.h:88
double * ranges
Range readings [m].
Definition: player_interfaces.h:5029
uint8_t type
The type of sensor (see above)
Definition: player_interfaces.h:5476
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:98
double frequency
Scanning frequency [Hz].
Definition: player_interfaces.h:4999
int16_t value
Value of the sensor/alarm
Definition: player_interfaces.h:5478
Base class for all drivers.
Definition: driver.h:107
Definition: MoteException.h:46
uint8_t * data
The node info not previously included.
Definition: player_interfaces.h:5509
Request: send request from robot to any or all WSN nodes or viceversa
Definition: player_interfaces.h:5516
The WSN position packet provides the position of the node.
Definition: player_interfaces.h:5457
#define PLAYER_WARN4(msg, a, b, c, d)
Error message macros.
Definition: error.h:92
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:104
#define PLAYER_COOPOBJECT_MSG_RSSI
Data subtypes
Definition: player_interfaces.h:5396
uint16_t sender_id
The node RSSI measurements.
Definition: player_interfaces.h:5445
#define PLAYER_COOPOBJECT_DATA_SENSOR
Data subtypes
Definition: player_interfaces.h:5355
Definition: MoteException.h:44
#define PLAYER_MSG2(level, msg, a, b)
Error message macros.
Definition: error.h:106
Data (PLAYER_COOPOBJECT_DATA_SENSOR)
Definition: player_interfaces.h:5485
#define PLAYER_COOPOBJECT_DATA_POSITION
Data subtypes
Definition: player_interfaces.h:5370
#define PLAYER_RANGER_REQ_GET_GEOM
Request/reply subtype: get geometry.
Definition: player_interfaces.h:4964
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:75
#define PLAYER_COOPOBJECT_CMD_POSITION
Data subtypes
Definition: player_interfaces.h:5379
double angular_res
Scan resolution [rad].
Definition: player_interfaces.h:4990