API
usbDevice.hpp
Go to the documentation of this file.
1 /** \file usbDevice.hpp
2  * \author Jared R. Males
3  * \brief Manage a USB TTY device in the MagAOXApp context
4  *
5  * \ingroup tty_files
6  *
7  */
8 
9 #ifndef tty_usbDevice_hpp
10 #define tty_usbDevice_hpp
11 
12 
13 #include <string>
14 
15 
16 #include <unistd.h>
17 //#include <fcntl.h>
18 //#include <poll.h>
19 #include <termios.h>
20 
21 #include <mx/app/appConfigurator.hpp>
22 
23 namespace MagAOX
24 {
25 namespace tty
26 {
27 
28 /// A USB device as a TTY device.
29 /**
30  * \ingroup tty
31  */
32 struct usbDevice
33 {
34  std::string m_idVendor; ///< The vendor id 4-digit code
35  std::string m_idProduct; ///< The product id 4-digit code
36  std::string m_serial; ///< The serial number
37 
38  speed_t m_baudRate {0}; ///< The baud rate specification.
39 
40  std::string m_deviceName; ///< The device path name, e.g. /dev/ttyUSB0
41 
42  int m_fileDescrip {0}; ///< The file descriptor
43 
44  ///Setup an application configurator for the USB section
45  /**
46  * \returns 0 on success.
47  * \returns -1 on error (nothing implemented yet)
48  */
49  int setupConfig( mx::app::appConfigurator & config /**< [in] an application configuration to setup */);
50 
51  ///Load the USB section from an application configurator
52  /**
53  * If config does not contain a baud rate, m_baudRate is unchanged. If m_baudRate is 0 at the end of this
54  * method, an error is returned. Set m_baudRate prior to calling to avoid this error.
55  *
56  * \returns 0 on success
57  * \returns -1 on error (nothing implemented yet)
58  */
59  int loadConfig( mx::app::appConfigurator & config /**< [in] an application configuration from which to load values */);
60 
61  ///Get the device name from udev using the vendor, product, and serial number.
62  int getDeviceName();
63 
64  ///Connect to the device.
65  /** Closes the device file descriptor if open, then calls ttyOpenRaw.
66  *
67  * \returns TTY_E_NOERROR on success.
68  * \returns TTY_E_TCGETATTR on a error from tcgetattr.
69  * \returns TTY_E_TCSETATTR on an error from tcsetattr.
70  * \returns TTY_E_SETISPEED on a cfsetispeed error.
71  * \returns TTY_E_SETOSPEED on a cfsetospeed error.
72  */
73  int connect();
74 };
75 
76 
77 } //namespace tty
78 } //namespace MagAOX
79 
80 #endif //tty_usbDevice_hpp
Definition: dm.hpp:24
A USB device as a TTY device.
Definition: usbDevice.hpp:33
std::string m_deviceName
The device path name, e.g. /dev/ttyUSB0.
Definition: usbDevice.hpp:40
int m_fileDescrip
The file descriptor.
Definition: usbDevice.hpp:42
int connect()
Connect to the device.
Definition: usbDevice.cpp:108
int getDeviceName()
Get the device name from udev using the vendor, product, and serial number.
Definition: usbDevice.cpp:103
std::string m_idProduct
The product id 4-digit code.
Definition: usbDevice.hpp:35
int setupConfig(mx::app::appConfigurator &config)
Setup an application configurator for the USB section.
Definition: usbDevice.cpp:24
std::string m_serial
The serial number.
Definition: usbDevice.hpp:36
int loadConfig(mx::app::appConfigurator &config)
Load the USB section from an application configurator.
Definition: usbDevice.cpp:34
speed_t m_baudRate
The baud rate specification.
Definition: usbDevice.hpp:38
std::string m_idVendor
The vendor id 4-digit code.
Definition: usbDevice.hpp:34