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))
}
// Extract gps from reply
// Extract location from reply
g, err := dec.String("ll")
if err != nil {
s.log(smartlogger.Warning, pkg+"No gps in reply")
s.log(smartlogger.Warning, pkg+"No location in reply")
} 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)
}

View File

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

View File

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

View File

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

View File

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

View File

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