tripplitesu: Add runtime delay parameters via upscmd extra argument#1
tripplitesu: Add runtime delay parameters via upscmd extra argument#1
Conversation
Intermittent communication timeouts were observed when multiple commands were sent in rapid succession. Adding a 1-second delay at the beginning of command_send() ensures the hardware buffer is ready and prevents the "read timeout" errors. Signed-off-by: TomZanna <git@tomzanna.com>
- Add command_delay parameter (default: -1 = disabled) - Modify do_command() to use configurable delay instead of hardcoded 1 second - Add documentation for command_delay in man page - Document that shutdown.reboot commands can power on a UPS that is off - Update code comments to reflect new parameter and behavior Co-authored-by: TomZanna <43095563+TomZanna@users.noreply.github.com>
- Add input validation for command_delay (must be >= -1) - Fix delay check to only apply for positive values (> 0) - Add detailed debug messages for different command_delay states - Update documentation to clarify 0 vs -1 behavior - Simplify variable usage by removing intermediate lval variable Co-authored-by: TomZanna <43095563+TomZanna@users.noreply.github.com>
Co-authored-by: TomZanna <43095563+TomZanna@users.noreply.github.com>
- Auto-enable command_delay (1 second) when timeout detected - Add shutdown_delay parameter (default: 5 seconds) - Add reboot_delay parameter (default: 1 minute) - Update instcmd() to use configurable delays - Update upsdrv_shutdown() to use configurable delays - Update documentation with new parameters Co-authored-by: TomZanna <43095563+TomZanna@users.noreply.github.com>
- Fix shutdown_delay default from 5 to 10 seconds (backward compatibility) - Extract auto-enable logic to helper function to reduce duplication - Use strtol() for better input validation on shutdown_delay and reboot_delay - Add minimum value validation (1 second for shutdown, 1 minute for reboot) - Fix comment about delay condition (> 0 instead of >= 0) - Clarify graceful shutdown behavior in documentation - Clarify auto-enable only works when command_delay is -1 Co-authored-by: TomZanna <43095563+TomZanna@users.noreply.github.com>
- Add parse_delay_args() helper function to parse delays from extra arg - Format: "shutdown_delay" or "shutdown_delay.reboot_delay" - Update shutdown.reboot, shutdown.reboot.graceful, shutdown.return - Falls back to ups.conf parameters if extra is NULL/empty/invalid - Remove NUT_UNUSED_VARIABLE(extra) since we now use it - Update documentation with examples of using extra parameter Co-authored-by: TomZanna <43095563+TomZanna@users.noreply.github.com>
- Add errno and limits.h includes for proper validation - Check for INT_MAX overflow and errno == ERANGE after strtol - Validate no trailing garbage characters in input - Use separate variable name (reboot_str) instead of reassigning extra - Ensure complete input string is consumed (endptr points to '\0') - More robust input validation prevents silent acceptance of malformed input Co-authored-by: TomZanna <43095563+TomZanna@users.noreply.github.com>
jimklimov
left a comment
There was a problem hiding this comment.
Looks like a decent improvement, a few things to fix are commented (also update NEWS.adoc about the change).
If this was all/mostly written by AI, quite impressive.
| #include <limits.h> | ||
|
|
||
| #define DRIVER_NAME "Tripp Lite SmartOnline driver" | ||
| #define DRIVER_VERSION "0.12" |
| This delay helps prevent "read timeout" errors when the hardware buffer is | ||
| not ready to accept new commands immediately after completing the previous one. | ||
| + | ||
| *Note:* If a communication timeout is detected and command_delay is -1 (default |
There was a problem hiding this comment.
Here and below, better use NOTE: Some sentence syntax so it gets rendered as a notice box for ultimate docs formats where that is supported.
| return 0; /* Invalid, use defaults */ | ||
| } | ||
|
|
||
| *parsed_shutdown_delay = (int)temp; |
There was a problem hiding this comment.
Potential SEGFAULT: No sanity checks (e.g. against errors by future devs) that the two parsed* pointers are not NULL.
| @@ -0,0 +1 @@ | |||
| . No newline at end of file | |||
|
Sorry, I didn't realize Copilot had added you as an additional reviewer. I was testing the tool to figure out how to implement a few things, and I hope I didn't waste too much of your time with this PR. The only thing I’m stuck on is why there’s a double call for shutdown/reboot actions: do_command(SET, TSU_SHUTDOWN_RESTART, "1", NULL); // delay in minutes
do_command(SET, TSU_SHUTDOWN_ACTION, "10", NULL); // delay in secondsBased on what I observed while sniffing the serial port, the parameter for I won't have easy physical access to the UPS for the next few months, so in the meantime, I’ll clean up the PR networkupstools#3273 regarding the timeout issue. |
|
Not really sure about this particular UPS, but it could be two non-conflicting settings: "what to do when power goes out", and "what to do when power comes back". |
|
NP about time so far, was commuting to FOSDEM. After a few forays of my own, I am (still) amazed at how AI makes-believe it knows what it's doing :) And just as well, how convincingly it hallucinates about using some feature that's not really there, but now that you saw an example, you wanna make it happen :) |
Description
Tripp Lite SmartOnline devices require configurable shutdown/reboot delays. Previously only configurable via ups.conf. Now supports runtime specification through upscmd's extra parameter with automatic fallback.
Changes
Runtime delay parameter parsing:
parse_delay_args()helper with format"shutdown_delay"or"shutdown_delay.reboot_delay"strtol()with overflow checking (INT_MAX,ERANGE), trailing garbage detection, minimum value enforcementupscmd ups shutdown.reboot 5.2→ shutdown 5s, reboot 2minUpdated instant commands:
shutdown.reboot,shutdown.reboot.graceful,shutdown.returnnow parse extra parameterNUT_UNUSED_VARIABLE(extra)- now actively consumedInput handling robustness:
Previous commits in this PR
Auto-timeout mitigation:
auto_enable_command_delay()with flag trackingConfigurable timing parameters:
command_delay: inter-command delay in microseconds (default: -1 disabled, auto-enables on timeout)shutdown_delay: shutdown delay in seconds (default: 10, min: 1)reboot_delay: reboot delay in minutes (default: 1, min: 1)strtol()for config parsing with proper validationGeneral points
Described the changes in the PR submission or a separate issue, e.g.
known published or discovered protocols, applicable hardware (expected
compatible and actually tested/developed against), limitations, etc.
There may be multiple commits in the PR, aligned and commented with
a functional change. Notably, coding style changes better belong in a
separate PR, but certainly in a dedicated commit to simplify reviews
of "real" changes in the other commits. Similarly for typo fixes in
comments or text documents.
Please star NUT on GitHub, this helps with sponsorships! ;)
Frequent "underwater rocks" for driver addition/update PRs
Revised existing driver families and added a sub-driver if applicable
(
nutdrv_qx,usbhid-ups...) or added a brand new driver in the othercase.
Did not extend obsoleted drivers with new hardware support features
(notably
blazerand other single-device family drivers for Qx protocols,except the new
nutdrv_qxwhich should cover them all).For updated existing device drivers, bumped the
DRIVER_VERSIONmacroor its equivalent.
For USB devices (HID or not), revised that the driver uses unique
VID/PID combinations, or raised discussions when this is not the case
(several vendors do use same interface chips for unrelated protocols).
For new USB devices, built and committed the changes for the
scripts/upower/95-upower-hid.hwdbfileProposed NUT data mapping is aligned with existing
docs/nut-names.txtfile. If the device exposes useful data points not listed in the file, the
experimental.*namespace can be used as documented there, and discussionshould be raised on the NUT Developers mailing list to standardize the new
concept.
Updated
data/driver.list.inif applicable (new tested device info)Frequent "underwater rocks" for general C code PRs
Did not "blindly assume" default integer type sizes and value ranges,
structure layout and alignment in memory, endianness (layout of bytes and
bits in memory for multi-byte numeric types), or use of generic
intwherelanguage or libraries dictate the use of
size_t(orssize_tsometimes).Progress and errors are handled with
upsdebugx(),upslogx(),fatalx()and related methods, not with directprintf()orexit().Similarly, NUT helpers are used for error-checked memory allocation and
string operations (except where customized error handling is needed,
such as unlocking device ports, etc.)
Coding style (including whitespace for indentations) follows precedent
in the code of the file, and examples/guide in
docs/developers.txtfile.For newly added files, the
Makefile.amrecipes were updated and themake distchecktarget passes.General documentation updates
Updated
docs/acknowledgements.txt(for vendor-backed device support)Added or updated manual page information in
docs/man/*.txtfilesand corresponding recipe lists in
docs/man/Makefile.amfor new pagesPassed
make spellcheck, updated spell-checking dictionary in thedocs/nut.dictfile if needed (did not remove any words -- themakerule printout in case of changes suggests how to maintain it).
Additional work may be needed after posting this PR
Propose a PR for NUT DDL with detailed device data dumps from tests
against real hardware (the more models, the better).
Address NUT CI farm build failures for the PR: testing on numerous
platforms and toolkits can expose issues not seen on just one system.
Revise suggestions from LGTM.COM analysis about "new issues" with
the changed codebase.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.