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 
Definition: hemisson_serial.h:39
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.
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.
int ReadInt(int section, const char *name, int value)
Read an integer value.
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
#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.
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
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
A device address.
Definition: player.h:146
An autopointer for the message queue.
Definition: message.h:74
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
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:99
Base class for all drivers.
Definition: driver.h:109
#define PLAYER_WARN4(msg, a, b, c, d)
Definition: error.h:93
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76