Skip to content

Commit

Permalink
Merge pull request #811 from kgizdov/cyberpower-ut-series
Browse files Browse the repository at this point in the history
CyberPower UT series do not seem to pass correct 'OB' flag, try to accommodate this with new "onlinedischarge" config flag
  • Loading branch information
jimklimov committed Mar 29, 2022
2 parents 11f36ac + 7efa550 commit a8e3687
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ control history for "live" codebase.
---------------------------------------------------------------------------
Release notes for NUT 2.8.0 - what's new since 2.7.4:

NOTE: Earlier discussions (mailing list threads, GitHub issues, etc.) could
refer to this change set (too long in the making) as NUT 2.7.5.

- New (optional) keywords for configuration files were added,
so existing NUT 2.7.x builds would not accept them if some
deployments switch versions back and forth -- due to this,
Expand Down Expand Up @@ -169,6 +172,8 @@ Release notes for NUT 2.8.0 - what's new since 2.7.4:
subdriver rather than polluting the main code with UPS specific
exceptions, and applied fixes for known mistakes in (some releases
of firmware for) CyberPower CPS*EPFCLCD [issue #439, PR #1245]
* added `onlinedischarge` option for UPSes that report `OL+DISCHRG`
when wall power is lost [PR #811]
* CPS HID: add input.frequency and output.frequency
* OpenUPS2: only check OEM Information string once (fewer log messages)
* Liebert GXT4 USB VID:PID [10AF:0000]
Expand Down
9 changes: 7 additions & 2 deletions ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,21 @@ if [ -z "$CI_OS_NAME" ]; then
"$OS_FAMILY-$OS_DISTRO" \
"`grep = /etc/os-release 2>/dev/null`" \
"`cat /etc/release 2>/dev/null`" \
"`uname -o`" \
"`uname -s -r -v`" \
"`uname -o 2>/dev/null`" \
"`uname -s -r -v 2>/dev/null`" \
"`uname -a`" \
"`uname`" \
; do
[ -z "$CI_OS_HINT" -o "$CI_OS_HINT" = "-" ] || break
done

case "`echo "$CI_OS_HINT" | tr 'A-Z' 'a-z'`" in
*freebsd*)
CI_OS_NAME="freebsd" ;;
*openbsd*)
CI_OS_NAME="openbsd" ;;
*netbsd*)
CI_OS_NAME="netbsd" ;;
*debian*|*ubuntu*)
CI_OS_NAME="debian" ;;
*centos*|*fedora*|*redhat*|*rhel*)
Expand Down
6 changes: 6 additions & 0 deletions docs/man/usbhid-ups.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ If this flag is set, the driver will not use Interrupt In transfers during the
shorter "pollinterval" cycles (not recommended, but needed if these reports
are broken on your UPS).

*onlinedischarge*::
If this flag is set, the driver will treat `OL+DISCHRG` status as offline.
For most devices this combination means calibration or similar maintenance;
however some UPS models (e.g. CyberPower UT series) emit `OL+DISCHRG` when
wall power is lost -- and need this option to handle shutdowns.

*vendor*='regex'::
*product*='regex'::
*serial*='regex'::
Expand Down
3 changes: 2 additions & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 2868 utf-8
personal_ws-1.1 en 2869 utf-8
AAS
ACFAIL
ACFREQ
Expand Down Expand Up @@ -2255,6 +2255,7 @@ onclick
ondelay
oneac
online
onlinedischarge
ont
ontd
ontimedays
Expand Down
37 changes: 34 additions & 3 deletions drivers/usbhid-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ bool_t use_interrupt_pipe = FALSE;
static time_t lastpoll; /* Timestamp the last polling */
hid_dev_handle_t udev = HID_DEV_HANDLE_CLOSED;

/**
* CyberPower UT series sometime need a bit of help deciding their online status.
* This quirk is to enable the special handling of OL & DISCHRG at the same time
* as being OB (on battery power/no mains power). Enabled by device config flag.
*/
static int onlinedischarge = 0;

/* support functions */
static hid_info_t *find_nut_info(const char *varname);
static hid_info_t *find_hid_info(const HIDData_t *hiddata);
Expand Down Expand Up @@ -789,6 +796,9 @@ void upsdrv_makevartable(void)

addvar(VAR_FLAG, "pollonly", "Don't use interrupt pipe, only use polling");

addvar(VAR_FLAG, "onlinedischarge",
"Set to treat discharging while online as being offline");

#ifndef SHUT_MODE
/* allow -x vendor=X, vendorid=X, product=X, productid=X, serial=X */
nut_usb_addvars();
Expand Down Expand Up @@ -1062,6 +1072,12 @@ void upsdrv_initups(void)
if (testvar("interruptonly")) {
interrupt_only = 1;
}

/* Activate Cyberpower tweaks */
if (testvar("onlinedischarge")) {
onlinedischarge = 1;
}

val = getval("interruptsize");
if (val) {
int ipv = atoi(val);
Expand Down Expand Up @@ -1617,10 +1633,25 @@ static void ups_status_set(void)
dstate_delinfo("input.transfer.reason");
}

if (ups_status & STATUS(ONLINE)) {
status_set("OL"); /* on line */
} else {

if (!(ups_status & STATUS(ONLINE))) {
status_set("OB"); /* on battery */
} else if ((ups_status & STATUS(DISCHRG))) {
/* if online */
if (onlinedischarge) {
/* if we treat OL+DISCHRG as being offline */
status_set("OB"); /* on battery */
} else {
if (!(ups_status & STATUS(CAL))) {
/* if in OL+DISCHRG unknowingly, warn user */
upslogx(LOG_WARNING, "%s: seems that UPS [%s] is in OL+DISCHRG state now. "
"Is it calibrating or do you perhaps want to set 'onlinedischarge' option? "
"Some UPS models (e.g. CyberPower UT series) emit OL+DISCHRG when offline.",
__func__, upsname);
}
/* if we're calibrating */
status_set("OL"); /* on line */
}
}
if ((ups_status & STATUS(DISCHRG)) &&
!(ups_status & STATUS(DEPLETED))) {
Expand Down

0 comments on commit a8e3687

Please sign in to comment.