Skip to content

Commit

Permalink
mge-shut/usbhid-ups: compute Output load for Eaton UPS
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
arnaudquette-eaton committed Nov 17, 2017
1 parent 704459f commit b7f7043
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
4 changes: 2 additions & 2 deletions drivers/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ USBHID_UPS_SUBDRIVERS = apc-hid.c belkin-hid.c cps-hid.c explore-hid.c \
openups-hid.c
usbhid_ups_SOURCES = usbhid-ups.c libhid.c libusb.c hidparser.c \
usb-common.c $(USBHID_UPS_SUBDRIVERS)
usbhid_ups_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS)
usbhid_ups_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm

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

# SNMP
snmp_ups_SOURCES = snmp-ups.c apc-mib.c baytech-mib.c compaq-mib.c \
Expand Down
39 changes: 38 additions & 1 deletion drivers/mge-hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
#include "main.h" /* for getval() */
#include "usbhid-ups.h"
#include "mge-hid.h"
#include <math.h>

#define MGE_HID_VERSION "MGE HID 1.42"
#define MGE_HID_VERSION "MGE HID 1.43"

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

/* When UPS.PowerConverter.Output.ActivePower is not present,
* compute a realpower approximation using available data */
static const char *eaton_compute_realpower_fun(double value)
{
const char *str_ups_load = dstate_getinfo("ups.load");
const char *str_power_nominal = dstate_getinfo("ups.power.nominal");
const char *str_powerfactor = dstate_getinfo("output.powerfactor");
float powerfactor = 0.80;
int power_nominal = 0;
int ups_load = 0;
double realpower = 0;
if (str_power_nominal && str_ups_load) {
/* Extract needed values */
ups_load = atoi(str_ups_load);
power_nominal = atoi(str_power_nominal);
if (str_powerfactor)
powerfactor = atoi(str_powerfactor);
/* Compute the value */
realpower = round(ups_load * 0.01 * power_nominal * powerfactor);
snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.0f", realpower);
upsdebugx(1, "eaton_compute_realpower_fun(%s)", mge_scratch_buf);
return mge_scratch_buf;
}
/* else can't process */
/* Return NULL, not to get the value published! */
return NULL;
}

static info_lkp_t eaton_compute_realpower_info[] = {
{ 0, "dummy", eaton_compute_realpower_fun },
{ 0, NULL, NULL }
};

/* Limit nominal output voltage according to HV or LV models */
static const char *nominal_output_voltage_fun(double value)
{
Expand Down Expand Up @@ -1153,6 +1187,9 @@ static hid_info_t mge_hid2nut[] =
{ "ups.L3.power", 0, 0, "UPS.PowerConverter.Output.Phase.[3].ApparentPower", NULL, "%.0f", 0, NULL },
{ "ups.power.nominal", 0, 0, "UPS.Flow.[4].ConfigApparentPower", NULL, "%.0f", HU_FLAG_STATIC, NULL },
{ "ups.realpower", 0, 0, "UPS.PowerConverter.Output.ActivePower", NULL, "%.0f", 0, NULL },
/* When not available, process an approximation from other data,
* but map to apparent power to be called */
{ "ups.realpower", 0, 0, "UPS.Flow.[4].ConfigApparentPower", NULL, "-1", 0, eaton_compute_realpower_info },
{ "ups.L1.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[1].ActivePower", NULL, "%.0f", 0, NULL },
{ "ups.L2.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[2].ActivePower", NULL, "%.0f", 0, NULL },
{ "ups.L3.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[3].ActivePower", NULL, "%.0f", 0, NULL },
Expand Down

0 comments on commit b7f7043

Please sign in to comment.