Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ https://github.com/networkupstools/nut/milestone/9
* The time stamp and inter-frame delay accounting was fixed, alleviating
one of the problems reported in issue #2609. [PR #2982]
* Fix missing variables due to mismatching format string. [PR #3013]
* Add CHRG and DISCHRG status. [PR #3014]

- `bcmxcp` driver updates:
* The latching on to a previous replace battery status was fixed, with its
Expand Down
54 changes: 38 additions & 16 deletions drivers/apc_modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#endif

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

#if defined NUT_MODBUS_HAS_USB

Expand Down Expand Up @@ -88,6 +88,7 @@ static int is_usb = 0;
static int is_open = 0;
static double power_nominal;
static double realpower_nominal;
static double battery_charge;
static int64_t last_send_time = 0;

/* Function declarations */
Expand Down Expand Up @@ -850,7 +851,7 @@ static apc_modbus_register_t apc_modbus_register_map_status[] = {

static apc_modbus_register_t apc_modbus_register_map_dynamic[] = {
{ "battery.runtime", 128, 2, APC_VT_UINT, 0, NULL, "%" PRIu64, 0, NULL },
{ "battery.charge", 130, 1, APC_VT_UINT, 0, &_apc_modbus_double_conversion, "%.2f", 9, NULL },
{ "battery.charge", 130, 1, APC_VT_UINT, 0, &_apc_modbus_double_conversion, "%.2f", 9, &battery_charge },
{ "battery.voltage", 131, 1, APC_VT_INT, 0, &_apc_modbus_double_conversion, "%.2f", 5, NULL },
{ "battery.date.maintenance", 133, 1, APC_VT_UINT, 0, &_apc_modbus_date_conversion, NULL, 0, NULL },
{ "battery.temperature", 135, 1, APC_VT_INT, 0, &_apc_modbus_double_conversion, "%.2f", 7, NULL },
Expand Down Expand Up @@ -1460,6 +1461,8 @@ void upsdrv_initinfo(void)
void upsdrv_updateinfo(void)
{
uint16_t regbuf[32];
uint64_t ups_status;
uint64_t bat_system_err;
uint64_t value;

if (!is_open) {
Expand All @@ -1477,32 +1480,32 @@ void upsdrv_updateinfo(void)
/* Status Data */
if (_apc_modbus_read_registers(modbus_ctx, 0, 27, regbuf)) {
/* UPSStatus_BF, 2 registers */
_apc_modbus_to_uint64(&regbuf[0], 2, &value);
if (value & (1 << 1)) {
_apc_modbus_to_uint64(&regbuf[0], 2, &ups_status);
if (ups_status & (1 << 1)) {
status_set("OL");
}
if (value & (1 << 2)) {
if (ups_status & (1 << 2)) {
status_set("OB");
}
if (value & (1 << 3)) {
if (ups_status & (1 << 3)) {
status_set("BYPASS");
}
if (value & (1 << 4)) {
if (ups_status & (1 << 4)) {
status_set("OFF");
}
if (value & (1 << 5)) {
if (ups_status & (1 << 5)) {
alarm_set("General fault");
}
if (value & (1 << 6)) {
if (ups_status & (1 << 6)) {
alarm_set("Input not acceptable");
}
if (value & (1 << 7)) {
if (ups_status & (1 << 7)) {
status_set("TEST");
}
if (value & (1 << 13)) {
if (ups_status & (1 << 13)) {
buzzmode_set("vendor:apc:HE"); /* High efficiency / ECO mode*/
}
if (value & (1 << 21)) {
if (ups_status & (1 << 21)) {
status_set("OVER");
}

Expand All @@ -1513,8 +1516,8 @@ void upsdrv_updateinfo(void)
}

/* BatterySystemError_BF, 1 register */
_apc_modbus_to_uint64(&regbuf[18], 1, &value);
if (value & (1 << 1)) { /* NeedsReplacement */
_apc_modbus_to_uint64(&regbuf[22], 1, &bat_system_err);
if (bat_system_err & (1 << 1)) { /* NeedsReplacement */
status_set("RB");
}

Expand All @@ -1524,6 +1527,17 @@ void upsdrv_updateinfo(void)
status_set("CAL");
}

/* No battery error ? */
if (bat_system_err == 0) {
if (ups_status & (1 << 1)) {
status_set("CHRG");
}
if (ups_status & (1 << 2)) {
status_set("DISCHRG");
}

}

_apc_modbus_process_registers(apc_modbus_register_map_status, regbuf, 27, 0);
} else {
dstate_datastale();
Expand All @@ -1532,16 +1546,24 @@ void upsdrv_updateinfo(void)

/* Dynamic Data */
if (_apc_modbus_read_registers(modbus_ctx, 128, 32, regbuf)) {
_apc_modbus_process_registers(apc_modbus_register_map_dynamic, regbuf, 32, 128);

/* InputStatus_BF, 1 register */
_apc_modbus_to_uint64(&regbuf[22], 1, &value);
if (value & (1 << 0)) {
// Acceptable input
if (battery_charge < 100.0) {
status_set("CHRG");
}
} else {
status_set("DISCHRG");
}
if (value & (1 << 5)) {
status_set("BOOST");
}
if (value & (1 << 6)) {
status_set("TRIM");
}

_apc_modbus_process_registers(apc_modbus_register_map_dynamic, regbuf, 32, 128);
} else {
dstate_datastale();
return;
Expand Down