mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2025-12-06 07:42:00 +01:00
fixing APRS-IS lib
This commit is contained in:
parent
00603fe2c3
commit
4a39c5e2f2
|
|
@ -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<APRSMessage> APRS_IS::getAPRSMessage() {
|
|||
line = _client.readStringUntil('\n');
|
||||
}
|
||||
if (line.startsWith("#")) {
|
||||
logPrintlnD(line);
|
||||
return 0;
|
||||
}
|
||||
if (line.length() == 0) {
|
||||
|
|
|
|||
|
|
@ -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<APRSMessage> 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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue