Re: onewire/owtemp: flags for no_detach+timestamp.

2018-03-17 Thread Artturi Alm
On Sun, Mar 18, 2018 at 02:13:14AM +0200, Artturi Alm wrote:
> 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 025f07aa)
> > hw.sensors.owtemp0.timedelta0=5.00 secs (LastUpdate)
> > hw.sensors.owtemp1.temp0=30.88 degC (sn 025ecdb5)
> > hw.sensors.owtemp1.timedelta0=5.00 secs (LastUpdate)
> > hw.sensors.owtemp2.temp0=30.50 degC (sn 025f13ad)
> > hw.sensors.owtemp2.timedelta0=5.00 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
> 
> 

forgot this from the last diff..:

diff --git sys/dev/gpio/gpioow.c sys/dev/gpio/gpioow.c
index 64d79ab0cb8..f7b7eb83e4b 100644
--- sys/dev/gpio/gpioow.c
+++ sys/dev/gpio/gpioow.c
@@ -147,6 +147,7 @@ gpioow_attach(struct device *parent, struct device *self, 
void *aux)
 
bzero(&oba, sizeof(oba));
oba.oba_bus = &sc->sc_ow_bus;
+   oba.oba_flags = ga->ga_flags;
sc->sc_ow_dev = config_found(self, &oba, onewirebus_print);
 
return;



Re: onewire/owtemp: flags for no_detach+timestamp.

2018-03-17 Thread Artturi Alm
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 025f07aa)
> hw.sensors.owtemp0.timedelta0=5.00 secs (LastUpdate)
> hw.sensors.owtemp1.temp0=30.88 degC (sn 025ecdb5)
> hw.sensors.owtemp1.timedelta0=5.00 secs (LastUpdate)
> hw.sensors.owtemp2.temp0=30.50 degC (sn 025f13ad)
> hw.sensors.owtemp2.timedelta0=5.00 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);
 intonewire_triplet(void *, int);
 void   onewire_matchrom(void *, u_int64_t);
 intonewire_search(void *, u_int64_t *, int, u_int64_t);
+intonewire_quirks(void *);
 
 #define ONEWIRE_NOWAIT 0x0001
 
@@ -60,6 +61,8 @@ struct onewirebus_attach_args {
int oba_flags;
 #defineONEWIRE_SCAN_NOW0x0001
 #defineONEWIRE_NO_PERIODIC_SCAN0x0002
+#defineONEWIRE_NO_DETACH   0x0004
+#defineONEWIRE_TIMESTAMP   0x0008
 };
 
 intonewirebus_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 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -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 = 27315 + val;
+   if (sc->sc_timestamp)
+   sc->sc_sensor.tv.tv_sec = time_second;
}
 
 done:



Re: onewire/owtemp: flags for no_detach+timestamp.

2018-03-09 Thread Artturi Alm
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 025f07aa)
hw.sensors.owtemp0.timedelta0=5.00 secs (LastUpdate)
hw.sensors.owtemp1.temp0=30.88 degC (sn 025ecdb5)
hw.sensors.owtemp1.timedelta0=5.00 secs (LastUpdate)
hw.sensors.owtemp2.temp0=30.50 degC (sn 025f13ad)
hw.sensors.owtemp2.timedelta0=5.00 secs (LastUpdate)

-Artturi


diff --git sys/dev/gpio/gpioow.c sys/dev/gpio/gpioow.c
index 64d79ab0cb8..f7b7eb83e4b 100644
--- sys/dev/gpio/gpioow.c
+++ sys/dev/gpio/gpioow.c
@@ -147,6 +147,7 @@ gpioow_attach(struct device *parent, struct device *self, 
void *aux)
 
bzero(&oba, sizeof(oba));
oba.oba_bus = &sc->sc_ow_bus;
+   oba.oba_flags = ga->ga_flags;
sc->sc_ow_dev = config_found(self, &oba, onewirebus_print);
 
return;
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);
 intonewire_triplet(void *, int);
 void   onewire_matchrom(void *, u_int64_t);
 intonewire_search(void *, u_int64_t *, int, u_int64_t);
+intonewire_quirks(void *);
 
 #define ONEWIRE_NOWAIT 0x0001
 
@@ -60,6 +61,8 @@ struct onewirebus_attach_args {
int oba_flags;
 #defineONEWIRE_SCAN_NOW0x0001
 #defineONEWIRE_NO_PERIODIC_SCAN0x0002
+#defineONEWIRE_NO_DETACH   0x0004
+#defineONEWIRE_TIMESTAMP   0x0008
 };
 
 intonewirebus_print(void *, const char *);
diff --git sys/dev/onewire/owtemp.c sys/dev/onewire/owtemp.c
index e883dbb17a9..4c7615ab1ef 100644
--- sys/dev/onewire/owtemp.c
+++ sys/dev/onewire/owtemp.c
@@ -24,8 +24,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -50,8 +52,10 @@ struct owtemp_softc {
 
void *  sc_onewire;
u_int64_t   sc_rom;
+   time_t  sc_timestamp;
 
struct ksensor  sc_sensor;
+   struct ksensor  *sc_sensor_td;
struct ksensordev   sc_sensordev;
struct sensor_task  *sc_sensortask;
struct rwlock   sc_lock;
@@ -104,12 +108,25 @@ 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));
 
+   if (onewire_quirks(sc->sc_onewire) & ONEWIRE_TIMESTAMP) {
+   sc->sc_sensor_td = malloc(sizeof(struct ksensor),
+   M_DEVBUF, M_NOWAIT|M_ZERO);
+   if (sc->sc_sensor_td) {
+   sc->sc_sensor_td->type = SENSOR_TIMEDELTA;
+   strlcpy(sc->sc_sensor_td->desc, "LastUpdate",
+   sizeof(sc->sc_

onewire/owtemp: flags for no_detach+timestamp.

2018-03-06 Thread Artturi Alm
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


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);
 intonewire_triplet(void *, int);
 void   onewire_matchrom(void *, u_int64_t);
 intonewire_search(void *, u_int64_t *, int, u_int64_t);
+intonewire_quirks(void *);
 
 #define ONEWIRE_NOWAIT 0x0001
 
@@ -60,6 +61,8 @@ struct onewirebus_attach_args {
int oba_flags;
 #defineONEWIRE_SCAN_NOW0x0001
 #defineONEWIRE_NO_PERIODIC_SCAN0x0002
+#defineONEWIRE_NO_DETACH   0x0004
+#defineONEWIRE_TIMESTAMP   0x0008
 };
 
 intonewirebus_print(void *, const char *);
diff --git sys/dev/onewire/owtemp.c sys/dev/onewire/owtemp.c
index e883dbb17a9..e21862889e3 100644
--- sys/dev/onewire/owtemp.c
+++ sys/dev/onewire/owtemp.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -50,8 +51,10 @@ struct owtemp_softc {
 
void *  sc_onewire;
u_int64_t   sc_rom;
+   time_t  sc_timestamp;
 
struct ksensor  sc_sensor;
+   struct ksensor  *sc_sensor_td;
struct ksensordev   sc_sensordev;
struct sensor_task  *sc_sensortask;
struct rwlock   sc_lock;
@@ -104,12 +107,25 @@ 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));
 
+   if (onewire_quirks(sc->sc_onewire) & ONEWIRE_TIMESTAMP) {
+   sc->sc_sensor_td = malloc(sizeof(struct onewire_device),
+   M_DEVBUF, M_NOWAIT);
+   if (sc->sc_sensor_td) {
+   sc->sc_sensor_td->type = SENSOR_TIMEDELTA;
+   strlcpy(sc->sc_sensor_td->desc, "LastUpdate",
+   sizeof(sc->sc_sensor_td->desc));
+   }
+   }
+   sc_timestamp = 0;
+
sc->sc_sensortask = sensor_task_register(sc, owtemp_update, 5);
if (sc->sc_sensortask == NULL) {
printf(": unable to register update task\n");
return;
}
sensor_attach(&sc->sc_sensordev, &sc->sc_sensor);
+   if (sc->sc_sensor_td)
+   sensor_attach(&sc->sc_sensordev, sc->sc_sensor_td);
sensordev_install(&sc->sc_sensordev);
 
rw_init(&sc->sc_lock, sc->sc_dev.dv_xname);
@@ -146,6 +162,13 @@ owtemp_update(void *arg)
 
rw_enter_write(&sc->sc_lock);
onewire_lock(sc->sc_onewire, 0);
+
+   /* Update timedelta of last successful reading */
+   if (sc->sc_sensor_td != NULL && sc_timestamp != 0) {
+   sc->sc_sensor_td->value = time_second - sc->sc_timestamp;
+   sc->sc_sensor_td->value *= 10LL;
+   }
+
if (onewire_reset(sc->sc_onewire) != 0)
goto done;
onewire_matchrom(sc->sc_onewire, sc->sc_rom);
@@ -196,6 +219,8 @@ owtemp_update(void *arg)
}
}
sc->sc_sensor.value = 27315 + val;
+   if (sc->sc_sensor_td != NULL)
+   sc->sc_timestamp = time_second;
}
 
 done: