github.com/nvi-inc/fsgo@v0.2.1/versions/fs9.12.12/rdbe.go (about) 1 // Copyright 2019 NVI Inc. All rights reserved. 2 // Use of this source code is governed by a MIT 3 // license that can be found in the LICENSE file. 4 5 package fs 6 7 import ( 8 "errors" 9 "github.com/fatih/structs" 10 ) 11 12 func (f *FieldSystem) RdbeNum() int { 13 return len(f.Fscom.RdbeTsysData[:]) 14 } 15 16 func (f *FieldSystem) RdbeMap(index int) (m map[string]interface{}, err error) { 17 if index < 0 || index >= f.RdbeNum() { 18 err = errors.New("invalid RDBE id") 19 return 20 } 21 22 i := int(f.Fscom.RdbeTsysData[index].Iping) 23 if i < 0 || i >= len(f.Fscom.RdbeTsysData[index].Data) { 24 err = errors.New("no data available") 25 return 26 } 27 28 data := f.Fscom.RdbeTsysData[index].Data[i] 29 m = structs.Map(data) 30 m["Epoch"] = cstr(data.Epoch[:]) 31 32 m["PcalAmp"] = data.PcalAmp[:] 33 m["PcalPhase"] = data.PcalPhase[:] 34 35 tsysmap := make([][]float32, len(data.Tsys)) 36 for i := range data.Tsys { 37 tsysmap[i] = data.Tsys[i][:] 38 } 39 m["Tsys"] = tsysmap 40 41 return m, nil 42 } 43 44 // Returns a function which returns if RDBE info has been updated 45 // since last check 46 func (f *FieldSystem) RdbeUpdatedFn(index int) (func() bool, error) { 47 if index < 0 || index >= f.RdbeNum() { 48 return nil, errors.New("invalid RDBE index") 49 } 50 i := -1 51 return func() bool { 52 j := int(f.Fscom.RdbeTsysData[index].Iping) 53 if j < 0 || j >= len(f.Fscom.RdbeTsysData[index].Data) || i == j { 54 i = j // For case when j < 0 55 return false 56 } 57 i = j 58 return true 59 }, nil 60 61 }