ready for some testing

This commit is contained in:
Saxon1 2018-04-19 16:33:12 +09:30
parent f50e1085b2
commit 0381a5dda0
1 changed files with 80 additions and 26 deletions

View File

@ -1,3 +1,30 @@
/*
NAME
RevidCLI.go
DESCRIPTION
See Readme.md
AUTHORS
Saxon A. Nelson-Milton <saxon@ausocean.org>
Jack Richardson <jack@ausocean.org>
LICENSE
RevidCLI.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
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 [GNU licenses](http://www.gnu.org/licenses).
*/
package main package main
import ( import (
@ -76,8 +103,10 @@ func main() {
flags[i] = flag.String(flagNames[i][0], "", flagNames[i][1]) flags[i] = flag.String(flagNames[i][0], "", flagNames[i][1])
} }
// Do we want a netsender session
netSenderFlagPtr := flag.Bool("netSender", false, "Are we checking vars through netsender?") netSenderFlagPtr := flag.Bool("netSender", false, "Are we checking vars through netsender?")
runDurationPtr := flag.Int("runDuration",defaultRunDuration,"how long do you want revid to run for?") // User might also want to define how long revid runs for
runDurationPtr := flag.Int("runDuration",defaultRunDuration,"How long do you want revid to run for?")
flag.Parse() flag.Parse()
@ -147,25 +176,18 @@ func main() {
config.Timeout = flags[timeoutPtr] config.Timeout = flags[timeoutPtr]
config.IntraRefreshPeriod = flags[intraRefreshPeriodPtr] config.IntraRefreshPeriod = flags[intraRefreshPeriodPtr]
// Try to create the revid instance with the given config createRevidInstance()
for revid, err := NewRevid(config); err != nil; {
// If the config does have a logger, use it to output error, otherwise
// just output to std output
if config.Logger != nil {
config.Logger.Log("FATAL ERROR", err)
} else {
fmt.Printf("FATAL ERROR: %v", err)
}
}
revid.Start() revid.Start()
// Is the netsender flag been used ? if so run this loop
for *netSenderFlagPtr { for *netSenderFlagPtr {
periodicNetsenderReport() periodicNetsenderReport()
sleepTime, err := strconv.Atoi(netsender.GetConfigParam("monPeriod")) sleepTime, err := strconv.Atoi(netsender.GetConfigParam("monPeriod"))
time.Sleep(time.Duration(sleepTime) * time.Second) time.Sleep(time.Duration(sleepTime) * time.Second)
} }
// If we're not running a netsender session then we run revid for the amount
// of time the user defined or the default 2 days
time.Sleep( time.Duration(*runDurationPtr) * time.Second ) time.Sleep( time.Duration(*runDurationPtr) * time.Second )
revid.Stop() revid.Stop()
} }
@ -212,43 +234,62 @@ func periodicNetsenderReport(){
} }
func updateRevid() { func updateRevid() {
revid.Stop() revid.Stop()
time.Sleep( time.Duration(revidStopTime) * time.Second ) time.Sleep( time.Duration(revidStopTime) * time.Second )
for key, value := range vars { for key, value := range vars {
switch key { switch key {
case "FramesPerClip": case "FramesPerClip":
config.FramesPerClip = value asInt,err := strconv.Atoi(value)
if asInt > 0 && err == nil {
config.FramesPerClip = value
}
case "RtmpUrl": case "RtmpUrl":
config.RtmpUrl = value config.RtmpUrl = value
case "Bitrate": case "Bitrate":
config.Bitrate = value asInt,err := strconv.Atoi(value)
if asInt > 0 && err == nil {
config.Bitrate = value
}
case "OutputFileName": case "OutputFileName":
config.OutputFileName = value config.OutputFileName = value
case "InputFileName": case "InputFileName":
config.InputFileName = value config.InputFileName = value
case "Height": case "Height":
config.Height = value asInt,err := strconv.Atoi(value)
if asInt > 0 && err == nil {
config.Height = value
}
case "Width": case "Width":
config.Width = value asInt,err := strconv.Atoi(value)
if asInt > 0 && err == nil {
config.Width = value
}
case "FrameRate": case "FrameRate":
config.FrameRate = value asInt,err := strconv.Atoi(value)
if asInt > 0 && err == nil {
config.FrameRate = value
}
case "HttpAddress": case "HttpAddress":
config.HttpAddress = value config.HttpAddress = value
case "Quantization": case "Quantization":
config.Quantization = value asInt,err := strconv.Atoi(value)
if asInt > 0 && err == nil {
config.Quantization = value
}
case "Timeout": case "Timeout":
config.Timeout = value asInt,err := strconv.Atoi(value)
if asInt > 0 && err == nil {
config.Timeout = value
}
case "IntraRefreshPeriod": case "IntraRefreshPeriod":
confog.IntraRefreshPeriod = value asInt,err := strconv.Atoi(value)
if asInt > 0 && err == nil {
confog.IntraRefreshPeriod = value
}
} }
} }
revid, err := Newrevidance(config) createRevidInstance()
if err != nil {
fmt.Println(err)
}
revid.Start() revid.Start()
} }
@ -340,3 +381,16 @@ func revidReportActions(pin int) (int, error) {
return -1, errors.New("External pin not defined") return -1, errors.New("External pin not defined")
} }
} }
func createRevidInstance(){
// Try to create the revid instance with the given config
for revid, err := NewRevid(config); err != nil; {
// If the config does have a logger, use it to output error, otherwise
// just output to std output
if config.Logger != nil {
config.Logger.Log("FATAL ERROR", err)
} else {
fmt.Printf("FATAL ERROR: %v", err)
}
}
}