C Language Development Kit/Functions/ReadGps

From OptiWiki

Jump to: navigation, search
Description Reads data from the GPS communication module inside the OPL9713.
Syntax
int ReadGps(void);
Arguments None
Returns When a character is available in the buffer, ReadGps() returns the received character.

When no data is available -1 is returned.

Remarks To be able to use this function it is needed that the power is set on the GPS module by the

GpsPower() function. If there was still some data left in the buffer from a previous session then this is transmitted first.


The OPL9713 buffers the data, so the first character in the buffer is returned by this function.


The GPS module inside the terminal transmits the NMEA-0183 protocol.

Example
//
// gps bluetooth server 
// transmits NMEA-0183 protocol from GPS receiver through bluetooth
// This sample can be used as an external GPS receiver.
//
// REMARK: This sample will drain the batteries quickly!!
//
#include <stdio.h>
#include "lib.h"
 
void main( void )
{
    int ch;
 
    //
    // Set local bluetooth name
    //
    SetBltLocalName("SuperGPS");
 
    //
    // Open the bluetooth port as server
    //
    comopen( COM5 );
    for(;;)
    {
        //
        // Wait for an incomming bluetooth connection
        //
        while( blt_is_connected() != TRUE)
        {
            delay( 50 );
            goodreadled( RED, 20);
            idle();
        }
        sound( TSTANDARD, VHIGH, SERROR, SLOW, SMEDIUM, SHIGH, SLOW, SMEDIUM, SHIGH, 0);
        //
        // Turn the GPS module ON
        //
        GpsPower( ON);
        ClearGpsReceiver(); // Clear the receive buffer
        while( blt_is_connected() == TRUE)
        {
            //
            // All all data from the GPS buffer
            //
            if( ( ch = ReadGps()) < 0)
            {
                idle();
                continue;
            }
            putcom( ch );
        }
        //
        // Bluetooth connection lost, turn the GPS module OFF
        //
        GpsPower( OFF );
        sound( TSTANDARD, VHIGH, SERROR, 0);
    }
}


Views
Personal tools