1 /* apcupsd-ups.h - NUT client driver to apcupsd 2 3 Copyright (C) 4 2005 - 2010 Arnaud Quette <http://arnaud.quette.free.fr/contact.html> 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21 /* from usbhid-ups.h */ 22 /* --------------------------------------------------------------- */ 23 /* Struct & data for ups.status processing */ 24 /* --------------------------------------------------------------- */ 25 26 typedef struct { 27 const char *status_str; /* ups.status string */ 28 int status_value; /* ups.status value */ 29 } status_lkp_t; 30 31 #define STATUS_CAL 1 /* calibration */ 32 #define STATUS_TRIM 2 /* SmartTrim */ 33 #define STATUS_BOOST 4 /* SmartBoost */ 34 #define STATUS_OL 8 /* on line */ 35 #define STATUS_OB 16 /* on battery */ 36 #define STATUS_OVER 32 /* overload */ 37 #define STATUS_LB 64 /* low battery */ 38 #define STATUS_RB 128 /* replace battery */ 39 #define STATUS_BYPASS 256 /* on bypass */ 40 #define STATUS_OFF 512 /* ups is off */ 41 #define STATUS_CHRG 1024 /* charging */ 42 #define STATUS_DISCHRG 2048 /* discharging */ 43 44 status_lkp_t status_info[] = { 45 { "CAL", STATUS_CAL }, 46 { "TRIM", STATUS_TRIM }, 47 { "BOOST", STATUS_BOOST }, 48 { "OL", STATUS_OL }, 49 { "OB", STATUS_OB }, 50 { "OVER", STATUS_OVER }, 51 { "LB", STATUS_LB }, 52 { "RB", STATUS_RB }, 53 { "BYPASS", STATUS_BYPASS }, 54 { "OFF", STATUS_OFF }, 55 { "CHRG", STATUS_CHRG }, 56 { "DISCHRG", STATUS_DISCHRG }, 57 { "NULL", 0 }, 58 }; 59 /* from usbhid-ups.h */ 60 61 typedef struct { 62 char hid_value; /* HID value */ 63 char *nut_value; /* NUT value */ 64 } info_enum_t; 65 66 /* --------------------------------------------------------------- */ 67 /* Structure containing information about how to get/set data */ 68 /* from/to the UPS and convert these to/from NUT standard */ 69 /* --------------------------------------------------------------- */ 70 71 typedef struct { 72 const char *apcupsd_item; 73 const char *info_type; /* NUT variable name */ 74 int info_flags; /* NUT flags (to set in addinfo) */ 75 float info_len; /* if ST_FLAG_STRING: length of the string */ 76 /* if HU_TYPE_CMD: command value ; multiplier (or max len) otherwise */ 77 const char *default_value; /* if HU_FLAG_ABSENT: default value ; format otherwise */ 78 int drv_flags; /* */ 79 char **var_values; /* all possible values for this variable (allows to check data...) */ 80 /* FIXME: "void *" so we can have bound or enum */ 81 /* interpreter interpret; */ /* FFE: interpreter fct, NULL if not needed */ 82 } apcuspd_info_t; 83 84 /* data flags */ 85 #define DU_FLAG_NONE 0 86 #define DU_FLAG_INIT 1 /* intialy show element to upsd */ 87 #define DU_FLAG_STATUS 2 88 #define DU_FLAG_DATE 4 89 #define DU_FLAG_TIME 8 90 #define DU_FLAG_FW1 16 91 #define DU_FLAG_FW2 32 92 93 /* ------------ */ 94 /* Data table */ 95 /* ------------ */ 96 97 static apcuspd_info_t nut_data[] = 98 { 99 { NULL, "ups.mfr", ST_FLAG_STRING | ST_FLAG_RW, 32, "APC", DU_FLAG_INIT, NULL }, 100 { "MODEL", "ups.model", ST_FLAG_STRING | ST_FLAG_RW, 32, "Unknown UPS", DU_FLAG_INIT, NULL }, 101 { "STATUS", "ups.status", ST_FLAG_STRING | ST_FLAG_RW, 32, "OFF", DU_FLAG_INIT|DU_FLAG_STATUS, NULL }, 102 { "SERIALNO", "ups.serial", ST_FLAG_STRING | ST_FLAG_RW, 32, NULL, DU_FLAG_NONE, NULL }, 103 { "LOADPCT", "ups.load", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 104 { "DATE", "ups.time", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_TIME, NULL }, 105 { "DATE", "ups.date", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_DATE, NULL }, 106 { "MANDATE", "ups.mfr.date", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL }, 107 { "FIRMWARE", "ups.firmware", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_FW1, NULL }, 108 { "FIRMWARE", "ups.firmware.aux", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_FW2, NULL }, 109 { "ITEMP", "ups.temperature", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 110 { "UPSNAME", "ups.id", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL }, 111 { "DWAKE", "ups.delay.start", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL }, 112 { "DSHUTD", "ups.delay.shutdown", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL }, 113 { "STESTI", "ups.test.interval", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL }, 114 { "SELFTEST", "ups.test.result", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL }, 115 { "LINEV", "input.voltage", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 116 { "MAXLINEV", "input.voltage.maximum", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 117 { "MINLINEV", "input.voltage.minimum", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 118 { "NOMINV", "input.voltage.nominal", 0, 1, "%.0f", DU_FLAG_NONE, NULL }, 119 { "NOMOUTV", "output.voltage.nominal", 0, 1, "%.0f", DU_FLAG_NONE, NULL }, 120 { "LASTXFER", "input.transfer.reason", ST_FLAG_STRING | ST_FLAG_RW, 32, NULL, DU_FLAG_NONE, NULL }, 121 { "LOTRANS", "input.transfer.low", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 122 { "HITRANS", "input.transfer.high", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 123 { "SENSE", "input.sensitivity", ST_FLAG_STRING | ST_FLAG_RW, 1, NULL, DU_FLAG_NONE, NULL }, 124 { "LINEFREQ", "input.frequency", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 125 { "OUTPUTV", "output.voltage", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 126 { "LINEFREQ", "output.frequency", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 127 { "BCHARGE", "battery.charge", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 128 { "MBATTCHG", "battery.charge.low", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL }, 129 { "BATTDATE", "battery.date", ST_FLAG_STRING /* | ST_FLAG_RW */, 16, NULL, DU_FLAG_DATE, NULL }, 130 { "BATTV", "battery.voltage", 0, 1, "%1.1f", DU_FLAG_NONE, NULL }, 131 { "NOMBATTV", "battery.voltage.nominal", 0, 1, "%1.1f", DU_FLAG_NONE, NULL }, 132 { "TIMELEFT", "battery.runtime", ST_FLAG_RW, 60, "%1.1f", DU_FLAG_NONE, NULL }, 133 { "MINTIMEL", "battery.runtime.low", ST_FLAG_RW, 60, "%.0f", DU_FLAG_NONE, NULL }, 134 { "RETPCT", "battery.charge.restart", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, 135 { "NOMPOWER", "ups.realpower.nominal", 0, 1, "%1.1f", DU_FLAG_INIT, NULL }, 136 { NULL, NULL, 0, 0, NULL, DU_FLAG_NONE, NULL } 137 }; 138