diff options
author | Serhii Voloshynov <serhii.voloshynov@globallogic.com> | 2024-05-28 11:01:19 +0300 |
---|---|---|
committer | Serhii Voloshynov <serhii.voloshynov@globallogic.com> | 2024-05-28 12:18:10 +0300 |
commit | f8ba2f3dcc186f7474e0a5433e5971737cc37282 (patch) | |
tree | 4a267756e1e3938e3a4e392a4e76a50b65bb6a9f | |
parent | 0b55b2997d17bbce5bea3ebe1f5700dca184574f (diff) | |
download | mts-io-sysfs-f8ba2f3dcc186f7474e0a5433e5971737cc37282.tar.gz mts-io-sysfs-f8ba2f3dcc186f7474e0a5433e5971737cc37282.tar.bz2 mts-io-sysfs-f8ba2f3dcc186f7474e0a5433e5971737cc37282.zip |
fixes after review
-rw-r--r-- | include/Device/Device.h | 1 | ||||
-rw-r--r-- | src/Device/Device.cpp | 29 |
2 files changed, 18 insertions, 12 deletions
diff --git a/include/Device/Device.h b/include/Device/Device.h index a1c0b1b..9118851 100644 --- a/include/Device/Device.h +++ b/include/Device/Device.h @@ -158,7 +158,6 @@ class Device { const std::string CONTROL_PIN_SERIAL_MODE = "MXC2_RS485_EN"; const std::string CONTROL_PIN_TERMINATION = "MXC2_RS485_TERM_EN"; - const std::string HW_VERSION_FILE = "/sys/devices/platform/mts-io/hw-version"; std::string program_name; std::string hw_version; 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); |