Last active
August 29, 2015 14:03
-
-
Save paingineer/5f23b02282553782ceec to your computer and use it in GitHub Desktop.
GPS presence testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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