int main(){ struct termios tio; int tty_fd; fd_set rdset; unsigned char c=0; char buffer[255]; char *bufptr; int nbytes; int fd; void* file_memory; int pos=0; //Prepare the mapped Memory file preparemappedMem(); RMC_DATA gpsRMCData; memset(&tio,0,sizeof(tio)); tio.c_iflag=0; tio.c_oflag &= ~OPOST; //0; tio.c_cflag &= CREAD|CLOCAL; tio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // (ICANON | ECHO | ECHOE); tio.c_cc[VMIN]=0; tio.c_cc[VTIME]=0; tty_fd=open("/dev/ttyS1", O_RDWR | O_NONBLOCK); cfsetospeed(&tio,B9600); cfsetispeed(&tio,B9600); tcsetattr(tty_fd,TCSANOW,&tio); writeMessageToPort(enableTenHz, sizeof(enableTenHz), tty_fd); //readResponse(); writeMessageToPort(disableAllMessages, sizeof(disableAllMessages), tty_fd); writeMessageToPort(enableRMC, sizeof(enableRMC), tty_fd); bufptr = buffer; while (1) { /* read characters into our string buffer until we get a CR or NL */ nbytes = 0; while((nbytes=read(tty_fd,bufptr,buffer+sizeof(buffer)-bufptr-1))>0) { bufptr += nbytes; if (bufptr[-2] == '\r' && bufptr[-1] == '\n') { *bufptr = '\0'; bufptr = buffer; //printf("*** %s ***",buffer); parseGPRMC(buffer, &gprmc); //printf("%d\r\n",gprmc.timeSecond); toXMLfile(&gprmc); //memset(&buffer,'\0',sizeof(buffer)); } } } return(0); }
void ArNovatelSPAN::handleGPRMC(ArNMEAParser::Message msg) { parseGPRMC(msg, GPSLatitude, GPSLongitude, GPSValidFlag, haveGPSPosition, timeGotGPSPosition, GPSTimestamp, myData.haveSpeed, myData.speed); }
bool WiGPS::update(int timeout_sec){ /* * The main function for fetching data * from the GPS module. * This function gets incoming Strings * from the _serial port and store them * in a buffer if they starts with the $ char * After retrieving a "valid" String the * parser is called. */ //Serial.println("GPS update."); char buffer[BUFFER_LENGTH_2]; char *buf = buffer; dataReady = false; //int failed5 = 0; unsigned long updateTimeout = millis() + timeout_sec*1000; while(buf - buffer < BUFFER_LENGTH_2){ *(buf++) = '\0'; } buf = buffer; //Serial.print("GPS begin loop: "); //Serial.print(updateTimeout - timeout_sec*1000); //Serial.print(" < "); //Serial.println(updateTimeout); while(!dataReady){ // Wait for the first incoming header while(_serial.read() != '$'); // Store the first 5 chars for(int i = 0; i<5; i++){ while(!_serial.available()); *(buf++) = _serial.read(); } //Serial.print("buffer:" ); //Serial.print(buffer); if(strncmp(buffer, PROTOCOL, 5) == 0){ // This is the right String, go on do { // Fetch the rest of the GPRMC String while(!_serial.available()); *buf = _serial.read(); } while(*(buf++) != '\n'); GPRMC str(buffer); //Serial.println(str); // 'A' for valid, 'V' for invalid if(str.dataValid().equals("A")){ //Serial.println("GPS data is valid."); // The string is ok, extract data // TODO: ADD CHECKSUM CONTROL TO THE STRING Serial.print(str); parseGPRMC(&str); //Now break the cycle //Serial.println("GPS success."); //Serial.println("GPS break loop."); //Serial.print("\n"); dataReady = true; return dataReady; } else { //Serial.println("GPS data invalid."); } } //Serial.println("6- Data is not ready "); //Serial.println("------"); //failed5++; //if(failed5 <= 1500){ //Serial.println("7- Too many fails.. quitting "); //return FALSE; //} //Serial.println("\n"); // if update timed out //Serial.print("GPS time: "); //Serial.print(millis()); //Serial.print(" < "); //Serial.println(updateTimeout); if (millis() >= updateTimeout) { //Serial.println("GPS timeout."); //Serial.println("GPS break loop."); //Serial.print("\n"); dataReady = false; return false; } buf = buffer; }; //Serial.println("GPS loop end."); //Serial.print("\n"); return true; }