Index | Thread | Search

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

Download raw body.

Thread
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:

uhid29 detached
hotplug: event lost, queue full
uhidev0 detached
hotplug: event lost, queue full
uhidev0 at uhub0 port 2 configuration 1 interface 0 "EATON Ellipse PRO" rev 1.10/1.00 addr 2

so something detaches/reattaches upd ? is that something to worry about?

as for RunTimeToEmpty, i found out that throwing 60*60 to the scaling
value gives me a value that matches what the lcd says, as 'systat
sensors' shows (converts secs to mins/hours):

upd0.percent2       20.00%    OK PercentLoad
upd0.timedelta0 19.344 min    OK RunTimeToEmpty

but ofc i dunno if that's a quirk of my model or something else..

so if you have an upd(4) somewhere and you have sensors, i'll be glad to
know if:
- you get more sensors and they make sense
- you get values that make more sense than before
- you had a value for RunTimeToEmpty that made sense and now doesn't
  (same for AtRateTimeToEmpty/AtRateTimeToFull if you have them)
- it now breaks/detaches/reattaches

with the attached diff.

help welcome on the units/scaling bits, the reference spec i found so far was
https://www.usb.org/sites/default/files/documents/pdcv10.pdf - i havent
tried with linux/nut yet.

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 11:15:52 -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_DC,	 "VoltageDc" },
+	{ HUP_POWER,	HUP_CURRENT,
+	    SENSOR_AMPS,	 "Current" },
 	{ HUP_BATTERY,	HUB_CHARGING,
 	    SENSOR_INDICATOR,	 "Charging" },
 	{ HUP_BATTERY,	HUB_DISCHARGING,
@@ -411,13 +426,20 @@
 	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 = 1000; /* uV/uW/uA ? */
 	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 */