2018-04-19 10:03:12 +03:00
|
|
|
/*
|
|
|
|
NAME
|
2019-11-06 09:57:10 +03:00
|
|
|
revid-cli - command line interface for revid.
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHORS
|
2018-06-20 08:08:34 +03:00
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
Jack Richardson <jack@ausocean.org>
|
2019-05-08 13:01:25 +03:00
|
|
|
Trek Hopton <trek@ausocean.org>
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
LICENSE
|
2018-06-27 01:20:05 +03:00
|
|
|
revid-cli is Copyright (C) 2017-2018 the Australian Ocean Lab (AusOcean)
|
2018-04-19 10:03:12 +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
|
2018-06-20 08:08:34 +03:00
|
|
|
for more details.
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2018-06-20 08:08:34 +03:00
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
2018-04-19 10:03:12 +03:00
|
|
|
*/
|
2018-07-05 14:24:10 +03:00
|
|
|
|
2019-05-08 13:01:25 +03:00
|
|
|
// revid-cli is a command line interface for revid.
|
2018-04-15 13:42:06 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2018-06-09 03:46:04 +03:00
|
|
|
"os"
|
2018-07-05 14:24:10 +03:00
|
|
|
"runtime/pprof"
|
2018-04-19 09:42:07 +03:00
|
|
|
"strconv"
|
2018-12-10 02:09:20 +03:00
|
|
|
"strings"
|
2018-04-19 11:19:36 +03:00
|
|
|
"time"
|
2018-04-19 08:58:16 +03:00
|
|
|
|
2019-06-05 19:39:55 +03:00
|
|
|
"bitbucket.org/ausocean/av/codec/codecutil"
|
2019-03-25 04:21:03 +03:00
|
|
|
"bitbucket.org/ausocean/av/container/mts"
|
|
|
|
"bitbucket.org/ausocean/av/container/mts/meta"
|
2019-11-12 14:55:48 +03:00
|
|
|
"bitbucket.org/ausocean/av/device/raspivid"
|
2018-04-19 11:19:36 +03:00
|
|
|
"bitbucket.org/ausocean/av/revid"
|
2019-11-06 09:57:10 +03:00
|
|
|
"bitbucket.org/ausocean/av/revid/config"
|
2018-05-03 06:51:28 +03:00
|
|
|
"bitbucket.org/ausocean/iot/pi/netsender"
|
2019-02-11 09:19:28 +03:00
|
|
|
"bitbucket.org/ausocean/iot/pi/sds"
|
2019-01-02 08:09:47 +03:00
|
|
|
"bitbucket.org/ausocean/iot/pi/smartlogger"
|
|
|
|
"bitbucket.org/ausocean/utils/logger"
|
2018-04-15 13:42:06 +03:00
|
|
|
)
|
|
|
|
|
2019-02-03 16:07:38 +03:00
|
|
|
// Revid modes
|
|
|
|
const (
|
|
|
|
normal = "Normal"
|
|
|
|
paused = "Paused"
|
|
|
|
burst = "Burst"
|
|
|
|
)
|
|
|
|
|
2018-04-19 09:42:07 +03:00
|
|
|
// Other misc consts
|
|
|
|
const (
|
2019-03-02 07:24:49 +03:00
|
|
|
netSendRetryTime = 5 * time.Second
|
|
|
|
defaultRunDuration = 24 * time.Hour
|
|
|
|
revidStopTime = 5 * time.Second
|
|
|
|
defaultLogPath = "/var/log/netsender"
|
|
|
|
pkg = "revid-cli:"
|
|
|
|
defaultLogVerbosity = logger.Info
|
2019-04-26 10:33:30 +03:00
|
|
|
defaultSleepTime = 60 // Seconds
|
2018-04-19 09:42:07 +03:00
|
|
|
)
|
|
|
|
|
2018-07-05 14:24:10 +03:00
|
|
|
// canProfile is set to false with revid-cli is built with "-tags profile".
|
|
|
|
var canProfile = true
|
|
|
|
|
2019-03-02 07:24:49 +03:00
|
|
|
// The logger that will be used throughout.
|
2019-01-02 08:09:47 +03:00
|
|
|
var log *logger.Logger
|
2018-09-10 12:19:09 +03:00
|
|
|
|
2019-02-07 00:55:37 +03:00
|
|
|
const (
|
|
|
|
metaPreambleKey = "copyright"
|
|
|
|
metaPreambleData = "ausocean.org/license/content2019"
|
2019-02-06 02:49:12 +03:00
|
|
|
)
|
|
|
|
|
2018-09-12 04:41:48 +03:00
|
|
|
func main() {
|
2019-02-07 00:55:37 +03:00
|
|
|
mts.Meta = meta.NewWith([][2]string{{metaPreambleKey, metaPreambleData}})
|
2019-02-06 02:49:12 +03:00
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
useNetsender := flag.Bool("NetSender", false, "Are we checking vars through netsender?")
|
|
|
|
runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?")
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg := handleFlags()
|
2018-09-12 04:41:48 +03:00
|
|
|
if !*useNetsender {
|
2019-02-12 04:02:02 +03:00
|
|
|
rv, err := revid.New(cfg, nil)
|
2018-12-09 08:31:47 +03:00
|
|
|
if err != nil {
|
2019-02-03 13:47:44 +03:00
|
|
|
cfg.Logger.Log(logger.Fatal, pkg+"failed to initialiase revid", "error", err.Error())
|
|
|
|
}
|
|
|
|
if err = rv.Start(); err != nil {
|
2019-01-13 14:45:30 +03:00
|
|
|
cfg.Logger.Log(logger.Fatal, pkg+"failed to start revid", "error", err.Error())
|
2018-12-09 08:31:47 +03:00
|
|
|
}
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(*runDurationPtr)
|
2019-03-02 06:00:46 +03:00
|
|
|
rv.Stop()
|
2018-09-12 04:41:48 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-02 06:16:43 +03:00
|
|
|
run(cfg)
|
2018-09-11 02:25:45 +03:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
// handleFlags parses command line flags and returns a revid configuration
|
|
|
|
// based on them.
|
2019-11-06 09:57:10 +03:00
|
|
|
func handleFlags() config.Config {
|
|
|
|
var cfg config.Config
|
2018-12-06 06:34:55 +03:00
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
var (
|
2019-08-25 10:44:06 +03:00
|
|
|
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
|
|
|
|
inputCodecPtr = flag.String("InputCodec", "H264", "The codec of the input: H264, Mjpeg, PCM, ADPCM")
|
|
|
|
inputPtr = flag.String("Input", "", "The input type: Raspivid, File, v4l, Audio, RTSP")
|
2019-10-23 12:32:10 +03:00
|
|
|
cameraIPPtr = flag.String("CameraIP", "", "The IP of the RTSP server")
|
2019-08-25 10:44:06 +03:00
|
|
|
verbosityPtr = flag.String("Verbosity", "Info", "Verbosity: Debug, Info, Warning, Error, Fatal")
|
|
|
|
rtpAddrPtr = flag.String("RtpAddr", "", "Rtp destination address: <IP>:<port> (port is generally 6970-6999)")
|
|
|
|
logPathPtr = flag.String("LogPath", defaultLogPath, "The log path")
|
|
|
|
configFilePtr = flag.String("ConfigFile", "", "NetSender config file")
|
|
|
|
rtmpUrlPtr = flag.String("RtmpUrl", "", "Url of rtmp endpoint")
|
|
|
|
outputPathPtr = flag.String("OutputPath", "", "The directory of the output file")
|
|
|
|
inputFilePtr = flag.String("InputPath", "", "The directory of the input file")
|
|
|
|
httpAddressPtr = flag.String("HttpAddress", "", "Destination address of http posts")
|
|
|
|
verticalFlipPtr = flag.Bool("VerticalFlip", false, "Flip video vertically: Yes, No")
|
|
|
|
horizontalFlipPtr = flag.Bool("HorizontalFlip", false, "Flip video horizontally: Yes, No")
|
2020-01-24 12:54:23 +03:00
|
|
|
loopPtr = flag.Bool("Loop", false, "Loop input source on completion (true/false)")
|
2019-08-25 10:44:06 +03:00
|
|
|
bitratePtr = flag.Uint("Bitrate", 0, "Bitrate of recorded video")
|
|
|
|
heightPtr = flag.Uint("Height", 0, "Height in pixels")
|
|
|
|
widthPtr = flag.Uint("Width", 0, "Width in pixels")
|
|
|
|
frameRatePtr = flag.Uint("FrameRate", 0, "Frame rate of captured video")
|
|
|
|
quantizationPtr = flag.Uint("Quantization", 0, "Desired quantization value: 0-40")
|
|
|
|
rotationPtr = flag.Uint("Rotation", 0, "Rotate video output. (0-359 degrees)")
|
|
|
|
brightnessPtr = flag.Uint("Brightness", 50, "Set brightness. (0-100) ")
|
|
|
|
saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)")
|
2019-11-12 14:55:48 +03:00
|
|
|
exposurePtr = flag.String("Exposure", "auto", "Set exposure mode. ("+strings.Join(raspivid.ExposureModes[:], ",")+")")
|
|
|
|
autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode. ("+strings.Join(raspivid.AutoWhiteBalanceModes[:], ",")+")")
|
2020-01-25 02:09:42 +03:00
|
|
|
fileFPSPtr = flag.Int("FileFPS", 0, "File source frame processing FPS")
|
2019-05-05 11:26:14 +03:00
|
|
|
|
|
|
|
// Audio specific flags.
|
|
|
|
sampleRatePtr = flag.Int("SampleRate", 48000, "Sample rate of recorded audio")
|
|
|
|
channelsPtr = flag.Int("Channels", 1, "Record in Mono or Stereo (1 or 2)")
|
2019-05-21 06:09:10 +03:00
|
|
|
recPeriodPtr = flag.Float64("recPeriod", 1, "How many seconds to record at a time")
|
2019-05-05 11:26:14 +03:00
|
|
|
bitDepthPtr = flag.Int("bitDepth", 16, "Bit Depth to record audio at.")
|
2018-12-05 12:24:52 +03:00
|
|
|
)
|
2018-09-11 02:25:45 +03:00
|
|
|
|
2019-01-19 12:09:43 +03:00
|
|
|
var outputs flagStrings
|
|
|
|
flag.Var(&outputs, "Output", "output type: Http, Rtmp, File, Udp, Rtp (may be used more than once)")
|
|
|
|
|
2018-09-12 04:30:04 +03:00
|
|
|
flag.Parse()
|
|
|
|
|
2019-02-12 11:07:15 +03:00
|
|
|
switch *verbosityPtr {
|
|
|
|
case "Debug":
|
|
|
|
cfg.LogLevel = logger.Debug
|
|
|
|
case "Info":
|
|
|
|
cfg.LogLevel = logger.Info
|
|
|
|
case "Warning":
|
|
|
|
cfg.LogLevel = logger.Warning
|
|
|
|
case "Error":
|
|
|
|
cfg.LogLevel = logger.Error
|
|
|
|
case "Fatal":
|
|
|
|
cfg.LogLevel = logger.Fatal
|
|
|
|
default:
|
2019-02-28 09:23:06 +03:00
|
|
|
cfg.LogLevel = defaultLogVerbosity
|
2019-02-12 11:07:15 +03:00
|
|
|
}
|
|
|
|
|
2019-10-23 05:18:22 +03:00
|
|
|
log = logger.New(cfg.LogLevel, &smartlogger.New(*logPathPtr).LogRoller, true)
|
2018-09-11 02:25:45 +03:00
|
|
|
|
2019-01-02 08:09:47 +03:00
|
|
|
cfg.Logger = log
|
2018-09-12 04:27:56 +03:00
|
|
|
|
2018-07-05 14:24:10 +03:00
|
|
|
if *cpuprofile != "" {
|
|
|
|
if canProfile {
|
|
|
|
f, err := os.Create(*cpuprofile)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Fatal, pkg+"could not create CPU profile", "error", err.Error())
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
if err := pprof.StartCPUProfile(f); err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Fatal, pkg+"could not start CPU profile", "error", err.Error())
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
defer pprof.StopCPUProfile()
|
|
|
|
} else {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"ignoring cpuprofile flag - http/pprof built in.")
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *inputPtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Raspivid":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Input = config.InputRaspivid
|
2019-01-17 08:34:04 +03:00
|
|
|
case "v4l":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Input = config.InputV4L
|
2018-04-15 13:42:06 +03:00
|
|
|
case "File":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Input = config.InputFile
|
2019-04-23 08:21:17 +03:00
|
|
|
case "Audio":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Input = config.InputAudio
|
2019-05-21 05:48:52 +03:00
|
|
|
case "RTSP":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Input = config.InputRTSP
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"bad input argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *inputCodecPtr {
|
2018-11-18 10:43:38 +03:00
|
|
|
case "H264":
|
2019-06-05 19:39:55 +03:00
|
|
|
cfg.InputCodec = codecutil.H264
|
2019-04-23 09:50:47 +03:00
|
|
|
case "PCM":
|
2019-06-05 19:39:55 +03:00
|
|
|
cfg.InputCodec = codecutil.PCM
|
2019-04-23 09:50:47 +03:00
|
|
|
case "ADPCM":
|
2019-06-05 19:39:55 +03:00
|
|
|
cfg.InputCodec = codecutil.ADPCM
|
2019-12-03 07:25:08 +03:00
|
|
|
case "MJPEG":
|
2019-12-03 04:35:57 +03:00
|
|
|
cfg.InputCodec = codecutil.MJPEG
|
2018-04-19 12:37:25 +03:00
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"bad input codec argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 10:33:30 +03:00
|
|
|
switch *inputPtr {
|
|
|
|
case "Audio":
|
2019-05-21 06:09:10 +03:00
|
|
|
cfg.WriteRate = 1.0 / (*recPeriodPtr)
|
2019-04-26 10:33:30 +03:00
|
|
|
default:
|
2019-05-21 06:09:10 +03:00
|
|
|
cfg.WriteRate = float64(*frameRatePtr)
|
2019-04-26 10:33:30 +03:00
|
|
|
}
|
|
|
|
|
2019-01-19 12:09:43 +03:00
|
|
|
for _, o := range outputs {
|
|
|
|
switch o {
|
|
|
|
case "File":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Outputs = append(cfg.Outputs, config.OutputFile)
|
2019-01-19 12:09:43 +03:00
|
|
|
case "Http":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Outputs = append(cfg.Outputs, config.OutputHTTP)
|
2019-01-19 12:09:43 +03:00
|
|
|
case "Rtmp":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Outputs = append(cfg.Outputs, config.OutputRTMP)
|
2019-01-19 12:09:43 +03:00
|
|
|
case "Rtp":
|
2019-11-06 09:57:10 +03:00
|
|
|
cfg.Outputs = append(cfg.Outputs, config.OutputRTP)
|
2019-01-19 12:09:43 +03:00
|
|
|
case "":
|
|
|
|
default:
|
|
|
|
log.Log(logger.Error, pkg+"bad output argument", "arg", o)
|
|
|
|
}
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2019-01-05 01:18:47 +03:00
|
|
|
if *configFilePtr != "" {
|
|
|
|
netsender.ConfigFile = *configFilePtr
|
|
|
|
}
|
|
|
|
|
2020-01-25 02:23:21 +03:00
|
|
|
cfg.FileFPS = *fileFPSPtr
|
2020-01-24 12:35:43 +03:00
|
|
|
cfg.Loop = *loopPtr
|
2019-10-22 07:24:38 +03:00
|
|
|
cfg.CameraIP = *cameraIPPtr
|
2019-03-04 04:41:34 +03:00
|
|
|
cfg.Rotation = *rotationPtr
|
2019-12-06 09:06:29 +03:00
|
|
|
cfg.HorizontalFlip = *horizontalFlipPtr
|
|
|
|
cfg.VerticalFlip = *verticalFlipPtr
|
2019-05-13 09:53:38 +03:00
|
|
|
cfg.RTMPURL = *rtmpUrlPtr
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Bitrate = *bitratePtr
|
2019-02-12 10:52:46 +03:00
|
|
|
cfg.OutputPath = *outputPathPtr
|
|
|
|
cfg.InputPath = *inputFilePtr
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Height = *heightPtr
|
|
|
|
cfg.Width = *widthPtr
|
|
|
|
cfg.FrameRate = *frameRatePtr
|
2019-05-13 09:53:38 +03:00
|
|
|
cfg.HTTPAddress = *httpAddressPtr
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Quantization = *quantizationPtr
|
2019-05-13 09:53:38 +03:00
|
|
|
cfg.RTPAddress = *rtpAddrPtr
|
2019-03-15 05:14:13 +03:00
|
|
|
cfg.Brightness = *brightnessPtr
|
|
|
|
cfg.Saturation = *saturationPtr
|
|
|
|
cfg.Exposure = *exposurePtr
|
2019-03-15 10:35:15 +03:00
|
|
|
cfg.AutoWhiteBalance = *autoWhiteBalancePtr
|
2019-04-24 07:28:56 +03:00
|
|
|
cfg.SampleRate = *sampleRatePtr
|
|
|
|
cfg.Channels = *channelsPtr
|
|
|
|
cfg.RecPeriod = *recPeriodPtr
|
|
|
|
cfg.BitDepth = *bitDepthPtr
|
2019-03-15 05:14:13 +03:00
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
return cfg
|
2018-09-12 04:41:48 +03:00
|
|
|
}
|
2018-04-19 09:42:07 +03:00
|
|
|
|
2018-09-12 04:41:48 +03:00
|
|
|
// initialize then run the main NetSender client
|
2019-11-06 09:57:10 +03:00
|
|
|
func run(cfg config.Config) {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Info, pkg+"running in NetSender mode")
|
2018-09-12 04:41:48 +03:00
|
|
|
|
2019-02-12 04:02:02 +03:00
|
|
|
var rv *revid.Revid
|
2019-02-04 09:42:30 +03:00
|
|
|
|
2019-02-12 04:02:02 +03:00
|
|
|
readPin := func(pin *netsender.Pin) error {
|
|
|
|
switch {
|
|
|
|
case pin.Name == "X23":
|
2019-03-04 02:22:42 +03:00
|
|
|
pin.Value = -1
|
|
|
|
if rv != nil {
|
2019-03-04 02:04:49 +03:00
|
|
|
pin.Value = rv.Bitrate()
|
2019-03-02 07:24:49 +03:00
|
|
|
}
|
2019-02-12 04:02:02 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-12-05 09:39:28 +03:00
|
|
|
ns, err := netsender.New(log, nil, readPin, nil, config.TypeData)
|
2018-09-12 04:41:48 +03:00
|
|
|
if err != nil {
|
2019-07-26 12:25:56 +03:00
|
|
|
log.Log(logger.Fatal, pkg+"could not initialise netsender client: "+err.Error())
|
2019-02-04 09:34:49 +03:00
|
|
|
}
|
|
|
|
|
2019-03-02 07:24:49 +03:00
|
|
|
var vs int
|
2018-09-12 04:41:48 +03:00
|
|
|
for {
|
2019-02-11 09:19:28 +03:00
|
|
|
err = ns.Run()
|
2019-02-05 03:02:16 +03:00
|
|
|
if err != nil {
|
2019-04-15 06:43:01 +03:00
|
|
|
log.Log(logger.Warning, pkg+"Run Failed. Retrying...", "error", err.Error())
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(netSendRetryTime)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-03-02 07:24:49 +03:00
|
|
|
// If var sum hasn't changed we continue.
|
|
|
|
var vars map[string]string
|
|
|
|
newVs := ns.VarSum()
|
|
|
|
if vs == newVs {
|
2019-02-04 09:42:30 +03:00
|
|
|
goto sleep
|
2019-02-04 05:55:37 +03:00
|
|
|
}
|
2019-03-02 07:24:49 +03:00
|
|
|
vs = newVs
|
2019-02-04 05:55:37 +03:00
|
|
|
|
2019-02-04 09:42:30 +03:00
|
|
|
vars, err = ns.Vars()
|
2019-02-04 05:55:37 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Log(logger.Error, pkg+"netSender failed to get vars", "error", err.Error())
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(netSendRetryTime)
|
|
|
|
continue
|
|
|
|
}
|
2019-03-02 07:24:49 +03:00
|
|
|
|
|
|
|
if rv == nil {
|
|
|
|
rv, err = revid.New(cfg, ns)
|
|
|
|
if err != nil {
|
2019-03-02 07:53:33 +03:00
|
|
|
log.Log(logger.Warning, pkg+"could not initialise revid", "error", err.Error())
|
2019-03-02 07:24:49 +03:00
|
|
|
goto sleep
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 04:41:48 +03:00
|
|
|
|
2019-02-05 03:02:16 +03:00
|
|
|
err = rv.Update(vars)
|
|
|
|
if err != nil {
|
2019-03-02 07:53:33 +03:00
|
|
|
log.Log(logger.Warning, pkg+"Couldn't update revid", "error", err.Error())
|
2019-03-02 07:24:49 +03:00
|
|
|
goto sleep
|
2019-02-04 05:55:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ns.Mode() {
|
|
|
|
case paused:
|
2019-03-02 07:24:49 +03:00
|
|
|
rv.Stop()
|
2019-02-04 05:55:37 +03:00
|
|
|
case normal:
|
2019-02-05 03:02:16 +03:00
|
|
|
err = rv.Start()
|
2018-09-12 04:41:48 +03:00
|
|
|
if err != nil {
|
2019-03-02 07:53:33 +03:00
|
|
|
log.Log(logger.Warning, pkg+"could not start revid", "error", err.Error())
|
2019-03-02 07:24:49 +03:00
|
|
|
ns.SetMode(paused, &vs)
|
|
|
|
goto sleep
|
2018-09-12 04:41:48 +03:00
|
|
|
}
|
2019-02-04 05:55:37 +03:00
|
|
|
case burst:
|
2019-02-04 09:34:49 +03:00
|
|
|
log.Log(logger.Info, pkg+"Starting burst...")
|
2019-03-02 07:24:49 +03:00
|
|
|
|
2019-02-05 03:02:16 +03:00
|
|
|
err = rv.Start()
|
|
|
|
if err != nil {
|
2019-03-02 07:53:33 +03:00
|
|
|
log.Log(logger.Warning, pkg+"could not start burst", "error", err.Error())
|
2019-03-02 07:24:49 +03:00
|
|
|
ns.SetMode(paused, &vs)
|
|
|
|
goto sleep
|
2018-09-12 04:41:48 +03:00
|
|
|
}
|
2019-03-02 07:24:49 +03:00
|
|
|
|
2019-02-04 09:34:49 +03:00
|
|
|
time.Sleep(time.Duration(rv.Config().BurstPeriod) * time.Second)
|
|
|
|
log.Log(logger.Info, pkg+"Stopping burst...")
|
2019-03-02 06:00:46 +03:00
|
|
|
rv.Stop()
|
2019-02-04 05:55:37 +03:00
|
|
|
ns.SetMode(paused, &vs)
|
2018-09-12 04:41:48 +03:00
|
|
|
}
|
2019-03-02 07:24:49 +03:00
|
|
|
|
2019-02-04 09:42:30 +03:00
|
|
|
sleep:
|
2019-02-05 03:15:15 +03:00
|
|
|
sleepTime, err := strconv.Atoi(ns.Param("mp"))
|
|
|
|
if err != nil {
|
2019-03-02 07:24:49 +03:00
|
|
|
log.Log(logger.Error, pkg+"could not get sleep time, using default")
|
|
|
|
sleepTime = defaultSleepTime
|
2018-09-12 04:41:48 +03:00
|
|
|
}
|
|
|
|
time.Sleep(time.Duration(sleepTime) * time.Second)
|
2018-04-20 05:20:33 +03:00
|
|
|
}
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|
|
|
|
|
2019-01-19 12:09:43 +03:00
|
|
|
// flagStrings implements an appending string set flag.
|
|
|
|
type flagStrings []string
|
2018-06-08 15:56:20 +03:00
|
|
|
|
2019-01-19 12:09:43 +03:00
|
|
|
func (v *flagStrings) String() string {
|
|
|
|
if *v != nil {
|
|
|
|
return strings.Join(*v, ",")
|
2019-01-13 14:34:50 +03:00
|
|
|
}
|
2019-01-19 12:09:43 +03:00
|
|
|
return ""
|
2018-05-07 04:16:44 +03:00
|
|
|
}
|
|
|
|
|
2019-01-19 12:09:43 +03:00
|
|
|
func (v *flagStrings) Set(s string) error {
|
|
|
|
if s == "" {
|
|
|
|
return nil
|
2018-05-07 04:16:44 +03:00
|
|
|
}
|
2019-01-19 12:09:43 +03:00
|
|
|
for _, e := range *v {
|
|
|
|
if e == s {
|
|
|
|
return nil
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-19 12:09:43 +03:00
|
|
|
*v = append(*v, s)
|
|
|
|
return nil
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|
2019-01-19 12:09:43 +03:00
|
|
|
|
|
|
|
func (v *flagStrings) Get() interface{} { return *v }
|