psi: wrote testing for get gps from pmt byte slice

This commit is contained in:
saxon 2018-12-14 11:15:49 +10:30
parent afc7c1f086
commit 7fa245bca3
2 changed files with 30 additions and 2 deletions

View File

@ -92,6 +92,19 @@ func TimeOf(p []byte) (t uint64, err error) {
return t, nil 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 - // 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 // easy update of slice representation of a pmt with gps descriptor
func GpsStrBytes(l string) (out []byte) { func GpsStrBytes(l string) (out []byte) {

View File

@ -39,8 +39,8 @@ const (
// GPS string for testing // GPS string for testing
const ( const (
gpsTstStr1 = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47" gpsTstStr1 = "$GPGGA,123519,4807.038,N,01131.0"
gpsTstStr2 = "$GPGGA,183710,4902.048,N,02171.020,E,1,09,0.5,547.2,M,43.4,M,,*42" gpsTstStr2 = "$GPGGA,183710,4902.048,N,02171.0"
) )
// err message // 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 // TestGpsUpdate checks to see if we can update the gps string in a pmt correctly
func TestGpsUpdate(t *testing.T) { func TestGpsUpdate(t *testing.T) {
cpy := make([]byte, len(pmtTimeGpsBytes1)) cpy := make([]byte, len(pmtTimeGpsBytes1))