* @brief Parses a Modbus TCP host[:port] string. */
| 976 | * @brief Parses a Modbus TCP host[:port] string. |
| 977 | */ |
| 978 | static bool parseModbusTcpAddress(const QString& tcpAddress, QString& host, quint16& port) |
| 979 | { |
| 980 | const QStringList parts = tcpAddress.split(':'); |
| 981 | if (parts.size() != 1 && parts.size() != 2) |
| 982 | return false; |
| 983 | |
| 984 | host = parts[0]; |
| 985 | port = 502; |
| 986 | if (parts.size() != 2) |
| 987 | return true; |
| 988 | |
| 989 | bool ok = false; |
| 990 | const quint16 p = parts[1].toUInt(&ok); |
| 991 | if (!ok || p == 0) { |
| 992 | qWarning() << "Invalid ModBus TCP port:" << parts[1]; |
| 993 | return true; |
| 994 | } |
| 995 | |
| 996 | port = p; |
| 997 | return true; |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * @brief Configures and connects a Modbus RTU bus from CLI options. |
no test coverage detected