1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | /*!
|
---|
6 | * \file Unix_SerialPort.h
|
---|
7 | * \brief Class for unix serial port
|
---|
8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
9 | * \date 2011/08/19
|
---|
10 | * \version 4.0
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef UNIX_SERIALPORT_H
|
---|
14 | #define UNIX_SERIALPORT_H
|
---|
15 |
|
---|
16 | #include <SerialPort.h>
|
---|
17 | #include <termios.h> /* POSIX terminal control definitions */
|
---|
18 |
|
---|
19 | namespace flair
|
---|
20 | {
|
---|
21 | namespace core
|
---|
22 | {
|
---|
23 | /*! \class RTDM_I2cPort
|
---|
24 | *
|
---|
25 | * \brief Class for unix serial port
|
---|
26 | *
|
---|
27 | */
|
---|
28 | class Unix_SerialPort: public SerialPort
|
---|
29 | {
|
---|
30 |
|
---|
31 | public:
|
---|
32 | /*!
|
---|
33 | * \brief Constructor
|
---|
34 | *
|
---|
35 | * Construct an unix serial port, with the following default values: \n
|
---|
36 | * - 115200bps baudrate
|
---|
37 | *
|
---|
38 | * \param parent parent
|
---|
39 | * \param name name
|
---|
40 | * \param device serial device (ex rtser1)
|
---|
41 | */
|
---|
42 | Unix_SerialPort(const Object* parent,std::string port_name,std::string device);
|
---|
43 |
|
---|
44 | /*!
|
---|
45 | * \brief Destructor
|
---|
46 | *
|
---|
47 | */
|
---|
48 | ~Unix_SerialPort();
|
---|
49 |
|
---|
50 | /*!
|
---|
51 | * \brief Set baudrate
|
---|
52 | *
|
---|
53 | * \param baudrate baudrate
|
---|
54 | *
|
---|
55 | */
|
---|
56 | void SetBaudrate(int baudrate);
|
---|
57 |
|
---|
58 | /*!
|
---|
59 | * \brief Set RX timeout
|
---|
60 | *
|
---|
61 | * Timeout for waiting datas.
|
---|
62 | *
|
---|
63 | * \param timeout_ns timeout in nano second
|
---|
64 | */
|
---|
65 | void SetRxTimeout(Time timeout_ns);
|
---|
66 |
|
---|
67 | /*!
|
---|
68 | * \brief Write datas
|
---|
69 | *
|
---|
70 | * \param buf pointer to datas
|
---|
71 | * \param nbyte length of datas
|
---|
72 | *
|
---|
73 | * \return amount of written datas
|
---|
74 | */
|
---|
75 | ssize_t Write(const void *buf,size_t nbyte);
|
---|
76 |
|
---|
77 | /*!
|
---|
78 | * \brief Read datas
|
---|
79 | *
|
---|
80 | * \param buf pointer to datas
|
---|
81 | * \param nbyte length of datas
|
---|
82 | *
|
---|
83 | * \return amount of read datas
|
---|
84 | */
|
---|
85 | ssize_t Read(void *buf,size_t nbyte);
|
---|
86 |
|
---|
87 | /*!
|
---|
88 | * \brief Flush input datas
|
---|
89 | *
|
---|
90 | */
|
---|
91 | void FlushInput(void);
|
---|
92 |
|
---|
93 | private:
|
---|
94 | int fd;
|
---|
95 | struct termios options;
|
---|
96 | };
|
---|
97 | } // end namespace core
|
---|
98 | } // end namespace flair
|
---|
99 |
|
---|
100 | #endif // UNIX_SERIALPORT_H
|
---|