Skip to content

Instantly share code, notes, and snippets.

@paingineer
Last active August 29, 2015 14:03
Show Gist options
  • Save paingineer/5f23b02282553782ceec to your computer and use it in GitHub Desktop.
Save paingineer/5f23b02282553782ceec to your computer and use it in GitHub Desktop.
GPS presence testing
const char* GPS_PORT_NAME = "/dev/ttyS2";
int testResult = 0;
int fd;
SF_PACKET_ERROR_CODE_t err = SF_FAILED_EXEC;
fd = open(GPS_PORT_NAME, O_RDONLY | O_NOCTTY | O_SYNC);
if (fd > 0)
{
tcflush(fd,TCIOFLUSH); // Flush the previously buffered data
if( set_interface_attribs(fd, B9600, 0) == 0 )
{
err = SF_SUCCESS;
set_blocking(fd, 0);
char buf [256];
memset(buf,256,0);
sleep(1); // Wait for at least 1 PPS
int n = read (fd, buf, sizeof buf);
if( n > 0 )
{
// Find a $GP string coming from the gps
char * pch = strstr(buf ,"$GP");
if( pch != NULL ){
testResult = 1;
}
}
}
else
{
err = SF_ERROR_SETTING_GPSCOM_ATTR;
}
close(fd);
}
else
{
err = SF_ERROR_OPENING_GPSCOM;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment