cmd/revid-cli: replaced use of send() with netsender.Run() and implemented readPin func.

This commit is contained in:
saxon 2019-02-11 16:49:28 +10:30
parent 934653991d
commit f67fb1ec8a
1 changed files with 13 additions and 25 deletions

View File

@ -40,6 +40,7 @@ import (
"bitbucket.org/ausocean/av/stream/mts" "bitbucket.org/ausocean/av/stream/mts"
"bitbucket.org/ausocean/av/stream/mts/meta" "bitbucket.org/ausocean/av/stream/mts/meta"
"bitbucket.org/ausocean/iot/pi/netsender" "bitbucket.org/ausocean/iot/pi/netsender"
"bitbucket.org/ausocean/iot/pi/sds"
"bitbucket.org/ausocean/iot/pi/smartlogger" "bitbucket.org/ausocean/iot/pi/smartlogger"
"bitbucket.org/ausocean/utils/logger" "bitbucket.org/ausocean/utils/logger"
) )
@ -267,8 +268,7 @@ func run(cfg revid.Config) error {
var vars map[string]string var vars map[string]string
// initialize NetSender and use NetSender's logger // initialize NetSender and use NetSender's logger
var ns netsender.Sender ns, err := netsender.New(log, nil, readPin, nil)
err := ns.Init(log, nil, nil, nil)
if err != nil { if err != nil {
return err return err
} }
@ -276,7 +276,7 @@ func run(cfg revid.Config) error {
vars, _ = ns.Vars() vars, _ = ns.Vars()
vs := ns.VarSum() vs := ns.VarSum()
rv, err := revid.New(cfg, &ns) rv, err := revid.New(cfg, ns)
if err != nil { if err != nil {
log.Log(logger.Fatal, pkg+"could not initialise revid", "error", err.Error()) log.Log(logger.Fatal, pkg+"could not initialise revid", "error", err.Error())
} }
@ -300,8 +300,7 @@ func run(cfg revid.Config) error {
} }
for { for {
// TODO(saxon): replace this call with call to ns.Run(). err = ns.Run()
err = send(&ns, rv)
if err != nil { if err != nil {
log.Log(logger.Error, pkg+"Run Failed. Retrying...", "error", err.Error()) log.Log(logger.Error, pkg+"Run Failed. Retrying...", "error", err.Error())
time.Sleep(netSendRetryTime) time.Sleep(netSendRetryTime)
@ -356,27 +355,16 @@ func run(cfg revid.Config) error {
} }
} }
// send implements our main NetSender client and handles NetReceiver configuration func readPin(pin *netsender.Pin) error {
// (as distinct from httpSender which just sends video data). switch {
func send(ns *netsender.Sender, rv *revid.Revid) error { case pin.Name == "X23":
// populate input values, if any //pin.Value = rv.Bitrate()
inputs := netsender.MakePins(ns.Param("ip"), "X") case pin.Name[0] == 'X':
if rv != nil { return sds.ReadSystem(pin)
for i, pin := range inputs { default:
if pin.Name == "X23" { pin.Value = -1
inputs[i].Value = rv.Bitrate()
} }
} return nil // Return error only if we want NetSender to generate an error
}
_, reconfig, err := ns.Send(netsender.RequestPoll, inputs)
if err != nil {
return err
}
if reconfig {
return ns.Config()
}
return nil
} }
// flagStrings implements an appending string set flag. // flagStrings implements an appending string set flag.