| ioPAC RTU Controllers C/C++ Sample Code Programming Guide

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Functions
gps_info.c File Reference

Retrieve GPS information Sample More...

`#include <stdio.h>`
`#include <unistd.h>`
`#include <libmoxa_rtu.h>`

## Functions
int | main (int argc, char **const argv)

## Detailed Description

Retrieve GPS information Sample

Copyright
  Moxa Inc.

Date
  06-04-2013

Author
  Changfu Hsieh

Version
  V1.0
  GPS information

    Introduction:
    This sample code shows how to retrieve GPS information by MOXA GPS API.
    Example:
    1. Execute the sample code with default settings: ./gps_info
    2. Execute the sample code with GPS active antenna: ./gps_info -a
    Default:
    Use passive antenna, if you are using an active antenna, please use -a parameter.
    Help:

    root@Moxa:/home#./gps_info -h
    GPS information

    Usage: ./gps_info [OPTIONS]

    Options:
            -a       Use active antenna.

Library:
GPS APIs

## Function Documentation

int main | ( | int | argc,
|  | char **const | argv
| ) |  |

/*******************************************************************************
* Copyright Moxa Inc.
*
* Get GPS information
*
* Date Author Comment
* 06-04-2013 Changfu Hsieh Created.
******************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <libmoxa_rtu.h>
int main(int argc, char **const argv)
{
INT32 rc = 0;
GPS_DATA gpsData;
INT8 cmd;
UINT8 activeAntenna = 0;
for(;;)
{
rc = getopt(argc, argv, "ah");
if(rc == EOF) break;
switch(rc)
{
case 'a':
activeAntenna = 1;
break;
case 'h':
printf("-a: Using active antenna, default is passive antenna.");
exit(1);
}
}
rc = MX_RTU_GPS_Start(activeAntenna);
printf("MX_RTU_GPS_Start rc:%d\n", rc);
while(1)
{
printf("Press 'enter' to retrieve GPS information or 'q' to quite GPS function.\n", rc);
scanf("%c", &cmd);
switch(cmd)
{
case 'q':
case 'Q':
rc = MX_RTU_GPS_Stop();
printf("MX_RTU_GPS_Stop rc:%d\n", rc);
printf("GPS: Quit\n");
return 0;
default:
MX_RTU_GPS_Get_Info(&gpsData);
printf("GPS fix:%d, latitude:%f, longitude:%f, satInUse:%d, satInView:%d\n", gpsData.fix, gpsData.lat, gpsData.lon, gpsData.satInUse, gpsData.satInView);
printf("GPS time:%d-%d-%d %d:%d:%d\n", gpsData.time.year, gpsData.time.mon, gpsData.time.day, gpsData.time.hour, gpsData.time.min, gpsData.time.sec);
break;
}
}
return 0;
}