diff --git a/ur_rtde_driver/include/ur_rtde_driver/comm/server.h b/ur_rtde_driver/include/ur_rtde_driver/comm/server.h index cc6ef2d..9381cb4 100644 --- a/ur_rtde_driver/include/ur_rtde_driver/comm/server.h +++ b/ur_rtde_driver/include/ur_rtde_driver/comm/server.h @@ -34,6 +34,10 @@ namespace comm { #define MAX_SERVER_BUF_LEN 50 +/*! + * \brief The URServer class abstracts communication with the robot. It opens a socket on a given + * port and waits for a robot to connect, at which point two way communication can be established. + */ class URServer : private comm::TCPSocket { private: @@ -44,13 +48,56 @@ protected: virtual bool open(int socket_fd, struct sockaddr* address, size_t address_len); public: + /*! + * \brief Creates a URServer object with a given port. + * + * \param port The port to open a socket on + */ URServer(int port); + /*! + * \brief Closes the socket to allow for destruction of the object. + */ ~URServer(); + /*! + * \brief Getter for the server IP. + * + * \returns The IP of the server + */ std::string getIP(); + /*! + * \brief Binds to server's port, setting up a socket if possible. + * + * \returns Success of setting up the socket + */ bool bind(); + /*! + * \brief Waits for a robot to connect to the socket. + * + * \returns True, if a robot successfully connected, false otherwise. + */ bool accept(); + /*! + * \brief Triggers a disconnect of the currently connected robot. + */ void disconnectClient(); + /*! + * \brief Reads the byte-stream from the robot to the next linebreak. + * + * \param buffer The buffer to write the received bytes to + * \param buf_len Size of the buffer + * + * \returns True if a successful read occurred, false otherwise + */ bool readLine(char* buffer, size_t buf_len); + /*! + * \brief Writes a buffer to the robot. + * + * \param buf The buffer to write from + * \param buf_len The length to write + * \param written A reference used to indicate how many bytes were written + * + * \returns Success of the write + */ bool write(const uint8_t* buf, size_t buf_len, size_t& written); }; } // namespace comm diff --git a/ur_rtde_driver/include/ur_rtde_driver/comm/shell_consumer.h b/ur_rtde_driver/include/ur_rtde_driver/comm/shell_consumer.h index 19fd21b..f6c6725 100644 --- a/ur_rtde_driver/include/ur_rtde_driver/comm/shell_consumer.h +++ b/ur_rtde_driver/include/ur_rtde_driver/comm/shell_consumer.h @@ -36,6 +36,12 @@ namespace ur_driver { namespace comm { +/*! + * \brief The ShellConsumer class is a simple consumer that writes a readable representation to + * the logging info channel. + * + * @tparam HeaderT Header type of the packages to consume + */ template class ShellConsumer : public IConsumer> { @@ -43,6 +49,13 @@ public: ShellConsumer() = default; virtual ~ShellConsumer() = default; + /*! + * \brief Consumes a package, writing a human readable representation to the logging. + * + * \param product The package to consume + * + * \returns True if the output was successful + */ virtual bool consume(std::shared_ptr> product) { LOG_INFO("%s", product->toString().c_str()); diff --git a/ur_rtde_driver/include/ur_rtde_driver/comm/stream.h b/ur_rtde_driver/include/ur_rtde_driver/comm/stream.h index 8a7e13e..b4347f7 100644 --- a/ur_rtde_driver/include/ur_rtde_driver/comm/stream.h +++ b/ur_rtde_driver/include/ur_rtde_driver/comm/stream.h @@ -56,7 +56,7 @@ public: /*! * \brief Connects to the configured socket. * - * \returns True on success, false if connection could not be established. + * \returns True on success, false if connection could not be established */ bool connect() { @@ -89,7 +89,7 @@ public: * \param[in] buf_len Number of bytes allocated for the buffer * \param[out] read Number of bytes actually read from the socket * - * \returns True on success, false on error, e.g. the buffer is smaller than the package size. + * \returns True on success, false on error, e.g. the buffer is smaller than the package size */ bool read(uint8_t* buf, const size_t buf_len, size_t& read); @@ -98,9 +98,9 @@ public: * * \param[in] buf Byte stream that should be sent * \param[in] buf_len Number of bytes in buffer - * \param[out] written Number of bytes actually written to the socket. + * \param[out] written Number of bytes actually written to the socket * - * \returns false if sending went wrong + * \returns False if sending went wrong */ bool write(const uint8_t* buf, const size_t buf_len, size_t& written); diff --git a/ur_rtde_driver/include/ur_rtde_driver/comm/tcp_socket.h b/ur_rtde_driver/include/ur_rtde_driver/comm/tcp_socket.h index 4a84747..7c7b8b4 100644 --- a/ur_rtde_driver/include/ur_rtde_driver/comm/tcp_socket.h +++ b/ur_rtde_driver/include/ur_rtde_driver/comm/tcp_socket.h @@ -59,18 +59,38 @@ protected: bool setup(std::string& host, int port); public: + /*! + * \brief Creates a TCPSocket object + */ TCPSocket(); virtual ~TCPSocket(); + /*! + * \brief Getter for the state of the socket. + * + * \returns Returns the current state of the socket + */ SocketState getState() { return state_; } + /*! + * \brief Getter for the file descriptor of the socket. + * + * \returns The file descriptor of the socket + */ int getSocketFD() { return socket_fd_; } + /*! + * \brief Setter for the file descriptor of the socket. + * + * \param socket_fd The new value + * + * \returns False, if the socket is in state connected + */ bool setSocketFD(int socket_fd); /*!