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)
Definition: error.h:110
#define PLAYER_WARN1(msg, a)
Definition: error.h:90
#define PLAYER_MSG1(level, msg, a)
Definition: error.h:106
#define PLAYER_MSG3(level, msg, a, b, c)
Definition: error.h:108
TinyOS generic message.
Definition: MoteProtocol.h:205
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:159
A rectangular bounding box, used to define the size of an object.
Definition: player.h:255
double ReadFloat(int section, const char *name, double value)
Read a floating point (double) value.
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:162
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:658
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:664
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
virtual void Main(void)=0
Main method for driver thread.
#define PLAYER_MSG4(level, msg, a, b, c, d)
Definition: error.h:109
int ReadInt(int section, const char *name, int value)
Read an integer value.
This class provides serial-port-ready access to the mote.
Definition: MoteIF.h:64
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:112
#define PLAYER_WARN2(msg, a, b)
Definition: error.h:91
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_MSGTYPE_REQ
A request message.
Definition: player.h:106
double ReadTupleAngle(int section, const char *name, int index, double value)
Read an angle form a tuple (includes units conversion)
#define PLAYER_MSG6(level, msg, a, b, c, d, e, f)
Definition: error.h:111
Class for loading configuration file information.
Definition: configfile.h:197
#define PLAYER_CAPABILITIES_REQ
Capability request message type.
Definition: player.h:397
An autopointer for the message queue.
Definition: message.h:74
#define PLAYER_ERROR1(msg, a)
Definition: error.h:82
A pose in space.
Definition: player.h:229
#define PLAYER_ERROR(msg)
Definition: error.h:81
Base class for drivers which oeprate with a thread.
Definition: driver.h:553
Messages between wsn and a robot.
Definition: er.h:87
Definition: MoteException.h:48
#define PLAYER_WARN(msg)
Warning message macros.
Definition: error.h:89
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:99
Base class for all drivers.
Definition: driver.h:109
Definition: MoteException.h:49
#define PLAYER_WARN4(msg, a, b, c, d)
Definition: error.h:93
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:105
Definition: MoteException.h:47
#define PLAYER_MSG2(level, msg, a, b)
Definition: error.h:107
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76