int main() { static const char * filename = "../../samples/parse_file/gpslog.txt"; nmeaINFO info; nmeaPARSER parser; FILE *file; char buff[2048]; int size, it = 0; nmeaPOS dpos; file = fopen(filename, "rb"); if(!file) { printf("Could not open file %s\n", filename); return -1; } nmea_property()->trace_func = &trace; nmea_property()->error_func = &error; nmea_zero_INFO(&info); nmea_parser_init(&parser); /* while(1) { */ while(!feof(file)) { size = (int)fread(&buff[0], 1, 100, file); nmea_parse(&parser, &buff[0], size, &info); nmea_info2pos(&info, &dpos); printf( "%03d, Lat: %f, Lon: %f, Sig: %d, Fix: %d\n", it++, dpos.lat, dpos.lon, info.sig, info.fix ); } fseek(file, 0, SEEK_SET); /* } */ nmea_parser_destroy(&parser); fclose(file); return 0; }
void nmea_error(const char *str, ...) { int size; va_list arg_list; char buff[NMEA_DEF_PARSEBUFF]; nmeaErrorFunc func = nmea_property()->error_func; if(func) { va_start(arg_list, str); size = NMEA_POSIX(vsnprintf)(&buff[0], NMEA_DEF_PARSEBUFF - 1, str, arg_list); va_end(arg_list); if(size > 0) (*func)(&buff[0], size); } }
void nmea_error(const char *str, ...) { // FILE *file; // file = fopen("nmeaError.txt","a+"); // fprintf(file,"%s\n",str); // fclose(file); int size; va_list arg_list; char buff[NMEA_DEF_PARSEBUFF]; nmeaErrorFunc func = nmea_property()->error_func; if(func) { va_start(arg_list, str); size = NMEA_POSIX(vsnprintf)(&buff[0], NMEA_DEF_PARSEBUFF - 1, str, arg_list); va_end(arg_list); if(size > 0) (*func)(&buff[0], size); } }
/** * \brief Initialization of parser object * @return true (1) - success or false (0) - fail */ int nmea_parser_init(nmeaPARSER *parser) { int resv = 0; int buff_size = nmea_property()->parse_buff_size; NMEA_ASSERT(parser); if(buff_size < NMEA_MIN_PARSEBUFF) buff_size = NMEA_MIN_PARSEBUFF; memset(parser, 0, sizeof(nmeaPARSER)); if(0 == (parser->buffer = malloc(buff_size))) nmea_error("Insufficient memory!"); else { parser->buff_size = buff_size; resv = 1; } return resv; }
int nmea_decode_test(void){ int tempOut=0; s16 AccelGyro[7]={0}; s16 TempBuffer[7]={0}; nmeaINFO info; //GPS parsed info nmeaPARSER parser; //struct used for decoding uint8_t new_parse=0; //new or not, have history? nmeaTIME beiJingTime; nmea_property()->trace_func = &trace; nmea_property()->error_func = &error; //GPS initialization nmea_zero_INFO(&info); nmea_parser_init(&parser); while(1) { if(GPS_HalfTransferEnd) /* received half the buffer size*/ { /* parse using nmea format */ nmea_parse(&parser, (const char*)&gps_rbuff[0], HALF_GPS_RBUFF_SIZE, &info); GPS_HalfTransferEnd = 0; //Clear flag new_parse = 1; //new info } else if(GPS_TransferEnd) /* receiving the other half */ { nmea_parse(&parser, (const char*)&gps_rbuff[HALF_GPS_RBUFF_SIZE], HALF_GPS_RBUFF_SIZE, &info); GPS_TransferEnd = 0; new_parse =1; } if(new_parse ) //if have new info { //Converts time to GMT GMTconvert(&info.utc,&beiJingTime,8,1); /* Output data*/ printf("\r\n Time:%d,%d,%d,%d,%d,%d\r\n", beiJingTime.year+1900, beiJingTime.mon+1,beiJingTime.day,beiJingTime.hour,beiJingTime.min,beiJingTime.sec); printf("\r\n Latitude:%f,Longtitude:%f\r\n",info.lat,info.lon); printf("\r\n Numbers of Sat in use:%d, Numbers of Sat in view:%d",info.satinfo.inuse,info.satinfo.inview); printf("\r\n Numbers of meters above horizon: %f", info.elv); printf("\r\n Speed: %f km/h ", info.speed); printf("\r\n Direction: %f degree", info.direction); new_parse = 0; } //--------------------------actual loop------------------------ //------------------------this is imu------------------------ printf("\r\nMPU Readings:"); MPU6050_GetRawAccelGyro(AccelGyro); printf("\r\nIMU[0]: %10d",AccelGyro[0]); printf("\t IMU[1]: %10d",AccelGyro[1]); printf("\t IMU[2]: %10d",AccelGyro[2]); printf("\t IMU[3]: %10d",AccelGyro[3]); printf("\t IMU[4]: %10d",AccelGyro[4]); printf("\t IMU[5]: %10d",AccelGyro[5]); //--------------------------temp loop-------------------------- //tempOut=USART3_getTemp(); //printf("\r\n temp is: %d\n",tempOut); //------------------------------------------------------------- delay_ms(1000); } }
void nmea_trace_buff(const char *buff, int buff_size) { nmeaTraceFunc func = nmea_property()->trace_func; if(func && buff_size) (*func)(buff, buff_size); }