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