Index | Thread | Search

From:
Landry Breuil <landry@openbsd.org>
Subject:
Re: upd(4): add more sensors (load, power..)
To:
tech@openbsd.org
Date:
Sat, 16 Nov 2024 19:59:29 +0100

Download raw body.

Thread
Le Sat, Nov 16, 2024 at 12:30:47PM +0100, Landry Breuil a écrit :
> hi,
> 
> i recently bought an "EATON Ellipse PRO" that is recognized by the
> upd(4) driver, thus i get some sensors, but some are off (RunTimeToEmpty
> says 200000s while the LCD says '15mn'..) and some are missing.
> 
> i looked at the lsusb -vv output and my model supports more sensors from
> the usb hid power/battery usage page specs.
> 
> defining UPD_DEBUG now gives me this:
> 
> upd: vendor=0x0463, product=0xffff
> upd0 at uhidev0
> upd: devname=upd0 sc_max_repid=256
> upd0: found RemainingCapacity on repid=6
> upd0: found FullChargeCapacity on repid=12
> upd0: found PercentLoad on repid=7
> upd0: found ActivePower on repid=14
> upd0: found ConfigApparentPower on repid=13
> upd0: found ApparentPower on repid=14
> upd0: found VoltageDc on repid=14
> upd0: found Charging on repid=1
> upd0: found Discharging on repid=1
> upd0: found RunTimeToEmpty on repid=6
> upd0: found NeedReplacement on repid=1
> upd0: found ShutdownImminent on repid=1
> upd0: found ACPresent on repid=1
> upd0: found Overload on repid=1
> upd: sc_num_sensors=14
> 
> but from all those, some are either garbage values, or i didnt find yet
> the right scale/multiplier/exponent/unit..
> 
> just showing the 'new ones' added by the below diff:
> 
> hw.sensors.upd0.volt0=878.40 VDC (VoltageDc), OK
> hw.sensors.upd0.power0=878.40 W (ActivePower), OK
> hw.sensors.upd0.power1=2340.00 W (ConfigApparentPower), OK
> hw.sensors.upd0.power2=0.00 W (ApparentPower), OK
> hw.sensors.upd0.percent2=30.00% (PercentLoad), OK
> hw.sensors.upd0.timedelta0=674.049600 secs (RunTimeToEmpty), OK
> 
> PercentLoad matches what the LCD says, so for this one it seems correct.
> 
> for the others, the values don't make sense/dont match what the LCD
> says, and as soon as i add too many sensors, i get this in dmesg:

new diff after miod@ pointed out i had forgotten a break..

upd0.acvolt0                              244.00 V AC    OK    VoltageAc
upd0.power0                                  244.00 W    OK    ActivePower
upd0.power1                                  650.00 W    OK    ConfigApparentPower
upd0.power2                                    0.00 W    OK    ApparentPower
upd0.indicator0                                    On    OK    Charging
upd0.indicator1                                   Off    OK    Discharging
upd0.indicator2                                   Off    OK    NeedReplacement
upd0.indicator3                                   Off    OK    ShutdownImminent
upd0.indicator4                                    On    OK    ACPresent
upd0.indicator5                                   Off    OK    Overload
upd0.percent0                                 100.00%    OK    RemainingCapacity
upd0.percent1                                 100.00%    OK    FullChargeCapacity
upd0.percent2                                  17.00%    OK    PercentLoad
upd0.timedelta0                            31.494 min    OK    RunTimeToEmpty

ConfigApparentPower makes sense to me, as that Eaton model is a 650..
but ApparentPower 0 and ActivePower 244 make zero sense to me, because the LCD
gives me between 60 and 120 depending on having the screen powered off or on,
and the value doesn't change at all.

So either i'm missing a formula to convert from an unit to another, or i'm
looking at the wrong usb hid feature, or the firmware tells shit.

voltage-wise, the lcd says that input/output is around 230v, so not 244 either.

besides that, now i have realistic/correct values for PercentLoad/RunTimeToEmpty.

Landry

Index: upd.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/upd.c,v
diff -u -r1.32 upd.c
--- upd.c	23 May 2024 03:21:09 -0000	1.32
+++ upd.c	16 Nov 2024 18:53:50 -0000
@@ -34,6 +34,7 @@
 #include <dev/usb/usbhid.h>
 #include <dev/usb/uhidev.h>
 
+#define UPD_DEBUG
 #ifdef UPD_DEBUG
 #define DPRINTF(x)	do { printf x; } while (0)
 #else
@@ -60,6 +61,20 @@
 	    SENSOR_PERCENT,	 "RemainingCapacity" },
 	{ HUP_BATTERY,	HUB_FULLCHARGE_CAPACITY,
 	    SENSOR_PERCENT,	 "FullChargeCapacity" },
+	{ HUP_POWER,	HUP_PERCENT_LOAD,
+	    SENSOR_PERCENT,	 "PercentLoad" },
+	{ HUP_POWER,	HUP_ACTIVE_POWER,
+	    SENSOR_WATTS,	 "ActivePower" },
+	{ HUP_POWER,	HUP_CONFIG_APP_POWER,
+	    SENSOR_WATTS,	 "ConfigApparentPower" },
+	{ HUP_POWER,	HUP_APPARENT_POWER,
+	    SENSOR_WATTS,	 "ApparentPower" },
+	{ HUP_POWER,	HUP_OUTPUT,
+	    SENSOR_WATTS,	 "Output" },
+	{ HUP_POWER,	HUP_VOLTAGE,
+	    SENSOR_VOLTS_AC,	 "VoltageAc" },
+	{ HUP_POWER,	HUP_CURRENT,
+	    SENSOR_AMPS,	 "Current" },
 	{ HUP_BATTERY,	HUB_CHARGING,
 	    SENSOR_INDICATOR,	 "Charging" },
 	{ HUP_BATTERY,	HUB_DISCHARGING,
@@ -411,13 +426,21 @@
 	case HUB_ABS_STATEOF_CHARGE:
 	case HUB_REM_CAPACITY:
 	case HUB_FULLCHARGE_CAPACITY:
+	case HUP_PERCENT_LOAD:
 		adjust = 1000; /* scale adjust */
 		break;
+	case HUP_CONFIG_APP_POWER:
+	case HUP_APPARENT_POWER:
+	case HUP_ACTIVE_POWER:
+	case HUP_CURRENT:
+	case HUP_VOLTAGE:
+		adjust = 1000000; /* uV/uW/uA ? */
+		break;
 	case HUB_ATRATE_TIMETOFULL:
 	case HUB_ATRATE_TIMETOEMPTY:
 	case HUB_RUNTIMETO_EMPTY:
 		/* spec says minutes, not seconds */
-		adjust = 1000000000LL;
+		adjust = 60*60*1000LL;
 		break;
 	default:
 		adjust = 1; /* no scale adjust */