Link here

GPS C Demo


This section presents the ANSI C version of the demonstration program source code. This instrumentation example shows how to acquire global positioning system (GPS) data and display it on the serial port. This program is a good starting point if you are building your own GPS data logger.

GPS C Demo

// *********************************************************************
// FILE NAME: GPS_WC_Demo.c
// copyright 2009 Mosaic Industries, Inc. All rights reserved.
// ---------------------------------------------------------------------
// DATE: 4/24/2009
// VERSION: 1.0, for QED/Q-Line (HC-11) and PDQ line (HCS-12) controllers
// ---------------------------------------------------------------------
// This is a demonstration program for the GPS Wildcard.
// Make sure that GPS_MODULE_NUM matches your hardware jumper settings.
// Note: in real applications, the GPS service should be invoked from a separate task.
// ---------------------------------------------------------------------
// Disclaimer: THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
// ANY WARRANTIES OR REPRESENTATIONS EXPRESS OR IMPLIED,
// INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES
// OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
//
// *********************************************************************
 
#include <mosaic\allqed.h>
#ifdef __GNUC__
// For PDQ line platforms, the driver is enabled by simply including
// the header file below.
#include <wgps.h>
#else
// For the QED/Q line platform, we include the kernel extension manager
// generated library.c. We assume that it is present in this directory.
#include "library.h"
#include "library.c"
#endif // __GNU__
 
 
#define GPS_MODULE_NUM 0
// MUST match hardware jumper settings!
 
 
 
 
#ifdef __GNUC__
 
// The PDQ line uses AskKey for a non-blocking way to check for keypresses
int KeepLooping( void )
{
    if( AskKey() == 0 )
        return 1;
    else
        return 0;
}
 
#else
 
// QED/Q line uses _peekTerminal() because the AskKey() flag gets reset
int KeepLooping( void )
{
    if( _peekTerminal() == 0 )
        return 1;
    else
        return 0;
}
 
#endif // __GNU__
 
 
 
 
void GPS_Run ( int local_hour_offset, int module_num )
// this function initializes the GPS Wildcard, powered by Garmin, and prints a formatted summary
// of GPS info to the terminal every 5 seconds.  Type any key to terminate the function.
// Note: in real applications, the GPS service should be invoked from a separate task.
{    int print_counter;
  print_counter = 0;
 
    if(GPS_Init(local_hour_offset, module_num))
        printf("GPS_Init FAILED!\r\n");        // we're done if GPS_Init error flag is true
    else                                    // if initialization ok, proceed...
    {
      printf("\r\nStarting GPS info dump.  Type any key to exit this function.\r\n");
        printf("This function gets a data frame from the GPS once per second,");
        printf("and prints a statement telling of the fix validity.");
        printf("If the fix is not valid, make sure your antenna is outside,");
        printf("and give the GPS some time (5 minutes worst case) to acquire its satellites.");
        printf("This function periodically calls GPS_Info_Dump to summarize the GPS data.\r\n");
 
        while( KeepLooping() == 1 )                          // type any key to end this routine
        {
          printf("\r\n\r\nValid fix?: ");
            if(GPS_Update(module_num))       // runs every second
                printf("NO");                // if GPS_Update returned true error flag: no fix
            else
                printf("YES");                // if no GPS_Update error: yes, we have a fix
 
            if(print_counter++ == 5)        // detailed print every 5 seconds
            {    print_counter = 0;            // restart counter
                GPS_Info_Dump();            // print formatted extracted gps info
            }
        }
    }
}
 
 
void GPS_Demo ( void )
// this function initializes the GPS Wildcard board with a specified time zone and module number,
// and prints a formatted summary of GPS info to the terminal every 5 seconds.
// Type any key to terminate the function.
// Note: in real applications, the GPS service should be invoked from a separate task.
{    GPS_Run(GPS_PACIFIC_TIME, GPS_MODULE_NUM);
}
 
int main(void)
{    GPS_Demo();
  return 0;
}



For more examples, see → GPS Wildcard User Guide
GPS Glossary
GPS Forth Demo

 
This page is about: C Language Data Logger Example Program, Embedded Device Tracking – C Language example program shows printing GPS data (ASCII), perfect for instrumentation of a remote device. GPS, Global Positioning System, Embedded location, Altitude, longitude latitude finder, fast it is moving, direction, current time and date, Latitude, longitude, altitude, speed, course heading, universal local time date, position error estimates, GPS fix quality, number of satellites
 
 
Navigation