|
24 | 24 | #error "target platform not defined." |
25 | 25 | #endif |
26 | 26 |
|
27 | | -class SerialPort |
| 27 | +namespace sp |
28 | 28 | { |
29 | | - public: |
30 | | - /// @brief default coustructor |
31 | | - SerialPort() = default; |
32 | | - /// @brief constructor that will open port |
33 | | - /// @param name port name to open |
34 | | - SerialPort(std::string name); |
35 | | - /// @brief constructor that will open port and configure it |
36 | | - /// @param name port name to open |
37 | | - /// @param config port configuration |
38 | | - SerialPort(std::string name, sp::PortConfig config); |
39 | | - /// @brief open port with passed name |
40 | | - /// @param name port name |
41 | | - /// @return error code |
42 | | - std::error_code open(const std::string name); |
43 | | - /// @brief setup port with passed configuration (if port is open) |
44 | | - /// @param config port configuration |
45 | | - /// @return error enum |
46 | | - std::error_code setup(sp::PortConfig config); |
47 | | - /// @brief request for port system path |
48 | | - /// @return actual path |
49 | | - std::string getPath() const {return path;}; |
50 | | - /// @brief request for port configuration |
51 | | - /// @return struct with configuration |
52 | | - sp::PortConfig getConfig() const {return config;}; |
53 | | - /// @brief request for port state |
54 | | - /// @return actual port state |
55 | | - sp::PortState getState() const {return state;}; |
56 | | - #if defined(PLATFORM_LINUX) |
57 | | - SerialPortLinux port; |
58 | | - #elif defined(PLATFORM_WINDOWS) |
59 | | - SerialPortWindows port; |
60 | | - #endif |
| 29 | + class SerialPort |
| 30 | + { |
| 31 | + public: |
| 32 | + /// @brief default coustructor |
| 33 | + SerialPort() = default; |
| 34 | + /// @brief constructor that will open port |
| 35 | + /// @param name port name to open |
| 36 | + SerialPort(std::string name); |
| 37 | + /// @brief constructor that will open port and configure it |
| 38 | + /// @param name port name to open |
| 39 | + /// @param config port configuration |
| 40 | + SerialPort(std::string name, sp::PortConfig config); |
| 41 | + /// @brief open port with passed name |
| 42 | + /// @param name port name |
| 43 | + /// @return error code |
| 44 | + std::error_code open(const std::string name); |
| 45 | + /// @brief setup port with passed configuration (if port is open) |
| 46 | + /// @param config port configuration |
| 47 | + /// @return error enum |
| 48 | + std::error_code setup(sp::PortConfig config); |
| 49 | + /// @brief request for port system path |
| 50 | + /// @return actual path |
| 51 | + std::string getPath() const {return path;}; |
| 52 | + /// @brief request for port configuration |
| 53 | + /// @return struct with configuration |
| 54 | + sp::PortConfig getConfig() const {return config;}; |
| 55 | + /// @brief request for port state |
| 56 | + /// @return actual port state |
| 57 | + sp::PortState getState() const {return state;}; |
| 58 | + #if defined(PLATFORM_LINUX) |
| 59 | + SerialPortLinux port; |
| 60 | + #elif defined(PLATFORM_WINDOWS) |
| 61 | + SerialPortWindows port; |
| 62 | + #endif |
61 | 63 |
|
62 | | - private: |
63 | | - /// @brief actual port state |
64 | | - sp::PortState state = sp::PortState::Close; |
65 | | - /// @brief actual port path |
66 | | - std::string path = "dev/null"; |
67 | | - /// @brief actual port config |
68 | | - sp::PortConfig config = sp::PortConfig(); |
69 | | -}; |
| 64 | + private: |
| 65 | + /// @brief actual port state |
| 66 | + sp::PortState state = sp::PortState::Close; |
| 67 | + /// @brief actual port path |
| 68 | + std::string path = "dev/null"; |
| 69 | + /// @brief actual port config |
| 70 | + sp::PortConfig config = sp::PortConfig(); |
| 71 | + }; |
70 | 72 |
|
71 | | -class SerialDevice |
72 | | -{ |
73 | | - public: |
74 | | - SerialDevice(){updateAvailableDevices();}; |
75 | | - /// @brief plaform depended call to update list with serial port devices |
76 | | - void updateAvailableDevices(); |
77 | | - /// @brief request for list with serial port devices in system |
78 | | - /// @return referense to a vector with devices |
79 | | - std::vector<std::string>& getListOfAvailableDevices(){return devices;}; |
80 | | - /// @brief request for list with serial port devices in system |
81 | | - /// @return vector with devices |
82 | | - std::vector<std::string> getListOfAvailableDevices() const {return devices;}; |
83 | | - |
84 | | - private: |
85 | | - /// @brief vertor with actual list of available serial ports |
86 | | - std::vector<std::string> devices; |
87 | | -}; |
| 73 | + class SerialDevice |
| 74 | + { |
| 75 | + public: |
| 76 | + SerialDevice(){updateAvailableDevices();}; |
| 77 | + /// @brief plaform depended call to update list with serial port devices |
| 78 | + void updateAvailableDevices(); |
| 79 | + /// @brief request for list with serial port devices in system |
| 80 | + /// @return referense to a vector with devices |
| 81 | + std::vector<std::string>& getListOfAvailableDevices(){return devices;}; |
| 82 | + /// @brief request for list with serial port devices in system |
| 83 | + /// @return vector with devices |
| 84 | + std::vector<std::string> getListOfAvailableDevices() const {return devices;}; |
| 85 | + |
| 86 | + private: |
| 87 | + /// @brief vertor with actual list of available serial ports |
| 88 | + std::vector<std::string> devices; |
| 89 | + }; |
| 90 | +} |
88 | 91 |
|
89 | 92 | #endif //SERIAL_PORT_H |
0 commit comments