diff --git a/stream/mts/psi/op.go b/stream/mts/psi/op.go index e8d2f04e..0d4f607c 100644 --- a/stream/mts/psi/op.go +++ b/stream/mts/psi/op.go @@ -92,6 +92,19 @@ func TimeOf(p []byte) (t uint64, err error) { return t, nil } +// 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) + if err != nil { + return "", err + } + gBytes := p[gpsDataIndx : gpsDataIndx+gpsDataSize] + 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) { diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index cba8247f..12f0ea5b 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -39,8 +39,8 @@ const ( // GPS string for testing const ( - gpsTstStr1 = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47" - gpsTstStr2 = "$GPGGA,183710,4902.048,N,02171.020,E,1,09,0.5,547.2,M,43.4,M,,*42" + gpsTstStr1 = "$GPGGA,123519,4807.038,N,01131.0" + gpsTstStr2 = "$GPGGA,183710,4902.048,N,02171.0" ) // err message @@ -240,6 +240,21 @@ func TestTimeGet(t *testing.T) { } } +func TestGpsGet(t *testing.T) { + pb := StdPmtTimeGps.Bytes() + err := UpdateGps(pb, gpsTstStr1) + if err != nil { + t.Errorf("Error for TestGpsGet UpdateGps(pb, gpsTstStr1): %v", err) + } + g, err := GpsOf(pb) + if err != nil { + t.Errorf("Error for TestGpsGet GpsOf(pb): %v", err) + } + if g != gpsTstStr1 { + t.Errorf(errCmp, "TestGpsGet", gpsTstStr1, 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))