[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_I2cPort.h
|
---|
| 7 | * \brief Class for unix i2c port
|
---|
| 8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 9 | * \date 2014/08/28
|
---|
| 10 | * \version 4.0
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | #ifndef UNIX_I2CPORT_H
|
---|
| 14 | #define UNIX_I2CPORT_H
|
---|
| 15 |
|
---|
| 16 | #include <I2cPort.h>
|
---|
| 17 |
|
---|
[13] | 18 | namespace flair {
|
---|
| 19 | namespace core {
|
---|
| 20 | /*! \class Unix_I2cPort
|
---|
| 21 | *
|
---|
| 22 | * \brief Class for unix serial port
|
---|
| 23 | *
|
---|
| 24 | */
|
---|
| 25 | class Unix_I2cPort : public I2cPort {
|
---|
[2] | 26 |
|
---|
[13] | 27 | public:
|
---|
| 28 | /*!
|
---|
| 29 | * \brief Constructor
|
---|
| 30 | *
|
---|
| 31 | * Construct an unix i2c port
|
---|
| 32 | *
|
---|
| 33 | * \param parent parent
|
---|
| 34 | * \param name name
|
---|
| 35 | * \param device serial device (ex /dev/i2c-1)
|
---|
| 36 | */
|
---|
| 37 | Unix_I2cPort(const Object *parent, std::string port_name, std::string device);
|
---|
[2] | 38 |
|
---|
[13] | 39 | /*!
|
---|
| 40 | * \brief Destructor
|
---|
| 41 | *
|
---|
| 42 | */
|
---|
| 43 | ~Unix_I2cPort();
|
---|
[2] | 44 |
|
---|
[13] | 45 | /*!
|
---|
| 46 | * \brief Set slave's address
|
---|
| 47 | *
|
---|
| 48 | * This method need to be called before any communication.
|
---|
| 49 | *
|
---|
| 50 | * \param address slave's address
|
---|
| 51 | */
|
---|
| 52 | int SetSlave(uint16_t address);
|
---|
[2] | 53 |
|
---|
[13] | 54 | /*!
|
---|
| 55 | * \brief Set RX timeout
|
---|
| 56 | *
|
---|
| 57 | * Timeout for waiting datas.
|
---|
| 58 | *
|
---|
| 59 | * \param timeout_ns timeout in nano second
|
---|
| 60 | */
|
---|
| 61 | void SetRxTimeout(Time timeout_ns);
|
---|
[2] | 62 |
|
---|
[13] | 63 | /*!
|
---|
| 64 | * \brief Set TX timeout
|
---|
| 65 | *
|
---|
| 66 | * Timeout for waiting an ACK from the slave.
|
---|
| 67 | *
|
---|
| 68 | * \param timeout_ns timeout in nano second
|
---|
| 69 | */
|
---|
| 70 | void SetTxTimeout(Time timeout_ns);
|
---|
[2] | 71 |
|
---|
[13] | 72 | /*!
|
---|
| 73 | * \brief Write datas
|
---|
| 74 | *
|
---|
| 75 | * \param buf pointer to datas
|
---|
| 76 | * \param nbyte length of datas
|
---|
| 77 | *
|
---|
| 78 | * \return amount of written datas
|
---|
| 79 | */
|
---|
| 80 | ssize_t Write(const void *buf, size_t nbyte);
|
---|
[2] | 81 |
|
---|
[13] | 82 | /*!
|
---|
| 83 | * \brief Read datas
|
---|
| 84 | *
|
---|
| 85 | * \param buf pointer to datas
|
---|
| 86 | * \param nbyte length of datas
|
---|
| 87 | *
|
---|
| 88 | * \return amount of read datas
|
---|
| 89 | */
|
---|
| 90 | ssize_t Read(void *buf, size_t nbyte);
|
---|
[2] | 91 |
|
---|
[13] | 92 | private:
|
---|
| 93 | int fd;
|
---|
| 94 | };
|
---|
[2] | 95 | } // end namespace core
|
---|
| 96 | } // end namespace flair
|
---|
| 97 |
|
---|
| 98 | #endif // UNIX_I2CPORT_H
|
---|