1 |
zoff99 |
27 |
/**
|
2 |
|
|
* ZANavi, Zoff Android Navigation system.
|
3 |
zoff99 |
40 |
* Copyright (C) 2011-2014 Zoff <zoff@zoff.cc>
|
4 |
zoff99 |
27 |
*
|
5 |
|
|
* This program is free software; you can redistribute it and/or
|
6 |
|
|
* modify it under the terms of the GNU General Public License
|
7 |
|
|
* version 2 as published by the Free Software Foundation.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the
|
16 |
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
|
|
* Boston, MA 02110-1301, USA.
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
zoff99 |
2 |
/** @file vehicle_android.c
|
21 |
|
|
* @brief android uses dbus signals
|
22 |
|
|
*
|
23 |
|
|
* Navit, a modular navigation system.
|
24 |
|
|
* Copyright (C) 2005-2008 Navit Team
|
25 |
|
|
*
|
26 |
|
|
* This program is free software; you can redistribute it and/or
|
27 |
|
|
* modify it under the terms of the GNU General Public License
|
28 |
|
|
* version 2 as published by the Free Software Foundation.
|
29 |
|
|
*
|
30 |
|
|
* This program is distributed in the hope that it will be useful,
|
31 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
32 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
33 |
|
|
* GNU General Public License for more details.
|
34 |
|
|
*
|
35 |
|
|
* You should have received a copy of the GNU General Public License
|
36 |
|
|
* along with this program; if not, write to the
|
37 |
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
38 |
|
|
* Boston, MA 02110-1301, USA.
|
39 |
|
|
*
|
40 |
|
|
* @Author Tim Niemeyer <reddog@mastersword.de>
|
41 |
|
|
* @date 2008-2009
|
42 |
|
|
*/
|
43 |
|
|
|
44 |
|
|
#include <config.h>
|
45 |
|
|
#include <string.h>
|
46 |
|
|
#include <glib.h>
|
47 |
|
|
#include <math.h>
|
48 |
|
|
#include <time.h>
|
49 |
|
|
#include "debug.h"
|
50 |
|
|
#include "callback.h"
|
51 |
|
|
#include "plugin.h"
|
52 |
|
|
#include "coord.h"
|
53 |
|
|
#include "item.h"
|
54 |
|
|
#include "android.h"
|
55 |
|
|
#include "vehicle.h"
|
56 |
|
|
|
57 |
zoff99 |
40 |
|
58 |
|
|
#define LOCATION_DAMPEN_BEARING_COUNT 5
|
59 |
|
|
|
60 |
|
|
struct vehicle_last_bearings
|
61 |
|
|
{
|
62 |
|
|
int *ring_buf; // ring buffer
|
63 |
|
|
float *dampen_value; // dampen values
|
64 |
|
|
int max; // max elements
|
65 |
|
|
int cur; // current element num
|
66 |
|
|
int first; // first == 1 --> buffer is not initialised yet
|
67 |
|
|
};
|
68 |
|
|
|
69 |
zoff99 |
28 |
struct vehicle_priv
|
70 |
|
|
{
|
71 |
zoff99 |
2 |
struct callback_list *cbl;
|
72 |
|
|
struct coord_geo geo;
|
73 |
|
|
double speed;
|
74 |
|
|
double direction;
|
75 |
|
|
double height;
|
76 |
|
|
double radius;
|
77 |
|
|
int fix_type;
|
78 |
|
|
time_t fix_time;
|
79 |
|
|
char fixiso8601[128];
|
80 |
|
|
int sats;
|
81 |
|
|
int sats_used;
|
82 |
|
|
int have_coords;
|
83 |
|
|
struct attr ** attrs;
|
84 |
|
|
struct callback *cb;
|
85 |
|
|
jclass NavitVehicleClass;
|
86 |
|
|
jobject NavitVehicle;
|
87 |
|
|
jclass LocationClass;
|
88 |
|
|
jmethodID Location_getLatitude, Location_getLongitude, Location_getSpeed, Location_getBearing, Location_getAltitude, Location_getTime, Location_getAccuracy;
|
89 |
zoff99 |
40 |
struct vehicle_last_bearings *lb;
|
90 |
zoff99 |
2 |
};
|
91 |
|
|
|
92 |
zoff99 |
28 |
// global vars
|
93 |
|
|
struct vehicle_priv *priv_global_android = NULL;
|
94 |
zoff99 |
30 |
|
95 |
|
|
jclass NavitClass3 = NULL;
|
96 |
|
|
jmethodID Navit_get_vehicle;
|
97 |
zoff99 |
28 |
// global vars
|
98 |
|
|
|
99 |
|
|
|
100 |
zoff99 |
30 |
|
101 |
|
|
|
102 |
|
|
static int find_static_method(jclass class, char *name, char *args, jmethodID *ret)
|
103 |
|
|
{
|
104 |
|
|
JNIEnv *jnienv2;
|
105 |
|
|
jnienv2 = jni_getenv();
|
106 |
|
|
|
107 |
|
|
//DBG dbg(0,"EEnter\n");
|
108 |
|
|
*ret = (*jnienv2)->GetStaticMethodID(jnienv2, class, name, args);
|
109 |
|
|
if (*ret == NULL)
|
110 |
|
|
{
|
111 |
|
|
//DBG dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
|
112 |
|
|
return 0;
|
113 |
|
|
}
|
114 |
|
|
return 1;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
|
118 |
zoff99 |
2 |
/**
|
119 |
|
|
* @brief Free the android_vehicle
|
120 |
|
|
*
|
121 |
|
|
* @param priv
|
122 |
|
|
* @returns nothing
|
123 |
|
|
*/
|
124 |
zoff99 |
28 |
static void vehicle_android_destroy(struct vehicle_priv *priv)
|
125 |
zoff99 |
2 |
{
|
126 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
127 |
|
|
dbg(0,"+#+:enter\n");
|
128 |
|
|
#endif
|
129 |
zoff99 |
40 |
|
130 |
|
|
g_free(priv->lb->dampen_value);
|
131 |
|
|
g_free(priv->lb->ring_buf);
|
132 |
|
|
g_free(priv->lb);
|
133 |
|
|
|
134 |
zoff99 |
27 |
// //DBG dbg(0,"enter\n");
|
135 |
zoff99 |
28 |
priv_global_android = NULL;
|
136 |
zoff99 |
2 |
g_free(priv);
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
/**
|
140 |
|
|
* @brief Provide the outside with information
|
141 |
|
|
*
|
142 |
|
|
* @param priv
|
143 |
|
|
* @param type TODO: What can this be?
|
144 |
|
|
* @param attr
|
145 |
|
|
* @returns true/false
|
146 |
|
|
*/
|
147 |
zoff99 |
28 |
static int vehicle_android_position_attr_get(struct vehicle_priv *priv, enum attr_type type, struct attr *attr)
|
148 |
zoff99 |
2 |
{
|
149 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
150 |
|
|
dbg(0,"+#+:enter\n");
|
151 |
|
|
#endif
|
152 |
zoff99 |
27 |
//dbg(1,"enter %s\n",attr_to_name(type));
|
153 |
|
|
switch (type)
|
154 |
|
|
{
|
155 |
zoff99 |
2 |
#if 0
|
156 |
zoff99 |
28 |
case attr_position_fix_type:
|
157 |
zoff99 |
2 |
attr->u.num = priv->fix_type;
|
158 |
|
|
break;
|
159 |
|
|
#endif
|
160 |
zoff99 |
28 |
case attr_position_height:
|
161 |
|
|
attr->u.numd = &priv->height;
|
162 |
|
|
break;
|
163 |
|
|
case attr_position_speed:
|
164 |
|
|
attr->u.numd = &priv->speed;
|
165 |
|
|
break;
|
166 |
|
|
case attr_position_direction:
|
167 |
|
|
attr->u.numd = &priv->direction;
|
168 |
|
|
break;
|
169 |
|
|
case attr_position_radius:
|
170 |
|
|
attr->u.numd = &priv->radius;
|
171 |
|
|
break;
|
172 |
zoff99 |
2 |
|
173 |
|
|
#if 0
|
174 |
zoff99 |
28 |
case attr_position_qual:
|
175 |
|
|
attr->u.num = priv->sats;
|
176 |
|
|
break;
|
177 |
|
|
case attr_position_sats_used:
|
178 |
|
|
attr->u.num = priv->sats_used;
|
179 |
|
|
break;
|
180 |
zoff99 |
2 |
#endif
|
181 |
zoff99 |
28 |
case attr_position_coord_geo:
|
182 |
|
|
attr->u.coord_geo = &priv->geo;
|
183 |
|
|
if (!priv->have_coords)
|
184 |
|
|
return 0;
|
185 |
|
|
break;
|
186 |
|
|
case attr_position_time_iso8601:
|
187 |
|
|
attr->u.str = priv->fixiso8601;
|
188 |
|
|
break;
|
189 |
|
|
default:
|
190 |
zoff99 |
2 |
return 0;
|
191 |
|
|
}
|
192 |
zoff99 |
27 |
//dbg(1,"ok\n");
|
193 |
zoff99 |
2 |
attr->type = type;
|
194 |
zoff99 |
28 |
|
195 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
196 |
|
|
dbg(0,"+#+:leave\n");
|
197 |
|
|
#endif
|
198 |
|
|
|
199 |
zoff99 |
2 |
return 1;
|
200 |
|
|
}
|
201 |
|
|
|
202 |
zoff99 |
34 |
static void vehicle_android_update_location_direct(double lat, double lon, float speed, float direction, double height, float radius, long gpstime)
|
203 |
zoff99 |
28 |
{
|
204 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
205 |
|
|
dbg(0,"+#+:enter\n");
|
206 |
|
|
#endif
|
207 |
zoff99 |
2 |
|
208 |
zoff99 |
28 |
#ifdef NAVIT_MEASURE_TIME_DEBUG
|
209 |
|
|
clock_t s_ = debug_measure_start();
|
210 |
|
|
#endif
|
211 |
|
|
|
212 |
zoff99 |
40 |
int j;
|
213 |
|
|
int k;
|
214 |
zoff99 |
2 |
time_t tnow;
|
215 |
|
|
struct tm *tm;
|
216 |
zoff99 |
28 |
struct vehicle_priv *v = priv_global_android;
|
217 |
zoff99 |
40 |
float direction_new = 0.0f;
|
218 |
zoff99 |
28 |
|
219 |
zoff99 |
34 |
// +++JNIEnv *jnienv2;
|
220 |
|
|
// +++jnienv2 = jni_getenv();
|
221 |
zoff99 |
30 |
|
222 |
zoff99 |
40 |
if (direction < 0)
|
223 |
|
|
{
|
224 |
|
|
direction = direction + 360.0f;
|
225 |
|
|
}
|
226 |
|
|
else if (direction >= 360)
|
227 |
|
|
{
|
228 |
|
|
direction = direction - 360.0f;
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
#ifdef NAVIT_GPS_DIRECTION_DAMPING
|
232 |
|
|
if (v->lb->first == 1)
|
233 |
|
|
{
|
234 |
|
|
v->lb->first = 0;
|
235 |
|
|
for (j = 0; j < LOCATION_DAMPEN_BEARING_COUNT; j++)
|
236 |
|
|
{
|
237 |
|
|
v->lb->ring_buf[j] = (int)(direction * 100.0f);
|
238 |
|
|
}
|
239 |
|
|
}
|
240 |
|
|
#endif
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
#ifdef NAVIT_GPS_DIRECTION_DAMPING
|
244 |
|
|
if (direction == 0.0f)
|
245 |
|
|
{
|
246 |
|
|
// dbg(0, "DAMPING:dir=0.0\n");
|
247 |
|
|
int direction_prev = v->lb->ring_buf[(v->lb->cur + (LOCATION_DAMPEN_BEARING_COUNT - 2)) % LOCATION_DAMPEN_BEARING_COUNT];
|
248 |
|
|
// dbg(0, "DAMPING:dir_prev=%d\n", (int)((float)direction_prev / 100.0f));
|
249 |
|
|
// if direction suddenly jumps to 0 (north), assume some problem or 3G location
|
250 |
|
|
if (abs(direction_prev) > 140) // last direction NOT between -1.4° and 1.4°
|
251 |
|
|
{
|
252 |
|
|
// use previous direction value
|
253 |
|
|
direction = ((float)direction_prev / 100.0f);
|
254 |
|
|
dbg(0, "DAMPING:dir_corr=%f\n", direction);
|
255 |
|
|
}
|
256 |
|
|
}
|
257 |
|
|
#endif
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
#ifdef NAVIT_GPS_DIRECTION_DAMPING
|
261 |
|
|
float direction_new2 = 0.0f;
|
262 |
|
|
|
263 |
|
|
// save orig value into slot
|
264 |
|
|
v->lb->ring_buf[v->lb->cur] = (int)(direction * 100.0f);
|
265 |
|
|
// move to next slot
|
266 |
|
|
v->lb->cur = (v->lb->cur + 1) % LOCATION_DAMPEN_BEARING_COUNT;
|
267 |
|
|
|
268 |
|
|
for (j = 0; j < LOCATION_DAMPEN_BEARING_COUNT; j++)
|
269 |
|
|
{
|
270 |
|
|
if (j == (LOCATION_DAMPEN_BEARING_COUNT - 1))
|
271 |
|
|
{
|
272 |
|
|
|
273 |
|
|
//dbg(0, "DAMPING:info last:direction_new=%f direction=%f j=%d\n", direction_new, direction, j);
|
274 |
|
|
|
275 |
|
|
#if 0
|
276 |
|
|
// if SUM >= 360
|
277 |
|
|
if (direction_new >= 36000)
|
278 |
|
|
{
|
279 |
|
|
for (k = 0; k < (LOCATION_DAMPEN_BEARING_COUNT - 1); k++)
|
280 |
|
|
{
|
281 |
|
|
v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] = v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] - 36000;
|
282 |
|
|
}
|
283 |
|
|
direction_new = direction_new - 36000;
|
284 |
|
|
dbg(0, "DAMPING:>= 360:direction_new=%f\n", (direction_new / 100.0f));
|
285 |
|
|
}
|
286 |
|
|
// if SUM < 0
|
287 |
|
|
else if (direction_new < 0)
|
288 |
|
|
{
|
289 |
|
|
for (k = 0; k < (LOCATION_DAMPEN_BEARING_COUNT - 1); k++)
|
290 |
|
|
{
|
291 |
|
|
v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] = v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] + 36000;
|
292 |
|
|
}
|
293 |
|
|
direction_new = direction_new + 36000;
|
294 |
|
|
dbg(0, "DAMPING:< 0:direction_new=%f\n", (direction_new / 100.0f));
|
295 |
|
|
}
|
296 |
|
|
#endif
|
297 |
|
|
|
298 |
|
|
direction_new2 = v->lb->ring_buf[(v->lb->cur + j - 1) % LOCATION_DAMPEN_BEARING_COUNT] ;
|
299 |
|
|
|
300 |
|
|
//dbg(0, "DAMPING:info last:direction_new2=%f\n", direction_new2);
|
301 |
|
|
//dbg(0, "DAMPING:info last:dir=%d damp=%f\n", v->lb->ring_buf[(v->lb->cur + j) % LOCATION_DAMPEN_BEARING_COUNT], v->lb->dampen_value[j]);
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
// correct for the jump from 0 -> 360 , or 360 -> 0
|
305 |
|
|
if (direction_new2 > (v->lb->ring_buf[(v->lb->cur + j) % LOCATION_DAMPEN_BEARING_COUNT] + 18000) )
|
306 |
|
|
{
|
307 |
|
|
direction_new += ((float)(v->lb->ring_buf[(v->lb->cur + j) % LOCATION_DAMPEN_BEARING_COUNT] + 36000 ) * (v->lb->dampen_value[j]));
|
308 |
|
|
//dbg(0, "DAMPING:jump 360 -> 0:direction_new=%f\n", (direction_new / 100.0f));
|
309 |
|
|
}
|
310 |
|
|
else if ((direction_new2 + 18000) < (v->lb->ring_buf[(v->lb->cur + j) % LOCATION_DAMPEN_BEARING_COUNT]) )
|
311 |
|
|
{
|
312 |
|
|
direction_new += ((float)(v->lb->ring_buf[(v->lb->cur + j) % LOCATION_DAMPEN_BEARING_COUNT] - 36000 ) * (v->lb->dampen_value[j]));
|
313 |
|
|
//dbg(0, "DAMPING:jump 0 -> 360:direction_new=%f\n", (direction_new / 100.0f));
|
314 |
|
|
}
|
315 |
|
|
else
|
316 |
|
|
{
|
317 |
|
|
direction_new += ((float)(v->lb->ring_buf[(v->lb->cur + j) % LOCATION_DAMPEN_BEARING_COUNT]) * (v->lb->dampen_value[j]));
|
318 |
|
|
}
|
319 |
|
|
}
|
320 |
|
|
else
|
321 |
|
|
{
|
322 |
|
|
direction_new += ((float)(v->lb->ring_buf[(v->lb->cur + j) % LOCATION_DAMPEN_BEARING_COUNT]) * (v->lb->dampen_value[j]));
|
323 |
|
|
//dbg(0, "DAMPING:info(%d):direction_new=%f\n", j, direction_new);
|
324 |
|
|
}
|
325 |
|
|
}
|
326 |
|
|
|
327 |
|
|
// if SUM >= 360
|
328 |
|
|
if (direction_new >= 36000)
|
329 |
|
|
{
|
330 |
|
|
for (k = 0; k < (LOCATION_DAMPEN_BEARING_COUNT); k++)
|
331 |
|
|
{
|
332 |
|
|
v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] = v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] - 36000;
|
333 |
|
|
}
|
334 |
|
|
direction_new = direction_new - 36000;
|
335 |
|
|
//dbg(0, "DAMPING:2:>= 360:direction_new=%f\n", (direction_new / 100.0f));
|
336 |
|
|
}
|
337 |
|
|
// if SUM < 0
|
338 |
|
|
else if (direction_new < 0)
|
339 |
|
|
{
|
340 |
|
|
for (k = 0; k < (LOCATION_DAMPEN_BEARING_COUNT); k++)
|
341 |
|
|
{
|
342 |
|
|
v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] = v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] + 36000;
|
343 |
|
|
}
|
344 |
|
|
direction_new = direction_new + 36000;
|
345 |
|
|
//dbg(0, "DAMPING:2:< 0:direction_new=%f\n", (direction_new / 100.0f));
|
346 |
|
|
}
|
347 |
|
|
|
348 |
|
|
|
349 |
|
|
// save corrected value into slot
|
350 |
|
|
v->lb->ring_buf[(v->lb->cur + (LOCATION_DAMPEN_BEARING_COUNT - 1)) % LOCATION_DAMPEN_BEARING_COUNT] = (int)direction_new;
|
351 |
|
|
|
352 |
|
|
v->direction = direction_new / 100.0f;
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
//for (k = 0; k < (LOCATION_DAMPEN_BEARING_COUNT); k++)
|
356 |
|
|
//{
|
357 |
|
|
// dbg(0, "DAMPING:damp[%d]=%f", k, ((float)v->lb->ring_buf[(v->lb->cur + k) % LOCATION_DAMPEN_BEARING_COUNT] / 100.0f));
|
358 |
|
|
//}
|
359 |
|
|
|
360 |
|
|
//dbg(0, "DAMPING:FIN:direction=%f corrected=%f\n", direction, (direction_new / 100.0f));
|
361 |
|
|
//dbg(0, "DAMPING:----------------------------\n");
|
362 |
|
|
|
363 |
|
|
#else
|
364 |
|
|
|
365 |
|
|
// --------------------------------------------------------
|
366 |
|
|
// normal direction, without DAMPING !!
|
367 |
|
|
|
368 |
|
|
v->direction = direction;
|
369 |
|
|
|
370 |
|
|
// --------------------------------------------------------
|
371 |
|
|
|
372 |
|
|
#endif
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
zoff99 |
28 |
//dbg(0,"jnienv=%p\n", jnienv);
|
378 |
|
|
//dbg(0,"priv_global_android=%p\n", priv_global_android);
|
379 |
|
|
//dbg(0,"v=%p\n", v);
|
380 |
|
|
//dbg(0,"location=%p\n", location);
|
381 |
|
|
|
382 |
|
|
// this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
|
383 |
|
|
// this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
|
384 |
|
|
// this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
|
385 |
zoff99 |
34 |
v->geo.lat = lat;
|
386 |
|
|
v->geo.lng = lon;
|
387 |
|
|
v->speed = speed;
|
388 |
zoff99 |
40 |
// ** DAMPING ** // v->direction = direction;
|
389 |
|
|
// dbg(0, "v->direction=%f\n", direction);
|
390 |
zoff99 |
34 |
v->height = height;
|
391 |
|
|
v->radius = radius;
|
392 |
|
|
tnow = gpstime;
|
393 |
zoff99 |
28 |
// this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
|
394 |
|
|
// this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
|
395 |
|
|
// this seems to slow and stupid, try to give those values directly (instead of calling those functions every time!!)
|
396 |
|
|
|
397 |
zoff99 |
2 |
tm = gmtime(&tnow);
|
398 |
|
|
strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm);
|
399 |
zoff99 |
27 |
// //DBG dbg(0,"lat %f lon %f\n",v->geo.lat,v->geo.lng);
|
400 |
zoff99 |
28 |
v->have_coords = 1;
|
401 |
zoff99 |
2 |
|
402 |
zoff99 |
28 |
// remove globalref again
|
403 |
zoff99 |
34 |
//+++(*jnienv2)->DeleteGlobalRef(jnienv2, location);
|
404 |
zoff99 |
28 |
|
405 |
zoff99 |
40 |
|
406 |
|
|
|
407 |
|
|
// xxx stupid callback stuff -> remove me!! xxx ----------------------------
|
408 |
|
|
// xxx stupid callback stuff -> remove me!! xxx ----------------------------
|
409 |
|
|
//
|
410 |
zoff99 |
2 |
// ***** calls: navit.c -> navit_vehicle_update
|
411 |
|
|
callback_list_call_attr_0(v->cbl, attr_position_coord_geo);
|
412 |
zoff99 |
40 |
//
|
413 |
|
|
// xxx stupid callback stuff -> remove me!! xxx ----------------------------
|
414 |
|
|
// xxx stupid callback stuff -> remove me!! xxx ----------------------------
|
415 |
zoff99 |
28 |
|
416 |
zoff99 |
40 |
|
417 |
|
|
|
418 |
|
|
|
419 |
zoff99 |
28 |
#ifdef NAVIT_MEASURE_TIME_DEBUG
|
420 |
|
|
debug_mrp(__PRETTY_FUNCTION__, debug_measure_end(s_));
|
421 |
|
|
#endif
|
422 |
|
|
|
423 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
424 |
|
|
dbg(0,"+#+:leave\n");
|
425 |
|
|
#endif
|
426 |
|
|
|
427 |
zoff99 |
2 |
}
|
428 |
|
|
|
429 |
zoff99 |
28 |
struct vehicle_methods vehicle_android_methods =
|
430 |
|
|
{ vehicle_android_destroy, vehicle_android_position_attr_get, NULL, vehicle_android_update_location_direct};
|
431 |
|
|
|
432 |
|
|
static int vehicle_android_init(struct vehicle_priv *ret)
|
433 |
zoff99 |
2 |
{
|
434 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
435 |
|
|
dbg(0,"+#+:enter\n");
|
436 |
|
|
#endif
|
437 |
zoff99 |
30 |
|
438 |
|
|
int thread_id = gettid();
|
439 |
|
|
dbg(0, "THREAD ID=%d\n", thread_id);
|
440 |
|
|
|
441 |
|
|
JNIEnv *jnienv2;
|
442 |
|
|
jnienv2 = jni_getenv();
|
443 |
|
|
|
444 |
zoff99 |
2 |
jmethodID cid;
|
445 |
|
|
|
446 |
zoff99 |
28 |
//dbg(0,"priv_global_android=%p\n", priv_global_android);
|
447 |
|
|
|
448 |
zoff99 |
2 |
if (!android_find_class_global("android/location/Location", &ret->LocationClass))
|
449 |
zoff99 |
28 |
return 0;
|
450 |
zoff99 |
2 |
if (!android_find_method(ret->LocationClass, "getLatitude", "()D", &ret->Location_getLatitude))
|
451 |
zoff99 |
28 |
return 0;
|
452 |
zoff99 |
2 |
if (!android_find_method(ret->LocationClass, "getLongitude", "()D", &ret->Location_getLongitude))
|
453 |
zoff99 |
28 |
return 0;
|
454 |
zoff99 |
2 |
if (!android_find_method(ret->LocationClass, "getSpeed", "()F", &ret->Location_getSpeed))
|
455 |
zoff99 |
28 |
return 0;
|
456 |
zoff99 |
2 |
if (!android_find_method(ret->LocationClass, "getBearing", "()F", &ret->Location_getBearing))
|
457 |
zoff99 |
28 |
return 0;
|
458 |
zoff99 |
2 |
if (!android_find_method(ret->LocationClass, "getAltitude", "()D", &ret->Location_getAltitude))
|
459 |
zoff99 |
28 |
return 0;
|
460 |
zoff99 |
2 |
if (!android_find_method(ret->LocationClass, "getTime", "()J", &ret->Location_getTime))
|
461 |
zoff99 |
28 |
return 0;
|
462 |
zoff99 |
2 |
if (!android_find_method(ret->LocationClass, "getAccuracy", "()F", &ret->Location_getAccuracy))
|
463 |
zoff99 |
28 |
return 0;
|
464 |
zoff99 |
2 |
if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitVehicle", &ret->NavitVehicleClass))
|
465 |
zoff99 |
27 |
{
|
466 |
zoff99 |
28 |
return 0;
|
467 |
zoff99 |
27 |
}
|
468 |
zoff99 |
28 |
|
469 |
zoff99 |
30 |
//dbg(0,"jnienv2=%p\n", jnienv2);
|
470 |
zoff99 |
28 |
|
471 |
|
|
//DBG dbg(0,"at 3\n");
|
472 |
zoff99 |
30 |
//cid = (*jnienv2)->GetMethodID(jnienv2, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;I)V");
|
473 |
|
|
//if (cid == NULL)
|
474 |
|
|
//{
|
475 |
|
|
// //DBG dbg(0,"no method found\n");
|
476 |
|
|
// return 0;
|
477 |
|
|
//}
|
478 |
|
|
|
479 |
|
|
// --------------- Init the new Vehicle Object here -----------------
|
480 |
|
|
// --------------- Init the new Vehicle Object here -----------------
|
481 |
|
|
// --------------- Init the new Vehicle Object here -----------------
|
482 |
|
|
dbg(0,"Init the new Vehicle Object here\n");
|
483 |
|
|
|
484 |
|
|
if (NavitClass3 == NULL)
|
485 |
zoff99 |
27 |
{
|
486 |
zoff99 |
30 |
if (!android_find_class_global("com/zoffcc/applications/zanavi/Navit", &NavitClass3))
|
487 |
|
|
{
|
488 |
|
|
NavitClass3 = NULL;
|
489 |
|
|
return 0;
|
490 |
|
|
}
|
491 |
|
|
}
|
492 |
|
|
|
493 |
|
|
if (!find_static_method(NavitClass3, "get_vehicle_object", "()Lcom/zoffcc/applications/zanavi/NavitVehicle;", &Navit_get_vehicle))
|
494 |
|
|
{
|
495 |
zoff99 |
28 |
return 0;
|
496 |
|
|
}
|
497 |
zoff99 |
30 |
|
498 |
|
|
/// --old-- ret->NavitVehicle = (*jnienv2)->NewObject(jnienv2, ret->NavitVehicleClass, cid, android_activity, (int) ret->cb);
|
499 |
|
|
/// --new--
|
500 |
|
|
ret->NavitVehicle = (*jnienv2)->CallStaticObjectMethod(jnienv2, NavitClass3, Navit_get_vehicle);
|
501 |
|
|
/// --new--
|
502 |
|
|
// --------------- Init the new Vehicle Object here -----------------
|
503 |
|
|
// --------------- Init the new Vehicle Object here -----------------
|
504 |
|
|
// --------------- Init the new Vehicle Object here -----------------
|
505 |
|
|
|
506 |
zoff99 |
2 |
if (!ret->NavitVehicle)
|
507 |
zoff99 |
27 |
{
|
508 |
zoff99 |
2 |
return 0;
|
509 |
zoff99 |
27 |
}
|
510 |
zoff99 |
2 |
|
511 |
zoff99 |
28 |
if (ret->NavitVehicle)
|
512 |
zoff99 |
27 |
{
|
513 |
zoff99 |
30 |
ret->NavitVehicle = (*jnienv2)->NewGlobalRef(jnienv2, ret->NavitVehicle);
|
514 |
zoff99 |
27 |
}
|
515 |
|
|
|
516 |
zoff99 |
30 |
dbg(0,"leave\n");
|
517 |
|
|
|
518 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
519 |
|
|
dbg(0,"+#+:leave\n");
|
520 |
|
|
#endif
|
521 |
|
|
|
522 |
zoff99 |
2 |
return 1;
|
523 |
|
|
}
|
524 |
|
|
|
525 |
|
|
/**
|
526 |
|
|
* @brief Create android_vehicle
|
527 |
|
|
*
|
528 |
|
|
* @param meth
|
529 |
|
|
* @param cbl
|
530 |
|
|
* @param attrs
|
531 |
|
|
* @returns vehicle_priv
|
532 |
|
|
*/
|
533 |
zoff99 |
40 |
struct vehicle_priv *
|
534 |
zoff99 |
28 |
vehicle_android_new_android(struct vehicle_methods *meth, struct callback_list *cbl, struct attr **attrs)
|
535 |
zoff99 |
2 |
{
|
536 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
537 |
|
|
dbg(0,"+#+:enter\n");
|
538 |
|
|
#endif
|
539 |
zoff99 |
2 |
struct vehicle_priv *ret;
|
540 |
zoff99 |
40 |
struct vehicle_last_bearings *lb;
|
541 |
|
|
int size;
|
542 |
zoff99 |
2 |
|
543 |
|
|
ret = g_new0(struct vehicle_priv, 1);
|
544 |
|
|
ret->cbl = cbl;
|
545 |
zoff99 |
28 |
// *********** // ret->cb = callback_new_1(callback_cast(vehicle_android_callback), ret);
|
546 |
zoff99 |
2 |
*meth = vehicle_android_methods;
|
547 |
zoff99 |
28 |
priv_global_android = ret;
|
548 |
zoff99 |
40 |
|
549 |
|
|
|
550 |
|
|
lb = g_new0(struct vehicle_last_bearings, 1);
|
551 |
|
|
size = sizeof(int) * LOCATION_DAMPEN_BEARING_COUNT;
|
552 |
|
|
lb->ring_buf = g_malloc(size);
|
553 |
|
|
lb->max = LOCATION_DAMPEN_BEARING_COUNT;
|
554 |
|
|
lb->first = 1;
|
555 |
|
|
lb->cur = 0;
|
556 |
|
|
|
557 |
|
|
size = sizeof(float) * LOCATION_DAMPEN_BEARING_COUNT;
|
558 |
|
|
lb->dampen_value = g_malloc(size);
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
#ifdef NAVIT_GPS_DIRECTION_DAMPING
|
562 |
|
|
|
563 |
|
|
// lb->dampen_value[0] = 0.00f;
|
564 |
|
|
// lb->dampen_value[1] = 0.00f;
|
565 |
|
|
// lb->dampen_value[2] = 0.00f;
|
566 |
|
|
// lb->dampen_value[3] = 0.00f;
|
567 |
|
|
// lb->dampen_value[4] = 0.01f;
|
568 |
|
|
// lb->dampen_value[5] = 0.02f;
|
569 |
|
|
// lb->dampen_value[6] = 0.04f;
|
570 |
|
|
// lb->dampen_value[7] = 0.10f;
|
571 |
|
|
// lb->dampen_value[8] = 0.16f;
|
572 |
|
|
// lb->dampen_value[9] = 0.67f;
|
573 |
|
|
|
574 |
|
|
lb->dampen_value[0] = 0.00f;
|
575 |
|
|
lb->dampen_value[1] = 0.00f;
|
576 |
|
|
lb->dampen_value[2] = 0.00f;
|
577 |
|
|
lb->dampen_value[3] = 0.10f;
|
578 |
|
|
lb->dampen_value[4] = 0.90f;
|
579 |
|
|
|
580 |
|
|
#endif
|
581 |
|
|
|
582 |
|
|
ret->lb = lb;
|
583 |
|
|
|
584 |
zoff99 |
28 |
//dbg(0,"priv_global_android=%p\n", priv_global_android);
|
585 |
zoff99 |
2 |
vehicle_android_init(ret);
|
586 |
zoff99 |
28 |
|
587 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
588 |
|
|
dbg(0,"+#+:leave\n");
|
589 |
|
|
#endif
|
590 |
|
|
|
591 |
zoff99 |
2 |
return ret;
|
592 |
|
|
}
|
593 |
|
|
|
594 |
|
|
/**
|
595 |
|
|
* @brief register vehicle_android
|
596 |
|
|
*
|
597 |
|
|
* @returns nothing
|
598 |
|
|
*/
|
599 |
zoff99 |
40 |
#ifdef PLUGSSS
|
600 |
zoff99 |
28 |
void plugin_init(void)
|
601 |
zoff99 |
2 |
{
|
602 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
603 |
|
|
dbg(0,"+#+:enter\n");
|
604 |
|
|
#endif
|
605 |
zoff99 |
27 |
//DBG dbg(0, "enter\n");
|
606 |
zoff99 |
2 |
plugin_register_vehicle_type("android", vehicle_android_new_android);
|
607 |
zoff99 |
28 |
|
608 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
609 |
|
|
dbg(0,"+#+:leave\n");
|
610 |
|
|
#endif
|
611 |
|
|
|
612 |
zoff99 |
2 |
}
|
613 |
zoff99 |
40 |
#endif
|
614 |
zoff99 |
28 |
|