From 68c0c5ed8ad7c733743de1afc5deb9de862d60f3 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Mon, 6 Jan 2020 13:06:41 -0600 Subject: Changed radio capability to be based on has_radio file --- src/Device/Device.cpp | 96 +++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'src/Device/Device.cpp') 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 writer(buffer); -- cgit v1.2.3