2020-01-27 05:38:00 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
2020-01-27 08:01:14 +03:00
|
|
|
rv is a netsender client using the revid package to perform media collection
|
2020-01-28 11:46:15 +03:00
|
|
|
and forwarding whose behaviour is controllable via the cloud interfaces
|
2020-01-27 08:01:14 +03:00
|
|
|
netreceiver and vidgrind.
|
2020-01-27 05:38:00 +03:00
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
2020-01-27 08:01:14 +03:00
|
|
|
Alan Noble <alan@ausocean.org>
|
|
|
|
Dan Kortschak <dan@ausocean.org>
|
2020-01-27 05:38:00 +03:00
|
|
|
Jack Richardson <jack@ausocean.org>
|
|
|
|
Trek Hopton <trek@ausocean.org>
|
2020-01-27 08:01:14 +03:00
|
|
|
Scott Barnard <scott@ausocean.org>
|
2022-01-06 09:24:30 +03:00
|
|
|
Russell Stanley <russell@ausocean.org>
|
2020-01-27 05:38:00 +03:00
|
|
|
|
|
|
|
LICENSE
|
2020-01-27 08:01:14 +03:00
|
|
|
Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
|
2020-01-27 05:38:00 +03:00
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
2020-01-28 04:15:18 +03:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
There must firstly be a netsender configuration file under /etc/netsender.conf.
|
|
|
|
Example:
|
|
|
|
|
|
|
|
ma 00:00:00:00:00:01
|
|
|
|
dk 0
|
|
|
|
wi
|
|
|
|
ip V0, T0
|
|
|
|
op
|
|
|
|
mp 60
|
|
|
|
ap 0
|
|
|
|
tg
|
|
|
|
hw
|
|
|
|
sh vidgrind.appspot.com
|
|
|
|
|
|
|
|
Revid configuration is controlled by valid variables given values on netreceiver
|
|
|
|
or vidgrind interface. See revid/config for valid variables.
|
|
|
|
|
|
|
|
To run rv simply build and call:
|
|
|
|
./rv
|
2020-01-27 05:38:00 +03:00
|
|
|
*/
|
|
|
|
|
2020-01-28 11:49:51 +03:00
|
|
|
// Package rv is a netsender client for revid.
|
2020-01-27 05:38:00 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-02-03 02:26:04 +03:00
|
|
|
"bytes"
|
2020-01-27 05:38:00 +03:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"runtime/pprof"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2022-01-07 07:12:15 +03:00
|
|
|
"gocv.io/x/gocv"
|
2022-01-13 04:08:30 +03:00
|
|
|
"gonum.org/v1/gonum/stat"
|
2020-01-27 08:01:14 +03:00
|
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
|
|
|
2020-01-27 05:38:00 +03:00
|
|
|
"bitbucket.org/ausocean/av/container/mts"
|
|
|
|
"bitbucket.org/ausocean/av/container/mts/meta"
|
|
|
|
"bitbucket.org/ausocean/av/revid"
|
|
|
|
"bitbucket.org/ausocean/av/revid/config"
|
2022-01-13 04:08:30 +03:00
|
|
|
"bitbucket.org/ausocean/av/turbidity"
|
2020-01-27 05:38:00 +03:00
|
|
|
"bitbucket.org/ausocean/iot/pi/netlogger"
|
|
|
|
"bitbucket.org/ausocean/iot/pi/netsender"
|
|
|
|
"bitbucket.org/ausocean/utils/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Copyright information prefixed to all metadata.
|
|
|
|
const (
|
|
|
|
metaPreambleKey = "copyright"
|
|
|
|
metaPreambleData = "ausocean.org/license/content2019"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Logging configuration.
|
|
|
|
const (
|
|
|
|
logPath = "/var/log/netsender/netsender.log"
|
|
|
|
logMaxSize = 500 // MB
|
|
|
|
logMaxBackup = 10
|
|
|
|
logMaxAge = 28 // days
|
|
|
|
logVerbosity = logger.Info
|
|
|
|
logSuppress = true
|
|
|
|
)
|
|
|
|
|
|
|
|
// Revid modes.
|
|
|
|
const (
|
|
|
|
modeNormal = "Normal"
|
|
|
|
modePaused = "Paused"
|
|
|
|
modeBurst = "Burst"
|
2020-01-27 08:01:14 +03:00
|
|
|
modeLoop = "Loop"
|
2020-01-27 05:38:00 +03:00
|
|
|
)
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// Misc constants.
|
2020-01-27 05:38:00 +03:00
|
|
|
const (
|
|
|
|
netSendRetryTime = 5 * time.Second
|
|
|
|
defaultSleepTime = 60 // Seconds
|
|
|
|
profilePath = "rv.prof"
|
2020-01-28 02:58:16 +03:00
|
|
|
pkg = "rv: "
|
2020-05-19 09:02:02 +03:00
|
|
|
runPreDelay = 20 * time.Second
|
2022-02-03 08:58:28 +03:00
|
|
|
maxImages = 1 // Max number of images read when evaluating turbidity.
|
2022-01-06 07:58:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Software define pin values.
|
|
|
|
// See https://netreceiver.appspot.com/help, External Pin Assignments.
|
|
|
|
const (
|
2022-01-11 07:05:53 +03:00
|
|
|
bitratePin = "X36"
|
|
|
|
sharpnessPin = "X38"
|
|
|
|
contrastPin = "X39"
|
2020-01-27 05:38:00 +03:00
|
|
|
)
|
|
|
|
|
2022-01-13 04:08:30 +03:00
|
|
|
// Turbidity sensor constants.
|
|
|
|
const (
|
|
|
|
k1, k2 = 8, 8 // Block size, must be divisible by the size template with no remainder.
|
|
|
|
filterSize = 3 // Sobel filter size.
|
|
|
|
scale = 1.0 // Amount of scale applied to sobel filter values.
|
|
|
|
alpha = 1.0 // Paramater for contrast equation.
|
|
|
|
)
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// This is set to true if the 'profile' build tag is provided on build.
|
|
|
|
var canProfile = false
|
2020-01-27 05:38:00 +03:00
|
|
|
|
2022-01-06 07:58:02 +03:00
|
|
|
type turbidityProbe struct {
|
2022-01-11 07:05:53 +03:00
|
|
|
sharpness, contrast float64
|
2022-01-13 04:08:30 +03:00
|
|
|
delay time.Duration
|
|
|
|
ticker time.Ticker
|
|
|
|
ts *turbidity.TurbiditySensor
|
|
|
|
log logger.Logger
|
2022-02-03 02:26:04 +03:00
|
|
|
buffer *bytes.Buffer
|
2022-01-13 04:08:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTurbidityProbe returns a new turbidity probe.
|
|
|
|
func NewTurbidityProbe(log logger.Logger, delay time.Duration) (*turbidityProbe, error) {
|
|
|
|
tp := new(turbidityProbe)
|
|
|
|
tp.log = log
|
|
|
|
tp.delay = delay
|
|
|
|
tp.ticker = *time.NewTicker(delay)
|
2022-02-03 02:26:04 +03:00
|
|
|
tp.buffer = bytes.NewBuffer(*new([]byte))
|
2022-01-13 04:08:30 +03:00
|
|
|
|
|
|
|
// Create the turbidity sensor.
|
|
|
|
standard := gocv.IMRead("../../turbidity/images/template.jpg", gocv.IMReadGrayScale)
|
|
|
|
template := gocv.IMRead("../../turbidity/images/template.jpg", gocv.IMReadGrayScale)
|
2022-02-04 06:16:55 +03:00
|
|
|
ts, err := turbidity.NewTurbiditySensor(template, standard, k1, k2, filterSize, scale, alpha, log)
|
2022-01-13 04:08:30 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Error("failed create turbidity sensor", "error", err.Error())
|
|
|
|
}
|
|
|
|
tp.ts = ts
|
|
|
|
return tp, nil
|
2022-01-06 07:58:02 +03:00
|
|
|
}
|
|
|
|
|
2022-01-13 04:08:30 +03:00
|
|
|
// Write, reads input h264 frames in the form of a byte stream and writes the the sharpness and contrast
|
|
|
|
// scores of a video to the the turbidity probe.
|
2022-01-06 07:58:02 +03:00
|
|
|
func (tp *turbidityProbe) Write(p []byte) (int, error) {
|
2022-02-03 02:26:04 +03:00
|
|
|
tp.buffer.Write(p)
|
2022-01-13 04:08:30 +03:00
|
|
|
select {
|
|
|
|
case <-tp.ticker.C:
|
2022-02-07 03:36:25 +03:00
|
|
|
go tp.turbidityCalculation(p)
|
2022-01-13 04:08:30 +03:00
|
|
|
default:
|
|
|
|
return len(p), nil
|
|
|
|
}
|
2022-01-06 07:58:02 +03:00
|
|
|
return len(p), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tp *turbidityProbe) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-07 03:36:25 +03:00
|
|
|
func (tp *turbidityProbe) turbidityCalculation(p []byte) {
|
|
|
|
var imgs []gocv.Mat
|
|
|
|
img := gocv.NewMat()
|
|
|
|
// Write byte array to a temp file.
|
|
|
|
file, err := os.CreateTemp("temp", "video*.h264")
|
|
|
|
if err != nil {
|
|
|
|
tp.log.Error("failed to create temp file", "error", err.Error())
|
|
|
|
// TODO: Error handling.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer os.Remove(file.Name())
|
|
|
|
_, err = file.Write(tp.buffer.Bytes())
|
|
|
|
if err != nil {
|
|
|
|
tp.log.Error("failed to write to temporary file", "error", err.Error())
|
|
|
|
// TODO: Error handling.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tp.buffer.Reset()
|
|
|
|
// Read the file and store each frame.
|
|
|
|
vc, err := gocv.VideoCaptureFile(file.Name())
|
|
|
|
if err != nil {
|
|
|
|
tp.log.Error("failed to open video file", "error", err.Error())
|
|
|
|
// TODO: Error handling.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for vc.Read(&img) && len(imgs) < maxImages {
|
|
|
|
imgs = append(imgs, img.Clone())
|
|
|
|
}
|
|
|
|
if len(imgs) <= 0 {
|
|
|
|
tp.log.Log(logger.Warning, "no frames found", "error", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tp.log.Log(logger.Debug, "found frames", "frames", len(imgs))
|
|
|
|
|
|
|
|
// Process video data to get saturation and contrast scores.
|
|
|
|
startTime := time.Now()
|
|
|
|
res, err := tp.ts.Evaluate(imgs)
|
|
|
|
if err != nil {
|
|
|
|
tp.log.Error("evaluate failed", "error", err.Error())
|
|
|
|
// TODO: Error handling.
|
|
|
|
} else {
|
|
|
|
tp.log.Log(logger.Debug, "finished evaluation", "total duration (sec)", time.Since(startTime).Seconds())
|
|
|
|
tp.contrast = stat.Mean(res.Contrast, nil)
|
|
|
|
tp.sharpness = stat.Mean(res.Sharpness, nil)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:38:00 +03:00
|
|
|
func main() {
|
|
|
|
mts.Meta = meta.NewWith([][2]string{{metaPreambleKey, metaPreambleData}})
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// Create lumberjack logger to handle logging to file.
|
2020-01-27 05:38:00 +03:00
|
|
|
fileLog := &lumberjack.Logger{
|
|
|
|
Filename: logPath,
|
|
|
|
MaxSize: logMaxSize,
|
|
|
|
MaxBackups: logMaxBackup,
|
|
|
|
MaxAge: logMaxAge,
|
|
|
|
}
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// Create netlogger to handle logging to cloud.
|
2020-01-27 05:38:00 +03:00
|
|
|
netLog := netlogger.New()
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// Create logger that we call methods on to log, which in turn writes to the
|
|
|
|
// lumberjack and netloggers.
|
2020-01-27 05:38:00 +03:00
|
|
|
log := logger.New(logVerbosity, io.MultiWriter(fileLog, netLog), logSuppress)
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// If rv has been built with the profile tag, then we'll start a CPU profile.
|
2020-01-27 05:38:00 +03:00
|
|
|
if canProfile {
|
|
|
|
profile(log)
|
|
|
|
defer pprof.StopCPUProfile()
|
2020-03-27 15:20:51 +03:00
|
|
|
log.Log(logger.Info, "profiling started")
|
2020-01-27 05:38:00 +03:00
|
|
|
}
|
|
|
|
|
2022-01-06 07:58:02 +03:00
|
|
|
var (
|
|
|
|
rv *revid.Revid
|
2022-01-06 09:24:30 +03:00
|
|
|
p *turbidityProbe
|
2022-01-06 07:58:02 +03:00
|
|
|
)
|
2022-02-04 06:16:55 +03:00
|
|
|
p, err := NewTurbidityProbe(*log, 60*time.Second)
|
2020-01-27 05:38:00 +03:00
|
|
|
|
2020-03-27 15:20:51 +03:00
|
|
|
log.Log(logger.Debug, "initialising netsender client")
|
2022-02-03 02:26:04 +03:00
|
|
|
ns, err := netsender.New(log, nil, readPin(p, rv, log), nil, createVarMap())
|
2020-01-27 05:38:00 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Log(logger.Fatal, pkg+"could not initialise netsender client: "+err.Error())
|
|
|
|
}
|
|
|
|
|
2020-03-27 15:20:51 +03:00
|
|
|
log.Log(logger.Debug, "initialising revid")
|
2020-01-28 03:19:42 +03:00
|
|
|
rv, err = revid.New(config.Config{Logger: log}, ns)
|
|
|
|
if err != nil {
|
|
|
|
log.Log(logger.Fatal, pkg+"could not initialise revid", "error", err.Error())
|
|
|
|
}
|
2020-05-19 09:02:02 +03:00
|
|
|
|
2022-01-06 09:24:30 +03:00
|
|
|
err = rv.SetProbe(p)
|
2022-01-06 07:58:02 +03:00
|
|
|
if err != nil {
|
2022-01-06 09:24:30 +03:00
|
|
|
log.Log(logger.Error, pkg+"could not set probe", "error", err.Error())
|
2022-01-06 07:58:02 +03:00
|
|
|
}
|
|
|
|
|
2020-05-19 09:02:02 +03:00
|
|
|
// NB: Problems were encountered with communicating with RTSP inputs. When trying to
|
|
|
|
// connect it would fail due to timeout; as if things had not been set up quickly
|
2020-04-10 19:33:24 +03:00
|
|
|
// enough before revid tried to do things. This delay fixes this, but there is probably
|
|
|
|
// a better way to solve this problem.
|
|
|
|
time.Sleep(runPreDelay)
|
2020-01-28 03:19:42 +03:00
|
|
|
|
2020-03-27 15:20:51 +03:00
|
|
|
log.Log(logger.Debug, "beginning main loop")
|
2020-01-27 05:38:00 +03:00
|
|
|
run(rv, ns, log, netLog)
|
|
|
|
}
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// run starts the main loop. This will run netsender on every pass of the loop
|
|
|
|
// (sleeping inbetween), check vars, and if changed, update revid as appropriate.
|
2020-01-27 05:38:00 +03:00
|
|
|
func run(rv *revid.Revid, ns *netsender.Sender, l *logger.Logger, nl *netlogger.Logger) {
|
|
|
|
var vs int
|
|
|
|
for {
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "running netsender")
|
2020-01-27 05:38:00 +03:00
|
|
|
err := ns.Run()
|
|
|
|
if err != nil {
|
|
|
|
l.Log(logger.Warning, pkg+"Run Failed. Retrying...", "error", err.Error())
|
|
|
|
time.Sleep(netSendRetryTime)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "sending logs")
|
2020-01-27 05:38:00 +03:00
|
|
|
err = nl.Send(ns)
|
|
|
|
if err != nil {
|
|
|
|
l.Log(logger.Warning, pkg+"Logs could not be sent", "error", err.Error())
|
|
|
|
}
|
|
|
|
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "checking varsum")
|
2020-01-27 05:38:00 +03:00
|
|
|
newVs := ns.VarSum()
|
|
|
|
if vs == newVs {
|
|
|
|
sleep(ns, l)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
vs = newVs
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Info, "varsum changed", "vs", vs)
|
2020-01-27 05:38:00 +03:00
|
|
|
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "getting new vars")
|
2020-01-27 05:38:00 +03:00
|
|
|
vars, err := ns.Vars()
|
|
|
|
if err != nil {
|
|
|
|
l.Log(logger.Error, pkg+"netSender failed to get vars", "error", err.Error())
|
|
|
|
time.Sleep(netSendRetryTime)
|
|
|
|
continue
|
|
|
|
}
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "got new vars", "vars", vars)
|
2020-01-27 05:38:00 +03:00
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// Configure revid based on the vars.
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "updating revid's configuration")
|
2020-01-27 05:38:00 +03:00
|
|
|
err = rv.Update(vars)
|
|
|
|
if err != nil {
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Warning, pkg+"couldn't update revid", "error", err.Error())
|
2020-01-27 05:38:00 +03:00
|
|
|
sleep(ns, l)
|
|
|
|
continue
|
|
|
|
}
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Info, "revid successfully reconfigured")
|
2020-01-27 05:38:00 +03:00
|
|
|
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "checking mode")
|
2020-01-27 05:38:00 +03:00
|
|
|
switch ns.Mode() {
|
|
|
|
case modePaused:
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "mode is Paused, stopping revid")
|
2020-01-27 05:38:00 +03:00
|
|
|
rv.Stop()
|
2020-01-27 08:01:14 +03:00
|
|
|
case modeNormal, modeLoop:
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "mode is Normal or Loop, starting revid")
|
2020-01-27 05:38:00 +03:00
|
|
|
err = rv.Start()
|
|
|
|
if err != nil {
|
2020-01-30 08:24:42 +03:00
|
|
|
l.Log(logger.Error, pkg+"could not start revid", "error", err.Error())
|
2020-01-27 05:38:00 +03:00
|
|
|
ns.SetMode(modePaused, &vs)
|
|
|
|
sleep(ns, l)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case modeBurst:
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "mode is Burst, bursting revid")
|
2020-01-31 07:01:17 +03:00
|
|
|
err = rv.Burst()
|
2020-01-27 05:38:00 +03:00
|
|
|
if err != nil {
|
|
|
|
l.Log(logger.Warning, pkg+"could not start burst", "error", err.Error())
|
|
|
|
ns.SetMode(modePaused, &vs)
|
|
|
|
sleep(ns, l)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ns.SetMode(modePaused, &vs)
|
|
|
|
}
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Info, "revid updated with new mode")
|
2020-01-28 02:59:40 +03:00
|
|
|
|
|
|
|
sleep(ns, l)
|
2020-01-27 05:38:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 09:02:02 +03:00
|
|
|
func createVarMap() map[string]string {
|
2020-05-19 09:46:47 +03:00
|
|
|
m := make(map[string]string)
|
2020-05-19 09:02:02 +03:00
|
|
|
for _, v := range config.Variables {
|
2021-07-22 06:33:01 +03:00
|
|
|
m[v.Name] = v.Type
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// profile opens a file to hold CPU profiling metrics and then starts the
|
|
|
|
// CPU profiler.
|
2020-01-27 05:38:00 +03:00
|
|
|
func profile(l *logger.Logger) {
|
|
|
|
f, err := os.Create(profilePath)
|
|
|
|
if err != nil {
|
|
|
|
l.Log(logger.Fatal, pkg+"could not create CPU profile", "error", err.Error())
|
|
|
|
}
|
|
|
|
if err := pprof.StartCPUProfile(f); err != nil {
|
|
|
|
l.Log(logger.Fatal, pkg+"could not start CPU profile", "error", err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// sleep uses a delay to halt the program based on the monitoring period
|
|
|
|
// netsender parameter (mp) defined in the netsender.conf config.
|
2020-01-27 05:38:00 +03:00
|
|
|
func sleep(ns *netsender.Sender, l *logger.Logger) {
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "sleeping")
|
2020-01-27 05:38:00 +03:00
|
|
|
t, err := strconv.Atoi(ns.Param("mp"))
|
|
|
|
if err != nil {
|
|
|
|
l.Log(logger.Error, pkg+"could not get sleep time, using default", "error", err)
|
|
|
|
t = defaultSleepTime
|
|
|
|
}
|
|
|
|
time.Sleep(time.Duration(t) * time.Second)
|
2020-03-27 15:20:51 +03:00
|
|
|
l.Log(logger.Debug, "finished sleeping")
|
2020-01-27 05:38:00 +03:00
|
|
|
}
|
|
|
|
|
2020-01-27 08:01:14 +03:00
|
|
|
// readPin provides a callback function of consistent signature for use by
|
2021-09-20 11:29:51 +03:00
|
|
|
// netsender to retrieve software defined pin values e.g. revid bitrate.
|
2022-02-03 02:26:04 +03:00
|
|
|
func readPin(p *turbidityProbe, rv *revid.Revid, l *logger.Logger) func(pin *netsender.Pin) error {
|
2020-01-27 05:38:00 +03:00
|
|
|
return func(pin *netsender.Pin) error {
|
|
|
|
switch {
|
2021-09-20 11:29:51 +03:00
|
|
|
case pin.Name == bitratePin:
|
2020-01-27 05:38:00 +03:00
|
|
|
pin.Value = -1
|
|
|
|
if rv != nil {
|
|
|
|
pin.Value = rv.Bitrate()
|
|
|
|
}
|
2022-01-11 07:05:53 +03:00
|
|
|
case pin.Name == sharpnessPin:
|
2022-01-06 07:58:02 +03:00
|
|
|
pin.Value = -1
|
|
|
|
if p != nil {
|
2022-02-03 02:26:04 +03:00
|
|
|
l.Debug("setting sharpness value", "sharpness", p.sharpness*1000)
|
2022-01-11 07:05:53 +03:00
|
|
|
pin.Value = int(p.sharpness * 1000)
|
2022-01-06 07:58:02 +03:00
|
|
|
}
|
|
|
|
case pin.Name == contrastPin:
|
|
|
|
pin.Value = -1
|
|
|
|
if p != nil {
|
2022-02-03 02:26:04 +03:00
|
|
|
l.Debug("setting contrast pin", "contrast", p.contrast)
|
2022-01-06 07:58:02 +03:00
|
|
|
pin.Value = int(p.contrast * 100)
|
|
|
|
}
|
2020-01-27 05:38:00 +03:00
|
|
|
default:
|
|
|
|
pin.Value = -1
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|