On Fri, Aug 14, 2020 at 01:46:57PM +0200, Paul de Weerd wrote:
> Hi all,
>
> I'm trying to read temperature sensor values from my ugold(4) device.
> Seems to work alright (I get the same temperature reading as sysctl(8)
> returns for the sensor), but the 'sensor value last change time'
> doesn't seem to be updated.
>
> [weerd@pom] $ cat sensor_last_change.c
> #include <stdio.h>
> #include <sys/time.h>
> #include <sys/sensors.h>
> #include <sys/sysctl.h>
>
> int
> main()
> {
> int mib[5];
> size_t sensorlen;
> struct sensor sensor;
>
> mib[0] = CTL_HW;
> mib[1] = HW_SENSORS;
> mib[2] = 3; /* ugold0 on my machine */
> mib[3] = SENSOR_TEMP;
> mib[4] = 0;
>
> sensorlen = sizeof(sensor);
> sysctl(mib, 5, &sensor, &sensorlen, NULL, 0);
> printf("%lld.%06ld: %.2f\n",
> sensor.tv.tv_sec,
> sensor.tv.tv_usec,
> ((sensor.value-273150000)/1000000.0));
>
> return 0;
> }
> [weerd@pom] $ make sensor_last_change
> cc -O2 -pipe -MD -MP -o sensor_last_change sensor_last_change.c
> [weerd@pom] $ ./sensor_last_change
> 0.000000: 32.32
> [weerd@pom] $ sysctl -n hw.sensors.ugold0.temp0
> 32.32 degC (inner)
>
> The 'tv' member of struct sensor seems to always be 0.0. Am I doing
> something wrong?
>
> Cluesticks very welcome...
>
> Thanks,
>
> Paul
>
> --
> >++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
> +++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
> http://www.weirdnet.nl/
>
Hi,
I don't think you're doing anything wrong, but I don't think its supported by
the device and it's simply not set and so stays zero.
A quick grep shows some files which do use it:
/usr/src/sys $ grep -R sc_sensor\.tv .
./dev/gpio/gpiodcf.c: microtime(&sc->sc_sensor.tv);
./dev/pv/hypervic.c: microtime(&sc->sc_sensor.tv);
./dev/pv/vmt.c: struct timeval *guest = &sc->sc_sensor.tv;
./dev/pv/vmmci.c: struct timeval *guest = &sc->sc_sensor.tv;
./dev/usb/udcf.c: microtime(&sc->sc_sensor.tv);
I have a ugold(4) device and will gladly test any improvements/patches.
--
Kind regards,
Hiltjo