Skip to content

Commit 97797af

Browse files
authored
Merge 191e9e1 into 9f76f3f
2 parents 9f76f3f + 191e9e1 commit 97797af

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

NEWS.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ https://github.com/networkupstools/nut/milestone/9
146146
* The time stamp and inter-frame delay accounting was fixed, alleviating
147147
one of the problems reported in issue #2609. [PR #2982]
148148
* Fix missing variables due to mismatching format string. [PR #3013]
149+
* Add CHRG and DISCHRG status. [PR #3014]
149150

150151
- `bcmxcp` driver updates:
151152
* The latching on to a previous replace battery status was fixed, with its

drivers/apc_modbus.c

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#endif
4545

4646
#define DRIVER_NAME "NUT APC Modbus driver " DRIVER_NAME_NUT_MODBUS_HAS_USB_WITH_STR " USB support (libmodbus link type: " NUT_MODBUS_LINKTYPE_STR ")"
47-
#define DRIVER_VERSION "0.16"
47+
#define DRIVER_VERSION "0.17"
4848

4949
#if defined NUT_MODBUS_HAS_USB
5050

@@ -88,6 +88,7 @@ static int is_usb = 0;
8888
static int is_open = 0;
8989
static double power_nominal;
9090
static double realpower_nominal;
91+
static double battery_charge;
9192
static int64_t last_send_time = 0;
9293

9394
/* Function declarations */
@@ -850,7 +851,7 @@ static apc_modbus_register_t apc_modbus_register_map_status[] = {
850851

851852
static apc_modbus_register_t apc_modbus_register_map_dynamic[] = {
852853
{ "battery.runtime", 128, 2, APC_VT_UINT, 0, NULL, "%" PRIu64, 0, NULL },
853-
{ "battery.charge", 130, 1, APC_VT_UINT, 0, &_apc_modbus_double_conversion, "%.2f", 9, NULL },
854+
{ "battery.charge", 130, 1, APC_VT_UINT, 0, &_apc_modbus_double_conversion, "%.2f", 9, &battery_charge },
854855
{ "battery.voltage", 131, 1, APC_VT_INT, 0, &_apc_modbus_double_conversion, "%.2f", 5, NULL },
855856
{ "battery.date.maintenance", 133, 1, APC_VT_UINT, 0, &_apc_modbus_date_conversion, NULL, 0, NULL },
856857
{ "battery.temperature", 135, 1, APC_VT_INT, 0, &_apc_modbus_double_conversion, "%.2f", 7, NULL },
@@ -1460,6 +1461,8 @@ void upsdrv_initinfo(void)
14601461
void upsdrv_updateinfo(void)
14611462
{
14621463
uint16_t regbuf[32];
1464+
uint64_t ups_status;
1465+
uint64_t bat_system_err;
14631466
uint64_t value;
14641467

14651468
if (!is_open) {
@@ -1477,32 +1480,32 @@ void upsdrv_updateinfo(void)
14771480
/* Status Data */
14781481
if (_apc_modbus_read_registers(modbus_ctx, 0, 27, regbuf)) {
14791482
/* UPSStatus_BF, 2 registers */
1480-
_apc_modbus_to_uint64(&regbuf[0], 2, &value);
1481-
if (value & (1 << 1)) {
1483+
_apc_modbus_to_uint64(&regbuf[0], 2, &ups_status);
1484+
if (ups_status & (1 << 1)) {
14821485
status_set("OL");
14831486
}
1484-
if (value & (1 << 2)) {
1487+
if (ups_status & (1 << 2)) {
14851488
status_set("OB");
14861489
}
1487-
if (value & (1 << 3)) {
1490+
if (ups_status & (1 << 3)) {
14881491
status_set("BYPASS");
14891492
}
1490-
if (value & (1 << 4)) {
1493+
if (ups_status & (1 << 4)) {
14911494
status_set("OFF");
14921495
}
1493-
if (value & (1 << 5)) {
1496+
if (ups_status & (1 << 5)) {
14941497
alarm_set("General fault");
14951498
}
1496-
if (value & (1 << 6)) {
1499+
if (ups_status & (1 << 6)) {
14971500
alarm_set("Input not acceptable");
14981501
}
1499-
if (value & (1 << 7)) {
1502+
if (ups_status & (1 << 7)) {
15001503
status_set("TEST");
15011504
}
1502-
if (value & (1 << 13)) {
1505+
if (ups_status & (1 << 13)) {
15031506
buzzmode_set("vendor:apc:HE"); /* High efficiency / ECO mode*/
15041507
}
1505-
if (value & (1 << 21)) {
1508+
if (ups_status & (1 << 21)) {
15061509
status_set("OVER");
15071510
}
15081511

@@ -1513,8 +1516,8 @@ void upsdrv_updateinfo(void)
15131516
}
15141517

15151518
/* BatterySystemError_BF, 1 register */
1516-
_apc_modbus_to_uint64(&regbuf[18], 1, &value);
1517-
if (value & (1 << 1)) { /* NeedsReplacement */
1519+
_apc_modbus_to_uint64(&regbuf[22], 1, &bat_system_err);
1520+
if (bat_system_err & (1 << 1)) { /* NeedsReplacement */
15181521
status_set("RB");
15191522
}
15201523

@@ -1524,6 +1527,17 @@ void upsdrv_updateinfo(void)
15241527
status_set("CAL");
15251528
}
15261529

1530+
/* No battery error ? */
1531+
if (bat_system_err == 0) {
1532+
if (ups_status & (1 << 1)) {
1533+
status_set("CHRG");
1534+
}
1535+
if (ups_status & (1 << 2)) {
1536+
status_set("DISCHRG");
1537+
}
1538+
1539+
}
1540+
15271541
_apc_modbus_process_registers(apc_modbus_register_map_status, regbuf, 27, 0);
15281542
} else {
15291543
dstate_datastale();
@@ -1532,16 +1546,24 @@ void upsdrv_updateinfo(void)
15321546

15331547
/* Dynamic Data */
15341548
if (_apc_modbus_read_registers(modbus_ctx, 128, 32, regbuf)) {
1549+
_apc_modbus_process_registers(apc_modbus_register_map_dynamic, regbuf, 32, 128);
1550+
15351551
/* InputStatus_BF, 1 register */
15361552
_apc_modbus_to_uint64(&regbuf[22], 1, &value);
1553+
if (value & (1 << 0)) {
1554+
// Acceptable input
1555+
if (battery_charge < 100.0) {
1556+
status_set("CHRG");
1557+
}
1558+
} else {
1559+
status_set("DISCHRG");
1560+
}
15371561
if (value & (1 << 5)) {
15381562
status_set("BOOST");
15391563
}
15401564
if (value & (1 << 6)) {
15411565
status_set("TRIM");
15421566
}
1543-
1544-
_apc_modbus_process_registers(apc_modbus_register_map_dynamic, regbuf, 32, 128);
15451567
} else {
15461568
dstate_datastale();
15471569
return;

0 commit comments

Comments
 (0)