revid: using location instead of gps in names

This commit is contained in:
saxon 2018-12-14 16:02:47 +10:30
parent e79f6d191d
commit 21dd2f4b70
6 changed files with 79 additions and 79 deletions

View File

@ -170,12 +170,12 @@ func (s *httpSender) extractMeta(r string) error {
mts.SetTimeStamp(uint64(t)) mts.SetTimeStamp(uint64(t))
} }
// Extract gps from reply // Extract location from reply
g, err := dec.String("ll") g, err := dec.String("ll")
if err != nil { if err != nil {
s.log(smartlogger.Warning, pkg+"No gps in reply") s.log(smartlogger.Warning, pkg+"No location in reply")
} else { } else {
s.log(smartlogger.Debug, fmt.Sprintf("%v got gps: %v", pkg, g)) s.log(smartlogger.Debug, fmt.Sprintf("%v got location: %v", pkg, g))
mts.SetLocation(g) mts.SetLocation(g)
} }

View File

@ -47,23 +47,23 @@ const (
) )
type MetaData struct { type MetaData struct {
time uint64 time uint64
gps string location string
} }
var metaData = MetaData{time: 0, gps: ""} var metaData = MetaData{time: 0, location: ""}
func SetTimeStamp(t uint64) { func SetTimeStamp(t uint64) {
metaData.time = t metaData.time = t
} }
func SetLocation(g string) { func SetLocation(g string) {
metaData.gps = g metaData.location = g
} }
func init() { func init() {
patTable = psi.StdPat.Bytes() patTable = psi.StdPat.Bytes()
pmtTable = psi.StdPmtTimeGps.Bytes() pmtTable = psi.StdPmtTimeLocation.Bytes()
} }
const ( const (
@ -188,12 +188,12 @@ func (e *Encoder) writePSI() error {
return err return err
} }
// Update pmt table time and gps // Update pmt table time and location
err = psi.UpdateTime(pmtTable, metaData.time) err = psi.UpdateTime(pmtTable, metaData.time)
if err != nil { if err != nil {
return err return err
} }
err = psi.UpdateGps(pmtTable, metaData.gps) err = psi.UpdateLocation(pmtTable, metaData.location)
if err != nil { if err != nil {
return nil return nil
} }

View File

@ -3,7 +3,7 @@ NAME
op.go op.go
DESCRIPTION DESCRIPTION
op.go provides functionality for editing and reading bytes slices op.go provides functionality for editing and reading bytes slices
directly in order to insert/read timestamp and gps data in psi. directly in order to insert/read timestamp and location data in psi.
AUTHOR AUTHOR
Saxon Milton <saxon@ausocean.org> Saxon Milton <saxon@ausocean.org>
@ -52,11 +52,11 @@ func ChkTime(p []byte) error {
return nil return nil
} }
// ChkGps takes a psi as a byte slice and checks to see if it has a gps descriptor // ChkLocation takes a psi as a byte slice and checks to see if it has a location descriptor
// - if so return nil, otherwise return error // - if so return nil, otherwise return error
func ChkGps(p []byte) error { func ChkLocation(p []byte) error {
if p[gpsTagIndx] != gpsDescTag { if p[locationTagIndx] != locationDescTag {
return errors.New("PSI does not contain a gps descriptor, cannot update") return errors.New("PSI does not contain a location descriptor, cannot update")
} }
return nil return nil
} }
@ -96,36 +96,36 @@ func TimeOf(p []byte) (t uint64, err error) {
// TimeOf takes a byte slice representation of a psi-pmt and extracts it's // TimeOf takes a byte slice representation of a psi-pmt and extracts it's
// timestamp, returning as a uint64 if it exists, otherwise returning 0 and nil // timestamp, returning as a uint64 if it exists, otherwise returning 0 and nil
// if it does not exist // if it does not exist
func GpsOf(p []byte) (g string, err error) { func LocationOf(p []byte) (g string, err error) {
err = ChkGps(p) err = ChkLocation(p)
if err != nil { if err != nil {
return "", err return "", err
} }
gBytes := p[gpsDataIndx : gpsDataIndx+gpsDataSize] gBytes := p[locationDataIndx : locationDataIndx+locationDataSize]
gBytes = bytes.Trim(gBytes, "\x00") gBytes = bytes.Trim(gBytes, "\x00")
g = string(gBytes) g = string(gBytes)
return g, nil return g, nil
} }
// GpsStrBytes take a string of gps data and converts to a 32 byte slice - // LocationStrBytes take a string of location data and converts to a 32 byte slice -
// easy update of slice representation of a pmt with gps descriptor // easy update of slice representation of a pmt with location descriptor
func GpsStrBytes(l string) (out []byte) { func LocationStrBytes(l string) (out []byte) {
out = make([]byte, gpsDataSize) out = make([]byte, locationDataSize)
copy(out, []byte(l)) copy(out, []byte(l))
return return
} }
// UpdateGps takes a byte slice representation of a psi-pmt containing a gps // UpdateLocation takes a byte slice representation of a psi-pmt containing a location
// descriptor and attempts to update the gps data value with the passed string. // descriptor and attempts to update the location data value with the passed string.
// If the psi does not contain a gps descriptor, and error is returned. // If the psi does not contain a location descriptor, and error is returned.
func UpdateGps(d []byte, s string) error { func UpdateLocation(d []byte, s string) error {
err := ChkGps(d) err := ChkLocation(d)
if err != nil { if err != nil {
return err return err
} }
gb := GpsStrBytes(s) gb := LocationStrBytes(s)
for i := range d[gpsDataIndx : gpsDataIndx+gpsDataSize] { for i := range d[locationDataIndx : locationDataIndx+locationDataSize] {
d[i+gpsDataIndx] = gb[i] d[i+locationDataIndx] = gb[i]
} }
d = updateCrc(d) d = updateCrc(d)
return nil return nil

View File

@ -54,12 +54,12 @@ const (
timeDataSize = 8 timeDataSize = 8
) )
// Consts relating to gps description // Consts relating to location description
const ( const (
gpsDescTag = 235 locationDescTag = 235
gpsTagIndx = 23 locationTagIndx = 23
gpsDataIndx = 25 locationDataIndx = 25
gpsDataSize = 32 // bytes locationDataSize = 32 // bytes
) )
// Program specific information // Program specific information

View File

@ -39,8 +39,8 @@ const (
// GPS string for testing // GPS string for testing
const ( const (
gpsTstStr1 = "$GPGGA,123519,4807.038,N,01131.0" locationTstStr1 = "$GPGGA,123519,4807.038,N,01131.0"
gpsTstStr2 = "$GPGGA,183710,4902.048,N,02171.0" locationTstStr2 = "$GPGGA,183710,4902.048,N,02171.0"
) )
// err message // err message
@ -57,15 +57,15 @@ var (
// Parts to construct bytes of pmt with time and bytes // Parts to construct bytes of pmt with time and bytes
var ( var (
pmtTimeGpsBytesPart1 = []byte{ pmtTimeLocationBytesPart1 = []byte{
0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a, 0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a,
byte(timeDescTag), // Descriptor tag for timestamp byte(timeDescTag), // Descriptor tag for timestamp
byte(timeDataSize), // Length of bytes to follow byte(timeDataSize), // Length of bytes to follow
0x00, 0x00, 0x00, 0x00, 0x67, 0x6F, 0x74, 0x5F, // Timestamp data 0x00, 0x00, 0x00, 0x00, 0x67, 0x6F, 0x74, 0x5F, // Timestamp data
byte(gpsDescTag), // Descriptor tag for gps byte(locationDescTag), // Descriptor tag for location
byte(gpsDataSize), // Length of bytes to follow byte(locationDataSize), // Length of bytes to follow
} }
pmtTimeGpsBytesPart2 = []byte{ pmtTimeLocationBytesPart2 = []byte{
0x1b, 0xe1, 0x00, 0xf0, 0x00, 0x1b, 0xe1, 0x00, 0xf0, 0x00,
} }
) )
@ -89,11 +89,11 @@ var (
0x1b, 0xe1, 0x00, 0xf0, 0x00, 0x1b, 0xe1, 0x00, 0xf0, 0x00,
} }
// Bytes representing pmt with time1 and gps1 // Bytes representing pmt with time1 and location1
pmtTimeGpsBytes1 = buildPmtTimeGpsBytes(gpsTstStr1) pmtTimeLocationBytes1 = buildPmtTimeLocationBytes(locationTstStr1)
// bytes representing pmt with with time1 and gps 2 // bytes representing pmt with with time1 and location 2
pmtTimeGpsBytes2 = buildPmtTimeGpsBytes(gpsTstStr2) pmtTimeLocationBytes2 = buildPmtTimeLocationBytes(locationTstStr2)
) )
// bytesTests contains data for testing the Bytes() funcs for the PSI data struct // bytesTests contains data for testing the Bytes() funcs for the PSI data struct
@ -151,9 +151,9 @@ var bytesTests = []struct {
want: pmtTimeBytes1, want: pmtTimeBytes1,
}, },
// Pmt with time and gps // Pmt with time and location
{ {
name: "pmt Bytes() with time and gps", name: "pmt Bytes() with time and location",
input: PSI{ input: PSI{
Pf: 0x00, Pf: 0x00,
Tid: 0x02, Tid: 0x02,
@ -175,9 +175,9 @@ var bytesTests = []struct {
Dd: TimeBytes(tstTime2), Dd: TimeBytes(tstTime2),
}, },
Desc{ Desc{
Dt: byte(gpsDescTag), Dt: byte(locationDescTag),
Dl: byte(gpsDataSize), Dl: byte(locationDataSize),
Dd: GpsStrBytes(gpsTstStr1), Dd: LocationStrBytes(locationTstStr1),
}, },
}, },
Essd: &ESSD{ Essd: &ESSD{
@ -188,7 +188,7 @@ var bytesTests = []struct {
}, },
}, },
}, },
want: buildPmtTimeGpsBytes(gpsTstStr1), want: buildPmtTimeLocationBytes(locationTstStr1),
}, },
} }
@ -240,40 +240,40 @@ func TestTimeGet(t *testing.T) {
} }
} }
func TestGpsGet(t *testing.T) { func TestLocationGet(t *testing.T) {
pb := StdPmtTimeGps.Bytes() pb := StdPmtTimeLocation.Bytes()
err := UpdateGps(pb, gpsTstStr1) err := UpdateLocation(pb, locationTstStr1)
if err != nil { if err != nil {
t.Errorf("Error for TestGpsGet UpdateGps(pb, gpsTstStr1): %v", err) t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationTstStr1): %v", err)
} }
g, err := GpsOf(pb) g, err := LocationOf(pb)
if err != nil { if err != nil {
t.Errorf("Error for TestGpsGet GpsOf(pb): %v", err) t.Errorf("Error for TestLocationGet LocationOf(pb): %v", err)
} }
if g != gpsTstStr1 { if g != locationTstStr1 {
t.Errorf(errCmp, "TestGpsGet", gpsTstStr1, g) t.Errorf(errCmp, "TestLocationGet", locationTstStr1, g)
} }
} }
// TestGpsUpdate checks to see if we can update the gps string in a pmt correctly // TestLocationUpdate checks to see if we can update the location string in a pmt correctly
func TestGpsUpdate(t *testing.T) { func TestLocationUpdate(t *testing.T) {
cpy := make([]byte, len(pmtTimeGpsBytes1)) cpy := make([]byte, len(pmtTimeLocationBytes1))
copy(cpy, pmtTimeGpsBytes1) copy(cpy, pmtTimeLocationBytes1)
cpy = addCrc(cpy) cpy = addCrc(cpy)
err := UpdateGps(cpy, gpsTstStr2) err := UpdateLocation(cpy, locationTstStr2)
cpy = cpy[:len(cpy)-4] cpy = cpy[:len(cpy)-4]
if err != nil { if err != nil {
t.Errorf("Update time returned err: %v", err) t.Errorf("Update time returned err: %v", err)
} }
if !bytes.Equal(pmtTimeGpsBytes2, cpy) { if !bytes.Equal(pmtTimeLocationBytes2, cpy) {
t.Errorf(errCmp, "TestGpsUpdate", pmtTimeGpsBytes2, cpy) t.Errorf(errCmp, "TestLocationUpdate", pmtTimeLocationBytes2, cpy)
} }
} }
// buildPmtTimeGpsBytes is a helper function to help construct the byte slices // buildPmtTimeLocationBytes is a helper function to help construct the byte slices
// for pmts with time and gps, as the gps data field is 32 bytes, i.e. quite large // for pmts with time and location, as the location data field is 32 bytes, i.e. quite large
// to type out // to type out
func buildPmtTimeGpsBytes(tstStr string) []byte { func buildPmtTimeLocationBytes(tstStr string) []byte {
return append(append(append(make([]byte, 0), pmtTimeGpsBytesPart1...), return append(append(append(make([]byte, 0), pmtTimeLocationBytesPart1...),
GpsStrBytes(tstStr)...), pmtTimeGpsBytesPart2...) LocationStrBytes(tstStr)...), pmtTimeLocationBytesPart2...)
} }

View File

@ -27,7 +27,7 @@ LICENSE
package psi package psi
const ( const (
pmtTimeGpsPil = 44 pmtTimeLocationPil = 44
) )
// Some common manifestations of PSI // Some common manifestations of PSI
@ -52,7 +52,7 @@ var (
}, },
} }
// PSI struct to represent basic pmt without descriptors for time and gps // PSI struct to represent basic pmt without descriptors for time and location
StdPmt = PSI{ StdPmt = PSI{
Pf: 0x00, Pf: 0x00,
Tid: 0x02, Tid: 0x02,
@ -76,8 +76,8 @@ var (
}, },
} }
// Std pmt with time and gps descriptors, time and gps fields are zerod out // Std pmt with time and location descriptors, time and location fields are zerod out
StdPmtTimeGps = PSI{ StdPmtTimeLocation = PSI{
Pf: 0x00, Pf: 0x00,
Tid: 0x02, Tid: 0x02,
Ssi: true, Ssi: true,
@ -90,7 +90,7 @@ var (
Lsn: 0, Lsn: 0,
Sd: &PMT{ Sd: &PMT{
Pcrpid: 0x0100, Pcrpid: 0x0100,
Pil: pmtTimeGpsPil, Pil: pmtTimeLocationPil,
Pd: []Desc{ Pd: []Desc{
Desc{ Desc{
Dt: byte(timeDescTag), Dt: byte(timeDescTag),
@ -98,9 +98,9 @@ var (
Dd: make([]byte, timeDataSize), Dd: make([]byte, timeDataSize),
}, },
Desc{ Desc{
Dt: byte(gpsDescTag), Dt: byte(locationDescTag),
Dl: byte(gpsDataSize), Dl: byte(locationDataSize),
Dd: make([]byte, gpsDataSize), Dd: make([]byte, locationDataSize),
}, },
}, },
Essd: &ESSD{ Essd: &ESSD{