summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-01-15 17:05:44 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-01-15 17:05:44 -0600
commit6516d0bbfc4217e3f1204ce07334e709e91b7bb6 (patch)
tree30320485d1f45238f5229addbd901f33b3f53cf6
parentacb6f2db223487f2a80d7733ce91c735ff50302e (diff)
downloadmts-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
-rw-r--r--include/Device/Device.h17
-rw-r--r--src/AccessoryCards/AcessoryCard.cpp3
-rw-r--r--src/AccessoryCards/Gpiob.cpp2
-rw-r--r--src/AccessoryCards/LoraCard.cpp6
-rw-r--r--src/AccessoryCards/LoraCard15.cpp2
-rw-r--r--src/AccessoryCards/LoraCard21.cpp2
-rw-r--r--src/AccessoryCards/LoraCard21Ext.cpp2
-rw-r--r--src/AccessoryCards/Mfser.cpp3
-rw-r--r--src/Device/Device.cpp19
-rw-r--r--src/Version.cpp2
10 files changed, 37 insertions, 21 deletions
diff --git a/include/Device/Device.h b/include/Device/Device.h
index ee75285..db45316 100644
--- a/include/Device/Device.h
+++ b/include/Device/Device.h
@@ -32,8 +32,10 @@ class Device {
class AccessoryCard {
protected:
Device& device;
+ const std::string productId;
+ const std::string port;
public:
- AccessoryCard(Device& d);
+ AccessoryCard(Device& d, const std::string ProductId, const std::string Port);
};
class LoraCard : public AccessoryCard {
@@ -41,7 +43,7 @@ class Device {
std::string spiPath;
uint8_t fpgaVersion = 255;
public:
- LoraCard(Device& d, const std::string productId, const std::string port);
+ LoraCard(Device& d, const std::string ProductId, const std::string Port);
void setCapabilities();
};
@@ -49,7 +51,7 @@ class Device {
private:
void *spi_target_ptr = NULL;
public:
- Lora15Card(Device& d, const std::string productId, const std::string port);
+ Lora15Card(Device& d, const std::string ProductId, const std::string Port);
int spiOpen(const char *spidev);
int spiRead(uint8_t address, uint8_t *data);
int spiClose();
@@ -59,24 +61,24 @@ class Device {
private:
std::string cmdFpgaVersion;
public:
- Lora21Card(Device& d, const std::string productId, const std::string port);
+ Lora21Card(Device& d, const std::string ProductId, const std::string Port);
};
class Lora21ExtCard : public Lora21Card {
private:
std::string cmdFpgaVersion2;
public:
- Lora21ExtCard(Device& d, const std::string productId, const std::string port);
+ Lora21ExtCard(Device& d, const std::string ProductId, const std::string Port);
};
class Gpiob : public AccessoryCard {
public:
- Gpiob(Device& d);
+ Gpiob(Device& d, const std::string ProductId, const std::string Port);
};
class Mfser : public AccessoryCard {
public:
- Mfser(Device& d, const std::string port);
+ Mfser(Device& d, const std::string ProductId, const std::string Port);
};
public:
@@ -97,6 +99,7 @@ class Device {
void printUsage(std::string program);
void show(std::string program);
void showTrigger(std::string name);
+ void sortAccessoryCards();
void store(std::string name, std::string value);
void storeTrigger(std::string name, std::string value);
void Verbose(bool val);
diff --git a/src/AccessoryCards/AcessoryCard.cpp b/src/AccessoryCards/AcessoryCard.cpp
index 16589b0..c4804d1 100644
--- a/src/AccessoryCards/AcessoryCard.cpp
+++ b/src/AccessoryCards/AcessoryCard.cpp
@@ -17,5 +17,6 @@
#include "Device.h"
-Device::AccessoryCard::AccessoryCard(Device& d) : device(d) {
+Device::AccessoryCard::AccessoryCard(Device& d, const std::string ProductId, const std::string Port) : device(d), productId(ProductId), port(Port) {
+ device.accessoryCard.AddMember("port", rapidjson::Value().SetString(port.c_str(), device.accessoryCardsAlloc), device.accessoryCardsAlloc);
}
diff --git a/src/AccessoryCards/Gpiob.cpp b/src/AccessoryCards/Gpiob.cpp
index 3a87c8a..44728ae 100644
--- a/src/AccessoryCards/Gpiob.cpp
+++ b/src/AccessoryCards/Gpiob.cpp
@@ -17,7 +17,7 @@
#include "Device.h"
-Device::Gpiob::Gpiob(Device& d) : AccessoryCard(d) {
+Device::Gpiob::Gpiob(Device& d, const std::string ProductId, const std::string Port) : AccessoryCard(d, ProductId, Port) {
capabilityList["adc"] = true;
capabilityList["din"] = true;
capabilityList["dout"] = true;
diff --git a/src/AccessoryCards/LoraCard.cpp b/src/AccessoryCards/LoraCard.cpp
index 66047f3..7a248dc 100644
--- a/src/AccessoryCards/LoraCard.cpp
+++ b/src/AccessoryCards/LoraCard.cpp
@@ -17,12 +17,10 @@
#include "Device.h"
-Device::LoraCard::LoraCard(Device& d, const std::string productId, const std::string port) : AccessoryCard(d) {
- spiPath = "/dev/spidev0.0";
-}
+Device::LoraCard::LoraCard(Device& d, const std::string ProductId, const std::string Port) : AccessoryCard(d, ProductId, Port), spiPath("/dev/spidev0.0") {}
void Device::LoraCard::setCapabilities() {
device.capabilityList["lora"] = true;
- device.accessoryCard.AddMember("spiPath", rapidjson::Value().SetString(spiPath.c_str(), device.accessoryCardsAlloc), device.accessoryCardsAlloc);
device.accessoryCard.AddMember("fpgaVersion", fpgaVersion, device.accessoryCardsAlloc);
+ device.accessoryCard.AddMember("spiPath", rapidjson::Value().SetString(spiPath.c_str(), device.accessoryCardsAlloc), device.accessoryCardsAlloc);
} \ No newline at end of file
diff --git a/src/AccessoryCards/LoraCard15.cpp b/src/AccessoryCards/LoraCard15.cpp
index 28f1e5d..69efb6b 100644
--- a/src/AccessoryCards/LoraCard15.cpp
+++ b/src/AccessoryCards/LoraCard15.cpp
@@ -17,7 +17,7 @@
#include "Device.h"
-Device::Lora15Card::Lora15Card(Device& d, const std::string productId, const std::string port) : LoraCard(d, productId, port) {
+Device::Lora15Card::Lora15Card(Device& d, const std::string ProductId, const std::string Port) : LoraCard(d, ProductId, Port) {
int ret;
if ((productId.rfind("MTCDT3-", 0) == 0 || productId.rfind("MTLGA-", 0) == 0) && (port.back() == '2')) {
spiPath = "/dev/spidev1.0";
diff --git a/src/AccessoryCards/LoraCard21.cpp b/src/AccessoryCards/LoraCard21.cpp
index 99f76d6..d40876b 100644
--- a/src/AccessoryCards/LoraCard21.cpp
+++ b/src/AccessoryCards/LoraCard21.cpp
@@ -17,7 +17,7 @@
#include "Device.h"
-Device::Lora21Card::Lora21Card(Device& d, const std::string productId, const std::string port): LoraCard(d, productId, port) {
+Device::Lora21Card::Lora21Card(Device& d, const std::string ProductId, const std::string Port): LoraCard(d, ProductId, Port) {
spiPath = "/dev/spidev32766.2";
MTS::System::cmd(LORA_2_1_FPGA_VERSION, cmdFpgaVersion);
fpgaVersion = std::stoi(cmdFpgaVersion);
diff --git a/src/AccessoryCards/LoraCard21Ext.cpp b/src/AccessoryCards/LoraCard21Ext.cpp
index 51b43f7..2595286 100644
--- a/src/AccessoryCards/LoraCard21Ext.cpp
+++ b/src/AccessoryCards/LoraCard21Ext.cpp
@@ -17,7 +17,7 @@
#include "Device.h"
-Device::Lora21ExtCard::Lora21ExtCard(Device& d, const std::string productId, const std::string port): Lora21Card(d, productId, port) {
+Device::Lora21ExtCard::Lora21ExtCard(Device& d, const std::string ProductId, const std::string Port): Lora21Card(d, ProductId, Port) {
MTS::System::cmd(LORA_2_1_EXT_FPGA_VERSION, cmdFpgaVersion2);
device.accessoryCard.AddMember("fpgaVersion2", std::stoi(cmdFpgaVersion2), device.accessoryCardsAlloc);
} \ No newline at end of file
diff --git a/src/AccessoryCards/Mfser.cpp b/src/AccessoryCards/Mfser.cpp
index ac6bb26..dfdfeb3 100644
--- a/src/AccessoryCards/Mfser.cpp
+++ b/src/AccessoryCards/Mfser.cpp
@@ -16,8 +16,7 @@
***********************************************************************/
#include "Device.h"
-
-Device::Mfser::Mfser(Device& d, const std::string port) : AccessoryCard(d) {
+Device::Mfser::Mfser(Device& d, const std::string ProductId, const std::string Port) : AccessoryCard(d, ProductId, Port) {
capabilityList["rs232"] = true;
capabilityList["rs422"] = true;
capabilityList["rs485"] = true;
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) {
diff --git a/src/Version.cpp b/src/Version.cpp
index 3e07a6a..1baaf5c 100644
--- a/src/Version.cpp
+++ b/src/Version.cpp
@@ -1,4 +1,4 @@
//Pre-Build Auto-Generated Source
#include "Version.h"
-const std::string Version::version("v1.0.0-12-g03299da");
+const std::string Version::version("v1.0.0-13-gacb6f2d");