cmd/revid-cli & stream/mts/meta: added meta.NewWith function that creates a new meta.Data and adds an initial entry. Using meta.NewWith in revid-cli to initialise mts' global meta.Data with some preamble data.

This commit is contained in:
saxon 2019-02-06 10:19:12 +10:30
parent d523677627
commit 2b7ab27763
3 changed files with 26 additions and 10 deletions

View File

@ -37,6 +37,8 @@ import (
"time" "time"
"bitbucket.org/ausocean/av/revid" "bitbucket.org/ausocean/av/revid"
"bitbucket.org/ausocean/av/stream/mts"
"bitbucket.org/ausocean/av/stream/mts/meta"
"bitbucket.org/ausocean/iot/pi/netsender" "bitbucket.org/ausocean/iot/pi/netsender"
"bitbucket.org/ausocean/iot/pi/smartlogger" "bitbucket.org/ausocean/iot/pi/smartlogger"
"bitbucket.org/ausocean/utils/logger" "bitbucket.org/ausocean/utils/logger"
@ -65,7 +67,16 @@ var canProfile = true
// The logger that will be used throughout // The logger that will be used throughout
var log *logger.Logger var log *logger.Logger
var (
metaPreambleKey = []byte{0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74}
metaPreambleData = []byte{0x61, 0x75, 0x73, 0x6f, 0x63, 0x65, 0x61, 0x6e, 0x2e,
0x6f, 0x72, 0x67, 0x2f, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2f, 0x63,
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x32, 0x30, 0x31, 0x39}
)
func main() { func main() {
mts.Meta = meta.NewWith(string(metaPreambleKey), string(metaPreambleData))
useNetsender := flag.Bool("NetSender", false, "Are we checking vars through netsender?") 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?") runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?")

View File

@ -88,17 +88,8 @@ const (
psiSndCnt = 7 psiSndCnt = 7
) )
const (
copyright = "copyright"
license = "ausocean.org/license/content2019"
)
// global Meta // global Meta
var Meta = meta.New() var Meta *meta.Data
func init() {
Meta.Add(copyright, license)
}
var ( var (
patTable = standardPat.Bytes() patTable = standardPat.Bytes()

View File

@ -76,6 +76,20 @@ func New() *Data {
} }
} }
func NewWith(key, data string) *Data {
meta := &Data{
data: make(map[string]string),
enc: []byte{
0x00, // Reserved byte
(majVer << 4) | minVer, // MS and LS versions
0x00, // Data len byte1
0x00, // Data len byte2
},
}
meta.Add(key, data)
return meta
}
// Add adds metadata with key and val. // Add adds metadata with key and val.
func (m *Data) Add(key, val string) { func (m *Data) Add(key, val string) {
m.mu.Lock() m.mu.Lock()