summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-01-06 13:06:41 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-01-06 13:06:41 -0600
commit68c0c5ed8ad7c733743de1afc5deb9de862d60f3 (patch)
tree317b59f77c0a9ce117f65debec3f3b8ebdce2a86
parent50a0344597edd0f4ae90ebee2fdf4e3160c572c8 (diff)
downloadmts-io-sysfs-68c0c5ed8ad7c733743de1afc5deb9de862d60f3.tar.gz
mts-io-sysfs-68c0c5ed8ad7c733743de1afc5deb9de862d60f3.tar.bz2
mts-io-sysfs-68c0c5ed8ad7c733743de1afc5deb9de862d60f3.zip
Changed radio capability to be based on has_radio file
-rw-r--r--include/Device/Device.h9
-rw-r--r--include/General.h2
-rw-r--r--src/Device/Device.cpp96
-rw-r--r--src/MtsIoSysfs.cpp10
-rw-r--r--src/Version.cpp2
5 files changed, 55 insertions, 64 deletions
diff --git a/include/Device/Device.h b/include/Device/Device.h
index b7cbeaf..946221b 100644
--- a/include/Device/Device.h
+++ b/include/Device/Device.h
@@ -7,9 +7,7 @@
class Device {
private:
- bool hasRadio;
bool verbose ;
- uint8_t radioTryCount;
bool isRoot;
rapidjson::Document capabilities;
rapidjson::Document deviceInfo;
@@ -55,6 +53,11 @@ class Device {
void printJson();
void printVersion (std::string name);
void printUsage(std::string program);
+ void setupLora15(std::string fileData, const char * dir_name);
+ void setupLoraG16(std::string fileData, const char * dir_name);
+ void setupLoraG64(std::string fileData, const char * dir_name);
+ void setupGpiob(std::string fileData, const char * dir_name);
+ void setupMfser(std::string fileData, const char * dir_name);
void show(std::string program);
void showTrigger(std::string name);
void store(std::string name, std::string value);
@@ -62,8 +65,6 @@ class Device {
std::string toCamelCase(const char * d_name);
void Verbose(bool val);
bool Verbose();
- void RadioTryCount(uint8_t val);
- uint8_t RadioTryCount();
void writeJson();
};
diff --git a/include/General.h b/include/General.h
index 81f5a3d..2ca729a 100644
--- a/include/General.h
+++ b/include/General.h
@@ -67,7 +67,7 @@ typedef unsigned int uint; //32 bit - even on 64 bit machines
#define READ_ACCESS 0x00
#define SPI_SPEED 8000000
-#define DEVICE_INFO_FILE "/var/run/config/device_info.json"
+#define DEVICE_INFO_FILE "/var/run/config/device_info.json"
#define RESET_SHORT_CMD "reset_short_handler"
#define RESET_LONG_CMD "reset_long_handler"
#define KILL_SIGNAL "kill -l "
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index b5c11e4..0083ff3 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -30,9 +30,7 @@ const std::regex Device::showFilters("(modalias)|(subsystem)|(uevent)");
Device::Device() {
isRoot = !getuid();
- hasRadio = false;
verbose = false;
- radioTryCount = 30;
}
void Device::exitHandler(int code) {
@@ -83,37 +81,15 @@ void Device::getSystemTreeJson(const char * dir_name) {
}
if (strcmp(d_name, "product-id") == 0) {
if (regex_match(fileData, lora15Filters)) {
- capabilityList["lora"] = true;
- AccessoryCardLora15 mSPI(fileData, dir_name);
- mSPI.getFPGAVersion();
- accessoryCard.AddMember("fpgaVersion", mSPI.getFPGAVersion(), accessoryCardsAlloc);
+ setupLora15(fileData, dir_name);
} else if (regex_match(fileData, loraG16Filters)) {
- capabilityList["lora"] = true;
- std::string fpgaVersion;
- MTS::System::cmd(LORA_2_1_FPGA_VERSION, fpgaVersion);
- accessoryCard.AddMember("fpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
+ setupLoraG16(fileData, dir_name);
} 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("fpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
- accessoryCard.AddMember("fpgaVersion2", std::stoi(fpgaVersion2), accessoryCardsAlloc);
+ setupLoraG64(fileData, dir_name);
} else if (regex_match(fileData, gpiobFilters)) {
- capabilityList["adc"] = true;
- capabilityList["din"] = true;
- capabilityList["dout"] = true;
- capabilityList["gpio"] = true;
+ setupGpiob(fileData, dir_name);
} else if (regex_match(fileData, mfserFilters)) {
- capabilityList["rs232"] = true;
- capabilityList["rs422"] = true;
- capabilityList["rs485"] = true;
- capabilityList["serial"] = true;
- if (!fileExists("/dev/ext_serial") && strlen(dir_name) > 0) {
- std::string temp;
- MTS::System::cmd("ln -s /dev/ttyAP" + std::string(dir_name + strlen(dir_name) - 1) + " /dev/ext_serial", temp);
- }
+ setupMfser(fileData, dir_name);
}
}
accessoryCard.AddMember(rapidjson::Value().SetString(toCamelCase(d_name).c_str(), accessoryCardsAlloc), rapidjson::Value().SetString(fileData.c_str(), accessoryCardsAlloc), accessoryCardsAlloc);
@@ -128,7 +104,7 @@ void Device::getSystemTreeJson(const char * dir_name) {
} else if (strcmp(d_name, "mac-eth") == 0) {
deviceInfoList["macAddress"] = fileData;
} else if (strcmp(d_name, "has-radio") == 0 && fileData == "1") {
- hasRadio = true;
+ capabilityList["cell"] = true;
}
}
}
@@ -210,15 +186,6 @@ void Device::mapFileToCapability() {
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;
}
@@ -334,6 +301,48 @@ void Device::printUsage(std::string program) {
exitHandler(1);
}
+void Device::setupLora15(std::string fileData, const char * dir_name) {
+ capabilityList["lora"] = true;
+ AccessoryCardLora15 mSPI(fileData, dir_name);
+ mSPI.getFPGAVersion();
+ accessoryCard.AddMember("fpgaVersion", mSPI.getFPGAVersion(), accessoryCardsAlloc);
+}
+
+void Device::setupLoraG16(std::string fileData, const char * dir_name) {
+ capabilityList["lora"] = true;
+ std::string fpgaVersion;
+ MTS::System::cmd(LORA_2_1_FPGA_VERSION, fpgaVersion);
+ accessoryCard.AddMember("fpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
+}
+
+void Device::setupLoraG64(std::string fileData, const char * dir_name) {
+ 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("fpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
+ accessoryCard.AddMember("fpgaVersion2", std::stoi(fpgaVersion2), accessoryCardsAlloc);
+}
+
+void Device::setupGpiob(std::string fileData, const char * dir_name) {
+ capabilityList["adc"] = true;
+ capabilityList["din"] = true;
+ capabilityList["dout"] = true;
+ capabilityList["gpio"] = true;
+}
+
+void Device::setupMfser(std::string fileData, const char * dir_name) {
+ capabilityList["rs232"] = true;
+ capabilityList["rs422"] = true;
+ capabilityList["rs485"] = true;
+ capabilityList["serial"] = true;
+ if (!fileExists("/dev/ext_serial") && strlen(dir_name) > 0) {
+ std::string temp;
+ MTS::System::cmd("ln -s /dev/ttyAP" + std::string(dir_name + strlen(dir_name) - 1) + " /dev/ext_serial", temp);
+ }
+}
+
void Device::show(std::string name) {
std::string fileData;
int32_t code = MTS::System::readFile(SYSFS_PLATFORM + name, fileData);
@@ -392,7 +401,6 @@ void Device::storeTrigger(std::string name, std::string value) {
logError("can't not open '" + std::string(LEDS_GPIO_DIR) + name + "/trigger': No such file or directory");
exitHandler(99);
}
-
}
std::string Device::toCamelCase(const char * d_name) {
@@ -418,14 +426,6 @@ 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 98c0108..0c9dc2e 100644
--- a/src/MtsIoSysfs.cpp
+++ b/src/MtsIoSysfs.cpp
@@ -32,16 +32,6 @@ 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 de88c98..96d0a2c 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-3-g92bd445");
+const std::string Version::version("v1.0.0-4-g50a0344");