44
44
#endif
45
45
46
46
#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 "
48
48
49
49
#if defined NUT_MODBUS_HAS_USB
50
50
@@ -88,6 +88,7 @@ static int is_usb = 0;
88
88
static int is_open = 0 ;
89
89
static double power_nominal ;
90
90
static double realpower_nominal ;
91
+ static double battery_charge ;
91
92
static int64_t last_send_time = 0 ;
92
93
93
94
/* Function declarations */
@@ -850,7 +851,7 @@ static apc_modbus_register_t apc_modbus_register_map_status[] = {
850
851
851
852
static apc_modbus_register_t apc_modbus_register_map_dynamic [] = {
852
853
{ "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 },
854
855
{ "battery.voltage" , 131 , 1 , APC_VT_INT , 0 , & _apc_modbus_double_conversion , "%.2f" , 5 , NULL },
855
856
{ "battery.date.maintenance" , 133 , 1 , APC_VT_UINT , 0 , & _apc_modbus_date_conversion , NULL , 0 , NULL },
856
857
{ "battery.temperature" , 135 , 1 , APC_VT_INT , 0 , & _apc_modbus_double_conversion , "%.2f" , 7 , NULL },
@@ -1460,6 +1461,8 @@ void upsdrv_initinfo(void)
1460
1461
void upsdrv_updateinfo (void )
1461
1462
{
1462
1463
uint16_t regbuf [32 ];
1464
+ uint64_t ups_status ;
1465
+ uint64_t bat_system_err ;
1463
1466
uint64_t value ;
1464
1467
1465
1468
if (!is_open ) {
@@ -1477,32 +1480,32 @@ void upsdrv_updateinfo(void)
1477
1480
/* Status Data */
1478
1481
if (_apc_modbus_read_registers (modbus_ctx , 0 , 27 , regbuf )) {
1479
1482
/* 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 )) {
1482
1485
status_set ("OL" );
1483
1486
}
1484
- if (value & (1 << 2 )) {
1487
+ if (ups_status & (1 << 2 )) {
1485
1488
status_set ("OB" );
1486
1489
}
1487
- if (value & (1 << 3 )) {
1490
+ if (ups_status & (1 << 3 )) {
1488
1491
status_set ("BYPASS" );
1489
1492
}
1490
- if (value & (1 << 4 )) {
1493
+ if (ups_status & (1 << 4 )) {
1491
1494
status_set ("OFF" );
1492
1495
}
1493
- if (value & (1 << 5 )) {
1496
+ if (ups_status & (1 << 5 )) {
1494
1497
alarm_set ("General fault" );
1495
1498
}
1496
- if (value & (1 << 6 )) {
1499
+ if (ups_status & (1 << 6 )) {
1497
1500
alarm_set ("Input not acceptable" );
1498
1501
}
1499
- if (value & (1 << 7 )) {
1502
+ if (ups_status & (1 << 7 )) {
1500
1503
status_set ("TEST" );
1501
1504
}
1502
- if (value & (1 << 13 )) {
1505
+ if (ups_status & (1 << 13 )) {
1503
1506
buzzmode_set ("vendor:apc:HE" ); /* High efficiency / ECO mode*/
1504
1507
}
1505
- if (value & (1 << 21 )) {
1508
+ if (ups_status & (1 << 21 )) {
1506
1509
status_set ("OVER" );
1507
1510
}
1508
1511
@@ -1513,8 +1516,8 @@ void upsdrv_updateinfo(void)
1513
1516
}
1514
1517
1515
1518
/* 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 */
1518
1521
status_set ("RB" );
1519
1522
}
1520
1523
@@ -1524,6 +1527,17 @@ void upsdrv_updateinfo(void)
1524
1527
status_set ("CAL" );
1525
1528
}
1526
1529
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
+
1527
1541
_apc_modbus_process_registers (apc_modbus_register_map_status , regbuf , 27 , 0 );
1528
1542
} else {
1529
1543
dstate_datastale ();
@@ -1532,16 +1546,24 @@ void upsdrv_updateinfo(void)
1532
1546
1533
1547
/* Dynamic Data */
1534
1548
if (_apc_modbus_read_registers (modbus_ctx , 128 , 32 , regbuf )) {
1549
+ _apc_modbus_process_registers (apc_modbus_register_map_dynamic , regbuf , 32 , 128 );
1550
+
1535
1551
/* InputStatus_BF, 1 register */
1536
1552
_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
+ }
1537
1561
if (value & (1 << 5 )) {
1538
1562
status_set ("BOOST" );
1539
1563
}
1540
1564
if (value & (1 << 6 )) {
1541
1565
status_set ("TRIM" );
1542
1566
}
1543
-
1544
- _apc_modbus_process_registers (apc_modbus_register_map_dynamic , regbuf , 32 , 128 );
1545
1567
} else {
1546
1568
dstate_datastale ();
1547
1569
return ;
0 commit comments