Skip to content

Commit

Permalink
Merge pull request #2169 from GreyWolfBW/contribution-cal
Browse files Browse the repository at this point in the history
It's important to reset the "CAL" status. This will be define later if necessary.
  • Loading branch information
jimklimov committed Nov 13, 2023
2 parents a01b072 + c174a8f commit 6f0689e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ https://github.com/networkupstools/nut/milestone/10
* dstate machinery: a segmentation fault (null pointer dereference) was
possible with `INSTCMD` processing of commands without parameters nor
`TRACKING` identifier. [#2155]
* `upsmon` recognition of `CAL` state could linger after the calibration
activity was completed by the hardware, which led to mis-processing of
shutdown triggers. Also, notification was added to report "finished
calibration". [issue #2168, PR #2169]

- nut-usbinfo.pl, nut-scanner and libnutscan:
* USB VendorID:ProductID support list files generated by the script for
Expand Down
18 changes: 16 additions & 2 deletions clients/upsmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ static void upsreplbatt(utype_t *ups)
}
}

static void ups_cal(utype_t *ups)
static void ups_is_cal(utype_t *ups)
{
if (flag_isset(ups->status, ST_CAL)) { /* no change */
upsdebugx(4, "%s: %s (no change)", __func__, ups->sys);
Expand All @@ -1226,6 +1226,16 @@ static void ups_cal(utype_t *ups)
setflag(&ups->status, ST_CAL);
}

static void ups_is_notcal(utype_t *ups)
{
/* Called when CAL is NOT among known states */
if (flag_isset(ups->status, ST_CAL)) { /* actual change */
do_notify(ups, NOTIFY_NOTCAL);
clearflag(&ups->status, ST_CAL);
try_restore_pollfreq(ups);
}
}

static void ups_fsd(utype_t *ups)
{
if (flag_isset(ups->status, ST_FSD)) { /* no change */
Expand Down Expand Up @@ -2130,6 +2140,10 @@ static void parse_status(utype_t *ups, char *status)
clearflag(&ups->status, ST_LOWBATT);
if (!strstr(status, "FSD"))
clearflag(&ups->status, ST_FSD);

/* similar to above - clear these flags and send notifications */
if (!strstr(status, "CAL"))
ups_is_notcal(ups);
if (!strstr(status, "OFF"))
ups_is_notoff(ups);
if (!strstr(status, "BYPASS"))
Expand All @@ -2154,7 +2168,7 @@ static void parse_status(utype_t *ups, char *status)
if (!strcasecmp(statword, "RB"))
upsreplbatt(ups);
if (!strcasecmp(statword, "CAL"))
ups_cal(ups);
ups_is_cal(ups);
if (!strcasecmp(statword, "OFF"))
ups_is_off(ups);
if (!strcasecmp(statword, "BYPASS"))
Expand Down
10 changes: 6 additions & 4 deletions clients/upsmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ typedef struct {
#define NOTIFY_NOCOMM 8 /* UPS hasn't been contacted in a while */
#define NOTIFY_NOPARENT 9 /* privileged parent process died */
#define NOTIFY_CAL 10 /* UPS is performing calibration */
#define NOTIFY_OFF 11 /* UPS is administratively OFF or asleep*/
#define NOTIFY_NOTOFF 12 /* UPS is not anymore administratively OFF or asleep*/
#define NOTIFY_BYPASS 13 /* UPS is administratively on bypass */
#define NOTIFY_NOTBYPASS 14 /* UPS is not anymore administratively on bypass */
#define NOTIFY_NOTCAL 11 /* UPS is performing calibration */
#define NOTIFY_OFF 12 /* UPS is administratively OFF or asleep*/
#define NOTIFY_NOTOFF 13 /* UPS is not anymore administratively OFF or asleep*/
#define NOTIFY_BYPASS 14 /* UPS is administratively on bypass */
#define NOTIFY_NOTBYPASS 15 /* UPS is not anymore administratively on bypass */

/* notify flag values */

Expand Down Expand Up @@ -140,6 +141,7 @@ static struct {
{ NOTIFY_NOCOMM, "NOCOMM", NULL, "UPS %s is unavailable", NOTIFY_DEFAULT },
{ NOTIFY_NOPARENT, "NOPARENT", NULL, "upsmon parent process died - shutdown impossible", NOTIFY_DEFAULT },
{ NOTIFY_CAL, "CAL", NULL, "UPS %s: calibration in progress", NOTIFY_DEFAULT },
{ NOTIFY_NOTCAL, "NOTCAL", NULL, "UPS %s: calibration finished", NOTIFY_DEFAULT },
{ NOTIFY_OFF, "OFF", NULL, "UPS %s: administratively OFF or asleep", NOTIFY_DEFAULT },
{ NOTIFY_NOTOFF, "NOTOFF", NULL, "UPS %s: no longer administratively OFF or asleep", NOTIFY_DEFAULT },
{ NOTIFY_BYPASS, "BYPASS", NULL, "UPS %s: on bypass (powered, not protecting)", NOTIFY_DEFAULT },
Expand Down
1 change: 1 addition & 0 deletions conf/upsmon.conf.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ POWERDOWNFLAG "@POWERDOWNFLAG@"
# NOTIFYMSG NOCOMM "UPS %s is unavailable"
# NOTIFYMSG NOPARENT "upsmon parent process died - shutdown impossible"
# NOTIFYMSG CAL "UPS %s: calibration in progress"
# NOTIFYMSG NOTCAL "UPS %s: calibration finished"
# NOTIFYMSG OFF "UPS %s: administratively OFF or asleep"
# NOTIFYMSG NOTOFF "UPS %s: no longer administratively OFF or asleep"
# NOTIFYMSG BYPASS "UPS %s: on bypass (powered, not protecting)"
Expand Down
2 changes: 2 additions & 0 deletions docs/man/upsmon.conf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ NOPARENT;; `upsmon` parent process died - shutdown impossible

CAL;; UPS calibration in progress

NOTCAL;; UPS calibration finished

OFF;; UPS administratively OFF or asleep

NOTOFF;; UPS no longer administratively OFF or asleep
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 3282 utf-8
personal_ws-1.1 en 3283 utf-8
AAC
AAS
ABI
Expand Down Expand Up @@ -778,6 +778,7 @@ NONUT
NOP
NOPARENT
NOTBYPASS
NOTCAL
NOTIFYCMD
NOTIFYFLAG
NOTIFYFLAGS
Expand Down

0 comments on commit 6f0689e

Please sign in to comment.