Skip to content

Commit 94139cb

Browse files
authored
Merge pull request #2117 from jimklimov/issue-2063
Follow-up for `apc_modbus` driver
2 parents e6cd5b3 + b52bd03 commit 94139cb

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

NEWS.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,28 @@ as part of https://github.com/networkupstools/nut/issues/1410 solution.
195195
* fix to clean obsoleted readings (if any) AFTER getting new info from an
196196
`apcupsd` daemon, to avoid the gap when NUT driver knows nothing [#2007]
197197

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

scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# is to just pick out some strings relevant for tracking config changes.
1010
#
1111
# Copyright (C) 2016-2020 Eaton
12-
# Copyright (C) 2020-2022 Jim Klimov <jimklimov+nut@gmail.com>
12+
# Copyright (C) 2020-2023 Jim Klimov <jimklimov+nut@gmail.com>
1313
#
1414
# This program is free software; you can redistribute it and/or modify
1515
# it under the terms of the GNU General Public License as published by
@@ -171,7 +171,7 @@ fi
171171
# Cache needed bits of ups.conf to speed up later parsing. Note that these
172172
# data are needed for most operations, and populated by upslist_readFile()
173173
UPSCONF_DATA=""
174-
# Subset of normalized data above that only has sections, drivers and ports
174+
# Subset of normalized data above that only has sections, drivers and ports (SDP)
175175
UPSCONF_DATA_SDP=""
176176

177177
# List of configured UPSes in the config-file
@@ -479,8 +479,45 @@ upsconf_getDriverMedia() {
479479
# particular system's physics, both serial and network media may need USB).
480480
CURR_DRV="`upsconf_getDriver "$1"`" || return $?
481481
case "$CURR_DRV" in
482-
*netxml*|*snmp*|*ipmi*|*powerman*|*-mib*|*avahi*|*apcupsd*)
482+
*netxml*|*snmp*|*ipmi*|*powerman*|*-mib*|*avahi*)
483483
printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;;
484+
*apcupsd-ups*)
485+
# Relay from a nearby apcupsd network server into NUT ecosystem:
486+
CURR_PORT="`upsconf_getPort "$1"`" || CURR_PORT=""
487+
case "$CURR_PORT" in
488+
*localhost*|*127.0.0.1*|*::1*)
489+
printf '%s\n%s\n' "$CURR_DRV" "network-localhost" ; return ;;
490+
*)
491+
printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;;
492+
esac
493+
;;
494+
*apc_modbus*)
495+
CURR_PORT="`upsconf_getPort "$1"`" || CURR_PORT=""
496+
CURR_PORTTYPE="`upsconf_getValue "$1" 'porttype'`" || CURR_PORTTYPE=""
497+
case "$CURR_PORTTYPE" in
498+
*usb*)
499+
printf '%s\n%s\n' "$CURR_DRV" "usb" ; return ;;
500+
*serial*)
501+
printf '%s\n%s\n' "$CURR_DRV" "serial" ; return ;;
502+
*) # default depends on driver build (against libmodbus
503+
# version with or without support for usb)
504+
# TOTHINK: Check for presence of config values like
505+
# vendorid (USB) or baud (Serial)? They are optional
506+
# with reasonable defaults anyway...
507+
case "$CURR_PORT" in
508+
*auto*)
509+
printf '%s\n%s\n' "$CURR_DRV" "usb" ; return ;;
510+
/*)
511+
printf '%s\n%s\n' "$CURR_DRV" "serial" ; return ;;
512+
*localhost*|*127.0.0.1*|*::1*)
513+
printf '%s\n%s\n' "$CURR_DRV" "network-localhost" ; return ;;
514+
*)
515+
printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;;
516+
esac
517+
# returns are above, but just in case - have a fallback:
518+
printf '%s\n%s\n' "$CURR_DRV" "" ; return ;;
519+
esac
520+
;;
484521
*usb*)
485522
printf '%s\n%s\n' "$CURR_DRV" "usb" ; return ;;
486523
nutdrv_qx) # May be direct serial or USB

0 commit comments

Comments
 (0)