Commit f45c121f8f4a96ad134369836a3015a348014d69
1 parent
e6a956d3
26-01-2021
Showing
6 changed files
with
48 additions
and
85 deletions
Show diff stats
FreematicsOBD/datalogger/customized_GPS.cpp
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | |
6 | 6 | extern void clr_buff(char*,uint32_t); |
7 | 7 | extern FreematicsESP32 sys; |
8 | +int init_gps=0; | |
8 | 9 | GPS_DATA* gd=0; |
9 | 10 | |
10 | 11 | void init_GPS_dev(void){ |
... | ... | @@ -23,6 +24,7 @@ void init_GPS_dev(void){ |
23 | 24 | pinMode(PIN_GPS_POWER, OUTPUT); |
24 | 25 | digitalWrite(PIN_GPS_POWER, HIGH); |
25 | 26 | int cnt=0; |
27 | + init_gps=0; | |
26 | 28 | while(!isDataGPSReady(10000)){ |
27 | 29 | delay(100); |
28 | 30 | cnt++; |
... | ... | @@ -32,15 +34,27 @@ void init_GPS_dev(void){ |
32 | 34 | esp_deep_sleep_start(); |
33 | 35 | } |
34 | 36 | } |
37 | + init_gps=1; | |
35 | 38 | UpdateTime(); |
36 | 39 | SetSysInstance(&sys); |
37 | 40 | } |
38 | 41 | |
39 | 42 | int isDataGPSReady(int wait_MS){ |
40 | 43 | for (uint32_t t=millis();millis()-t<wait_MS;){ |
41 | - digitalWrite(26, digitalRead(34)); | |
44 | + if (!init_gps){ | |
45 | + digitalWrite(26, digitalRead(34)); | |
46 | + }else{ | |
47 | + vTaskSuspendAll(); | |
48 | + digitalWrite(26, digitalRead(34)); | |
49 | + xTaskResumeAll(); | |
50 | + } | |
42 | 51 | if (sys.gpsGetData(&gd)) |
43 | 52 | return 1; |
53 | + if (!init_gps){ | |
54 | + delay(5); | |
55 | + }else{ | |
56 | + vTaskDelay(pdMS_TO_TICKS(5)); | |
57 | + } | |
44 | 58 | } |
45 | 59 | return 0; |
46 | 60 | } |
... | ... | @@ -111,13 +125,11 @@ int FilterGpsData(char* isoTime, double* res){ |
111 | 125 | |
112 | 126 | if (slope_flag){ |
113 | 127 | double dist = (double) TinyGPS::distance_between((float) meanGPSCoord[prev][2],(float) meanGPSCoord[prev][1],(float) res[2],(float) res[1]); |
114 | - #if USE_OBD==0 | |
115 | - double dist_max = gd->speed*shiftTime/3.6*1.25; | |
116 | - #else | |
117 | - double dist_max = GetOBDSpeed()*shiftTime/3.6*1.2; | |
118 | - #endif | |
119 | - if ((dist>dist_max) || (dist>(85*shiftTime))) | |
128 | + //double dist_max = gd->speed*shiftTime/3.6*1.25; | |
129 | + | |
130 | + if (dist>(85*shiftTime)) | |
120 | 131 | return -1; |
132 | + | |
121 | 133 | res[3]=(res[0]-meanGPSCoord[prev][0])/(dist+10)*100; |
122 | 134 | meanGPSCoord[n][0]=res[0]; |
123 | 135 | meanGPSCoord[n][1]=res[1]; |
... | ... | @@ -129,40 +141,9 @@ int FilterGpsData(char* isoTime, double* res){ |
129 | 141 | for (j=0;j<time_size;j++){ |
130 | 142 | lastTimeStamp2[j]=isoTime[j]; |
131 | 143 | } |
132 | - #if USE_OBD==0 | |
133 | - isVehicleStopped(isoTime,res[4]); | |
134 | - #endif | |
135 | 144 | return slope_flag; |
136 | 145 | } |
137 | 146 | |
138 | -void isVehicleStopped(char* isoTime,double val){ | |
139 | - static char lastTimeStamp[time_size]={0}; | |
140 | - static float meanSpeed=0; | |
141 | - int j; | |
142 | - | |
143 | - if (lastTimeStamp[0]){ | |
144 | - if (GetShiftTime(lastTimeStamp,isoTime)>NBR_GPS_POINTS){ | |
145 | - if ((meanSpeed<2)&&(abs(val-meanSpeed)<0.5)){ | |
146 | - esp_sleep_enable_timer_wakeup(5 * uS_TO_S_FACTOR); | |
147 | - esp_deep_sleep_start(); | |
148 | - }else{ | |
149 | - meanSpeed=val; | |
150 | - for (j=0;j<time_size;j++){ | |
151 | - lastTimeStamp[j]=isoTime[j]; | |
152 | - } | |
153 | - } | |
154 | - }else{ | |
155 | - meanSpeed+=val; | |
156 | - meanSpeed/=2; | |
157 | - } | |
158 | - }else{ | |
159 | - meanSpeed=val; | |
160 | - for (j=0;j<time_size;j++){ | |
161 | - lastTimeStamp[j]=isoTime[j]; | |
162 | - } | |
163 | - } | |
164 | -} | |
165 | - | |
166 | 147 | int AddGPSData(char* isoTime,char* p, int* nbr){ |
167 | 148 | |
168 | 149 | int GPS_Stat=0; | ... | ... |
FreematicsOBD/datalogger/customized_GPS.h
... | ... | @@ -10,9 +10,6 @@ int isDataGPSReady(int); |
10 | 10 | //return -1 if GPS coordinates are incorrect accroding to speed |
11 | 11 | int FilterGpsData(char*, double*); |
12 | 12 | |
13 | -//check if the vehicle has stopped | |
14 | -void isVehicleStopped(char*,double); | |
15 | - | |
16 | 13 | int AddGPSData(char*,char*,int*); |
17 | 14 | |
18 | 15 | #endif /* __customized_GPS_H */ | ... | ... |
FreematicsOBD/datalogger/customized_OBD.cpp
... | ... | @@ -15,36 +15,21 @@ static SemaphoreHandle_t xSemaphore_err=NULL; |
15 | 15 | //Semaphore to synchronize access to ODB |
16 | 16 | static SemaphoreHandle_t xSemaphore_OBD=NULL; |
17 | 17 | |
18 | -static SemaphoreHandle_t xSemaphore_Speed=NULL; | |
19 | - | |
20 | -int OBD_Speed = 0; | |
21 | - | |
22 | - | |
23 | -int GetOBDSpeed(void){ | |
24 | - int res=0; | |
25 | - xSemaphoreTake(xSemaphore_Speed,portMAX_DELAY); | |
26 | - res = OBD_Speed; | |
27 | - xSemaphoreGive(xSemaphore_Speed); | |
28 | - return res; | |
29 | -} | |
30 | -void setOBDSpeed(int val){ | |
31 | - xSemaphoreTake(xSemaphore_Speed,portMAX_DELAY); | |
32 | - OBD_Speed = val; | |
33 | - xSemaphoreGive(xSemaphore_Speed); | |
34 | -} | |
35 | - | |
36 | 18 | |
37 | 19 | void init_OBD_dev(void){ |
38 | 20 | xSemaphore_err= xSemaphoreCreateMutex(); |
39 | 21 | //creating mutex to synchronze the access to OBD |
40 | 22 | xSemaphore_OBD= xSemaphoreCreateMutex(); |
41 | - xSemaphore_Speed= xSemaphoreCreateMutex(); | |
42 | 23 | obd.begin(sys.link); |
43 | 24 | int cnt=0; |
44 | 25 | while(!set_obd()){ |
45 | 26 | cnt++; |
46 | 27 | delay(200); |
47 | - if (cnt==10){ | |
28 | + #if USE_OBD==0 | |
29 | + break; | |
30 | + #endif | |
31 | + | |
32 | + if (cnt==5){ | |
48 | 33 | esp_sleep_enable_timer_wakeup(5 * uS_TO_S_FACTOR); |
49 | 34 | esp_deep_sleep_start(); |
50 | 35 | } |
... | ... | @@ -72,11 +57,14 @@ void ErrorOBDCheck(void){ |
72 | 57 | obd.reset(); |
73 | 58 | int cnt=0; |
74 | 59 | while(!set_obd()){ |
75 | - delay(200); | |
60 | + #if USE_OBD==0 | |
61 | + break; | |
62 | + #endif | |
76 | 63 | if (cnt==5){ |
77 | 64 | esp_sleep_enable_timer_wakeup(2 * uS_TO_S_FACTOR); |
78 | 65 | esp_deep_sleep_start(); |
79 | 66 | } |
67 | + cnt++; | |
80 | 68 | } |
81 | 69 | } |
82 | 70 | xSemaphoreGive(xSemaphore_err); |
... | ... | @@ -126,7 +114,7 @@ int OBD_looping(ObdInfoPid* PIDs, int nbr_elem,int fr_max){ |
126 | 114 | int j; |
127 | 115 | int val; |
128 | 116 | int OBD_flag; |
129 | - int res=5; | |
117 | + int res=90; | |
130 | 118 | |
131 | 119 | if (!fr_max) |
132 | 120 | res=60000; |
... | ... | @@ -184,13 +172,14 @@ void CheckObdSpeed(char* label,char* isoTime,int val, int* res){ |
184 | 172 | int j; |
185 | 173 | |
186 | 174 | if (!strcmp(label,"PID_SPEED")){ |
187 | - setOBDSpeed(val); | |
188 | 175 | if (lastTimeStamp[0]){ |
189 | 176 | if (GetShiftTime(lastTimeStamp,isoTime)>3){ |
190 | 177 | if (abs(val-meanSpeed)<5){ |
191 | 178 | if (val<2){ |
192 | - esp_sleep_enable_timer_wakeup(5 * uS_TO_S_FACTOR); | |
193 | - esp_deep_sleep_start(); | |
179 | + #if STOP_SLEEP==1 | |
180 | + esp_sleep_enable_timer_wakeup(5 * uS_TO_S_FACTOR); | |
181 | + esp_deep_sleep_start(); | |
182 | + #endif | |
194 | 183 | } |
195 | 184 | *res=100; |
196 | 185 | }else{ |
... | ... | @@ -210,4 +199,4 @@ void CheckObdSpeed(char* label,char* isoTime,int val, int* res){ |
210 | 199 | } |
211 | 200 | } |
212 | 201 | } |
213 | -} | |
214 | 202 | \ No newline at end of file |
203 | +} | ... | ... |
FreematicsOBD/datalogger/simple_obd_test.bin
No preview for this file type
FreematicsOBD/datalogger/simple_obd_test.h
... | ... | @@ -38,13 +38,13 @@ |
38 | 38 | #include <freertos/portmacro.h> |
39 | 39 | #include <freertos/semphr.h> |
40 | 40 | |
41 | -#define USE_SERIAL 0 | |
41 | +#define USE_SERIAL 1 | |
42 | 42 | #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ |
43 | 43 | #define STACK_SIZE 1024 // in words (= 4*STACK_SIZE bytes) |
44 | 44 | #define buff_SIZE 500 |
45 | 45 | #define time_size 100 |
46 | 46 | #define USE_OBD 1 |
47 | -#define NBR_GPS_POINTS 10 | |
48 | - | |
47 | +#define NBR_GPS_POINTS 1 | |
48 | +#define SLEEP_STOP 0 | |
49 | 49 | |
50 | 50 | #endif /* __simple_obd_test_H */ | ... | ... |
FreematicsOBD/datalogger/simple_obd_test.ino
... | ... | @@ -70,9 +70,8 @@ void setup(){ |
70 | 70 | //initialize MEMS device |
71 | 71 | init_MEMS_dev(); |
72 | 72 | |
73 | - #if USE_OBD==1 | |
74 | - init_OBD_dev(); | |
75 | - #endif | |
73 | + | |
74 | + init_OBD_dev(); | |
76 | 75 | |
77 | 76 | // turn on buzzer at 2000Hz frequency |
78 | 77 | sys.buzzer(2000); |
... | ... | @@ -81,20 +80,16 @@ void setup(){ |
81 | 80 | sys.buzzer(0); |
82 | 81 | |
83 | 82 | //creating queue with a size (15*sizeof(Irp*)) |
84 | - xQueue_print = xQueueCreate(15,sizeof(Irp*)); | |
83 | + xQueue_print = xQueueCreate(25,sizeof(Irp*)); | |
85 | 84 | |
86 | - #if USE_OBD==1 | |
87 | - //f=fmax | |
88 | - xTaskCreate(write_task_1,"write_task_1",STACK_SIZE*3,(void*) 0,tskIDLE_PRIORITY+1,NULL); | |
89 | - #endif | |
85 | + //f=fmax | |
86 | + xTaskCreate(write_task_1,"write_task_1",STACK_SIZE*3,(void*) 0,tskIDLE_PRIORITY+1,NULL); | |
90 | 87 | |
91 | 88 | //f=10Hz |
92 | - xTaskCreate(write_task_2,"write_task_2",STACK_SIZE*5,(void*) 0,tskIDLE_PRIORITY+4,NULL); | |
89 | + xTaskCreate(write_task_2,"write_task_2",STACK_SIZE*5,(void*) 0,tskIDLE_PRIORITY+1,NULL); | |
93 | 90 | |
94 | - #if USE_OBD==1 | |
95 | - //f=1/60 Hz | |
96 | - xTaskCreate(write_task_3,"write_task_3",STACK_SIZE*3,(void*) 0,tskIDLE_PRIORITY+1,NULL); | |
97 | - #endif | |
91 | + //f=1/60 Hz | |
92 | + xTaskCreate(write_task_3,"write_task_3",STACK_SIZE*3,(void*) 0,tskIDLE_PRIORITY+1,NULL); | |
98 | 93 | |
99 | 94 | //create daemon task |
100 | 95 | xTaskCreate(vTask_Transmit,"vTask_Transmit",STACK_SIZE*40,(void*) 0,tskIDLE_PRIORITY+3,NULL); |
... | ... | @@ -110,6 +105,7 @@ void write_task_1(void* parameter) |
110 | 105 | sleep_tme=OBD_looping(PIDs,nbr_elem,1); |
111 | 106 | taskYIELD(); |
112 | 107 | ErrorOBDCheck(); |
108 | + Serial.println("OBD signal lost !"); | |
113 | 109 | vTaskDelay(pdMS_TO_TICKS(sleep_tme)); |
114 | 110 | } |
115 | 111 | vTaskDelete(NULL); |
... | ... | @@ -139,7 +135,7 @@ void write_task_2(void* parameter) |
139 | 135 | sprintf(p,"\n"); |
140 | 136 | print_data(buff,nbr+1); |
141 | 137 | } |
142 | - vTaskDelay(pdMS_TO_TICKS(100)); | |
138 | + vTaskDelay(pdMS_TO_TICKS(25)); | |
143 | 139 | } |
144 | 140 | vTaskDelete(NULL); |
145 | 141 | } |
... | ... | @@ -180,7 +176,7 @@ void vTask_Transmit(void *pvParameters){ |
180 | 176 | appendFile(SD, getFileName(),buff); |
181 | 177 | //free the semaphore |
182 | 178 | xSemaphoreGive(ReceiveItem->completion); |
183 | - taskYIELD(); | |
179 | + vTaskDelay(pdMS_TO_TICKS(20)); | |
184 | 180 | } |
185 | 181 | |
186 | 182 | } | ... | ... |