summaryrefslogtreecommitdiff
path: root/navit/vehicle
diff options
context:
space:
mode:
authorJoseph Herlant <herlantj@gmail.com>2018-05-25 22:06:51 -0700
committerJoseph Herlant <aerostitch@users.noreply.github.com>2018-05-25 22:17:50 -0700
commit8a76acb966f7059caf9d72c853175bd923b1e9d7 (patch)
tree1735178f7a0718831b88d2c36ea18a9955de3224 /navit/vehicle
parent032f15287b472f1a4b5349533f3e5b468684b281 (diff)
downloadnavit-8a76acb966f7059caf9d72c853175bd923b1e9d7.tar.gz
cleanup:global:Use astyle to reformat everything
Diffstat (limited to 'navit/vehicle')
-rw-r--r--navit/vehicle/android/vehicle_android.c320
-rw-r--r--navit/vehicle/demo/vehicle_demo.c459
-rw-r--r--navit/vehicle/file/vehicle_file.c1476
-rw-r--r--navit/vehicle/file/vehicle_pipe.c5
-rw-r--r--navit/vehicle/file/vehicle_serial.c5
-rw-r--r--navit/vehicle/file/vehicle_socket.c5
-rw-r--r--navit/vehicle/gpsd/vehicle_gpsd.c662
-rw-r--r--navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c340
-rw-r--r--navit/vehicle/gypsy/vehicle_gypsy.c590
-rw-r--r--navit/vehicle/iphone/vehicle_iphone.c201
-rw-r--r--navit/vehicle/maemo/vehicle_maemo.c506
-rw-r--r--navit/vehicle/null/vehicle_null.c167
-rw-r--r--navit/vehicle/qt5/vehicle_qt5.cpp45
-rw-r--r--navit/vehicle/webos/bluetooth.c986
-rw-r--r--navit/vehicle/webos/cJSON.c1069
-rw-r--r--navit/vehicle/webos/vehicle_webos.c570
-rw-r--r--navit/vehicle/wince/vehicle_wince.c1662
17 files changed, 4590 insertions, 4478 deletions
diff --git a/navit/vehicle/android/vehicle_android.c b/navit/vehicle/android/vehicle_android.c
index 722943294..5eb9a24b7 100644
--- a/navit/vehicle/android/vehicle_android.c
+++ b/navit/vehicle/android/vehicle_android.c
@@ -41,39 +41,39 @@
*/
struct vehicle_priv {
- struct callback_list *cbl;
- struct coord_geo geo; /**< The last known position of the vehicle **/
- double speed; /**< Speed in km/h **/
- double direction; /**< Bearing in degrees **/
- double height; /**< Elevation in meters **/
- double radius; /**< Position accuracy in meters **/
- int fix_type; /**< Type of last fix (1 = valid, 0 = invalid) **/
- time_t fix_time; /**< Timestamp of last fix (not used) **/
- char fixiso8601[128]; /**< Timestamp of last fix in ISO 8601 format **/
- int sats; /**< Number of satellites in view **/
- int sats_used; /**< Number of satellites used in fix **/
- int valid; /**< Whether the vehicle coordinates in {@code geo} are valid **/
- struct attr ** attrs;
- struct callback *pcb; /**< The callback function for position updates **/
- struct callback *scb; /**< The callback function for status updates **/
- struct callback *fcb; /**< The callback function for fix status updates **/
- jclass NavitVehicleClass; /**< The {@code NavitVehicle} class **/
- jobject NavitVehicle; /**< An instance of {@code NavitVehicle} **/
- jclass LocationClass; /**< Android's {@code Location} class **/
- jmethodID Location_getLatitude, Location_getLongitude, Location_getSpeed, Location_getBearing, Location_getAltitude, Location_getTime, Location_getAccuracy;
+ struct callback_list *cbl;
+ struct coord_geo geo; /**< The last known position of the vehicle **/
+ double speed; /**< Speed in km/h **/
+ double direction; /**< Bearing in degrees **/
+ double height; /**< Elevation in meters **/
+ double radius; /**< Position accuracy in meters **/
+ int fix_type; /**< Type of last fix (1 = valid, 0 = invalid) **/
+ time_t fix_time; /**< Timestamp of last fix (not used) **/
+ char fixiso8601[128]; /**< Timestamp of last fix in ISO 8601 format **/
+ int sats; /**< Number of satellites in view **/
+ int sats_used; /**< Number of satellites used in fix **/
+ int valid; /**< Whether the vehicle coordinates in {@code geo} are valid **/
+ struct attr ** attrs;
+ struct callback *pcb; /**< The callback function for position updates **/
+ struct callback *scb; /**< The callback function for status updates **/
+ struct callback *fcb; /**< The callback function for fix status updates **/
+ jclass NavitVehicleClass; /**< The {@code NavitVehicle} class **/
+ jobject NavitVehicle; /**< An instance of {@code NavitVehicle} **/
+ jclass LocationClass; /**< Android's {@code Location} class **/
+ jmethodID Location_getLatitude, Location_getLongitude, Location_getSpeed, Location_getBearing, Location_getAltitude,
+ Location_getTime, Location_getAccuracy;
};
/**
* @brief Free the android_vehicle
- *
+ *
* @param priv vehicle_priv structure for the vehicle
* @returns nothing
*/
static void
-vehicle_android_destroy(struct vehicle_priv *priv)
-{
- dbg(lvl_debug,"enter");
- g_free(priv);
+vehicle_android_destroy(struct vehicle_priv *priv) {
+ dbg(lvl_debug,"enter");
+ g_free(priv);
}
/**
@@ -86,53 +86,52 @@ vehicle_android_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_android_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- dbg(lvl_debug,"enter %s",attr_to_name(type));
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->fix_type;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_radius:
- attr->u.numd = &priv->radius;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- if (priv->valid == attr_position_valid_invalid)
- return 0;
- break;
- case attr_position_time_iso8601:
- attr->u.str=priv->fixiso8601;
- break;
- case attr_position_valid:
- attr->u.num = priv->valid;
- break;
- default:
- return 0;
- }
- dbg(lvl_debug,"ok");
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ dbg(lvl_debug,"enter %s",attr_to_name(type));
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->fix_type;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_radius:
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ if (priv->valid == attr_position_valid_invalid)
+ return 0;
+ break;
+ case attr_position_time_iso8601:
+ attr->u.str=priv->fixiso8601;
+ break;
+ case attr_position_valid:
+ attr->u.num = priv->valid;
+ break;
+ default:
+ return 0;
+ }
+ dbg(lvl_debug,"ok");
+ attr->type = type;
+ return 1;
}
struct vehicle_methods vehicle_android_methods = {
- vehicle_android_destroy,
- vehicle_android_position_attr_get,
+ vehicle_android_destroy,
+ vehicle_android_position_attr_get,
};
/**
@@ -145,25 +144,25 @@ struct vehicle_methods vehicle_android_methods = {
*/
static void
vehicle_android_position_callback(struct vehicle_priv *v, jobject location) {
- time_t tnow;
- struct tm *tm;
- dbg(lvl_debug,"enter");
+ time_t tnow;
+ struct tm *tm;
+ dbg(lvl_debug,"enter");
- v->geo.lat = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLatitude);
- v->geo.lng = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLongitude);
- v->speed = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getSpeed)*3.6;
- v->direction = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getBearing);
- v->height = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getAltitude);
- v->radius = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getAccuracy);
- tnow=(*jnienv)->CallLongMethod(jnienv, location, v->Location_getTime)/1000;
- tm = gmtime(&tnow);
- strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm);
- dbg(lvl_debug,"lat %f lon %f time %s",v->geo.lat,v->geo.lng,v->fixiso8601);
- if (v->valid != attr_position_valid_valid) {
- v->valid = attr_position_valid_valid;
- callback_list_call_attr_0(v->cbl, attr_position_valid);
- }
- callback_list_call_attr_0(v->cbl, attr_position_coord_geo);
+ v->geo.lat = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLatitude);
+ v->geo.lng = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLongitude);
+ v->speed = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getSpeed)*3.6;
+ v->direction = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getBearing);
+ v->height = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getAltitude);
+ v->radius = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getAccuracy);
+ tnow=(*jnienv)->CallLongMethod(jnienv, location, v->Location_getTime)/1000;
+ tm = gmtime(&tnow);
+ strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm);
+ dbg(lvl_debug,"lat %f lon %f time %s",v->geo.lat,v->geo.lng,v->fixiso8601);
+ if (v->valid != attr_position_valid_valid) {
+ v->valid = attr_position_valid_valid;
+ callback_list_call_attr_0(v->cbl, attr_position_valid);
+ }
+ callback_list_call_attr_0(v->cbl, attr_position_coord_geo);
}
/**
@@ -182,14 +181,14 @@ vehicle_android_position_callback(struct vehicle_priv *v, jobject location) {
*/
static void
vehicle_android_status_callback(struct vehicle_priv *v, int sats_in_view, int sats_used) {
- if (v->sats != sats_in_view) {
- v->sats = sats_in_view;
- callback_list_call_attr_0(v->cbl, attr_position_qual);
- }
- if (v->sats_used != sats_used) {
- v->sats_used = sats_used;
- callback_list_call_attr_0(v->cbl, attr_position_sats_used);
- }
+ if (v->sats != sats_in_view) {
+ v->sats = sats_in_view;
+ callback_list_call_attr_0(v->cbl, attr_position_qual);
+ }
+ if (v->sats_used != sats_used) {
+ v->sats_used = sats_used;
+ callback_list_call_attr_0(v->cbl, attr_position_sats_used);
+ }
}
/**
@@ -202,14 +201,14 @@ vehicle_android_status_callback(struct vehicle_priv *v, int sats_in_view, int sa
*/
static void
vehicle_android_fix_callback(struct vehicle_priv *v, int fix_type) {
- if (v->fix_type != fix_type) {
- v->fix_type = fix_type;
- callback_list_call_attr_0(v->cbl, attr_position_fix_type);
- if (!fix_type && (v->valid == attr_position_valid_valid)) {
- v->valid = attr_position_valid_extrapolated_time;
- callback_list_call_attr_0(v->cbl, attr_position_valid);
- }
- }
+ if (v->fix_type != fix_type) {
+ v->fix_type = fix_type;
+ callback_list_call_attr_0(v->cbl, attr_position_fix_type);
+ if (!fix_type && (v->valid == attr_position_valid_valid)) {
+ v->valid = attr_position_valid_extrapolated_time;
+ callback_list_call_attr_0(v->cbl, attr_position_valid);
+ }
+ }
}
/**
@@ -218,49 +217,48 @@ vehicle_android_fix_callback(struct vehicle_priv *v, int fix_type) {
* @return True on success, false on failure
*/
static int
-vehicle_android_init(struct vehicle_priv *ret)
-{
- jmethodID cid;
+vehicle_android_init(struct vehicle_priv *ret) {
+ jmethodID cid;
- if (!android_find_class_global("android/location/Location", &ret->LocationClass))
- return 0;
- if (!android_find_method(ret->LocationClass, "getLatitude", "()D", &ret->Location_getLatitude))
- return 0;
- if (!android_find_method(ret->LocationClass, "getLongitude", "()D", &ret->Location_getLongitude))
- return 0;
- if (!android_find_method(ret->LocationClass, "getSpeed", "()F", &ret->Location_getSpeed))
- return 0;
- if (!android_find_method(ret->LocationClass, "getBearing", "()F", &ret->Location_getBearing))
- return 0;
- if (!android_find_method(ret->LocationClass, "getAltitude", "()D", &ret->Location_getAltitude))
- return 0;
- if (!android_find_method(ret->LocationClass, "getTime", "()J", &ret->Location_getTime))
- return 0;
- if (!android_find_method(ret->LocationClass, "getAccuracy", "()F", &ret->Location_getAccuracy))
- return 0;
- if (!android_find_class_global("org/navitproject/navit/NavitVehicle", &ret->NavitVehicleClass))
- return 0;
- dbg(lvl_debug,"at 3");
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;III)V");
- if (cid == NULL) {
- dbg(lvl_error,"no method found");
- return 0; /* exception thrown */
- }
- dbg(lvl_debug, "at 4 android_activity=%p", android_activity);
- ret->NavitVehicle=(*jnienv)->NewObject(jnienv, ret->NavitVehicleClass, cid, android_activity,
- (int) ret->pcb, (int) ret->scb, (int) ret->fcb);
- dbg(lvl_debug,"result=%p",ret->NavitVehicle);
- if (!ret->NavitVehicle)
- return 0;
- if (ret->NavitVehicle)
- ret->NavitVehicle = (*jnienv)->NewGlobalRef(jnienv, ret->NavitVehicle);
+ if (!android_find_class_global("android/location/Location", &ret->LocationClass))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getLatitude", "()D", &ret->Location_getLatitude))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getLongitude", "()D", &ret->Location_getLongitude))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getSpeed", "()F", &ret->Location_getSpeed))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getBearing", "()F", &ret->Location_getBearing))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getAltitude", "()D", &ret->Location_getAltitude))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getTime", "()J", &ret->Location_getTime))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getAccuracy", "()F", &ret->Location_getAccuracy))
+ return 0;
+ if (!android_find_class_global("org/navitproject/navit/NavitVehicle", &ret->NavitVehicleClass))
+ return 0;
+ dbg(lvl_debug,"at 3");
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;III)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no method found");
+ return 0; /* exception thrown */
+ }
+ dbg(lvl_debug, "at 4 android_activity=%p", android_activity);
+ ret->NavitVehicle=(*jnienv)->NewObject(jnienv, ret->NavitVehicleClass, cid, android_activity,
+ (int) ret->pcb, (int) ret->scb, (int) ret->fcb);
+ dbg(lvl_debug,"result=%p",ret->NavitVehicle);
+ if (!ret->NavitVehicle)
+ return 0;
+ if (ret->NavitVehicle)
+ ret->NavitVehicle = (*jnienv)->NewGlobalRef(jnienv, ret->NavitVehicle);
- return 1;
+ return 1;
}
/**
* @brief Create android_vehicle
- *
+ *
* @param meth
* @param cbl
* @param attrs
@@ -268,36 +266,34 @@ vehicle_android_init(struct vehicle_priv *ret)
*/
static struct vehicle_priv *
vehicle_android_new_android(struct vehicle_methods *meth,
- struct callback_list *cbl,
- struct attr **attrs)
-{
- struct vehicle_priv *ret;
+ struct callback_list *cbl,
+ struct attr **attrs) {
+ struct vehicle_priv *ret;
- dbg(lvl_debug, "enter");
- ret = g_new0(struct vehicle_priv, 1);
- ret->cbl = cbl;
- ret->pcb = callback_new_1(callback_cast(vehicle_android_position_callback), ret);
- ret->scb = callback_new_1(callback_cast(vehicle_android_status_callback), ret);
- ret->fcb = callback_new_1(callback_cast(vehicle_android_fix_callback), ret);
- ret->valid = attr_position_valid_invalid;
- ret->sats = 0;
- ret->sats_used = 0;
- *meth = vehicle_android_methods;
- vehicle_android_init(ret);
- dbg(lvl_debug, "return");
- return ret;
+ dbg(lvl_debug, "enter");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ ret->pcb = callback_new_1(callback_cast(vehicle_android_position_callback), ret);
+ ret->scb = callback_new_1(callback_cast(vehicle_android_status_callback), ret);
+ ret->fcb = callback_new_1(callback_cast(vehicle_android_fix_callback), ret);
+ ret->valid = attr_position_valid_invalid;
+ ret->sats = 0;
+ ret->sats_used = 0;
+ *meth = vehicle_android_methods;
+ vehicle_android_init(ret);
+ dbg(lvl_debug, "return");
+ return ret;
}
/**
* @brief register vehicle_android
- *
+ *
* @returns nothing
*/
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("android", vehicle_android_new_android);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("android", vehicle_android_new_android);
}
/** @} */
diff --git a/navit/vehicle/demo/vehicle_demo.c b/navit/vehicle/demo/vehicle_demo.c
index 036e97e27..54e243381 100644
--- a/navit/vehicle/demo/vehicle_demo.c
+++ b/navit/vehicle/demo/vehicle_demo.c
@@ -42,272 +42,267 @@
*/
struct vehicle_priv {
- int interval;
- int position_set;
- struct callback_list *cbl;
- struct navit *navit;
- struct route *route;
- struct coord_geo geo;
- struct coord last;
- double config_speed;
- double speed;
- double direction;
- struct callback *timer_callback;
- struct event_timeout *timer;
- char *timep;
- char *nmea;
- enum attr_position_valid valid; /**< Whether the vehicle has valid position data **/
+ int interval;
+ int position_set;
+ struct callback_list *cbl;
+ struct navit *navit;
+ struct route *route;
+ struct coord_geo geo;
+ struct coord last;
+ double config_speed;
+ double speed;
+ double direction;
+ struct callback *timer_callback;
+ struct event_timeout *timer;
+ char *timep;
+ char *nmea;
+ enum attr_position_valid valid; /**< Whether the vehicle has valid position data **/
};
static void
-vehicle_demo_destroy(struct vehicle_priv *priv)
-{
- if (priv->timer)
- event_remove_timeout(priv->timer);
- callback_destroy(priv->timer_callback);
- g_free(priv->timep);
- g_free(priv);
+vehicle_demo_destroy(struct vehicle_priv *priv) {
+ if (priv->timer)
+ event_remove_timeout(priv->timer);
+ callback_destroy(priv->timer_callback);
+ g_free(priv->timep);
+ g_free(priv);
}
static void
-nmea_chksum(char *nmea)
-{
- int i;
- if (nmea && strlen(nmea) > 3) {
- unsigned char csum=0;
- for (i = 1 ; i < strlen(nmea)-4 ; i++)
- csum^=(unsigned char)(nmea[i]);
- sprintf(nmea+strlen(nmea)-3,"%02X\n",csum);
- }
+nmea_chksum(char *nmea) {
+ int i;
+ if (nmea && strlen(nmea) > 3) {
+ unsigned char csum=0;
+ for (i = 1 ; i < strlen(nmea)-4 ; i++)
+ csum^=(unsigned char)(nmea[i]);
+ sprintf(nmea+strlen(nmea)-3,"%02X\n",csum);
+ }
}
static int
vehicle_demo_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- char ns='N',ew='E',*timep,*rmc,*gga;
- int hr,min,sec,year,mon,day;
- double lat,lng;
- switch (type) {
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_time_iso8601:
- g_free(priv->timep);
- priv->timep=current_to_iso8601();
- attr->u.str=priv->timep;
- break;
- case attr_position_fix_type:
- attr->u.num = 2;
- break;
- case attr_position_sats_used:
- attr->u.num = 9;
- break;
- case attr_position_nmea:
- lat=priv->geo.lat;
- if (lat < 0) {
- lat=-lat;
- ns='S';
- }
- lng=priv->geo.lng;
- if (lng < 0) {
- lng=-lng;
- ew='W';
- }
- timep=current_to_iso8601();
- sscanf(timep,"%d-%d-%dT%d:%d:%d",&year,&mon,&day,&hr,&min,&sec);
- g_free(timep);
- gga=g_strdup_printf("$GPGGA,%02d%02d%02d,%02.0f%07.4f,%c,%03.0f%07.4f,%c,1,08,2.5,0,M,,,,0000* \n",hr,min,sec,floor(lat),(lat-floor(lat))*60.0,ns,floor(lng),(lng-floor(lng))*60,ew);
- nmea_chksum(gga);
- rmc=g_strdup_printf("$GPRMC,%02d%02d%02d,A,%02.0f%07.4f,%c,%03.0f%07.4f,%c,%3.1f,%3.1f,%02d%02d%02d,,* \n",hr,min,sec,floor(lat),(lat-floor(lat))*60.0,ns,floor(lng),(lng-floor(lng))*60,ew,priv->speed/1.852,(double)priv->direction,day,mon,year%100);
- nmea_chksum(rmc);
- g_free(priv->nmea);
- priv->nmea=g_strdup_printf("%s%s",gga,rmc);
- g_free(gga);
- g_free(rmc);
- attr->u.str=priv->nmea;
- break;
- case attr_position_valid:
- attr->u.num=priv->valid;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ char ns='N',ew='E',*timep,*rmc,*gga;
+ int hr,min,sec,year,mon,day;
+ double lat,lng;
+ switch (type) {
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601:
+ g_free(priv->timep);
+ priv->timep=current_to_iso8601();
+ attr->u.str=priv->timep;
+ break;
+ case attr_position_fix_type:
+ attr->u.num = 2;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = 9;
+ break;
+ case attr_position_nmea:
+ lat=priv->geo.lat;
+ if (lat < 0) {
+ lat=-lat;
+ ns='S';
+ }
+ lng=priv->geo.lng;
+ if (lng < 0) {
+ lng=-lng;
+ ew='W';
+ }
+ timep=current_to_iso8601();
+ sscanf(timep,"%d-%d-%dT%d:%d:%d",&year,&mon,&day,&hr,&min,&sec);
+ g_free(timep);
+ gga=g_strdup_printf("$GPGGA,%02d%02d%02d,%02.0f%07.4f,%c,%03.0f%07.4f,%c,1,08,2.5,0,M,,,,0000* \n",hr,min,sec,
+ floor(lat),(lat-floor(lat))*60.0,ns,floor(lng),(lng-floor(lng))*60,ew);
+ nmea_chksum(gga);
+ rmc=g_strdup_printf("$GPRMC,%02d%02d%02d,A,%02.0f%07.4f,%c,%03.0f%07.4f,%c,%3.1f,%3.1f,%02d%02d%02d,,* \n",hr,min,sec,
+ floor(lat),(lat-floor(lat))*60.0,ns,floor(lng),(lng-floor(lng))*60,ew,priv->speed/1.852,(double)priv->direction,day,mon,
+ year%100);
+ nmea_chksum(rmc);
+ g_free(priv->nmea);
+ priv->nmea=g_strdup_printf("%s%s",gga,rmc);
+ g_free(gga);
+ g_free(rmc);
+ attr->u.str=priv->nmea;
+ break;
+ case attr_position_valid:
+ attr->u.num=priv->valid;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static int
-vehicle_demo_set_attr_do(struct vehicle_priv *priv, struct attr *attr)
-{
- switch(attr->type) {
- case attr_navit:
- priv->navit = attr->u.navit;
- break;
- case attr_route:
- priv->route = attr->u.route;
- break;
- case attr_speed:
- priv->config_speed=attr->u.num;
- break;
- case attr_interval:
- priv->interval=attr->u.num;
- if (priv->timer)
- event_remove_timeout(priv->timer);
- priv->timer=event_add_timeout(priv->interval, 1, priv->timer_callback);
- break;
- case attr_position_coord_geo:
- priv->geo=*(attr->u.coord_geo);
- if (priv->valid != attr_position_valid_valid) {
- priv->valid = attr_position_valid_valid;
- callback_list_call_attr_0(priv->cbl, attr_position_valid);
- }
- priv->position_set=1;
- dbg(lvl_debug,"position_set %f %f", priv->geo.lat, priv->geo.lng);
- break;
- case attr_profilename:
- case attr_source:
- case attr_name:
- case attr_follow:
- case attr_active:
- // Ignore; used by Navit's infrastructure, but not relevant for this vehicle.
- break;
- default:
- dbg(lvl_error,"unsupported attribute %s",attr_to_name(attr->type));
- return 0;
- }
- return 1;
+vehicle_demo_set_attr_do(struct vehicle_priv *priv, struct attr *attr) {
+ switch(attr->type) {
+ case attr_navit:
+ priv->navit = attr->u.navit;
+ break;
+ case attr_route:
+ priv->route = attr->u.route;
+ break;
+ case attr_speed:
+ priv->config_speed=attr->u.num;
+ break;
+ case attr_interval:
+ priv->interval=attr->u.num;
+ if (priv->timer)
+ event_remove_timeout(priv->timer);
+ priv->timer=event_add_timeout(priv->interval, 1, priv->timer_callback);
+ break;
+ case attr_position_coord_geo:
+ priv->geo=*(attr->u.coord_geo);
+ if (priv->valid != attr_position_valid_valid) {
+ priv->valid = attr_position_valid_valid;
+ callback_list_call_attr_0(priv->cbl, attr_position_valid);
+ }
+ priv->position_set=1;
+ dbg(lvl_debug,"position_set %f %f", priv->geo.lat, priv->geo.lng);
+ break;
+ case attr_profilename:
+ case attr_source:
+ case attr_name:
+ case attr_follow:
+ case attr_active:
+ // Ignore; used by Navit's infrastructure, but not relevant for this vehicle.
+ break;
+ default:
+ dbg(lvl_error,"unsupported attribute %s",attr_to_name(attr->type));
+ return 0;
+ }
+ return 1;
}
static int
-vehicle_demo_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- return vehicle_demo_set_attr_do(priv, attr);
+vehicle_demo_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ return vehicle_demo_set_attr_do(priv, attr);
}
struct vehicle_methods vehicle_demo_methods = {
- vehicle_demo_destroy,
- vehicle_demo_position_attr_get,
- vehicle_demo_set_attr,
+ vehicle_demo_destroy,
+ vehicle_demo_position_attr_get,
+ vehicle_demo_set_attr,
};
static void
-vehicle_demo_timer(struct vehicle_priv *priv)
-{
- struct coord c, c2, pos, ci;
- int slen, len, dx, dy;
- struct route *route=NULL;
- struct map *route_map=NULL;
- struct map_rect *mr=NULL;
- struct item *item=NULL;
+vehicle_demo_timer(struct vehicle_priv *priv) {
+ struct coord c, c2, pos, ci;
+ int slen, len, dx, dy;
+ struct route *route=NULL;
+ struct map *route_map=NULL;
+ struct map_rect *mr=NULL;
+ struct item *item=NULL;
- len = (priv->config_speed * priv->interval / 1000)/ 3.6;
- dbg(lvl_debug, "###### Entering simulation loop");
- if (!priv->config_speed)
- return;
- if (priv->route)
- route=priv->route;
- else if (priv->navit)
- route=navit_get_route(priv->navit);
- if (route)
- route_map=route_get_map(route);
- if (route_map)
- mr=map_rect_new(route_map, NULL);
- if (mr)
- item=map_rect_get_item(mr);
- if (item && item->type == type_route_start)
- item=map_rect_get_item(mr);
- while(item && item->type!=type_street_route)
- item=map_rect_get_item(mr);
- if (item && item_coord_get(item, &pos, 1)) {
- priv->position_set=0;
- dbg(lvl_debug, "current pos=0x%x,0x%x", pos.x, pos.y);
- dbg(lvl_debug, "last pos=0x%x,0x%x", priv->last.x, priv->last.y);
- if (priv->last.x == pos.x && priv->last.y == pos.y) {
- dbg(lvl_warning, "endless loop");
- }
- priv->last = pos;
- while (item && priv->config_speed) {
- if (!item_coord_get(item, &c, 1)) {
- item=map_rect_get_item(mr);
- continue;
- }
- dbg(lvl_debug, "next pos=0x%x,0x%x", c.x, c.y);
- slen = transform_distance(projection_mg, &pos, &c);
- dbg(lvl_debug, "len=%d slen=%d", len, slen);
- if (slen < len) {
- len -= slen;
- pos = c;
- } else {
- if (item_coord_get(item, &c2, 1) || map_rect_get_item(mr)) {
- dx = c.x - pos.x;
- dy = c.y - pos.y;
- ci.x = pos.x + dx * len / slen;
- ci.y = pos.y + dy * len / slen;
- priv->direction =
- transform_get_angle_delta(&pos, &c, 0);
- priv->speed=priv->config_speed;
- } else {
- ci.x = pos.x;
- ci.y = pos.y;
- priv->speed=0;
- dbg(lvl_debug,"destination reached");
- }
- dbg(lvl_debug, "ci=0x%x,0x%x", ci.x, ci.y);
- transform_to_geo(projection_mg, &ci,
- &priv->geo);
- if (priv->valid != attr_position_valid_valid) {
- priv->valid = attr_position_valid_valid;
- callback_list_call_attr_0(priv->cbl, attr_position_valid);
- }
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- break;
- }
- }
- } else {
- if (priv->position_set)
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
- if (mr)
- map_rect_destroy(mr);
+ len = (priv->config_speed * priv->interval / 1000)/ 3.6;
+ dbg(lvl_debug, "###### Entering simulation loop");
+ if (!priv->config_speed)
+ return;
+ if (priv->route)
+ route=priv->route;
+ else if (priv->navit)
+ route=navit_get_route(priv->navit);
+ if (route)
+ route_map=route_get_map(route);
+ if (route_map)
+ mr=map_rect_new(route_map, NULL);
+ if (mr)
+ item=map_rect_get_item(mr);
+ if (item && item->type == type_route_start)
+ item=map_rect_get_item(mr);
+ while(item && item->type!=type_street_route)
+ item=map_rect_get_item(mr);
+ if (item && item_coord_get(item, &pos, 1)) {
+ priv->position_set=0;
+ dbg(lvl_debug, "current pos=0x%x,0x%x", pos.x, pos.y);
+ dbg(lvl_debug, "last pos=0x%x,0x%x", priv->last.x, priv->last.y);
+ if (priv->last.x == pos.x && priv->last.y == pos.y) {
+ dbg(lvl_warning, "endless loop");
+ }
+ priv->last = pos;
+ while (item && priv->config_speed) {
+ if (!item_coord_get(item, &c, 1)) {
+ item=map_rect_get_item(mr);
+ continue;
+ }
+ dbg(lvl_debug, "next pos=0x%x,0x%x", c.x, c.y);
+ slen = transform_distance(projection_mg, &pos, &c);
+ dbg(lvl_debug, "len=%d slen=%d", len, slen);
+ if (slen < len) {
+ len -= slen;
+ pos = c;
+ } else {
+ if (item_coord_get(item, &c2, 1) || map_rect_get_item(mr)) {
+ dx = c.x - pos.x;
+ dy = c.y - pos.y;
+ ci.x = pos.x + dx * len / slen;
+ ci.y = pos.y + dy * len / slen;
+ priv->direction =
+ transform_get_angle_delta(&pos, &c, 0);
+ priv->speed=priv->config_speed;
+ } else {
+ ci.x = pos.x;
+ ci.y = pos.y;
+ priv->speed=0;
+ dbg(lvl_debug,"destination reached");
+ }
+ dbg(lvl_debug, "ci=0x%x,0x%x", ci.x, ci.y);
+ transform_to_geo(projection_mg, &ci,
+ &priv->geo);
+ if (priv->valid != attr_position_valid_valid) {
+ priv->valid = attr_position_valid_valid;
+ callback_list_call_attr_0(priv->cbl, attr_position_valid);
+ }
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ break;
+ }
+ }
+ } else {
+ if (priv->position_set)
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
+ if (mr)
+ map_rect_destroy(mr);
}
static struct vehicle_priv *
vehicle_demo_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
- dbg(lvl_debug, "enter");
- ret = g_new0(struct vehicle_priv, 1);
- ret->cbl = cbl;
- ret->interval=1000;
- ret->config_speed=40;
- ret->timer_callback=callback_new_1(callback_cast(vehicle_demo_timer), ret);
- ret->valid = attr_position_valid_invalid;
- *meth = vehicle_demo_methods;
- while (attrs && *attrs)
- vehicle_demo_set_attr_do(ret, *attrs++);
- if (!ret->timer)
- ret->timer=event_add_timeout(ret->interval, 1, ret->timer_callback);
- return ret;
+ dbg(lvl_debug, "enter");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ ret->interval=1000;
+ ret->config_speed=40;
+ ret->timer_callback=callback_new_1(callback_cast(vehicle_demo_timer), ret);
+ ret->valid = attr_position_valid_invalid;
+ *meth = vehicle_demo_methods;
+ while (attrs && *attrs)
+ vehicle_demo_set_attr_do(ret, *attrs++);
+ if (!ret->timer)
+ ret->timer=event_add_timeout(ret->interval, 1, ret->timer_callback);
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("demo", vehicle_demo_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("demo", vehicle_demo_new);
}
diff --git a/navit/vehicle/file/vehicle_file.c b/navit/vehicle/file/vehicle_file.c
index 114fd2874..572902553 100644
--- a/navit/vehicle/file/vehicle_file.c
+++ b/navit/vehicle/file/vehicle_file.c
@@ -28,7 +28,7 @@
#include <glib.h>
#include <sys/stat.h>
#ifdef _WIN32
- #include <serial_io.h>
+#include <serial_io.h>
#else
#include <termios.h>
#endif
@@ -51,11 +51,10 @@
#include <winsock2.h>
int inet_aton(const char *cp, struct in_addr *inp);
-int inet_aton(const char *cp, struct in_addr *inp)
-{
- unsigned long addr = inet_addr(cp);
- inp->S_un.S_addr = addr;
- return addr!=-1;
+int inet_aton(const char *cp, struct in_addr *inp) {
+ unsigned long addr = inet_addr(cp);
+ inp->S_un.S_addr = addr;
+ return addr!=-1;
}
#endif
@@ -75,67 +74,67 @@ static void vehicle_file_close(struct vehicle_priv *priv);
enum file_type {
- file_type_pipe = 1, file_type_device, file_type_file, file_type_socket, file_type_serial
+ file_type_pipe = 1, file_type_device, file_type_file, file_type_socket, file_type_serial
};
static int buffer_size = 1024;
struct gps_sat {
- int prn;
- int elevation;
- int azimuth;
- int snr;
+ int prn;
+ int elevation;
+ int azimuth;
+ int snr;
};
struct vehicle_priv {
- char *source;
- struct callback_list *cbl;
- int fd;
- struct callback *cb,*cbt,*cb_fix_timeout;
- char *buffer;
- int buffer_pos;
- char *nmea_data;
- char *nmea_data_buf;
-
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- double hdop;
- double vdop;
- char fixtime[20];
- int fixyear;
- int fixmonth;
- int fixday;
- int status;
- int sats_used;
- int sats_visible;
- int sats_signal;
- int time;
- int on_eof;
+ char *source;
+ struct callback_list *cbl;
+ int fd;
+ struct callback *cb,*cbt,*cb_fix_timeout;
+ char *buffer;
+ int buffer_pos;
+ char *nmea_data;
+ char *nmea_data_buf;
+
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ double hdop;
+ double vdop;
+ char fixtime[20];
+ int fixyear;
+ int fixmonth;
+ int fixday;
+ int status;
+ int sats_used;
+ int sats_visible;
+ int sats_signal;
+ int time;
+ int on_eof;
#ifdef _WIN32
- int no_data_count;
- struct event_timeout * timeout;
- struct callback *timeout_callback;
+ int no_data_count;
+ struct event_timeout * timeout;
+ struct callback *timeout_callback;
#endif
- enum file_type file_type;
- FILE *file;
- struct event_watch *watch;
- struct event_timeout *ev_fix_timeout;
- speed_t baudrate;
- struct attr ** attrs;
- char fixiso8601[128];
- int checksum_ignore;
- int magnetic_direction;
- int current_count;
- struct gps_sat current[24];
- int next_count;
- struct gps_sat next[24];
- struct item sat_item;
- int valid;
- char *statefile;
- int process_statefile;
+ enum file_type file_type;
+ FILE *file;
+ struct event_watch *watch;
+ struct event_timeout *ev_fix_timeout;
+ speed_t baudrate;
+ struct attr ** attrs;
+ char fixiso8601[128];
+ int checksum_ignore;
+ int magnetic_direction;
+ int current_count;
+ struct gps_sat current[24];
+ int next_count;
+ struct gps_sat next[24];
+ struct item sat_item;
+ int valid;
+ char *statefile;
+ int process_statefile;
};
/**
@@ -146,8 +145,7 @@ struct vehicle_priv {
* @return Always 1
*/
#ifdef _WIN32
-static int vehicle_win32_serial_track(struct vehicle_priv *priv)
-{
+static int vehicle_win32_serial_track(struct vehicle_priv *priv) {
static char buffer[2048] = {0,};
static int current_index = 0;
const int chunk_size = 1024;
@@ -156,8 +154,7 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
dbg(lvl_debug, "enter, *priv='%x', priv->source='%s'", priv, priv->source);
- if ( priv->no_data_count > 5 )
- {
+ if ( priv->no_data_count > 5 ) {
vehicle_file_close( priv );
priv->no_data_count = 0;
vehicle_file_open( priv );
@@ -169,21 +166,18 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
// vehicle_file_open( priv );
//}
- if ( current_index >= ( sizeof( buffer ) - chunk_size ) )
- {
+ if ( current_index >= ( sizeof( buffer ) - chunk_size ) ) {
// discard
current_index = 0;
- memset( buffer, 0 , sizeof( buffer ) );
+ memset( buffer, 0, sizeof( buffer ) );
}
dwBytes = serial_io_read( priv->fd, &buffer[ current_index ], chunk_size );
- if ( dwBytes > 0 )
- {
+ if ( dwBytes > 0 ) {
char* return_pos = NULL;
current_index += dwBytes;
- while ( ( return_pos = strchr( buffer, '\n' ) ) != NULL )
- {
+ while ( ( return_pos = strchr( buffer, '\n' ) ) != NULL ) {
char return_buffer[1024];
int bytes_to_copy = return_pos - buffer + 1;
memcpy( return_buffer, buffer, bytes_to_copy );
@@ -194,7 +188,7 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
rc += vehicle_file_parse( priv, return_buffer );
current_index -= bytes_to_copy;
- memmove( buffer, &buffer[ bytes_to_copy ] , sizeof( buffer ) - bytes_to_copy );
+ memmove( buffer, &buffer[ bytes_to_copy ], sizeof( buffer ) - bytes_to_copy );
}
if (rc) {
priv->no_data_count = 0;
@@ -203,9 +197,7 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
dbg(lvl_error, "Can not keep with gps data delay is %d seconds", rc - 1);
}
- }
- else
- {
+ } else {
priv->no_data_count++;
}
dbg(lvl_info, "leave, return '1', priv->no_data_count='%d'", priv->no_data_count);
@@ -221,104 +213,102 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
* @return 1 if ok, 0 if error
*/
static int
-vehicle_file_open(struct vehicle_priv *priv)
-{
- char *name;
+vehicle_file_open(struct vehicle_priv *priv) {
+ char *name;
#ifndef _WIN32
- struct termios tio;
+ struct termios tio;
#else
- #define O_NDELAY 0
+#define O_NDELAY 0
#endif
- name = priv->source + 5;
- if (!strncmp(priv->source, "file:", 5)) {
- priv->fd = open(name, O_RDONLY | O_NDELAY);
- if (priv->fd < 0)
- return 0;
- if (file_is_reg(name)) {
- priv->file_type = file_type_file;
- }
+ name = priv->source + 5;
+ if (!strncmp(priv->source, "file:", 5)) {
+ priv->fd = open(name, O_RDONLY | O_NDELAY);
+ if (priv->fd < 0)
+ return 0;
+ if (file_is_reg(name)) {
+ priv->file_type = file_type_file;
+ }
#ifndef _WIN32
- else {
- tcgetattr(priv->fd, &tio);
- cfmakeraw(&tio);
- cfsetispeed(&tio, priv->baudrate);
- cfsetospeed(&tio, priv->baudrate);
- tio.c_cc[VMIN] = 0;
- tio.c_cc[VTIME] = 200;
- tcsetattr(priv->fd, TCSANOW, &tio);
- priv->file_type = file_type_device;
- }
- } else if (!strncmp(priv->source,"pipe:", 5)) {
- priv->file = popen(name, "r");
- if (!priv->file)
- return 0;
- priv->fd = fileno(priv->file);
- priv->file_type = file_type_pipe;
+ else {
+ tcgetattr(priv->fd, &tio);
+ cfmakeraw(&tio);
+ cfsetispeed(&tio, priv->baudrate);
+ cfsetospeed(&tio, priv->baudrate);
+ tio.c_cc[VMIN] = 0;
+ tio.c_cc[VTIME] = 200;
+ tcsetattr(priv->fd, TCSANOW, &tio);
+ priv->file_type = file_type_device;
+ }
+ } else if (!strncmp(priv->source,"pipe:", 5)) {
+ priv->file = popen(name, "r");
+ if (!priv->file)
+ return 0;
+ priv->fd = fileno(priv->file);
+ priv->file_type = file_type_pipe;
#endif //!_WIN32
-#if defined(HAVE_SOCKET) || defined(HAVE_WINSOCK)
- } else if (!strncmp(priv->source,"socket:", 7)) {
- #ifdef _WIN32
- WSADATA wsi;
- WSAStartup(0x00020002,&wsi);
- #endif
- char *p,*s=g_strdup(priv->source+7);
- struct sockaddr_in sin;
- p=strchr(s,':');
- if (!p) {
- dbg(lvl_error,"port number missing in %s",s);
- g_free(s);
- return 0;
- }
- *p++='\0';
- sin.sin_family=AF_INET;
- sin.sin_port=ntohs(atoi(p));
- if (!inet_aton(s, &sin.sin_addr)) {
- dbg(lvl_error,"failed to parse %s",s);
- g_free(s);
- return 0;
- }
- priv->fd = socket(PF_INET, SOCK_STREAM, 0);
- if (priv->fd != -1) {
- if (connect(priv->fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- dbg(lvl_error,"failed to connect to %s:%s",s,p);
- g_free(s);
- return 0;
- }
- }
- p=strchr(p,':');
- if (p) {
- p++;
- int write_result;
- write_result = write(priv->fd, p, strlen(p));
- if (write_result == -1){
- dbg(lvl_warning, "write failed.");
- }
- }
- priv->file_type = file_type_socket;
+#if defined(HAVE_SOCKET) || defined(HAVE_WINSOCK)
+ } else if (!strncmp(priv->source,"socket:", 7)) {
+#ifdef _WIN32
+ WSADATA wsi;
+ WSAStartup(0x00020002,&wsi);
+#endif
+ char *p,*s=g_strdup(priv->source+7);
+ struct sockaddr_in sin;
+ p=strchr(s,':');
+ if (!p) {
+ dbg(lvl_error,"port number missing in %s",s);
+ g_free(s);
+ return 0;
+ }
+ *p++='\0';
+ sin.sin_family=AF_INET;
+ sin.sin_port=ntohs(atoi(p));
+ if (!inet_aton(s, &sin.sin_addr)) {
+ dbg(lvl_error,"failed to parse %s",s);
+ g_free(s);
+ return 0;
+ }
+ priv->fd = socket(PF_INET, SOCK_STREAM, 0);
+ if (priv->fd != -1) {
+ if (connect(priv->fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+ dbg(lvl_error,"failed to connect to %s:%s",s,p);
+ g_free(s);
+ return 0;
+ }
+ }
+ p=strchr(p,':');
+ if (p) {
+ p++;
+ int write_result;
+ write_result = write(priv->fd, p, strlen(p));
+ if (write_result == -1) {
+ dbg(lvl_warning, "write failed.");
+ }
+ }
+ priv->file_type = file_type_socket;
#endif //HAVE_SOCKET
- } else if (!strncmp(priv->source,"serial:",7)) {
+ } else if (!strncmp(priv->source,"serial:",7)) {
#ifdef _WIN32
- char* raw_setting_str = g_strdup( priv->source );
-
- char* strport = strchr(raw_setting_str, ':' );
- char* strsettings = strchr(raw_setting_str, ' ' );
-
- if ( strport && strsettings )
- {
- strport++;
- *strsettings = '\0';
- strsettings++;
-
- priv->fd=serial_io_init( strport, strsettings );
- }
- g_free( raw_setting_str );
- priv->file_type = file_type_serial;
- // Add the callback
- dbg(lvl_info, "Add the callback ...", priv->source);
- priv->timeout_callback=callback_new_1(callback_cast(vehicle_win32_serial_track), priv);
+ char* raw_setting_str = g_strdup( priv->source );
+
+ char* strport = strchr(raw_setting_str, ':' );
+ char* strsettings = strchr(raw_setting_str, ' ' );
+
+ if ( strport && strsettings ) {
+ strport++;
+ *strsettings = '\0';
+ strsettings++;
+
+ priv->fd=serial_io_init( strport, strsettings );
+ }
+ g_free( raw_setting_str );
+ priv->file_type = file_type_serial;
+ // Add the callback
+ dbg(lvl_info, "Add the callback ...", priv->source);
+ priv->timeout_callback=callback_new_1(callback_cast(vehicle_win32_serial_track), priv);
#else
- //TODO - add linux serial
+ //TODO - add linux serial
#endif //!_WIN32
}
return(priv->fd != -1);
@@ -330,32 +320,28 @@ vehicle_file_open(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_close(struct vehicle_priv *priv)
-{
+vehicle_file_close(struct vehicle_priv *priv) {
dbg(lvl_debug, "enter, priv->fd='%d'", priv->fd);
- vehicle_file_disable_watch(priv);
+ vehicle_file_disable_watch(priv);
#ifdef _WIN32
- if(priv->file_type == file_type_serial)
- {
+ if(priv->file_type == file_type_serial) {
if (priv->timeout_callback) {
- callback_destroy(priv->timeout_callback);
- priv->timeout_callback=NULL; // dangling pointer! prevent double freeing.
+ callback_destroy(priv->timeout_callback);
+ priv->timeout_callback=NULL; // dangling pointer! prevent double freeing.
}
- serial_io_shutdown( priv->fd );
- }
- else
+ serial_io_shutdown( priv->fd );
+ } else
#endif
{
- if (priv->file) {
+ if (priv->file) {
#ifndef _MSC_VER
- pclose(priv->file);
+ pclose(priv->file);
#endif /* _MSC_VER */
- }
- else if (priv->fd >= 0) {
- close(priv->fd);
- }
- priv->file = NULL;
- priv->fd = -1;
+ } else if (priv->fd >= 0) {
+ close(priv->fd);
+ }
+ priv->file = NULL;
+ priv->fd = -1;
}
}
@@ -367,12 +353,11 @@ vehicle_file_close(struct vehicle_priv *priv)
* @return Always 0
*/
static int
-vehicle_file_enable_watch_timer(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "enter");
- vehicle_file_enable_watch(priv);
+vehicle_file_enable_watch_timer(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "enter");
+ vehicle_file_enable_watch(priv);
- return FALSE;
+ return FALSE;
}
@@ -383,11 +368,10 @@ vehicle_file_enable_watch_timer(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_fix_timeout_cb(struct vehicle_priv *priv)
-{
- priv->valid = attr_position_valid_invalid;
- priv->ev_fix_timeout = NULL;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_file_fix_timeout_cb(struct vehicle_priv *priv) {
+ priv->valid = attr_position_valid_invalid;
+ priv->ev_fix_timeout = NULL;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
@@ -397,11 +381,10 @@ vehicle_file_fix_timeout_cb(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_restart_fix_timeout(struct vehicle_priv *priv)
-{
- if (priv->ev_fix_timeout != NULL)
- event_remove_timeout(priv->ev_fix_timeout);
- priv->ev_fix_timeout = event_add_timeout(10000, 0, priv->cb_fix_timeout);
+vehicle_file_restart_fix_timeout(struct vehicle_priv *priv) {
+ if (priv->ev_fix_timeout != NULL)
+ event_remove_timeout(priv->ev_fix_timeout);
+ priv->ev_fix_timeout = event_add_timeout(10000, 0, priv->cb_fix_timeout);
}
@@ -415,267 +398,267 @@ vehicle_file_restart_fix_timeout(struct vehicle_priv *priv)
* 0 if not found
*/
static int
-vehicle_file_parse(struct vehicle_priv *priv, char *buffer)
-{
- char *nmea_data_buf, *p, *item[32];
- double lat, lng;
- int i, j, bcsum;
- int len = strlen(buffer);
- unsigned char csum = 0;
- int valid=0;
- int ret = 0;
-
- dbg(lvl_info, "enter: buffer='%s'", buffer);
- for (;;) {
- if (len < 4) {
- dbg(lvl_error, "'%s' too short", buffer);
- return ret;
- }
- if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
- buffer[--len] = '\0';
+vehicle_file_parse(struct vehicle_priv *priv, char *buffer) {
+ char *nmea_data_buf, *p, *item[32];
+ double lat, lng;
+ int i, j, bcsum;
+ int len = strlen(buffer);
+ unsigned char csum = 0;
+ int valid=0;
+ int ret = 0;
+
+ dbg(lvl_info, "enter: buffer='%s'", buffer);
+ for (;;) {
+ if (len < 4) {
+ dbg(lvl_error, "'%s' too short", buffer);
+ return ret;
+ }
+ if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
+ buffer[--len] = '\0';
if (buffer[len - 1] == '\r')
buffer[--len] = '\0';
} else
- break;
- }
- if (buffer[0] != '$') {
- dbg(lvl_error, "no leading $ in '%s'", buffer);
- return ret;
- }
- if (buffer[len - 3] != '*') {
- dbg(lvl_error, "no *XX in '%s'", buffer);
- return ret;
- }
- for (i = 1; i < len - 3; i++) {
- csum ^= (unsigned char) (buffer[i]);
- }
- if (!sscanf(buffer + len - 2, "%x", &bcsum) && priv->checksum_ignore != 2) {
- dbg(lvl_error, "no checksum in '%s'", buffer);
- return ret;
- }
- if (bcsum != csum && priv->checksum_ignore == 0) {
- dbg(lvl_error, "wrong checksum in '%s was %x should be %x'", buffer,bcsum,csum);
- return ret;
- }
-
- if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
- nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
- g_free(priv->nmea_data_buf);
- priv->nmea_data_buf=nmea_data_buf;
- } else {
- dbg(lvl_error, "nmea buffer overflow (len %zu), discarding '%s'", priv->nmea_data_buf?strlen(priv->nmea_data_buf):-1,buffer);
- }
- i = 0;
- p = buffer;
- while (i < 31) {
- item[i++] = p;
- while (*p && *p != ',')
- p++;
- if (!*p)
- break;
- *p++ = '\0';
- }
-
- if (!strncmp(&buffer[3], "GGA", 3)) {
- /* 1 1111
- 0 1 2 3 4 5 6 7 8 9 0 1234
- $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
- UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
- HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
- */
- if (*item[2] && *item[3] && *item[4] && *item[5] && *item[6] > 0) {
- lat = g_ascii_strtod(item[2], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_ascii_strcasecmp(item[3],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[4], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_ascii_strcasecmp(item[5],"W"))
- priv->geo.lng=-priv->geo.lng;
-
- if (priv->valid == attr_position_valid_invalid)
- ret = 1;
- priv->valid = attr_position_valid_valid;
- vehicle_file_restart_fix_timeout(priv);
-
- if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
- ret = 1;
- strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
- }
-
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else {
- if (priv->valid == attr_position_valid_valid)
- ret = 1;
- priv->valid=attr_position_valid_invalid;
- }
-
- if (*item[6])
- sscanf(item[6], "%d", &priv->status);
- if (*item[7])
- sscanf(item[7], "%d", &priv->sats_used);
- if (*item[8])
- sscanf(item[8], "%lf", &priv->hdop);
- if (*item[9])
- sscanf(item[9], "%lf", &priv->height);
-
- g_free(priv->nmea_data);
- priv->nmea_data=priv->nmea_data_buf;
- priv->nmea_data_buf=NULL;
- if (priv->file_type == file_type_file) {
- if (priv->watch) {
- vehicle_file_disable_watch(priv);
- event_add_timeout(priv->time, 0, priv->cbt);
- }
- }
- }
- if (!strncmp(&buffer[3], "VTG", 3)) {
- /* 0 1 2 34 5 6 7 8
- $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
- Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
- Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
- */
- if (item[1] && item[7])
- valid = 1;
- if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
- valid = 1;
- if (valid) {
- priv->direction = g_ascii_strtod( item[1], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- dbg(lvl_info,"direction %lf, speed %2.1lf", priv->direction, priv->speed);
- }
- }
- if (!strncmp(&buffer[3], "RMC", 3)) {
- /* 1 1
- 0 1 2 3 4 5 6 7 8 9 0 1
- $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
- Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
- magnetic variation[10],magnetic variation direction[11]
- */
- if (*item[2] == 'A')
- valid = 1;
- if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
- valid = 1;
- if (valid) {
- priv->direction = g_ascii_strtod( item[8], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- priv->speed *= 1.852;
- sscanf(item[9], "%02d%02d%02d",
- &priv->fixday,
- &priv->fixmonth,
- &priv->fixyear);
- priv->fixyear += 2000;
-
- lat = g_ascii_strtod(item[3], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_ascii_strcasecmp(item[4],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[5], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_ascii_strcasecmp(item[6],"W"))
- priv->geo.lng=-priv->geo.lng;
-
- if (priv->valid == attr_position_valid_invalid)
- ret = 1;
- priv->valid=attr_position_valid_valid;
- vehicle_file_restart_fix_timeout(priv);
-
- if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
- ret = 1;
- strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
- }
-
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else {
- if (priv->valid == attr_position_valid_valid)
- ret = 1;
- priv->valid=attr_position_valid_invalid;
- }
- }
- if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
- /*
- 0 GSV Satellites in view
- 1 2 Number of sentences for full data
- 2 1 sentence 1 of 2
- 3 08 Number of satellites in view
-
- 4 01 Satellite PRN number
- 5 40 Elevation, degrees
- 6 083 Azimuth, degrees
- 7 46 SNR - higher is better
- for up to 4 satellites per sentence
- *75 the checksum data, always begins with *
- */
- if (item[3]) {
- sscanf(item[3], "%d", &priv->sats_visible);
- }
- j=4;
- while (j+4 <= i && priv->current_count < 24) {
- struct gps_sat *sat=&priv->next[priv->next_count++];
- sat->prn=atoi(item[j]);
- sat->elevation=atoi(item[j+1]);
- sat->azimuth=atoi(item[j+2]);
- sat->snr=atoi(item[j+3]);
- j+=4;
- }
- if (!strcmp(item[1], item[2])) {
- priv->sats_signal=0;
- for (i = 0 ; i < priv->next_count ; i++) {
- priv->current[i]=priv->next[i];
- if (priv->current[i].snr)
- priv->sats_signal++;
- }
- priv->current_count=priv->next_count;
- priv->next_count=0;
- }
- }
- if (!strncmp(&buffer[3], "ZDA", 3)) {
- /*
- 0 1 2 3 4 5 6
- $GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
- hhmmss HrMinSec(UTC)
- dd,mm,yyy Day,Month,Year
- xx local zone hours -13..13
- yy local zone minutes 0..59
- */
- if (item[1] && item[2] && item[3] && item[4]) {
- strncpy(priv->fixtime, item[1], strlen(priv->fixtime));
- priv->fixday = atoi(item[2]);
- priv->fixmonth = atoi(item[3]);
- priv->fixyear = atoi(item[4]);
- }
- }
- if (!strncmp(buffer, "$IISMD", 6)) {
- /*
- 0 1 2 3 4
- $IISMD,dir,press,height,temp*CC"
- dir Direction (0-359)
- press Pressure (hpa, i.e. 1032)
- height Barometric height above ground (meter)
- temp Temperature (Degree Celsius)
- */
- if (item[1]) {
- priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
- dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
- }
- }
- return ret;
+ break;
+ }
+ if (buffer[0] != '$') {
+ dbg(lvl_error, "no leading $ in '%s'", buffer);
+ return ret;
+ }
+ if (buffer[len - 3] != '*') {
+ dbg(lvl_error, "no *XX in '%s'", buffer);
+ return ret;
+ }
+ for (i = 1; i < len - 3; i++) {
+ csum ^= (unsigned char) (buffer[i]);
+ }
+ if (!sscanf(buffer + len - 2, "%x", &bcsum) && priv->checksum_ignore != 2) {
+ dbg(lvl_error, "no checksum in '%s'", buffer);
+ return ret;
+ }
+ if (bcsum != csum && priv->checksum_ignore == 0) {
+ dbg(lvl_error, "wrong checksum in '%s was %x should be %x'", buffer,bcsum,csum);
+ return ret;
+ }
+
+ if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
+ nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
+ g_free(priv->nmea_data_buf);
+ priv->nmea_data_buf=nmea_data_buf;
+ } else {
+ dbg(lvl_error, "nmea buffer overflow (len %zu), discarding '%s'", priv->nmea_data_buf?strlen(priv->nmea_data_buf):-1,
+ buffer);
+ }
+ i = 0;
+ p = buffer;
+ while (i < 31) {
+ item[i++] = p;
+ while (*p && *p != ',')
+ p++;
+ if (!*p)
+ break;
+ *p++ = '\0';
+ }
+
+ if (!strncmp(&buffer[3], "GGA", 3)) {
+ /* 1 1111
+ 0 1 2 3 4 5 6 7 8 9 0 1234
+ $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
+ UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
+ HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
+ */
+ if (*item[2] && *item[3] && *item[4] && *item[5] && *item[6] > 0) {
+ lat = g_ascii_strtod(item[2], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_ascii_strcasecmp(item[3],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[4], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_ascii_strcasecmp(item[5],"W"))
+ priv->geo.lng=-priv->geo.lng;
+
+ if (priv->valid == attr_position_valid_invalid)
+ ret = 1;
+ priv->valid = attr_position_valid_valid;
+ vehicle_file_restart_fix_timeout(priv);
+
+ if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
+ ret = 1;
+ strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
+ }
+
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else {
+ if (priv->valid == attr_position_valid_valid)
+ ret = 1;
+ priv->valid=attr_position_valid_invalid;
+ }
+
+ if (*item[6])
+ sscanf(item[6], "%d", &priv->status);
+ if (*item[7])
+ sscanf(item[7], "%d", &priv->sats_used);
+ if (*item[8])
+ sscanf(item[8], "%lf", &priv->hdop);
+ if (*item[9])
+ sscanf(item[9], "%lf", &priv->height);
+
+ g_free(priv->nmea_data);
+ priv->nmea_data=priv->nmea_data_buf;
+ priv->nmea_data_buf=NULL;
+ if (priv->file_type == file_type_file) {
+ if (priv->watch) {
+ vehicle_file_disable_watch(priv);
+ event_add_timeout(priv->time, 0, priv->cbt);
+ }
+ }
+ }
+ if (!strncmp(&buffer[3], "VTG", 3)) {
+ /* 0 1 2 34 5 6 7 8
+ $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
+ Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
+ Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
+ */
+ if (item[1] && item[7])
+ valid = 1;
+ if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->direction = g_ascii_strtod( item[1], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ dbg(lvl_info,"direction %lf, speed %2.1lf", priv->direction, priv->speed);
+ }
+ }
+ if (!strncmp(&buffer[3], "RMC", 3)) {
+ /* 1 1
+ 0 1 2 3 4 5 6 7 8 9 0 1
+ $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
+ Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
+ magnetic variation[10],magnetic variation direction[11]
+ */
+ if (*item[2] == 'A')
+ valid = 1;
+ if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->direction = g_ascii_strtod( item[8], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ priv->speed *= 1.852;
+ sscanf(item[9], "%02d%02d%02d",
+ &priv->fixday,
+ &priv->fixmonth,
+ &priv->fixyear);
+ priv->fixyear += 2000;
+
+ lat = g_ascii_strtod(item[3], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_ascii_strcasecmp(item[4],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[5], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_ascii_strcasecmp(item[6],"W"))
+ priv->geo.lng=-priv->geo.lng;
+
+ if (priv->valid == attr_position_valid_invalid)
+ ret = 1;
+ priv->valid=attr_position_valid_valid;
+ vehicle_file_restart_fix_timeout(priv);
+
+ if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
+ ret = 1;
+ strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
+ }
+
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else {
+ if (priv->valid == attr_position_valid_valid)
+ ret = 1;
+ priv->valid=attr_position_valid_invalid;
+ }
+ }
+ if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
+ /*
+ 0 GSV Satellites in view
+ 1 2 Number of sentences for full data
+ 2 1 sentence 1 of 2
+ 3 08 Number of satellites in view
+
+ 4 01 Satellite PRN number
+ 5 40 Elevation, degrees
+ 6 083 Azimuth, degrees
+ 7 46 SNR - higher is better
+ for up to 4 satellites per sentence
+ *75 the checksum data, always begins with *
+ */
+ if (item[3]) {
+ sscanf(item[3], "%d", &priv->sats_visible);
+ }
+ j=4;
+ while (j+4 <= i && priv->current_count < 24) {
+ struct gps_sat *sat=&priv->next[priv->next_count++];
+ sat->prn=atoi(item[j]);
+ sat->elevation=atoi(item[j+1]);
+ sat->azimuth=atoi(item[j+2]);
+ sat->snr=atoi(item[j+3]);
+ j+=4;
+ }
+ if (!strcmp(item[1], item[2])) {
+ priv->sats_signal=0;
+ for (i = 0 ; i < priv->next_count ; i++) {
+ priv->current[i]=priv->next[i];
+ if (priv->current[i].snr)
+ priv->sats_signal++;
+ }
+ priv->current_count=priv->next_count;
+ priv->next_count=0;
+ }
+ }
+ if (!strncmp(&buffer[3], "ZDA", 3)) {
+ /*
+ 0 1 2 3 4 5 6
+ $GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
+ hhmmss HrMinSec(UTC)
+ dd,mm,yyy Day,Month,Year
+ xx local zone hours -13..13
+ yy local zone minutes 0..59
+ */
+ if (item[1] && item[2] && item[3] && item[4]) {
+ strncpy(priv->fixtime, item[1], strlen(priv->fixtime));
+ priv->fixday = atoi(item[2]);
+ priv->fixmonth = atoi(item[3]);
+ priv->fixyear = atoi(item[4]);
+ }
+ }
+ if (!strncmp(buffer, "$IISMD", 6)) {
+ /*
+ 0 1 2 3 4
+ $IISMD,dir,press,height,temp*CC"
+ dir Direction (0-359)
+ press Pressure (hpa, i.e. 1032)
+ height Barometric height above ground (meter)
+ temp Temperature (Degree Celsius)
+ */
+ if (item[1]) {
+ priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
+ dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
+ }
+ }
+ return ret;
}
/**
@@ -684,68 +667,67 @@ vehicle_file_parse(struct vehicle_priv *priv, char *buffer)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_io(struct vehicle_priv *priv)
-{
- int size, rc = 0;
- char *str, *tok;
+vehicle_file_io(struct vehicle_priv *priv) {
+ int size, rc = 0;
+ char *str, *tok;
dbg(lvl_debug, "vehicle_file_io : enter");
- if (priv->process_statefile) {
- unsigned char *data;
- priv->process_statefile=0;
- if (file_get_contents(priv->statefile, &data, &size)) {
- if (size > buffer_size)
- size=buffer_size;
- memcpy(priv->buffer, data, size);
- priv->buffer_pos=0;
- g_free(data);
- } else
- return;
- } else {
- size = read(priv->fd, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1);
- }
- if (size <= 0) {
- switch (priv->on_eof) {
- case 0:
- vehicle_file_close(priv);
- vehicle_file_open(priv);
- break;
- case 1:
- vehicle_file_disable_watch(priv);
- break;
- case 2:
- exit(0);
- break;
- }
- return;
- }
- priv->buffer_pos += size;
- priv->buffer[priv->buffer_pos] = '\0';
- dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
- priv->buffer_pos, priv->buffer);
- str = priv->buffer;
- while ((tok = strchr(str, '\n'))) {
- *tok++ = '\0';
- dbg(lvl_debug, "line='%s'", str);
- rc +=vehicle_file_parse(priv, str);
- str = tok;
- if (priv->file_type == file_type_file && rc)
- break;
- }
-
- if (str != priv->buffer) {
- size = priv->buffer + priv->buffer_pos - str;
- memmove(priv->buffer, str, size + 1);
- priv->buffer_pos = size;
- dbg(lvl_debug, "now pos=%d buffer='%s'",
- priv->buffer_pos, priv->buffer);
- } else if (priv->buffer_pos == buffer_size - 1) {
- dbg(lvl_debug,
- "Overflow. Most likely wrong baud rate or no nmea protocol");
- priv->buffer_pos = 0;
- }
- if (rc)
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ if (priv->process_statefile) {
+ unsigned char *data;
+ priv->process_statefile=0;
+ if (file_get_contents(priv->statefile, &data, &size)) {
+ if (size > buffer_size)
+ size=buffer_size;
+ memcpy(priv->buffer, data, size);
+ priv->buffer_pos=0;
+ g_free(data);
+ } else
+ return;
+ } else {
+ size = read(priv->fd, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1);
+ }
+ if (size <= 0) {
+ switch (priv->on_eof) {
+ case 0:
+ vehicle_file_close(priv);
+ vehicle_file_open(priv);
+ break;
+ case 1:
+ vehicle_file_disable_watch(priv);
+ break;
+ case 2:
+ exit(0);
+ break;
+ }
+ return;
+ }
+ priv->buffer_pos += size;
+ priv->buffer[priv->buffer_pos] = '\0';
+ dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
+ priv->buffer_pos, priv->buffer);
+ str = priv->buffer;
+ while ((tok = strchr(str, '\n'))) {
+ *tok++ = '\0';
+ dbg(lvl_debug, "line='%s'", str);
+ rc +=vehicle_file_parse(priv, str);
+ str = tok;
+ if (priv->file_type == file_type_file && rc)
+ break;
+ }
+
+ if (str != priv->buffer) {
+ size = priv->buffer + priv->buffer_pos - str;
+ memmove(priv->buffer, str, size + 1);
+ priv->buffer_pos = size;
+ dbg(lvl_debug, "now pos=%d buffer='%s'",
+ priv->buffer_pos, priv->buffer);
+ } else if (priv->buffer_pos == buffer_size - 1) {
+ dbg(lvl_debug,
+ "Overflow. Most likely wrong baud rate or no nmea protocol");
+ priv->buffer_pos = 0;
+ }
+ if (rc)
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
/**
@@ -754,22 +736,20 @@ vehicle_file_io(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_enable_watch(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "enter");
+vehicle_file_enable_watch(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "enter");
#ifdef _WIN32
- // add an event : don't use glib timers and g_timeout_add
- if (priv->file_type == file_type_serial)
- {
- if (priv->timeout_callback != NULL)
+ // add an event : don't use glib timers and g_timeout_add
+ if (priv->file_type == file_type_serial) {
+ if (priv->timeout_callback != NULL)
priv->timeout = event_add_timeout(500, 1, priv->timeout_callback);
else
- dbg(lvl_warning, "error : watch not enabled : priv->timeout_callback is null"); }
- else
+ dbg(lvl_warning, "error : watch not enabled : priv->timeout_callback is null");
+ } else
#endif
{
- if (! priv->watch)
- priv->watch = event_add_watch(priv->fd, event_watch_cond_read, priv->cb);
+ if (! priv->watch)
+ priv->watch = event_add_watch(priv->fd, event_watch_cond_read, priv->cb);
}
}
@@ -779,23 +759,20 @@ vehicle_file_enable_watch(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_disable_watch(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "vehicle_file_disable_watch : enter");
+vehicle_file_disable_watch(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "vehicle_file_disable_watch : enter");
#ifdef _WIN32
- if(priv->file_type == file_type_serial)
- {
- if (priv->timeout) {
- event_remove_timeout(priv->timeout);
- priv->timeout=NULL; // dangling pointer! prevent double freeing.
+ if(priv->file_type == file_type_serial) {
+ if (priv->timeout) {
+ event_remove_timeout(priv->timeout);
+ priv->timeout=NULL; // dangling pointer! prevent double freeing.
}
- }
- else
+ } else
#endif //!_WIN32
{
- if (priv->watch)
- event_remove_watch(priv->watch);
- priv->watch = NULL;
+ if (priv->watch)
+ event_remove_watch(priv->watch);
+ priv->watch = NULL;
}
}
@@ -807,32 +784,31 @@ vehicle_file_disable_watch(struct vehicle_priv *priv)
* @remarks private data is freed by this function (g_free)
*/
static void
-vehicle_file_destroy(struct vehicle_priv *priv)
-{
- if (priv->statefile && priv->nmea_data) {
- struct attr readwrite={attr_readwrite};
- struct attr create={attr_create};
- struct attr *attrs[]={&readwrite,&create,NULL};
- struct file *f;
- readwrite.u.num=1;
- create.u.num=1;
- f=file_create(priv->statefile, attrs);
- if (f) {
- file_data_write(f, 0, strlen(priv->nmea_data), priv->nmea_data);
- file_fsync(f);
- file_destroy(f);
- }
- }
- vehicle_file_close(priv);
- callback_destroy(priv->cb);
- callback_destroy(priv->cbt);
- if (priv->statefile)
- g_free(priv->statefile);
- if (priv->source)
- g_free(priv->source);
- if (priv->buffer)
- g_free(priv->buffer);
- g_free(priv);
+vehicle_file_destroy(struct vehicle_priv *priv) {
+ if (priv->statefile && priv->nmea_data) {
+ struct attr readwrite= {attr_readwrite};
+ struct attr create= {attr_create};
+ struct attr *attrs[]= {&readwrite,&create,NULL};
+ struct file *f;
+ readwrite.u.num=1;
+ create.u.num=1;
+ f=file_create(priv->statefile, attrs);
+ if (f) {
+ file_data_write(f, 0, strlen(priv->nmea_data), priv->nmea_data);
+ file_fsync(f);
+ file_destroy(f);
+ }
+ }
+ vehicle_file_close(priv);
+ callback_destroy(priv->cb);
+ callback_destroy(priv->cbt);
+ if (priv->statefile)
+ g_free(priv->statefile);
+ if (priv->source)
+ g_free(priv->source);
+ if (priv->buffer)
+ g_free(priv->buffer);
+ g_free(priv);
}
/**
@@ -846,71 +822,70 @@ vehicle_file_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_file_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->status;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_magnetic_direction:
- attr->u.num = priv->magnetic_direction;
- break;
- case attr_position_hdop:
- attr->u.numd = &priv->hdop;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats_visible;
- break;
- case attr_position_sats_signal:
- attr->u.num = priv->sats_signal;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_nmea:
- attr->u.str=priv->nmea_data;
- if (! attr->u.str)
- return 0;
- break;
- case attr_position_time_iso8601:
- if (!priv->fixyear || !priv->fixtime[0])
- return 0;
- sprintf(priv->fixiso8601, "%04d-%02d-%02dT%.2s:%.2s:%sZ",
- priv->fixyear, priv->fixmonth, priv->fixday,
- priv->fixtime, (priv->fixtime+2), (priv->fixtime+4));
- attr->u.str=priv->fixiso8601;
- break;
- case attr_position_sat_item:
- dbg(lvl_debug,"at here");
- priv->sat_item.id_lo++;
- if (priv->sat_item.id_lo > priv->current_count) {
- priv->sat_item.id_lo=0;
- return 0;
- }
- attr->u.item=&priv->sat_item;
- break;
- case attr_position_valid:
- attr->u.num=priv->valid;
- break;
- default:
- return 0;
- }
- if (type != attr_position_sat_item)
- priv->sat_item.id_lo=0;
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->status;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_magnetic_direction:
+ attr->u.num = priv->magnetic_direction;
+ break;
+ case attr_position_hdop:
+ attr->u.numd = &priv->hdop;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats_visible;
+ break;
+ case attr_position_sats_signal:
+ attr->u.num = priv->sats_signal;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_nmea:
+ attr->u.str=priv->nmea_data;
+ if (! attr->u.str)
+ return 0;
+ break;
+ case attr_position_time_iso8601:
+ if (!priv->fixyear || !priv->fixtime[0])
+ return 0;
+ sprintf(priv->fixiso8601, "%04d-%02d-%02dT%.2s:%.2s:%sZ",
+ priv->fixyear, priv->fixmonth, priv->fixday,
+ priv->fixtime, (priv->fixtime+2), (priv->fixtime+4));
+ attr->u.str=priv->fixiso8601;
+ break;
+ case attr_position_sat_item:
+ dbg(lvl_debug,"at here");
+ priv->sat_item.id_lo++;
+ if (priv->sat_item.id_lo > priv->current_count) {
+ priv->sat_item.id_lo=0;
+ return 0;
+ }
+ attr->u.item=&priv->sat_item;
+ break;
+ case attr_position_valid:
+ attr->u.num=priv->valid;
+ break;
+ default:
+ return 0;
+ }
+ if (type != attr_position_sat_item)
+ priv->sat_item.id_lo=0;
+ attr->type = type;
+ return 1;
}
/**
@@ -923,45 +898,44 @@ vehicle_file_position_attr_get(struct vehicle_priv *priv,
* @return 1 if ok, 0 for unknown attribute
*/
static int
-vehicle_file_sat_attr_get(void *priv_data, enum attr_type type, struct attr *attr)
-{
+vehicle_file_sat_attr_get(void *priv_data, enum attr_type type, struct attr *attr) {
struct gps_sat *sat;
- struct vehicle_priv *priv=priv_data;
- if (priv->sat_item.id_lo < 1)
- return 0;
- if (priv->sat_item.id_lo > priv->current_count)
- return 0;
- sat=&priv->current[priv->sat_item.id_lo-1];
- switch (type) {
- case attr_sat_prn:
- attr->u.num=sat->prn;
- break;
- case attr_sat_elevation:
- attr->u.num=sat->elevation;
- break;
- case attr_sat_azimuth:
- attr->u.num=sat->azimuth;
- break;
- case attr_sat_snr:
- attr->u.num=sat->snr;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ struct vehicle_priv *priv=priv_data;
+ if (priv->sat_item.id_lo < 1)
+ return 0;
+ if (priv->sat_item.id_lo > priv->current_count)
+ return 0;
+ sat=&priv->current[priv->sat_item.id_lo-1];
+ switch (type) {
+ case attr_sat_prn:
+ attr->u.num=sat->prn;
+ break;
+ case attr_sat_elevation:
+ attr->u.num=sat->elevation;
+ break;
+ case attr_sat_azimuth:
+ attr->u.num=sat->azimuth;
+ break;
+ case attr_sat_snr:
+ attr->u.num=sat->snr;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static struct item_methods vehicle_file_sat_methods = {
- NULL,
- NULL,
- NULL,
- vehicle_file_sat_attr_get,
+ NULL,
+ NULL,
+ NULL,
+ vehicle_file_sat_attr_get,
};
static struct vehicle_methods vehicle_file_methods = {
- vehicle_file_destroy,
- vehicle_file_position_attr_get,
+ vehicle_file_destroy,
+ vehicle_file_position_attr_get,
};
/**
@@ -977,114 +951,112 @@ static struct vehicle_methods vehicle_file_methods = {
*/
static struct vehicle_priv *
vehicle_file_new_file(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source;
- struct attr *time;
- struct attr *on_eof;
- struct attr *baudrate;
- struct attr *checksum_ignore;
- struct attr *state_file;
-
- dbg(lvl_debug, "enter");
-
- source = attr_search(attrs, NULL, attr_source);
- if(source == NULL){
- dbg(lvl_error,"Missing source attribute");
- return NULL;
- }
- ret = g_new0(struct vehicle_priv, 1); // allocate and initialize to 0
- ret->fd = -1;
- ret->cbl = cbl;
- ret->source = g_strdup(source->u.str);
- ret->buffer = g_malloc(buffer_size);
- ret->time=1000;
- ret->baudrate=B4800;
- ret->fixtime[0] = '\0';
- ret->ev_fix_timeout = NULL;
- state_file=attr_search(attrs, NULL, attr_state_file);
- if (state_file)
- ret->statefile=g_strdup(state_file->u.str);
- time = attr_search(attrs, NULL, attr_time);
- if (time)
- ret->time=time->u.num;
- baudrate = attr_search(attrs, NULL, attr_baudrate);
- if (baudrate) {
- switch (baudrate->u.num) {
- case 4800:
- ret->baudrate=B4800;
- break;
- case 9600:
- ret->baudrate=B9600;
- break;
- case 19200:
- ret->baudrate=B19200;
- break;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source;
+ struct attr *time;
+ struct attr *on_eof;
+ struct attr *baudrate;
+ struct attr *checksum_ignore;
+ struct attr *state_file;
+
+ dbg(lvl_debug, "enter");
+
+ source = attr_search(attrs, NULL, attr_source);
+ if(source == NULL) {
+ dbg(lvl_error,"Missing source attribute");
+ return NULL;
+ }
+ ret = g_new0(struct vehicle_priv, 1); // allocate and initialize to 0
+ ret->fd = -1;
+ ret->cbl = cbl;
+ ret->source = g_strdup(source->u.str);
+ ret->buffer = g_malloc(buffer_size);
+ ret->time=1000;
+ ret->baudrate=B4800;
+ ret->fixtime[0] = '\0';
+ ret->ev_fix_timeout = NULL;
+ state_file=attr_search(attrs, NULL, attr_state_file);
+ if (state_file)
+ ret->statefile=g_strdup(state_file->u.str);
+ time = attr_search(attrs, NULL, attr_time);
+ if (time)
+ ret->time=time->u.num;
+ baudrate = attr_search(attrs, NULL, attr_baudrate);
+ if (baudrate) {
+ switch (baudrate->u.num) {
+ case 4800:
+ ret->baudrate=B4800;
+ break;
+ case 9600:
+ ret->baudrate=B9600;
+ break;
+ case 19200:
+ ret->baudrate=B19200;
+ break;
#ifdef B38400
- case 38400:
- ret->baudrate=B38400;
- break;
+ case 38400:
+ ret->baudrate=B38400;
+ break;
#endif
#ifdef B57600
- case 57600:
- ret->baudrate=B57600;
- break;
+ case 57600:
+ ret->baudrate=B57600;
+ break;
#endif
#ifdef B115200
- case 115200:
- ret->baudrate=B115200;
- break;
+ case 115200:
+ ret->baudrate=B115200;
+ break;
#endif
- }
- }
- checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
- if (checksum_ignore)
- ret->checksum_ignore=checksum_ignore->u.num;
- ret->attrs = attrs;
- on_eof = attr_search(attrs, NULL, attr_on_eof);
- if (on_eof && !g_ascii_strcasecmp(on_eof->u.str, "stop"))
- ret->on_eof=1;
- if (on_eof && !g_ascii_strcasecmp(on_eof->u.str, "exit"))
- ret->on_eof=2;
- dbg(lvl_debug,"on_eof=%d", ret->on_eof);
- *meth = vehicle_file_methods;
- ret->cb=callback_new_1(callback_cast(vehicle_file_io), ret);
- ret->cbt=callback_new_1(callback_cast(vehicle_file_enable_watch_timer), ret);
- ret->cb_fix_timeout=callback_new_1(callback_cast(vehicle_file_fix_timeout_cb), ret);
- if (ret->statefile && file_exists(ret->statefile)) {
- ret->process_statefile=1;
- event_add_timeout(1000, 0, ret->cb);
- }
- ret->sat_item.type=type_position_sat;
- ret->sat_item.id_hi=ret->sat_item.id_lo=0;
- ret->sat_item.priv_data=ret;
- ret->sat_item.meth=&vehicle_file_sat_methods;
+ }
+ }
+ checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
+ if (checksum_ignore)
+ ret->checksum_ignore=checksum_ignore->u.num;
+ ret->attrs = attrs;
+ on_eof = attr_search(attrs, NULL, attr_on_eof);
+ if (on_eof && !g_ascii_strcasecmp(on_eof->u.str, "stop"))
+ ret->on_eof=1;
+ if (on_eof && !g_ascii_strcasecmp(on_eof->u.str, "exit"))
+ ret->on_eof=2;
+ dbg(lvl_debug,"on_eof=%d", ret->on_eof);
+ *meth = vehicle_file_methods;
+ ret->cb=callback_new_1(callback_cast(vehicle_file_io), ret);
+ ret->cbt=callback_new_1(callback_cast(vehicle_file_enable_watch_timer), ret);
+ ret->cb_fix_timeout=callback_new_1(callback_cast(vehicle_file_fix_timeout_cb), ret);
+ if (ret->statefile && file_exists(ret->statefile)) {
+ ret->process_statefile=1;
+ event_add_timeout(1000, 0, ret->cb);
+ }
+ ret->sat_item.type=type_position_sat;
+ ret->sat_item.id_hi=ret->sat_item.id_lo=0;
+ ret->sat_item.priv_data=ret;
+ ret->sat_item.meth=&vehicle_file_sat_methods;
#ifdef _WIN32
- ret->no_data_count = 0;
+ ret->no_data_count = 0;
#endif
- dbg(lvl_debug, "vehicle_file_new_file:open");
- if (!vehicle_file_open(ret)) {
+ dbg(lvl_debug, "vehicle_file_new_file:open");
+ if (!vehicle_file_open(ret)) {
dbg(lvl_error, "Failed to open '%s'", ret->source);
- }
+ }
- vehicle_file_enable_watch(ret);
- // vehicle_file_destroy(ret);
- // return NULL;
- dbg(lvl_debug, "leave");
- return ret;
+ vehicle_file_enable_watch(ret);
+ // vehicle_file_destroy(ret);
+ // return NULL;
+ dbg(lvl_debug, "leave");
+ return ret;
}
/**
* @brief Initialisation of vehicle_file plugin
*/
-void plugin_init(void)
-{
- dbg(lvl_debug, "vehicle_file:plugin_init:enter");
- plugin_register_category_vehicle("file", vehicle_file_new_file);
- plugin_register_category_vehicle("pipe", vehicle_file_new_file);
- plugin_register_category_vehicle("socket", vehicle_file_new_file);
- plugin_register_category_vehicle("serial", vehicle_file_new_file);
+void plugin_init(void) {
+ dbg(lvl_debug, "vehicle_file:plugin_init:enter");
+ plugin_register_category_vehicle("file", vehicle_file_new_file);
+ plugin_register_category_vehicle("pipe", vehicle_file_new_file);
+ plugin_register_category_vehicle("socket", vehicle_file_new_file);
+ plugin_register_category_vehicle("serial", vehicle_file_new_file);
}
diff --git a/navit/vehicle/file/vehicle_pipe.c b/navit/vehicle/file/vehicle_pipe.c
index 420390d4e..8da12f4e8 100644
--- a/navit/vehicle/file/vehicle_pipe.c
+++ b/navit/vehicle/file/vehicle_pipe.c
@@ -21,7 +21,6 @@
#include "plugin.h"
void
-plugin_init(void)
-{
- plugin_get_category_vehicle("file");
+plugin_init(void) {
+ plugin_get_category_vehicle("file");
}
diff --git a/navit/vehicle/file/vehicle_serial.c b/navit/vehicle/file/vehicle_serial.c
index 420390d4e..8da12f4e8 100644
--- a/navit/vehicle/file/vehicle_serial.c
+++ b/navit/vehicle/file/vehicle_serial.c
@@ -21,7 +21,6 @@
#include "plugin.h"
void
-plugin_init(void)
-{
- plugin_get_category_vehicle("file");
+plugin_init(void) {
+ plugin_get_category_vehicle("file");
}
diff --git a/navit/vehicle/file/vehicle_socket.c b/navit/vehicle/file/vehicle_socket.c
index 420390d4e..8da12f4e8 100644
--- a/navit/vehicle/file/vehicle_socket.c
+++ b/navit/vehicle/file/vehicle_socket.c
@@ -21,7 +21,6 @@
#include "plugin.h"
void
-plugin_init(void)
-{
- plugin_get_category_vehicle("file");
+plugin_init(void) {
+ plugin_get_category_vehicle("file");
}
diff --git a/navit/vehicle/gpsd/vehicle_gpsd.c b/navit/vehicle/gpsd/vehicle_gpsd.c
index 285e05ccb..fa8df9c74 100644
--- a/navit/vehicle/gpsd/vehicle_gpsd.c
+++ b/navit/vehicle/gpsd/vehicle_gpsd.c
@@ -44,31 +44,31 @@
*/
static struct vehicle_priv {
- char *source;
- char *gpsd_query;
- struct callback_list *cbl;
- struct callback *cb, *cbt;
- struct event_watch *evwatch;
- guint retry_interval;
- struct gps_data_t *gps;
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- double hdop;
- int status;
- int fix_type;
- time_t fix_time;
- int sats;
- int sats_signal;
- int sats_used;
- char *nmea_data;
- char *nmea_data_buf;
- struct event_timeout *retry_timer2;
- struct attr ** attrs;
- char fixiso8601[128];
+ char *source;
+ char *gpsd_query;
+ struct callback_list *cbl;
+ struct callback *cb, *cbt;
+ struct event_watch *evwatch;
+ guint retry_interval;
+ struct gps_data_t *gps;
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ double hdop;
+ int status;
+ int fix_type;
+ time_t fix_time;
+ int sats;
+ int sats_signal;
+ int sats_used;
+ char *nmea_data;
+ char *nmea_data_buf;
+ struct event_timeout *retry_timer2;
+ struct attr ** attrs;
+ char fixiso8601[128];
#ifdef HAVE_GPSBT
- gpsbt_t context;
+ gpsbt_t context;
#endif
} *vehicle_last;
@@ -82,126 +82,127 @@ static void
vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len)
#else
vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len,
- int level)
+ int level)
#endif
{
- char *pos,*nmea_data_buf;
- int i=0,sats_signal=0;
-
- struct vehicle_priv *priv = vehicle_last;
- if( len > 0 && buf[0] == '$' ) {
- char buffer[len+2];
- buffer[len+1]='\0';
- memcpy(buffer, buf, len);
- pos=strchr(buffer,'\n');
- if(!pos) {
- pos=strchr(buffer,'\r');
- }
- if (pos) {
- *pos ='\n';
- *++pos='\0';
- if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
- nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, NULL);
- g_free(priv->nmea_data_buf);
- priv->nmea_data_buf=nmea_data_buf;
- } else {
- dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
- }
- }
- }
+ char *pos,*nmea_data_buf;
+ int i=0,sats_signal=0;
- dbg(lvl_debug,"data->set="LONGLONG_HEX_FMT"", (unsigned long long)data->set);
- if (data->set & SPEED_SET) {
- priv->speed = data->fix.speed * MPS_TO_KPH;
- if(!isnan(data->fix.speed))
- callback_list_call_attr_0(priv->cbl, attr_position_speed);
- data->set &= ~SPEED_SET;
- }
+ struct vehicle_priv *priv = vehicle_last;
+ if( len > 0 && buf[0] == '$' ) {
+ char buffer[len+2];
+ buffer[len+1]='\0';
+ memcpy(buffer, buf, len);
+ pos=strchr(buffer,'\n');
+ if(!pos) {
+ pos=strchr(buffer,'\r');
+ }
+ if (pos) {
+ *pos ='\n';
+ *++pos='\0';
+ if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
+ nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, NULL);
+ g_free(priv->nmea_data_buf);
+ priv->nmea_data_buf=nmea_data_buf;
+ } else {
+ dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
+ }
+ }
+ }
- if (data->set & TRACK_SET) {
- priv->direction = data->fix.track;
- data->set &= ~TRACK_SET;
- }
- if (data->set & ALTITUDE_SET) {
- priv->height = data->fix.altitude;
- data->set &= ~ALTITUDE_SET;
- }
- if (data->set & SATELLITE_SET) {
+ dbg(lvl_debug,"data->set="LONGLONG_HEX_FMT"", (unsigned long long)data->set);
+ if (data->set & SPEED_SET) {
+ priv->speed = data->fix.speed * MPS_TO_KPH;
+ if(!isnan(data->fix.speed))
+ callback_list_call_attr_0(priv->cbl, attr_position_speed);
+ data->set &= ~SPEED_SET;
+ }
+
+ if (data->set & TRACK_SET) {
+ priv->direction = data->fix.track;
+ data->set &= ~TRACK_SET;
+ }
+ if (data->set & ALTITUDE_SET) {
+ priv->height = data->fix.altitude;
+ data->set &= ~ALTITUDE_SET;
+ }
+ if (data->set & SATELLITE_SET) {
// We cannot rely on GPSD_API_MAJOR_VERSION here because it was not
// incremented for this change :-(.
#ifdef HAVE_LIBGPS19
- if(data->satellites_visible > 0) {
+ if(data->satellites_visible > 0) {
#else
- if(data->satellites > 0) {
+ if(data->satellites > 0) {
#endif
- sats_signal=0;
+ sats_signal=0;
#ifdef HAVE_LIBGPS19
- for( i=0;i<data->satellites_visible;i++) {
+ for( i=0; i<data->satellites_visible; i++) {
#else
- for( i=0;i<data->satellites;i++) {
+ for( i=0; i<data->satellites; i++) {
#endif
#if GPSD_API_MAJOR_VERSION >= 6
- if (data->skyview[i].ss > 0)
+ if (data->skyview[i].ss > 0)
#else
- if (data->ss[i] > 0)
+ if (data->ss[i] > 0)
#endif
- sats_signal++;
- }
- }
+ sats_signal++;
+ }
+ }
#ifdef HAVE_LIBGPS19
- if (priv->sats_used != data->satellites_used || priv->sats != data->satellites_visible || priv->sats_signal != sats_signal ) {
+ if (priv->sats_used != data->satellites_used || priv->sats != data->satellites_visible
+ || priv->sats_signal != sats_signal ) {
#else
- if (priv->sats_used != data->satellites_used || priv->sats != data->satellites || priv->sats_signal != sats_signal ) {
+ if (priv->sats_used != data->satellites_used || priv->sats != data->satellites || priv->sats_signal != sats_signal ) {
#endif
- priv->sats_used = data->satellites_used;
+ priv->sats_used = data->satellites_used;
#ifdef HAVE_LIBGPS19
- priv->sats = data->satellites_visible;
+ priv->sats = data->satellites_visible;
#else
- priv->sats = data->satellites;
+ priv->sats = data->satellites;
#endif
- priv->sats_signal = sats_signal;
- callback_list_call_attr_0(priv->cbl, attr_position_sats);
- }
- data->set &= ~SATELLITE_SET;
- }
- if (data->set & STATUS_SET) {
- priv->status = data->status;
- data->set &= ~STATUS_SET;
- }
- if (data->set & MODE_SET) {
- priv->fix_type = data->fix.mode - 1;
- data->set &= ~MODE_SET;
- }
- if (data->set & TIME_SET) {
- priv->fix_time = data->fix.time;
- data->set &= ~TIME_SET;
- }
+ priv->sats_signal = sats_signal;
+ callback_list_call_attr_0(priv->cbl, attr_position_sats);
+ }
+ data->set &= ~SATELLITE_SET;
+ }
+ if (data->set & STATUS_SET) {
+ priv->status = data->status;
+ data->set &= ~STATUS_SET;
+ }
+ if (data->set & MODE_SET) {
+ priv->fix_type = data->fix.mode - 1;
+ data->set &= ~MODE_SET;
+ }
+ if (data->set & TIME_SET) {
+ priv->fix_time = data->fix.time;
+ data->set &= ~TIME_SET;
+ }
#ifdef HAVE_LIBGPS19
- if (data->set & DOP_SET) {
- dbg(lvl_debug, "pdop : %g", data->dop.pdop);
- priv->hdop = data->dop.pdop;
- data->set &= ~DOP_SET;
+ if (data->set & DOP_SET) {
+ dbg(lvl_debug, "pdop : %g", data->dop.pdop);
+ priv->hdop = data->dop.pdop;
+ data->set &= ~DOP_SET;
#else
- if (data->set & PDOP_SET) {
- dbg(lvl_debug, "pdop : %g", data->pdop);
- priv->hdop = data->hdop;
- data->set &= ~PDOP_SET;
+ if (data->set & PDOP_SET) {
+ dbg(lvl_debug, "pdop : %g", data->pdop);
+ priv->hdop = data->hdop;
+ data->set &= ~PDOP_SET;
#endif
- }
- if (data->set & LATLON_SET) {
- priv->geo.lat = data->fix.latitude;
- priv->geo.lng = data->fix.longitude;
- dbg(lvl_debug,"lat=%f lng=%f", priv->geo.lat, priv->geo.lng);
- g_free(priv->nmea_data);
- priv->nmea_data=priv->nmea_data_buf;
- priv->nmea_data_buf=NULL;
- data->set &= ~LATLON_SET;
- }
- // If data->fix.speed is NAN, then the drawing gets jumpy.
- if (! isnan(data->fix.speed) && priv->fix_type > 0) {
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
- dbg(lvl_info,"speed ok");
+ }
+ if (data->set & LATLON_SET) {
+ priv->geo.lat = data->fix.latitude;
+ priv->geo.lng = data->fix.longitude;
+ dbg(lvl_debug,"lat=%f lng=%f", priv->geo.lat, priv->geo.lng);
+ g_free(priv->nmea_data);
+ priv->nmea_data=priv->nmea_data_buf;
+ priv->nmea_data_buf=NULL;
+ data->set &= ~LATLON_SET;
+ }
+ // If data->fix.speed is NAN, then the drawing gets jumpy.
+ if (! isnan(data->fix.speed) && priv->fix_type > 0) {
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
+ dbg(lvl_info,"speed ok");
}
/**
@@ -210,276 +211,267 @@ vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len,
* Return TRUE to try again
*/
static int
-vehicle_gpsd_try_open(struct vehicle_priv *priv)
-{
- char *source = g_strdup(priv->source);
- char *colon = index(source + 7, ':');
- char *port=NULL;
- if (colon) {
- *colon = '\0';
- port=colon+1;
- }
- dbg(lvl_debug,"Trying to connect to %s:%s",source+7,port?port:"default");
+vehicle_gpsd_try_open(struct vehicle_priv *priv) {
+ char *source = g_strdup(priv->source);
+ char *colon = index(source + 7, ':');
+ char *port=NULL;
+ if (colon) {
+ *colon = '\0';
+ port=colon+1;
+ }
+ dbg(lvl_debug,"Trying to connect to %s:%s",source+7,port?port:"default");
#if GPSD_API_MAJOR_VERSION >= 5
- /* gps_open returns 0 on success */
- if (gps_open(source + 7, port, priv->gps)) {
+ /* gps_open returns 0 on success */
+ if (gps_open(source + 7, port, priv->gps)) {
#else
- priv->gps = gps_open(source + 7, port);
- if(!priv->gps) {
+ priv->gps = gps_open(source + 7, port);
+ if(!priv->gps) {
#endif
- dbg(lvl_error,"gps_open failed for '%s'. Retrying in %d seconds. Have you started gpsd?", priv->source, priv->retry_interval);
- g_free(source);
- return TRUE;
- }
- g_free(source);
+ dbg(lvl_error,"gps_open failed for '%s'. Retrying in %d seconds. Have you started gpsd?", priv->source,
+ priv->retry_interval);
+ g_free(source);
+ return TRUE;
+ }
+ g_free(source);
#ifdef HAVE_LIBGPS19
- if (strchr(priv->gpsd_query,'r'))
- gps_stream(priv->gps, WATCH_ENABLE|WATCH_NMEA|WATCH_JSON, NULL);
- else
- gps_stream(priv->gps, WATCH_ENABLE|WATCH_JSON, NULL);
+ if (strchr(priv->gpsd_query,'r'))
+ gps_stream(priv->gps, WATCH_ENABLE|WATCH_NMEA|WATCH_JSON, NULL);
+ else
+ gps_stream(priv->gps, WATCH_ENABLE|WATCH_JSON, NULL);
#else
- gps_query(priv->gps, priv->gpsd_query);
+ gps_query(priv->gps, priv->gpsd_query);
#endif
#if GPSD_API_MAJOR_VERSION < 5
- gps_set_raw_hook(priv->gps, vehicle_gpsd_callback);
+ gps_set_raw_hook(priv->gps, vehicle_gpsd_callback);
#endif
- priv->cb = callback_new_1(callback_cast(vehicle_gpsd_io), priv);
- priv->cbt = callback_new_1(callback_cast(vehicle_gpsd_try_open), priv);
- priv->evwatch = event_add_watch(priv->gps->gps_fd, event_watch_cond_read, priv->cb);
- if (!priv->gps->gps_fd) {
- dbg(lvl_error,"Warning: gps_fd is 0, most likely you have used a gps.h incompatible to libgps");
- }
- dbg(lvl_debug,"Connected to gpsd fd=%d evwatch=%p", priv->gps->gps_fd, priv->evwatch);
- event_remove_timeout(priv->retry_timer2);
- priv->retry_timer2=NULL;
- return FALSE;
+ priv->cb = callback_new_1(callback_cast(vehicle_gpsd_io), priv);
+ priv->cbt = callback_new_1(callback_cast(vehicle_gpsd_try_open), priv);
+ priv->evwatch = event_add_watch(priv->gps->gps_fd, event_watch_cond_read, priv->cb);
+ if (!priv->gps->gps_fd) {
+ dbg(lvl_error,"Warning: gps_fd is 0, most likely you have used a gps.h incompatible to libgps");
+ }
+ dbg(lvl_debug,"Connected to gpsd fd=%d evwatch=%p", priv->gps->gps_fd, priv->evwatch);
+ event_remove_timeout(priv->retry_timer2);
+ priv->retry_timer2=NULL;
+ return FALSE;
}
/**
* Open a connection to gpsd. Will re-try the connection if it fails
*/
static void
-vehicle_gpsd_open(struct vehicle_priv *priv)
-{
+vehicle_gpsd_open(struct vehicle_priv *priv) {
#ifdef HAVE_GPSBT
- char errstr[256] = "";
- /* We need to start gpsd (via gpsbt) first. */
- errno = 0;
- memset(&priv->context, 0, sizeof(gpsbt_t));
- if(gpsbt_start(NULL, 0, 0, 0, errstr, sizeof(errstr),
- 0, &priv->context) < 0) {
- dbg(lvl_error,"Error connecting to GPS with gpsbt: (%d) %s (%s)",
- errno, strerror(errno), errstr);
- }
- sleep(1); /* give gpsd time to start */
- dbg(lvl_debug,"gpsbt_start: completed");
+ char errstr[256] = "";
+ /* We need to start gpsd (via gpsbt) first. */
+ errno = 0;
+ memset(&priv->context, 0, sizeof(gpsbt_t));
+ if(gpsbt_start(NULL, 0, 0, 0, errstr, sizeof(errstr),
+ 0, &priv->context) < 0) {
+ dbg(lvl_error,"Error connecting to GPS with gpsbt: (%d) %s (%s)",
+ errno, strerror(errno), errstr);
+ }
+ sleep(1); /* give gpsd time to start */
+ dbg(lvl_debug,"gpsbt_start: completed");
#endif
- priv->retry_timer2=NULL;
- if (vehicle_gpsd_try_open(priv))
- priv->retry_timer2=event_add_timeout(priv->retry_interval*1000, 1, priv->cbt);
+ priv->retry_timer2=NULL;
+ if (vehicle_gpsd_try_open(priv))
+ priv->retry_timer2=event_add_timeout(priv->retry_interval*1000, 1, priv->cbt);
}
static void
-vehicle_gpsd_close(struct vehicle_priv *priv)
-{
+vehicle_gpsd_close(struct vehicle_priv *priv) {
#ifdef HAVE_GPSBT
- int err;
+ int err;
#endif
- if (priv->retry_timer2) {
- event_remove_timeout(priv->retry_timer2);
- priv->retry_timer2=NULL;
- }
- if (priv->evwatch) {
- event_remove_watch(priv->evwatch);
- priv->evwatch = NULL;
- }
- if (priv->cb) {
- callback_destroy(priv->cb);
- priv->cb = NULL;
- }
- if (priv->cbt) {
- callback_destroy(priv->cbt);
- priv->cbt = NULL;
- }
- if (priv->gps) {
- gps_close(priv->gps);
+ if (priv->retry_timer2) {
+ event_remove_timeout(priv->retry_timer2);
+ priv->retry_timer2=NULL;
+ }
+ if (priv->evwatch) {
+ event_remove_watch(priv->evwatch);
+ priv->evwatch = NULL;
+ }
+ if (priv->cb) {
+ callback_destroy(priv->cb);
+ priv->cb = NULL;
+ }
+ if (priv->cbt) {
+ callback_destroy(priv->cbt);
+ priv->cbt = NULL;
+ }
+ if (priv->gps) {
+ gps_close(priv->gps);
#if GPSD_API_MAJOR_VERSION >= 5
- g_free(priv->gps);
+ g_free(priv->gps);
#endif
- priv->gps = NULL;
- }
+ priv->gps = NULL;
+ }
#ifdef HAVE_GPSBT
- err = gpsbt_stop(&priv->context);
- if (err < 0) {
- dbg(lvl_error,"Error %d while gpsbt_stop", err);
- }
- dbg(lvl_debug,"gpsbt_stop: completed, (%d)",err);
+ err = gpsbt_stop(&priv->context);
+ if (err < 0) {
+ dbg(lvl_error,"Error %d while gpsbt_stop", err);
+ }
+ dbg(lvl_debug,"gpsbt_stop: completed, (%d)",err);
#endif
}
static void
-vehicle_gpsd_io(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "enter");
- if (priv->gps) {
- vehicle_last = priv;
+vehicle_gpsd_io(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "enter");
+ if (priv->gps) {
+ vehicle_last = priv;
#if GPSD_API_MAJOR_VERSION >= 5
- int read_result;
- /* Read until EOF, in case we are lagging behind.
- * No point in processing old GPS reports. */
- while((read_result=gps_read(priv->gps))>0);
- if(read_result==-1) {
- dbg(lvl_error,"gps_poll failed");
- vehicle_gpsd_close(priv);
- vehicle_gpsd_open(priv);
- }
- else {
- const char *buf;
- buf = gps_data(priv->gps);
- vehicle_gpsd_callback(priv->gps,buf,strlen(buf));
- }
+ int read_result;
+ /* Read until EOF, in case we are lagging behind.
+ * No point in processing old GPS reports. */
+ while((read_result=gps_read(priv->gps))>0);
+ if(read_result==-1) {
+ dbg(lvl_error,"gps_poll failed");
+ vehicle_gpsd_close(priv);
+ vehicle_gpsd_open(priv);
+ } else {
+ const char *buf;
+ buf = gps_data(priv->gps);
+ vehicle_gpsd_callback(priv->gps,buf,strlen(buf));
+ }
#else
- if (gps_poll(priv->gps)) {
- dbg(lvl_error,"gps_poll failed");
- vehicle_gpsd_close(priv);
- vehicle_gpsd_open(priv);
- }
+ if (gps_poll(priv->gps)) {
+ dbg(lvl_error,"gps_poll failed");
+ vehicle_gpsd_close(priv);
+ vehicle_gpsd_open(priv);
+ }
#endif
- }
+ }
}
static void
-vehicle_gpsd_destroy(struct vehicle_priv *priv)
-{
- vehicle_gpsd_close(priv);
- if (priv->source)
- g_free(priv->source);
- if (priv->gpsd_query)
- g_free(priv->gpsd_query);
+vehicle_gpsd_destroy(struct vehicle_priv *priv) {
+ vehicle_gpsd_close(priv);
+ if (priv->source)
+ g_free(priv->source);
+ if (priv->gpsd_query)
+ g_free(priv->gpsd_query);
#if GPSD_API_MAJOR_VERSION >= 5
- g_free(priv->gps);
+ g_free(priv->gps);
#endif
- g_free(priv);
+ g_free(priv);
}
static int
vehicle_gpsd_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- struct attr * active=NULL;
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->fix_type;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_hdop:
- attr->u.numd = &priv->hdop;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats;
- break;
- case attr_position_sats_signal:
- attr->u.num = priv->sats_signal;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_nmea:
- attr->u.str=priv->nmea_data;
- if (! attr->u.str)
- return 0;
- break;
- case attr_position_time_iso8601:
- {
- struct tm tm;
- if (!priv->fix_time)
- return 0;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- } else
- return 0;
- }
- break;
- case attr_active:
- active = attr_search(priv->attrs,NULL,attr_active);
- if(active != NULL) {
- attr->u.num=active->u.num;
- return 1;
- } else
- return 0;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ struct attr * active=NULL;
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->fix_type;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_hdop:
+ attr->u.numd = &priv->hdop;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats;
+ break;
+ case attr_position_sats_signal:
+ attr->u.num = priv->sats_signal;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_nmea:
+ attr->u.str=priv->nmea_data;
+ if (! attr->u.str)
+ return 0;
+ break;
+ case attr_position_time_iso8601: {
+ struct tm tm;
+ if (!priv->fix_time)
+ return 0;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else
+ return 0;
+ }
+ break;
+ case attr_active:
+ active = attr_search(priv->attrs,NULL,attr_active);
+ if(active != NULL) {
+ attr->u.num=active->u.num;
+ return 1;
+ } else
+ return 0;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static struct vehicle_methods vehicle_gpsd_methods = {
- vehicle_gpsd_destroy,
- vehicle_gpsd_position_attr_get,
+ vehicle_gpsd_destroy,
+ vehicle_gpsd_position_attr_get,
};
static struct vehicle_priv *
vehicle_gpsd_new_gpsd(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source, *query, *retry_int;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source, *query, *retry_int;
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- ret = g_new0(struct vehicle_priv, 1);
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ ret = g_new0(struct vehicle_priv, 1);
#if GPSD_API_MAJOR_VERSION >= 5
- ret->gps = g_new0(struct gps_data_t, 1);
+ ret->gps = g_new0(struct gps_data_t, 1);
#endif
- ret->source = g_strdup(source->u.str);
- query = attr_search(attrs, NULL, attr_gpsd_query);
- if (query) {
- ret->gpsd_query = g_strconcat(query->u.str, "\n", NULL);
- } else {
- ret->gpsd_query = g_strdup("w+x\n");
- }
- dbg(lvl_debug,"Format string for gpsd_query: %s",ret->gpsd_query);
- retry_int = attr_search(attrs, NULL, attr_retry_interval);
- if (retry_int) {
- ret->retry_interval = retry_int->u.num;
- if (ret->retry_interval < MIN_RETRY_INTERVAL) {
- dbg(lvl_error, "Retry interval %d too small, setting to %d", ret->retry_interval, MIN_RETRY_INTERVAL);
- ret->retry_interval = MIN_RETRY_INTERVAL;
- }
- } else {
- dbg(lvl_debug, "Retry interval not defined, setting to %d", DEFAULT_RETRY_INTERVAL);
- ret->retry_interval = DEFAULT_RETRY_INTERVAL;
- }
- ret->cbl = cbl;
- *meth = vehicle_gpsd_methods;
- ret->attrs = attrs;
- vehicle_gpsd_open(ret);
- return ret;
+ ret->source = g_strdup(source->u.str);
+ query = attr_search(attrs, NULL, attr_gpsd_query);
+ if (query) {
+ ret->gpsd_query = g_strconcat(query->u.str, "\n", NULL);
+ } else {
+ ret->gpsd_query = g_strdup("w+x\n");
+ }
+ dbg(lvl_debug,"Format string for gpsd_query: %s",ret->gpsd_query);
+ retry_int = attr_search(attrs, NULL, attr_retry_interval);
+ if (retry_int) {
+ ret->retry_interval = retry_int->u.num;
+ if (ret->retry_interval < MIN_RETRY_INTERVAL) {
+ dbg(lvl_error, "Retry interval %d too small, setting to %d", ret->retry_interval, MIN_RETRY_INTERVAL);
+ ret->retry_interval = MIN_RETRY_INTERVAL;
+ }
+ } else {
+ dbg(lvl_debug, "Retry interval not defined, setting to %d", DEFAULT_RETRY_INTERVAL);
+ ret->retry_interval = DEFAULT_RETRY_INTERVAL;
+ }
+ ret->cbl = cbl;
+ *meth = vehicle_gpsd_methods;
+ ret->attrs = attrs;
+ vehicle_gpsd_open(ret);
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("gpsd", vehicle_gpsd_new_gpsd);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("gpsd", vehicle_gpsd_new_gpsd);
}
diff --git a/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c b/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c
index dd7b99ef0..eb5805ea3 100644
--- a/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c
+++ b/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c
@@ -45,212 +45,202 @@
static char *vehicle_gpsd_dbus_prefix="gpsd_dbus:";
struct vehicle_priv {
- char *source;
- char *address;
- int flags;
- struct callback_list *cbl;
- DBusConnection *connection;
- double time, track, speed, altitude;
- time_t fix_time;
- struct coord_geo geo;
- struct attr ** attrs;
- char fixiso8601[128];
+ char *source;
+ char *address;
+ int flags;
+ struct callback_list *cbl;
+ DBusConnection *connection;
+ double time, track, speed, altitude;
+ time_t fix_time;
+ struct coord_geo geo;
+ struct attr ** attrs;
+ char fixiso8601[128];
};
static void
-vehicle_gpsd_dbus_close(struct vehicle_priv *priv)
-{
- if (priv->connection)
- dbus_connection_unref(priv->connection);
- priv->connection=NULL;
+vehicle_gpsd_dbus_close(struct vehicle_priv *priv) {
+ if (priv->connection)
+ dbus_connection_unref(priv->connection);
+ priv->connection=NULL;
}
static DBusHandlerResult
-vehicle_gpsd_dbus_filter(DBusConnection *connection, DBusMessage *message, void *user_data)
-{
- struct vehicle_priv *priv=user_data;
- double time,ept,latitude,longitude,eph,altitude,epv,track,epd,speed,eps,climb,epc;
- int mode;
- char *devname;
-
- if (dbus_message_is_signal(message, "org.gpsd","fix")) {
- dbus_message_get_args (message, NULL,
- DBUS_TYPE_DOUBLE, &time,
- DBUS_TYPE_INT32, &mode,
- DBUS_TYPE_DOUBLE, &ept,
- DBUS_TYPE_DOUBLE, &latitude,
- DBUS_TYPE_DOUBLE, &longitude,
- DBUS_TYPE_DOUBLE, &eph,
- DBUS_TYPE_DOUBLE, &altitude,
- DBUS_TYPE_DOUBLE, &epv,
- DBUS_TYPE_DOUBLE, &track,
- DBUS_TYPE_DOUBLE, &epd,
- DBUS_TYPE_DOUBLE, &speed,
- DBUS_TYPE_DOUBLE, &eps,
- DBUS_TYPE_DOUBLE, &climb,
- DBUS_TYPE_DOUBLE, &epc,
- DBUS_TYPE_STRING, &devname,
- DBUS_TYPE_INVALID);
- if (!isnan(latitude) && !isnan(longitude)) {
- priv->geo.lat=latitude;
- priv->geo.lng=longitude;
- }
- if (!isnan(track))
- priv->track=track;
- if (!isnan(speed))
- priv->speed=speed;
- if (!isnan(altitude))
- priv->altitude=altitude;
- if (time != priv->time || (priv->flags & 1)) {
- priv->time=time;
- priv->fix_time=time;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+vehicle_gpsd_dbus_filter(DBusConnection *connection, DBusMessage *message, void *user_data) {
+ struct vehicle_priv *priv=user_data;
+ double time,ept,latitude,longitude,eph,altitude,epv,track,epd,speed,eps,climb,epc;
+ int mode;
+ char *devname;
+
+ if (dbus_message_is_signal(message, "org.gpsd","fix")) {
+ dbus_message_get_args (message, NULL,
+ DBUS_TYPE_DOUBLE, &time,
+ DBUS_TYPE_INT32, &mode,
+ DBUS_TYPE_DOUBLE, &ept,
+ DBUS_TYPE_DOUBLE, &latitude,
+ DBUS_TYPE_DOUBLE, &longitude,
+ DBUS_TYPE_DOUBLE, &eph,
+ DBUS_TYPE_DOUBLE, &altitude,
+ DBUS_TYPE_DOUBLE, &epv,
+ DBUS_TYPE_DOUBLE, &track,
+ DBUS_TYPE_DOUBLE, &epd,
+ DBUS_TYPE_DOUBLE, &speed,
+ DBUS_TYPE_DOUBLE, &eps,
+ DBUS_TYPE_DOUBLE, &climb,
+ DBUS_TYPE_DOUBLE, &epc,
+ DBUS_TYPE_STRING, &devname,
+ DBUS_TYPE_INVALID);
+ if (!isnan(latitude) && !isnan(longitude)) {
+ priv->geo.lat=latitude;
+ priv->geo.lng=longitude;
+ }
+ if (!isnan(track))
+ priv->track=track;
+ if (!isnan(speed))
+ priv->speed=speed;
+ if (!isnan(altitude))
+ priv->altitude=altitude;
+ if (time != priv->time || (priv->flags & 1)) {
+ priv->time=time;
+ priv->fix_time=time;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static int
-vehicle_gpsd_dbus_open(struct vehicle_priv *priv)
-{
- DBusError error;
-
- dbus_error_init(&error);
- if (priv->address) {
- priv->connection = dbus_connection_open(priv->address, &error);
- } else {
- priv->connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
- }
- if (!priv->connection) {
- dbg(lvl_error,"Failed to open connection to %s message bus: %s", priv->address?priv->address:"session",error.message);
- dbus_error_free(&error);
- return 0;
- }
- dbus_connection_setup_with_g_main(priv->connection, NULL);
- dbus_bus_add_match(priv->connection,"type='signal',interface='org.gpsd'",&error);
- dbus_connection_flush(priv->connection);
- if (dbus_error_is_set(&error)) {
- dbg(lvl_error,"Failed to add match to connection: %s", error.message);
- vehicle_gpsd_dbus_close(priv);
- return 0;
- }
- if (!dbus_connection_add_filter(priv->connection, vehicle_gpsd_dbus_filter, priv, NULL)) {
- dbg(lvl_error,"Failed to add filter to connection");
- vehicle_gpsd_dbus_close(priv);
- return 0;
- }
- return 1;
+vehicle_gpsd_dbus_open(struct vehicle_priv *priv) {
+ DBusError error;
+
+ dbus_error_init(&error);
+ if (priv->address) {
+ priv->connection = dbus_connection_open(priv->address, &error);
+ } else {
+ priv->connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ }
+ if (!priv->connection) {
+ dbg(lvl_error,"Failed to open connection to %s message bus: %s", priv->address?priv->address:"session",error.message);
+ dbus_error_free(&error);
+ return 0;
+ }
+ dbus_connection_setup_with_g_main(priv->connection, NULL);
+ dbus_bus_add_match(priv->connection,"type='signal',interface='org.gpsd'",&error);
+ dbus_connection_flush(priv->connection);
+ if (dbus_error_is_set(&error)) {
+ dbg(lvl_error,"Failed to add match to connection: %s", error.message);
+ vehicle_gpsd_dbus_close(priv);
+ return 0;
+ }
+ if (!dbus_connection_add_filter(priv->connection, vehicle_gpsd_dbus_filter, priv, NULL)) {
+ dbg(lvl_error,"Failed to add filter to connection");
+ vehicle_gpsd_dbus_close(priv);
+ return 0;
+ }
+ return 1;
}
static void
-vehicle_gpsd_dbus_destroy(struct vehicle_priv *priv)
-{
- vehicle_gpsd_dbus_close(priv);
- if (priv->source)
- g_free(priv->source);
- g_free(priv);
+vehicle_gpsd_dbus_destroy(struct vehicle_priv *priv) {
+ vehicle_gpsd_dbus_close(priv);
+ if (priv->source)
+ g_free(priv->source);
+ g_free(priv);
}
static int
vehicle_gpsd_dbus_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_height:
- attr->u.numd = &priv->altitude;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->track;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_time_iso8601:
- {
- struct tm tm;
- if (!priv->fix_time)
- return 0;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- } else
- return 0;
- }
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_height:
+ attr->u.numd = &priv->altitude;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->track;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601: {
+ struct tm tm;
+ if (!priv->fix_time)
+ return 0;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else
+ return 0;
+ }
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static int
-vehicle_gpsd_dbus_set_attr_do(struct vehicle_priv *priv, struct attr *attr, int init)
-{
- switch (attr->type) {
- case attr_source:
- if (strncmp(vehicle_gpsd_dbus_prefix,attr->u.str,strlen(vehicle_gpsd_dbus_prefix))) {
- dbg(lvl_error,"source must start with '%s'", vehicle_gpsd_dbus_prefix);
- return 0;
- }
- g_free(priv->source);
- priv->source=g_strdup(attr->u.str);
- priv->address=priv->source+strlen(vehicle_gpsd_dbus_prefix);
- if (!priv->address[0])
- priv->address=NULL;
- if (!init) {
- vehicle_gpsd_dbus_close(priv);
- vehicle_gpsd_dbus_open(priv);
- }
- return 1;
- case attr_flags:
- priv->flags=attr->u.num;
- return 1;
- default:
- return 0;
- }
+vehicle_gpsd_dbus_set_attr_do(struct vehicle_priv *priv, struct attr *attr, int init) {
+ switch (attr->type) {
+ case attr_source:
+ if (strncmp(vehicle_gpsd_dbus_prefix,attr->u.str,strlen(vehicle_gpsd_dbus_prefix))) {
+ dbg(lvl_error,"source must start with '%s'", vehicle_gpsd_dbus_prefix);
+ return 0;
+ }
+ g_free(priv->source);
+ priv->source=g_strdup(attr->u.str);
+ priv->address=priv->source+strlen(vehicle_gpsd_dbus_prefix);
+ if (!priv->address[0])
+ priv->address=NULL;
+ if (!init) {
+ vehicle_gpsd_dbus_close(priv);
+ vehicle_gpsd_dbus_open(priv);
+ }
+ return 1;
+ case attr_flags:
+ priv->flags=attr->u.num;
+ return 1;
+ default:
+ return 0;
+ }
}
static int
-vehicle_gpsd_dbus_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- return vehicle_gpsd_dbus_set_attr_do(priv, attr, 0);
+vehicle_gpsd_dbus_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ return vehicle_gpsd_dbus_set_attr_do(priv, attr, 0);
}
static struct vehicle_methods vehicle_gpsd_methods = {
- vehicle_gpsd_dbus_destroy,
- vehicle_gpsd_dbus_position_attr_get,
- vehicle_gpsd_dbus_set_attr,
+ vehicle_gpsd_dbus_destroy,
+ vehicle_gpsd_dbus_position_attr_get,
+ vehicle_gpsd_dbus_set_attr,
};
static struct vehicle_priv *
vehicle_gpsd_dbus_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
-
-
- ret = g_new0(struct vehicle_priv, 1);
- ret->attrs = attrs;
- ret->cbl = cbl;
- *meth = vehicle_gpsd_methods;
- while (*attrs) {
- vehicle_gpsd_dbus_set_attr_do(ret, *attrs, 1);
- attrs++;
- }
- vehicle_gpsd_dbus_open(ret);
- return ret;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+
+
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->attrs = attrs;
+ ret->cbl = cbl;
+ *meth = vehicle_gpsd_methods;
+ while (*attrs) {
+ vehicle_gpsd_dbus_set_attr_do(ret, *attrs, 1);
+ attrs++;
+ }
+ vehicle_gpsd_dbus_open(ret);
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("gpsd_dbus", vehicle_gpsd_dbus_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("gpsd_dbus", vehicle_gpsd_dbus_new);
}
diff --git a/navit/vehicle/gypsy/vehicle_gypsy.c b/navit/vehicle/gypsy/vehicle_gypsy.c
index db3acf588..b8dc8f2cc 100644
--- a/navit/vehicle/gypsy/vehicle_gypsy.c
+++ b/navit/vehicle/gypsy/vehicle_gypsy.c
@@ -54,27 +54,27 @@
*/
static struct vehicle_priv {
- char *source;
- GypsyControl *control;
- GypsyPosition *position;
- GypsyDevice *device;
- GypsyCourse *course;
- GypsySatellite *satellite;
- char *path;
- struct callback_list *cbl;
- guint retry_interval;
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- int fix_type;
- time_t fix_time;
- char fixiso8601[128];
- int sats;
- int sats_used;
- guint retry_timer;
- struct attr ** attrs;
- int have_cords;
+ char *source;
+ GypsyControl *control;
+ GypsyPosition *position;
+ GypsyDevice *device;
+ GypsyCourse *course;
+ GypsySatellite *satellite;
+ char *path;
+ struct callback_list *cbl;
+ guint retry_interval;
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ int fix_type;
+ time_t fix_time;
+ char fixiso8601[128];
+ int sats;
+ int sats_used;
+ guint retry_timer;
+ struct attr ** attrs;
+ int have_cords;
} *vehicle_last;
#define DEFAULT_RETRY_INTERVAL 10 // seconds
@@ -91,7 +91,7 @@ static struct vehicle_priv {
*
* Anytime this functions get called, we have to call the global
* callback.
- *
+ *
* @param device The GypsyDevice
* @param fixstatus The fisstatus 0, 1, 2 or 3
* @param userdata
@@ -99,19 +99,18 @@ static struct vehicle_priv {
*/
static void
vehicle_gypsy_fixstatus_changed(GypsyDevice *device,
- gint fixstatus,
- gpointer userdata)
-{
- struct vehicle_priv *priv = vehicle_last;
-
- if (fixstatus==GYPSY_DEVICE_FIX_STATUS_3D)
- priv->fix_type = 3;
- else if (fixstatus==GYPSY_DEVICE_FIX_STATUS_2D)
- priv->fix_type = 1;
- else
- priv->fix_type = 0;
-
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ gint fixstatus,
+ gpointer userdata) {
+ struct vehicle_priv *priv = vehicle_last;
+
+ if (fixstatus==GYPSY_DEVICE_FIX_STATUS_3D)
+ priv->fix_type = 3;
+ else if (fixstatus==GYPSY_DEVICE_FIX_STATUS_2D)
+ priv->fix_type = 1;
+ else
+ priv->fix_type = 0;
+
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
/**
@@ -125,49 +124,44 @@ vehicle_gypsy_fixstatus_changed(GypsyDevice *device,
*
* If we get any new information, we have to call the global
* callback.
- *
+ *
* @param position The GypsyPosition
- * @param fields_set Bitmask indicating what field was set
+ * @param fields_set Bitmask indicating what field was set
* @param timestamp the time since Unix Epoch
- * @param latitude
- * @param longitude
+ * @param latitude
+ * @param longitude
* @param altitude
* @param userdata
* @returns nothing
*/
-static void
-vehicle_gypsy_position_changed(GypsyPosition *position,
- GypsyPositionFields fields_set, int timestamp,
- double latitude, double longitude, double altitude,
- gpointer userdata)
-{
- struct vehicle_priv *priv = vehicle_last;
- int cb = FALSE;
-
- if (timestamp > 0)
- priv->fix_time = timestamp;
-
- if (fields_set & GYPSY_POSITION_FIELDS_LATITUDE)
- {
- cb = TRUE;
- priv->geo.lat = latitude;
- }
- if (fields_set & GYPSY_POSITION_FIELDS_LONGITUDE)
- {
- cb = TRUE;
- priv->geo.lng = longitude;
- }
- if (fields_set & GYPSY_POSITION_FIELDS_ALTITUDE)
- {
- cb = TRUE;
- priv->height = altitude;
- }
-
- if (cb)
- {
- priv->have_cords = 1;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
+static void
+vehicle_gypsy_position_changed(GypsyPosition *position,
+ GypsyPositionFields fields_set, int timestamp,
+ double latitude, double longitude, double altitude,
+ gpointer userdata) {
+ struct vehicle_priv *priv = vehicle_last;
+ int cb = FALSE;
+
+ if (timestamp > 0)
+ priv->fix_time = timestamp;
+
+ if (fields_set & GYPSY_POSITION_FIELDS_LATITUDE) {
+ cb = TRUE;
+ priv->geo.lat = latitude;
+ }
+ if (fields_set & GYPSY_POSITION_FIELDS_LONGITUDE) {
+ cb = TRUE;
+ priv->geo.lng = longitude;
+ }
+ if (fields_set & GYPSY_POSITION_FIELDS_ALTITUDE) {
+ cb = TRUE;
+ priv->height = altitude;
+ }
+
+ if (cb) {
+ priv->have_cords = 1;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
}
/**
@@ -178,31 +172,30 @@ vehicle_gypsy_position_changed(GypsyPosition *position,
* Anytime this functions get called, we have to call the global
* callback.
*
- * @param satellite The GypsySatellite
+ * @param satellite The GypsySatellite
* @param satellites An GPtrArray wich hold information of all sats
* @param userdata
* @returns nothing
*/
-static void
-vehicle_gypsy_satellite_changed(GypsySatellite *satellite,
- GPtrArray *satellites,
- gpointer userdata)
-{
- struct vehicle_priv *priv = vehicle_last;
-
- int i, sats, used=0;
-
- sats = satellites->len;
- for (i = 0; i < sats; i++) {
- GypsySatelliteDetails *details = satellites->pdata[i];
- if (details->in_use)
- used++;
- }
-
- priv->sats_used = used;
- priv->sats = sats;
-
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+static void
+vehicle_gypsy_satellite_changed(GypsySatellite *satellite,
+ GPtrArray *satellites,
+ gpointer userdata) {
+ struct vehicle_priv *priv = vehicle_last;
+
+ int i, sats, used=0;
+
+ sats = satellites->len;
+ for (i = 0; i < sats; i++) {
+ GypsySatelliteDetails *details = satellites->pdata[i];
+ if (details->in_use)
+ used++;
+ }
+
+ priv->sats_used = used;
+ priv->sats = sats;
+
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
/**
@@ -212,9 +205,9 @@ vehicle_gypsy_satellite_changed(GypsySatellite *satellite,
*
* If we get any new information, we have to call the global
* callback.
- *
+ *
* @param course The GypsyCourse
- * @param fields Bitmask indicating what field was set
+ * @param fields Bitmask indicating what field was set
* @param timestamp the time since Unix Epoch
* @param speed
* @param direction
@@ -222,146 +215,139 @@ vehicle_gypsy_satellite_changed(GypsySatellite *satellite,
* @param userdata
* @returns nothing
*/
-static void
-vehicle_gypsy_course_changed (GypsyCourse *course,
- GypsyCourseFields fields,
- int timestamp,
- double speed,
- double direction,
- double climb,
- gpointer userdata)
-{
- struct vehicle_priv *priv = vehicle_last;
- int cb = FALSE;
-
- if (fields & GYPSY_COURSE_FIELDS_SPEED)
- {
- priv->speed = speed*3.6;
- cb = TRUE;
- }
- if (fields & GYPSY_COURSE_FIELDS_DIRECTION)
- {
- priv->direction = direction;
- cb = TRUE;
- }
-
- if (cb)
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+static void
+vehicle_gypsy_course_changed (GypsyCourse *course,
+ GypsyCourseFields fields,
+ int timestamp,
+ double speed,
+ double direction,
+ double climb,
+ gpointer userdata) {
+ struct vehicle_priv *priv = vehicle_last;
+ int cb = FALSE;
+
+ if (fields & GYPSY_COURSE_FIELDS_SPEED) {
+ priv->speed = speed*3.6;
+ cb = TRUE;
+ }
+ if (fields & GYPSY_COURSE_FIELDS_DIRECTION) {
+ priv->direction = direction;
+ cb = TRUE;
+ }
+
+ if (cb)
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
/**
* @brief Attempt to open the gypsy device.
- *
+ *
* Tells gypsy wich functions to call when anything occours.
*
* @param data
* @returns TRUE to try again; FALSE if retry not required
*/
static gboolean
-vehicle_gypsy_try_open(gpointer *data)
-{
- struct vehicle_priv *priv = (struct vehicle_priv *)data;
- char *source = g_strdup(priv->source);
-
- GError *error = NULL;
-
- g_type_init();
- priv->control = gypsy_control_get_default();
- priv->path = gypsy_control_create(priv->control, source+8, &error);
- if (priv->path == NULL) {
- g_warning ("Error creating gypsy conrtol path for %s: %s", source+8, error->message);
- return TRUE;
- }
-
- priv->position = gypsy_position_new(priv->path);
- g_signal_connect(priv->position, "position-changed", G_CALLBACK (vehicle_gypsy_position_changed), NULL);
-
- priv->satellite = gypsy_satellite_new(priv->path);
- g_signal_connect(priv->satellite, "satellites-changed", G_CALLBACK (vehicle_gypsy_satellite_changed), NULL);
-
- priv->course = gypsy_course_new(priv->path);
- g_signal_connect(priv->course, "course-changed", G_CALLBACK (vehicle_gypsy_course_changed), NULL);
-
- priv->device = gypsy_device_new(priv->path);
- g_signal_connect(priv->device, "fix-status-changed", G_CALLBACK (vehicle_gypsy_fixstatus_changed), NULL);
-
- gypsy_device_start(priv->device, &error);
- if (error != NULL) {
- g_warning ("Error starting gypsy for %s: %s", source+8, error->message);
- return TRUE;
- }
-
- vehicle_last = priv;
- dbg(lvl_debug,"gypsy connected to %d", source+8);
- g_free(source);
- return FALSE;
+vehicle_gypsy_try_open(gpointer *data) {
+ struct vehicle_priv *priv = (struct vehicle_priv *)data;
+ char *source = g_strdup(priv->source);
+
+ GError *error = NULL;
+
+ g_type_init();
+ priv->control = gypsy_control_get_default();
+ priv->path = gypsy_control_create(priv->control, source+8, &error);
+ if (priv->path == NULL) {
+ g_warning ("Error creating gypsy conrtol path for %s: %s", source+8, error->message);
+ return TRUE;
+ }
+
+ priv->position = gypsy_position_new(priv->path);
+ g_signal_connect(priv->position, "position-changed", G_CALLBACK (vehicle_gypsy_position_changed), NULL);
+
+ priv->satellite = gypsy_satellite_new(priv->path);
+ g_signal_connect(priv->satellite, "satellites-changed", G_CALLBACK (vehicle_gypsy_satellite_changed), NULL);
+
+ priv->course = gypsy_course_new(priv->path);
+ g_signal_connect(priv->course, "course-changed", G_CALLBACK (vehicle_gypsy_course_changed), NULL);
+
+ priv->device = gypsy_device_new(priv->path);
+ g_signal_connect(priv->device, "fix-status-changed", G_CALLBACK (vehicle_gypsy_fixstatus_changed), NULL);
+
+ gypsy_device_start(priv->device, &error);
+ if (error != NULL) {
+ g_warning ("Error starting gypsy for %s: %s", source+8, error->message);
+ return TRUE;
+ }
+
+ vehicle_last = priv;
+ dbg(lvl_debug,"gypsy connected to %d", source+8);
+ g_free(source);
+ return FALSE;
}
/**
* @brief Open a connection to gypsy. Will re-try the connection if it fails
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_gypsy_open(struct vehicle_priv *priv)
-{
- priv->retry_timer=0;
- if (vehicle_gypsy_try_open((gpointer *)priv)) {
- priv->retry_timer = g_timeout_add(priv->retry_interval*1000, (GSourceFunc)vehicle_gypsy_try_open, (gpointer *)priv);
- }
+vehicle_gypsy_open(struct vehicle_priv *priv) {
+ priv->retry_timer=0;
+ if (vehicle_gypsy_try_open((gpointer *)priv)) {
+ priv->retry_timer = g_timeout_add(priv->retry_interval*1000, (GSourceFunc)vehicle_gypsy_try_open, (gpointer *)priv);
+ }
}
/**
* @brief Stop retry timer; Free alloced memory
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_gypsy_close(struct vehicle_priv *priv)
-{
- if (priv->retry_timer) {
- g_source_remove(priv->retry_timer);
- priv->retry_timer=0;
- }
- if (priv->path)
- g_free(priv->path);
-
- if (priv->position)
- g_free(priv->position);
-
- if (priv->satellite)
- g_free(priv->satellite);
-
- if (priv->course)
- g_free(priv->course);
-
- if (priv->device)
- g_free(priv->device);
-
- if (priv->control)
- g_object_unref(G_OBJECT (priv->control));
+vehicle_gypsy_close(struct vehicle_priv *priv) {
+ if (priv->retry_timer) {
+ g_source_remove(priv->retry_timer);
+ priv->retry_timer=0;
+ }
+ if (priv->path)
+ g_free(priv->path);
+
+ if (priv->position)
+ g_free(priv->position);
+
+ if (priv->satellite)
+ g_free(priv->satellite);
+
+ if (priv->course)
+ g_free(priv->course);
+
+ if (priv->device)
+ g_free(priv->device);
+
+ if (priv->control)
+ g_object_unref(G_OBJECT (priv->control));
}
/**
* @brief Free the gypsy_vehicle
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_gypsy_destroy(struct vehicle_priv *priv)
-{
- vehicle_gypsy_close(priv);
- if (priv->source)
- g_free(priv->source);
- g_free(priv);
+vehicle_gypsy_destroy(struct vehicle_priv *priv) {
+ vehicle_gypsy_close(priv);
+ if (priv->source)
+ g_free(priv->source);
+ g_free(priv);
}
/**
* @brief Provide the outside with information
- *
+ *
* @param priv
* @param type TODO: What can this be?
* @param attr
@@ -369,68 +355,66 @@ vehicle_gypsy_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_gypsy_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- struct attr * active=NULL;
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->fix_type;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- if (!priv->have_cords)
- return 0;
- break;
- case attr_position_time_iso8601:
- {
- struct tm tm;
- if (!priv->fix_time)
- return 0;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- } else
- return 0;
- }
- case attr_active:
- active = attr_search(priv->attrs,NULL,attr_active);
- if(active != NULL && active->u.num == 1)
- return 1;
- else
- return 0;
- break;
-
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ struct attr * active=NULL;
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->fix_type;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ if (!priv->have_cords)
+ return 0;
+ break;
+ case attr_position_time_iso8601: {
+ struct tm tm;
+ if (!priv->fix_time)
+ return 0;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else
+ return 0;
+ }
+ case attr_active:
+ active = attr_search(priv->attrs,NULL,attr_active);
+ if(active != NULL && active->u.num == 1)
+ return 1;
+ else
+ return 0;
+ break;
+
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
struct vehicle_methods vehicle_gypsy_methods = {
- vehicle_gypsy_destroy,
- vehicle_gypsy_position_attr_get,
+ vehicle_gypsy_destroy,
+ vehicle_gypsy_position_attr_get,
};
/**
* @brief Create gypsy_vehicle
- *
+ *
* @param meth
* @param cbl
* @param attrs
@@ -438,66 +422,64 @@ struct vehicle_methods vehicle_gypsy_methods = {
*/
static struct vehicle_priv *
vehicle_gypsy_new_gypsy(struct vehicle_methods *meth,
- struct callback_list *cbl,
- struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source, *retry_int;
+ struct callback_list *cbl,
+ struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source, *retry_int;
#if defined(USE_BINDING_DBUS) && defined(HAVE_UNISTD_H)
- DBusConnection *conn;
- DBusMessage *message;
- dbus_uint32_t serial,pid=getpid();
- struct attr *destination,*path,*interface,*method;
-
- destination=attr_search(attrs, NULL, attr_dbus_destination);
- path=attr_search(attrs, NULL, attr_dbus_path);
- interface=attr_search(attrs, NULL, attr_dbus_interface);
- method=attr_search(attrs, NULL, attr_dbus_method);
- if (destination && path && interface && method) {
- conn=dbus_bus_get(DBUS_BUS_SESSION, NULL);
- if (conn) {
- message=dbus_message_new_method_call(destination->u.str,path->u.str,interface->u.str,method->u.str);
- dbus_message_append_args(message, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
- dbus_connection_send(conn, message, &serial);
- dbus_message_unref(message);
- dbus_connection_unref(conn);
- } else {
- dbg(lvl_error,"failed to connect to session bus");
- }
- }
+ DBusConnection *conn;
+ DBusMessage *message;
+ dbus_uint32_t serial,pid=getpid();
+ struct attr *destination,*path,*interface,*method;
+
+ destination=attr_search(attrs, NULL, attr_dbus_destination);
+ path=attr_search(attrs, NULL, attr_dbus_path);
+ interface=attr_search(attrs, NULL, attr_dbus_interface);
+ method=attr_search(attrs, NULL, attr_dbus_method);
+ if (destination && path && interface && method) {
+ conn=dbus_bus_get(DBUS_BUS_SESSION, NULL);
+ if (conn) {
+ message=dbus_message_new_method_call(destination->u.str,path->u.str,interface->u.str,method->u.str);
+ dbus_message_append_args(message, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
+ dbus_connection_send(conn, message, &serial);
+ dbus_message_unref(message);
+ dbus_connection_unref(conn);
+ } else {
+ dbg(lvl_error,"failed to connect to session bus");
+ }
+ }
#endif
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- ret = g_new0(struct vehicle_priv, 1);
- ret->have_cords = 0;
- ret->source = g_strdup(source->u.str);
- ret->attrs = attrs;
- retry_int = attr_search(attrs, NULL, attr_retry_interval);
- if (retry_int) {
- ret->retry_interval = retry_int->u.num;
- if (ret->retry_interval < MIN_RETRY_INTERVAL) {
- dbg(lvl_error, "Retry interval %d too small, setting to %d", ret->retry_interval, MIN_RETRY_INTERVAL);
- ret->retry_interval = MIN_RETRY_INTERVAL;
- }
- } else {
- dbg(lvl_error, "Retry interval not defined, setting to %d", DEFAULT_RETRY_INTERVAL);
- ret->retry_interval = DEFAULT_RETRY_INTERVAL;
- }
- ret->cbl = cbl;
- *meth = vehicle_gypsy_methods;
- vehicle_gypsy_open(ret);
- return ret;
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->have_cords = 0;
+ ret->source = g_strdup(source->u.str);
+ ret->attrs = attrs;
+ retry_int = attr_search(attrs, NULL, attr_retry_interval);
+ if (retry_int) {
+ ret->retry_interval = retry_int->u.num;
+ if (ret->retry_interval < MIN_RETRY_INTERVAL) {
+ dbg(lvl_error, "Retry interval %d too small, setting to %d", ret->retry_interval, MIN_RETRY_INTERVAL);
+ ret->retry_interval = MIN_RETRY_INTERVAL;
+ }
+ } else {
+ dbg(lvl_error, "Retry interval not defined, setting to %d", DEFAULT_RETRY_INTERVAL);
+ ret->retry_interval = DEFAULT_RETRY_INTERVAL;
+ }
+ ret->cbl = cbl;
+ *meth = vehicle_gypsy_methods;
+ vehicle_gypsy_open(ret);
+ return ret;
}
/**
* @brief register vehicle_gypsy
- *
+ *
* @returns nothing
*/
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("gypsy", vehicle_gypsy_new_gypsy);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("gypsy", vehicle_gypsy_new_gypsy);
}
diff --git a/navit/vehicle/iphone/vehicle_iphone.c b/navit/vehicle/iphone/vehicle_iphone.c
index 28ac0beff..74429a954 100644
--- a/navit/vehicle/iphone/vehicle_iphone.c
+++ b/navit/vehicle/iphone/vehicle_iphone.c
@@ -42,132 +42,127 @@
*/
struct vehicle_priv {
- int interval;
- int position_set;
- struct callback_list *cbl;
- struct navit *navit;
- struct coord_geo geo;
- struct coord last;
- double config_speed;
- double speed;
- double direction;
- double radius;
- struct callback *timer_callback;
- struct event_timeout *timer;
- char str_time[200];
+ int interval;
+ int position_set;
+ struct callback_list *cbl;
+ struct navit *navit;
+ struct coord_geo geo;
+ struct coord last;
+ double config_speed;
+ double speed;
+ double direction;
+ double radius;
+ struct callback *timer_callback;
+ struct event_timeout *timer;
+ char str_time[200];
};
static void
-vehicle_iphone_destroy(struct vehicle_priv *priv)
-{
- corelocation_exit();
- g_free(priv);
+vehicle_iphone_destroy(struct vehicle_priv *priv) {
+ corelocation_exit();
+ g_free(priv);
}
static int
vehicle_iphone_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_time_iso8601:
- attr->u.str = priv->str_time;
- break;
- case attr_position_radius:
- attr->u.numd = &priv->radius;
- break;
- case attr_position_nmea:
- return 0;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601:
+ attr->u.str = priv->str_time;
+ break;
+ case attr_position_radius:
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_nmea:
+ return 0;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static int
-vehicle_iphone_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- if (attr->type == attr_navit) {
- priv->navit = attr->u.navit;
- return 1;
- }
- return 0;
+vehicle_iphone_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ if (attr->type == attr_navit) {
+ priv->navit = attr->u.navit;
+ return 1;
+ }
+ return 0;
}
struct vehicle_methods vehicle_iphone_methods = {
- vehicle_iphone_destroy,
- vehicle_iphone_position_attr_get,
- vehicle_iphone_set_attr,
+ vehicle_iphone_destroy,
+ vehicle_iphone_position_attr_get,
+ vehicle_iphone_set_attr,
};
void
-vehicle_iphone_update(void *arg,
- double lat,
- double lng,
- double dir,
- double spd,
- char * str_time,
- double radius
- )
-{
- struct vehicle_priv * priv = arg;
- priv->geo.lat = lat;
- priv->geo.lng = lng;
- if(dir > 0) priv->direction = dir;
- if(spd > 0) priv->speed = spd*3.6;
- strcpy(priv->str_time, str_time);
- priv->radius = radius;
-
- dbg(lvl_debug,"position_get lat:%f lng:%f (spd:%f dir:%f time:%s)", priv->geo.lat, priv->geo.lng, priv->speed, priv->direction, priv->str_time);
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_iphone_update(void *arg,
+ double lat,
+ double lng,
+ double dir,
+ double spd,
+ char * str_time,
+ double radius
+ ) {
+ struct vehicle_priv * priv = arg;
+ priv->geo.lat = lat;
+ priv->geo.lng = lng;
+ if(dir > 0) priv->direction = dir;
+ if(spd > 0) priv->speed = spd*3.6;
+ strcpy(priv->str_time, str_time);
+ priv->radius = radius;
+
+ dbg(lvl_debug,"position_get lat:%f lng:%f (spd:%f dir:%f time:%s)", priv->geo.lat, priv->geo.lng, priv->speed,
+ priv->direction, priv->str_time);
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
static struct vehicle_priv *
vehicle_iphone_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *interval,*speed,*position_coord_geo;
-
- dbg(lvl_debug, "enter");
- ret = g_new0(struct vehicle_priv, 1);
- ret->cbl = cbl;
- ret->interval=1000;
- ret->config_speed=40;
- if ((speed=attr_search(attrs, NULL, attr_speed))) {
- ret->config_speed=speed->u.num;
- }
- if ((interval=attr_search(attrs, NULL, attr_interval)))
- ret->interval=interval->u.num;
- if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
- ret->geo=*(position_coord_geo->u.coord_geo);
- ret->position_set=1;
- dbg(lvl_debug,"position_set %f %f", ret->geo.lat, ret->geo.lng);
- }
- *meth = vehicle_iphone_methods;
- ret->str_time[0] = '\0';
-
- /** Initialize corelocation */
- corelocation_init(ret, vehicle_iphone_update);
-
- return ret;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *interval,*speed,*position_coord_geo;
+
+ dbg(lvl_debug, "enter");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ ret->interval=1000;
+ ret->config_speed=40;
+ if ((speed=attr_search(attrs, NULL, attr_speed))) {
+ ret->config_speed=speed->u.num;
+ }
+ if ((interval=attr_search(attrs, NULL, attr_interval)))
+ ret->interval=interval->u.num;
+ if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
+ ret->geo=*(position_coord_geo->u.coord_geo);
+ ret->position_set=1;
+ dbg(lvl_debug,"position_set %f %f", ret->geo.lat, ret->geo.lng);
+ }
+ *meth = vehicle_iphone_methods;
+ ret->str_time[0] = '\0';
+
+ /** Initialize corelocation */
+ corelocation_init(ret, vehicle_iphone_update);
+
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("iphone", vehicle_iphone_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("iphone", vehicle_iphone_new);
}
diff --git a/navit/vehicle/maemo/vehicle_maemo.c b/navit/vehicle/maemo/vehicle_maemo.c
index 2ff6296d5..badbde9c5 100644
--- a/navit/vehicle/maemo/vehicle_maemo.c
+++ b/navit/vehicle/maemo/vehicle_maemo.c
@@ -46,289 +46,283 @@
*/
static struct vehicle_priv {
- LocationGPSDControl *control;
- LocationGPSDevice *device;
- char *source;
- guint retry_interval;
- struct callback_list *cbl;
- struct attr ** attrs;
- int sats; // satellites_in_view
- int sats_used; //satellites_in_user
- int fix_type; //mode
- struct coord_geo geo; //lattigute&longittude
- double speed; //speed:)
- double direction; //track
- double height; //altitude
- double hdop; //eph
- time_t fix_time; //time
- char fixiso8601[128];
+ LocationGPSDControl *control;
+ LocationGPSDevice *device;
+ char *source;
+ guint retry_interval;
+ struct callback_list *cbl;
+ struct attr ** attrs;
+ int sats; // satellites_in_view
+ int sats_used; //satellites_in_user
+ int fix_type; //mode
+ struct coord_geo geo; //lattigute&longittude
+ double speed; //speed:)
+ double direction; //track
+ double height; //altitude
+ double hdop; //eph
+ time_t fix_time; //time
+ char fixiso8601[128];
};
-
+
static void vehicle_maemo_callback(LocationGPSDevice *device, gpointer user_data) {
- struct vehicle_priv *priv=(struct vehicle_priv*)user_data;
-
- priv->sats=device->satellites_in_view;
- priv->sats_used=device->satellites_in_use;
- callback_list_call_attr_0(priv->cbl, attr_position_sats);
-
- dbg(lvl_debug,"Got update with %u/%u satellites",priv->sats_used,priv->sats);
-
- if (device->fix) {
- switch(device->fix->mode) {
- case LOCATION_GPS_DEVICE_MODE_NOT_SEEN:
- case LOCATION_GPS_DEVICE_MODE_NO_FIX:
- priv->fix_type=0;
- break;
- case LOCATION_GPS_DEVICE_MODE_2D:
- case LOCATION_GPS_DEVICE_MODE_3D:
- priv->fix_type=1;
- break;
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
- priv->geo.lat=device->fix->latitude;
- priv->geo.lng=device->fix->longitude;
- priv->hdop=device->fix->eph/100;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- dbg(lvl_debug,"Position: %f %f with error %f meters",priv->geo.lat,priv->geo.lng,priv->hdop);
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
- priv->speed=device->fix->speed;
- callback_list_call_attr_0(priv->cbl, attr_position_speed);
- dbg(lvl_debug,"Speed: %f ",priv->speed);
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
- priv->direction=device->fix->track;
- dbg(lvl_debug,"Direction: %f",priv->direction);
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
- priv->fix_time=device->fix->time;
- dbg(lvl_debug,"Time: %f",priv->fix_time);
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
- priv->height=device->fix->altitude;
- dbg(lvl_debug,"Elevation: %f",priv->height);
- }
-
- }
-
- return;
+ struct vehicle_priv *priv=(struct vehicle_priv*)user_data;
+
+ priv->sats=device->satellites_in_view;
+ priv->sats_used=device->satellites_in_use;
+ callback_list_call_attr_0(priv->cbl, attr_position_sats);
+
+ dbg(lvl_debug,"Got update with %u/%u satellites",priv->sats_used,priv->sats);
+
+ if (device->fix) {
+ switch(device->fix->mode) {
+ case LOCATION_GPS_DEVICE_MODE_NOT_SEEN:
+ case LOCATION_GPS_DEVICE_MODE_NO_FIX:
+ priv->fix_type=0;
+ break;
+ case LOCATION_GPS_DEVICE_MODE_2D:
+ case LOCATION_GPS_DEVICE_MODE_3D:
+ priv->fix_type=1;
+ break;
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
+ priv->geo.lat=device->fix->latitude;
+ priv->geo.lng=device->fix->longitude;
+ priv->hdop=device->fix->eph/100;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ dbg(lvl_debug,"Position: %f %f with error %f meters",priv->geo.lat,priv->geo.lng,priv->hdop);
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
+ priv->speed=device->fix->speed;
+ callback_list_call_attr_0(priv->cbl, attr_position_speed);
+ dbg(lvl_debug,"Speed: %f ",priv->speed);
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
+ priv->direction=device->fix->track;
+ dbg(lvl_debug,"Direction: %f",priv->direction);
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
+ priv->fix_time=device->fix->time;
+ dbg(lvl_debug,"Time: %f",priv->fix_time);
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
+ priv->height=device->fix->altitude;
+ dbg(lvl_debug,"Elevation: %f",priv->height);
+ }
+
+ }
+
+ return;
}
-
-static void vehicle_maemo_error(LocationGPSDControl *control, LocationGPSDControlError error, gpointer user_data)
-{
- switch (error) {
- case LOCATION_ERROR_USER_REJECTED_DIALOG:
- dbg(lvl_error,"User didn't enable requested methods");
- break;
- case LOCATION_ERROR_USER_REJECTED_SETTINGS:
- dbg(lvl_error,"User changed settings, which disabled location");
- break;
- case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE:
- dbg(lvl_error,"Problems with BT GPS");
- break;
- case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE:
- dbg(lvl_error,"Requested method is not allowed in offline mode");
- break;
- case LOCATION_ERROR_SYSTEM:
- dbg(lvl_error,"System error");
- break;
- }
+
+static void vehicle_maemo_error(LocationGPSDControl *control, LocationGPSDControlError error, gpointer user_data) {
+ switch (error) {
+ case LOCATION_ERROR_USER_REJECTED_DIALOG:
+ dbg(lvl_error,"User didn't enable requested methods");
+ break;
+ case LOCATION_ERROR_USER_REJECTED_SETTINGS:
+ dbg(lvl_error,"User changed settings, which disabled location");
+ break;
+ case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE:
+ dbg(lvl_error,"Problems with BT GPS");
+ break;
+ case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE:
+ dbg(lvl_error,"Requested method is not allowed in offline mode");
+ break;
+ case LOCATION_ERROR_SYSTEM:
+ dbg(lvl_error,"System error");
+ break;
+ }
}
/**
* Instantiate liblocation objects
*/
static void
-vehicle_maemo_open(struct vehicle_priv *priv)
-{
-
- priv->control = location_gpsd_control_get_default();
- priv->device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
-
- if (!strcasecmp(priv->source+8,"cwp")) {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_CWP, NULL);
- dbg(lvl_debug,"Method set: CWP");
- } else if (!strcasecmp(priv->source+8,"acwp")) {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
- dbg(lvl_debug,"Method set: ACWP");
- } else if (!strcasecmp(priv->source+8,"gnss")) {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_GNSS, NULL);
- dbg(lvl_debug,"Method set: GNSS");
- } else if (!strcasecmp(priv->source+8,"agnss")) {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
- dbg(lvl_debug,"Method set: AGNSS");
- } else {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_USER_SELECTED, NULL);
- dbg(lvl_debug,"Method set: ANY");
- }
-
- switch (priv->retry_interval) {
- case 2:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_2S, NULL);
- dbg(lvl_debug,"Interval set: 2s");
- break;
- case 5:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_5S, NULL);
- dbg(lvl_debug,"Interval set: 5s");
- break;
- case 10:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_10S, NULL);
- dbg(lvl_debug,"Interval set: 10s");
- break;
- case 20:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_20S, NULL);
- dbg(lvl_debug,"Interval set: 20s");
- break;
- case 30:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_30S, NULL);
- dbg(lvl_debug,"Interval set: 30s");
- break;
- case 60:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_60S, NULL);
- dbg(lvl_debug,"Interval set: 60s");
- break;
- case 120:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_120S, NULL);
- dbg(lvl_debug,"Interval set: 120s");
- break;
- case 1:
- default:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_1S, NULL);
- dbg(lvl_debug,"Interval set: 1s");
- break;
- }
-
- g_signal_connect(priv->device, "changed", G_CALLBACK(vehicle_maemo_callback), priv);
- g_signal_connect(priv->control, "error-verbose", G_CALLBACK(vehicle_maemo_error), priv);
-
- location_gpsd_control_start(priv->control);
-
- return;
+vehicle_maemo_open(struct vehicle_priv *priv) {
+
+ priv->control = location_gpsd_control_get_default();
+ priv->device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
+
+ if (!strcasecmp(priv->source+8,"cwp")) {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_CWP, NULL);
+ dbg(lvl_debug,"Method set: CWP");
+ } else if (!strcasecmp(priv->source+8,"acwp")) {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
+ dbg(lvl_debug,"Method set: ACWP");
+ } else if (!strcasecmp(priv->source+8,"gnss")) {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_GNSS, NULL);
+ dbg(lvl_debug,"Method set: GNSS");
+ } else if (!strcasecmp(priv->source+8,"agnss")) {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
+ dbg(lvl_debug,"Method set: AGNSS");
+ } else {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_USER_SELECTED, NULL);
+ dbg(lvl_debug,"Method set: ANY");
+ }
+
+ switch (priv->retry_interval) {
+ case 2:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_2S, NULL);
+ dbg(lvl_debug,"Interval set: 2s");
+ break;
+ case 5:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_5S, NULL);
+ dbg(lvl_debug,"Interval set: 5s");
+ break;
+ case 10:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_10S, NULL);
+ dbg(lvl_debug,"Interval set: 10s");
+ break;
+ case 20:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_20S, NULL);
+ dbg(lvl_debug,"Interval set: 20s");
+ break;
+ case 30:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_30S, NULL);
+ dbg(lvl_debug,"Interval set: 30s");
+ break;
+ case 60:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_60S, NULL);
+ dbg(lvl_debug,"Interval set: 60s");
+ break;
+ case 120:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_120S, NULL);
+ dbg(lvl_debug,"Interval set: 120s");
+ break;
+ case 1:
+ default:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_1S, NULL);
+ dbg(lvl_debug,"Interval set: 1s");
+ break;
+ }
+
+ g_signal_connect(priv->device, "changed", G_CALLBACK(vehicle_maemo_callback), priv);
+ g_signal_connect(priv->control, "error-verbose", G_CALLBACK(vehicle_maemo_error), priv);
+
+ location_gpsd_control_start(priv->control);
+
+ return;
}
static void
-vehicle_maemo_destroy(struct vehicle_priv *priv)
-{
- location_gpsd_control_stop(priv->control);
+vehicle_maemo_destroy(struct vehicle_priv *priv) {
+ location_gpsd_control_stop(priv->control);
- g_object_unref(priv->device);
- g_object_unref(priv->control);
+ g_object_unref(priv->device);
+ g_object_unref(priv->control);
- return;
+ return;
}
static int
vehicle_maemo_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- struct attr * active=NULL;
- switch (type) {
- case attr_position_fix_type:
- dbg(lvl_debug,"Attr requested: position_fix_type");
- attr->u.num = priv->fix_type;
- break;
- case attr_position_height:
- dbg(lvl_debug,"Attr requested: position_height");
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- dbg(lvl_debug,"Attr requested: position_speed");
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- dbg(lvl_debug,"Attr requested: position_direction");
- attr->u.numd = &priv->direction;
- break;
- case attr_position_hdop:
- dbg(lvl_debug,"Attr requested: position_hdop");
- attr->u.numd = &priv->hdop;
- break;
- case attr_position_sats:
- dbg(lvl_debug,"Attr requested: position_sats");
- attr->u.num = priv->sats;
- break;
- case attr_position_sats_used:
- dbg(lvl_debug,"Attr requested: position_sats_used");
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- dbg(lvl_debug,"Attr requested: position_coord_geo");
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_time_iso8601:
- {
- struct tm tm;
- dbg(lvl_debug,"Attr requested: position_time_iso8601");
- if (!priv->fix_time)
- return 0;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- } else
- return 0;
- }
- break;
- case attr_active:
- dbg(lvl_debug,"Attr requested: position_active");
- active = attr_search(priv->attrs,NULL,attr_active);
- if(active != NULL) {
- attr->u.num=active->u.num;
- return 1;
- } else
- return 0;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ struct attr * active=NULL;
+ switch (type) {
+ case attr_position_fix_type:
+ dbg(lvl_debug,"Attr requested: position_fix_type");
+ attr->u.num = priv->fix_type;
+ break;
+ case attr_position_height:
+ dbg(lvl_debug,"Attr requested: position_height");
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ dbg(lvl_debug,"Attr requested: position_speed");
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ dbg(lvl_debug,"Attr requested: position_direction");
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_hdop:
+ dbg(lvl_debug,"Attr requested: position_hdop");
+ attr->u.numd = &priv->hdop;
+ break;
+ case attr_position_sats:
+ dbg(lvl_debug,"Attr requested: position_sats");
+ attr->u.num = priv->sats;
+ break;
+ case attr_position_sats_used:
+ dbg(lvl_debug,"Attr requested: position_sats_used");
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ dbg(lvl_debug,"Attr requested: position_coord_geo");
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601: {
+ struct tm tm;
+ dbg(lvl_debug,"Attr requested: position_time_iso8601");
+ if (!priv->fix_time)
+ return 0;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else
+ return 0;
+ }
+ break;
+ case attr_active:
+ dbg(lvl_debug,"Attr requested: position_active");
+ active = attr_search(priv->attrs,NULL,attr_active);
+ if(active != NULL) {
+ attr->u.num=active->u.num;
+ return 1;
+ } else
+ return 0;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
struct vehicle_methods vehicle_maemo_methods = {
- vehicle_maemo_destroy,
- vehicle_maemo_position_attr_get,
+ vehicle_maemo_destroy,
+ vehicle_maemo_position_attr_get,
};
static struct vehicle_priv *
vehicle_maemo_new_maemo(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source, *retry_int;
-
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- ret = g_new0(struct vehicle_priv, 1);
- ret->source = g_strdup(source->u.str);
- retry_int = attr_search(attrs, NULL, attr_retry_interval);
- if (retry_int) {
- ret->retry_interval = retry_int->u.num;
- if (ret->retry_interval !=1 && ret->retry_interval !=2 && ret->retry_interval !=5 && ret->retry_interval !=10 && ret->retry_interval !=20 && ret->retry_interval !=30 && ret->retry_interval !=60 && ret->retry_interval !=120 ) {
- dbg(lvl_error, "Retry interval %d invalid, setting to 1", ret->retry_interval,1);
- ret->retry_interval = 1;
- }
- } else {
- ret->retry_interval = 1;
- }
- dbg(lvl_debug,"source: %s, interval: %u",ret->source,ret->retry_interval);
- ret->cbl = cbl;
- *meth = vehicle_maemo_methods;
- ret->attrs = attrs;
- vehicle_maemo_open(ret);
- return ret;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source, *retry_int;
+
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->source = g_strdup(source->u.str);
+ retry_int = attr_search(attrs, NULL, attr_retry_interval);
+ if (retry_int) {
+ ret->retry_interval = retry_int->u.num;
+ if (ret->retry_interval !=1 && ret->retry_interval !=2 && ret->retry_interval !=5 && ret->retry_interval !=10
+ && ret->retry_interval !=20 && ret->retry_interval !=30 && ret->retry_interval !=60 && ret->retry_interval !=120 ) {
+ dbg(lvl_error, "Retry interval %d invalid, setting to 1", ret->retry_interval,1);
+ ret->retry_interval = 1;
+ }
+ } else {
+ ret->retry_interval = 1;
+ }
+ dbg(lvl_debug,"source: %s, interval: %u",ret->source,ret->retry_interval);
+ ret->cbl = cbl;
+ *meth = vehicle_maemo_methods;
+ ret->attrs = attrs;
+ vehicle_maemo_open(ret);
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("maemo", vehicle_maemo_new_maemo);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("maemo", vehicle_maemo_new_maemo);
}
diff --git a/navit/vehicle/null/vehicle_null.c b/navit/vehicle/null/vehicle_null.c
index ea990a31e..1d67a6a1a 100644
--- a/navit/vehicle/null/vehicle_null.c
+++ b/navit/vehicle/null/vehicle_null.c
@@ -43,37 +43,36 @@
*/
struct vehicle_priv {
- struct callback_list *cbl;
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- double radius;
- int fix_type;
- time_t fix_time;
- char fixiso8601[128];
- int sats;
- int sats_used;
- int have_coords;
- struct attr ** attrs;
+ struct callback_list *cbl;
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ double radius;
+ int fix_type;
+ time_t fix_time;
+ char fixiso8601[128];
+ int sats;
+ int sats_used;
+ int have_coords;
+ struct attr ** attrs;
};
/**
* @brief Free the null_vehicle
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_null_destroy(struct vehicle_priv *priv)
-{
- dbg(lvl_debug,"enter");
- g_free(priv);
+vehicle_null_destroy(struct vehicle_priv *priv) {
+ dbg(lvl_debug,"enter");
+ g_free(priv);
}
/**
* @brief Provide the outside with information
- *
+ *
* @param priv
* @param type TODO: What can this be?
* @param attr
@@ -81,69 +80,67 @@ vehicle_null_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_null_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- dbg(lvl_debug,"enter %s",attr_to_name(type));
- switch (type) {
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_radius:
- attr->u.numd = &priv->radius;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- if (!priv->have_coords)
- return 0;
- break;
- case attr_position_time_iso8601:
- attr->u.str=priv->fixiso8601;
- break;
- default:
- return 0;
- }
- dbg(lvl_debug,"ok");
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ dbg(lvl_debug,"enter %s",attr_to_name(type));
+ switch (type) {
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_radius:
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ if (!priv->have_coords)
+ return 0;
+ break;
+ case attr_position_time_iso8601:
+ attr->u.str=priv->fixiso8601;
+ break;
+ default:
+ return 0;
+ }
+ dbg(lvl_debug,"ok");
+ attr->type = type;
+ return 1;
}
static int
-vehicle_null_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- switch (attr->type) {
- case attr_position_speed:
- priv->speed=*attr->u.numd;
- break;
- case attr_position_direction:
- priv->direction=*attr->u.numd;
- break;
- case attr_position_coord_geo:
- priv->geo=*attr->u.coord_geo;
- priv->have_coords=1;
- break;
- default:
- break;
- }
- callback_list_call_attr_0(priv->cbl, attr->type);
- return 1;
+vehicle_null_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ switch (attr->type) {
+ case attr_position_speed:
+ priv->speed=*attr->u.numd;
+ break;
+ case attr_position_direction:
+ priv->direction=*attr->u.numd;
+ break;
+ case attr_position_coord_geo:
+ priv->geo=*attr->u.coord_geo;
+ priv->have_coords=1;
+ break;
+ default:
+ break;
+ }
+ callback_list_call_attr_0(priv->cbl, attr->type);
+ return 1;
}
struct vehicle_methods vehicle_null_methods = {
- vehicle_null_destroy,
- vehicle_null_position_attr_get,
- vehicle_null_set_attr,
+ vehicle_null_destroy,
+ vehicle_null_position_attr_get,
+ vehicle_null_set_attr,
};
/**
* @brief Create null_vehicle
- *
+ *
* @param meth
* @param cbl
* @param attrs
@@ -151,27 +148,25 @@ struct vehicle_methods vehicle_null_methods = {
*/
static struct vehicle_priv *
vehicle_null_new_null(struct vehicle_methods *meth,
- struct callback_list *cbl,
- struct attr **attrs)
-{
- struct vehicle_priv *ret;
+ struct callback_list *cbl,
+ struct attr **attrs) {
+ struct vehicle_priv *ret;
- dbg(lvl_debug, "enter");
- ret = g_new0(struct vehicle_priv, 1);
- ret->cbl = cbl;
- *meth = vehicle_null_methods;
- dbg(lvl_debug, "return");
- return ret;
+ dbg(lvl_debug, "enter");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ *meth = vehicle_null_methods;
+ dbg(lvl_debug, "return");
+ return ret;
}
/**
* @brief register vehicle_null
- *
+ *
* @returns nothing
*/
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("null", vehicle_null_new_null);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("null", vehicle_null_new_null);
}
diff --git a/navit/vehicle/qt5/vehicle_qt5.cpp b/navit/vehicle/qt5/vehicle_qt5.cpp
index 6d263a649..9f0ad7cbc 100644
--- a/navit/vehicle/qt5/vehicle_qt5.cpp
+++ b/navit/vehicle/qt5/vehicle_qt5.cpp
@@ -50,33 +50,31 @@ extern "C" {
*/
QNavitGeoReceiver::QNavitGeoReceiver(QObject* parent, struct vehicle_priv* c)
- : QObject(parent)
-{
+ : QObject(parent) {
priv = c;
if (priv->source != NULL) {
connect(priv->source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
}
if (priv->satellites != NULL) {
- connect(priv->satellites, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)), this, SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)));
- connect(priv->satellites, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)), this, SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)));
+ connect(priv->satellites, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)), this,
+ SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)));
+ connect(priv->satellites, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)), this,
+ SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)));
}
}
-void QNavitGeoReceiver::satellitesInUseUpdated(const QList<QGeoSatelliteInfo>& sats)
-{
+void QNavitGeoReceiver::satellitesInUseUpdated(const QList<QGeoSatelliteInfo>& sats) {
dbg(lvl_debug, "Sats in use: %d", sats.count());
priv->sats_used = sats.count();
callback_list_call_attr_0(priv->cbl, attr_position_sats_used);
}
-void QNavitGeoReceiver::satellitesInViewUpdated(const QList<QGeoSatelliteInfo>& sats)
-{
+void QNavitGeoReceiver::satellitesInViewUpdated(const QList<QGeoSatelliteInfo>& sats) {
dbg(lvl_debug, "Sats in view: %d", sats.count());
priv->sats = sats.count();
callback_list_call_attr_0(priv->cbl, attr_position_qual);
}
-void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info)
-{
+void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info) {
/* ignore stale view */
if (info.coordinate().isValid()) {
@@ -135,13 +133,12 @@ void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info)
/**
* @brief Free the null_vehicle
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_qt5_destroy(struct vehicle_priv* priv)
-{
+vehicle_qt5_destroy(struct vehicle_priv* priv) {
dbg(lvl_debug, "enter");
if (priv->receiver != NULL)
delete priv->receiver;
@@ -152,7 +149,7 @@ vehicle_qt5_destroy(struct vehicle_priv* priv)
/**
* @brief Provide the outside with information
- *
+ *
* @param priv
* @param type TODO: What can this be?
* @param attr
@@ -160,8 +157,7 @@ vehicle_qt5_destroy(struct vehicle_priv* priv)
*/
static int
vehicle_qt5_position_attr_get(struct vehicle_priv* priv,
- enum attr_type type, struct attr* attr)
-{
+ enum attr_type type, struct attr* attr) {
struct attr* active = NULL;
dbg(lvl_debug, "enter %s", attr_to_name(type));
switch (type) {
@@ -199,7 +195,7 @@ vehicle_qt5_position_attr_get(struct vehicle_priv* priv,
struct tm tm;
if (gmtime_r(&priv->fix_time, &tm)) {
strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
+ "%Y-%m-%dT%TZ", &tm);
attr->u.str = priv->fixiso8601;
} else {
priv->fix_time = 0;
@@ -230,8 +226,7 @@ vehicle_qt5_position_attr_get(struct vehicle_priv* priv,
}
static int
-vehicle_qt5_set_attr(struct vehicle_priv* priv, struct attr* attr)
-{
+vehicle_qt5_set_attr(struct vehicle_priv* priv, struct attr* attr) {
switch (attr->type) {
case attr_position_speed:
priv->speed = *attr->u.numd;
@@ -258,7 +253,7 @@ struct vehicle_methods vehicle_null_methods = {
/**
* @brief Create null_vehicle
- *
+ *
* @param meth
* @param cbl
* @param attrs
@@ -266,9 +261,8 @@ struct vehicle_methods vehicle_null_methods = {
*/
static struct vehicle_priv*
vehicle_qt5_new_qt5(struct vehicle_methods* meth,
- struct callback_list* cbl,
- struct attr** attrs)
-{
+ struct callback_list* cbl,
+ struct attr** attrs) {
struct vehicle_priv* ret;
dbg(lvl_debug, "enter");
@@ -294,11 +288,10 @@ vehicle_qt5_new_qt5(struct vehicle_methods* meth,
/**
* @brief register vehicle_null
- *
+ *
* @returns nothing
*/
-void plugin_init(void)
-{
+void plugin_init(void) {
dbg(lvl_debug, "enter");
plugin_register_category_vehicle("qt5", vehicle_qt5_new_qt5);
}
diff --git a/navit/vehicle/webos/bluetooth.c b/navit/vehicle/webos/bluetooth.c
index 906a42b07..707478f7d 100644
--- a/navit/vehicle/webos/bluetooth.c
+++ b/navit/vehicle/webos/bluetooth.c
@@ -1,4 +1,4 @@
-/* vim: sw=3 ts=3
+/* vim: sw=3 ts=3
* */
#include <config.h>
@@ -22,594 +22,578 @@ static void vehicle_webos_spp_init_read(struct vehicle_priv *priv, unsigned int
/********************************************************************/
static void
-mlPDL_ServiceCall_callback(struct callback_list *cbl, char *service, char *parameters/*, struct callback *fail_cb*/)
-{
- PDL_Err err;
- dbg(lvl_debug,"PDL_ServiceCall(%s) parameters(%s)",service,parameters);
- err = PDL_ServiceCall(service, parameters);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_ServiceCall to (%s) with (%s) failed with (%d): (%s)", service, parameters, err, PDL_GetError());
- }
-
- callback_list_destroy(cbl);
- g_free(service);
- g_free(parameters);
+mlPDL_ServiceCall_callback(struct callback_list *cbl, char *service, char *parameters/*, struct callback *fail_cb*/) {
+ PDL_Err err;
+ dbg(lvl_debug,"PDL_ServiceCall(%s) parameters(%s)",service,parameters);
+ err = PDL_ServiceCall(service, parameters);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_ServiceCall to (%s) with (%s) failed with (%d): (%s)", service, parameters, err, PDL_GetError());
+ }
+
+ callback_list_destroy(cbl);
+ g_free(service);
+ g_free(parameters);
}
static void
-mlPDL_ServiceCall(const char *service, const char *parameters/*, struct callback *fail_cb = NULL*/)
-{
- struct callback *cb = NULL;
- struct callback_list *cbl = NULL;
+mlPDL_ServiceCall(const char *service, const char *parameters/*, struct callback *fail_cb = NULL*/) {
+ struct callback *cb = NULL;
+ struct callback_list *cbl = NULL;
- char *service2 = g_strdup(service);
- char *parameters2 = g_strdup(parameters);
+ char *service2 = g_strdup(service);
+ char *parameters2 = g_strdup(parameters);
- cbl = callback_list_new();
- cb = callback_new_3(callback_cast(mlPDL_ServiceCall_callback),cbl,service2,parameters2);
+ cbl = callback_list_new();
+ cb = callback_new_3(callback_cast(mlPDL_ServiceCall_callback),cbl,service2,parameters2);
- callback_list_add(cbl, cb);
+ callback_list_add(cbl, cb);
-dbg(lvl_debug,"event_call_callback(%p)",cbl);
- event_call_callback(cbl);
+ dbg(lvl_debug,"event_call_callback(%p)",cbl);
+ event_call_callback(cbl);
}
/********************************************************************/
static void
mlPDL_ServiceCallWithCallback_callback(struct callback_list *cbl,
- char *service,
- char *parameters,
- PDL_ServiceCallbackFunc callback,
- void *user,
- PDL_bool removeAfterResponse)
-{
- PDL_Err err;
- dbg(lvl_debug,"PDL_ServiceCallWithCallback(%s) parameters(%s)",service,parameters);
- err = PDL_ServiceCallWithCallback(service, parameters, callback, user, removeAfterResponse);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_ServiceCallWithCallback to (%s) with (%s) failed with (%d): (%s)", service, parameters, err, PDL_GetError());
- }
-
- callback_list_destroy(cbl);
- g_free(service);
- g_free(parameters);
+ char *service,
+ char *parameters,
+ PDL_ServiceCallbackFunc callback,
+ void *user,
+ PDL_bool removeAfterResponse) {
+ PDL_Err err;
+ dbg(lvl_debug,"PDL_ServiceCallWithCallback(%s) parameters(%s)",service,parameters);
+ err = PDL_ServiceCallWithCallback(service, parameters, callback, user, removeAfterResponse);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_ServiceCallWithCallback to (%s) with (%s) failed with (%d): (%s)", service, parameters, err,
+ PDL_GetError());
+ }
+
+ callback_list_destroy(cbl);
+ g_free(service);
+ g_free(parameters);
}
static void
mlPDL_ServiceCallWithCallback(const char *service,
- const char *parameters,
- PDL_ServiceCallbackFunc callback,
- void *user,
- PDL_bool removeAfterResponse)
-{
- struct callback *cb = NULL;
- struct callback_list *cbl = NULL;
+ const char *parameters,
+ PDL_ServiceCallbackFunc callback,
+ void *user,
+ PDL_bool removeAfterResponse) {
+ struct callback *cb = NULL;
+ struct callback_list *cbl = NULL;
- char *service2 = g_strdup(service);
- char *parameters2 = g_strdup(parameters);
+ char *service2 = g_strdup(service);
+ char *parameters2 = g_strdup(parameters);
- cbl = callback_list_new();
- cb = callback_new_args(callback_cast(mlPDL_ServiceCallWithCallback_callback),6,cbl,service2,parameters2,callback,user,removeAfterResponse);
+ cbl = callback_list_new();
+ cb = callback_new_args(callback_cast(mlPDL_ServiceCallWithCallback_callback),6,cbl,service2,parameters2,callback,user,
+ removeAfterResponse);
- callback_list_add(cbl, cb);
+ callback_list_add(cbl, cb);
- dbg(lvl_debug,"event_call_callback(%p)",cbl);
- event_call_callback(cbl);
+ dbg(lvl_debug,"event_call_callback(%p)",cbl);
+ event_call_callback(cbl);
}
/********************************************************************/
static void
-vehicle_webos_init_pdl_locationtracking_callback(struct vehicle_priv *priv, struct callback_list *cbl, int param)
-{
- PDL_Err err;
+vehicle_webos_init_pdl_locationtracking_callback(struct vehicle_priv *priv, struct callback_list *cbl, int param) {
+ PDL_Err err;
- priv->gps_type = param ? GPS_TYPE_INT: GPS_TYPE_NONE;
+ priv->gps_type = param ? GPS_TYPE_INT: GPS_TYPE_NONE;
- dbg(lvl_debug,"Calling PDL_EnableLocationTracking(%i)",param);
- err = PDL_EnableLocationTracking(param);
+ dbg(lvl_debug,"Calling PDL_EnableLocationTracking(%i)",param);
+ err = PDL_EnableLocationTracking(param);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_EnableLocationTracking failed with (%d): (%s)", err, PDL_GetError());
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_EnableLocationTracking failed with (%d): (%s)", err, PDL_GetError());
// vehicle_webos_close(priv);
// return 0;
- }
+ }
- callback_list_destroy(cbl);
+ callback_list_destroy(cbl);
}
static void
-vehicle_webos_init_pdl_locationtracking(struct vehicle_priv *priv, int param)
-{
- struct callback *cb = NULL;
- struct callback_list *cbl = NULL;
+vehicle_webos_init_pdl_locationtracking(struct vehicle_priv *priv, int param) {
+ struct callback *cb = NULL;
+ struct callback_list *cbl = NULL;
- cbl = callback_list_new();
- cb = callback_new_3(callback_cast(vehicle_webos_init_pdl_locationtracking_callback),priv,cbl,param);
+ cbl = callback_list_new();
+ cb = callback_new_3(callback_cast(vehicle_webos_init_pdl_locationtracking_callback),priv,cbl,param);
- callback_list_add(cbl, cb);
+ callback_list_add(cbl, cb);
- event_call_callback(cbl);
+ event_call_callback(cbl);
}
/********************************************************************/
static int
-vehicle_webos_parse_nmea(struct vehicle_priv *priv, char *buffer)
-{
- char *nmea_data_buf, *p, *item[32];
- double lat, lng;
- int i, bcsum;
- int len = strlen(buffer);
- unsigned char csum = 0;
- int valid=0;
- int ret = 0;
-
- dbg(lvl_info, "enter: buffer='%s'", buffer);
- for (;;) {
- if (len < 4) {
- dbg(lvl_error, "'%s' too short", buffer);
- return ret;
- }
- if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
- buffer[--len] = '\0';
+vehicle_webos_parse_nmea(struct vehicle_priv *priv, char *buffer) {
+ char *nmea_data_buf, *p, *item[32];
+ double lat, lng;
+ int i, bcsum;
+ int len = strlen(buffer);
+ unsigned char csum = 0;
+ int valid=0;
+ int ret = 0;
+
+ dbg(lvl_info, "enter: buffer='%s'", buffer);
+ for (;;) {
+ if (len < 4) {
+ dbg(lvl_error, "'%s' too short", buffer);
+ return ret;
+ }
+ if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
+ buffer[--len] = '\0';
if (buffer[len - 1] == '\r')
buffer[--len] = '\0';
} else
- break;
- }
- if (buffer[0] != '$') {
- dbg(lvl_error, "no leading $ in '%s'", buffer);
- return ret;
- }
- if (buffer[len - 3] != '*') {
- dbg(lvl_error, "no *XX in '%s'", buffer);
- return ret;
- }
- for (i = 1; i < len - 3; i++) {
- csum ^= (unsigned char) (buffer[i]);
- }
- if (!sscanf(buffer + len - 2, "%x", &bcsum) /*&& priv->checksum_ignore != 2*/) {
- dbg(lvl_error, "no checksum in '%s'", buffer);
- return ret;
- }
- if (bcsum != csum /*&& priv->checksum_ignore == 0*/) {
- dbg(lvl_error, "wrong checksum in '%s was %x should be %x'", buffer,bcsum,csum);
- return ret;
- }
-
- if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
- nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
- g_free(priv->nmea_data_buf);
- priv->nmea_data_buf=nmea_data_buf;
- } else {
- dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
- }
- i = 0;
- p = buffer;
- while (i < 31) {
- item[i++] = p;
- while (*p && *p != ',')
- p++;
- if (!*p)
- break;
- *p++ = '\0';
- }
+ break;
+ }
+ if (buffer[0] != '$') {
+ dbg(lvl_error, "no leading $ in '%s'", buffer);
+ return ret;
+ }
+ if (buffer[len - 3] != '*') {
+ dbg(lvl_error, "no *XX in '%s'", buffer);
+ return ret;
+ }
+ for (i = 1; i < len - 3; i++) {
+ csum ^= (unsigned char) (buffer[i]);
+ }
+ if (!sscanf(buffer + len - 2, "%x", &bcsum) /*&& priv->checksum_ignore != 2*/) {
+ dbg(lvl_error, "no checksum in '%s'", buffer);
+ return ret;
+ }
+ if (bcsum != csum /*&& priv->checksum_ignore == 0*/) {
+ dbg(lvl_error, "wrong checksum in '%s was %x should be %x'", buffer,bcsum,csum);
+ return ret;
+ }
+
+ if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
+ nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
+ g_free(priv->nmea_data_buf);
+ priv->nmea_data_buf=nmea_data_buf;
+ } else {
+ dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
+ }
+ i = 0;
+ p = buffer;
+ while (i < 31) {
+ item[i++] = p;
+ while (*p && *p != ',')
+ p++;
+ if (!*p)
+ break;
+ *p++ = '\0';
+ }
// if (buffer[0] == '$') {
// struct timeval tv;
// gettimeofday(&tv,NULL);
- priv->delta = 0; // (unsigned int)difftime(tv.tv_sec, priv->fix_time);
+ priv->delta = 0; // (unsigned int)difftime(tv.tv_sec, priv->fix_time);
// priv->fix_time = tv.tv_sec;
// dbg(lvl_info,"delta(%i)",priv->delta);
// }
- if (!strncmp(&buffer[3], "GGA", 3)) {
- /* 1 1111
- 0 1 2 3 4 5 6 7 8 9 0 1234
- $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
- UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
- HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
- */
- if (*item[2] && *item[3] && *item[4] && *item[5]) {
- lat = g_ascii_strtod(item[2], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_strcasecmp(item[3],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[4], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_strcasecmp(item[5],"W"))
- priv->geo.lng=-priv->geo.lng;
- priv->valid=attr_position_valid_valid;
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else
- priv->valid=attr_position_valid_invalid;
- if (*item[6])
- sscanf(item[6], "%d", &priv->status);
- if (*item[7])
- sscanf(item[7], "%d", &priv->sats_used);
- if (*item[8])
- sscanf(item[8], "%lf", &priv->hdop);
- if (*item[1]) {
- struct tm tm;
- strptime(item[1],"%H%M%S",&tm);
- priv->fix_time = mktime(&tm);
- }
-
- if (*item[9])
- sscanf(item[9], "%lf", &priv->altitude);
-
- g_free(priv->nmea_data);
- priv->nmea_data=priv->nmea_data_buf;
- priv->nmea_data_buf=NULL;
- ret = 1;
- }
- if (!strncmp(&buffer[3], "VTG", 3)) {
- /* 0 1 2 34 5 6 7 8
- $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
- Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
- Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
- */
- if (item[1] && item[7])
- valid = 1;
- if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
- valid = 1;
- if (valid) {
- priv->track = g_ascii_strtod( item[1], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- dbg(lvl_info,"direction %lf, speed %2.1lf", priv->track, priv->speed);
- }
- }
- if (!strncmp(&buffer[3], "RMC", 3)) {
- /* 1 1
- 0 1 2 3 4 5 6 7 8 9 0 1
- $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
- Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
- magnetic variation[10],magnetic variation direction[11]
- */
- if (*item[2] == 'A')
- valid = 1;
- if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
- valid = 1;
- if (valid) {
- priv->track = g_ascii_strtod( item[8], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- priv->speed *= 1.852;
-
- struct tm tm;
- char time[13];
-
- sprintf(time,"%s%s",item[1],item[9]);
-
- strptime(time,"%H%M%S%d%m%y",&tm);
-
- priv->fix_time = mktime(&tm);
- }
- ret = 1;
- }
- if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
- /*
- 0 GSV Satellites in view
- 1 2 Number of sentences for full data
- 2 1 sentence 1 of 2
- 3 08 Number of satellites in view
-
- 4 01 Satellite PRN number
- 5 40 Elevation, degrees
- 6 083 Azimuth, degrees
- 7 46 SNR - higher is better
- for up to 4 satellites per sentence
- *75 the checksum data, always begins with *
- */
- if (item[3]) {
- sscanf(item[3], "%d", &priv->sats_visible);
- }
- }
- if (!strncmp(buffer, "$IISMD", 6)) {
- /*
- 0 1 2 3 4
- $IISMD,dir,press,height,temp*CC"
- dir Direction (0-359)
- press Pressure (hpa, i.e. 1032)
- height Barometric height above ground (meter)
- temp Temperature (Degree Celsius)
- */
- if (item[1]) {
- priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
- dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
- }
- }
- return ret;
+ if (!strncmp(&buffer[3], "GGA", 3)) {
+ /* 1 1111
+ 0 1 2 3 4 5 6 7 8 9 0 1234
+ $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
+ UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
+ HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
+ */
+ if (*item[2] && *item[3] && *item[4] && *item[5]) {
+ lat = g_ascii_strtod(item[2], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_strcasecmp(item[3],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[4], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_strcasecmp(item[5],"W"))
+ priv->geo.lng=-priv->geo.lng;
+ priv->valid=attr_position_valid_valid;
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else
+ priv->valid=attr_position_valid_invalid;
+ if (*item[6])
+ sscanf(item[6], "%d", &priv->status);
+ if (*item[7])
+ sscanf(item[7], "%d", &priv->sats_used);
+ if (*item[8])
+ sscanf(item[8], "%lf", &priv->hdop);
+ if (*item[1]) {
+ struct tm tm;
+ strptime(item[1],"%H%M%S",&tm);
+ priv->fix_time = mktime(&tm);
+ }
+
+ if (*item[9])
+ sscanf(item[9], "%lf", &priv->altitude);
+
+ g_free(priv->nmea_data);
+ priv->nmea_data=priv->nmea_data_buf;
+ priv->nmea_data_buf=NULL;
+ ret = 1;
+ }
+ if (!strncmp(&buffer[3], "VTG", 3)) {
+ /* 0 1 2 34 5 6 7 8
+ $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
+ Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
+ Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
+ */
+ if (item[1] && item[7])
+ valid = 1;
+ if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->track = g_ascii_strtod( item[1], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ dbg(lvl_info,"direction %lf, speed %2.1lf", priv->track, priv->speed);
+ }
+ }
+ if (!strncmp(&buffer[3], "RMC", 3)) {
+ /* 1 1
+ 0 1 2 3 4 5 6 7 8 9 0 1
+ $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
+ Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
+ magnetic variation[10],magnetic variation direction[11]
+ */
+ if (*item[2] == 'A')
+ valid = 1;
+ if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->track = g_ascii_strtod( item[8], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ priv->speed *= 1.852;
+
+ struct tm tm;
+ char time[13];
+
+ sprintf(time,"%s%s",item[1],item[9]);
+
+ strptime(time,"%H%M%S%d%m%y",&tm);
+
+ priv->fix_time = mktime(&tm);
+ }
+ ret = 1;
+ }
+ if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
+ /*
+ 0 GSV Satellites in view
+ 1 2 Number of sentences for full data
+ 2 1 sentence 1 of 2
+ 3 08 Number of satellites in view
+
+ 4 01 Satellite PRN number
+ 5 40 Elevation, degrees
+ 6 083 Azimuth, degrees
+ 7 46 SNR - higher is better
+ for up to 4 satellites per sentence
+ *75 the checksum data, always begins with *
+ */
+ if (item[3]) {
+ sscanf(item[3], "%d", &priv->sats_visible);
+ }
+ }
+ if (!strncmp(buffer, "$IISMD", 6)) {
+ /*
+ 0 1 2 3 4
+ $IISMD,dir,press,height,temp*CC"
+ dir Direction (0-359)
+ press Pressure (hpa, i.e. 1032)
+ height Barometric height above ground (meter)
+ temp Temperature (Degree Celsius)
+ */
+ if (item[1]) {
+ priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
+ dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
+ }
+ }
+ return ret;
}
static void
-vehicle_webos_spp_handle_read(PDL_ServiceParameters *params, void *user)
-{
- struct vehicle_priv *priv = user;
- int size, rc = 0;
- char *str, *tok;
-
- //PDL_Err err;
- size = PDL_GetParamInt(params, "dataLength");
- if (size > buffer_size) {
- dbg(lvl_error, "read returned too much data");
- return;
- }
-
- char buffer[buffer_size];
-
- PDL_GetParamString(params,"data",buffer,buffer_size);
- dbg(lvl_debug,"data(%s) dataLength(%i)",buffer,size);
-
- memmove(priv->buffer + priv->buffer_pos, buffer, size);
-
-
-
- priv->buffer_pos += size;
- priv->buffer[priv->buffer_pos] = '\0';
- dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
- priv->buffer_pos, priv->buffer);
- str = priv->buffer;
- while ((tok = strchr(str, '\n'))) {
- *tok++ = '\0';
- dbg(lvl_debug, "line='%s'", str);
- rc += vehicle_webos_parse_nmea(priv, str);
- str = tok;
+vehicle_webos_spp_handle_read(PDL_ServiceParameters *params, void *user) {
+ struct vehicle_priv *priv = user;
+ int size, rc = 0;
+ char *str, *tok;
+
+ //PDL_Err err;
+ size = PDL_GetParamInt(params, "dataLength");
+ if (size > buffer_size) {
+ dbg(lvl_error, "read returned too much data");
+ return;
+ }
+
+ char buffer[buffer_size];
+
+ PDL_GetParamString(params,"data",buffer,buffer_size);
+ dbg(lvl_debug,"data(%s) dataLength(%i)",buffer,size);
+
+ memmove(priv->buffer + priv->buffer_pos, buffer, size);
+
+
+
+ priv->buffer_pos += size;
+ priv->buffer[priv->buffer_pos] = '\0';
+ dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
+ priv->buffer_pos, priv->buffer);
+ str = priv->buffer;
+ while ((tok = strchr(str, '\n'))) {
+ *tok++ = '\0';
+ dbg(lvl_debug, "line='%s'", str);
+ rc += vehicle_webos_parse_nmea(priv, str);
+ str = tok;
// if (priv->file_type == file_type_file && rc)
// break;
- }
-
- if (str != priv->buffer) {
- size = priv->buffer + priv->buffer_pos - str;
- memmove(priv->buffer, str, size + 1);
- priv->buffer_pos = size;
- dbg(lvl_debug,"now pos=%d buffer='%s'",
- priv->buffer_pos, priv->buffer);
- } else if (priv->buffer_pos == buffer_size - 1) {
- dbg(lvl_error,"Overflow. Most likely wrong baud rate or no nmea protocol");
- priv->buffer_pos = 0;
- }
- if (rc) {
- SDL_Event event;
- SDL_UserEvent userevent;
-
- userevent.type = SDL_USEREVENT;
- userevent.code = PDL_GPS_UPDATE;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent(&event);
- }
-
- vehicle_webos_spp_init_read(priv, buffer_size - priv->buffer_pos - 1);
+ }
+
+ if (str != priv->buffer) {
+ size = priv->buffer + priv->buffer_pos - str;
+ memmove(priv->buffer, str, size + 1);
+ priv->buffer_pos = size;
+ dbg(lvl_debug,"now pos=%d buffer='%s'",
+ priv->buffer_pos, priv->buffer);
+ } else if (priv->buffer_pos == buffer_size - 1) {
+ dbg(lvl_error,"Overflow. Most likely wrong baud rate or no nmea protocol");
+ priv->buffer_pos = 0;
+ }
+ if (rc) {
+ SDL_Event event;
+ SDL_UserEvent userevent;
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = PDL_GPS_UPDATE;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent(&event);
+ }
+
+ vehicle_webos_spp_init_read(priv, buffer_size - priv->buffer_pos - 1);
}
static void
-vehicle_webos_spp_init_read(struct vehicle_priv *priv, unsigned int length)
-{
- //PDL_Err err;
- char parameters[128];
-
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i, \"dataLength\":%i}", priv->spp_instance_id, length);
- mlPDL_ServiceCallWithCallback("palm://com.palm.service.bluetooth.spp/read",
- parameters,
- (PDL_ServiceCallbackFunc)vehicle_webos_spp_handle_read,
- priv,
- PDL_FALSE
- );
+vehicle_webos_spp_init_read(struct vehicle_priv *priv, unsigned int length) {
+ //PDL_Err err;
+ char parameters[128];
+
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i, \"dataLength\":%i}", priv->spp_instance_id, length);
+ mlPDL_ServiceCallWithCallback("palm://com.palm.service.bluetooth.spp/read",
+ parameters,
+ (PDL_ServiceCallbackFunc)vehicle_webos_spp_handle_read,
+ priv,
+ PDL_FALSE
+ );
}
static void
-vehicle_webos_spp_handle_open(PDL_ServiceParameters *params, void *user)
-{
- struct vehicle_priv *priv = (struct vehicle_priv *)user;
+vehicle_webos_spp_handle_open(PDL_ServiceParameters *params, void *user) {
+ struct vehicle_priv *priv = (struct vehicle_priv *)user;
- if (!priv->buffer)
- priv->buffer = g_malloc(buffer_size);
-
- dbg(lvl_debug,"instanceId(%i)",priv->spp_instance_id);
+ if (!priv->buffer)
+ priv->buffer = g_malloc(buffer_size);
- priv->gps_type = GPS_TYPE_BT;
+ dbg(lvl_debug,"instanceId(%i)",priv->spp_instance_id);
- vehicle_webos_spp_init_read(priv, buffer_size-1);
+ priv->gps_type = GPS_TYPE_BT;
+
+ vehicle_webos_spp_init_read(priv, buffer_size-1);
}
static void
-vehicle_webos_spp_notify(PDL_ServiceParameters *params, void *user)
-{
- struct vehicle_priv *priv = user;
-
- char notification[128];
- char parameters[128];
-
- const char *params_json = PDL_GetParamJson(params);
- dbg(lvl_info,"params_json(%s)", params_json);
-
- if (PDL_ParamExists(params, "errorText")) {
- PDL_GetParamString(params, "errorText", notification, sizeof(notification));
- dbg(lvl_error,"errorText(%s)",notification);
- return;
- }
-
- PDL_GetParamString(params, "notification", notification, sizeof(notification));
- notification[sizeof(notification)-1] = '\0';
-
- dbg(lvl_warning,"notification(%s) %i",notification,PDL_ParamExists(params, "notification"));
-
- if(strcmp(notification,"notifnservicenames") == 0) {
- int instance_id = PDL_GetParamInt(params, "instanceId");
-
- dbg(lvl_debug,"instanceId(%i)", instance_id);
-
- cJSON *root = cJSON_Parse(params_json);
- if (!root) {
- dbg(lvl_error,"parsing json failed");
- return;
- }
-
- cJSON *services = cJSON_GetObjectItem(root, "services");
-
- char *service_name = cJSON_GetArrayItem(services, 0)->valuestring;
-
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i, \"servicename\":\"%s\"}",instance_id, service_name);
- mlPDL_ServiceCall("palm://com.palm.bluetooth/spp/selectservice", parameters);
-
- cJSON_Delete(root);
- }
- else if(strcmp(notification,"notifnconnected") == 0) {
- if (PDL_GetParamInt(params,"error") == 0) {
- vehicle_webos_init_pdl_locationtracking(priv, 0);
-
- int instance_id = PDL_GetParamInt(params, "instanceId");
- priv->spp_instance_id = instance_id;
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}", instance_id);
- mlPDL_ServiceCallWithCallback("palm://com.palm.service.bluetooth.spp/open",
- parameters,
- (PDL_ServiceCallbackFunc)vehicle_webos_spp_handle_open,
- priv,
- PDL_TRUE);
- }
- else {
- dbg(lvl_error,"notifnconnected error(%i)",PDL_GetParamInt(params,"error"));
- }
- }
- else if(strcmp(notification,"notifndisconnected") == 0) {
- priv->gps_type = GPS_TYPE_NONE;
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}",priv->spp_instance_id);
- mlPDL_ServiceCall("palm://com.palm.service.bluetooth.spp/close", parameters);
- priv->spp_instance_id = 0;
- vehicle_webos_init_pdl_locationtracking(priv, 1);
- }
+vehicle_webos_spp_notify(PDL_ServiceParameters *params, void *user) {
+ struct vehicle_priv *priv = user;
+
+ char notification[128];
+ char parameters[128];
+
+ const char *params_json = PDL_GetParamJson(params);
+ dbg(lvl_info,"params_json(%s)", params_json);
+
+ if (PDL_ParamExists(params, "errorText")) {
+ PDL_GetParamString(params, "errorText", notification, sizeof(notification));
+ dbg(lvl_error,"errorText(%s)",notification);
+ return;
+ }
+
+ PDL_GetParamString(params, "notification", notification, sizeof(notification));
+ notification[sizeof(notification)-1] = '\0';
+
+ dbg(lvl_warning,"notification(%s) %i",notification,PDL_ParamExists(params, "notification"));
+
+ if(strcmp(notification,"notifnservicenames") == 0) {
+ int instance_id = PDL_GetParamInt(params, "instanceId");
+
+ dbg(lvl_debug,"instanceId(%i)", instance_id);
+
+ cJSON *root = cJSON_Parse(params_json);
+ if (!root) {
+ dbg(lvl_error,"parsing json failed");
+ return;
+ }
+
+ cJSON *services = cJSON_GetObjectItem(root, "services");
+
+ char *service_name = cJSON_GetArrayItem(services, 0)->valuestring;
+
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i, \"servicename\":\"%s\"}",instance_id, service_name);
+ mlPDL_ServiceCall("palm://com.palm.bluetooth/spp/selectservice", parameters);
+
+ cJSON_Delete(root);
+ } else if(strcmp(notification,"notifnconnected") == 0) {
+ if (PDL_GetParamInt(params,"error") == 0) {
+ vehicle_webos_init_pdl_locationtracking(priv, 0);
+
+ int instance_id = PDL_GetParamInt(params, "instanceId");
+ priv->spp_instance_id = instance_id;
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}", instance_id);
+ mlPDL_ServiceCallWithCallback("palm://com.palm.service.bluetooth.spp/open",
+ parameters,
+ (PDL_ServiceCallbackFunc)vehicle_webos_spp_handle_open,
+ priv,
+ PDL_TRUE);
+ } else {
+ dbg(lvl_error,"notifnconnected error(%i)",PDL_GetParamInt(params,"error"));
+ }
+ } else if(strcmp(notification,"notifndisconnected") == 0) {
+ priv->gps_type = GPS_TYPE_NONE;
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}",priv->spp_instance_id);
+ mlPDL_ServiceCall("palm://com.palm.service.bluetooth.spp/close", parameters);
+ priv->spp_instance_id = 0;
+ vehicle_webos_init_pdl_locationtracking(priv, 1);
+ }
}
static void
-vehicle_webos_init_bt_gps(struct vehicle_priv *priv, char *addr)
-{
- char parameters[128];
+vehicle_webos_init_bt_gps(struct vehicle_priv *priv, char *addr) {
+ char parameters[128];
- dbg(lvl_debug,"subscribeNotifications");
- mlPDL_ServiceCallWithCallback("palm://com.palm.bluetooth/spp/subscribenotifications",
- "{\"subscribe\":true}",
- (PDL_ServiceCallbackFunc)vehicle_webos_spp_notify,
- priv,
- PDL_FALSE);
+ dbg(lvl_debug,"subscribeNotifications");
+ mlPDL_ServiceCallWithCallback("palm://com.palm.bluetooth/spp/subscribenotifications",
+ "{\"subscribe\":true}",
+ (PDL_ServiceCallbackFunc)vehicle_webos_spp_notify,
+ priv,
+ PDL_FALSE);
- snprintf(parameters, sizeof(parameters), "{\"address\":\"%s\"}", addr);
- mlPDL_ServiceCall("palm://com.palm.bluetooth/spp/connect", parameters);
+ snprintf(parameters, sizeof(parameters), "{\"address\":\"%s\"}", addr);
+ mlPDL_ServiceCall("palm://com.palm.bluetooth/spp/connect", parameters);
- priv->spp_address = addr;
+ priv->spp_address = addr;
}
static void
-vehicle_webos_bt_gap_callback(PDL_ServiceParameters *params, void *param)
-{
- const char *params_json;
- struct vehicle_priv *priv = (struct vehicle_priv *)param;
- char *device_addr = NULL;
- cJSON *root;
-
- dbg(lvl_debug,"enter");
-
- PDL_Err err;
- err = PDL_GetParamInt(params, "errorCode");
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"BT GAP Callback errorCode %d", err);
- return /*PDL_EOTHER*/;
- }
-
- params_json = PDL_GetParamJson(params);
- dbg(lvl_info,"params_json(%s)",params_json);
-
- root = cJSON_Parse(params_json);
- if (!root) {
- dbg(lvl_error,"parsing json failed");
- return;
- }
-
- cJSON *trusted_devices = cJSON_GetObjectItem(root, "trusteddevices");
-
- unsigned int i,c = cJSON_GetArraySize(trusted_devices);
- dbg(lvl_debug, "trusted_devices(%i)",c);
- for(i=0; i < c && !device_addr; i++) {
- cJSON *device = cJSON_GetArrayItem(trusted_devices,i);
- char *name = cJSON_GetObjectItem(device, "name")->valuestring;
- char *address = cJSON_GetObjectItem(device, "address")->valuestring;
- char *status = cJSON_GetObjectItem(device, "status")->valuestring;
-
- dbg(lvl_debug,"i(%i) name(%s) address(%s) status(%s)",i,name,address,status);
-
- if (/*strncmp(status, "connected",9) == 0 && */strstr(name, "GPS") != NULL) {
- dbg(lvl_debug,"choose name(%s) address(%s)",name,address);
- device_addr = g_strdup(address);
- break;
- }
- }
-
- cJSON_Delete(root);
-
- if (device_addr) {
- vehicle_webos_init_bt_gps(priv, device_addr);
- }
-
- g_free(device_addr);
+vehicle_webos_bt_gap_callback(PDL_ServiceParameters *params, void *param) {
+ const char *params_json;
+ struct vehicle_priv *priv = (struct vehicle_priv *)param;
+ char *device_addr = NULL;
+ cJSON *root;
+
+ dbg(lvl_debug,"enter");
+
+ PDL_Err err;
+ err = PDL_GetParamInt(params, "errorCode");
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"BT GAP Callback errorCode %d", err);
+ return /*PDL_EOTHER*/;
+ }
+
+ params_json = PDL_GetParamJson(params);
+ dbg(lvl_info,"params_json(%s)",params_json);
+
+ root = cJSON_Parse(params_json);
+ if (!root) {
+ dbg(lvl_error,"parsing json failed");
+ return;
+ }
+
+ cJSON *trusted_devices = cJSON_GetObjectItem(root, "trusteddevices");
+
+ unsigned int i,c = cJSON_GetArraySize(trusted_devices);
+ dbg(lvl_debug, "trusted_devices(%i)",c);
+ for(i=0; i < c && !device_addr; i++) {
+ cJSON *device = cJSON_GetArrayItem(trusted_devices,i);
+ char *name = cJSON_GetObjectItem(device, "name")->valuestring;
+ char *address = cJSON_GetObjectItem(device, "address")->valuestring;
+ char *status = cJSON_GetObjectItem(device, "status")->valuestring;
+
+ dbg(lvl_debug,"i(%i) name(%s) address(%s) status(%s)",i,name,address,status);
+
+ if (/*strncmp(status, "connected",9) == 0 && */strstr(name, "GPS") != NULL) {
+ dbg(lvl_debug,"choose name(%s) address(%s)",name,address);
+ device_addr = g_strdup(address);
+ break;
+ }
+ }
+
+ cJSON_Delete(root);
+
+ if (device_addr) {
+ vehicle_webos_init_bt_gps(priv, device_addr);
+ }
+
+ g_free(device_addr);
}
int
-vehicle_webos_bt_open(struct vehicle_priv *priv)
-{
- // Try to connect to BT GPS, or use PDL method
-
- dbg(lvl_debug,"enter");
-
- PDL_Err err;
- err = PDL_ServiceCallWithCallback("palm://com.palm.bluetooth/gap/gettrusteddevices",
- "{}",
- (PDL_ServiceCallbackFunc)vehicle_webos_bt_gap_callback,
- priv,
- PDL_TRUE);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_ServiceCallWithCallback failed with (%d): (%s)", err, PDL_GetError());
- vehicle_webos_close(priv);
- return 0;
- }
- return 1;
+vehicle_webos_bt_open(struct vehicle_priv *priv) {
+ // Try to connect to BT GPS, or use PDL method
+
+ dbg(lvl_debug,"enter");
+
+ PDL_Err err;
+ err = PDL_ServiceCallWithCallback("palm://com.palm.bluetooth/gap/gettrusteddevices",
+ "{}",
+ (PDL_ServiceCallbackFunc)vehicle_webos_bt_gap_callback,
+ priv,
+ PDL_TRUE);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_ServiceCallWithCallback failed with (%d): (%s)", err, PDL_GetError());
+ vehicle_webos_close(priv);
+ return 0;
+ }
+ return 1;
}
void
-vehicle_webos_bt_close(struct vehicle_priv *priv)
-{
- dbg(lvl_debug,"XXX");
- char parameters[128];
- if (priv->spp_instance_id) {
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}", priv->spp_instance_id);
- PDL_ServiceCall("palm://com.palm.service.bluetooth.spp/close", parameters);
- }
- if (priv->spp_address) {
- snprintf(parameters, sizeof(parameters), "{\"address\":\"%s\"}", priv->spp_address);
- PDL_ServiceCall("palm://com.palm.bluetooth.spp/disconnect", parameters);
- g_free(priv->spp_address);
- priv->spp_address = NULL;
- }
- //g_free(priv->buffer);
- //priv->buffer = NULL;
- // g_free(priv->nmea_data);
- // priv->nmea_data = NULL;
- // g_free(priv->nmea_data_buf);
- // priv->nmea_data_buf = NULL;
+vehicle_webos_bt_close(struct vehicle_priv *priv) {
+ dbg(lvl_debug,"XXX");
+ char parameters[128];
+ if (priv->spp_instance_id) {
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}", priv->spp_instance_id);
+ PDL_ServiceCall("palm://com.palm.service.bluetooth.spp/close", parameters);
+ }
+ if (priv->spp_address) {
+ snprintf(parameters, sizeof(parameters), "{\"address\":\"%s\"}", priv->spp_address);
+ PDL_ServiceCall("palm://com.palm.bluetooth.spp/disconnect", parameters);
+ g_free(priv->spp_address);
+ priv->spp_address = NULL;
+ }
+ //g_free(priv->buffer);
+ //priv->buffer = NULL;
+ // g_free(priv->nmea_data);
+ // priv->nmea_data = NULL;
+ // g_free(priv->nmea_data_buf);
+ // priv->nmea_data_buf = NULL;
}
diff --git a/navit/vehicle/webos/cJSON.c b/navit/vehicle/webos/cJSON.c
index 19d3151e2..9026a224f 100644
--- a/navit/vehicle/webos/cJSON.c
+++ b/navit/vehicle/webos/cJSON.c
@@ -34,208 +34,260 @@
static const char *ep;
-const char *cJSON_GetErrorPtr() {return ep;}
+const char *cJSON_GetErrorPtr() {
+ return ep;
+}
-static int cJSON_strcasecmp(const char *s1,const char *s2)
-{
- if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
- for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
- return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
+static int cJSON_strcasecmp(const char *s1,const char *s2) {
+ if (!s1) return (s1==s2)?0:1;
+ if (!s2) return 1;
+ for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
+ return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
}
static void *(*cJSON_malloc)(size_t sz) = malloc;
static void (*cJSON_free)(void *ptr) = free;
-static char* cJSON_strdup(const char* str)
-{
- size_t len;
- char* copy;
+static char* cJSON_strdup(const char* str) {
+ size_t len;
+ char* copy;
- len = strlen(str) + 1;
- if (!(copy = (char*)cJSON_malloc(len))) return 0;
- memcpy(copy,str,len);
- return copy;
+ len = strlen(str) + 1;
+ if (!(copy = (char*)cJSON_malloc(len))) return 0;
+ memcpy(copy,str,len);
+ return copy;
}
-void cJSON_InitHooks(cJSON_Hooks* hooks)
-{
+void cJSON_InitHooks(cJSON_Hooks* hooks) {
if (!hooks) { /* Reset hooks */
cJSON_malloc = malloc;
cJSON_free = free;
return;
}
- cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
- cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
+ cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
+ cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
}
/* Internal constructor. */
-static cJSON *cJSON_New_Item(void)
-{
- cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
- if (node) memset(node,0,sizeof(cJSON));
- return node;
+static cJSON *cJSON_New_Item(void) {
+ cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
+ if (node) memset(node,0,sizeof(cJSON));
+ return node;
}
/* Delete a cJSON structure. */
-void cJSON_Delete(cJSON *c)
-{
- cJSON *next;
- while (c)
- {
- next=c->next;
- if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
- if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
- if (c->string) cJSON_free(c->string);
- cJSON_free(c);
- c=next;
- }
+void cJSON_Delete(cJSON *c) {
+ cJSON *next;
+ while (c) {
+ next=c->next;
+ if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
+ if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
+ if (c->string) cJSON_free(c->string);
+ cJSON_free(c);
+ c=next;
+ }
}
/* Parse the input text to generate a number, and populate the result into item. */
-static const char *parse_number(cJSON *item,const char *num)
-{
- double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
-
- /* Could use sscanf for this? */
- if (*num=='-') sign=-1,num++; /* Has sign? */
- if (*num=='0') num++; /* is zero */
- if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
- if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
- if (*num=='e' || *num=='E') /* Exponent? */
- { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
- while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
- }
-
- n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
-
- item->valuedouble=n;
- item->valueint=(int)n;
- item->type=cJSON_Number;
- return num;
+static const char *parse_number(cJSON *item,const char *num) {
+ double n=0,sign=1,scale=0;
+ int subscale=0,signsubscale=1;
+
+ /* Could use sscanf for this? */
+ if (*num=='-') sign=-1,num++; /* Has sign? */
+ if (*num=='0') num++; /* is zero */
+ if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0');
+ while (*num>='0' && *num<='9'); /* Number? */
+ if (*num=='.' && num[1]>='0' && num[1]<='9') {
+ num++; /* Fractional part? */
+ do n=(n*10.0)+(*num++ -'0'),scale--;
+ while (*num>='0' && *num<='9');
+ }
+ if (*num=='e' || *num=='E') { /* Exponent? */
+ num++;
+ if (*num=='+') num++;
+ else if (*num=='-') signsubscale=-1,num++; /* With sign? */
+ while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
+ }
+
+ n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
+
+ item->valuedouble=n;
+ item->valueint=(int)n;
+ item->type=cJSON_Number;
+ return num;
}
/* Render the number nicely from the given item into a string. */
-static char *print_number(cJSON *item)
-{
- char *str;
- double d=item->valuedouble;
- if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
- {
- str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
- if (str) sprintf(str,"%d",item->valueint);
- }
- else
- {
- str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
- if (str)
- {
- if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
- else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
- else sprintf(str,"%f",d);
- }
- }
- return str;
+static char *print_number(cJSON *item) {
+ char *str;
+ double d=item->valuedouble;
+ if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN) {
+ str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
+ if (str) sprintf(str,"%d",item->valueint);
+ } else {
+ str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
+ if (str) {
+ if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
+ else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
+ else sprintf(str,"%f",d);
+ }
+ }
+ return str;
}
/* Parse the input text into an unescaped cstring, and populate item. */
static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
-static const char *parse_string(cJSON *item,const char *str)
-{
- const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
- if (*str!='\"') {ep=str;return 0;} /* not a string! */
-
- while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
-
- out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
- if (!out) return 0;
-
- ptr=str+1;ptr2=out;
- while (*ptr!='\"' && *ptr)
- {
- if (*ptr!='\\') *ptr2++=*ptr++;
- else
- {
- ptr++;
- switch (*ptr)
- {
- case 'b': *ptr2++='\b'; break;
- case 'f': *ptr2++='\f'; break;
- case 'n': *ptr2++='\n'; break;
- case 'r': *ptr2++='\r'; break;
- case 't': *ptr2++='\t'; break;
- case 'u': /* transcode utf16 to utf8. */
- sscanf(ptr+1,"%4x",&uc);ptr+=4; /* get the unicode char. */
-
- if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid.
-
- if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs.
- {
- if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate.
- sscanf(ptr+3,"%4x",&uc2);ptr+=6;
- if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate.
- uc=0x10000 | ((uc&0x3FF)<<10) | (uc2&0x3FF);
- }
-
- len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;
-
- switch (len) {
- case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
- case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
- case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
- case 1: *--ptr2 =(uc | firstByteMark[len]);
- }
- ptr2+=len;
- break;
- default: *ptr2++=*ptr; break;
- }
- ptr++;
- }
- }
- *ptr2=0;
- if (*ptr=='\"') ptr++;
- item->valuestring=out;
- item->type=cJSON_String;
- return ptr;
+static const char *parse_string(cJSON *item,const char *str) {
+ const char *ptr=str+1;
+ char *ptr2;
+ char *out;
+ int len=0;
+ unsigned uc,uc2;
+ if (*str!='\"') {
+ ep=str; /* not a string! */
+ return 0;
+ }
+
+ while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
+
+ out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
+ if (!out) return 0;
+
+ ptr=str+1;
+ ptr2=out;
+ while (*ptr!='\"' && *ptr) {
+ if (*ptr!='\\') *ptr2++=*ptr++;
+ else {
+ ptr++;
+ switch (*ptr) {
+ case 'b':
+ *ptr2++='\b';
+ break;
+ case 'f':
+ *ptr2++='\f';
+ break;
+ case 'n':
+ *ptr2++='\n';
+ break;
+ case 'r':
+ *ptr2++='\r';
+ break;
+ case 't':
+ *ptr2++='\t';
+ break;
+ case 'u': /* transcode utf16 to utf8. */
+ sscanf(ptr+1,"%4x",&uc);
+ ptr+=4; /* get the unicode char. */
+
+ if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid.
+
+ if (uc>=0xD800 && uc<=0xDBFF) { // UTF16 surrogate pairs.
+ if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate.
+ sscanf(ptr+3,"%4x",&uc2);
+ ptr+=6;
+ if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate.
+ uc=0x10000 | ((uc&0x3FF)<<10) | (uc2&0x3FF);
+ }
+
+ len=4;
+ if (uc<0x80) len=1;
+ else if (uc<0x800) len=2;
+ else if (uc<0x10000) len=3;
+ ptr2+=len;
+
+ switch (len) {
+ case 4:
+ *--ptr2 =((uc | 0x80) & 0xBF);
+ uc >>= 6;
+ case 3:
+ *--ptr2 =((uc | 0x80) & 0xBF);
+ uc >>= 6;
+ case 2:
+ *--ptr2 =((uc | 0x80) & 0xBF);
+ uc >>= 6;
+ case 1:
+ *--ptr2 =(uc | firstByteMark[len]);
+ }
+ ptr2+=len;
+ break;
+ default:
+ *ptr2++=*ptr;
+ break;
+ }
+ ptr++;
+ }
+ }
+ *ptr2=0;
+ if (*ptr=='\"') ptr++;
+ item->valuestring=out;
+ item->type=cJSON_String;
+ return ptr;
}
/* Render the cstring provided to an escaped version that can be printed. */
-static char *print_string_ptr(const char *str)
-{
- const char *ptr;char *ptr2,*out;int len=0;unsigned char token;
-
- if (!str) return cJSON_strdup("");
- ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;}
-
- out=(char*)cJSON_malloc(len+3);
- if (!out) return 0;
-
- ptr2=out;ptr=str;
- *ptr2++='\"';
- while (*ptr)
- {
- if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
- else
- {
- *ptr2++='\\';
- switch (token=*ptr++)
- {
- case '\\': *ptr2++='\\'; break;
- case '\"': *ptr2++='\"'; break;
- case '\b': *ptr2++='b'; break;
- case '\f': *ptr2++='f'; break;
- case '\n': *ptr2++='n'; break;
- case '\r': *ptr2++='r'; break;
- case '\t': *ptr2++='t'; break;
- default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */
- }
- }
- }
- *ptr2++='\"';*ptr2++=0;
- return out;
+static char *print_string_ptr(const char *str) {
+ const char *ptr;
+ char *ptr2,*out;
+ int len=0;
+ unsigned char token;
+
+ if (!str) return cJSON_strdup("");
+ ptr=str;
+ while ((token=*ptr) && ++len) {
+ if (strchr("\"\\\b\f\n\r\t",token)) len++;
+ else if (token<32) len+=5;
+ ptr++;
+ }
+
+ out=(char*)cJSON_malloc(len+3);
+ if (!out) return 0;
+
+ ptr2=out;
+ ptr=str;
+ *ptr2++='\"';
+ while (*ptr) {
+ if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
+ else {
+ *ptr2++='\\';
+ switch (token=*ptr++) {
+ case '\\':
+ *ptr2++='\\';
+ break;
+ case '\"':
+ *ptr2++='\"';
+ break;
+ case '\b':
+ *ptr2++='b';
+ break;
+ case '\f':
+ *ptr2++='f';
+ break;
+ case '\n':
+ *ptr2++='n';
+ break;
+ case '\r':
+ *ptr2++='r';
+ break;
+ case '\t':
+ *ptr2++='t';
+ break;
+ default:
+ sprintf(ptr2,"u%04x",token);
+ ptr2+=5;
+ break; /* escape and print */
+ }
+ }
+ }
+ *ptr2++='\"';
+ *ptr2++=0;
+ return out;
}
/* Invote print_string_ptr (which is useful) on an item. */
-static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);}
+static char *print_string(cJSON *item) {
+ return print_string_ptr(item->valuestring);
+}
/* Predeclare these prototypes. */
static const char *parse_value(cJSON *item,const char *value);
@@ -246,269 +298,502 @@ static const char *parse_object(cJSON *item,const char *value);
static char *print_object(cJSON *item,int depth,int fmt);
/* Utility to jump whitespace and cr/lf */
-static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
+static const char *skip(const char *in) {
+ while (in && *in && (unsigned char)*in<=32) in++;
+ return in;
+}
/* Parse an object - create a new root, and populate. */
-cJSON *cJSON_Parse(const char *value)
-{
- cJSON *c=cJSON_New_Item();
- ep=0;
- if (!c) return 0; /* memory fail */
-
- if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;}
- return c;
+cJSON *cJSON_Parse(const char *value) {
+ cJSON *c=cJSON_New_Item();
+ ep=0;
+ if (!c) return 0; /* memory fail */
+
+ if (!parse_value(c,skip(value))) {
+ cJSON_Delete(c);
+ return 0;
+ }
+ return c;
}
/* Render a cJSON item/entity/structure to text. */
-char *cJSON_Print(cJSON *item) {return print_value(item,0,1);}
-char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);}
+char *cJSON_Print(cJSON *item) {
+ return print_value(item,0,1);
+}
+char *cJSON_PrintUnformatted(cJSON *item) {
+ return print_value(item,0,0);
+}
/* Parser core - when encountering text, process appropriately. */
-static const char *parse_value(cJSON *item,const char *value)
-{
- if (!value) return 0; /* Fail on null. */
- if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; }
- if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; }
- if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; }
- if (*value=='\"') { return parse_string(item,value); }
- if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); }
- if (*value=='[') { return parse_array(item,value); }
- if (*value=='{') { return parse_object(item,value); }
+static const char *parse_value(cJSON *item,const char *value) {
+ if (!value) return 0; /* Fail on null. */
+ if (!strncmp(value,"null",4)) {
+ item->type=cJSON_NULL;
+ return value+4;
+ }
+ if (!strncmp(value,"false",5)) {
+ item->type=cJSON_False;
+ return value+5;
+ }
+ if (!strncmp(value,"true",4)) {
+ item->type=cJSON_True;
+ item->valueint=1;
+ return value+4;
+ }
+ if (*value=='\"') {
+ return parse_string(item,value);
+ }
+ if (*value=='-' || (*value>='0' && *value<='9')) {
+ return parse_number(item,value);
+ }
+ if (*value=='[') {
+ return parse_array(item,value);
+ }
+ if (*value=='{') {
+ return parse_object(item,value);
+ }
- ep=value;return 0; /* failure. */
+ ep=value;
+ return 0; /* failure. */
}
/* Render a value to text. */
-static char *print_value(cJSON *item,int depth,int fmt)
-{
- char *out=0;
- if (!item) return 0;
- switch ((item->type)&255)
- {
- case cJSON_NULL: out=cJSON_strdup("null"); break;
- case cJSON_False: out=cJSON_strdup("false");break;
- case cJSON_True: out=cJSON_strdup("true"); break;
- case cJSON_Number: out=print_number(item);break;
- case cJSON_String: out=print_string(item);break;
- case cJSON_Array: out=print_array(item,depth,fmt);break;
- case cJSON_Object: out=print_object(item,depth,fmt);break;
- }
- return out;
+static char *print_value(cJSON *item,int depth,int fmt) {
+ char *out=0;
+ if (!item) return 0;
+ switch ((item->type)&255) {
+ case cJSON_NULL:
+ out=cJSON_strdup("null");
+ break;
+ case cJSON_False:
+ out=cJSON_strdup("false");
+ break;
+ case cJSON_True:
+ out=cJSON_strdup("true");
+ break;
+ case cJSON_Number:
+ out=print_number(item);
+ break;
+ case cJSON_String:
+ out=print_string(item);
+ break;
+ case cJSON_Array:
+ out=print_array(item,depth,fmt);
+ break;
+ case cJSON_Object:
+ out=print_object(item,depth,fmt);
+ break;
+ }
+ return out;
}
/* Build an array from input text. */
-static const char *parse_array(cJSON *item,const char *value)
-{
- cJSON *child;
- if (*value!='[') {ep=value;return 0;} /* not an array! */
-
- item->type=cJSON_Array;
- value=skip(value+1);
- if (*value==']') return value+1; /* empty array. */
-
- item->child=child=cJSON_New_Item();
- if (!item->child) return 0; /* memory fail */
- value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
- if (!value) return 0;
+static const char *parse_array(cJSON *item,const char *value) {
+ cJSON *child;
+ if (*value!='[') {
+ ep=value; /* not an array! */
+ return 0;
+ }
- while (*value==',')
- {
- cJSON *new_item;
- if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
- child->next=new_item;new_item->prev=child;child=new_item;
- value=skip(parse_value(child,skip(value+1)));
- if (!value) return 0; /* memory fail */
- }
+ item->type=cJSON_Array;
+ value=skip(value+1);
+ if (*value==']') return value+1; /* empty array. */
+
+ item->child=child=cJSON_New_Item();
+ if (!item->child) return 0; /* memory fail */
+ value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
+ if (!value) return 0;
+
+ while (*value==',') {
+ cJSON *new_item;
+ if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
+ child->next=new_item;
+ new_item->prev=child;
+ child=new_item;
+ value=skip(parse_value(child,skip(value+1)));
+ if (!value) return 0; /* memory fail */
+ }
- if (*value==']') return value+1; /* end of array */
- ep=value;return 0; /* malformed. */
+ if (*value==']') return value+1; /* end of array */
+ ep=value;
+ return 0; /* malformed. */
}
/* Render an array to text */
-static char *print_array(cJSON *item,int depth,int fmt)
-{
- char **entries;
- char *out=0,*ptr,*ret;int len=5;
- cJSON *child=item->child;
- int numentries=0,i=0,fail=0;
-
- /* How many entries in the array? */
- while (child) numentries++,child=child->next;
- /* Allocate an array to hold the values for each */
- entries=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!entries) return 0;
- memset(entries,0,numentries*sizeof(char*));
- /* Retrieve all the results: */
- child=item->child;
- while (child && !fail)
- {
- ret=print_value(child,depth+1,fmt);
- entries[i++]=ret;
- if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1;
- child=child->next;
- }
-
- /* If we didn't fail, try to malloc the output string */
- if (!fail) out=(char*)cJSON_malloc(len);
- /* If that fails, we fail. */
- if (!out) fail=1;
-
- /* Handle failure. */
- if (fail)
- {
- for (i=0;i<numentries;i++) if (entries[i]) cJSON_free(entries[i]);
- cJSON_free(entries);
- return 0;
- }
-
- /* Compose the output array. */
- *out='[';
- ptr=out+1;*ptr=0;
- for (i=0;i<numentries;i++)
- {
- strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
- if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
- cJSON_free(entries[i]);
- }
- cJSON_free(entries);
- *ptr++=']';*ptr++=0;
- return out;
+static char *print_array(cJSON *item,int depth,int fmt) {
+ char **entries;
+ char *out=0,*ptr,*ret;
+ int len=5;
+ cJSON *child=item->child;
+ int numentries=0,i=0,fail=0;
+
+ /* How many entries in the array? */
+ while (child) numentries++,child=child->next;
+ /* Allocate an array to hold the values for each */
+ entries=(char**)cJSON_malloc(numentries*sizeof(char*));
+ if (!entries) return 0;
+ memset(entries,0,numentries*sizeof(char*));
+ /* Retrieve all the results: */
+ child=item->child;
+ while (child && !fail) {
+ ret=print_value(child,depth+1,fmt);
+ entries[i++]=ret;
+ if (ret) len+=strlen(ret)+2+(fmt?1:0);
+ else fail=1;
+ child=child->next;
+ }
+
+ /* If we didn't fail, try to malloc the output string */
+ if (!fail) out=(char*)cJSON_malloc(len);
+ /* If that fails, we fail. */
+ if (!out) fail=1;
+
+ /* Handle failure. */
+ if (fail) {
+ for (i=0; i<numentries; i++) if (entries[i]) cJSON_free(entries[i]);
+ cJSON_free(entries);
+ return 0;
+ }
+
+ /* Compose the output array. */
+ *out='[';
+ ptr=out+1;
+ *ptr=0;
+ for (i=0; i<numentries; i++) {
+ strcpy(ptr,entries[i]);
+ ptr+=strlen(entries[i]);
+ if (i!=numentries-1) {
+ *ptr++=',';
+ if(fmt)*ptr++=' ';
+ *ptr=0;
+ }
+ cJSON_free(entries[i]);
+ }
+ cJSON_free(entries);
+ *ptr++=']';
+ *ptr++=0;
+ return out;
}
/* Build an object from the text. */
-static const char *parse_object(cJSON *item,const char *value)
-{
- cJSON *child;
- if (*value!='{') {ep=value;return 0;} /* not an object! */
-
- item->type=cJSON_Object;
- value=skip(value+1);
- if (*value=='}') return value+1; /* empty array. */
-
- item->child=child=cJSON_New_Item();
- if (!item->child) return 0;
- value=skip(parse_string(child,skip(value)));
- if (!value) return 0;
- child->string=child->valuestring;child->valuestring=0;
- if (*value!=':') {ep=value;return 0;} /* fail! */
- value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
- if (!value) return 0;
-
- while (*value==',')
- {
- cJSON *new_item;
- if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
- child->next=new_item;new_item->prev=child;child=new_item;
- value=skip(parse_string(child,skip(value+1)));
- if (!value) return 0;
- child->string=child->valuestring;child->valuestring=0;
- if (*value!=':') {ep=value;return 0;} /* fail! */
- value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
- if (!value) return 0;
- }
-
- if (*value=='}') return value+1; /* end of array */
- ep=value;return 0; /* malformed. */
+static const char *parse_object(cJSON *item,const char *value) {
+ cJSON *child;
+ if (*value!='{') {
+ ep=value; /* not an object! */
+ return 0;
+ }
+
+ item->type=cJSON_Object;
+ value=skip(value+1);
+ if (*value=='}') return value+1; /* empty array. */
+
+ item->child=child=cJSON_New_Item();
+ if (!item->child) return 0;
+ value=skip(parse_string(child,skip(value)));
+ if (!value) return 0;
+ child->string=child->valuestring;
+ child->valuestring=0;
+ if (*value!=':') {
+ ep=value; /* fail! */
+ return 0;
+ }
+ value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
+ if (!value) return 0;
+
+ while (*value==',') {
+ cJSON *new_item;
+ if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
+ child->next=new_item;
+ new_item->prev=child;
+ child=new_item;
+ value=skip(parse_string(child,skip(value+1)));
+ if (!value) return 0;
+ child->string=child->valuestring;
+ child->valuestring=0;
+ if (*value!=':') {
+ ep=value; /* fail! */
+ return 0;
+ }
+ value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
+ if (!value) return 0;
+ }
+
+ if (*value=='}') return value+1; /* end of array */
+ ep=value;
+ return 0; /* malformed. */
}
/* Render an object to text. */
-static char *print_object(cJSON *item,int depth,int fmt)
-{
- char **entries=0,**names=0;
- char *out=0,*ptr,*ret,*str;int len=7,i=0,j;
- cJSON *child=item->child;
- int numentries=0,fail=0;
- /* Count the number of entries. */
- while (child) numentries++,child=child->next;
- /* Allocate space for the names and the objects */
- entries=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!entries) return 0;
- names=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!names) {cJSON_free(entries);return 0;}
- memset(entries,0,sizeof(char*)*numentries);
- memset(names,0,sizeof(char*)*numentries);
-
- /* Collect all the results into our arrays: */
- child=item->child;depth++;if (fmt) len+=depth;
- while (child)
- {
- names[i]=str=print_string_ptr(child->string);
- entries[i++]=ret=print_value(child,depth,fmt);
- if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1;
- child=child->next;
- }
-
- /* Try to allocate the output string */
- if (!fail) out=(char*)cJSON_malloc(len);
- if (!out) fail=1;
-
- /* Handle failure */
- if (fail)
- {
- for (i=0;i<numentries;i++) {if (names[i]) cJSON_free(names[i]);if (entries[i]) cJSON_free(entries[i]);}
- cJSON_free(names);cJSON_free(entries);
- return 0;
- }
-
- /* Compose the output: */
- *out='{';ptr=out+1;if (fmt)*ptr++='\n';*ptr=0;
- for (i=0;i<numentries;i++)
- {
- if (fmt) for (j=0;j<depth;j++) *ptr++='\t';
- strcpy(ptr,names[i]);ptr+=strlen(names[i]);
- *ptr++=':';if (fmt) *ptr++='\t';
- strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
- if (i!=numentries-1) *ptr++=',';
- if (fmt) *ptr++='\n';*ptr=0;
- cJSON_free(names[i]);cJSON_free(entries[i]);
- }
-
- cJSON_free(names);cJSON_free(entries);
- if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
- *ptr++='}';*ptr++=0;
- return out;
+static char *print_object(cJSON *item,int depth,int fmt) {
+ char **entries=0,**names=0;
+ char *out=0,*ptr,*ret,*str;
+ int len=7,i=0,j;
+ cJSON *child=item->child;
+ int numentries=0,fail=0;
+ /* Count the number of entries. */
+ while (child) numentries++,child=child->next;
+ /* Allocate space for the names and the objects */
+ entries=(char**)cJSON_malloc(numentries*sizeof(char*));
+ if (!entries) return 0;
+ names=(char**)cJSON_malloc(numentries*sizeof(char*));
+ if (!names) {
+ cJSON_free(entries);
+ return 0;
+ }
+ memset(entries,0,sizeof(char*)*numentries);
+ memset(names,0,sizeof(char*)*numentries);
+
+ /* Collect all the results into our arrays: */
+ child=item->child;
+ depth++;
+ if (fmt) len+=depth;
+ while (child) {
+ names[i]=str=print_string_ptr(child->string);
+ entries[i++]=ret=print_value(child,depth,fmt);
+ if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0);
+ else fail=1;
+ child=child->next;
+ }
+
+ /* Try to allocate the output string */
+ if (!fail) out=(char*)cJSON_malloc(len);
+ if (!out) fail=1;
+
+ /* Handle failure */
+ if (fail) {
+ for (i=0; i<numentries; i++) {
+ if (names[i]) cJSON_free(names[i]);
+ if (entries[i]) cJSON_free(entries[i]);
+ }
+ cJSON_free(names);
+ cJSON_free(entries);
+ return 0;
+ }
+
+ /* Compose the output: */
+ *out='{';
+ ptr=out+1;
+ if (fmt)*ptr++='\n';
+ *ptr=0;
+ for (i=0; i<numentries; i++) {
+ if (fmt) for (j=0; j<depth; j++) *ptr++='\t';
+ strcpy(ptr,names[i]);
+ ptr+=strlen(names[i]);
+ *ptr++=':';
+ if (fmt) *ptr++='\t';
+ strcpy(ptr,entries[i]);
+ ptr+=strlen(entries[i]);
+ if (i!=numentries-1) *ptr++=',';
+ if (fmt) *ptr++='\n';
+ *ptr=0;
+ cJSON_free(names[i]);
+ cJSON_free(entries[i]);
+ }
+
+ cJSON_free(names);
+ cJSON_free(entries);
+ if (fmt) for (i=0; i<depth-1; i++) *ptr++='\t';
+ *ptr++='}';
+ *ptr++=0;
+ return out;
}
/* Get Array size/item / object item. */
-int cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;}
-cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;}
-cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
+int cJSON_GetArraySize(cJSON *array) {
+ cJSON *c=array->child;
+ int i=0;
+ while(c)i++,c=c->next;
+ return i;
+}
+cJSON *cJSON_GetArrayItem(cJSON *array,int item) {
+ cJSON *c=array->child;
+ while (c && item>0) item--,c=c->next;
+ return c;
+}
+cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {
+ cJSON *c=object->child;
+ while (c && cJSON_strcasecmp(c->string,string)) c=c->next;
+ return c;
+}
/* Utility for array list handling. */
-static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;}
+static void suffix_object(cJSON *prev,cJSON *item) {
+ prev->next=item;
+ item->prev=prev;
+}
/* Utility for handling references. */
-static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;}
+static cJSON *create_reference(cJSON *item) {
+ cJSON *ref=cJSON_New_Item();
+ if (!ref) return 0;
+ memcpy(ref,item,sizeof(cJSON));
+ ref->string=0;
+ ref->type|=cJSON_IsReference;
+ ref->next=ref->prev=0;
+ return ref;
+}
/* Add item to array/object. */
-void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}}
-void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}
-void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));}
-void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
+void cJSON_AddItemToArray(cJSON *array, cJSON *item) {
+ cJSON *c=array->child;
+ if (!item) return;
+ if (!c) {
+ array->child=item;
+ } else {
+ while (c && c->next) c=c->next;
+ suffix_object(c,item);
+ }
+}
+void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {
+ if (!item) return;
+ if (item->string) cJSON_free(item->string);
+ item->string=cJSON_strdup(string);
+ cJSON_AddItemToArray(object,item);
+}
+void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {
+ cJSON_AddItemToArray(array,create_reference(item));
+}
+void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {
+ cJSON_AddItemToObject(object,string,create_reference(item));
+}
-cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
- if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;}
-void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
-cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;}
-void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}
+cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {
+ cJSON *c=array->child;
+ while (c && which>0) c=c->next,which--;
+ if (!c) return 0;
+ if (c->prev) c->prev->next=c->next;
+ if (c->next) c->next->prev=c->prev;
+ if (c==array->child) array->child=c->next;
+ c->prev=c->next=0;
+ return c;
+}
+void cJSON_DeleteItemFromArray(cJSON *array,int which) {
+ cJSON_Delete(cJSON_DetachItemFromArray(array,which));
+}
+cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {
+ int i=0;
+ cJSON *c=object->child;
+ while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;
+ if (c) return cJSON_DetachItemFromArray(object,i);
+ return 0;
+}
+void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {
+ cJSON_Delete(cJSON_DetachItemFromObject(object,string));
+}
/* Replace array/object items with new ones. */
-void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
- newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
- if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
-void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}
+void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {
+ cJSON *c=array->child;
+ while (c && which>0) c=c->next,which--;
+ if (!c) return;
+ newitem->next=c->next;
+ newitem->prev=c->prev;
+ if (newitem->next) newitem->next->prev=newitem;
+ if (c==array->child) array->child=newitem;
+ else newitem->prev->next=newitem;
+ c->next=c->prev=0;
+ cJSON_Delete(c);
+}
+void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem) {
+ int i=0;
+ cJSON *c=object->child;
+ while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;
+ if(c) {
+ newitem->string=cJSON_strdup(string);
+ cJSON_ReplaceItemInArray(object,i,newitem);
+ }
+}
/* Create basic types: */
-cJSON *cJSON_CreateNull() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
-cJSON *cJSON_CreateTrue() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;}
-cJSON *cJSON_CreateFalse() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;}
-cJSON *cJSON_CreateBool(int b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
-cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int)num;}return item;}
-cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
-cJSON *cJSON_CreateArray() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
-cJSON *cJSON_CreateObject() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
+cJSON *cJSON_CreateNull() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_NULL;
+ return item;
+}
+cJSON *cJSON_CreateTrue() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_True;
+ return item;
+}
+cJSON *cJSON_CreateFalse() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_False;
+ return item;
+}
+cJSON *cJSON_CreateBool(int b) {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=b?cJSON_True:cJSON_False;
+ return item;
+}
+cJSON *cJSON_CreateNumber(double num) {
+ cJSON *item=cJSON_New_Item();
+ if(item) {
+ item->type=cJSON_Number;
+ item->valuedouble=num;
+ item->valueint=(int)num;
+ }
+ return item;
+}
+cJSON *cJSON_CreateString(const char *string) {
+ cJSON *item=cJSON_New_Item();
+ if(item) {
+ item->type=cJSON_String;
+ item->valuestring=cJSON_strdup(string);
+ }
+ return item;
+}
+cJSON *cJSON_CreateArray() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_Array;
+ return item;
+}
+cJSON *cJSON_CreateObject() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_Object;
+ return item;
+}
/* Create Arrays: */
-cJSON *cJSON_CreateIntArray(int *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateFloatArray(float *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateDoubleArray(double *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateStringArray(const char **strings,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateString(strings[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
+cJSON *cJSON_CreateIntArray(int *numbers,int count) {
+ int i;
+ cJSON *n=0,*p=0,*a=cJSON_CreateArray();
+ for(i=0; a && i<count; i++) {
+ n=cJSON_CreateNumber(numbers[i]);
+ if(!i)a->child=n;
+ else suffix_object(p,n);
+ p=n;
+ }
+ return a;
+}
+cJSON *cJSON_CreateFloatArray(float *numbers,int count) {
+ int i;
+ cJSON *n=0,*p=0,*a=cJSON_CreateArray();
+ for(i=0; a && i<count; i++) {
+ n=cJSON_CreateNumber(numbers[i]);
+ if(!i)a->child=n;
+ else suffix_object(p,n);
+ p=n;
+ }
+ return a;
+}
+cJSON *cJSON_CreateDoubleArray(double *numbers,int count) {
+ int i;
+ cJSON *n=0,*p=0,*a=cJSON_CreateArray();
+ for(i=0; a && i<count; i++) {
+ n=cJSON_CreateNumber(numbers[i]);
+ if(!i)a->child=n;
+ else suffix_object(p,n);
+ p=n;
+ }
+ return a;
+}
+cJSON *cJSON_CreateStringArray(const char **strings,int count) {
+ int i;
+ cJSON *n=0,*p=0,*a=cJSON_CreateArray();
+ for(i=0; a && i<count; i++) {
+ n=cJSON_CreateString(strings[i]);
+ if(!i)a->child=n;
+ else suffix_object(p,n);
+ p=n;
+ }
+ return a;
+}
diff --git a/navit/vehicle/webos/vehicle_webos.c b/navit/vehicle/webos/vehicle_webos.c
index 8ba477305..31f4b6cda 100644
--- a/navit/vehicle/webos/vehicle_webos.c
+++ b/navit/vehicle/webos/vehicle_webos.c
@@ -50,345 +50,331 @@ static char *vehicle_webos_prefix="webos:";
/*******************************************************************/
static void
-vehicle_webos_callback(PDL_ServiceParameters *params, void *priv)
-{
- PDL_Location *location;
- SDL_Event event;
- SDL_UserEvent userevent;
- int err;
-
- err = PDL_GetParamInt(params, "errorCode");
- if (err != 0) {
- dbg(lvl_error,"Location Callback errorCode %d", err);
- return /*PDL_EOTHER*/;
- }
-
- location = g_new0 (PDL_Location, 1);
-
- location->altitude = PDL_GetParamDouble(params, "altitude");
- location->velocity = PDL_GetParamDouble(params, "velocity");
- location->heading = PDL_GetParamDouble(params, "heading");
- location->horizontalAccuracy = PDL_GetParamDouble(params, "horizAccuracy");
- location->latitude = PDL_GetParamDouble(params, "latitude");
- location->longitude = PDL_GetParamDouble(params, "longitude");
-
- userevent.type = SDL_USEREVENT;
- userevent.code = PDL_GPS_UPDATE;
- userevent.data1 = location;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent(&event);
-
- return /*PDL_NOERROR*/;
+vehicle_webos_callback(PDL_ServiceParameters *params, void *priv) {
+ PDL_Location *location;
+ SDL_Event event;
+ SDL_UserEvent userevent;
+ int err;
+
+ err = PDL_GetParamInt(params, "errorCode");
+ if (err != 0) {
+ dbg(lvl_error,"Location Callback errorCode %d", err);
+ return /*PDL_EOTHER*/;
+ }
+
+ location = g_new0 (PDL_Location, 1);
+
+ location->altitude = PDL_GetParamDouble(params, "altitude");
+ location->velocity = PDL_GetParamDouble(params, "velocity");
+ location->heading = PDL_GetParamDouble(params, "heading");
+ location->horizontalAccuracy = PDL_GetParamDouble(params, "horizAccuracy");
+ location->latitude = PDL_GetParamDouble(params, "latitude");
+ location->longitude = PDL_GetParamDouble(params, "longitude");
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = PDL_GPS_UPDATE;
+ userevent.data1 = location;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent(&event);
+
+ return /*PDL_NOERROR*/;
}
static void
-vehicle_webos_gps_update(struct vehicle_priv *priv, PDL_Location *location)
-{
- if(location) { // location may be NULL if called by bluetooth-code. priv is already prefilled there
- struct timeval tv;
- gettimeofday(&tv,NULL);
-
- priv->delta = (int)difftime(tv.tv_sec, priv->fix_time);
- dbg(lvl_info,"delta(%i)",priv->delta);
- priv->fix_time = tv.tv_sec;
- priv->geo.lat = location->latitude;
- /* workaround for webOS GPS bug following */
- priv->geo.lng = (priv->pdk_version >= 200 && location->longitude >= -1 && location->longitude <= 1) ?
- -location->longitude : location->longitude;
-
- dbg(lvl_info,"Location: %f %f %f %.12g %.12g +-%fm",
- location->altitude,
- location->velocity,
- location->heading,
- priv->geo.lat,
- priv->geo.lng,
- location->horizontalAccuracy);
-
- if (location->altitude != -1)
- priv->altitude = location->altitude;
- if (location->velocity != -1)
- priv->speed = location->velocity * 3.6;
- if (location->heading != -1)
- priv->track = location->heading;
- if (location->horizontalAccuracy != -1)
- priv->radius = location->horizontalAccuracy;
-
- if (priv->pdk_version <= 100)
- g_free(location);
- }
-
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_webos_gps_update(struct vehicle_priv *priv, PDL_Location *location) {
+ if(location) { // location may be NULL if called by bluetooth-code. priv is already prefilled there
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+
+ priv->delta = (int)difftime(tv.tv_sec, priv->fix_time);
+ dbg(lvl_info,"delta(%i)",priv->delta);
+ priv->fix_time = tv.tv_sec;
+ priv->geo.lat = location->latitude;
+ /* workaround for webOS GPS bug following */
+ priv->geo.lng = (priv->pdk_version >= 200 && location->longitude >= -1 && location->longitude <= 1) ?
+ -location->longitude : location->longitude;
+
+ dbg(lvl_info,"Location: %f %f %f %.12g %.12g +-%fm",
+ location->altitude,
+ location->velocity,
+ location->heading,
+ priv->geo.lat,
+ priv->geo.lng,
+ location->horizontalAccuracy);
+
+ if (location->altitude != -1)
+ priv->altitude = location->altitude;
+ if (location->velocity != -1)
+ priv->speed = location->velocity * 3.6;
+ if (location->heading != -1)
+ priv->track = location->heading;
+ if (location->horizontalAccuracy != -1)
+ priv->radius = location->horizontalAccuracy;
+
+ if (priv->pdk_version <= 100)
+ g_free(location);
+ }
+
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
static void
-vehicle_webos_timeout_callback(struct vehicle_priv *priv)
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
+vehicle_webos_timeout_callback(struct vehicle_priv *priv) {
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
- if (priv->fix_time && priv->delta) {
- int delta = (int)difftime(tv.tv_sec, priv->fix_time);
+ if (priv->fix_time && priv->delta) {
+ int delta = (int)difftime(tv.tv_sec, priv->fix_time);
- if (delta >= priv->delta*2) {
- dbg(lvl_warning, "GPS timeout triggered cb(%p) delta(%d)", priv->timeout_cb, delta);
+ if (delta >= priv->delta*2) {
+ dbg(lvl_warning, "GPS timeout triggered cb(%p) delta(%d)", priv->timeout_cb, delta);
- priv->delta = -1;
+ priv->delta = -1;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
- }
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
+ }
}
void
-vehicle_webos_close(struct vehicle_priv *priv)
-{
- event_remove_timeout(priv->ev_timeout);
- priv->ev_timeout = NULL;
-
- callback_destroy(priv->timeout_cb);
-
- if (priv->pdk_version <= 100)
- PDL_UnregisterServiceCallback((PDL_ServiceCallbackFunc)vehicle_webos_callback);
- else {
- PDL_EnableLocationTracking(PDL_FALSE);
- vehicle_webos_bt_close(priv);
- }
+vehicle_webos_close(struct vehicle_priv *priv) {
+ event_remove_timeout(priv->ev_timeout);
+ priv->ev_timeout = NULL;
+
+ callback_destroy(priv->timeout_cb);
+
+ if (priv->pdk_version <= 100)
+ PDL_UnregisterServiceCallback((PDL_ServiceCallbackFunc)vehicle_webos_callback);
+ else {
+ PDL_EnableLocationTracking(PDL_FALSE);
+ vehicle_webos_bt_close(priv);
+ }
}
static int
-vehicle_webos_open(struct vehicle_priv *priv)
-{
- PDL_Err err;
-
- priv->pdk_version = PDL_GetPDKVersion();
- dbg(lvl_debug,"pdk_version(%d)", priv->pdk_version);
-
- if (priv->pdk_version <= 100) {
- // Use Location Service via callback interface
- err = PDL_ServiceCallWithCallback("palm://com.palm.location/startTracking",
- "{subscribe:true}",
- (PDL_ServiceCallbackFunc)vehicle_webos_callback,
- priv,
- PDL_FALSE);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_ServiceCallWithCallback failed with (%d): (%s)", err, PDL_GetError());
- vehicle_webos_close(priv);
- return 0;
- }
- }
- else {
- PDL_Err err;
- err = PDL_EnableLocationTracking(PDL_TRUE);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_EnableLocationTracking failed with (%d): (%s)", err, PDL_GetError());
+vehicle_webos_open(struct vehicle_priv *priv) {
+ PDL_Err err;
+
+ priv->pdk_version = PDL_GetPDKVersion();
+ dbg(lvl_debug,"pdk_version(%d)", priv->pdk_version);
+
+ if (priv->pdk_version <= 100) {
+ // Use Location Service via callback interface
+ err = PDL_ServiceCallWithCallback("palm://com.palm.location/startTracking",
+ "{subscribe:true}",
+ (PDL_ServiceCallbackFunc)vehicle_webos_callback,
+ priv,
+ PDL_FALSE);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_ServiceCallWithCallback failed with (%d): (%s)", err, PDL_GetError());
+ vehicle_webos_close(priv);
+ return 0;
+ }
+ } else {
+ PDL_Err err;
+ err = PDL_EnableLocationTracking(PDL_TRUE);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_EnableLocationTracking failed with (%d): (%s)", err, PDL_GetError());
// vehicle_webos_close(priv);
// return 0;
- }
-
- priv->gps_type = GPS_TYPE_INT;
+ }
- if(!vehicle_webos_bt_open(priv))
- return 0;
- }
+ priv->gps_type = GPS_TYPE_INT;
- priv->ev_timeout = event_add_timeout(1000, 1, priv->timeout_cb);
- return 1;
+ if(!vehicle_webos_bt_open(priv))
+ return 0;
+ }
+
+ priv->ev_timeout = event_add_timeout(1000, 1, priv->timeout_cb);
+ return 1;
}
static void
-vehicle_webos_destroy(struct vehicle_priv *priv)
-{
- vehicle_webos_close(priv);
- if (priv->source)
- g_free(priv->source);
- g_free(priv);
+vehicle_webos_destroy(struct vehicle_priv *priv) {
+ vehicle_webos_close(priv);
+ if (priv->source)
+ g_free(priv->source);
+ g_free(priv);
}
static int
vehicle_webos_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_height:
- dbg(lvl_info,"Altitude: %f", priv->altitude);
- attr->u.numd = &priv->altitude;
- break;
- case attr_position_speed:
- dbg(lvl_info,"Speed: %f", priv->speed);
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- dbg(lvl_info,"Direction: %f", priv->track);
- attr->u.numd = &priv->track;
- break;
- case attr_position_magnetic_direction:
- switch (priv->gps_type) {
- case GPS_TYPE_BT:
- attr->u.num = priv->magnetic_direction;
- break;
- default:
- return 0;
- break;
- }
- break;
- case attr_position_hdop:
- switch (priv->gps_type) {
- case GPS_TYPE_BT:
- attr->u.numd = &priv->hdop;
- break;
- default:
- return 0;
- break;
- }
- break;
- case attr_position_coord_geo:
- dbg(lvl_info,"Coord: %.12g %.12g", priv->geo.lat, priv->geo.lng);
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_radius:
- dbg(lvl_info,"Radius: %f", priv->radius);
- attr->u.numd = &priv->radius;
- break;
- case attr_position_time_iso8601:
- if (priv->fix_time) {
- struct tm tm;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- }
- else {
- priv->fix_time = 0;
- return 0;
- }
- dbg(lvl_info,"Fix Time: %d %s", priv->fix_time, priv->fixiso8601);
- }
- else {
- dbg(lvl_info,"Fix Time: %d", priv->fix_time);
- return 0;
- }
-
- break;
- case attr_position_fix_type:
- switch (priv->gps_type) {
- case GPS_TYPE_INT:
- if (priv->delta <= 0 || priv->radius == 0.0)
- attr->u.num = 0; // strength = 1
- else if (priv->radius > 20.0)
- attr->u.num = 1; // strength >= 2
- else
- attr->u.num = 2; // strength >= 2
- break;
- case GPS_TYPE_BT:
- attr->u.num = priv->status;
- break;
- default:
- return 0;
- break;
- }
- break;
- case attr_position_sats_used:
- switch (priv->gps_type) {
- case GPS_TYPE_INT:
- if (priv->delta <= 0)
- attr->u.num = 0;
- else if (priv->radius <= 6.0 )
- attr->u.num = 6; // strength = 5
- else if (priv->radius <= 10.0 )
- attr->u.num = 5; // strength = 4
- else if (priv->radius <= 15.0 )
- attr->u.num = 4; // strength = 3
- else
- return 0;
- break;
- case GPS_TYPE_BT:
- attr->u.num = priv->sats_used;
- break;
- default:
- return 0;
- break;
- }
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_height:
+ dbg(lvl_info,"Altitude: %f", priv->altitude);
+ attr->u.numd = &priv->altitude;
+ break;
+ case attr_position_speed:
+ dbg(lvl_info,"Speed: %f", priv->speed);
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ dbg(lvl_info,"Direction: %f", priv->track);
+ attr->u.numd = &priv->track;
+ break;
+ case attr_position_magnetic_direction:
+ switch (priv->gps_type) {
+ case GPS_TYPE_BT:
+ attr->u.num = priv->magnetic_direction;
+ break;
+ default:
+ return 0;
+ break;
+ }
+ break;
+ case attr_position_hdop:
+ switch (priv->gps_type) {
+ case GPS_TYPE_BT:
+ attr->u.numd = &priv->hdop;
+ break;
+ default:
+ return 0;
+ break;
+ }
+ break;
+ case attr_position_coord_geo:
+ dbg(lvl_info,"Coord: %.12g %.12g", priv->geo.lat, priv->geo.lng);
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_radius:
+ dbg(lvl_info,"Radius: %f", priv->radius);
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_time_iso8601:
+ if (priv->fix_time) {
+ struct tm tm;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else {
+ priv->fix_time = 0;
+ return 0;
+ }
+ dbg(lvl_info,"Fix Time: %d %s", priv->fix_time, priv->fixiso8601);
+ } else {
+ dbg(lvl_info,"Fix Time: %d", priv->fix_time);
+ return 0;
+ }
+
+ break;
+ case attr_position_fix_type:
+ switch (priv->gps_type) {
+ case GPS_TYPE_INT:
+ if (priv->delta <= 0 || priv->radius == 0.0)
+ attr->u.num = 0; // strength = 1
+ else if (priv->radius > 20.0)
+ attr->u.num = 1; // strength >= 2
+ else
+ attr->u.num = 2; // strength >= 2
+ break;
+ case GPS_TYPE_BT:
+ attr->u.num = priv->status;
+ break;
+ default:
+ return 0;
+ break;
+ }
+ break;
+ case attr_position_sats_used:
+ switch (priv->gps_type) {
+ case GPS_TYPE_INT:
+ if (priv->delta <= 0)
+ attr->u.num = 0;
+ else if (priv->radius <= 6.0 )
+ attr->u.num = 6; // strength = 5
+ else if (priv->radius <= 10.0 )
+ attr->u.num = 5; // strength = 4
+ else if (priv->radius <= 15.0 )
+ attr->u.num = 4; // strength = 3
+ else
+ return 0;
+ break;
+ case GPS_TYPE_BT:
+ attr->u.num = priv->sats_used;
+ break;
+ default:
+ return 0;
+ break;
+ }
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static int
-vehicle_webos_set_attr_do(struct vehicle_priv *priv, struct attr *attr, int init)
-{
- switch (attr->type) {
- case attr_source:
- if (strncmp(vehicle_webos_prefix,attr->u.str,strlen(vehicle_webos_prefix))) {
- dbg(lvl_warning,"source must start with '%s'", vehicle_webos_prefix);
- return 0;
- }
- g_free(priv->source);
- priv->source=g_strdup(attr->u.str);
- priv->address=priv->source+strlen(vehicle_webos_prefix);
- if (!priv->address[0])
- priv->address=NULL;
- if (!init) {
- vehicle_webos_close(priv);
- vehicle_webos_open(priv);
- }
- return 1;
- case attr_profilename:
- return 1;
- case attr_pdl_gps_update:
- vehicle_webos_gps_update(priv, (PDL_Location *)attr->u.data);
- return 1;
- default:
- return 0;
- }
+vehicle_webos_set_attr_do(struct vehicle_priv *priv, struct attr *attr, int init) {
+ switch (attr->type) {
+ case attr_source:
+ if (strncmp(vehicle_webos_prefix,attr->u.str,strlen(vehicle_webos_prefix))) {
+ dbg(lvl_warning,"source must start with '%s'", vehicle_webos_prefix);
+ return 0;
+ }
+ g_free(priv->source);
+ priv->source=g_strdup(attr->u.str);
+ priv->address=priv->source+strlen(vehicle_webos_prefix);
+ if (!priv->address[0])
+ priv->address=NULL;
+ if (!init) {
+ vehicle_webos_close(priv);
+ vehicle_webos_open(priv);
+ }
+ return 1;
+ case attr_profilename:
+ return 1;
+ case attr_pdl_gps_update:
+ vehicle_webos_gps_update(priv, (PDL_Location *)attr->u.data);
+ return 1;
+ default:
+ return 0;
+ }
}
static int
-vehicle_webos_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- return vehicle_webos_set_attr_do(priv, attr, 0);
+vehicle_webos_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ return vehicle_webos_set_attr_do(priv, attr, 0);
}
struct vehicle_methods vehicle_webos_methods = {
- vehicle_webos_destroy,
- vehicle_webos_position_attr_get,
- vehicle_webos_set_attr,
+ vehicle_webos_destroy,
+ vehicle_webos_position_attr_get,
+ vehicle_webos_set_attr,
};
static struct vehicle_priv *
vehicle_webos_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *priv;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *priv;
- priv = g_new0(struct vehicle_priv, 1);
- priv->attrs = attrs;
- priv->cbl = cbl;
+ priv = g_new0(struct vehicle_priv, 1);
+ priv->attrs = attrs;
+ priv->cbl = cbl;
- priv->timeout_cb = callback_new_1(callback_cast(vehicle_webos_timeout_callback), priv);
+ priv->timeout_cb = callback_new_1(callback_cast(vehicle_webos_timeout_callback), priv);
- *meth = vehicle_webos_methods;
- while (*attrs) {
- vehicle_webos_set_attr_do(priv, *attrs, 1);
- attrs++;
- }
+ *meth = vehicle_webos_methods;
+ while (*attrs) {
+ vehicle_webos_set_attr_do(priv, *attrs, 1);
+ attrs++;
+ }
- vehicle_webos_open(priv);
+ vehicle_webos_open(priv);
- return priv;
+ return priv;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("webos", vehicle_webos_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("webos", vehicle_webos_new);
}
diff --git a/navit/vehicle/wince/vehicle_wince.c b/navit/vehicle/wince/vehicle_wince.c
index da77c5b6f..6d615c0fb 100644
--- a/navit/vehicle/wince/vehicle_wince.c
+++ b/navit/vehicle/wince/vehicle_wince.c
@@ -73,304 +73,277 @@ static int vehicle_wince_open(struct vehicle_priv *priv);
static void vehicle_wince_close(struct vehicle_priv *priv);
enum file_type {
- file_type_pipe = 1, file_type_device, file_type_file, file_type_socket
+ file_type_pipe = 1, file_type_device, file_type_file, file_type_socket
};
static int buffer_size = 1024;
struct gps_sat {
- int prn;
- int elevation;
- int azimuth;
- int snr;
+ int prn;
+ int elevation;
+ int azimuth;
+ int snr;
};
struct vehicle_priv {
- char *source;
- struct callback_list *cbl;
- struct callback_list *priv_cbl;
- struct callback *cb_fix_timeout;
- struct event_timeout *ev_fix_timeout;
- int is_running;
- int thread_up;
- int fd;
- HANDLE m_hGPSDevice; // Handle to the device
- HANDLE m_hGPSThread; // Handle to the thread
- DWORD m_dwGPSThread; // Thread id
-
- char *buffer;
- int buffer_pos;
- char *read_buffer;
- int read_buffer_pos;
- char *nmea_data;
- char *nmea_data_buf;
-
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- double hdop;
- double vdop;
- char fixtime[20];
- int fixyear;
- int fixmonth;
- int fixday;
- int status;
- int sats_used;
- int sats_visible;
- int sats_signal;
- int time;
- int on_eof;
- int baudrate;
- enum file_type file_type;
- struct attr ** attrs;
- char fixiso8601[128];
- int checksum_ignore;
- HMODULE hBthDll;
- PFN_BthSetMode BthSetMode;
- int magnetic_direction;
- int current_count;
- struct gps_sat current[24];
- int next_count;
- struct gps_sat next[24];
- struct item sat_item;
- int valid;
- int has_data;
- GMutex lock;
+ char *source;
+ struct callback_list *cbl;
+ struct callback_list *priv_cbl;
+ struct callback *cb_fix_timeout;
+ struct event_timeout *ev_fix_timeout;
+ int is_running;
+ int thread_up;
+ int fd;
+ HANDLE m_hGPSDevice; // Handle to the device
+ HANDLE m_hGPSThread; // Handle to the thread
+ DWORD m_dwGPSThread; // Thread id
+
+ char *buffer;
+ int buffer_pos;
+ char *read_buffer;
+ int read_buffer_pos;
+ char *nmea_data;
+ char *nmea_data_buf;
+
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ double hdop;
+ double vdop;
+ char fixtime[20];
+ int fixyear;
+ int fixmonth;
+ int fixday;
+ int status;
+ int sats_used;
+ int sats_visible;
+ int sats_signal;
+ int time;
+ int on_eof;
+ int baudrate;
+ enum file_type file_type;
+ struct attr ** attrs;
+ char fixiso8601[128];
+ int checksum_ignore;
+ HMODULE hBthDll;
+ PFN_BthSetMode BthSetMode;
+ int magnetic_direction;
+ int current_count;
+ struct gps_sat current[24];
+ int next_count;
+ struct gps_sat next[24];
+ struct item sat_item;
+ int valid;
+ int has_data;
+ GMutex lock;
};
-static void initBth(struct vehicle_priv *priv)
-{
-
- BOOL succeeded = FALSE;
- priv->hBthDll = LoadLibrary(TEXT("bthutil.dll"));
- if ( priv->hBthDll )
- {
- DWORD bthMode;
- PFN_BthGetMode BthGetMode = (PFN_BthGetMode)GetProcAddress(priv->hBthDll, TEXT("BthGetMode") );
-
- if ( BthGetMode && BthGetMode(&bthMode) == ERROR_SUCCESS && bthMode == 0 )
- {
- priv->BthSetMode = (PFN_BthSetMode)GetProcAddress(priv->hBthDll, TEXT("BthSetMode") );
- if( priv->BthSetMode && priv->BthSetMode(1) == ERROR_SUCCESS )
- {
- dbg(lvl_debug, "bluetooth activated");
- succeeded = TRUE;
- }
- }
-
- }
- else
- {
- dbg(lvl_error, "Bluetooth library notfound");
- }
-
- if ( !succeeded )
- {
-
- dbg(lvl_warning, "Bluetooth already enabled or failed to enable it.");
- priv->BthSetMode = NULL;
- if ( priv->hBthDll )
- {
- FreeLibrary(priv->hBthDll);
- }
- }
+static void initBth(struct vehicle_priv *priv) {
+
+ BOOL succeeded = FALSE;
+ priv->hBthDll = LoadLibrary(TEXT("bthutil.dll"));
+ if ( priv->hBthDll ) {
+ DWORD bthMode;
+ PFN_BthGetMode BthGetMode = (PFN_BthGetMode)GetProcAddress(priv->hBthDll, TEXT("BthGetMode") );
+
+ if ( BthGetMode && BthGetMode(&bthMode) == ERROR_SUCCESS && bthMode == 0 ) {
+ priv->BthSetMode = (PFN_BthSetMode)GetProcAddress(priv->hBthDll, TEXT("BthSetMode") );
+ if( priv->BthSetMode && priv->BthSetMode(1) == ERROR_SUCCESS ) {
+ dbg(lvl_debug, "bluetooth activated");
+ succeeded = TRUE;
+ }
+ }
+
+ } else {
+ dbg(lvl_error, "Bluetooth library notfound");
+ }
+
+ if ( !succeeded ) {
+
+ dbg(lvl_warning, "Bluetooth already enabled or failed to enable it.");
+ priv->BthSetMode = NULL;
+ if ( priv->hBthDll ) {
+ FreeLibrary(priv->hBthDll);
+ }
+ }
}
-static int initDevice(struct vehicle_priv *priv)
-{
- COMMTIMEOUTS commTiming;
- HANDLE hGPS;
- if ( priv->m_hGPSDevice )
- CloseHandle(priv->m_hGPSDevice);
-
- if ( priv->file_type == file_type_device )
- {
- dbg(lvl_debug, "Init Device");
- /* GPD0 is the control port for the GPS driver */
- hGPS = CreateFile(L"GPD0:", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
- if (hGPS != INVALID_HANDLE_VALUE) {
+static int initDevice(struct vehicle_priv *priv) {
+ COMMTIMEOUTS commTiming;
+ HANDLE hGPS;
+ if ( priv->m_hGPSDevice )
+ CloseHandle(priv->m_hGPSDevice);
+
+ if ( priv->file_type == file_type_device ) {
+ dbg(lvl_debug, "Init Device");
+ /* GPD0 is the control port for the GPS driver */
+ hGPS = CreateFile(L"GPD0:", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
+ 0);
+ if (hGPS != INVALID_HANDLE_VALUE) {
#ifndef IOCTL_SERVICE_REFRESH
#define IOCTL_SERVICE_REFRESH 0x4100000C
#endif
- DeviceIoControl(hGPS,IOCTL_SERVICE_REFRESH,0,0,0,0,0,0);
+ DeviceIoControl(hGPS,IOCTL_SERVICE_REFRESH,0,0,0,0,0,0);
#ifndef IOCTL_SERVICE_START
#define IOCTL_SERVICE_START 0x41000004
#endif
- DeviceIoControl(hGPS,IOCTL_SERVICE_START,0,0,0,0,0,0);
- CloseHandle(hGPS);
- }
-
- while (priv->is_running &&
- (priv->m_hGPSDevice = CreateFile(A2W(priv->source),
- GENERIC_READ, 0,
- NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
- {
- Sleep(1000);
- dbg(lvl_debug, "Waiting to connect to %s", priv->source);
- }
- GetCommTimeouts (priv->m_hGPSDevice, &commTiming);
- commTiming.ReadIntervalTimeout = 20;
- commTiming.ReadTotalTimeoutMultiplier = 0;
- commTiming.ReadTotalTimeoutConstant = 200;
-
- commTiming.WriteTotalTimeoutMultiplier=5;
- commTiming.WriteTotalTimeoutConstant=5;
- SetCommTimeouts (priv->m_hGPSDevice, &commTiming);
-
- if (priv->baudrate) {
- DCB portState;
- if (!GetCommState(priv->m_hGPSDevice, &portState)) {
- MessageBox (NULL, TEXT ("GetCommState Error"), TEXT (""),
- MB_APPLMODAL|MB_OK);
- priv->thread_up = 0;
- return 0;
- }
- portState.BaudRate = priv->baudrate;
- if (!SetCommState(priv->m_hGPSDevice, &portState)) {
- MessageBox (NULL, TEXT ("SetCommState Error"), TEXT (""),
- MB_APPLMODAL|MB_OK);
- priv->thread_up = 0;
- return 0;
- }
- }
-
- }
- else
- {
- dbg(lvl_debug, "Open File");
- priv->m_hGPSDevice = CreateFileW( A2W(priv->source),
- GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
- if ( priv->m_hGPSDevice == INVALID_HANDLE_VALUE) {
- dbg(lvl_error, "Could not open %s", priv->source);
- return 0;
- }
- }
- return 1;
+ DeviceIoControl(hGPS,IOCTL_SERVICE_START,0,0,0,0,0,0);
+ CloseHandle(hGPS);
+ }
+
+ while (priv->is_running &&
+ (priv->m_hGPSDevice = CreateFile(A2W(priv->source),
+ GENERIC_READ, 0,
+ NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
+ Sleep(1000);
+ dbg(lvl_debug, "Waiting to connect to %s", priv->source);
+ }
+ GetCommTimeouts (priv->m_hGPSDevice, &commTiming);
+ commTiming.ReadIntervalTimeout = 20;
+ commTiming.ReadTotalTimeoutMultiplier = 0;
+ commTiming.ReadTotalTimeoutConstant = 200;
+
+ commTiming.WriteTotalTimeoutMultiplier=5;
+ commTiming.WriteTotalTimeoutConstant=5;
+ SetCommTimeouts (priv->m_hGPSDevice, &commTiming);
+
+ if (priv->baudrate) {
+ DCB portState;
+ if (!GetCommState(priv->m_hGPSDevice, &portState)) {
+ MessageBox (NULL, TEXT ("GetCommState Error"), TEXT (""),
+ MB_APPLMODAL|MB_OK);
+ priv->thread_up = 0;
+ return 0;
+ }
+ portState.BaudRate = priv->baudrate;
+ if (!SetCommState(priv->m_hGPSDevice, &portState)) {
+ MessageBox (NULL, TEXT ("SetCommState Error"), TEXT (""),
+ MB_APPLMODAL|MB_OK);
+ priv->thread_up = 0;
+ return 0;
+ }
+ }
+
+ } else {
+ dbg(lvl_debug, "Open File");
+ priv->m_hGPSDevice = CreateFileW( A2W(priv->source),
+ GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
+ if ( priv->m_hGPSDevice == INVALID_HANDLE_VALUE) {
+ dbg(lvl_error, "Could not open %s", priv->source);
+ return 0;
+ }
+ }
+ return 1;
}
-static int read_win32(struct vehicle_priv *priv, char *buffer, size_t size)
-{
- int ret_size;
-
- g_mutex_lock(&priv->lock);
- ret_size = MIN(size,priv->read_buffer_pos);
- priv->has_data = 0;
- memcpy(buffer, priv->read_buffer, ret_size);
-
- memmove(priv->read_buffer, priv->read_buffer + ret_size, buffer_size - ret_size);
- priv->read_buffer_pos -= ret_size;
- g_mutex_unlock(&priv->lock);
- return ret_size;
+static int read_win32(struct vehicle_priv *priv, char *buffer, size_t size) {
+ int ret_size;
+
+ g_mutex_lock(&priv->lock);
+ ret_size = MIN(size,priv->read_buffer_pos);
+ priv->has_data = 0;
+ memcpy(buffer, priv->read_buffer, ret_size);
+
+ memmove(priv->read_buffer, priv->read_buffer + ret_size, buffer_size - ret_size);
+ priv->read_buffer_pos -= ret_size;
+ g_mutex_unlock(&priv->lock);
+ return ret_size;
}
-static DWORD WINAPI wince_reader_thread (LPVOID lParam)
-{
- struct vehicle_priv *priv = lParam;
- char chunk_buffer[3*82];
- BOOL status;
- DWORD bytes_read;
- int waitcounter;
-
- dbg(lvl_debug, "GPS Port:[%s]", priv->source);
- priv->thread_up = 1;
-
- if ( !initDevice(priv) ) {
- return -1;
- }
- while (priv->is_running)
- {
- dbg(lvl_debug,"readfile");
- waitcounter = 0;
- status = ReadFile(priv->m_hGPSDevice,
- chunk_buffer, sizeof(chunk_buffer),
- &bytes_read, NULL);
-
- if ( !status )
- {
- dbg(lvl_error,"Error reading file/device. Try again.");
- initDevice(priv);
- continue;
- }
-
- while ( priv->read_buffer_pos + bytes_read > buffer_size )
- {
- /* TODO (rikky#1#): should use blocking */
- if ( priv->file_type != file_type_file )
- {
- dbg(lvl_debug, "GPS data comes too fast. Have to wait here");
- }
-
- Sleep(50);
- waitcounter++;
- if ( waitcounter % 8 == 0 )
- {
- dbg(lvl_debug, "Remind them of the data");
- event_call_callback(priv->priv_cbl);
- }
- if(waitcounter % 200 == 0) {
- dbg(lvl_error,"Will main thread ever be ready for the GPS data? Already %d intervals gone.",waitcounter);
- }
-
- }
-
- if(waitcounter>2)
- dbg(lvl_debug,"Sent GPS data to the main thread after %d intervals delay.",waitcounter);
-
- g_mutex_lock(&priv->lock);
- memcpy(priv->read_buffer + priv->read_buffer_pos , chunk_buffer, bytes_read );
-
- priv->read_buffer_pos += bytes_read;
-
- if ( !priv->has_data )
- {
- event_call_callback(priv->priv_cbl);
- priv->has_data = 1;
- }
-
- g_mutex_unlock(&priv->lock);
- }
- return TRUE;
+static DWORD WINAPI wince_reader_thread (LPVOID lParam) {
+ struct vehicle_priv *priv = lParam;
+ char chunk_buffer[3*82];
+ BOOL status;
+ DWORD bytes_read;
+ int waitcounter;
+
+ dbg(lvl_debug, "GPS Port:[%s]", priv->source);
+ priv->thread_up = 1;
+
+ if ( !initDevice(priv) ) {
+ return -1;
+ }
+ while (priv->is_running) {
+ dbg(lvl_debug,"readfile");
+ waitcounter = 0;
+ status = ReadFile(priv->m_hGPSDevice,
+ chunk_buffer, sizeof(chunk_buffer),
+ &bytes_read, NULL);
+
+ if ( !status ) {
+ dbg(lvl_error,"Error reading file/device. Try again.");
+ initDevice(priv);
+ continue;
+ }
+
+ while ( priv->read_buffer_pos + bytes_read > buffer_size ) {
+ /* TODO (rikky#1#): should use blocking */
+ if ( priv->file_type != file_type_file ) {
+ dbg(lvl_debug, "GPS data comes too fast. Have to wait here");
+ }
+
+ Sleep(50);
+ waitcounter++;
+ if ( waitcounter % 8 == 0 ) {
+ dbg(lvl_debug, "Remind them of the data");
+ event_call_callback(priv->priv_cbl);
+ }
+ if(waitcounter % 200 == 0) {
+ dbg(lvl_error,"Will main thread ever be ready for the GPS data? Already %d intervals gone.",waitcounter);
+ }
+
+ }
+
+ if(waitcounter>2)
+ dbg(lvl_debug,"Sent GPS data to the main thread after %d intervals delay.",waitcounter);
+
+ g_mutex_lock(&priv->lock);
+ memcpy(priv->read_buffer + priv->read_buffer_pos, chunk_buffer, bytes_read );
+
+ priv->read_buffer_pos += bytes_read;
+
+ if ( !priv->has_data ) {
+ event_call_callback(priv->priv_cbl);
+ priv->has_data = 1;
+ }
+
+ g_mutex_unlock(&priv->lock);
+ }
+ return TRUE;
}
static int
-vehicle_wince_available_ports(void)
-{
- HKEY hkResult;
- HKEY hkSubResult;
- wchar_t keyname[20];
- wchar_t devicename[100];
- wchar_t devicetype[100];
- int index = 0;
- DWORD regkey_length = sizeof(keyname);
- DWORD regdevtype_length = sizeof(devicetype);
-
- RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Drivers\\Active"), 0, 0, &hkResult);
- while (RegEnumKeyEx( hkResult, index++, keyname, &regkey_length, NULL, NULL, NULL, NULL) == ERROR_SUCCESS )
- {
- if (RegOpenKeyEx( hkResult, keyname, 0, 0, &hkSubResult) == ERROR_SUCCESS )
- {
- regkey_length = sizeof(keyname);
- if ( RegQueryValueEx( hkSubResult, L"Name", NULL, NULL, (LPBYTE)devicename, &regkey_length) == ERROR_SUCCESS )
- {
- regdevtype_length = sizeof(devicetype);
- if ( RegQueryValueEx( hkSubResult, L"Key", NULL, NULL, (LPBYTE)devicetype, &regdevtype_length) == ERROR_SUCCESS )
- {
- dbg(lvl_debug, "Found device '%s' (%s)", W2A(devicename), W2A(devicetype));
- }
- else
- {
- dbg(lvl_debug, "Found device '%s'", W2A(devicename));
- }
- }
- RegCloseKey(hkSubResult);
- }
- regkey_length = sizeof(keyname);
- }
-
- RegCloseKey(hkResult);
- return 0;
+vehicle_wince_available_ports(void) {
+ HKEY hkResult;
+ HKEY hkSubResult;
+ wchar_t keyname[20];
+ wchar_t devicename[100];
+ wchar_t devicetype[100];
+ int index = 0;
+ DWORD regkey_length = sizeof(keyname);
+ DWORD regdevtype_length = sizeof(devicetype);
+
+ RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Drivers\\Active"), 0, 0, &hkResult);
+ while (RegEnumKeyEx( hkResult, index++, keyname, &regkey_length, NULL, NULL, NULL, NULL) == ERROR_SUCCESS ) {
+ if (RegOpenKeyEx( hkResult, keyname, 0, 0, &hkSubResult) == ERROR_SUCCESS ) {
+ regkey_length = sizeof(keyname);
+ if ( RegQueryValueEx( hkSubResult, L"Name", NULL, NULL, (LPBYTE)devicename, &regkey_length) == ERROR_SUCCESS ) {
+ regdevtype_length = sizeof(devicetype);
+ if ( RegQueryValueEx( hkSubResult, L"Key", NULL, NULL, (LPBYTE)devicetype, &regdevtype_length) == ERROR_SUCCESS ) {
+ dbg(lvl_debug, "Found device '%s' (%s)", W2A(devicename), W2A(devicetype));
+ } else {
+ dbg(lvl_debug, "Found device '%s'", W2A(devicename));
+ }
+ }
+ RegCloseKey(hkSubResult);
+ }
+ regkey_length = sizeof(keyname);
+ }
+
+ RegCloseKey(hkResult);
+ return 0;
}
@@ -381,11 +354,10 @@ vehicle_wince_available_ports(void)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_wince_fix_timeout_cb(struct vehicle_priv *priv)
-{
- priv->valid = attr_position_valid_invalid;
- priv->ev_fix_timeout = NULL;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_wince_fix_timeout_cb(struct vehicle_priv *priv) {
+ priv->valid = attr_position_valid_invalid;
+ priv->ev_fix_timeout = NULL;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
@@ -395,426 +367,416 @@ vehicle_wince_fix_timeout_cb(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_wince_restart_fix_timeout(struct vehicle_priv *priv)
-{
- if (priv->ev_fix_timeout != NULL)
- event_remove_timeout(priv->ev_fix_timeout);
- priv->ev_fix_timeout = event_add_timeout(10000, 0, priv->cb_fix_timeout);
+vehicle_wince_restart_fix_timeout(struct vehicle_priv *priv) {
+ if (priv->ev_fix_timeout != NULL)
+ event_remove_timeout(priv->ev_fix_timeout);
+ priv->ev_fix_timeout = event_add_timeout(10000, 0, priv->cb_fix_timeout);
}
static int
-vehicle_wince_open(struct vehicle_priv *priv)
-{
- char* raw_setting_str;
- char* strport;
- char* strsettings;
-
- dbg(lvl_debug, "enter vehicle_wince_open, priv->source='%s'", priv->source);
-
- if (priv->source ) {
-
- if ( strcmp(priv->source, "list") == 0 )
- {
- vehicle_wince_available_ports();
- return 0;
- }
-
- raw_setting_str = g_strdup( priv->source );
- strport = strchr(raw_setting_str, ':' );
- strsettings = strchr(raw_setting_str, ' ' );
-
- if (raw_setting_str && strport&&strsettings ) {
- strport++;
- *strsettings = '\0';
- strsettings++;
-
- dbg(lvl_debug, "serial('%s', '%s')", strport, strsettings );
- }
- if (raw_setting_str)
- g_free( raw_setting_str );
- }
- return 1;
+vehicle_wince_open(struct vehicle_priv *priv) {
+ char* raw_setting_str;
+ char* strport;
+ char* strsettings;
+
+ dbg(lvl_debug, "enter vehicle_wince_open, priv->source='%s'", priv->source);
+
+ if (priv->source ) {
+
+ if ( strcmp(priv->source, "list") == 0 ) {
+ vehicle_wince_available_ports();
+ return 0;
+ }
+
+ raw_setting_str = g_strdup( priv->source );
+ strport = strchr(raw_setting_str, ':' );
+ strsettings = strchr(raw_setting_str, ' ' );
+
+ if (raw_setting_str && strport&&strsettings ) {
+ strport++;
+ *strsettings = '\0';
+ strsettings++;
+
+ dbg(lvl_debug, "serial('%s', '%s')", strport, strsettings );
+ }
+ if (raw_setting_str)
+ g_free( raw_setting_str );
+ }
+ return 1;
}
static void
-vehicle_wince_close(struct vehicle_priv *priv)
-{
- dbg(lvl_debug,"enter");
+vehicle_wince_close(struct vehicle_priv *priv) {
+ dbg(lvl_debug,"enter");
}
static int
-vehicle_wince_parse(struct vehicle_priv *priv, char *buffer)
-{
- char *nmea_data_buf, *p, *item[32];
- double lat, lng;
- int i, j, bcsum;
- int len = strlen(buffer);
- unsigned char csum = 0;
- int valid=0;
- int ret = 0;
-
- dbg(lvl_info, "enter: buffer='%s'", buffer);
- for (;;) {
- if (len < 4) {
- dbg(lvl_error, "'%s' too short", buffer);
- return ret;
- }
- if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
- buffer[--len] = '\0';
- if (buffer[len - 1] == '\r')
- buffer[--len] = '\0';
- } else
- break;
- }
- if (buffer[0] != '$') {
- dbg(lvl_error, "no leading $ in '%s'", buffer);
- return ret;
- }
- if (buffer[len - 3] != '*') {
- dbg(lvl_error, "no *XX in '%s'", buffer);
- return ret;
- }
- for (i = 1; i < len - 3; i++) {
- csum ^= (unsigned char) (buffer[i]);
- }
- if (!sscanf(buffer + len - 2, "%x", &bcsum) && priv->checksum_ignore != 2) {
- dbg(lvl_error, "no checksum in '%s'", buffer);
- return ret;
- }
- if (bcsum != csum && priv->checksum_ignore == 0) {
- dbg(lvl_error, "wrong checksum in '%s'", buffer);
- return ret;
- }
-
- if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
- nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
- g_free(priv->nmea_data_buf);
- priv->nmea_data_buf=nmea_data_buf;
- } else {
- dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
- }
- i = 0;
- p = buffer;
- while (i < 31) {
- item[i++] = p;
- while (*p && *p != ',')
- p++;
- if (!*p)
- break;
- *p++ = '\0';
- }
-
- if (!strncmp(&buffer[3], "GGA", 3)) {
- /* 1 1111
- 0 1 2 3 4 5 6 7 8 9 0 1234
- $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
- UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
- HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
- */
- if (*item[2] && *item[3] && *item[4] && *item[5] && *item[6] > 0) {
- lat = g_ascii_strtod(item[2], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_strcasecmp(item[3],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[4], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_strcasecmp(item[5],"W"))
- priv->geo.lng=-priv->geo.lng;
-
- if (priv->valid == attr_position_valid_invalid)
- ret = 1;
- priv->valid = attr_position_valid_valid;
- vehicle_wince_restart_fix_timeout(priv);
-
- if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
- ret = 1;
- strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
- }
-
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else {
- if (priv->valid == attr_position_valid_valid)
- ret = 1;
- priv->valid=attr_position_valid_invalid;
- }
-
- if (*item[6])
- sscanf(item[6], "%d", &priv->status);
- if (*item[7])
- sscanf(item[7], "%d", &priv->sats_used);
- if (*item[8])
- sscanf(item[8], "%lf", &priv->hdop);
- if (*item[9])
- sscanf(item[9], "%lf", &priv->height);
-
- g_free(priv->nmea_data);
- priv->nmea_data=priv->nmea_data_buf;
- priv->nmea_data_buf=NULL;
- }
- if (!strncmp(&buffer[3], "VTG", 3)) {
- /* 0 1 2 34 5 6 7 8
- $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
- Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
- Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
- */
- if (item[1] && item[7])
- valid = 1;
- if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
- valid = 1;
- if (valid) {
- priv->direction = g_ascii_strtod( item[1], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- dbg(lvl_info,"direction %lf, speed %2.1lf", priv->direction, priv->speed);
- }
- }
- if (!strncmp(&buffer[3], "RMC", 3)) {
- /* 1 1
- 0 1 2 3 4 5 6 7 8 9 0 1
- $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
- Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
- magnetic variation[10],magnetic variation direction[11]
- */
- if (*item[2] == 'A')
- valid = 1;
- if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
- valid = 1;
- if (valid) {
- priv->direction = g_ascii_strtod( item[8], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- priv->speed *= 1.852;
- sscanf(item[9], "%02d%02d%02d",
- &priv->fixday,
- &priv->fixmonth,
- &priv->fixyear);
- priv->fixyear += 2000;
-
- lat = g_ascii_strtod(item[3], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_ascii_strcasecmp(item[4],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[5], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_ascii_strcasecmp(item[6],"W"))
- priv->geo.lng=-priv->geo.lng;
-
- if (priv->valid == attr_position_valid_invalid)
- ret = 1;
- priv->valid=attr_position_valid_valid;
- vehicle_wince_restart_fix_timeout(priv);
-
- if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
- ret = 1;
- strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
- }
-
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else {
- if (priv->valid == attr_position_valid_valid)
- ret = 1;
- priv->valid=attr_position_valid_invalid;
- }
- }
- if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
- /*
- 0 GSV Satellites in view
- 1 2 Number of sentences for full data
- 2 1 sentence 1 of 2
- 3 08 Number of satellites in view
-
- 4 01 Satellite PRN number
- 5 40 Elevation, degrees
- 6 083 Azimuth, degrees
- 7 46 SNR - higher is better
- for up to 4 satellites per sentence
- *75 the checksum data, always begins with *
- */
- if (item[3]) {
- sscanf(item[3], "%d", &priv->sats_visible);
- }
- j=4;
- while (j+4 <= i && priv->current_count < 24) {
- struct gps_sat *sat=&priv->next[priv->next_count++];
- sat->prn=atoi(item[j]);
- sat->elevation=atoi(item[j+1]);
- sat->azimuth=atoi(item[j+2]);
- sat->snr=atoi(item[j+3]);
- j+=4;
- }
- if (!strcmp(item[1], item[2])) {
- priv->sats_signal=0;
- for (i = 0 ; i < priv->next_count ; i++) {
- priv->current[i]=priv->next[i];
- if (priv->current[i].snr)
- priv->sats_signal++;
- }
- priv->current_count=priv->next_count;
- priv->next_count=0;
- }
- }
- if (!strncmp(&buffer[3], "ZDA", 3)) {
- /*
- 0 1 2 3 4 5 6
- $GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
- hhmmss HrMinSec(UTC)
- dd,mm,yyy Day,Month,Year
- xx local zone hours -13..13
- yy local zone minutes 0..59
- */
- if (item[1] && item[2] && item[3] && item[4]) {
- strncpy(priv->fixtime, item[1], strlen(priv->fixtime));
- priv->fixday = atoi(item[2]);
- priv->fixmonth = atoi(item[3]);
- priv->fixyear = atoi(item[4]);
- }
- }
- if (!strncmp(buffer, "$IISMD", 6)) {
- /*
- 0 1 2 3 4
- $IISMD,dir,press,height,temp*CC"
- dir Direction (0-359)
- press Pressure (hpa, i.e. 1032)
- height Barometric height above ground (meter)
- temp Temperature (Degree Celsius)
- */
- if (item[1]) {
- priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
- dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
- }
- }
- return ret;
+vehicle_wince_parse(struct vehicle_priv *priv, char *buffer) {
+ char *nmea_data_buf, *p, *item[32];
+ double lat, lng;
+ int i, j, bcsum;
+ int len = strlen(buffer);
+ unsigned char csum = 0;
+ int valid=0;
+ int ret = 0;
+
+ dbg(lvl_info, "enter: buffer='%s'", buffer);
+ for (;;) {
+ if (len < 4) {
+ dbg(lvl_error, "'%s' too short", buffer);
+ return ret;
+ }
+ if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
+ buffer[--len] = '\0';
+ if (buffer[len - 1] == '\r')
+ buffer[--len] = '\0';
+ } else
+ break;
+ }
+ if (buffer[0] != '$') {
+ dbg(lvl_error, "no leading $ in '%s'", buffer);
+ return ret;
+ }
+ if (buffer[len - 3] != '*') {
+ dbg(lvl_error, "no *XX in '%s'", buffer);
+ return ret;
+ }
+ for (i = 1; i < len - 3; i++) {
+ csum ^= (unsigned char) (buffer[i]);
+ }
+ if (!sscanf(buffer + len - 2, "%x", &bcsum) && priv->checksum_ignore != 2) {
+ dbg(lvl_error, "no checksum in '%s'", buffer);
+ return ret;
+ }
+ if (bcsum != csum && priv->checksum_ignore == 0) {
+ dbg(lvl_error, "wrong checksum in '%s'", buffer);
+ return ret;
+ }
+
+ if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
+ nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
+ g_free(priv->nmea_data_buf);
+ priv->nmea_data_buf=nmea_data_buf;
+ } else {
+ dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
+ }
+ i = 0;
+ p = buffer;
+ while (i < 31) {
+ item[i++] = p;
+ while (*p && *p != ',')
+ p++;
+ if (!*p)
+ break;
+ *p++ = '\0';
+ }
+
+ if (!strncmp(&buffer[3], "GGA", 3)) {
+ /* 1 1111
+ 0 1 2 3 4 5 6 7 8 9 0 1234
+ $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
+ UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
+ HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
+ */
+ if (*item[2] && *item[3] && *item[4] && *item[5] && *item[6] > 0) {
+ lat = g_ascii_strtod(item[2], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_strcasecmp(item[3],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[4], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_strcasecmp(item[5],"W"))
+ priv->geo.lng=-priv->geo.lng;
+
+ if (priv->valid == attr_position_valid_invalid)
+ ret = 1;
+ priv->valid = attr_position_valid_valid;
+ vehicle_wince_restart_fix_timeout(priv);
+
+ if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
+ ret = 1;
+ strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
+ }
+
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else {
+ if (priv->valid == attr_position_valid_valid)
+ ret = 1;
+ priv->valid=attr_position_valid_invalid;
+ }
+
+ if (*item[6])
+ sscanf(item[6], "%d", &priv->status);
+ if (*item[7])
+ sscanf(item[7], "%d", &priv->sats_used);
+ if (*item[8])
+ sscanf(item[8], "%lf", &priv->hdop);
+ if (*item[9])
+ sscanf(item[9], "%lf", &priv->height);
+
+ g_free(priv->nmea_data);
+ priv->nmea_data=priv->nmea_data_buf;
+ priv->nmea_data_buf=NULL;
+ }
+ if (!strncmp(&buffer[3], "VTG", 3)) {
+ /* 0 1 2 34 5 6 7 8
+ $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
+ Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
+ Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
+ */
+ if (item[1] && item[7])
+ valid = 1;
+ if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->direction = g_ascii_strtod( item[1], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ dbg(lvl_info,"direction %lf, speed %2.1lf", priv->direction, priv->speed);
+ }
+ }
+ if (!strncmp(&buffer[3], "RMC", 3)) {
+ /* 1 1
+ 0 1 2 3 4 5 6 7 8 9 0 1
+ $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
+ Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
+ magnetic variation[10],magnetic variation direction[11]
+ */
+ if (*item[2] == 'A')
+ valid = 1;
+ if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->direction = g_ascii_strtod( item[8], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ priv->speed *= 1.852;
+ sscanf(item[9], "%02d%02d%02d",
+ &priv->fixday,
+ &priv->fixmonth,
+ &priv->fixyear);
+ priv->fixyear += 2000;
+
+ lat = g_ascii_strtod(item[3], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_ascii_strcasecmp(item[4],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[5], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_ascii_strcasecmp(item[6],"W"))
+ priv->geo.lng=-priv->geo.lng;
+
+ if (priv->valid == attr_position_valid_invalid)
+ ret = 1;
+ priv->valid=attr_position_valid_valid;
+ vehicle_wince_restart_fix_timeout(priv);
+
+ if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
+ ret = 1;
+ strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
+ }
+
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else {
+ if (priv->valid == attr_position_valid_valid)
+ ret = 1;
+ priv->valid=attr_position_valid_invalid;
+ }
+ }
+ if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
+ /*
+ 0 GSV Satellites in view
+ 1 2 Number of sentences for full data
+ 2 1 sentence 1 of 2
+ 3 08 Number of satellites in view
+
+ 4 01 Satellite PRN number
+ 5 40 Elevation, degrees
+ 6 083 Azimuth, degrees
+ 7 46 SNR - higher is better
+ for up to 4 satellites per sentence
+ *75 the checksum data, always begins with *
+ */
+ if (item[3]) {
+ sscanf(item[3], "%d", &priv->sats_visible);
+ }
+ j=4;
+ while (j+4 <= i && priv->current_count < 24) {
+ struct gps_sat *sat=&priv->next[priv->next_count++];
+ sat->prn=atoi(item[j]);
+ sat->elevation=atoi(item[j+1]);
+ sat->azimuth=atoi(item[j+2]);
+ sat->snr=atoi(item[j+3]);
+ j+=4;
+ }
+ if (!strcmp(item[1], item[2])) {
+ priv->sats_signal=0;
+ for (i = 0 ; i < priv->next_count ; i++) {
+ priv->current[i]=priv->next[i];
+ if (priv->current[i].snr)
+ priv->sats_signal++;
+ }
+ priv->current_count=priv->next_count;
+ priv->next_count=0;
+ }
+ }
+ if (!strncmp(&buffer[3], "ZDA", 3)) {
+ /*
+ 0 1 2 3 4 5 6
+ $GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
+ hhmmss HrMinSec(UTC)
+ dd,mm,yyy Day,Month,Year
+ xx local zone hours -13..13
+ yy local zone minutes 0..59
+ */
+ if (item[1] && item[2] && item[3] && item[4]) {
+ strncpy(priv->fixtime, item[1], strlen(priv->fixtime));
+ priv->fixday = atoi(item[2]);
+ priv->fixmonth = atoi(item[3]);
+ priv->fixyear = atoi(item[4]);
+ }
+ }
+ if (!strncmp(buffer, "$IISMD", 6)) {
+ /*
+ 0 1 2 3 4
+ $IISMD,dir,press,height,temp*CC"
+ dir Direction (0-359)
+ press Pressure (hpa, i.e. 1032)
+ height Barometric height above ground (meter)
+ temp Temperature (Degree Celsius)
+ */
+ if (item[1]) {
+ priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
+ dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
+ }
+ }
+ return ret;
}
static void
-vehicle_wince_io(struct vehicle_priv *priv)
-{
- int size, rc = 0;
- char *str, *tok;
-
- dbg(lvl_debug, "vehicle_file_io : enter");
-
- size = read_win32(priv, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1);
-
- if (size <= 0) {
- switch (priv->on_eof) {
- case 0:
- vehicle_wince_close(priv);
- vehicle_wince_open(priv);
- break;
- case 1:
- vehicle_wince_disable_watch(priv);
- break;
- case 2:
- exit(0);
- break;
- }
- return;
- }
- priv->buffer_pos += size;
- priv->buffer[priv->buffer_pos] = '\0';
- dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
- priv->buffer_pos, priv->buffer);
- str = priv->buffer;
- while ((tok = strchr(str, '\n'))) {
- *tok++ = '\0';
- dbg(lvl_debug, "line='%s'", str);
- rc +=vehicle_wince_parse(priv, str);
- str = tok;
- if (priv->file_type == file_type_file && rc)
- break;
- }
-
- if (str != priv->buffer) {
- size = priv->buffer + priv->buffer_pos - str;
- memmove(priv->buffer, str, size + 1);
- priv->buffer_pos = size;
- dbg(lvl_info, "now pos=%d buffer='%s'",
- priv->buffer_pos, priv->buffer);
- } else if (priv->buffer_pos == buffer_size - 1) {
- dbg(lvl_error,
- "Overflow. Most likely wrong baud rate or no nmea protocol\n");
- priv->buffer_pos = 0;
- }
- if (rc)
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_wince_io(struct vehicle_priv *priv) {
+ int size, rc = 0;
+ char *str, *tok;
+
+ dbg(lvl_debug, "vehicle_file_io : enter");
+
+ size = read_win32(priv, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1);
+
+ if (size <= 0) {
+ switch (priv->on_eof) {
+ case 0:
+ vehicle_wince_close(priv);
+ vehicle_wince_open(priv);
+ break;
+ case 1:
+ vehicle_wince_disable_watch(priv);
+ break;
+ case 2:
+ exit(0);
+ break;
+ }
+ return;
+ }
+ priv->buffer_pos += size;
+ priv->buffer[priv->buffer_pos] = '\0';
+ dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
+ priv->buffer_pos, priv->buffer);
+ str = priv->buffer;
+ while ((tok = strchr(str, '\n'))) {
+ *tok++ = '\0';
+ dbg(lvl_debug, "line='%s'", str);
+ rc +=vehicle_wince_parse(priv, str);
+ str = tok;
+ if (priv->file_type == file_type_file && rc)
+ break;
+ }
+
+ if (str != priv->buffer) {
+ size = priv->buffer + priv->buffer_pos - str;
+ memmove(priv->buffer, str, size + 1);
+ priv->buffer_pos = size;
+ dbg(lvl_info, "now pos=%d buffer='%s'",
+ priv->buffer_pos, priv->buffer);
+ } else if (priv->buffer_pos == buffer_size - 1) {
+ dbg(lvl_error,
+ "Overflow. Most likely wrong baud rate or no nmea protocol\n");
+ priv->buffer_pos = 0;
+ }
+ if (rc)
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
static void
-vehicle_wince_enable_watch(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "enter");
- vehicle_wince_disable_watch(priv);
- priv->is_running = 1;
-
- InitializeCriticalSection(&priv->lock);
- priv->m_hGPSThread = CreateThread(NULL, 0, wince_reader_thread,
- priv, 0, &priv->m_dwGPSThread);
-
- if (!priv->m_hGPSThread) {
- priv->is_running = 0;
- // error creating thread
- MessageBox (NULL, TEXT ("Can not create GPS reader thread"), TEXT (""),
- MB_APPLMODAL|MB_OK);
- }
+vehicle_wince_enable_watch(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "enter");
+ vehicle_wince_disable_watch(priv);
+ priv->is_running = 1;
+
+ InitializeCriticalSection(&priv->lock);
+ priv->m_hGPSThread = CreateThread(NULL, 0, wince_reader_thread,
+ priv, 0, &priv->m_dwGPSThread);
+
+ if (!priv->m_hGPSThread) {
+ priv->is_running = 0;
+ // error creating thread
+ MessageBox (NULL, TEXT ("Can not create GPS reader thread"), TEXT (""),
+ MB_APPLMODAL|MB_OK);
+ }
}
static void
-vehicle_wince_disable_watch(struct vehicle_priv *priv)
-{
- int wait = 5000;
-
- dbg(lvl_debug, "enter");
-
- priv->is_running = 0;
- while (wait-- > 0 && priv->thread_up) {
- SwitchToThread();
- }
- if (priv->m_hGPSThread) {
- // Terminate reader, sorry
- TerminateThread(priv->m_hGPSThread, -1);
- }
+vehicle_wince_disable_watch(struct vehicle_priv *priv) {
+ int wait = 5000;
+
+ dbg(lvl_debug, "enter");
+
+ priv->is_running = 0;
+ while (wait-- > 0 && priv->thread_up) {
+ SwitchToThread();
+ }
+ if (priv->m_hGPSThread) {
+ // Terminate reader, sorry
+ TerminateThread(priv->m_hGPSThread, -1);
+ }
}
/**
* @brief Frees the wince_vehicle
- *
+ *
* @param priv vehicle_priv structure for the vehicle
*/
static void
-vehicle_wince_destroy(struct vehicle_priv *priv)
-{
- vehicle_wince_disable_watch(priv);
- vehicle_wince_close(priv);
- if (priv->BthSetMode)
- {
- (void)priv->BthSetMode(0);
- FreeLibrary(priv->hBthDll);
- }
- if (priv->source)
- g_free(priv->source);
- if (priv->buffer)
- g_free(priv->buffer);
- if (priv->read_buffer)
- g_free(priv->read_buffer);
- g_free(priv);
+vehicle_wince_destroy(struct vehicle_priv *priv) {
+ vehicle_wince_disable_watch(priv);
+ vehicle_wince_close(priv);
+ if (priv->BthSetMode) {
+ (void)priv->BthSetMode(0);
+ FreeLibrary(priv->hBthDll);
+ }
+ if (priv->source)
+ g_free(priv->source);
+ if (priv->buffer)
+ g_free(priv->buffer);
+ if (priv->read_buffer)
+ g_free(priv->read_buffer);
+ g_free(priv);
}
/**
@@ -828,124 +790,122 @@ vehicle_wince_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_wince_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->status;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_magnetic_direction:
- attr->u.num = priv->magnetic_direction;
- break;
- case attr_position_hdop:
- attr->u.numd = &priv->hdop;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats_visible;
- break;
- case attr_position_sats_signal:
- attr->u.num = priv->sats_signal;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_nmea:
- attr->u.str=priv->nmea_data;
- if (! attr->u.str)
- return 0;
- break;
- case attr_position_time_iso8601:
- if (!priv->fixyear || !priv->fixtime[0])
- return 0;
- sprintf(priv->fixiso8601, "%04d-%02d-%02dT%.2s:%.2s:%sZ",
- priv->fixyear, priv->fixmonth, priv->fixday,
- priv->fixtime, (priv->fixtime+2), (priv->fixtime+4));
- attr->u.str=priv->fixiso8601;
- break;
- case attr_position_sat_item:
- dbg(lvl_debug,"at here");
- priv->sat_item.id_lo++;
- if (priv->sat_item.id_lo > priv->current_count) {
- priv->sat_item.id_lo=0;
- return 0;
- }
- attr->u.item=&priv->sat_item;
- break;
- case attr_position_valid:
- attr->u.num=priv->valid;
- break;
- default:
- return 0;
- }
- if (type != attr_position_sat_item)
- priv->sat_item.id_lo=0;
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->status;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_magnetic_direction:
+ attr->u.num = priv->magnetic_direction;
+ break;
+ case attr_position_hdop:
+ attr->u.numd = &priv->hdop;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats_visible;
+ break;
+ case attr_position_sats_signal:
+ attr->u.num = priv->sats_signal;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_nmea:
+ attr->u.str=priv->nmea_data;
+ if (! attr->u.str)
+ return 0;
+ break;
+ case attr_position_time_iso8601:
+ if (!priv->fixyear || !priv->fixtime[0])
+ return 0;
+ sprintf(priv->fixiso8601, "%04d-%02d-%02dT%.2s:%.2s:%sZ",
+ priv->fixyear, priv->fixmonth, priv->fixday,
+ priv->fixtime, (priv->fixtime+2), (priv->fixtime+4));
+ attr->u.str=priv->fixiso8601;
+ break;
+ case attr_position_sat_item:
+ dbg(lvl_debug,"at here");
+ priv->sat_item.id_lo++;
+ if (priv->sat_item.id_lo > priv->current_count) {
+ priv->sat_item.id_lo=0;
+ return 0;
+ }
+ attr->u.item=&priv->sat_item;
+ break;
+ case attr_position_valid:
+ attr->u.num=priv->valid;
+ break;
+ default:
+ return 0;
+ }
+ if (type != attr_position_sat_item)
+ priv->sat_item.id_lo=0;
+ attr->type = type;
+ return 1;
}
static int
-vehicle_wince_sat_attr_get(void *priv_data, enum attr_type type, struct attr *attr)
-{
- struct vehicle_priv *priv=priv_data;
- struct gps_sat *sat;
-
- if (priv->sat_item.id_lo < 1)
- return 0;
- if (priv->sat_item.id_lo > priv->current_count)
- return 0;
- sat=&priv->current[priv->sat_item.id_lo-1];
- switch (type) {
- case attr_sat_prn:
- attr->u.num=sat->prn;
- break;
- case attr_sat_elevation:
- attr->u.num=sat->elevation;
- break;
- case attr_sat_azimuth:
- attr->u.num=sat->azimuth;
- break;
- case attr_sat_snr:
- attr->u.num=sat->snr;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+vehicle_wince_sat_attr_get(void *priv_data, enum attr_type type, struct attr *attr) {
+ struct vehicle_priv *priv=priv_data;
+ struct gps_sat *sat;
+
+ if (priv->sat_item.id_lo < 1)
+ return 0;
+ if (priv->sat_item.id_lo > priv->current_count)
+ return 0;
+ sat=&priv->current[priv->sat_item.id_lo-1];
+ switch (type) {
+ case attr_sat_prn:
+ attr->u.num=sat->prn;
+ break;
+ case attr_sat_elevation:
+ attr->u.num=sat->elevation;
+ break;
+ case attr_sat_azimuth:
+ attr->u.num=sat->azimuth;
+ break;
+ case attr_sat_snr:
+ attr->u.num=sat->snr;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static struct item_methods vehicle_wince_sat_methods = {
- NULL,
- NULL,
- NULL,
- vehicle_wince_sat_attr_get,
- NULL,
- NULL,
- NULL,
- NULL,
+ NULL,
+ NULL,
+ NULL,
+ vehicle_wince_sat_attr_get,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
};
struct vehicle_methods vehicle_wince_methods = {
- vehicle_wince_destroy,
- vehicle_wince_position_attr_get,
- NULL,
+ vehicle_wince_destroy,
+ vehicle_wince_position_attr_get,
+ NULL,
};
/**
* @brief Creates a new wince_vehicle
- *
+ *
* @param meth ?
* @param cbl ?
* @param attrs ?
@@ -954,89 +914,85 @@ struct vehicle_methods vehicle_wince_methods = {
*/
static struct vehicle_priv *
vehicle_wince_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source;
- struct attr *time;
- struct attr *on_eof;
- struct attr *baudrate;
- struct attr *checksum_ignore;
- struct attr *handle_bluetooth;
- char *cp;
-
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- ret = g_new0(struct vehicle_priv, 1);
- ret->fd = -1;
- ret->cbl = cbl;
-
- ret->file_type = file_type_device;
- cp = strchr(source->u.str,':');
- if (cp)
- {
- if ( strncmp(source->u.str, "file", 4) == 0 )
- ret->file_type = file_type_file;
- cp++;
- }
- else
- cp = source->u.str;
- ret->source = g_strdup(cp);
- ret->buffer = g_malloc(buffer_size);
- ret->time=1000;
- ret->baudrate=0; // do not change the rate if not configured
- ret->fixtime[0] = '\0';
- ret->ev_fix_timeout = NULL;
-
- time = attr_search(attrs, NULL, attr_time);
- if (time)
- ret->time=time->u.num;
- baudrate = attr_search(attrs, NULL, attr_baudrate);
- if (baudrate) {
- ret->baudrate = baudrate->u.num;
- }
- checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
- if (checksum_ignore)
- ret->checksum_ignore=checksum_ignore->u.num;
- ret->attrs = attrs;
- on_eof = attr_search(attrs, NULL, attr_on_eof);
- if (on_eof && !g_strcasecmp(on_eof->u.str, "stop"))
- ret->on_eof=1;
- if (on_eof && !g_strcasecmp(on_eof->u.str, "exit"))
- ret->on_eof=2;
- dbg(lvl_debug,"on_eof=%d", ret->on_eof);
- *meth = vehicle_wince_methods;
- ret->priv_cbl = callback_list_new();
- callback_list_add(ret->priv_cbl, callback_new_1(callback_cast(vehicle_wince_io), ret));
- ret->cb_fix_timeout=callback_new_1(callback_cast(vehicle_wince_fix_timeout_cb), ret);
- ret->sat_item.type=type_position_sat;
- ret->sat_item.id_hi=ret->sat_item.id_lo=0;
- ret->sat_item.priv_data=ret;
- ret->sat_item.meth=&vehicle_wince_sat_methods;
-
- ret->read_buffer = g_malloc(buffer_size);
-
- handle_bluetooth = attr_search(attrs, NULL, attr_bluetooth);
- if ( handle_bluetooth && handle_bluetooth->u.num == 1 )
- initBth(ret);
-
- if (vehicle_wince_open(ret)) {
- vehicle_wince_enable_watch(ret);
- return ret;
- }
- dbg(lvl_error, "Failed to open '%s'", ret->source);
- vehicle_wince_destroy(ret);
- return NULL;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source;
+ struct attr *time;
+ struct attr *on_eof;
+ struct attr *baudrate;
+ struct attr *checksum_ignore;
+ struct attr *handle_bluetooth;
+ char *cp;
+
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->fd = -1;
+ ret->cbl = cbl;
+
+ ret->file_type = file_type_device;
+ cp = strchr(source->u.str,':');
+ if (cp) {
+ if ( strncmp(source->u.str, "file", 4) == 0 )
+ ret->file_type = file_type_file;
+ cp++;
+ } else
+ cp = source->u.str;
+ ret->source = g_strdup(cp);
+ ret->buffer = g_malloc(buffer_size);
+ ret->time=1000;
+ ret->baudrate=0; // do not change the rate if not configured
+ ret->fixtime[0] = '\0';
+ ret->ev_fix_timeout = NULL;
+
+ time = attr_search(attrs, NULL, attr_time);
+ if (time)
+ ret->time=time->u.num;
+ baudrate = attr_search(attrs, NULL, attr_baudrate);
+ if (baudrate) {
+ ret->baudrate = baudrate->u.num;
+ }
+ checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
+ if (checksum_ignore)
+ ret->checksum_ignore=checksum_ignore->u.num;
+ ret->attrs = attrs;
+ on_eof = attr_search(attrs, NULL, attr_on_eof);
+ if (on_eof && !g_strcasecmp(on_eof->u.str, "stop"))
+ ret->on_eof=1;
+ if (on_eof && !g_strcasecmp(on_eof->u.str, "exit"))
+ ret->on_eof=2;
+ dbg(lvl_debug,"on_eof=%d", ret->on_eof);
+ *meth = vehicle_wince_methods;
+ ret->priv_cbl = callback_list_new();
+ callback_list_add(ret->priv_cbl, callback_new_1(callback_cast(vehicle_wince_io), ret));
+ ret->cb_fix_timeout=callback_new_1(callback_cast(vehicle_wince_fix_timeout_cb), ret);
+ ret->sat_item.type=type_position_sat;
+ ret->sat_item.id_hi=ret->sat_item.id_lo=0;
+ ret->sat_item.priv_data=ret;
+ ret->sat_item.meth=&vehicle_wince_sat_methods;
+
+ ret->read_buffer = g_malloc(buffer_size);
+
+ handle_bluetooth = attr_search(attrs, NULL, attr_bluetooth);
+ if ( handle_bluetooth && handle_bluetooth->u.num == 1 )
+ initBth(ret);
+
+ if (vehicle_wince_open(ret)) {
+ vehicle_wince_enable_watch(ret);
+ return ret;
+ }
+ dbg(lvl_error, "Failed to open '%s'", ret->source);
+ vehicle_wince_destroy(ret);
+ return NULL;
}
/**
* @brief Registers the vehicle_wince plugin
*/
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("wince", vehicle_wince_new);
- plugin_register_category_vehicle("file", vehicle_wince_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("wince", vehicle_wince_new);
+ plugin_register_category_vehicle("file", vehicle_wince_new);
}