#include "simple_obd_test.h" #include "customized_GPS.h" #include "customized_OBD.h" #include "customized_DateAndTime.h" extern void clr_buff(char*,uint32_t); extern FreematicsESP32 sys; GPS_DATA* gd=0; void init_GPS_dev(void){ if (sys.gpsBegin(GPS_SERIAL_BAUDRATE)) { #if USE_SERIAL==1 Serial.println("GPS is initialized successfully"); #endif }else{ #if USE_SERIAL==1 Serial.println("Error occured while initializing GPS"); #endif while(1); } pinMode(26, OUTPUT); pinMode(34, INPUT); pinMode(PIN_GPS_POWER, OUTPUT); digitalWrite(PIN_GPS_POWER, HIGH); int cnt=0; while(!isDataGPSReady(10000)){ delay(100); cnt++; if(cnt==5){ esp_sleep_enable_timer_wakeup(1 * uS_TO_S_FACTOR); esp_deep_sleep_start(); } } UpdateTime(); SetSysInstance(&sys); } int isDataGPSReady(int wait_MS){ for (uint32_t t=millis();millis()-t5){ meanGPSCoord[0][0]=gd->alt; meanGPSCoord[0][1]=gd->lng; meanGPSCoord[0][2]=gd->lat; meanGPSCoord[0][3]=gd->speed*1.852f; AuxGPSCoord[0]=gd->alt; AuxGPSCoord[1]=gd->lng; AuxGPSCoord[2]=gd->lat; AuxGPSCoord[3]=gd->speed*1.852f; cnt=0; }else{ if (cnt+1alt; AuxGPSCoord[1]=gd->lng; AuxGPSCoord[2]=gd->lat; AuxGPSCoord[3]=gd->speed*1.852f; for(j=0;jalt; meanGPSCoord[0][1]=gd->lng; meanGPSCoord[0][2]=gd->lat; meanGPSCoord[0][3]=gd->speed*1.852f; AuxGPSCoord[0]=gd->alt; AuxGPSCoord[1]=gd->lng; AuxGPSCoord[2]=gd->lat; AuxGPSCoord[3]=gd->speed*1.852f; cnt=0; } int n=(cnt+1)%NBR_GPS_POINTS; int prev= !(n) ? NBR_GPS_POINTS-1 : n-1; res[0]=AuxGPSCoord[0]; res[1]=AuxGPSCoord[1]; res[2]=AuxGPSCoord[2]; res[4]=AuxGPSCoord[3]; if (slope_flag){ double dist = (double) TinyGPS::distance_between((float) meanGPSCoord[prev][2],(float) meanGPSCoord[prev][1],(float) res[2],(float) res[1]); #if USE_OBD==0 double dist_max = gd->speed*shiftTime/3.6*1.25; #else double dist_max = GetOBDSpeed()*shiftTime/3.6*1.2; #endif if ((dist>dist_max) || (dist>(85*shiftTime))) return -1; res[3]=(res[0]-meanGPSCoord[prev][0])/(dist+10)*100; meanGPSCoord[n][0]=res[0]; meanGPSCoord[n][1]=res[1]; meanGPSCoord[n][2]=res[2]; meanGPSCoord[n][3]=res[4]; cnt++; } for (j=0;jNBR_GPS_POINTS){ if ((meanSpeed<2)&&(abs(val-meanSpeed)<0.5)){ esp_sleep_enable_timer_wakeup(5 * uS_TO_S_FACTOR); esp_deep_sleep_start(); }else{ meanSpeed=val; for (j=0;j