diff options
author | Harsh Sharma <harsh.sharma@multitech.com> | 2020-01-15 17:05:44 -0600 |
---|---|---|
committer | Harsh Sharma <harsh.sharma@multitech.com> | 2020-01-15 17:05:44 -0600 |
commit | 6516d0bbfc4217e3f1204ce07334e709e91b7bb6 (patch) | |
tree | 30320485d1f45238f5229addbd901f33b3f53cf6 /src/Device | |
parent | acb6f2db223487f2a80d7733ce91c735ff50302e (diff) | |
download | mts-io-sysfs-6516d0bbfc4217e3f1204ce07334e709e91b7bb6.tar.gz mts-io-sysfs-6516d0bbfc4217e3f1204ce07334e709e91b7bb6.tar.bz2 mts-io-sysfs-6516d0bbfc4217e3f1204ce07334e709e91b7bb6.zip |
Added port to accessory card list. Added sorting for accessory card array if the array is longer than 1
Diffstat (limited to 'src/Device')
-rw-r--r-- | src/Device/Device.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp index 4e449ab..e182b20 100644 --- a/src/Device/Device.cpp +++ b/src/Device/Device.cpp @@ -47,6 +47,17 @@ bool Device::isAccessoryCard(const char * d_name, const char * dir_name) { return std::binary_search(apIdentifiers.begin(), apIdentifiers.end(), dir_name) && !regex_match(d_name, apFilters); } +void Device::sortAccessoryCards() { + rapidjson::SizeType i, j; + for (i = 0; i < accessoryCards.Size() - 1; i++) { + for (j = 0; j < accessoryCards.Size() - i - 1; j++) { + if (accessoryCards[j]["port"].GetString() < accessoryCards[j+1]["port"].GetString()) { + accessoryCards[j].Swap( accessoryCards[j+1]); + } + } + } +} + bool Device::isValidDirectory(const struct dirent * entry, std::string fullPath, const char * d_name) { std::string path = fullPath + "/" + std::string(d_name); return (entry->d_type & DT_DIR) && strcmp (d_name, "..") != 0 && strcmp (d_name, ".") != 0 && (path.length() < PATH_MAX); @@ -85,9 +96,9 @@ void Device::getSystemTreeJson(const char * dir_name) { } else if (regex_match(fileData, lora15Filters)) { Lora15Card lora15(*this, fileData, dir_name); } else if (regex_match(fileData, gpiobFilters)) { - Gpiob ppiob(*this); + Gpiob ppiob(*this, fileData, dir_name); } else if (regex_match(fileData, mfserFilters)) { - Mfser msfer(*this, dir_name); + Mfser msfer(*this, fileData, dir_name); } } accessoryCard.AddMember(rapidjson::Value().SetString(toCamelCase(d_name).c_str(), accessoryCardsAlloc), rapidjson::Value().SetString(fileData.c_str(), accessoryCardsAlloc), accessoryCardsAlloc); @@ -143,7 +154,11 @@ void Device::load() { getSystemTreeJson(""); if (!accessoryCard.IsNull()) { accessoryCards.PushBack(accessoryCard, accessoryCardsAlloc); + if (accessoryCards.Size() > 1) { + sortAccessoryCards(); + } } + mapFileToCapability(); mapFirmware(); for (const auto capability : capabilityList) { |