diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 6ca6ba68..81c2e55a 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -40,6 +40,7 @@ import ( "bitbucket.org/ausocean/av/stream/mts" "bitbucket.org/ausocean/av/stream/mts/meta" "bitbucket.org/ausocean/iot/pi/netsender" + "bitbucket.org/ausocean/iot/pi/sds" "bitbucket.org/ausocean/iot/pi/smartlogger" "bitbucket.org/ausocean/utils/logger" ) @@ -86,7 +87,6 @@ func main() { runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?") cfg := handleFlags() - if !*useNetsender { rv, err := revid.New(cfg, nil) if err != nil { @@ -266,21 +266,33 @@ func run(cfg revid.Config) error { var vars map[string]string - // initialize NetSender and use NetSender's logger - var ns netsender.Sender - err := ns.Init(log, nil, nil, nil) + var rv *revid.Revid + + readPin := func(pin *netsender.Pin) error { + switch { + case pin.Name == "X23": + pin.Value = rv.Bitrate() + case pin.Name[0] == 'X': + return sds.ReadSystem(pin) + default: + pin.Value = -1 + } + return nil // Return error only if we want NetSender to generate an error + } + + ns, err := netsender.New(log, nil, readPin, nil) if err != nil { return err } - vars, _ = ns.Vars() - vs := ns.VarSum() - - rv, err := revid.New(cfg, &ns) + rv, err = revid.New(cfg, ns) if err != nil { log.Log(logger.Fatal, pkg+"could not initialise revid", "error", err.Error()) } + vars, _ = ns.Vars() + vs := ns.VarSum() + // Update revid to get latest config settings from netreceiver. err = rv.Update(vars) if err != nil { @@ -300,8 +312,7 @@ func run(cfg revid.Config) error { } for { - // TODO(saxon): replace this call with call to ns.Run(). - err = send(&ns, rv) + err = ns.Run() if err != nil { log.Log(logger.Error, pkg+"Run Failed. Retrying...", "error", err.Error()) time.Sleep(netSendRetryTime) @@ -356,29 +367,6 @@ func run(cfg revid.Config) error { } } -// send implements our main NetSender client and handles NetReceiver configuration -// (as distinct from httpSender which just sends video data). -func send(ns *netsender.Sender, rv *revid.Revid) error { - // populate input values, if any - inputs := netsender.MakePins(ns.Param("ip"), "X") - if rv != nil { - for i, pin := range inputs { - if pin.Name == "X23" { - inputs[i].Value = rv.Bitrate() - } - } - } - - _, 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. type flagStrings []string