diff --git a/lib/APRS-IS/APRS-IS.cpp b/lib/APRS-IS/APRS-IS.cpp index 6988ac9..7863bbf 100644 --- a/lib/APRS-IS/APRS-IS.cpp +++ b/lib/APRS-IS/APRS-IS.cpp @@ -8,34 +8,32 @@ void APRS_IS::setup(const String &user, const String &passcode, const String &to _version = version; } -bool APRS_IS::connect(const String &server, const int port) { +APRS_IS::ConnectionStatus APRS_IS::connect(const String &server, const int port) { const String login = "user " + _user + " pass " + _passcode + " vers " + _tool_name + " " + _version + "\n\r"; return _connect(server, port, login); } -bool APRS_IS::connect(const String &server, const int port, const String &filter) { +APRS_IS::ConnectionStatus APRS_IS::connect(const String &server, const int port, const String &filter) { const String login = "user " + _user + " pass " + _passcode + " vers " + _tool_name + " " + _version + " filter " + filter + "\n\r"; return _connect(server, port, login); } -bool APRS_IS::_connect(const String &server, const int port, const String &login_line) { +APRS_IS::ConnectionStatus APRS_IS::_connect(const String &server, const int port, const String &login_line) { if (!_client.connect(server.c_str(), port)) { - logPrintlnE("Something went wrong on connecting! Is the server reachable?"); - return false; + return ERROR_CONNECTION; } sendMessage(login_line); while (true) { String line = _client.readStringUntil('\n'); if (line.indexOf("logresp") != -1) { if (line.indexOf("unverified") == -1) { - return true; + return SUCCESS; } else { - logPrintlnE("User can not be verified with passcode!"); - return false; + return ERROR_PASSCODE; } } } - return true; + return SUCCESS; } bool APRS_IS::connected() { @@ -76,7 +74,6 @@ std::shared_ptr APRS_IS::getAPRSMessage() { line = _client.readStringUntil('\n'); } if (line.startsWith("#")) { - logPrintlnD(line); return 0; } if (line.length() == 0) { diff --git a/lib/APRS-IS/APRS-IS.h b/lib/APRS-IS/APRS-IS.h index 00d27ca..0aa0691 100644 --- a/lib/APRS-IS/APRS-IS.h +++ b/lib/APRS-IS/APRS-IS.h @@ -9,9 +9,16 @@ class APRS_IS { public: void setup(const String &user, const String &passcode, const String &tool_name, const String &version); - bool connect(const String &server, const int port); - bool connect(const String &server, const int port, const String &filter); - bool connected(); + enum ConnectionStatus + { + SUCCESS, + ERROR_CONNECTION, + ERROR_PASSCODE, + }; + + ConnectionStatus connect(const String &server, const int port); + ConnectionStatus connect(const String &server, const int port, const String &filter); + bool connected(); bool sendMessage(const String &message); bool sendMessage(const std::shared_ptr message); @@ -28,7 +35,7 @@ private: String _version; WiFiClient _client; - bool _connect(const String &server, const int port, const String &login_line); + ConnectionStatus _connect(const String &server, const int port, const String &login_line); }; #endif diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index 8aa80c4..86ef766 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -42,7 +42,13 @@ bool AprsIsTask::loop(System &system) { bool AprsIsTask::connect(System &system) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); - if (!_aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port)) { + APRS_IS::ConnectionStatus status = _aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); + if (status == APRS_IS::ERROR_CONNECTION) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Something went wrong on connecting! Is the server reachable?"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Connection failed."); + return false; + } else if (status == APRS_IS::ERROR_PASSCODE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "User can not be verified with passcode!"); system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Connection failed."); return false; }