diff options
Diffstat (limited to 'src/Device/Device.cpp')
-rw-r--r-- | src/Device/Device.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp index be198f1..2d93ed7 100644 --- a/src/Device/Device.cpp +++ b/src/Device/Device.cpp @@ -56,8 +56,8 @@ std::map<std::string, bool> Device::capabilityList = { {"userDataEncryption", false}}; std::map<std::string, std::string> Device::ethSwitchList; -std::string Device::extIoStr; -std::string Device::serialStr; +std::string Device::extIoStr = "{\"dInputs\":[],\"dOutputs\":[]}";; +std::string Device::serialStr = "[]"; std::map<std::string, std::string> Device::deviceInfoList = { {"deviceId", ""}, @@ -725,9 +725,8 @@ int Device::getPinValue(const std::string &name) { if (code == 0) { if (fileData == "1") { return 1; - } else { - return 0; - } + }; + return 0; } printError("cat: can't open %s%s: %s", SYSFS_PLATFORM, name.c_str(),strerror(errno)); @@ -897,6 +896,8 @@ void Device::storeOutputStateToNonvolatile(const std::string& name, const std::s void Device::setSerialModesMTR3(const std::string ¶meter, const std::string &value) { std::vector<std::string> parts = MTS::Text::split(parameter, '/'); if (parts.size() < 2) { + // it is not a serial things, return and compare to other options + // serial things look like `serial1/mode' return; } const std::string &serialName = parts[0]; @@ -917,16 +918,20 @@ void Device::setSerialModesMTR3(const std::string ¶meter, const std::string if (value == SERIAL_MODE_RS485) { store(CONTROL_PIN_SERIAL_MODE, "1"); } - exitHandler(0); } else if (mode == SERIAL_TERMINATION) { store(CONTROL_PIN_TERMINATION, value); - exitHandler(0); + } else { + printError("Unknown mode: %s", mode.c_str()); + exitHandler(98); } + exitHandler(0); } void Device::showSerialModesMTR3(const std::string ¶meter) { std::vector<std::string> parts = MTS::Text::split(parameter, '/'); if (parts.size() < 2) { + // it is not a serial things, return and compare to other options + // serial things look like `serial1/mode' return; } const std::string &serialName = parts[0]; @@ -943,11 +948,13 @@ void Device::showSerialModesMTR3(const std::string ¶meter) { } else { std::cout << SERIAL_MODE_RS232 << std::endl; } - exitHandler(0); } else if (mode == SERIAL_TERMINATION) { std::cout << getPinValue(CONTROL_PIN_TERMINATION) << std::endl; - exitHandler(0); + } else { + printError("Unknown mode: %s", mode.c_str()); + exitHandler(98); } + exitHandler(0); } void Device::setProgramName(const std::string &name){ @@ -955,9 +962,9 @@ void Device::setProgramName(const std::string &name){ } void Device::setHWVersion(){ - std::ifstream is(HW_VERSION_FILE); + std::ifstream is(HW_VERSION_PATH); if (!is.is_open()) { - printDebug("Can't read to %s: %s", HW_VERSION_FILE, strerror(errno)); + printDebug("Can't read to %s: %s", HW_VERSION_PATH, strerror(errno)); return; } std::getline(is, hw_version); |