3
3
* Copyright (C)
4
4
* 2003 - 2008 Arnaud Quette <[email protected] >
5
5
* 2005 Peter Selinger <[email protected] >
6
- * 2011, 2014 Charles Lepple <clepple+nut@gmail>
6
+ * 2011, 2014 Charles Lepple <[email protected] >
7
+ * 2024 James R. Parks <[email protected] >
8
+ * 2024 Jim Klimov <[email protected] >
7
9
*
8
10
* Sponsored by MGE UPS SYSTEMS <http://www.mgeups.com>
9
11
*
31
33
32
34
#include <math.h> /* for fabs() */
33
35
34
- #define BELKIN_HID_VERSION "Belkin/Liebert HID 0.20 "
36
+ #define BELKIN_HID_VERSION "Belkin/Liebert HID 0.21 "
35
37
36
38
/* Belkin */
37
39
#define BELKIN_VENDORID 0x050d
@@ -88,32 +90,39 @@ static const char *liebert_charging_fun(double value);
88
90
static const char * liebert_lowbatt_fun (double value );
89
91
static const char * liebert_replacebatt_fun (double value );
90
92
static const char * liebert_shutdownimm_fun (double value );
93
+
94
+ /* These lookup functions also cover the 1e-7 factor which seems to
95
+ * be due to a broken report descriptor in certain Liebert units.
96
+ * Exposed for unit testing - not "static" */
91
97
static const char * liebert_config_voltage_fun (double value );
92
98
static const char * liebert_line_voltage_fun (double value );
93
- static const char * liebert_psi5_line_voltage_fun (double value );
99
+
100
+ static double liebert_config_voltage_mult = 1.0 ;
101
+ static double liebert_line_voltage_mult = 1.0 ;
102
+ static char liebert_conversion_buf [10 ];
94
103
95
104
static info_lkp_t liebert_online_info [] = {
96
105
{ 0 , NULL , liebert_online_fun , NULL }
97
106
};
98
107
99
108
static info_lkp_t liebert_discharging_info [] = {
100
- { 0 , NULL , liebert_discharging_fun , NULL }
109
+ { 0 , NULL , liebert_discharging_fun , NULL }
101
110
};
102
111
103
112
static info_lkp_t liebert_charging_info [] = {
104
- { 0 , NULL , liebert_charging_fun , NULL }
113
+ { 0 , NULL , liebert_charging_fun , NULL }
105
114
};
106
115
107
116
static info_lkp_t liebert_lowbatt_info [] = {
108
- { 0 , NULL , liebert_lowbatt_fun , NULL }
117
+ { 0 , NULL , liebert_lowbatt_fun , NULL }
109
118
};
110
119
111
120
static info_lkp_t liebert_replacebatt_info [] = {
112
- { 0 , NULL , liebert_replacebatt_fun , NULL }
121
+ { 0 , NULL , liebert_replacebatt_fun , NULL }
113
122
};
114
123
115
124
static info_lkp_t liebert_shutdownimm_info [] = {
116
- { 0 , NULL , liebert_shutdownimm_fun , NULL }
125
+ { 0 , NULL , liebert_shutdownimm_fun , NULL }
117
126
};
118
127
119
128
static info_lkp_t liebert_config_voltage_info [] = {
@@ -124,17 +133,6 @@ static info_lkp_t liebert_line_voltage_info[] = {
124
133
{ 0 , NULL , liebert_line_voltage_fun , NULL },
125
134
};
126
135
127
- static info_lkp_t liebert_psi5_line_voltage_info [] = {
128
- { 0 , NULL , liebert_psi5_line_voltage_fun , NULL },
129
- };
130
-
131
- static double liebert_config_voltage_mult = 1.0 ;
132
- static double liebert_line_voltage_mult = 1.0 ;
133
- static char liebert_conversion_buf [10 ];
134
-
135
- /* These lookup functions also cover the 1e-7 factor which seems to be due to a
136
- * broken report descriptor in certain Liebert units.
137
- */
138
136
static const char * liebert_online_fun (double value )
139
137
{
140
138
return value ? "online" : "!online" ;
@@ -171,8 +169,13 @@ static const char *liebert_shutdownimm_fun(double value)
171
169
*/
172
170
static const char * liebert_config_voltage_fun (double value )
173
171
{
174
- if ( value < 1 ) {
175
- if ( fabs (value - 1e-7 ) < 1e-9 ) {
172
+ /* Does not fire with devices seen diring investigation for
173
+ * https://github.com/networkupstools/nut/issues/2370
174
+ * as the ones seen serve nominal "config" values as integers
175
+ * (e.g. "230" for line and "24" for battery).
176
+ */
177
+ if (value < 1 ) {
178
+ if (fabs (value - 1e-7 ) < 1e-9 ) {
176
179
liebert_config_voltage_mult = 1e8 ;
177
180
liebert_line_voltage_mult = 1e7 ; /* stomp this in case input voltage was low */
178
181
upsdebugx (2 , "ConfigVoltage = %g -> assuming correction factor = %g" ,
@@ -189,26 +192,33 @@ static const char *liebert_config_voltage_fun(double value)
189
192
190
193
static const char * liebert_line_voltage_fun (double value )
191
194
{
192
- if ( value < 1 ) {
193
- if ( fabs (value - 1e-7 ) < 1e-9 ) {
195
+ /* Keep large readings like "230" or "24" as is */
196
+ if (value < 1 ) {
197
+ int picked_scale = 0 ;
198
+ /* NOTE: Start with tiniest scale first */
199
+
200
+ /* Practical use-case for mult=1e7:
201
+ * 1.39e-06 => 13.9
202
+ * 2.201e-05 => 220.1
203
+ * NOTE: The clause below is in fact broken for this use-case,
204
+ * but was present in sources for ages (worked wrongly with an
205
+ * integer-oriented abs() so collapsed into "if (0 < 1e-9) {")!
206
+ * if (fabs(value - 1e-7) < 1e-9) {
207
+ */
208
+ if (fabs (value - 1e-5 ) < 4 * 1e-5 ) {
194
209
liebert_line_voltage_mult = 1e7 ;
195
- upsdebugx (2 , "Input/OutputVoltage = %g -> assuming correction factor = %g" ,
196
- value , liebert_line_voltage_mult );
197
- } else {
198
- upslogx (LOG_NOTICE , "LineVoltage exponent looks wrong, but not correcting." );
210
+ picked_scale = 1 ;
211
+ } else
212
+ /* Practical use-case for mult=1e5:
213
+ * 0.000273 => 27.3
214
+ * 0.001212 => 121.2
215
+ */
216
+ if (fabs (value - 1e-3 ) < 4 * 1e-3 ) {
217
+ liebert_line_voltage_mult = 1e5 ;
218
+ picked_scale = 1 ;
199
219
}
200
- }
201
-
202
- snprintf (liebert_conversion_buf , sizeof (liebert_conversion_buf ), "%.1f" ,
203
- value * liebert_line_voltage_mult );
204
- return liebert_conversion_buf ;
205
- }
206
220
207
- static const char * liebert_psi5_line_voltage_fun (double value )
208
- {
209
- if ( value < 1 ) {
210
- if ( fabs (value - 1e-3 ) < 1e-3 ) {
211
- liebert_line_voltage_mult = 1e5 ;
221
+ if (picked_scale ) {
212
222
upsdebugx (2 , "Input/OutputVoltage = %g -> assuming correction factor = %g" ,
213
223
value , liebert_line_voltage_mult );
214
224
} else {
@@ -507,12 +517,12 @@ static hid_info_t belkin_hid2nut[] = {
507
517
/* Liebert PSI5 */
508
518
{ "input.voltage.nominal" , 0 , 0 , "UPS.Flow.ConfigVoltage" , NULL , "%.0f" , 0 , NULL },
509
519
{ "input.frequency" , 0 , 0 , "UPS.PowerConverter.Input.Frequency" , NULL , "%s" , 0 , divide_by_100_conversion },
510
- { "input.voltage" , 0 , 0 , "UPS.PowerConverter.Input.Voltage" , NULL , "%s" , 0 , liebert_psi5_line_voltage_info },
520
+ { "input.voltage" , 0 , 0 , "UPS.PowerConverter.Input.Voltage" , NULL , "%s" , 0 , liebert_line_voltage_info },
511
521
{ "output.voltage.nominal" , 0 , 0 , "UPS.Flow.ConfigVoltage" , NULL , "%.0f" , 0 , NULL },
512
522
{ "output.frequency" , 0 , 0 , "UPS.PowerConverter.Output.Frequency" , NULL , "%s" , 0 , divide_by_100_conversion },
513
- { "output.voltage" , 0 , 0 , "UPS.PowerConverter.Output.Voltage" , NULL , "%s" , 0 , liebert_psi5_line_voltage_info },
523
+ { "output.voltage" , 0 , 0 , "UPS.PowerConverter.Output.Voltage" , NULL , "%s" , 0 , liebert_line_voltage_info },
514
524
{ "ups.load" , 0 , 0 , "UPS.OutletSystem.Outlet.PercentLoad" , NULL , "%.0f" , 0 , NULL },
515
- { "battery.voltage" , 0 , 0 , "UPS.BatterySystem.Battery.Voltage" , NULL , "%s" , 0 , liebert_psi5_line_voltage_info },
525
+ { "battery.voltage" , 0 , 0 , "UPS.BatterySystem.Battery.Voltage" , NULL , "%s" , 0 , liebert_line_voltage_info },
516
526
{ "battery.voltage.nominal" , 0 , 0 , "UPS.BatterySystem.Battery.ConfigVoltage" , NULL , "%.0f" , 0 , NULL },
517
527
{ "battery.capacity" , 0 , 0 , "UPS.Flow.ConfigApparentPower" , NULL , "%.0f" , 0 , NULL },
518
528
/* status */
0 commit comments