serialPort.hpp
Go to the documentation of this file.
1/* Copyright 2008 Renato Florentino Garcia <fgar.renato@gmail.com>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2, as
5 * published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15
16#ifndef SERIAL_PORT_HPP
17#define SERIAL_PORT_HPP
18
19#include <string>
20#include <vector>
21#include <stdexcept>
22#include <sys/time.h>
23#include <termios.h>
24
41{
42public:
43
51 SerialPort(std::string &serialPort);
52
54
60 inline std::string getError() const
61 {
62 return this->errorDescription;
63 }
64
66 int initialize();
67
74 int recvInt() const;
75
82 unsigned recvUnsigned() const;
83
90 char recvChar() const;
91
97 int recvUnsignedCharArray(unsigned char* const array, unsigned length) const;
98
104 void sendInt(int message) const;
105
111 void sendChar(char message) const;
112
113private:
114
115 int fileDescriptor;
116
117 std::string serialPort;
118
119 // Describe the last error.
120 std::string errorDescription;
121
122 // Backup the tremios struct for reload it on exit.
123 struct termios termios_backup;
124};
125
126#endif
Send and receive messages from e-puck.
Definition serialPort.hpp:41
std::string getError() const
Return the last error.
Definition serialPort.hpp:60
int recvInt() const
Receive a signed interger from e-puck.
Definition serialPort.cpp:96
char recvChar() const
Receive a char from e-puck.
Definition serialPort.cpp:134
SerialPort(std::string &serialPort)
Constructor of SerialPort class.
Definition serialPort.cpp:26
unsigned recvUnsigned() const
Receive an unsigned interger from e-puck.
Definition serialPort.cpp:115
int recvUnsignedCharArray(unsigned char *const array, unsigned length) const
Receive an array of unsigned char from e-puck.
Definition serialPort.cpp:148
int initialize()
Open the serial port device and set the configurations for it.
Definition serialPort.cpp:39
void sendChar(char message) const
Send a character to e-puck.
Definition serialPort.cpp:184
void sendInt(int message) const
Send an integer to e-puck.
Definition serialPort.cpp:172