Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-12945
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Sep 23, 2023
1 parent 5a3ce59 commit c5737de
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
string(REGEX REPLACE "\n$" "" GIT_HASH "${GIT_HASH}")
endif()

add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT)
add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT -DBOOST_NO_CXX98_FUNCTION_BASE=1)

find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
Expand Down
88 changes: 43 additions & 45 deletions src/AutoDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ namespace OpenWifi {
poco_information(Logger(), "Stopped...");
};

void AutoDiscovery::ProcessPing(const Poco::JSON::Object::Ptr & P, std::string &FW, std::string &SN,
std::string &Compat, std::string &Conn, std::string &locale) {
if (P->has(uCentralProtocol::CONNECTIONIP))
Conn = P->get(uCentralProtocol::CONNECTIONIP).toString();
if (P->has(uCentralProtocol::FIRMWARE))
FW = P->get(uCentralProtocol::FIRMWARE).toString();
if (P->has(uCentralProtocol::SERIALNUMBER))
SN = P->get(uCentralProtocol::SERIALNUMBER).toString();
if (P->has(uCentralProtocol::COMPATIBLE))
Compat = P->get(uCentralProtocol::COMPATIBLE).toString();
if (P->has("locale")) {
locale = P->get("locale").toString();
}
}

void AutoDiscovery::ProcessConnect(const Poco::JSON::Object::Ptr &P, std::string &FW, std::string &SN,
std::string &Compat, std::string &Conn, std::string &locale) {
if (P->has(uCentralProtocol::CONNECTIONIP))
Conn = P->get(uCentralProtocol::CONNECTIONIP).toString();
if (P->has(uCentralProtocol::FIRMWARE))
FW = P->get(uCentralProtocol::FIRMWARE).toString();
if (P->has(uCentralProtocol::SERIALNUMBER))
SN = P->get(uCentralProtocol::SERIALNUMBER).toString();
if (P->has("locale")) {
locale = P->get("locale").toString();
}
if(P->has(uCentralProtocol::CAPABILITIES)) {
auto CapObj = P->getObject(uCentralProtocol::CAPABILITIES);
if (CapObj->has(uCentralProtocol::COMPATIBLE))
Compat = CapObj->get(uCentralProtocol::COMPATIBLE).toString();
}
}

void AutoDiscovery::run() {
Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification());
Utils::SetThreadName("auto-discovery");
Expand All @@ -47,53 +80,18 @@ namespace OpenWifi {
if (Object->has(uCentralProtocol::PAYLOAD)) {
DBGLINE
auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD);
if (PayloadObj->has("ping")) {
std::string ConnectedIP, SerialNumber, Compatible, Firmware, Locale ;
if (PayloadObj->has(uCentralProtocol::PING)) {
auto PingObj = PayloadObj->getObject("ping");
std::string ConnectedIP, SerialNumber, DeviceType;
DBGLINE
if (PayloadObj->has(uCentralProtocol::CONNECTIONIP))
DBGLINE
ConnectedIP =
PayloadObj->get(uCentralProtocol::CONNECTIONIP).toString();
if (PayloadObj->has(uCentralProtocol::CAPABILITIES)) {
DBGLINE
auto CapObj = PayloadObj->getObject(uCentralProtocol::CAPABILITIES);
if (CapObj->has(uCentralProtocol::COMPATIBLE)) {
DBGLINE
DeviceType = CapObj->get(uCentralProtocol::COMPATIBLE).toString();
SerialNumber = PayloadObj->get(uCentralProtocol::SERIAL).toString();
DBGLINE
}
} else if (PayloadObj->has(uCentralProtocol::PING)) {
DBGLINE
auto PingMessage = PayloadObj->getObject(uCentralProtocol::PING);
DBGLINE
if (PingMessage->has(uCentralProtocol::FIRMWARE) &&
PingMessage->has(uCentralProtocol::SERIALNUMBER) &&
PingMessage->has(uCentralProtocol::COMPATIBLE)) {
if (PingMessage->has(uCentralProtocol::CONNECTIONIP))
ConnectedIP =
PingMessage->get(uCentralProtocol::CONNECTIONIP).toString();
SerialNumber =
PingMessage->get(uCentralProtocol::SERIALNUMBER).toString();
DeviceType =
PingMessage->get(uCentralProtocol::COMPATIBLE).toString();
DBGLINE
}
DBGLINE
}
std::string Locale;
if (PayloadObj->has("locale")) {
DBGLINE
Locale = PayloadObj->get("locale").toString();
DBGLINE
}
ProcessPing(PingObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale);
} else if(PayloadObj->has("capabilities")) {
ProcessConnect(PayloadObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale);
}

if (!SerialNumber.empty()) {
DBGLINE
StorageService()->InventoryDB().CreateFromConnection(
SerialNumber, ConnectedIP, DeviceType, Locale);
}
if (!SerialNumber.empty()) {
DBGLINE
StorageService()->InventoryDB().CreateFromConnection(
SerialNumber, ConnectedIP, Compatible, Locale);
}
}
} catch (const Poco::Exception &E) {
Expand Down
8 changes: 7 additions & 1 deletion src/AutoDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "Poco/Notification.h"
#include "Poco/NotificationQueue.h"
#include "Poco/JSON/Object.h"

namespace OpenWifi {

Expand Down Expand Up @@ -46,7 +47,12 @@ namespace OpenWifi {
Poco::Thread Worker_;
std::atomic_bool Running_ = false;

AutoDiscovery() noexcept
void ProcessPing(const Poco::JSON::Object::Ptr & P, std::string &FW, std::string &SN,
std::string &Compat, std::string &Conn, std::string &locale) ;
void ProcessConnect(const Poco::JSON::Object::Ptr & P, std::string &FW, std::string &SN,
std::string &Compat, std::string &Conn, std::string &locale) ;

AutoDiscovery() noexcept
: SubSystemServer("AutoDiscovery", "AUTO-DISCOVERY", "discovery") {}
};

Expand Down

0 comments on commit c5737de

Please sign in to comment.