diff options
author | John Klug <john.klug@multitech.com> | 2024-06-04 15:02:10 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2024-06-04 15:02:10 -0500 |
commit | ae1740d9a2582d1a4815bdf11ae18b46d696dbff (patch) | |
tree | 8cfaa7b8b17c1ffb2712378c09910bd1014495f0 | |
parent | 6c150487349cef76aeeacabc849152828b883968 (diff) | |
download | mts-io-sysfs-ae1740d9a2582d1a4815bdf11ae18b46d696dbff.tar.gz mts-io-sysfs-ae1740d9a2582d1a4815bdf11ae18b46d696dbff.tar.bz2 mts-io-sysfs-ae1740d9a2582d1a4815bdf11ae18b46d696dbff.zip |
Fix up mts-io EEPROM queries in mts-io-sysfs
-rw-r--r-- | include/Device/Device.h | 2 | ||||
-rw-r--r-- | src/Device/Device.cpp | 38 |
2 files changed, 30 insertions, 10 deletions
diff --git a/include/Device/Device.h b/include/Device/Device.h index 9118851..d6b6efc 100644 --- a/include/Device/Device.h +++ b/include/Device/Device.h @@ -194,7 +194,7 @@ class Device { void simpleError(std::string msg, int error, int exitval); void setSerialModesMTR3(const std::string &mode, const std::string &value); void showSerialModesMTR3(const std::string &mode); - int getPinValue(const std::string &name); + int getPinValue(const std::string &name, std::string *value); void setProgramName(const std::string &name); void setHWVersion(); }; diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp index 2d93ed7..e743dd6 100644 --- a/src/Device/Device.cpp +++ b/src/Device/Device.cpp @@ -703,19 +703,31 @@ unsigned int Device::gpio_request::offset() * assume the name is an attribute of the mts-io * driver. GPIOs can only be zero * or one, never a text string. + * + * If the data pointer (2nd parm) is not NULL, + * return the text of the value. This covers + * non-gpio instances, such as device-id. */ -int Device::getPinValue(const std::string &name) { +int Device::getPinValue(const std::string &name, std::string *data) +{ std::string fileData; if(isupper(name[0])) { gpio_request gr(this, name); if (gr.request()) { enum gpiod_line_value lv = gpiod_line_request_get_value(gr.request(),gr.offset()); if(lv != GPIOD_LINE_VALUE_ERROR) { - if(lv == GPIOD_LINE_VALUE_INACTIVE) + if(lv == GPIOD_LINE_VALUE_INACTIVE) { + if(data != NULL) + *data = "0"; return 0; - else - return 1; + } else { + if(data != NULL) { + *data = "1"; + return 0; + } else + return 1; + } } else simpleError("Invalid GPIO line value", errno, 109); } @@ -723,6 +735,10 @@ int Device::getPinValue(const std::string &name) { int32_t code = MTS::System::readFile(SYSFS_PLATFORM + name, fileData); if (code == 0) { + if (data != NULL) { + *data = fileData; + return 0; + } if (fileData == "1") { return 1; }; @@ -735,11 +751,15 @@ int Device::getPinValue(const std::string &name) { } void Device::show(std::string name) { + std::string fileData; + int result; if (regex_match(hw_version, iotRtrVersionFilters)) { showSerialModesMTR3(name); } - printf("%i", getPinValue(name)); - exitHandler(0); + result = getPinValue(name,&fileData); + if (result == 0) + printf("%s\n", fileData.c_str()); + exitHandler(result); } // End of show void Device::showTrigger(std::string name) { @@ -943,13 +963,13 @@ void Device::showSerialModesMTR3(const std::string ¶meter) { printUsage(); } if (mode == SERIAL_MODE) { - if (getPinValue(CONTROL_PIN_SERIAL_MODE) == 1) { + if (getPinValue(CONTROL_PIN_SERIAL_MODE,NULL) == 1) { std::cout << SERIAL_MODE_RS485 << std::endl; } else { std::cout << SERIAL_MODE_RS232 << std::endl; } } else if (mode == SERIAL_TERMINATION) { - std::cout << getPinValue(CONTROL_PIN_TERMINATION) << std::endl; + std::cout << getPinValue(CONTROL_PIN_TERMINATION,NULL) << std::endl; } else { printError("Unknown mode: %s", mode.c_str()); exitHandler(98); @@ -968,4 +988,4 @@ void Device::setHWVersion(){ return; } std::getline(is, hw_version); -}
\ No newline at end of file +} |