Exemplo n.º 1
0
void
popup(struct navit *nav, int button, struct point *p)
{
	void *popup,*men;
	char buffer[1024];
	struct coord_geo g;
	struct coord co;

	popup=gui_popup_new(navit_get_gui(nav));
	transform_reverse(navit_get_trans(nav), p, &co);
	men=popup_printf(popup, menu_type_submenu, _("Point 0x%x 0x%x"), co.x, co.y);
	popup_printf(men, menu_type_menu, _("Screen %d %d"), p->x, p->y);
	transform_to_geo(transform_get_projection(navit_get_trans(nav)), &co, &g);
	transform_geo_text(&g, buffer);	
	popup_printf(men, menu_type_menu, "%s", buffer);
	popup_printf(men, menu_type_menu, "%f %f", g.lat, g.lng);
	dbg(0,"%p %p\n", nav, &c);
	c.pro = transform_get_projection(navit_get_trans(nav));
	c.x = co.x;
	c.y = co.y;
	popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, &c), _("Set as position"));
	popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, &c), _("Set as destination"));
	popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, &c), _("Add as bookmark"));
	popup_display(nav, popup, p);
#ifdef _WIN32
	// menu needs first to be constructed before doing the menu popup
	// therefore this work around for win32
	// needs to be fixed
	popup=gui_popup_new(navit_get_gui(nav));
#endif
}
Exemplo n.º 2
0
static int
vehicle_add_log(struct vehicle *this_, struct log *log,
		struct attr **attrs)
{
	struct attr *type;
	struct callback *cb;
	type = attr_search(attrs, NULL, attr_type);
	if (!type)
		return 1;
	if (!strcmp(type->u.str, "nmea")) {
		cb=callback_new_2(callback_cast(vehicle_log_nmea), this_, log);
	} else if (!strcmp(type->u.str, "gpx")) {
		char *header =
		    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpx version=\"1.0\" creator=\"Navit http://navit.sourceforge.net\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/0\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n<trk>\n<trkseg>\n";
		char *trailer = "</trkseg>\n</trk>\n</gpx>\n";
		log_set_header(log, header, strlen(header));
		log_set_trailer(log, trailer, strlen(trailer));
		cb=callback_new_2(callback_cast(vehicle_log_gpx), this_, log);
	} else if (!strcmp(type->u.str, "textfile")) {
		char *header = "type=track\n";
		log_set_header(log, header, strlen(header));
		cb=callback_new_2(callback_cast(vehicle_log_textfile), this_, log);
	} else
		return 1;
	callback_list_add(this_->cbl, cb);
	return 0;
}
Exemplo n.º 3
0
static void
popup_show_item(struct navit *nav, void *popup, struct displayitem *di)
{
	struct map_rect *mr;
	void *menu, *menu_map, *menu_item, *menu_dist;
	char *label;
	struct item *item,*diitem;
	int count;

	label=graphics_displayitem_get_label(di);
	diitem=graphics_displayitem_get_item(di);
	count=graphics_displayitem_get_coord_count(di);

	dbg_assert(diitem);

	if (label) 
		menu=popup_printf(popup, menu_type_submenu, "%s '%s' (%d coords)", item_to_name(diitem->type), label, count);
	else
		menu=popup_printf(popup, menu_type_submenu, "%s (%d coords)", item_to_name(diitem->type), count);
	menu_item=popup_printf(menu, menu_type_submenu, "Item");
	popup_printf(menu_item, menu_type_menu, "type: 0x%x", diitem->type);
	popup_printf(menu_item, menu_type_menu, "id: 0x%x 0x%x", diitem->id_hi, diitem->id_lo);
	if (diitem->map) {
		struct attr type,data;
		if (!map_get_attr(diitem->map, attr_type, &type, NULL))
			type.u.str="";
		if (!map_get_attr(diitem->map, attr_data, &data, NULL))
			data.u.str="";
		popup_printf(menu_item, menu_type_menu, "map: %s:%s", type.u.str, data.u.str);
	}
	if (diitem->map) {
		mr=map_rect_new(diitem->map,NULL);
		item=map_rect_get_item_byid(mr, diitem->id_hi, diitem->id_lo);
		dbg(1,"item=%p\n", item);
		if (item) {
			popup_show_attrs(item->map, menu_item, item);
			popup_printf_cb(menu_item, menu_type_menu, callback_new_1(callback_cast(popup_item_dump), diitem), "Dump");
			if (item->type < type_line) {
				struct coord co;
				struct pcoord *c;
				if (item_coord_get(item, &co, 1)) {
					c=g_new(struct pcoord, 1);
					c->pro = transform_get_projection(navit_get_trans(nav));
					c->x = co.x;
					c->y = co.y;
					popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, c), _("Set as position"));
					popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, c), _("Set as destination"));
					popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, c), _("Add as bookmark"));
				}
			}
		}
Exemplo n.º 4
0
static struct vehicle_priv *
vehicle_demo_new(struct vehicle_methods
		 *meth, struct callback_list
		 *cbl, struct attr **attrs)
{
	struct vehicle_priv *ret;
	struct attr *interval,*speed,*position_coord_geo;

	dbg(1, "enter\n");
	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(0,"position_set %f %f\n", ret->geo.lat, ret->geo.lng);
	}
	*meth = vehicle_demo_methods;
	ret->timer_callback=callback_new_1(callback_cast(vehicle_demo_timer), ret);
	ret->timer=event_add_timeout(ret->interval, 1, ret->timer_callback);
	return ret;
}
Exemplo n.º 5
0
/** @fn static int vehicle_file_open(struct vehicle_priv *priv)
*****************************************************************************
* @b Description: open dialogue with the GPS
*****************************************************************************
* @param      priv : pointer on the private data of the plugin
*****************************************************************************
* @return     1 if ok
*             0 if error
*****************************************************************************
**/
static int
vehicle_file_open(struct vehicle_priv *priv)
{
#ifdef _WIN32
    dbg(1, "enter, priv->source='%s'\n", priv->source);

    if ( priv->source )
    {
        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 );

        // Add the callback
        dbg(2, "Add the callback ...\n", priv->source);
   		priv->timeout_callback=callback_new_1(callback_cast(vehicle_win32_serial_track), priv);
    }
#else
	char *name;
	struct stat st;
	struct termios tio;

	name = priv->source + 5;
	if (!strncmp(priv->source, "file:", 5)) {
		priv->fd = open(name, O_RDONLY | O_NDELAY);
		if (priv->fd < 0)
			return 0;
		stat(name, &st);
		if (S_ISREG(st.st_mode)) {
			priv->file_type = file_type_file;
		} 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 {
		priv->file = popen(name, "r");
		if (!priv->file)
			return 0;
		priv->fd = fileno(priv->file);
		priv->file_type = file_type_pipe;
	}
#endif
    return(priv->fd != -1);
}
Exemplo n.º 6
0
void
navit_window_roadbook_new(struct navit *this_)
{
	this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
	navigation_register_callback(this_->navigation, navigation_mode_long, this_->roadbook_callback);
	this_->roadbook_window=gui_datawindow_new(this_->gui, "Roadbook", NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
}
Exemplo n.º 7
0
/**
 * @brief Create android_vehicle
 * 
 * @param meth
 * @param cbl
 * @param attrs
 * @returns vehicle_priv
 */
static struct vehicle_priv *
vehicle_android_new_android(struct vehicle_methods *meth,
	       		struct callback_list *cbl,
		       	struct attr **attrs)
{
	struct vehicle_priv *ret;

	dbg(lvl_debug, "enter\n");
	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\n");
	return ret;
}
Exemplo n.º 8
0
Arquivo: log.c Projeto: Jalakas/navit
struct log *
log_new(struct attr * parent,struct attr **attrs)
{
	struct log *ret=g_new0(struct log, 1);
	struct attr *data,*overwrite,*lazy,*mkdir,*flush_size,*flush_time;
	struct file_wordexp *wexp;
	char *filename, **wexp_data;

	dbg(1,"enter\n");
	ret->func=&log_func;
	navit_object_ref((struct navit_object *)ret);
	data=attr_search(attrs, NULL, attr_data);
	if (! data)
		return NULL;
	filename=data->u.str;
	wexp=file_wordexp_new(filename);
	if (wexp && file_wordexp_get_count(wexp) > 0) {
		wexp_data=file_wordexp_get_array(wexp);
		filename=wexp_data[0];
	}
	if (filename)
		ret->filename=g_strdup(filename);
	if (wexp)
		file_wordexp_destroy(wexp);
	overwrite=attr_search(attrs, NULL, attr_overwrite);
	if (overwrite)
		ret->overwrite=overwrite->u.num;
	lazy=attr_search(attrs, NULL, attr_lazy);
	if (lazy)
		ret->lazy=lazy->u.num;
	mkdir=attr_search(attrs, NULL, attr_mkdir);
	if (mkdir)
		ret->mkdir=mkdir->u.num;
	flush_size=attr_search(attrs, NULL, attr_flush_size);
	if (flush_size)
		ret->flush_size=flush_size->u.num;
	flush_time=attr_search(attrs, NULL, attr_flush_time);
	if (flush_time)
		ret->flush_time=flush_time->u.num;
	if (ret->flush_time) {
		dbg(1,"interval %d\n", ret->flush_time*1000);
		ret->timer_callback=callback_new_1(callback_cast(log_timer), ret);
		ret->timer=event_add_timeout(ret->flush_time*1000, 1, ret->timer_callback);
	}
	expand_filenames(ret);
	if (ret->lazy)
		log_set_last_flush(ret);
	else
		log_open(ret);
	ret->attrs=attr_list_dup(attrs);
	return ret;
}
Exemplo n.º 9
0
static void
popup_show_item(struct navit *nav, void *popup, struct displayitem *di)
{
	struct map_rect *mr;
	void *menu, *menu_map, *menu_item;
	char *label;
	struct item *item;

	label=graphics_displayitem_get_label(di);
	item=graphics_displayitem_get_item(di);

	if (label) 
		menu=popup_printf(popup, menu_type_submenu, "%s '%s'", item_to_name(item->type), label);
	else
		menu=popup_printf(popup, menu_type_submenu, "%s", item_to_name(item->type));
	menu_item=popup_printf(menu, menu_type_submenu, "Item");
	popup_printf(menu_item, menu_type_menu, "type: 0x%x", item->type);
	popup_printf(menu_item, menu_type_menu, "id: 0x%x 0x%x", item->id_hi, item->id_lo);
	if (item->map) {
		mr=map_rect_new(item->map,NULL);
		item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
		dbg(1,"item=%p\n", item);
		if (item) {
			popup_show_attrs(item->map, menu_item, item);
			if (item->type < type_line) {
				struct coord co;
				struct pcoord *c;
				if (item_coord_get(item, &co, 1)) {
					c=g_new(struct pcoord, 1);
					c->pro = transform_get_projection(navit_get_trans(nav));
					c->x = co.x;
					c->y = co.y;
					popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, c), _("Set as position"));
					popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, c), _("Set as destination"));
					popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, c), _("Add as bookmark"));
				}
			}
		}
Exemplo n.º 10
0
static void
osd_rocket_init(struct navit *nav)
{
    struct rocket *rocket=g_new0(struct rocket, 1);
    struct attr attr;
    rocket->navit=nav;
    rocket->callback=callback_new_1(callback_cast(pedestrian_rocket_idle), rocket);
    if (navit_get_attr(nav, attr_layout, &attr, NULL))
        rocket->layout=attr.u.layout;
    if (navit_get_attr(nav, attr_callback_list, &attr, NULL)) {
        dbg(0,"ok\n");
        command_add_table(attr.u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), rocket);
    }
}
Exemplo n.º 11
0
void
navit_init(struct navit *this_)
{
	struct menu *men;
	struct mapset *ms;

	if (this_->mapsets) {
		ms=this_->mapsets->data;
		if (this_->route)
			route_set_mapset(this_->route, ms);
		if (this_->tracking)
			tracking_set_mapset(this_->tracking, ms);
		if (this_->navigation)
			navigation_set_mapset(this_->navigation, ms);
		if (this_->menubar) {
			men=menu_add(this_->menubar, "Map", menu_type_submenu, NULL, NULL, NULL);
			if (men) {
				navit_add_menu_layout(this_, men);
				navit_add_menu_projection(this_, men);
				navit_add_menu_vehicle(this_, men);
				navit_add_menu_maps(this_, ms, men);
			}
			men=menu_add(this_->menubar, "Route", menu_type_submenu, NULL, NULL, NULL);
			if (men) {
				navit_add_menu_former_destinations(this_, men, this_->route);
				navit_add_menu_bookmarks(this_, men);
			}
		} else
			navit_add_menu_former_destinations(this_, NULL, this_->route);
	}
	if (this_->navigation && this_->speech) {
		this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
		navigation_register_callback(this_->navigation, navigation_mode_speech, this_->nav_speech_cb);
#if 0
#endif
	}
	if (this_->menubar) {
		men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL, NULL, NULL);
		if (men) {
			navit_add_menu_windows_items(this_, men);
		}
	}
	global_navit=this_;
#if 0
	navit_window_roadbook_new(this_);
	navit_window_items_new(this_);
#endif
	navit_debug(this_);
}
Exemplo n.º 12
0
static struct script *
script_new(struct attr *parent, struct attr **attrs)
{
    struct script *scr=g_new0(struct script, 1);
    scr->func=&script_func;
    navit_object_ref((struct navit_object *)scr);
    scr->attrs=attr_list_dup(attrs);
    attrs=scr->attrs;
    scr->cb=callback_new_1(callback_cast(script_run), scr);
    scr->parent=*parent;
    while (attrs && *attrs)
        script_set_attr_int(scr, *attrs++);
    dbg(lvl_debug,"return %p\n",scr);
    return scr;
}
Exemplo n.º 13
0
struct navit_vehicle *
navit_add_vehicle(struct navit *this_, struct vehicle *v, const char *name, struct color *c, int update, int follow)
{
	struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
	nv->vehicle=v;
	nv->name=g_strdup(name);
	nv->update_curr=nv->update=update;
	nv->follow_curr=nv->follow=follow;
	nv->cursor=cursor_new(this_->gra, v, c, this_->trans);
	nv->update_cb=callback_new_1(callback_cast(navit_cursor_update), this_);
	cursor_add_callback(nv->cursor, nv->update_cb);

	this_->vehicles=g_list_append(this_->vehicles, nv);
	return nv;
}
Exemplo n.º 14
0
/**
 * @brief Create android_vehicle
 * 
 * @param meth
 * @param cbl
 * @param attrs
 * @returns vehicle_priv
 */
static struct vehicle_priv *
vehicle_android_new_android(struct vehicle_methods *meth,
	       		struct callback_list *cbl,
		       	struct attr **attrs)
{
	struct vehicle_priv *ret;

	dbg(0, "enter\n");
	ret = g_new0(struct vehicle_priv, 1);
	ret->cbl = cbl;
	ret->cb=callback_new_1(callback_cast(vehicle_android_callback), ret);
	*meth = vehicle_android_methods;
	vehicle_android_init(ret);
	dbg(0, "return\n");
	return ret;
}
Exemplo n.º 15
0
static struct vehicle_priv *
vehicle_demo_new(struct vehicle_methods
		 *meth, struct callback_list
		 *cbl, struct attr **attrs)
{
	struct vehicle_priv *ret;

	dbg(1, "enter\n");
	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);
	*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;
}
Exemplo n.º 16
0
static void event_sdl_main_loop_run(void) {
#ifdef USE_WEBOS_ACCELEROMETER
	struct callback* accel_cb = NULL;
	struct event_timeout* accel_to = NULL;
	if (PDL_GetPDKVersion() > 100) {
		accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
		accel_to = event_add_timeout(200, 1, accel_cb);
	}
#endif
	graphics_sdl_idle(NULL);

	event_sdl_watch_stopthread();

#ifdef USE_WEBOS_ACCELEROMETER
	SDL_JoystickClose(accelerometer);
	if (PDL_GetPDKVersion() > 100) {
		event_remove_timeout(accel_to);
		callback_destroy(accel_cb);
	}
#endif
}
Exemplo n.º 17
0
struct graphics_opengl_window_system *
graphics_opengl_x11_new(void *displayname, int w, int h, int depth, struct graphics_opengl_window_system_methods **methods)
{
	struct graphics_opengl_window_system *ret=g_new0(struct graphics_opengl_window_system, 1);
	XSetWindowAttributes attributes;
	unsigned long valuemask;

	ret->cb=callback_new_1(callback_cast(graphics_opengl_x11_watch), ret);
	if (!event_request_system("glib", "graphics_opengl_x11_new"))
		goto error;
	*methods=&graphics_opengl_x11_methods;
	ret->display=XOpenDisplay(displayname);
	if (!ret->display) {
		dbg(lvl_error,"failed to open display\n");
		goto error;
	}
	ret->watch=event_add_watch(ConnectionNumber(ret->display), event_watch_cond_read, ret->cb);
	ret->screen=XDefaultScreen(ret->display);
	ret->root_window=RootWindow(ret->display, ret->screen);
	if (!XMatchVisualInfo(ret->display, ret->screen, depth, TrueColor, &ret->visual)) {
		dbg(lvl_error,"failed to find visual\n");
		goto error;
	}
	ret->colormap=XCreateColormap(ret->display, ret->root_window, ret->visual.visual, AllocNone);
	valuemask = /* CWBackPixel | */ CWBorderPixel | CWEventMask | CWColormap ; // | CWBackingStore;
	attributes.colormap = ret->colormap;
	attributes.border_pixel = 0;
	attributes.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonMotionMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask;
	attributes.backing_store = Always;
	ret->window=XCreateWindow(ret->display, RootWindow(ret->display, ret->screen), 0, 0, w, h, 0, ret->visual.depth, InputOutput, ret->visual.visual, valuemask, &attributes);
	XMapWindow(ret->display, ret->window);
	XFlush(ret->display);
	graphics_opengl_x11_watch(ret);
	return ret;
error:
	graphics_opengl_x11_destroy(ret);
	return NULL;	
}
Exemplo n.º 18
0
static struct vehicle_priv *
vehicle_webos_new(struct vehicle_methods
		*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->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++;
	}

	vehicle_webos_open(priv);

	return priv;
}
Exemplo n.º 19
0
/** @fn static struct vehicle_priv * vehicle_file_new_file(
*                                       struct vehicle_methods *meth,
*                                       struct callback_list   *cbl,
*                                       struct attr            **attrs)
*****************************************************************************
* @b Description: Function called to initialize the plugin
*****************************************************************************
* @param      meth  : ?
* @param      cbl   : ?
* @param      attrs : ?
*****************************************************************************
* @return     pointer on the private data of the plugin
*****************************************************************************
* @remarks private data is allocated by this function (g_new0)
*****************************************************************************
**/
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;

	dbg(1, "enter\n");

	source = attr_search(attrs, NULL, attr_source);
	if(source == NULL){
		 dbg(0,"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;
	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;
#endif
#ifdef B57600
		case 57600:
			ret->baudrate=B57600;
			break;
#endif
#ifdef B115200
		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 && !strcasecmp(on_eof->u.str, "stop"))
		ret->on_eof=1;
	if (on_eof && !strcasecmp(on_eof->u.str, "exit"))
		ret->on_eof=2;
	dbg(0,"on_eof=%d\n", 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->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;
#endif

	dbg(1, "vehicle_file_new_file:open\n");
	if (!vehicle_file_open(ret)) {
        dbg(0, "Failed to open '%s'\n", ret->source);
	}

	vehicle_file_enable_watch(ret);
	// vehicle_file_destroy(ret);
	// return NULL;
	dbg(1, "leave\n");
	return ret;
}
Exemplo n.º 20
0
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(1, "enter\n");
	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

	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 && !strcasecmp(on_eof->u.str, "stop"))
		ret->on_eof=1;
	if (on_eof && !strcasecmp(on_eof->u.str, "exit"))
		ret->on_eof=2;
	dbg(0,"on_eof=%d\n", 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->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(0, "Failed to open '%s'\n", ret->source);
	vehicle_wince_destroy(ret);
	return NULL;
}
Exemplo n.º 21
0
/** @fn static int vehicle_file_open(struct vehicle_priv *priv)
*****************************************************************************
* @b Description: open dialogue with the GPS
*****************************************************************************
* @param      priv : pointer on the private data of the plugin
*****************************************************************************
* @return     1 if ok
*             0 if error
*****************************************************************************
**/
static int
vehicle_file_open(struct vehicle_priv *priv)
{
	char *name;
#ifndef _WIN32
	struct termios tio;
#else
	#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;
		}
#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;
#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(0,"port number missing in %s\n",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(0,"failed to parse %s\n",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(0,"failed to connect to %s:%s\n",s,p);
				g_free(s);
				return 0;
			}
		}
		priv->file_type = file_type_socket;
#endif //HAVE_SOCKET
	} 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(2, "Add the callback ...\n", priv->source);
			priv->timeout_callback=callback_new_1(callback_cast(vehicle_win32_serial_track), priv);
#else
		//TODO - add linux serial
#endif //!_WIN32
    }
    return(priv->fd != -1);
}