' ' GPS_Example.bas ' ' Many modern GPS devices default on startup to automatically sending ' some group of NMEA sentences without any need for initialization by ' the host application. Unfortunately, the host application may have ' to sort through a great deal of unwanted data in order to extract a ' small amount of desired data. For smaller processors, the overhead ' required for this task may be prohibitive. ' ' One way to deal with this problem is to stop the automatic sending of ' data and poll the GPS device for the desired data. This method allows ' the host application to receive only the data that it needs and receive ' it only when it wants the data. ' ' GPS devices that use the SiRF protocol have the ability to be controlled ' by the host application and return data in NMEA sentences. The control ' commands and the poll requests are sent as SiRF msgs and the responses to ' the poll requests are returned as NMEA sentences. ' ' (If NMEA and SiRF are meaningless to you, for NMEA sentence definitions see ' http://www.gpsinformation.org/dale/nmea.htm#nmea ' ' For SiRF msg definitions and info on computing checksums for both NMEA ' and SiRF msgs (BEWARE: the two checksums are calculated differently), see ' http://www.royaltek.com/manuals/software%20interface%201.1(SIRF).pdf ' ' In the example, the sub routine GPS_Init is called to stop the 6 NMEA ' sentences that the Laipac G30 automatically starts sending on power up. ' The do loop in Main polls the GPS to query the two NMEA sentences that I'm ' interested in, RMC and GGA. ' ' The RMC sentence (Recommended Minimum) has the info that is of most interest. ' It contains: Latitude, Longitude, UTC Time, UTC Date, Course Over Ground, ' Speed Over Ground and Magnetic Variation. ' ' The GGA msg (Global positioning system fixed data) is only used for altitude ' data though it has other data elements. ' ' This code takes advantage of the greater amount of RAM available in the ZX-24 ' microprocessor. If you are using the BX-24, you will have to experiment with ' queue buffer sizes in order to fit everything into RAM. ' ' Many thx to clokwerx (W7KMV, Dennis Nendza in Tuscon) for some initial code ' that made all of the rest possible. ' ' Paul Dubinsky - 2006-01-04 ' Option Explicit Public Const ASCII_LF As Byte = 10 Public Const ASCII_CAR As Byte = 13 Public Const GPSInPin As Byte = 7 ' Pin for GPS serial input Public Const GPSOutPin As Byte = 8 ' Pin for GPS serial output Public Const GPSBaud4800 As Long = 4800 ' GPS serial baudrate Public Const GPSInQueueSize As Integer = 100 ' These queue sizes are not useable in the BX-24 environment. Public Const GPSOutQueueSize As Integer = 60 ' They work for the ZX-24 which has 1K on RAM. Experiment with ' the BX-24 to find a size that fits. Public GPSInQueue(1 To GPSInQueueSize) As Byte Public GPSOutQueue(1 To GPSOutQueueSize) As Byte Public Sub Main() Dim TimeOut as Single Call OpenQueue(GPSInQueue, GPSInQueueSize) Call OpenQueue(GPSOutQueue, GPSOutQueueSize) Call OpenCom(1, GPSBaud4800, GPSInQueue, GPSOutQueue) call delay(5.0) ' Let GPS Device settle Call GPS_Init() ' GPS Initialization do ' Poll for GGA Msgs Call GPS_Send("$PSRF103,00,01,00,01*25" & Chr(ASCII_CAR) & Chr(ASCII_LF)) TimeOut = Timer + 1.0 ' Set up a time output do while ((GetQueueCount(GPSInQueue) < 7) and (TimeOut > timer)) loop ' Now see if the GPS has sent data or time out has occurred If (StatusQueue(GPSInQueue)) Then 'Any characters available ? ' Process GPS GGA data End If ' Poll for RMC Msgs Call GPS_Send("$PSRF103,04,01,00,01*21" & Chr(ASCII_CAR) & Chr(ASCII_LF)) TimeOut = Timer + 1.0 ' Set up a time output do while ((GetQueueCount(GPSInQueue) < 7) and (TimeOut > timer)) loop ' Now see if the GPS has sent data If (StatusQueue(GPSInQueue)) Then 'Any characters available ? 'Process the RMC data End If loop end sub Sub GPS_Init() Dim TimeOut as Single ' ' The Laipac G30 GPS starts in NMEA 4800 baud mode reporting once per second ' The G30 automatically reports the NMEA GGA, GLL, GSA, GGV, RMC and VTG sentences ' ' If you desire to use the automatic data but only want to stop certain sentences, ' simply rem out the sentences that you want to KEEP SENDING and in Main(), rem out ' the polling lines. You then have to write a routine that looks for the start sequence ' of a NMEA sentence, $GPXXX where XXX is the NMEA NMEA Record identifier, ie $GPRMC is ' the identifier for an RMC NMEA sentence. ' ' Stop All Default NMEA Msgs TimeOut = Timer + 2.0 Call GPS_Send("$PSRF103,00,00,00,01*24" & Chr(ASCII_CAR) & Chr(ASCII_LF)) ' Stop GGA Msgs Call Delay(0.2) Call GPS_Send("$PSRF103,01,00,00,01*25" & Chr(ASCII_CAR) & Chr(ASCII_LF)) ' Stop GLL Msgs Call Delay(0.2) Call GPS_Send("$PSRF103,02,00,00,01*26" & Chr(ASCII_CAR) & Chr(ASCII_LF)) ' Stop GSA Msgs Call Delay(0.2) Call GPS_Send("$PSRF103,03,00,00,01*27" & Chr(ASCII_CAR) & Chr(ASCII_LF)) ' Stop GGV Msgs Call Delay(0.2) Call GPS_Send("$PSRF103,04,00,00,01*20" & Chr(ASCII_CAR) & Chr(ASCII_LF)) ' Stop RMC Msgs Call Delay(0.2) Call GPS_Send("$PSRF103,05,00,00,01*21" & Chr(ASCII_CAR) & Chr(ASCII_LF)) ' Stop VTG Msgs Call Delay(0.2) Call Delay(2.0) ' Give the GPS time to settle end sub Public Sub GPS_Send(ByVal St As String) ' Writes string to GPS Dim k As Byte Dim ts as String * 1 Dim StLen As Byte StLen = CByte(Len(St)) 'Get String length For k = 1 To StLen Ts = Mid(St, CInt(k), 1) 'Get next byte to move out Call PutQueueStr(GPSOutQueue, Ts) 'Write string Next End Sub