Appendix B. Serial Programming
B-2
Sample
(1,ggapositionfix,
String
)
Sample
(1,gganumsatellites,
String
)
Sample
(1,ggahdop,
String
)
Sample
(1,ggaaltitude,
String
)
Sample
(1,ggaaltutudeunits,
String
)
Sample
(1,ggageoidsep,
String
)
Sample
(1,ggageoidunits,
String
)
Sample
(1,ggachecksum,
String
)
EndTable
'Main Program
BeginProg
SerialOpen
(GPSPort,38400,3,0,1001)
Scan
(1,Sec,0,0)
SerialInRecord
(GPSPort,rawdata,36,0,&h0D0A,NBytesReturned,11)
CalculatedChecksum =
CheckSum
(rawdata,9,
Len
(rawdata) - 3)
CalculatedChecksum = CalculatedChecksum
AND
255
ReportedChecksum =
HexToDec
(
Right
(rawdata,2))
If
CalculatedChecksum = ReportedChecksum
Then
If
InStr
(1,rawdata,"GPRMC",2)
Then
RMCstring = rawdata
ElseIf
InStr
(1,rawdata,"GPGGA",2)
Then
GGAstring = rawdata
EndIf
EndIf
SerialInRecord
(GPSPort,rawdata,36,0,&h0D0A,NBytesReturned,11)
CalculatedChecksum =
CheckSum
(rawdata,9,
Len
(rawdata) - 3)
CalculatedChecksum = CalculatedChecksum
AND
255
ReportedChecksum =
HexToDec
(
Right
(rawdata,2))
If
CalculatedChecksum = ReportedChecksum
Then
If
InStr
(1,rawdata,"GPRMC",2)
Then
RMCstring = rawdata
ElseIf
InStr
(1,rawdata,"GPGGA",2)
Then
GGAstring = rawdata
EndIf
EndIf
'parse rmc data
SplitStr
(SubStrings(),RMCstring,",",16,5)
rmcid = SubStrings(1)
rmcutc = SubStrings(2)
rmcstatus = SubStrings(3)
rmclatitude = SubStrings(4)
rmcin_s_ind =SubStrings(5)
rmclongitude=SubStrings(6)
rmce_w_indicator=SubStrings(7)
rmcspeed=SubStrings(8)
rmccourse=SubStrings(9)
rmcutcdate=SubStrings(10)
rmcmagvariation=SubStrings(11)
rmcmage_w =
Left
(SubStrings(12),1)
rmcchecksum=
Right
(RMCstring,2)
'parse gga data
SplitStr
(SubStrings(),GGAstring,",",16,5)
ggaid=SubStrings(1)
ggautc=SubStrings(2)
ggailatitude=SubStrings(3)
ggan_s_ind=SubStrings(4)
ggalongitude=SubStrings(5)
ggae_w_ind=SubStrings(6)
ggapositionfix=SubStrings(7)
gganumsatellites=SubStrings(8)
ggahdop=SubStrings(9)
ggaaltitude=SubStrings(10)
ggaaltutudeunits=SubStrings(11)
ggageoidsep=SubStrings(12)
ggageoidunits=
Left
(SubStrings(13),1)