Skip to content

Commit 0545c6e

Browse files
authored
Merge pull request #2936 from desertwitch/modernize-drv-alarms
drivers/, dummy-ups: modernize status/alarm handling, ALARM instruction for dummy modes
2 parents 8decca2 + 995a82c commit 0545c6e

File tree

7 files changed

+246
-100
lines changed

7 files changed

+246
-100
lines changed

NEWS.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ https://github.com/networkupstools/nut/milestone/9
8181
Driver-code related test-cases were updated to reflect these changes.
8282
[issue #2928, PRs #2931 and #2934]
8383

84+
- `dummy-ups` driver updates:
85+
* A new instruction `ALARM` was added for the `Dummy Mode` operation
86+
of the driver, enabling simulation of UPS alarm states more closely
87+
in line with modern, real-world UPS driver implementations. This
88+
follows the updated principle of keeping alarm states decoupled from
89+
the `ups.status` variable, with alarms now raised via common alarm
90+
functions rather than direct manipulation. [issue #2928, PR #2936]
91+
92+
- `clone`, `clone-outlet`, `nhs_ser` driver and `nutdrv_qx_ablerex`
93+
subdriver updates:
94+
* Refactored to follow modern handling of status and alarm conditions,
95+
aligning with current driver design practices. This includes fixing
96+
copy-paste related issues in alarm reporting and removing some alarm
97+
messages that should instead be reflected as status flags. [#2936]
98+
8499
- `nutdrv_qx` driver updates:
85100
* Introduced `innovart33` protocol support for Ippon Innova RT 3/3 topology
86101
UPSes. [#2938]

docs/man/dummy-ups.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,31 @@ a bit between file-reading cycles (currently this delay is hardcoded to one
189189
second), independently of (and/or in addition to) any `TIMER` keywords and
190190
possibly the common `pollinterval` setting.
191191

192+
Another, more recently introduced instruction is `ALARM`, which allows
193+
the simulation of UPS alarms in much the same way they would be raised
194+
by real driver implementations. Modern drivers decouple alarm states
195+
from the `ups.status` variable, and raising `ALARM` by setting it as a
196+
status token is discouraged in favor of using modern, common functions
197+
for raising alarms within the driver code.
198+
199+
The `ALARM` instruction is intended to simulate this behavior as closely
200+
as possible. The value following an `ALARM` instruction is treated as
201+
the alarm message and is eventually published as the `ups.alarm`
202+
variable, with the `ALARM` token also set in `ups.status` by internal
203+
driver mechanisms, rather than by directly manipulating the variable.
204+
Multiple `ALARM` instructions will have their messages combined into
205+
the `ups.alarm` variable, just as would happen with real driver logic.
206+
207+
Conversely, any `ALARM` instruction on its own will clear active alarm
208+
states. See below for an example of setting and resetting alarms:
209+
210+
ALARM [UPS too warm to charge]
211+
ALARM [UPS circuit is overheating]
212+
TIMER 5
213+
ALARM
214+
TIMER 5
215+
ALARM [UPS too cold to charge]
216+
192217
Repeater Mode
193218
~~~~~~~~~~~~~
194219

drivers/clone-outlet.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#endif /* !WIN32 */
3232

3333
#define DRIVER_NAME "Clone outlet UPS driver"
34-
#define DRIVER_VERSION "0.07"
34+
#define DRIVER_VERSION "0.08"
3535

3636
/* driver description structure */
3737
upsdrv_info_t upsdrv_info = {
@@ -303,7 +303,9 @@ static TYPE_FD sstate_connect(void)
303303
dumpdone = 0;
304304

305305
/* set ups.status to "WAIT" while waiting for the driver response to dumpcmd */
306-
dstate_setinfo("ups.status", "WAIT");
306+
status_init();
307+
status_set("WAIT");
308+
status_commit();
307309

308310
upslogx(LOG_INFO, "Connected to UPS [%s]", device_path);
309311
return fd;
@@ -491,20 +493,20 @@ void upsdrv_updateinfo(void)
491493
return;
492494
}
493495

496+
status_init();
497+
494498
if (outlet.status == 0) {
495499
upsdebugx(2, "OFF flag set (%s: switched off)", prefix.status);
496-
dstate_setinfo("ups.status", "%s OFF", ups.status);
497-
return;
500+
status_set("OFF");
498501
}
499502

500503
if ((outlet.timer.shutdown > -1) && (outlet.timer.shutdown <= outlet.delay.shutdown)) {
501504
upsdebugx(2, "FSD flag set (%s: -1 < [%ld] <= %ld)", prefix.timer.shutdown, outlet.timer.shutdown, outlet.delay.shutdown);
502-
dstate_setinfo("ups.status", "FSD %s", ups.status);
503-
return;
505+
status_set("FSD");
504506
}
505507

506-
upsdebugx(3, "%s: power state not critical", getval("prefix"));
507-
dstate_setinfo("ups.status", "%s", ups.status);
508+
status_set(ups.status); /* FIXME: Split token words? */
509+
status_commit();
508510

509511
last_poll = now;
510512
}

0 commit comments

Comments
 (0)