void loop() { int delayMillis = 10000; for (int i = 0; i < baudRates.length(); i++) { uart_gps.begin(baudRates[i]); int startMillis = millis(); while ((millis() - startMillis) < delayMillis) { while (uart_gps.available()) // While there is data on the RX pin... { int c = uart_gps.read(); // load the data into a variable... Serial.print("baud = "); Serial.print(baudRates[i], DEC); Serial.print(" "); Serial.print(c); Serial.println(); if (gps.encode(c)) // if there is a new valid sentence... { getgps(gps); // then grab the data. } } } } }
void main() { auto int chan, ang, rvalue; auto float dist; auto int pwm, r_head, r_head2, head; auto long freq; auto char tmpbuf[128], c; char gpsString[MAX_SENTENCE]; GPSPosition testPoint, testPoint_old; brdInit(); serPORT(BAUDGPS); //serCopen(BAUDGPS); serMode(0); serCrdFlush();// main loop initGPS(); freq = pwm_init(450ul); printf("pick heading: "); r_head = atoi(gets(tmpbuf)); //while(1) // { /*goal.lat_degrees = 43; goal.lat_minutes = 7036; goal.lon_degrees = 72; goal.lon_minutes = 2811; goal.lat_direction = 'N'; goal.lon_direction = 'W'; goal.sog = 0; //goal.tog = */ if ((r_head > 90) || (r_head < -90)) { printf("\nbad heading "); } else { while (1) { costate GPSRead always_on { // wait until gps mode is engaged and a gps string has been recieved waitfor(serCrdUsed() > 0); //printf("gps read: "); // read until finding the beginning of a gps string then wait while(1) { //int test2; c = serCgetc(); if (c == -1) { serCrdFlush(); abort; } else if (c == '$') { waitfor(DelayMs(20)); //should only take 5ms or so at 115200 baud break; } }//end while(1) // now that 20 ms have passed, read in the gps string (it must all // be there by now, since so much time has passed getgps(gpsString); rvalue = gps_get_position(&testPoint,gpsString); if( rvalue != -1) { printGPSPosition(&testPoint); } //printf("gps: %u \n",strlen(test2)); printf("gps: %s ",gpsString); //printGPSPosition(&testPoint); //puts(gpsString); //puts(": end gps \n"); //dist = gps_ground_distance(&testPoint, &testPoint_old); //head = (int)gps_bearing(&testPoint, &testPoint_old, dist); //testPoint_old = testPoint; head = testPoint.tog; // grab current heading r_head2 = r_head-head; pwm = set_angle(0, r_head2); printf("angle: %d, head %d \n",pwm, head); }//end costate } // end while } // end else //} // end first while } // end main