Skip to content

Commit b7f7043

Browse files
mge-shut/usbhid-ups: compute Output load for Eaton UPS
When HID data UPS.PowerConverter.Output.ActivePower is not present, compute a realpower approximation using available data. This is needed for Eaton 5E and some other units Closes: #484 Signed-off-by: Arnaud Quette <ArnaudQuette@Eaton.com>
1 parent 704459f commit b7f7043

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

drivers/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ USBHID_UPS_SUBDRIVERS = apc-hid.c belkin-hid.c cps-hid.c explore-hid.c \
173173
openups-hid.c
174174
usbhid_ups_SOURCES = usbhid-ups.c libhid.c libusb.c hidparser.c \
175175
usb-common.c $(USBHID_UPS_SUBDRIVERS)
176-
usbhid_ups_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS)
176+
usbhid_ups_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm
177177

178178
tripplite_usb_SOURCES = tripplite_usb.c libusb.c usb-common.c
179179
tripplite_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm
@@ -198,7 +198,7 @@ riello_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm
198198
mge_shut_SOURCES = usbhid-ups.c libshut.c libhid.c hidparser.c mge-hid.c
199199
# per-target CFLAGS are necessary here
200200
mge_shut_CFLAGS = $(AM_CFLAGS) -DSHUT_MODE
201-
mge_shut_LDADD = $(LDADD)
201+
mge_shut_LDADD = $(LDADD) -lm
202202

203203
# SNMP
204204
snmp_ups_SOURCES = snmp-ups.c apc-mib.c baytech-mib.c compaq-mib.c \

drivers/mge-hid.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
#include "main.h" /* for getval() */
3737
#include "usbhid-ups.h"
3838
#include "mge-hid.h"
39+
#include <math.h>
3940

40-
#define MGE_HID_VERSION "MGE HID 1.42"
41+
#define MGE_HID_VERSION "MGE HID 1.43"
4142

4243
/* (prev. MGE Office Protection Systems, prev. MGE UPS SYSTEMS) */
4344
/* Eaton */
@@ -653,6 +654,39 @@ static info_lkp_t eaton_check_country_info[] = {
653654
{ 0, NULL, NULL }
654655
};
655656

657+
/* When UPS.PowerConverter.Output.ActivePower is not present,
658+
* compute a realpower approximation using available data */
659+
static const char *eaton_compute_realpower_fun(double value)
660+
{
661+
const char *str_ups_load = dstate_getinfo("ups.load");
662+
const char *str_power_nominal = dstate_getinfo("ups.power.nominal");
663+
const char *str_powerfactor = dstate_getinfo("output.powerfactor");
664+
float powerfactor = 0.80;
665+
int power_nominal = 0;
666+
int ups_load = 0;
667+
double realpower = 0;
668+
if (str_power_nominal && str_ups_load) {
669+
/* Extract needed values */
670+
ups_load = atoi(str_ups_load);
671+
power_nominal = atoi(str_power_nominal);
672+
if (str_powerfactor)
673+
powerfactor = atoi(str_powerfactor);
674+
/* Compute the value */
675+
realpower = round(ups_load * 0.01 * power_nominal * powerfactor);
676+
snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.0f", realpower);
677+
upsdebugx(1, "eaton_compute_realpower_fun(%s)", mge_scratch_buf);
678+
return mge_scratch_buf;
679+
}
680+
/* else can't process */
681+
/* Return NULL, not to get the value published! */
682+
return NULL;
683+
}
684+
685+
static info_lkp_t eaton_compute_realpower_info[] = {
686+
{ 0, "dummy", eaton_compute_realpower_fun },
687+
{ 0, NULL, NULL }
688+
};
689+
656690
/* Limit nominal output voltage according to HV or LV models */
657691
static const char *nominal_output_voltage_fun(double value)
658692
{
@@ -1153,6 +1187,9 @@ static hid_info_t mge_hid2nut[] =
11531187
{ "ups.L3.power", 0, 0, "UPS.PowerConverter.Output.Phase.[3].ApparentPower", NULL, "%.0f", 0, NULL },
11541188
{ "ups.power.nominal", 0, 0, "UPS.Flow.[4].ConfigApparentPower", NULL, "%.0f", HU_FLAG_STATIC, NULL },
11551189
{ "ups.realpower", 0, 0, "UPS.PowerConverter.Output.ActivePower", NULL, "%.0f", 0, NULL },
1190+
/* When not available, process an approximation from other data,
1191+
* but map to apparent power to be called */
1192+
{ "ups.realpower", 0, 0, "UPS.Flow.[4].ConfigApparentPower", NULL, "-1", 0, eaton_compute_realpower_info },
11561193
{ "ups.L1.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[1].ActivePower", NULL, "%.0f", 0, NULL },
11571194
{ "ups.L2.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[2].ActivePower", NULL, "%.0f", 0, NULL },
11581195
{ "ups.L3.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[3].ActivePower", NULL, "%.0f", 0, NULL },

0 commit comments

Comments
 (0)