Skip to content

Commit

Permalink
Merge pull request #2117 from jimklimov/issue-2063
Browse files Browse the repository at this point in the history
Follow-up for `apc_modbus` driver
  • Loading branch information
jimklimov authored Oct 20, 2023
2 parents e6cd5b3 + b52bd03 commit 94139cb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
22 changes: 22 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ as part of https://github.com/networkupstools/nut/issues/1410 solution.
* fix to clean obsoleted readings (if any) AFTER getting new info from an
`apcupsd` daemon, to avoid the gap when NUT driver knows nothing [#2007]

- apc_modbus driver was introduced, to cover the feature gap between existing
NUT drivers for APC hardware and the actual USB-connected devices (or their
firmwares) released since roughly 2010, which deprecated standard USB HID
support in favor of Modbus-based protocol which is used across the board
(also with their network management cards). The new driver can monitor APC
UPS devices over TCP and Serial connections, as well as USB with a patched
libmodbus (check https://github.com/EchterAgo/libmodbus/commits/rtu_usb
for now, PR pending). [#139, #2063]
* For a decade until this driver got introduced, people were advised to
use apcupsd project as the actual program which talks to a device, and
NUT apcupsd-ups driver to relay information back and forth. This was a
limited solution due to lack of command and variable setting support,
as well as relaying of just some readings (just whatever apcupsd exposes,
further constrained by what our driver knows to re-translate), with
little leverage for NUT to tap into everything the device has to offer.
There were also issues on some systems due to packaging (e.g. marking
NUT and apcupsd as competing implementations of the same features) which
required clumsy workarounds to get both installed and running. Finally,
there is a small matter of long-term viability of that approach: last
commits to apcupsd sources were in 2017 (with last release 3.14.14 in
May 2016): https://sourceforge.net/p/apcupsd/svn/HEAD/tree/

- NUT for Windows:
* Ability to build NUT for Windows, last tackled with a branch based on
NUT v2.6.5 a decade ago, has been revived with the 2.8.x era codebase [#5].
Expand Down
43 changes: 40 additions & 3 deletions scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# is to just pick out some strings relevant for tracking config changes.
#
# Copyright (C) 2016-2020 Eaton
# Copyright (C) 2020-2022 Jim Klimov <[email protected]>
# Copyright (C) 2020-2023 Jim Klimov <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -171,7 +171,7 @@ fi
# Cache needed bits of ups.conf to speed up later parsing. Note that these
# data are needed for most operations, and populated by upslist_readFile()
UPSCONF_DATA=""
# Subset of normalized data above that only has sections, drivers and ports
# Subset of normalized data above that only has sections, drivers and ports (SDP)
UPSCONF_DATA_SDP=""

# List of configured UPSes in the config-file
Expand Down Expand Up @@ -479,8 +479,45 @@ upsconf_getDriverMedia() {
# particular system's physics, both serial and network media may need USB).
CURR_DRV="`upsconf_getDriver "$1"`" || return $?
case "$CURR_DRV" in
*netxml*|*snmp*|*ipmi*|*powerman*|*-mib*|*avahi*|*apcupsd*)
*netxml*|*snmp*|*ipmi*|*powerman*|*-mib*|*avahi*)
printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;;
*apcupsd-ups*)
# Relay from a nearby apcupsd network server into NUT ecosystem:
CURR_PORT="`upsconf_getPort "$1"`" || CURR_PORT=""
case "$CURR_PORT" in
*localhost*|*127.0.0.1*|*::1*)
printf '%s\n%s\n' "$CURR_DRV" "network-localhost" ; return ;;
*)
printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;;
esac
;;
*apc_modbus*)
CURR_PORT="`upsconf_getPort "$1"`" || CURR_PORT=""
CURR_PORTTYPE="`upsconf_getValue "$1" 'porttype'`" || CURR_PORTTYPE=""
case "$CURR_PORTTYPE" in
*usb*)
printf '%s\n%s\n' "$CURR_DRV" "usb" ; return ;;
*serial*)
printf '%s\n%s\n' "$CURR_DRV" "serial" ; return ;;
*) # default depends on driver build (against libmodbus
# version with or without support for usb)
# TOTHINK: Check for presence of config values like
# vendorid (USB) or baud (Serial)? They are optional
# with reasonable defaults anyway...
case "$CURR_PORT" in
*auto*)
printf '%s\n%s\n' "$CURR_DRV" "usb" ; return ;;
/*)
printf '%s\n%s\n' "$CURR_DRV" "serial" ; return ;;
*localhost*|*127.0.0.1*|*::1*)
printf '%s\n%s\n' "$CURR_DRV" "network-localhost" ; return ;;
*)
printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;;
esac
# returns are above, but just in case - have a fallback:
printf '%s\n%s\n' "$CURR_DRV" "" ; return ;;
esac
;;
*usb*)
printf '%s\n%s\n' "$CURR_DRV" "usb" ; return ;;
nutdrv_qx) # May be direct serial or USB
Expand Down

0 comments on commit 94139cb

Please sign in to comment.