Skip to content

Commit ad58b27

Browse files
authored
Merge 6ecb7fe into 373241b
2 parents 373241b + 6ecb7fe commit ad58b27

File tree

6 files changed

+73
-10
lines changed

6 files changed

+73
-10
lines changed

NEWS.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ relocated into new `shutdown.default` INSTCMD definitions. [#2670]
479479
* custom `distcheck-something` targets did not inherit `DISTCHECK_FLAGS`
480480
properly. [#2541]
481481
* added `status_get()` in NUT driver state API, to check if a status
482-
token string had been set recently, and to avoid duplicate settings.
483-
[PR #2565]
482+
token string had been set recently, and to avoid duplicate settings;
483+
fixed `status_set()` for multi-token arguments. [PR #2565, issue #2708]
484484
* local socket/pipe protocol introduced a `LOGOUT` command for cleaner
485485
disconnection handling. [#2572]
486486
* codebase adapted to the liking of `clang-18` and newer revisions of

docs/new-drivers.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ Possible values for status_set:
247247
BOOST -- UPS is boosting incoming voltage
248248
FSD -- Forced Shutdown (restricted use, see the note below)
249249

250+
Internally, an `ALARM` value would be added (typically as first in the list)
251+
if the `ups.alarm` is currently not empty. For more details, see below in
252+
`alarm_set()` description.
253+
250254
Anything else will not be recognized by the usual clients expecting a
251255
particular NUT standard release. New tokens may appear over time, but
252256
driver developers should coordinate with the nut-upsdev list before creating

drivers/bestfortress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#endif
3636

3737
#define DRIVER_NAME "Best Fortress UPS driver"
38-
#define DRIVER_VERSION "0.10"
38+
#define DRIVER_VERSION "0.11"
3939

4040
/* driver description structure */
4141
upsdrv_info_t upsdrv_info = {
@@ -401,13 +401,13 @@ void upsdrv_updateinfo(void)
401401

402402
status_init();
403403
if (low_batt)
404-
status_set("LB ");
404+
status_set("LB");
405405
else if (trimming)
406406
status_set("TRIM");
407407
else if (boosting)
408408
status_set("BOOST");
409409
else
410-
status_set(is_online ? (is_off ? "OFF " : "OL ") : "OB ");
410+
status_set(is_online ? (is_off ? "OFF" : "OL") : "OB");
411411

412412
/* setinfo(INFO_STATUS, "%s%s",
413413
* (util < lownorm) ? "BOOST ", "",

drivers/dstate.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,11 @@ int status_get(const char *buf)
16481648
if (!s)
16491649
return 0;
16501650

1651-
offset = status_buf - s;
1651+
offset = s - status_buf;
1652+
#if 0
1653+
upsdebugx(3, "%s: '%s' in '%s': offset=%" PRIuSIZE" buflen=%" PRIuSIZE" s[buflen]='0x%2X'\n",
1654+
__func__, buf, status_buf, offset, buflen, s[buflen]);
1655+
#endif
16521656
if (offset == 0 || status_buf[offset - 1] == ' ') {
16531657
/* We have hit the start of token */
16541658
if (s[buflen] == '\0' || s[buflen] == ' ') {
@@ -1664,6 +1668,39 @@ int status_get(const char *buf)
16641668
/* add a status element */
16651669
void status_set(const char *buf)
16661670
{
1671+
#if 0
1672+
upsdebugx(3, "%s: '%s'\n", __func__, buf);
1673+
#endif
1674+
if (strstr(buf, " ")) {
1675+
/* Recurse adding each sub-status one by one (avoid duplicates)
1676+
* We frown upon adding "A FEW TOKENS" at once, but in e.g.
1677+
* snmp-ups subdrivers with a mapping table this is not easily
1678+
* avoidable...
1679+
*/
1680+
char *tmp = xstrdup(buf), *p = tmp, *s = tmp;
1681+
while (*p) {
1682+
if (*p == ' ') {
1683+
*p = '\0';
1684+
if (s != p) {
1685+
/* Only recurse to set non-trivial tokens */
1686+
status_set(s);
1687+
}
1688+
p++;
1689+
s = p; /* Start of new word... or a consecutive space to ignore on next cycle */
1690+
} else {
1691+
p++;
1692+
}
1693+
}
1694+
1695+
if (s != p) {
1696+
/* Last valid token did end with (*p=='\0') */
1697+
status_set(s);
1698+
}
1699+
1700+
free(tmp);
1701+
return;
1702+
}
1703+
16671704
if (ignorelb && !strcasecmp(buf, "LB")) {
16681705
upsdebugx(2, "%s: ignoring LB flag from device", __func__);
16691706
return;

drivers/liebert-gxe.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "ydn23.h"
2525

2626
#define DRIVER_NAME "Liebert GXE Series UPS driver"
27-
#define DRIVER_VERSION "0.02"
27+
#define DRIVER_VERSION "0.03"
2828

2929
#define PROBE_RETRIES 3
3030
#define DEFAULT_STALE_RETRIES 3
@@ -173,9 +173,10 @@ static void upsdrv_updateinfo_onoff(void)
173173
status_set("OB");
174174
else if (pwrval == 0x01)
175175
status_set("OL");
176-
else if (pwrval == 0x02)
177-
status_set("OL BYPASS");
178-
else
176+
else if (pwrval == 0x02) {
177+
status_set("OL");
178+
status_set("BYPASS");
179+
} else
179180
upslogx(LOG_WARNING, "unknown ups state: %x %x",
180181
(unsigned int)pwrval,
181182
(unsigned int)rectval);

tests/generic_gpio_utest.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ int main(int argc, char **argv) {
143143
char testDescFileNameBuf[LARGEBUF];
144144
char *testDescFileName = "generic_gpio_test.txt";
145145
unsigned int i;
146+
const char *valueStr = NULL;
146147

147148
test_with_exit=0;
148149

@@ -384,6 +385,26 @@ int main(int argc, char **argv) {
384385
}
385386
}
386387

388+
/* FIXME: Standalone test with driver-program dependencies? */
389+
status_init();
390+
nut_debug_level = 6;
391+
status_set(" OL ");
392+
status_set("OL BOOST");
393+
status_set("OB ");
394+
status_set(" BOOST");
395+
status_commit();
396+
valueStr = dstate_getinfo("ups.status");
397+
nut_debug_level = 0;
398+
if (!strcmp(valueStr, "OL BOOST OB")) {
399+
printf("pass");
400+
cases_passed++;
401+
} else {
402+
printf("fail");
403+
cases_failed++;
404+
}
405+
i++;
406+
printf(" test for ups.status: '%s'; any duplicates?\n", NUT_STRARG(valueStr));
407+
387408
printf("test_rules completed. Total cases %d, passed %d, failed %d\n",
388409
cases_passed+cases_failed, cases_passed, cases_failed);
389410
fclose(testData);

0 commit comments

Comments
 (0)