summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-01-02 15:37:04 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-01-02 15:37:04 -0600
commit50a0344597edd0f4ae90ebee2fdf4e3160c572c8 (patch)
tree569d7242c0a77f226c93bb42faab32da19535896 /src
parent92bd4453f1db67a5250afb6316afe8c3fc2f36b3 (diff)
downloadmts-io-sysfs-50a0344597edd0f4ae90ebee2fdf4e3160c572c8.tar.gz
mts-io-sysfs-50a0344597edd0f4ae90ebee2fdf4e3160c572c8.tar.bz2
mts-io-sysfs-50a0344597edd0f4ae90ebee2fdf4e3160c572c8.zip
Added capability radio retry with a retry count and sleep timer
Diffstat (limited to 'src')
-rw-r--r--src/Device/Device.cpp46
-rw-r--r--src/MtsIoSysfs.cpp10
-rw-r--r--src/Version.cpp2
3 files changed, 44 insertions, 14 deletions
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index 7cfd285..b5c11e4 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -30,6 +30,9 @@ const std::regex Device::showFilters("(modalias)|(subsystem)|(uevent)");
Device::Device() {
isRoot = !getuid();
+ hasRadio = false;
+ verbose = false;
+ radioTryCount = 30;
}
void Device::exitHandler(int code) {
@@ -83,20 +86,20 @@ void Device::getSystemTreeJson(const char * dir_name) {
capabilityList["lora"] = true;
AccessoryCardLora15 mSPI(fileData, dir_name);
mSPI.getFPGAVersion();
- accessoryCard.AddMember("loraFpgaVersion", mSPI.getFPGAVersion(), accessoryCardsAlloc);
+ accessoryCard.AddMember("fpgaVersion", mSPI.getFPGAVersion(), accessoryCardsAlloc);
} else if (regex_match(fileData, loraG16Filters)) {
capabilityList["lora"] = true;
std::string fpgaVersion;
MTS::System::cmd(LORA_2_1_FPGA_VERSION, fpgaVersion);
- accessoryCard.AddMember("loraFpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
+ accessoryCard.AddMember("fpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
} else if (regex_match(fileData, loraG64Filters)) {
capabilityList["lora"] = true;
std::string fpgaVersion;
std::string fpgaVersion2;
MTS::System::cmd(LORA_2_1_FPGA_VERSION, fpgaVersion);
MTS::System::cmd(LORA_2_1_EXT_FPGA_VERSION, fpgaVersion2);
- accessoryCard.AddMember("loraFpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
- accessoryCard.AddMember("loraFpgaVersion2", std::stoi(fpgaVersion2), accessoryCardsAlloc);
+ accessoryCard.AddMember("fpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
+ accessoryCard.AddMember("fpgaVersion2", std::stoi(fpgaVersion2), accessoryCardsAlloc);
} else if (regex_match(fileData, gpiobFilters)) {
capabilityList["adc"] = true;
capabilityList["din"] = true;
@@ -124,6 +127,8 @@ void Device::getSystemTreeJson(const char * dir_name) {
deviceInfoList["hardwareVersion"] = fileData;
} else if (strcmp(d_name, "mac-eth") == 0) {
deviceInfoList["macAddress"] = fileData;
+ } else if (strcmp(d_name, "has-radio") == 0 && fileData == "1") {
+ hasRadio = true;
}
}
}
@@ -199,8 +204,20 @@ void Device::logInfo(std::string info) {
}
void Device::mapFileToCapability() {
- if (fileType("/dev/modem_at0") == S_IFLNK && fileType("/dev/modem_at1") == S_IFLNK) { /* Cellular module symlink */
- capabilityList["cell"] = true;
+ if (fileType("/opt/node-red") == S_IFDIR) { /* node-red is a directory */
+ capabilityList["nodeRed"] = true;
+ }
+ if (fileType("/opt/lora/lora-network-server") == S_IFREG) { /* lora-network-server is a regular file */
+ capabilityList["loraNetworkServer"] = true;
+ }
+ if (hasRadio) {
+ for (uint8_t i = 0; i < radioTryCount; i++) {
+ if (fileType("/dev/modem_at0") == S_IFLNK && fileType("/dev/modem_at1") == S_IFLNK) { /* Cellular module symlink */
+ capabilityList["cell"] = true;
+ break;
+ }
+ sleep(0.5);
+ }
}
if (fileType("/dev/cdc-wdm0") == S_IFCHR) { /* Cellular modem is wwan/qmi character device */
capabilityList["cellWwan"] = true;
@@ -208,12 +225,6 @@ void Device::mapFileToCapability() {
if (fileType("/dev/ext_serial") == S_IFCHR) { /* ext_serial is a character device */
capabilityList["externalSerialPort"] = true;
}
- if (fileType("/opt/node-red") == S_IFDIR) { /* node-red is a directory */
- capabilityList["nodeRed"] = true;
- }
- if (fileType("/opt/lora/lora-network-server") == S_IFREG) { /* lora-network-server is a regular file */
- capabilityList["loraNetworkServer"] = true;
- }
}
void Device::mapFirmware() {
@@ -398,7 +409,8 @@ std::string Device::toCamelCase(const char * d_name) {
return camelString;
}
-void Device::Verbose(bool val) {
+
+void Device::Verbose(const bool val) {
verbose = val;
}
@@ -406,6 +418,14 @@ bool Device::Verbose() {
return verbose;
}
+void Device::RadioTryCount(const uint8_t val) {
+ radioTryCount = val;
+}
+
+uint8_t Device::RadioTryCount() {
+ return radioTryCount;
+}
+
void Device::writeJson() {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
diff --git a/src/MtsIoSysfs.cpp b/src/MtsIoSysfs.cpp
index 0c9dc2e..98c0108 100644
--- a/src/MtsIoSysfs.cpp
+++ b/src/MtsIoSysfs.cpp
@@ -32,6 +32,16 @@ int main(int argc, char const* const argv[]) {
m.printUsage(argv[0]);
} else if (parameter == "-verbose") {
m.Verbose(true);
+ } else if (parameter == "-t") {
+ if (argv[i + 1] && std::isdigit(argv[i + 1][0])) {
+ m.RadioTryCount(std::atoi(argv[i + 1]));
+ } else {
+ m.logError(std::string(argv[0]) + "[init -t TRY_COUNT]");
+ m.logError(" Where TRY_COUNT is the number of half");
+ m.logError(" second waits for the cellular radio");
+ m.logError(" to be ready for identification");
+ m.exitHandler(1);
+ }
}
}
}
diff --git a/src/Version.cpp b/src/Version.cpp
index 54fe215..de88c98 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-1-g41f2282");
+const std::string Version::version("v1.0.0-3-g92bd445");