| 92 | } |
| 93 | |
| 94 | void verifySerialPort(std::string const &port, std::string const &origPort) { |
| 95 | std::string const *origPortPtr = origPort.empty() ? &port : &origPort; |
| 96 | auto portState = getSerialPortState(port); |
| 97 | if (SERIAL_BUSY == portState) { |
| 98 | throw std::runtime_error("Cannot access " + *origPortPtr + |
| 99 | ": currently busy. Do you have another " |
| 100 | "application open using that port?"); |
| 101 | } else if (SERIAL_MISSING == portState) { |
| 102 | throw std::runtime_error("Cannot access " + *origPortPtr + |
| 103 | ": port apparently not found. Make sure the " |
| 104 | "device is plugged in and you've specified " |
| 105 | "the right device and the right port."); |
| 106 | } else if (SERIAL_INVALID == portState) { |
| 107 | throw std::runtime_error("Cannot access serial port '" + *origPortPtr + |
| 108 | "': apparently invalid."); |
| 109 | } else if (SERIAL_AVAILABLE != portState) { |
| 110 | /// safety catch-all |
| 111 | throw std::runtime_error("Cannot access serial port '" + *origPortPtr + |
| 112 | "'"); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | std::string normalizeAndVerifySerialPort(std::string const &port) { |
| 117 | std::string ret = normalizeSerialPort(port); |
no test coverage detected