@@ -95,6 +95,7 @@ static int is_usb = 0;
9595static int is_open = 0 ;
9696static double power_nominal ;
9797static double realpower_nominal ;
98+ static double battery_charge ;
9899static int64_t last_send_time = 0 ;
99100
100101/* Function declarations */
@@ -894,7 +895,7 @@ static apc_modbus_register_t apc_modbus_register_map_status[] = {
894895
895896static apc_modbus_register_t apc_modbus_register_map_dynamic [] = {
896897 { "battery.runtime" , 128 , 2 , APC_VT_UINT , APC_VF_NONE , NULL , "%" PRIu64 , 0 , NULL },
897- { "battery.charge" , 130 , 1 , APC_VT_UINT , APC_VF_NONE , & _apc_modbus_double_conversion , "%.2f" , 9 , NULL },
898+ { "battery.charge" , 130 , 1 , APC_VT_UINT , APC_VF_NONE , & _apc_modbus_double_conversion , "%.2f" , 9 , & battery_charge },
898899 { "battery.voltage" , 131 , 1 , APC_VT_INT , APC_VF_NONE , & _apc_modbus_double_conversion , "%.2f" , 5 , NULL },
899900 { "battery.date.maintenance" , 133 , 1 , APC_VT_UINT , APC_VF_NONE , & _apc_modbus_date_conversion , NULL , 0 , NULL },
900901 { "battery.temperature" , 135 , 1 , APC_VT_INT , APC_VF_NONE , & _apc_modbus_double_conversion , "%.2f" , 7 , NULL },
@@ -1790,6 +1791,8 @@ void upsdrv_initinfo(void)
17901791void upsdrv_updateinfo (void )
17911792{
17921793 uint16_t regbuf [44 ];
1794+ uint64_t ups_status ;
1795+ uint64_t bat_system_err ;
17931796 uint64_t value ;
17941797 char var_name [64 ];
17951798 size_t i , ri ;
@@ -1809,32 +1812,32 @@ void upsdrv_updateinfo(void)
18091812 /* Status Data */
18101813 if (_apc_modbus_read_registers (modbus_ctx , 0 , 27 , regbuf )) {
18111814 /* UPSStatus_BF, 2 registers */
1812- _apc_modbus_to_uint64 (& regbuf [0 ], 2 , & value );
1813- if (value & (1 << 1 )) {
1815+ _apc_modbus_to_uint64 (& regbuf [0 ], 2 , & ups_status );
1816+ if (ups_status & (1 << 1 )) {
18141817 status_set ("OL" );
18151818 }
1816- if (value & (1 << 2 )) {
1819+ if (ups_status & (1 << 2 )) {
18171820 status_set ("OB" );
18181821 }
1819- if (value & (1 << 3 )) {
1822+ if (ups_status & (1 << 3 )) {
18201823 status_set ("BYPASS" );
18211824 }
1822- if (value & (1 << 4 )) {
1825+ if (ups_status & (1 << 4 )) {
18231826 status_set ("OFF" );
18241827 }
1825- if (value & (1 << 5 )) {
1828+ if (ups_status & (1 << 5 )) {
18261829 alarm_set ("General fault" );
18271830 }
1828- if (value & (1 << 6 )) {
1831+ if (ups_status & (1 << 6 )) {
18291832 alarm_set ("Input not acceptable" );
18301833 }
1831- if (value & (1 << 7 )) {
1834+ if (ups_status & (1 << 7 )) {
18321835 status_set ("TEST" );
18331836 }
1834- if (value & (1 << 13 )) {
1837+ if (ups_status & (1 << 13 )) {
18351838 buzzmode_set ("vendor:apc:HE" ); /* High efficiency / ECO mode*/
18361839 }
1837- if (value & (1 << 21 )) {
1840+ if (ups_status & (1 << 21 )) {
18381841 status_set ("OVER" );
18391842 }
18401843
@@ -1863,8 +1866,8 @@ void upsdrv_updateinfo(void)
18631866 }
18641867
18651868 /* BatterySystemError_BF, 1 register */
1866- _apc_modbus_to_uint64 (& regbuf [18 ], 1 , & value );
1867- if (value & (1 << 1 )) { /* NeedsReplacement */
1869+ _apc_modbus_to_uint64 (& regbuf [22 ], 1 , & bat_system_err );
1870+ if (bat_system_err & (1 << 1 )) { /* NeedsReplacement */
18681871 status_set ("RB" );
18691872 }
18701873
@@ -1874,6 +1877,17 @@ void upsdrv_updateinfo(void)
18741877 status_set ("CAL" );
18751878 }
18761879
1880+ /* No battery error ? */
1881+ if (bat_system_err == 0 ) {
1882+ if (ups_status & (1 << 1 )) {
1883+ status_set ("CHRG" );
1884+ }
1885+ if (ups_status & (1 << 2 )) {
1886+ status_set ("DISCHRG" );
1887+ }
1888+
1889+ }
1890+
18771891 _apc_modbus_process_registers (apc_modbus_register_map_status , regbuf , 27 , 0 );
18781892 } else {
18791893 dstate_datastale ();
@@ -1882,16 +1896,24 @@ void upsdrv_updateinfo(void)
18821896
18831897 /* Dynamic Data */
18841898 if (_apc_modbus_read_registers (modbus_ctx , 128 , 44 , regbuf )) {
1899+ _apc_modbus_process_registers (apc_modbus_register_map_dynamic , regbuf , 44 , 128 );
1900+
18851901 /* InputStatus_BF, 1 register */
18861902 _apc_modbus_to_uint64 (& regbuf [22 ], 1 , & value );
1903+ if (value & (1 << 0 )) {
1904+ // Acceptable input
1905+ if (battery_charge < 100.0 ) {
1906+ status_set ("CHRG" );
1907+ }
1908+ } else {
1909+ status_set ("DISCHRG" );
1910+ }
18871911 if (value & (1 << 5 )) {
18881912 status_set ("BOOST" );
18891913 }
18901914 if (value & (1 << 6 )) {
18911915 status_set ("TRIM" );
18921916 }
1893-
1894- _apc_modbus_process_registers (apc_modbus_register_map_dynamic , regbuf , 44 , 128 );
18951917 } else {
18961918 dstate_datastale ();
18971919 return ;
0 commit comments