Hi,

I just decided to fix some scaling issues for my UPS (TRIPP-LITE SMART1500LCDT). Apparently that issue existed for some time (and I knew about it as well:-()

See http://thread.gmane.org/gmane.comp.monitoring.nut.devel/6482 for a thread.

My little patch is attached (against 2.7.3). It seems to be working better for me but I don't have any other TRIPP-LITE's to test that I did not break anything:-( So, please check it!

Thanks,
-- Marco

--- a/drivers/tripplite-hid.c
+++ b/drivers/tripplite-hid.c
@@ -39,6 +39,8 @@
  * battery voltage. By default, the factor is 1 (no scaling).
  */
 static double	battery_scale = 1.0;
+static double   voltage_scale = 1.0;
+static double   frequency_scale = 1.0;
 
 /* Specific handlers for USB device matching */
 static void *battery_scale_1dot0(USBDevice_t *device)
@@ -53,6 +55,14 @@
 	return NULL;
 }
 
+static void *smart_ldct_scale(USBDevice_t *device) {
+	battery_scale = 100000.0;
+	voltage_scale = 100000.0;
+	frequency_scale = 0.01;
+
+	return NULL;
+}
+
 /* TrippLite */
 #define TRIPPLITE_VENDORID 0x09ae
 
@@ -96,7 +106,7 @@
 	/* e.g. ? */
 	{ USB_DEVICE(TRIPPLITE_VENDORID, 0x3015), battery_scale_1dot0 },
 	/* e.g. TrippLite Smart1500LCD (newer unit) */
-	{ USB_DEVICE(TRIPPLITE_VENDORID, 0x3016), battery_scale_1dot0 },
+	{ USB_DEVICE(TRIPPLITE_VENDORID, 0x3016), smart_ldct_scale },
 	/* e.g. TrippLite SmartOnline SU1500RTXL2UA (older unit?) */
 	{ USB_DEVICE(TRIPPLITE_VENDORID, 0x4001), battery_scale_1dot0 },
 	/* e.g. TrippLite SmartOnline SU6000RT4U? */
@@ -175,6 +185,36 @@
 	{ 0, NULL, tripplite_battvolt_fun }
 };
 
+/* returns statically allocated string - must not use it again before
+   done with result! */
+static const char *tripplite_voltage_fun(double value)
+{
+        static char     buf[8];
+
+        snprintf(buf, sizeof(buf), "%.1f", voltage_scale * value);
+
+        return buf;
+}
+
+static info_lkp_t tripplite_voltage[] = {
+        { 0, NULL, tripplite_voltage_fun }
+};
+
+/* returns statically allocated string - must not use it again before
+   done with result! */
+static const char *tripplite_frequency_fun(double value)
+{
+        static char     buf[8];
+
+        snprintf(buf, sizeof(buf), "%.1f", frequency_scale * value);
+
+        return buf;
+}
+
+static info_lkp_t tripplite_frequency[] = {
+        { 0, NULL, tripplite_frequency_fun }
+};
+
 /* --------------------------------------------------------------- */
 /*	Vendor-specific usage table */
 /* --------------------------------------------------------------- */
@@ -363,9 +403,9 @@
 
 	/* Input page */
 	{ "input.voltage.nominal", 0, 0, "UPS.PowerSummary.Input.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL },
-	{ "input.voltage", 0, 0, "UPS.PowerSummary.Input.Voltage", NULL, "%.1f", 0, NULL },
-	{ "input.voltage", 0, 0, "UPS.PowerConverter.Input.Voltage", NULL, "%.1f", 0, NULL },
-	{ "input.frequency", 0, 0, "UPS.PowerConverter.Input.Frequency", NULL, "%.1f", 0, NULL },
+	{ "input.voltage", 0, 0, "UPS.PowerSummary.Input.Voltage", NULL, "%s", 0, tripplite_voltage },
+	{ "input.voltage", 0, 0, "UPS.PowerConverter.Input.Voltage", NULL, "%s", 0, tripplite_voltage },
+	{ "input.frequency", 0, 0, "UPS.PowerConverter.Input.Frequency", NULL, "%s", 0, tripplite_frequency },
 	{ "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.LowVoltageTransfer", NULL, "%.1f", HU_FLAG_SEMI_STATIC, NULL },
 	{ "input.transfer.low.max", 0, 0, "UPS.PowerConverter.Output.TLLowVoltageTransferMax", NULL, "%.0f", HU_FLAG_STATIC, NULL },
 	{ "input.transfer.low.min", 0, 0, "UPS.PowerConverter.Output.TLLowVoltageTransferMin", NULL, "%.0f", HU_FLAG_STATIC, NULL },
@@ -375,11 +415,11 @@
 
 	/* Output page */
 	{ "output.voltage.nominal", 0, 0, "UPS.Flow.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL },
-	{ "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%.1f", 0, NULL },
-	{ "output.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%.1f", 0, NULL },
+	{ "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%s", 0, tripplite_voltage },
+	{ "output.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%s", 0, tripplite_voltage },
 	{ "output.current", 0, 0, "UPS.PowerConverter.Output.Current", NULL, "%.2f", 0, NULL },
 	{ "output.frequency.nominal", 0, 0, "UPS.Flow.ConfigFrequency", NULL, "%.0f", HU_FLAG_STATIC, NULL },
-	{ "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%.1f", 0, NULL },
+	{ "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%s", 0, tripplite_frequency },
 
 	/* instant commands. */
 	{ "test.battery.start.quick", 0, 0, "UPS.BatterySystem.Test", NULL, "1", HU_TYPE_CMD, NULL }, /* reported to work on OMNI1000 */
_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsdev

Reply via email to