diff --git a/DAPNETGateway.cpp b/DAPNETGateway.cpp index 87a93f2..effb377 100644 --- a/DAPNETGateway.cpp +++ b/DAPNETGateway.cpp @@ -234,7 +234,7 @@ int CDAPNETGateway::run() return 1; } - m_dapnetNetwork = new CDAPNETNetwork(dapnetAddress, dapnetPort, callsign, dapnetAuthKey, VERSION, debug); + m_dapnetNetwork = new CDAPNETNetwork(dapnetAddress, dapnetPort, callsign, dapnetAuthKey, VERSION, false, debug); ret = m_dapnetNetwork->open(); if (!ret) { m_pocsagNetwork->close(); @@ -247,6 +247,8 @@ int CDAPNETGateway::run() return 1; } + LogMessage("Starting DAPNETGateway-%s", VERSION); + ret = m_dapnetNetwork->login(); if (!ret) { m_pocsagNetwork->close(); @@ -260,12 +262,8 @@ int CDAPNETGateway::run() return 1; } - ::LogMessage("Logged into the DAPNET network"); - std::vector whiteList = m_conf.getWhiteList(); - LogMessage("Starting DAPNETGateway-%s", VERSION); - for (;;) { unsigned char buffer[200U]; diff --git a/DAPNETNetwork.cpp b/DAPNETNetwork.cpp index ee54dc1..f54f6a4 100644 --- a/DAPNETNetwork.cpp +++ b/DAPNETNetwork.cpp @@ -29,11 +29,12 @@ const unsigned int BUFFER_LENGTH = 200U; -CDAPNETNetwork::CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool debug) : +CDAPNETNetwork::CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool loggedin, bool debug) : m_socket(address, port), m_callsign(callsign), m_authKey(authKey), m_version(version), +m_loggedin(false), m_debug(debug), m_message(NULL), m_schedule(NULL) @@ -92,6 +93,11 @@ bool CDAPNETNetwork::read() // Error LogWarning("An error has been reported by DAPNET"); } else if (buffer[0U] == '2') { + // First time sync paket indicated successful login + if (!m_loggedin) { + m_loggedin = true; + LogMessage("Logged into the DAPNET network"); + } // Time synchronisation char* p = ::strchr((char*)buffer, '\n'); if (p != NULL) @@ -110,6 +116,9 @@ bool CDAPNETNetwork::read() } else if (buffer[0U] == '4') { // Timeslot information return parseSchedule(buffer); + } else if (buffer[0U] == '7') { + // Login failed + return parseFailedLogin(buffer); } else if (buffer[0U] == '#') { // A message return parseMessage(buffer, length); @@ -250,3 +259,15 @@ bool CDAPNETNetwork::parseSchedule(unsigned char* data) return write((unsigned char*)"+\r\n"); } + +bool CDAPNETNetwork::parseFailedLogin(unsigned char* data) +{ + assert(data != NULL); + + char* p = ::strtok((char*)data + 2U, "\r\n"); + assert(p != NULL); + + LogMessage("Login failed: %s", p); + + return write((unsigned char*)"+\r\n"); +} diff --git a/DAPNETNetwork.h b/DAPNETNetwork.h index a314a67..122bf9a 100644 --- a/DAPNETNetwork.h +++ b/DAPNETNetwork.h @@ -28,7 +28,7 @@ class CDAPNETNetwork { public: - CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool debug); + CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool loggedin, bool debug); ~CDAPNETNetwork(); bool open(); @@ -48,12 +48,14 @@ private: std::string m_callsign; std::string m_authKey; const char* m_version; + bool m_loggedin; bool m_debug; CPOCSAGMessage* m_message; bool* m_schedule; bool parseMessage(unsigned char* data, unsigned int length); bool parseSchedule(unsigned char* data); + bool parseFailedLogin(unsigned char* data); bool write(unsigned char* data); };