Example #1
0
/**
 * @brief Called when a change in GPS fix status has been reported
 *
 * This function is called by {@code NavitLocationListener} upon receiving a new {@code android.location.GPS_FIX_CHANGE} broadcast.
 *
 * @param v The {@code struct_vehicle_priv} for the vehicle
 * @param fix_type The fix type (1 = valid, 0 = invalid)
 */
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);
		}
	}
}
Example #2
0
/**
 * @brief Called when a new GPS status has been reported
 *
 * This function is called by {@code NavitLocationListener} upon receiving a new {@code GpsStatus}.
 *
 * Note that {@code sats_used} should not be used to determine whether the vehicle's position is valid:
 * some devices report non-zero numbers even when they do not have a fix. Position validity should be
 * determined in {@code vehicle_android_fix_callback} (an invalid fix type means we have lost the fix)
 * and {@code vehicle_android_position_callback} (receiving a position means we have a fix).
 *
 * @param v The {@code struct_vehicle_priv} for the vehicle
 * @param sats_in_view The number of satellites in view
 * @param sats_used The number of satellites currently used to determine the position
 */
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);
	}
}
Example #3
0
int
bookmarks_rename_bookmark(struct bookmarks *this_, const char *oldName, const char* newName) {
	int result;

	bookmarks_item_rewind(this_);
	if (this_->current->children==NULL) {
		return 0;
	}
	while (this_->current->iter!=NULL) {
		struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
		if (!strcmp(data->label,oldName)) {
			g_free(data->label);
			data->label=g_strdup(newName);

			result=bookmarks_store_bookmarks_to_file(this_,0,0);

			callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
			bookmarks_clear_hash(this_);
			bookmarks_load_hash(this_);

			return result;
		}
		this_->current->iter=g_list_next(this_->current->iter);
	}

	return FALSE;
}
Example #4
0
int
bookmarks_delete_bookmark(struct bookmarks *this_, const char *label) {
	int result;

	bookmarks_item_rewind(this_);
	if (this_->current->children==NULL) {
		return 0;
	}
	while (this_->current->iter!=NULL) {
		struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
		if (!strcmp(data->label,label)) {
			this_->bookmarks_list=g_list_first(this_->bookmarks_list);
			this_->bookmarks_list=g_list_remove(this_->bookmarks_list,data);

			result=bookmarks_store_bookmarks_to_file(this_,0,0);

			callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
			bookmarks_clear_hash(this_);
			bookmarks_load_hash(this_);

			bookmarks_emit_dbus_signal(this_,&(data->c),label,FALSE);

			return result;
		}
		this_->current->iter=g_list_next(this_->current->iter);
	}

	return FALSE;
}
Example #5
0
int
bookmarks_paste_bookmark(struct bookmarks *this_) {
	int result;
	struct bookmark_item_priv* b_item;

	if (!this_->clipboard->label) {
	    return FALSE;
    }

	b_item=g_new0(struct bookmark_item_priv,1);
	b_item->c.x=this_->clipboard->c.x;
	b_item->c.y=this_->clipboard->c.y;
	b_item->label=g_strdup(this_->clipboard->label);
	b_item->type=this_->clipboard->type;
	b_item->item=this_->clipboard->item;
	b_item->parent=this_->current;
	b_item->children=this_->clipboard->children;

	g_hash_table_insert(this_->bookmarks_hash,b_item->label,b_item);
	this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);
	this_->current->children=g_list_append(this_->current->children,b_item);
	this_->current->children=g_list_first(this_->current->children);

	result=bookmarks_store_bookmarks_to_file(this_,0,0);

	callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
	bookmarks_clear_hash(this_);
	bookmarks_load_hash(this_);

	return result;
}
Example #6
0
/**
 * Record the given set of coordinates as a bookmark
 *
 * @param navit The navit instance
 * @param c The coordinate to store
 * @param description A label which allows the user to later identify this bookmark
 * @returns nothing
 */
int
bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *pc, const char *description)
{
	struct bookmark_item_priv *b_item=g_new0(struct bookmark_item_priv,1);
	int result;

	if (pc) {
		b_item->c.x=pc->x;
		b_item->c.y=pc->y;
		b_item->type=type_bookmark;
	} else {
		b_item->type=type_bookmark_folder;
	}
	b_item->label=g_strdup(description);
	b_item->parent=this_->current;
	b_item->children=NULL;

	this_->current->children=g_list_first(this_->current->children);
	this_->current->children=g_list_append(this_->current->children,b_item);
	this_->bookmarks_list=g_list_first(this_->bookmarks_list);
	this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);

	result=bookmarks_store_bookmarks_to_file(this_,0,0);

	callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
	bookmarks_clear_hash(this_);
	bookmarks_load_hash(this_);

    bookmarks_emit_dbus_signal(this_,&(b_item->c),description,TRUE);

	return result;
}
Example #7
0
static void
vehicle_wince_io(struct vehicle_priv *priv)
{
	int size, rc = 0;
	char *str, *tok;

	dbg(1, "vehicle_file_io : enter\n");

	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(1, "size=%d pos=%d buffer='%s'\n", size,
		priv->buffer_pos, priv->buffer);
	str = priv->buffer;
	while ((tok = strchr(str, '\n'))) {
		*tok++ = '\0';
		dbg(1, "line='%s'\n", 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(2, "now pos=%d buffer='%s'\n",
			priv->buffer_pos, priv->buffer);
	} else if (priv->buffer_pos == buffer_size - 1) {
		dbg(0,
			"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);
}
Example #8
0
/**
 * @brief Called when a new position has been reported
 *
 * This function is called by {@code NavitLocationListener} upon receiving a new {@code Location}.
 *
 * @param v The {@code struct_vehicle_priv} for the vehicle
 * @param location A {@code Location} object describing the new position
 */
static void
vehicle_android_position_callback(struct vehicle_priv *v, jobject location) {
	time_t tnow;
	struct tm *tm;
	dbg(lvl_debug,"enter\n");

	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\n",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);
}
Example #9
0
static void
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 (delta >= priv->delta*2) {
			dbg(lvl_warning, "GPS timeout triggered cb(%p) delta(%d)\n", priv->timeout_cb, delta);

			priv->delta = -1;

			callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
		}
	}
}
Example #10
0
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;
}
Example #11
0
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;
}
Example #12
0
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)\n",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\n",
				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);
}
Example #13
0
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;
    int rc = 0;

    dbg(1, "enter, *priv='%x', priv->source='%s'\n", priv, priv->source);

    if ( priv->no_data_count > 5 )
    {
        vehicle_file_close( priv );
        priv->no_data_count = 0;
        vehicle_file_open( priv );
        vehicle_file_enable_watch(priv);
    }

    //if ( priv->fd <= 0 )
    //{
    //    vehicle_file_open( priv );
    //}

    if ( current_index >= ( sizeof( buffer ) - chunk_size ) )
    {
        // discard
        current_index = 0;
        memset( buffer, 0 , sizeof( buffer ) );
    }

    int dwBytes = serial_io_read( priv->fd, &buffer[ current_index ], chunk_size );
    if ( dwBytes > 0 )
    {
        current_index += dwBytes;

        char* return_pos = 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 );
            return_buffer[ bytes_to_copy + 1 ] = '\0';
            return_buffer[ bytes_to_copy ] = '\0';

            // printf( "received %d : '%s' bytes to copy\n", bytes_to_copy, return_buffer );
            rc += vehicle_file_parse( priv, return_buffer );

            current_index -= bytes_to_copy;
            memmove( buffer, &buffer[ bytes_to_copy ] , sizeof( buffer ) - bytes_to_copy );
        }
        if (rc) {
            priv->no_data_count = 0;
            callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
            if (rc > 1)
                dbg(0, "Can not keep with gps data delay is %d seconds\n", rc - 1);

        }
    }
    else
    {
        priv->no_data_count++;
    }
    dbg(2, "leave, return '1', priv->no_data_count='%d'\n", priv->no_data_count);
    return 1;
}
Example #14
0
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;

	len = (priv->config_speed * priv->interval / 1000)/ 3.6;
	dbg(1, "###### Entering simulation loop\n");
	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(1, "current pos=0x%x,0x%x\n", pos.x, pos.y);
		dbg(1, "last pos=0x%x,0x%x\n", priv->last.x, priv->last.y);
		if (priv->last.x == pos.x && priv->last.y == pos.y) {
			dbg(1, "endless loop\n");
		}
		priv->last = pos;
		while (item && priv->config_speed) {
			if (!item_coord_get(item, &c, 1)) {
				item=map_rect_get_item(mr);
				continue;
			}
			dbg(1, "next pos=0x%x,0x%x\n", c.x, c.y);
			slen = transform_distance(projection_mg, &pos, &c);
			dbg(1, "len=%d slen=%d\n", 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(0,"destination reached\n");
				}
				dbg(1, "ci=0x%x,0x%x\n", ci.x, ci.y);
				transform_to_geo(projection_mg, &ci,
						 &priv->geo);
				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);
}