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 */
virtual int Subscribe(player_devaddr_t addr)
Subscribe to this driver.
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:159
Generic message header.
Definition: player.h:162
virtual int Subscribe(QueuePointer &, player_devaddr_t)
Subscribe to this driver.
Definition: driver.h:343
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.
uint8_t subtype
Message subtype; interface specific.
Definition: player.h:168
virtual void Main(void)=0
Main method for driver thread.
int ReadInt(int section, const char *name, int value)
Read an integer value.
Definition: mica2.h:68
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
#define PLAYER_ERROR2(msg, a, b)
Definition: error.h:83
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:112
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:201
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
#define PLAYER_MSGTYPE_RESP_NACK
A negative response message.
Definition: player.h:125
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
Class for loading configuration file information.
Definition: configfile.h:197
int ReadTupleInt(int section, const char *name, int index, int value)
Read an integer from a tuple field.
Definition: mica2.h:45
A device address.
Definition: player.h:146
virtual int Unsubscribe(QueuePointer &, player_devaddr_t)
Unsubscribe from this driver.
Definition: driver.h:369
An autopointer for the message queue.
Definition: message.h:74
#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
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:99
Definition: mica2.h:80
Base class for all drivers.
Definition: driver.h:109
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:105
Definition: mica2.h:58
virtual int Unsubscribe(player_devaddr_t addr)
Unsubscribe from this driver.