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{
40public:
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
47protected:
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
58private:
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