Imported Upstream version 2.6.4

This commit is contained in:
Arnaud Quette 2012-06-01 15:55:19 +02:00
parent fad6ced6f6
commit fefe62b2bd
257 changed files with 6020 additions and 1394 deletions

View file

@ -1,6 +1,6 @@
/* mge-hid.c - data to monitor MGE UPS SYSTEMS HID (USB and serial) devices
/* mge-hid.c - data to monitor Eaton / MGE HID (USB and serial) devices
*
* Copyright (C) 2003 - 2009
* Copyright (C) 2003 - 2012
* Arnaud Quette <arnaud.quette@free.fr>
*
* Sponsored by MGE UPS SYSTEMS <http://www.mgeups.com>
@ -22,11 +22,21 @@
*
*/
/* TODO list:
* - better processing of FW info:
* * some models (HP R5000) include firmware.aux (00.01.0021;00.01.00)
* * other (9130) need more processing (0128 => 1.28)
* ...
* - better handling of input.transfer.* (need dstate_addrange)
* - outlet management logic (Ie, for outlet.X.load.{on,off}.delay
* => use outlet.X.delay.{start,stop}
*/
#include "main.h" /* for getval() */
#include "usbhid-ups.h"
#include "mge-hid.h"
#define MGE_HID_VERSION "MGE HID 1.27"
#define MGE_HID_VERSION "MGE HID 1.31"
/* (prev. MGE Office Protection Systems, prev. MGE UPS SYSTEMS) */
/* Eaton */
@ -38,6 +48,9 @@
/* Powerware */
#define POWERWARE_VENDORID 0x0592
/* Hewlett Packard */
#define HP_VENDORID 0x03f0
#ifndef SHUT_MODE
#include "usb-common.h"
@ -53,6 +66,14 @@ static usb_device_id_t mge_usb_device_table[] = {
/* PW 9140 */
{ USB_DEVICE(POWERWARE_VENDORID, 0x0004), NULL },
/* R/T3000 */
{ USB_DEVICE(HP_VENDORID, 0x1fe5), NULL },
/* R/T3000 */
{ USB_DEVICE(HP_VENDORID, 0x1fe6), NULL },
/* various models */
{ USB_DEVICE(HP_VENDORID, 0x1fe7), NULL },
{ USB_DEVICE(HP_VENDORID, 0x1fe8), NULL },
/* Terminating entry */
{ -1, -1, NULL }
};
@ -326,6 +347,53 @@ static info_lkp_t pegasus_threshold_info[] = {
{ 0, NULL, NULL }
};
/* allow limiting standard yes/no info (here, to enable ECO mode) to
* ups.model = Protection Station, Ellipse Eco and 3S (US 750 and AUS 700 only!)
* this allows to enable special flags used in hid_info_t entries (Ie RW) */
static const char *pegasus_yes_no_info_fun(double value)
{
switch (mge_type & 0xFF00) /* Ignore model byte */
{
case MGE_PEGASUS:
break;
case MGE_3S:
/* Only consider non European models */
if (country_code != COUNTRY_EUROPE)
break;
default:
return NULL;
}
return (value == 0) ? "no" : "yes";
}
/* Conversion back of yes/no info */
static double pegasus_yes_no_info_nuf(const char *value)
{
switch (mge_type & 0xFF00) /* Ignore model byte */
{
case MGE_PEGASUS:
break;
case MGE_3S:
/* Only consider non European models */
if (country_code != COUNTRY_EUROPE)
break;
default:
return 0;
}
if (!strncmp(value, "yes", 3))
return 1;
else
return 0;
}
info_lkp_t pegasus_yes_no_info[] = {
{ 0, "no", pegasus_yes_no_info_fun, pegasus_yes_no_info_nuf },
{ 1, "yes", pegasus_yes_no_info_fun, pegasus_yes_no_info_nuf },
{ 0, NULL, NULL }
};
/* Determine country using UPS.PowerSummary.Country.
* If not present:
* if PowerConverter.Output.Voltage >= 200 => "Europe"
@ -448,7 +516,7 @@ static info_lkp_t nominal_output_voltage_info[] = {
/* Vendor-specific usage table */
/* --------------------------------------------------------------- */
/* MGE UPS SYSTEMS usage table */
/* Eaton / MGE HID usage table */
static usage_lkp_t mge_usage_lkp[] = {
{ "Undefined", 0xffff0000 },
{ "STS", 0xffff0001 },
@ -474,7 +542,7 @@ static usage_lkp_t mge_usage_lkp[] = {
{ "EventID", 0xffff001f },
{ "CircuitBreaker", 0xffff0020 },
{ "TransferForbidden", 0xffff0021 },
{ "OverallAlarm", 0xffff0022 },
{ "OverallAlarm", 0xffff0022 }, /* renamed to Alarm in Eaton SW! */
{ "Dephasing", 0xffff0023 },
{ "BypassBreaker", 0xffff0024 },
{ "PowerModule", 0xffff0025 },
@ -486,8 +554,9 @@ static usage_lkp_t mge_usage_lkp[] = {
{ "NotificationStatus", 0xffff002b },
{ "ProtectionLost", 0xffff002c },
{ "ConfigurationFailure", 0xffff002d },
{ "CompatibilityFailure", 0xffff002e },
/* 0xffff002e-0xffff003f => Reserved */
{ "SwitchType", 0xffff0040 },
{ "SwitchType", 0xffff0040 }, /* renamed to Type in Eaton SW! */
{ "ConverterType", 0xffff0041 },
{ "FrequencyConverterMode", 0xffff0042 },
{ "AutomaticRestart", 0xffff0043 },
@ -556,8 +625,12 @@ static usage_lkp_t mge_usage_lkp[] = {
{ "HighHumidity", 0xffff0082 },
{ "LowTemperature", 0xffff0083 },
{ "HighTemperature", 0xffff0084 },
/* 0xffff0085-0xffff008f (minus 0xffff0086) => Reserved */
{ "ECOControl", 0xffff0085 },
{ "Efficiency", 0xffff0086 },
{ "ABMEnable", 0xffff0087 },
{ "NegativeCurrent", 0xffff0088 },
{ "AutomaticStart", 0xffff0089 },
/* 0xffff008a-0xffff008f => Reserved */
{ "Count", 0xffff0090 },
{ "Timer", 0xffff0091 },
{ "Interval", 0xffff0092 },
@ -569,16 +642,26 @@ static usage_lkp_t mge_usage_lkp[] = {
{ "Code", 0xffff0098 },
{ "DataValid", 0xffff0099 },
{ "ToggleTimer", 0xffff009a },
/* 0xffff009b-0xffff009f => Reserved */
{ "PDU", 0xffff00a0 },
{ "BypassTransferDelay", 0xffff009b },
{ "HysteresysVoltageTransfer", 0xffff009c },
{ "SlewRate", 0xffff009d },
/* 0xffff009e-0xffff009f => Reserved */
{ "PDU", 0xffff00a0 },
{ "Breaker", 0xffff00a1 },
{ "BreakerID", 0xffff00a2 },
{ "OverVoltage", 0xffff00a3 },
{ "OverVoltage", 0xffff00a3 },
{ "Tripped", 0xffff00a4 },
{ "OverEnergy", 0xffff00a5 },
{ "OverHumidity", 0xffff00a6 },
{ "LCDControl", 0xffff00a6 },
/* 0xffff00a8-0xffff00df => Reserved */
{ "OverHumidity", 0xffff00a6 },
{ "ConfigurationReset", 0xffff00a7 }, /* renamed from LCDControl in Eaton SW! */
{ "Level", 0xffff00a8 },
{ "PDUType", 0xffff00a9 },
{ "ReactivePower", 0xffff00aa },
{ "Pole", 0xffff00ab },
{ "PoleID", 0xffff00ac },
{ "Reset", 0xffff00ad },
{ "WatchdogReset", 0xffff00ae },
/* 0xffff00af-0xffff00df => Reserved */
{ "COPIBridge", 0xffff00e0 },
/* 0xffff00e1-0xffff00ef => Reserved */
{ "iModel", 0xffff00f0 },
@ -586,7 +669,8 @@ static usage_lkp_t mge_usage_lkp[] = {
{ "iTechnicalLevel", 0xffff00f2 },
{ "iPartNumber", 0xffff00f3 },
{ "iReferenceNumber", 0xffff00f4 },
/* 0xffff00f5-0xffff00ff => Reserved */
{ "iGang", 0xffff00f5 },
/* 0xffff00f6-0xffff00ff => Reserved */
/* end of table */
{ NULL, 0 }
@ -941,7 +1025,7 @@ static hid_info_t mge_hid2nut[] =
{ "outlet.power", 0, 0, "UPS.OutletSystem.Outlet.[1].ApparentPower", NULL, "%.0f", 0, NULL },
{ "outlet.realpower", 0, 0, "UPS.OutletSystem.Outlet.[1].ActivePower", NULL, "%.0f", 0, NULL },
{ "outlet.current", 0, 0, "UPS.OutletSystem.Outlet.[1].Current", NULL, "%.2f", 0, NULL },
{ "outlet.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[1].PowerFactor", NULL, "%.2f", 0, NULL }, // "%s", 0, mge_powerfactor_conversion },
{ "outlet.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[1].PowerFactor", NULL, "%.2f", 0, NULL }, /* "%s", 0, mge_powerfactor_conversion }, */
/* First outlet */
{ "outlet.1.id", 0, 0, "UPS.OutletSystem.Outlet.[2].OutletID", NULL, "%.0f", HU_FLAG_STATIC, NULL },
@ -950,18 +1034,22 @@ static hid_info_t mge_hid2nut[] =
{ "outlet.1.status", 0, 0, "UPS.OutletSystem.Outlet.[2].PresentStatus.SwitchOn/Off", NULL, "%s", 0, on_off_info },
/* For low end models, with 1 non backup'ed outlet */
{ "outlet.1.status", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, "%s", 0, on_off_info },
/* FIXME: change to outlet.1.battery.charge.low, as in mge-xml.c?! */
{ "outlet.1.autoswitch.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.OutletSystem.Outlet.[2].RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
{ "outlet.1.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.OutletSystem.Outlet.[2].ShutdownTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
{ "outlet.1.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.OutletSystem.Outlet.[2].StartupTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
{ "outlet.1.power", 0, 0, "UPS.OutletSystem.Outlet.[2].ApparentPower", NULL, "%.0f", 0, NULL },
{ "outlet.1.realpower", 0, 0, "UPS.OutletSystem.Outlet.[2].ActivePower", NULL, "%.0f", 0, NULL },
{ "outlet.1.current", 0, 0, "UPS.OutletSystem.Outlet.[2].Current", NULL, "%.2f", 0, NULL },
{ "outlet.1.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[2].PowerFactor", NULL, "%.2f", 0, NULL }, // "%s", 0, mge_powerfactor_conversion },
{ "outlet.1.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[2].PowerFactor", NULL, "%.2f", 0, NULL }, /* "%s", 0, mge_powerfactor_conversion }, */
/* Second outlet */
{ "outlet.2.id", 0, 0, "UPS.OutletSystem.Outlet.[3].OutletID", NULL, "%.0f", HU_FLAG_STATIC, NULL },
{ "outlet.2.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, "UPS.OutletSystem.Outlet.[3].OutletID", NULL, "PowerShare Outlet 2", HU_FLAG_ABSENT, NULL },
/* needed for Pegasus to enable master/slave mode */
{ "outlet.2.switchable", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.OutletSystem.Outlet.[3].PresentStatus.Switchable", NULL, "%s", HU_FLAG_SEMI_STATIC, yes_no_info },
/* needed for Pegasus to enable master/slave mode:
* FIXME: rename to something more suitable (outlet.?) */
{ "outlet.2.switchable", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.OutletSystem.Outlet.[3].PresentStatus.Switchable", NULL, "%s", HU_FLAG_SEMI_STATIC, pegasus_yes_no_info },
/* Generic version (RO) for other models */
{ "outlet.2.switchable", 0, 0, "UPS.OutletSystem.Outlet.[3].PresentStatus.Switchable", NULL, "%s", 0, yes_no_info },
{ "outlet.2.status", 0, 0, "UPS.OutletSystem.Outlet.[3].PresentStatus.SwitchOn/Off", NULL, "%s", 0, on_off_info },
{ "outlet.2.autoswitch.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.OutletSystem.Outlet.[3].RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
{ "outlet.2.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.OutletSystem.Outlet.[3].ShutdownTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
@ -969,7 +1057,7 @@ static hid_info_t mge_hid2nut[] =
{ "outlet.2.power", 0, 0, "UPS.OutletSystem.Outlet.[3].ApparentPower", NULL, "%.0f", 0, NULL },
{ "outlet.2.realpower", 0, 0, "UPS.OutletSystem.Outlet.[3].ActivePower", NULL, "%.0f", 0, NULL },
{ "outlet.2.current", 0, 0, "UPS.OutletSystem.Outlet.[3].Current", NULL, "%.2f", 0, NULL },
{ "outlet.2.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[3].PowerFactor", NULL, "%.2f", 0, NULL }, // "%s", 0, mge_powerfactor_conversion },
{ "outlet.2.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[3].PowerFactor", NULL, "%.2f", 0, NULL }, /* "%s", 0, mge_powerfactor_conversion }, */
/* instant commands. */
/* splited into subset while waiting for extradata support
@ -1084,20 +1172,37 @@ static int mge_claim(HIDDevice_t *hd) {
switch (status) {
case POSSIBLY_SUPPORTED:
/* by default, reject, unless the productid option is given */
if (getval("productid")) {
return 1;
}
possibly_supported("Eaton / MGE", hd);
return 0;
case POSSIBLY_SUPPORTED:
case SUPPORTED:
return 1;
switch (hd->VendorID)
{
case HP_VENDORID:
case DELL_VENDORID:
/* by default, reject, unless the productid option is given */
if (getval("productid")) {
return 1;
}
case NOT_SUPPORTED:
default:
return 0;
/*
* this vendor makes lots of USB devices that are
* not a UPS, so don't use possibly_supported here
*/
return 0;
default: /* Valid for Eaton */
/* by default, reject, unless the productid option is given */
if (getval("productid")) {
return 1;
}
possibly_supported("Eaton / MGE", hd);
return 0;
}
case SUPPORTED:
return 1;
case NOT_SUPPORTED:
default:
return 0;
}
#else
return 1;