summaryrefslogtreecommitdiff
path: root/src/Device/Device.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Device/Device.cpp')
-rw-r--r--src/Device/Device.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index d367284..ee8ba83 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -34,6 +34,8 @@ std::map<std::string, bool> Device::capabilityList = {{"adc", false},{"battery",
{"nodeRed", false},{"rs232", false},{"rs422", false},{"rs485", false},{"serial", false},
{"supercap", false},{"wifi", false}};
+std::map<std::string, std::string> Device::ethSwitchList;
+
std::map<std::string, std::string> Device::deviceInfoList = {{"deviceId", ""},{"hardwareVersion", ""},
{"imei", ""},{"macAddress", "00:00:00:00:00:00"},{"macBluetooth", "00:00:00:00:00:00"},
{"macWifi", "00:00:00:00:00:00"},{"productId", ""},{"uuid", ""},{"vendorId", ""}};
@@ -106,6 +108,8 @@ void Device::getSystemTreeJson(const char * dir_name) {
accessoryCard.AddMember(rapidjson::Value().SetString(toCamelCase(d_name).c_str(), accessoryCardsAlloc), rapidjson::Value().SetString(fileData.c_str(), accessoryCardsAlloc), accessoryCardsAlloc);
} else if (strcmp (dir_name, "capability") == 0 && fileData == "1") {
capabilityList[toCamelCase(d_name)] = true;
+ } else if (strcmp (dir_name, "eth-switch") == 0) {
+ ethSwitchList[toCamelCase(d_name)] = fileData;
}
} else if ((entry->d_type != DT_LNK)){
if (deviceInfoList.count(toCamelCase(d_name)) > 0) {
@@ -152,6 +156,7 @@ void Device::json() {
void Device::load() {
deviceInfo.SetObject();
capabilities.SetObject();
+ ethSwitch.SetObject();
accessoryCards.SetArray();
getSystemTreeJson("");
if (!accessoryCard.IsNull()) {
@@ -168,6 +173,41 @@ void Device::load() {
capabilities.AddMember(rapidjson::Value().SetString(capability.first.c_str(),
capability.first.length(), accessoryCardsAlloc), capability.second, accessoryCardsAlloc);
}
+
+ if (ethSwitchList.count("chip") && ethSwitchList.count("numPorts")) {
+ auto& ethSwitchAlloc = ethSwitch.GetAllocator();
+ const std::string& chip = ethSwitchList.at("chip");
+ ethSwitch.AddMember("chip",
+ rapidjson::Value().SetString(chip.c_str(), chip.length(), ethSwitchAlloc),
+ ethSwitchAlloc);
+ rapidjson::Value ports;
+ ports.SetObject();
+ for (int i=0; i < std::stoi(ethSwitchList.at("numPorts")); ++i) {
+ const std::string num = std::to_string(i);
+ const std::string keyLabel = "port" + num + "Label";
+ const std::string keyId = "port" + num + "Id";
+ const std::string keyMac = "port" + num + "Mac";;
+ if (ethSwitchList.count(keyLabel) &&
+ ethSwitchList.count(keyId) &&
+ ethSwitchList.count(keyMac)) {
+ rapidjson::Value port;
+ port.SetObject();
+ port.AddMember("id", rapidjson::Value().SetInt(std::stoi(ethSwitchList.at(keyId))), ethSwitchAlloc);
+ port.AddMember("mac",
+ rapidjson::Value().SetString(ethSwitchList.at(keyMac).c_str(),
+ ethSwitchList.at(keyMac).length(),
+ ethSwitchAlloc),
+ ethSwitchAlloc);
+ ports.AddMember(rapidjson::Value().SetString(ethSwitchList.at(keyLabel).c_str(),
+ ethSwitchList.at(keyLabel).length(),
+ ethSwitchAlloc),
+ std::move(port),
+ ethSwitchAlloc);
+ }
+ }
+ ethSwitch.AddMember("ports", std::move(ports), ethSwitchAlloc);
+ }
+
for (const auto device : deviceInfoList) {
deviceInfo.AddMember(rapidjson::Value().SetString(device.first.c_str(),
device.first.length(), alloc), rapidjson::Value().SetString(device.second.c_str(),
@@ -175,6 +215,7 @@ void Device::load() {
}
deviceInfo.AddMember("capabilities", capabilities, alloc);
+ deviceInfo.AddMember("ethSwitch", ethSwitch, alloc);
deviceInfo.AddMember("accessoryCards", accessoryCards, alloc);
}