From 04841cf0d45677afb0a8f40472ae1cb9a283b028 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Wed, 23 Nov 2022 21:55:52 -0800 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-11303 Signed-off-by: stephb9959 --- build | 2 +- src/APStats.cpp | 33 ++++++++++++++++- src/RESTObjects/RESTAPI_GWobjects.cpp | 53 +++++++++++++++++++++++++++ src/RESTObjects/RESTAPI_GWobjects.h | 27 ++++++++++++++ 4 files changed, 112 insertions(+), 3 deletions(-) diff --git a/build b/build index 3cacc0b..ca7bf83 100644 --- a/build +++ b/build @@ -1 +1 @@ -12 \ No newline at end of file +13 \ No newline at end of file diff --git a/src/APStats.cpp b/src/APStats.cpp index a067d18..d4a1b50 100644 --- a/src/APStats.cpp +++ b/src/APStats.cpp @@ -90,6 +90,13 @@ namespace OpenWifi { return false; } + static int BandToInt(const std::string &band) { + if(band=="2G") return 2; + if(band=="5G") return 5; + if(band=="6G") return 6; + return 2; + } + void AP::UpdateStats(const std::shared_ptr &State) { DI_.states++; DI_.connected =true; @@ -126,7 +133,13 @@ namespace OpenWifi { if (radio.contains("channel")) { AnalyticsObjects::RadioTimePoint RTP; GetJSON("channel", radio, RTP.channel, (uint64_t) 2); - RTP.band = RTP.channel <= 16 ? 2 : 5; + if(radio.contains("band") && radio["band"].is_array()) { + auto BandArray = radio["band"]; + RTP.band = BandToInt(BandArray[0]); + std::cout << "BAND (radio): " << BandToInt(BandArray[0]) << std::endl; + } else { + RTP.band = RTP.channel <= 16 ? 2 : 5; + } radio_map[radio_index++] = std::make_pair(RTP.band, RTP.channel); GetJSON("busy_ms", radio, RTP.busy_ms, (uint64_t) 0); GetJSON("receive_ms", radio, RTP.receive_ms, (uint64_t) 0); @@ -209,7 +222,23 @@ namespace OpenWifi { AnalyticsObjects::SSIDTimePoint SSIDTP; uint radio_location=0; SSIDTP.band = 2; - if(ssid.contains("radio")) { + + if(ssid.contains("band")) { + std::string Band = ssid["band"]; + SSIDTP.band = BandToInt(Band); + std::cout << "BAND (ssid): " << SSIDTP.band << std::endl; + auto radio = ssid["radio"]; + if(radio.contains("$ref")) { + auto ref = radio["$ref"]; + auto radio_parts = Poco::StringTokenizer(ref, "/"); + if(radio_parts.count()==3) { + radio_location = std::strtol(radio_parts[2].c_str(), nullptr, 10); + if(radio_map.find(radio_location)!=radio_map.end()) { + SSIDTP.channel = radio_map[radio_location].second; + } + } + } + } else if(ssid.contains("radio")) { auto radio = ssid["radio"]; if(radio.contains("$ref")) { auto ref = radio["$ref"]; diff --git a/src/RESTObjects/RESTAPI_GWobjects.cpp b/src/RESTObjects/RESTAPI_GWobjects.cpp index 07ed9e1..4f00308 100644 --- a/src/RESTObjects/RESTAPI_GWobjects.cpp +++ b/src/RESTObjects/RESTAPI_GWobjects.cpp @@ -304,6 +304,7 @@ namespace OpenWifi::GWObjects { field_to_json(Obj,"serialNumber",serialNumber); field_to_json(Obj,"timeout",timeout); field_to_json(Obj,"type",type); + field_to_json(Obj,"scriptId",scriptId); field_to_json(Obj,"script",script); field_to_json(Obj,"when",when); field_to_json(Obj,"signature", signature); @@ -317,6 +318,7 @@ namespace OpenWifi::GWObjects { field_from_json(Obj,"timeout",timeout); field_from_json(Obj,"type",type); field_from_json(Obj,"script",script); + field_from_json(Obj,"scriptId",scriptId); field_from_json(Obj,"when",when); field_from_json(Obj,"signature", signature); field_from_json(Obj,"deferred", deferred); @@ -422,5 +424,56 @@ namespace OpenWifi::GWObjects { } return false; } + + void ScriptEntry::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"id", id); + field_to_json(Obj,"name", name); + field_to_json(Obj,"description", description); + field_to_json(Obj,"uri", uri); + field_to_json(Obj,"content", content); + field_to_json(Obj,"version", version); + field_to_json(Obj,"type", type); + field_to_json(Obj,"created", created); + field_to_json(Obj,"modified", modified); + field_to_json(Obj,"author", author); + field_to_json(Obj,"restricted", restricted); + field_to_json(Obj,"deferred", deferred); + field_to_json(Obj,"timeout", timeout); + } + + bool ScriptEntry::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj,"id", id); + field_from_json(Obj,"name", name); + field_from_json(Obj,"description", description); + field_from_json(Obj,"uri", uri); + field_from_json(Obj,"content", content); + field_from_json(Obj,"version", version); + field_from_json(Obj,"type", type); + field_from_json(Obj,"created", created); + field_from_json(Obj,"modified", modified); + field_from_json(Obj,"author", author); + field_from_json(Obj,"restricted", restricted); + field_from_json(Obj,"deferred", deferred); + field_from_json(Obj,"timeout", timeout); + return true; + } catch (const Poco::Exception &E) { + } + return false; + } + + void ScriptEntryList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"scripts",scripts); + } + + bool ScriptEntryList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj,"scripts",scripts); + return true; + } catch (const Poco::Exception &E) { + } + return false; + } + } diff --git a/src/RESTObjects/RESTAPI_GWobjects.h b/src/RESTObjects/RESTAPI_GWobjects.h index 8e53bd6..1f18171 100644 --- a/src/RESTObjects/RESTAPI_GWobjects.h +++ b/src/RESTObjects/RESTAPI_GWobjects.h @@ -216,11 +216,38 @@ namespace OpenWifi::GWObjects { void to_json(Poco::JSON::Object &Obj) const; }; + struct ScriptEntry { + std::string id; + std::string name; + std::string description; + std::string uri; + std::string content; + std::string version; + std::string type; + std::uint64_t created; + std::uint64_t modified; + std::string author; + Types::StringVec restricted; + bool deferred=false; + std::uint64_t timeout=30; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct ScriptEntryList { + std::vector scripts; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + struct ScriptRequest { std::string serialNumber; uint64_t timeout=30; std::string type; std::string script; + std::string scriptId; std::uint64_t when; std::string signature; bool deferred;