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.cpp46
1 files changed, 33 insertions, 13 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);