On Fri, Mar 09, 2018 at 11:51:20AM +0200, Artturi Alm wrote:
> On Wed, Mar 07, 2018 at 06:26:15AM +0200, Artturi Alm wrote:
> > Hi,
> > 
> > i tested gpioow on beaglebone black a few days ago, and when i was lazy
> > to fix the 'cables' my sensors were attached to, console was spammed
> > over night by some of the sensors.
> > i found the hotplug spam+disappearing sensors annoying.
> > 
> > if i read gpioctl(8) correctly, i should be able to pass these flags like
> > "gpioctl gpio1 attach gpioow 16 0x01 [flags]" ?
> > 
> > yet untested diff below showing what i think i'm missing,
> > and for which any input would be much appreciated by those familiar with
> > gpioow(4)i/sensors frsmrwork, or anyone w/comments generally :)
> > 
> > -Artturi
> > 
> 
> so this does lower the bar for owtemp(4) to be more easily usable/reliable
> via sysctl(8) alone in some simple script or w/e(sensor will be there,
> and w/timedelta one can decide whether to use the value or not).
> 
> besides the obvious copy-paste-bugs in the previous draft,
> i missed how gpioow(4) didn't pass the flags to onewire(4) oba_flags.
> 
> diff below does work good enough for my use, and i don't care about the
> inherent 5sec 'lag' on timedelta enough to make the diff any bigger.
> 
> rc.securelevel:
> gpioctl gpio1 attach gpioow 16 1 12
> 
> root@av7bbb:~ # sysctl hw.sensors
> hw.sensors.owtemp0.temp0=30.56 degC (sn 0000025f07aa)
> hw.sensors.owtemp0.timedelta0=5.000000 secs (LastUpdate)
> hw.sensors.owtemp1.temp0=30.88 degC (sn 0000025ecdb5)
> hw.sensors.owtemp1.timedelta0=5.000000 secs (LastUpdate)
> hw.sensors.owtemp2.temp0=30.50 degC (sn 0000025f13ad)
> hw.sensors.owtemp2.timedelta0=5.000000 secs (LastUpdate)
> 
> -Artturi
> 

Hi,

admittedly my last diff was funny, and hardly worth of any comments:D

maybe this one would be more acceptable? no fake-sensors/lag involved,
as sysctl(8) does make use of s->tv.tv_sec, if provided i found out.

-Artturi


diff --git sys/dev/onewire/onewire.c sys/dev/onewire/onewire.c
index 679bcd90e85..263f65ab674 100644
--- sys/dev/onewire/onewire.c
+++ sys/dev/onewire/onewire.c
@@ -434,8 +434,11 @@ onewire_scan(struct onewire_softc *sc)
         * scanning. This allows to find out later which devices
         * have been disappeared.
         */
-       TAILQ_FOREACH(d, &sc->sc_devs, d_list)
+       TAILQ_FOREACH(d, &sc->sc_devs, d_list) {
+               if (sc->sc_flags & ONEWIRE_NO_DETACH)
+                       break;
                d->d_present = 0;
+       }
 
        /*
         * Reset the bus. If there's no presence pulse don't search
@@ -497,3 +500,11 @@ out:
                }
        }
 }
+
+int
+onewire_quirks(void *arg)
+{
+       struct onewire_softc *sc = arg;
+
+       return (sc->sc_flags & ONEWIRE_TIMESTAMP);
+}
diff --git sys/dev/onewire/onewirevar.h sys/dev/onewire/onewirevar.h
index ab3776f50bf..673e0d7e7b2 100644
--- sys/dev/onewire/onewirevar.h
+++ sys/dev/onewire/onewirevar.h
@@ -51,6 +51,7 @@ void          onewire_write_block(void *, const void *, int);
 int            onewire_triplet(void *, int);
 void           onewire_matchrom(void *, u_int64_t);
 int            onewire_search(void *, u_int64_t *, int, u_int64_t);
+int            onewire_quirks(void *);
 
 #define ONEWIRE_NOWAIT         0x0001
 
@@ -60,6 +61,8 @@ struct onewirebus_attach_args {
        int                     oba_flags;
 #define        ONEWIRE_SCAN_NOW                0x0001
 #define        ONEWIRE_NO_PERIODIC_SCAN        0x0002
+#define        ONEWIRE_NO_DETACH               0x0004
+#define        ONEWIRE_TIMESTAMP               0x0008
 };
 
 int    onewirebus_print(void *, const char *);
diff --git sys/dev/onewire/owtemp.c sys/dev/onewire/owtemp.c
index e883dbb17a9..542a331c508 100644
--- sys/dev/onewire/owtemp.c
+++ sys/dev/onewire/owtemp.c
@@ -26,6 +26,7 @@
 #include <sys/kernel.h>
 #include <sys/rwlock.h>
 #include <sys/sensors.h>
+#include <sys/time.h>
 
 #include <dev/onewire/onewiredevs.h>
 #include <dev/onewire/onewirereg.h>
@@ -50,6 +51,7 @@ struct owtemp_softc {
 
        void *                  sc_onewire;
        u_int64_t               sc_rom;
+       int                     sc_timestamp;
 
        struct ksensor          sc_sensor;
        struct ksensordev       sc_sensordev;
@@ -104,6 +106,8 @@ owtemp_attach(struct device *parent, struct device *self, 
void *aux)
        snprintf(sc->sc_sensor.desc, sizeof(sc->sc_sensor.desc), "sn %012llx",
            ONEWIRE_ROM_SN(oa->oa_rom));
 
+       sc->sc_timestamp = onewire_quirks(sc->sc_onewire) & ONEWIRE_TIMESTAMP;
+
        sc->sc_sensortask = sensor_task_register(sc, owtemp_update, 5);
        if (sc->sc_sensortask == NULL) {
                printf(": unable to register update task\n");
@@ -196,6 +200,8 @@ owtemp_update(void *arg)
                        }
                }
                sc->sc_sensor.value = 273150000 + val;
+               if (sc->sc_timestamp)
+                       sc->sc_sensor.tv.tv_sec = time_second;
        }
 
 done:

Reply via email to