summaryrefslogtreecommitdiff
path: root/src/Device
diff options
context:
space:
mode:
authorSerhii Voloshynov <serhii.voloshynov@globallogic.com>2024-05-28 11:01:19 +0300
committerSerhii Voloshynov <serhii.voloshynov@globallogic.com>2024-05-28 12:18:10 +0300
commitf8ba2f3dcc186f7474e0a5433e5971737cc37282 (patch)
tree4a267756e1e3938e3a4e392a4e76a50b65bb6a9f /src/Device
parent0b55b2997d17bbce5bea3ebe1f5700dca184574f (diff)
downloadmts-io-sysfs-f8ba2f3dcc186f7474e0a5433e5971737cc37282.tar.gz
mts-io-sysfs-f8ba2f3dcc186f7474e0a5433e5971737cc37282.tar.bz2
mts-io-sysfs-f8ba2f3dcc186f7474e0a5433e5971737cc37282.zip
fixes after review
Diffstat (limited to 'src/Device')
-rw-r--r--src/Device/Device.cpp29
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 &parameter, 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 &parameter, 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 &parameter) {
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 &parameter) {
} 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);