@@ -88,6 +88,7 @@ static int is_usb = 0;
8888static int is_open = 0 ;
8989static double power_nominal ;
9090static double realpower_nominal ;
91+ static double battery_charge ;
9192static 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
851852static 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