Skip to content

Commit 737bef0

Browse files
committed
apc_modbus: Add CHRG and DISCHRG status
We use the acceptable input flag and the current battery level to determine if the device status is charging or discharging. Signed-off-by: Axel Gembe <[email protected]>
1 parent dcb2fc3 commit 737bef0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

NEWS.adoc

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

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

drivers/apc_modbus.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 },
@@ -1535,16 +1536,24 @@ void upsdrv_updateinfo(void)
15351536

15361537
/* Dynamic Data */
15371538
if (_apc_modbus_read_registers(modbus_ctx, 128, 32, regbuf)) {
1539+
_apc_modbus_process_registers(apc_modbus_register_map_dynamic, regbuf, 32, 128);
1540+
15381541
/* InputStatus_BF, 1 register */
15391542
_apc_modbus_to_uint64(&regbuf[22], 1, &value);
1543+
if (value & (1 << 0)) {
1544+
// Acceptable input
1545+
if (battery_charge < 100.0) {
1546+
status_set("CHRG");
1547+
}
1548+
} else {
1549+
status_set("DISCHRG");
1550+
}
15401551
if (value & (1 << 5)) {
15411552
status_set("BOOST");
15421553
}
15431554
if (value & (1 << 6)) {
15441555
status_set("TRIM");
15451556
}
1546-
1547-
_apc_modbus_process_registers(apc_modbus_register_map_dynamic, regbuf, 32, 128);
15481557
} else {
15491558
dstate_datastale();
15501559
return;

0 commit comments

Comments
 (0)