hemisson_serial.h
1 /*
2  * Serial communication helper class for Hemisson robot driver
3  * Copyright (C) 2010 Paul Osmialowski
4  * Based on Minicom code released on the same license
5  * Minicom is Copyright (C) 1991,1992,1993,1994,1995,1996
6  * Miquel van Smoorenburg.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 #ifndef HEMISSON_SERIAL_H
25 #define HEMISSON_SERIAL_H
26 
27 #include <stddef.h>
28 #include <termios.h>
29 
30 #define HEMISSON_BAUDRATE "115200"
31 #define HEMISSON_DEFAULT_SERIAL_PORT "/dev/rfcomm0"
32 #define HEMISSON_BUFFER_LEN 255
33 #define HEMISSON_SERIAL_TIMEOUT_USECS 100000
34 
35 #define TTYBUFFLEN 255
36 #define TTYBUFFSIZE (TTYBUFFLEN + 1)
37 
39 {
40 public:
41  HemissonSerial(int debug = 0, const char * port = HEMISSON_DEFAULT_SERIAL_PORT, const char * rate = HEMISSON_BAUDRATE);
42  virtual ~HemissonSerial();
43 
44  bool Open() { return fd >0; };
45  int HemissonCommand(char command, int InCount, int * InValues, int OutCount, int * OutValues);
46 
47 protected:
48  // serial port descriptor
49  int fd;
50  // read/write buffer
51  char buffer[HEMISSON_BUFFER_LEN + 1];
52 
53  int WriteInts(char command, int Count = 0, int * Values = NULL);
54  int ReadInts(char Header, int Count = 0, int * Values = NULL);
55 
56  int debug;
57 
58 private:
59  char ttybuf[TTYBUFFSIZE];
60  char parity;
61  struct termios savetty;
62  int m_word;
63 
64  char * m_gets(int fd, int tmout);
65  int m_getchar(int fd, int tmout);
66  void m_puts(int fd, const char * s);
67  void m_putchar(int fd, int chr);
68  void m_dtrtoggle(int fd, int sec);
69  void m_break(int fd);
70  int m_getdcd(int fd);
71  void m_flush(int fd);
72  void m_setparms(int fd, const char * baudr, const char * par, const char * bits, const char * stopb, int hwf, int swf);
73  int serial_open(const char * devname);
74  void serial_close(int fd);
75 
76  void m_sethwf(int fd, int on);
77  void m_setrts(int fd);
78  void m_savestate(int fd);
79  void m_restorestate(int fd);
80  void m_nohang(int fd);
81  void m_hupcl(int fd, int on);
82 };
83 
84 #endif
85 
uint8_t state
FALSE for off, TRUE for on.
Definition: player_interfaces.h:667
position 2d velocity command
Definition: player_interfaces.h:617
uint32_t element_sizes_count
Number of individual elements that make up the device.
Definition: player_interfaces.h:5016
player_pose3d_t * element_poses
Pose of each individual element that makes up the device (in device CS).
Definition: player_interfaces.h:5014
player_pose2d_t vel
translational velocities [m/s,m/s,rad/s] (x, y, yaw)
Definition: player_interfaces.h:620
Definition: hemisson_serial.h:38
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.
double px
X [m].
Definition: player.h:230
Generic message header.
Definition: player.h:160
double pz
Z [m].
Definition: player.h:234
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
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
#define PLAYER_POSITION2D_REQ_MOTOR_POWER
Request/reply: Motor power.
Definition: player_interfaces.h:496
position2d power config
Definition: player_interfaces.h:664
double px
X [m].
Definition: player.h:219
#define PLAYER_RANGER_REQ_GET_CONFIG
Request/reply subtype: get configuration.
Definition: player_interfaces.h:4976
#define PLAYER_POSITION2D_CMD_VEL
Command: velocity (PLAYER_POSITION2D_CMD_VEL)
Definition: player_interfaces.h:581
double pyaw
yaw [rad]
Definition: player.h:240
virtual void Main(void)=0
Main method for driver thread.
#define PLAYER_RANGER_DATA_RANGE
Data subtype: range scan.
Definition: player_interfaces.h:4949
int ReadInt(int section, const char *name, int value)
Read an integer value.
#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
player_bbox3d_t size
Size of the device [m, m, m].
Definition: player_interfaces.h:5010
#define PLAYER_POSITION2D_REQ_GET_GEOM
Request/reply: geometry.
Definition: player_interfaces.h:483
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
double ppitch
pitch [rad]
Definition: player.h:238
Data and Request/reply: Get geometry.
Definition: player_interfaces.h:5005
double sh
Height [m].
Definition: player.h:260
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:105
double sl
Length [m].
Definition: player.h:258
Data: range scan (PLAYER_RANGER_DATA_RANGE)
Definition: player_interfaces.h:5024
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
uint32_t element_poses_count
Number of individual elements that make up the device.
Definition: player_interfaces.h:5012
Class for loading configuration file information.
Definition: configfile.h:195
double sw
Width [m].
Definition: player.h:256
A device address.
Definition: player.h:144
An autopointer for the message queue.
Definition: message.h:72
double py
Y [m].
Definition: player.h:232
player_bbox3d_t * element_sizes
Size of each individual element that makes up the device.
Definition: player_interfaces.h:5018
position2d data
Definition: player_interfaces.h:606
position2d geom
Definition: player_interfaces.h:655
A pose in space.
Definition: player.h:227
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:80
Base class for drivers which oeprate with a thread.
Definition: driver.h:551
#define PLAYER_POSITION2D_DATA_STATE
Data: state (PLAYER_POSITION2D_DATA_STATE)
Definition: player_interfaces.h:568
double * ranges
Range readings [m].
Definition: player_interfaces.h:5029
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:98
double pa
yaw [rad]
Definition: player.h:223
Base class for all drivers.
Definition: driver.h:107
#define PLAYER_WARN4(msg, a, b, c, d)
Error message macros.
Definition: error.h:92
uint8_t stall
Are the motors stalled?
Definition: player_interfaces.h:613
player_bbox3d_t size
Dimensions of the base (m).
Definition: player_interfaces.h:660
#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