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.cpp94
1 files changed, 12 insertions, 82 deletions
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index 0083ff3..b806f06 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -28,29 +28,17 @@ const std::regex Device::serialModeFilter("(.*)(serial-mode)");
const std::regex Device::storeFilters("(.*)(mac-)(.*)|(.*)(-id)|(uuid)|(.*)(/eui)|(.*)(/cdone)|(.*)(hw-version)|(imei)|(capability)(.*)|(radio-reset-backoff-seconds)|(modalias)|(power)|((subsystem)(.*))|(uevent)|(board-temperature)|(reset)|(led3)|(led-ls)|(usbhd-ps-oc)|(.*)(adc[0-9])|(.*)(din[0-9])|(gpi[0-9])|(gpi[0-9][0-9])");
const std::regex Device::showFilters("(modalias)|(subsystem)|(uevent)");
+std::map<std::string, bool> Device::capabilityList = {{"adc", false},{"battery", false},{"bluetooth", false},
+ {"cell", false},{"cellWwan", false},{"din", false},{"dout", false},{"externalSerialPort", false},
+ {"gpio", false},{"gps", false},{"lora", false},{"loraNetworkServer", false},
+ {"nodeRed", false},{"rs232", false},{"rs422", false},{"rs485", false},{"serial", false},
+ {"wifi", false}};
+
Device::Device() {
isRoot = !getuid();
verbose = false;
}
-void Device::exitHandler(int code) {
- if (code != 0) {
- logError("exiting with " + std::to_string(code));
- }
- exit(code);
-}
-
-bool Device::fileExists(std::string file) {
- struct stat buffer;
- return (stat (file.c_str(), &buffer) == 0) ? true : false;
-}
-
-mode_t Device::fileType(std::string file) {
- struct stat buf;
- stat (file.c_str(), &buf);
- return buf.st_mode & S_IFMT;
-}
-
void Device::getSystemTreeJson(const char * dir_name) {
std::string fullPath = SYSFS_PLATFORM + std::string(dir_name);
DIR * d = opendir (fullPath.c_str());
@@ -81,15 +69,15 @@ void Device::getSystemTreeJson(const char * dir_name) {
}
if (strcmp(d_name, "product-id") == 0) {
if (regex_match(fileData, lora15Filters)) {
- setupLora15(fileData, dir_name);
+ Lora15Card lora15(*this, fileData, dir_name);
} else if (regex_match(fileData, loraG16Filters)) {
- setupLoraG16(fileData, dir_name);
+ Lora21Card lora21(*this, fileData, dir_name);
} else if (regex_match(fileData, loraG64Filters)) {
- setupLoraG64(fileData, dir_name);
+ Lora21ExtCard lora21Ext(*this, fileData, dir_name);
} else if (regex_match(fileData, gpiobFilters)) {
- setupGpiob(fileData, dir_name);
+ Gpiob ppiob(*this);
} else if (regex_match(fileData, mfserFilters)) {
- setupMfser(fileData, dir_name);
+ Mfser msfer(*this, dir_name);
}
}
accessoryCard.AddMember(rapidjson::Value().SetString(toCamelCase(d_name).c_str(), accessoryCardsAlloc), rapidjson::Value().SetString(fileData.c_str(), accessoryCardsAlloc), accessoryCardsAlloc);
@@ -301,48 +289,6 @@ 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);
@@ -353,7 +299,6 @@ void Device::show(std::string name) {
logError("cat: can't open " + std::string(SYSFS_PLATFORM) + name + ": No such file or directory");
exitHandler(99);
}
-
}
void Device::showTrigger(std::string name) {
@@ -403,21 +348,6 @@ void Device::storeTrigger(std::string name, std::string value) {
}
}
-std::string Device::toCamelCase(const char * d_name) {
- std::string camelString = strdup(d_name);
- std::string tempString = "";
- for (size_t x = 0; x < camelString.length(); x++){
- if (camelString[x] == '-' || camelString[x] == '_'){
- tempString = camelString.substr(x + 1, 1);
- transform(tempString.begin(), tempString.end(), tempString.begin(), toupper);
- camelString.erase(x, 2);
- camelString.insert(x, tempString);
- }
- }
- return camelString;
-}
-
-
void Device::Verbose(const bool val) {
verbose = val;
}
@@ -437,4 +367,4 @@ void Device::writeJson() {
} else {
os << buffer.GetString();
}
-}
+} \ No newline at end of file