mirror of https://bitbucket.org/ausocean/av.git
Merged in burst-mode (pull request #364)
revid: make burst mode part of revid API Approved-by: Saxon Milton <saxon.milton@gmail.com>
This commit is contained in:
commit
9b8f0dc887
|
@ -54,7 +54,6 @@ USAGE
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
|
@ -199,7 +198,7 @@ func run(rv *revid.Revid, ns *netsender.Sender, l *logger.Logger, nl *netlogger.
|
|||
continue
|
||||
}
|
||||
case modeBurst:
|
||||
err = burst(l, rv, ns)
|
||||
err = rv.Burst()
|
||||
if err != nil {
|
||||
l.Log(logger.Warning, pkg+"could not start burst", "error", err.Error())
|
||||
ns.SetMode(modePaused, &vs)
|
||||
|
@ -254,21 +253,3 @@ func readPin(rv *revid.Revid) func(pin *netsender.Pin) error {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// burst starts revid, waits for time specified in the Config.BurstPeriod
|
||||
// field, and then stops revid.
|
||||
//
|
||||
// TODO: move this functionality to the revid API into a Revid.Burst(time) method.
|
||||
func burst(l *logger.Logger, r *revid.Revid, s *netsender.Sender) error {
|
||||
l.Log(logger.Info, pkg+"starting burst")
|
||||
|
||||
err := r.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not start revid: %w", err)
|
||||
}
|
||||
|
||||
time.Sleep(time.Duration(r.Config().BurstPeriod) * time.Second)
|
||||
l.Log(logger.Info, pkg+"stopping burst")
|
||||
r.Stop()
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -492,6 +492,23 @@ func (r *Revid) Stop() {
|
|||
r.running = false
|
||||
}
|
||||
|
||||
// Burst starts revid, waits for time specified, and then stops revid.
|
||||
func (r *Revid) Burst() error {
|
||||
r.cfg.Logger.Log(logger.Info, pkg+"starting burst")
|
||||
|
||||
err := r.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not start revid: %w", err)
|
||||
}
|
||||
|
||||
dur := time.Duration(r.cfg.BurstPeriod) * time.Second
|
||||
time.Sleep(dur)
|
||||
|
||||
r.cfg.Logger.Log(logger.Info, pkg+"stopping burst")
|
||||
r.Stop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Revid) IsRunning() bool {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
|
Loading…
Reference in New Issue