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