mica2.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2006 Radu Bogdan Rusu (rusu@cs.tum.edu)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  */
20 
21 /*
22  * TinyOS data structures.
23  * Portions borrowed from the TinyOS project (http://www.tinyos.net),
24  * distributed according to the Intel Open Source License.
25  */
26 
27 #include <vector>
28 
29 // Change to 19200 for Mica2DOT (!)
30 #define DEFAULT_MICA2_PORT "/dev/ttyS0"
31 #define DEFAULT_MICA2_RATE B57600
32 
33 // ---[ Node calibration values ]---
34 class NodeCalibrationValues
35 {
36  public:
37  unsigned int node_id; // node identifier
38  unsigned int group_id; // group identifier
39  int c_values[6]; // calibration values
40 };
41 typedef std::vector<NodeCalibrationValues> NCV;
42 
43 // ---[ MTS310 data packet structure ]---
44 typedef struct
45 {
46  unsigned short vref;
47  unsigned short thermistor;
48  unsigned short light;
49  unsigned short mic;
50  unsigned short accelX;
51  unsigned short accelY;
52  unsigned short magX;
53  unsigned short magY;
54 } MTS310Data;
55 
56 // ---[ MTS510 data packet structure ]---
57 typedef struct
58 {
59  unsigned short light;
60  unsigned short accelX;
61  unsigned short accelY;
62  unsigned short sound[5];
63 } MTS510Data;
64 
65 // ---[ M1-mini RFID reader command packet structure ]---
66 // (Attn: ASCII mode ! make time to change to BINARY!)
67 typedef struct
68 {
69  unsigned char flags [2];
70  unsigned char request[2];
71  unsigned char type [2];
72  unsigned char TID [16];
73  unsigned char start [2];
74  unsigned char length [2];
75  unsigned char data [8];
77 
78 // ---[ Generic sensor data packet structure ]---
79 typedef struct
80 {
81  unsigned char board_id; // unique sensorboard id
82  unsigned char packet_id; // unique packet type for sensorboard
83  unsigned char node_id; // ID of originating node
84  unsigned char parent; // ID of node's parent
85  unsigned short data[12]; // data payload defaults to 24 bytes
86  unsigned char terminator; // reserved for null terminator
87 } SensorPacket;
88 
89 // ---[ The standard header for all TinyOS active messages ]---
90 typedef struct
91 {
92  unsigned short addr;
93  unsigned char type;
94  unsigned char group;
95  unsigned char length;
96 } __attribute__ ((packed)) TOSMsgHeader;
97 
98 // ---[ Packet structure for XCOMMAND ]---
99 typedef struct
100 {
101  unsigned short cmd;
102  union
103  {
104  unsigned int new_rate; // XCOMMAND_SET_RATE
105  unsigned int node_id; // XCOMMAND_SET_NODEID
106  unsigned char group; // XCOMMAND_SET_GROUP
107  unsigned char rf_power; // XCOMMAND_SET_RF_POWER
108  unsigned char rf_channel; // XCOMMAND_SET_RF_CHANNEL
109  struct
110  {
111  unsigned short device; // device: LEDs, speaker, etc
112  unsigned short state; // state : on/off, etc
113  } actuate;
114  } param;
115 } __attribute__ ((packed)) XCommandOp;
116 
117 typedef struct
118 {
119  TOSMsgHeader tos;
120  unsigned short seq_no;
121  unsigned short destination_id; // 0xFFFF for all
122  XCommandOp inst[1];
123 } __attribute__ ((packed)) XCommandMsg;
124 
125 // ---[ RFID data packet structure] ---
126 typedef struct{
127  TOSMsgHeader tos;
128  unsigned char ptotal; // num of packets
129  unsigned char pi; // index of current packet
130  unsigned short RID; // receive id
131  unsigned short SG; // signal strength
132  unsigned char data[23];
133  unsigned short crc;
134 } __attribute__ ((packed)) RFIDMsg;
135 
136 // ---[ Health data packet structure ]---
137 /*typedef struct
138 {
139  unsigned short id;
140  unsigned char hop_count;
141  unsigned char send_est;
142 } DBGEstEntry;
143 typedef struct
144 {
145  unsigned short node_id;
146  unsigned short origin_addr;
147  short seq_no;
148  unsigned char hop_count;
149  // HealthMsg
150  unsigned char est_entries;
151  DBGEstEntry est_list[4];
152 } HealthData;
153 */
#define PLAYER_RFID_REQ_READTAG
Request/reply: read data from the RFID tag - to be implemented.
Definition: player_interfaces.h:4304
char * guid
The Globally Unique IDentifier (GUID) of the tag.
Definition: player_interfaces.h:4323
player_rfid_tag_t * tags
The list of RFID tags.
Definition: player_interfaces.h:4334
int32_t group_id
The Group ID of the WSN node.
Definition: player_interfaces.h:4449
virtual int Subscribe(player_devaddr_t addr)
Subscribe to this driver.
float accel_z
The node's acceleration on Z-axis from an acceleration sensor.
Definition: player_interfaces.h:4397
int32_t node_id
The ID of the WSN node.
Definition: player_interfaces.h:4473
Request/reply: Put the node in sleep mode (0) or wake it up (1).
Definition: player_interfaces.h:4444
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:158
float temperature
The node's templerature measurement from a temperature sensor.
Definition: player_interfaces.h:4405
Generic message header.
Definition: player.h:160
virtual int Subscribe(QueuePointer &, player_devaddr_t)
Subscribe to this driver.
Definition: driver.h:342
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:657
#define PLAYER_WSN_REQ_DATATYPE
Request/reply: change the data type to RAW or converted metric units.
Definition: player_interfaces.h:4378
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:663
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
#define PLAYER_WSN_REQ_POWER
Request/reply: put the node in sleep mode (0) or wake it up (1).
Definition: player_interfaces.h:4375
uint8_t subtype
Message subtype; interface specific.
Definition: player.h:167
virtual void Main(void)=0
Main method for driver thread.
#define PLAYER_WSN_CMD_DEVSTATE
Command subtype: set device state
Definition: player_interfaces.h:4372
int ReadInt(int section, const char *name, int value)
Read an integer value.
Definition: mica2.h:67
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:94
#define PLAYER_ERROR2(msg, a, b)
Error message macros.
Definition: error.h:82
float battery
The node's remaining battery voltage.
Definition: player_interfaces.h:4407
player_wsn_node_data_t data_packet
The WSN node's data packet.
Definition: player_interfaces.h:4422
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:111
#define PLAYER_RFID_DATA_TAGS
Data subtype.
Definition: player_interfaces.h:4298
int32_t node_id
The ID of the WSN node.
Definition: player_interfaces.h:4447
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
static bool MatchDeviceAddress(player_devaddr_t addr1, player_devaddr_t addr2)
Compare two addresses.
Definition: device.h:200
float magn_x
The node's magnetic measurement on X-axis from a magnetometer.
Definition: player_interfaces.h:4399
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:105
float light
The node's light measurement from a light sensor.
Definition: player_interfaces.h:4389
#define PLAYER_MSGTYPE_RESP_NACK
A negative response message.
Definition: player.h:124
uint8_t value
Power setting: 0 for off, 1 for on.
Definition: player_interfaces.h:4451
Request/reply: Change data delivery frequency.
Definition: player_interfaces.h:4470
uint32_t node_type
The type of WSN node.
Definition: player_interfaces.h:4416
float mic
The node's accoustic measurement from a microphone.
Definition: player_interfaces.h:4391
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
float accel_x
The node's acceleration on X-axis from an acceleration sensor.
Definition: player_interfaces.h:4393
#define PLAYER_RFID_REQ_WRITETAG
Request/reply: write data to the RFID tag - to be implemented.
Definition: player_interfaces.h:4307
Class for loading configuration file information.
Definition: configfile.h:195
int ReadTupleInt(int section, const char *name, int index, int value)
Read an integer from a tuple field.
Definition: mica2.h:44
A device address.
Definition: player.h:144
virtual int Unsubscribe(QueuePointer &, player_devaddr_t)
Unsubscribe from this driver.
Definition: driver.h:368
An autopointer for the message queue.
Definition: message.h:72
uint32_t node_parent_id
The ID of the WSN node's parent (if existing).
Definition: player_interfaces.h:4420
uint32_t tags_count
The number of RFID tags found.
Definition: player_interfaces.h:4332
float magn_z
The node's magnetic measurement on Z-axis from a magnetometer.
Definition: player_interfaces.h:4403
#define PLAYER_WSN_DATA_STATE
Data subtypes
Definition: player_interfaces.h:4369
uint32_t node_id
The ID of the WSN node.
Definition: player_interfaces.h:4418
#define PLAYER_WSN_REQ_DATAFREQ
Request/reply: change the receiving data frequency.
Definition: player_interfaces.h:4381
uint32_t type
Tag type.
Definition: player_interfaces.h:4319
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:80
Base class for drivers which oeprate with a thread.
Definition: driver.h:551
Messages between wsn and a robot.
Definition: er.h:86
Data (PLAYER_WSN_DATA_STATE)
Definition: player_interfaces.h:4413
float magn_y
The node's magnetic measurement on Y-axis from a magnetometer.
Definition: player_interfaces.h:4401
Structure describing a single RFID tag.
Definition: player_interfaces.h:4316
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:98
Definition: mica2.h:79
Base class for all drivers.
Definition: driver.h:107
Command: set device state (PLAYER_WSN_CMD_DEVSTATE) This wsn command sets the state of the node's ind...
Definition: player_interfaces.h:4428
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:104
float accel_y
The node's acceleration on Y-axis from an acceleration sensor.
Definition: player_interfaces.h:4395
Definition: mica2.h:57
Request/reply: change the data type to RAW or converted engineering units.
Definition: player_interfaces.h:4459
uint8_t value
Data type setting: 0 for RAW values, 1 for converted units.
Definition: player_interfaces.h:4462
uint32_t guid_count
GUID count.
Definition: player_interfaces.h:4321
virtual int Unsubscribe(player_devaddr_t addr)
Unsubscribe from this driver.
Data.
Definition: player_interfaces.h:4329
double frequency
Requested frequency in Hz.
Definition: player_interfaces.h:4477
int32_t group_id
The Group ID of the WSN node.
Definition: player_interfaces.h:4475