-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <math.h>
#include <glib.h>
+#include "debug.h"
#include "coord.h"
#include "transform.h"
#include "projection.h"
struct cursor *
cursor_new(struct graphics *gra, struct vehicle *v, struct color *c, struct transformation *t)
{
- printf("cursor_new v=%p\n", v);
+ dbg(2,"enter gra=%p v=%p c=%p t=%p\n", gra, v, c, t);
struct cursor *this=g_new(struct cursor,1);
this->gra=gra;
this->trans=t;
graphics_gc_set_foreground(this->cursor_gc, c);
graphics_gc_set_linewidth(this->cursor_gc, 2);
this->vehicle_callback=vehicle_callback_register(v, cursor_update, this);
+ dbg(2,"ret=%p\n", this);
return this;
}
this->update_callback.data=data;
}
-
#include "navit.h"
#include "callback.h"
#include "gui.h"
+#include "item.h"
#include "map.h"
#include "mapset.h"
#include "main.h"
struct datawindow *roadbook_window;
};
-struct gui *
-main_loop_gui;
+struct gui *main_loop_gui;
void
this_->roadbook_window=gui_datawindow_new(this_->gui, "Roadbook", NULL, NULL);
}
+static void
+navit_window_items_new(struct navit *this_)
+{
+ struct datawindow *win;
+ struct map_selection sel;
+ struct coord c,*center;
+ struct mapset_handle *h;
+ struct map *m;
+ struct map_rect *mr;
+ struct item *item;
+ struct attr attr;
+ GHashTable *hash;
+ int idist,dist=100000;
+ enum item_type type1,type2,type3;
+ struct param_list param[4];
+ char distbuf[32];
+
+ param[0].name="Distance";
+ param[1].name="Direction";
+ param[2].name="Type";
+ param[3].name="Name";
+ sel.next=NULL;
+ sel.order[layer_town]=18;
+ sel.order[layer_street]=18;
+ sel.order[layer_poly]=18;
+ center=transform_center(this_->trans);
+ sel.rect.lu.x=center->x-dist;
+ sel.rect.lu.y=center->y+dist;
+ sel.rect.rl.x=center->x+dist;
+ sel.rect.rl.y=center->y-dist;
+ hash=g_hash_table_new(g_int_hash, g_int_equal);
+ type1=type_bookmark;
+ g_hash_table_insert(hash, &type1, 1);
+ type2=type_poi_camping;
+ g_hash_table_insert(hash, &type2, 1);
+ type3=type_roadbook;
+ g_hash_table_insert(hash, &type3, 1);
+ dbg(2,"0x%x,0x%x - 0x%x,0x%x\n", sel.rect.lu.x, sel.rect.lu.y, sel.rect.rl.x, sel.rect.rl.y);
+ win=gui_datawindow_new(this_->gui, "Itemlist", NULL, NULL);
+ h=mapset_open(navit_get_mapset(this_));
+ while ((m=mapset_next(h, 1))) {
+ dbg(2,"m=%p %s\n", m, map_get_filename(m));
+ mr=map_rect_new(m, &sel);
+ dbg(2,"mr=%p\n", mr);
+ while ((item=map_rect_get_item(mr))) {
+ if (item_coord_get(item, &c, 1)) {
+ if (coord_rect_contains(&sel.rect, &c) && g_hash_table_lookup(hash, &item->type)) {
+ if (! item_attr_get(item, attr_label, &attr))
+ attr.u.str=NULL;
+ idist=transform_distance(center, &c);
+ param[0].value=distbuf;
+ param[1].value="";
+ param[2].value=item_to_name(item->type);
+ sprintf(distbuf,"%d", idist/1000);
+ param[3].value=attr.u.str;
+ datawindow_add(win, param, 4);
+ /* printf("gefunden %s %s %d\n",item_to_name(item->type), attr.u.str, idist/1000); */
+ }
+ if (item->type >= type_line)
+ while (item_coord_get(item, &c, 1));
+ }
+ }
+ map_rect_destroy(mr);
+ }
+ mapset_close(h);
+ g_hash_table_destroy(hash);
+}
+
void
navit_init(struct navit *this_)
global_navit=this_;
#if 0
navit_window_roadbook_new(this_);
+ navit_window_items_new(this_);
#endif
navit_debug(this_);
}
int dir=cursor_get_dir(cursor);
int speed=cursor_get_speed(cursor);
+
if (this_->pid && speed > 2)
kill(this_->pid, SIGWINCH);
}
void
-navit_vehicle_add(struct navit *this_, struct vehicle *v, struct color *c, int update, int follow)
+navit_vehicle_add(struct navit *this_, struct vehicle *v, struct color *c, int update, int follow, int active)
{
this_->vehicle=v;
this_->update_curr=this_->update=update;
void navit_set_center_screen(struct navit *this_, struct point *p);
void navit_toggle_cursor(struct navit *this_);
void navit_set_position(struct navit *this_, struct coord *c);
-void navit_vehicle_add(struct navit *this_, struct vehicle *v, struct color *c, int update, int follow);
+void navit_vehicle_add(struct navit *this_, struct vehicle *v, struct color *c, int update, int follow, int active);
void navit_tracking_add(struct navit *this_, struct tracking *tracking);
void navit_route_add(struct navit *this_, struct route *route);
void navit_navigation_add(struct navit *this_, struct navigation *navigation);
#include <fcntl.h>
#include <math.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include <glib.h>
#ifdef HAVE_LIBGPS
#include <gps.h>
#define BUFFER_SIZE 256
char buffer[BUFFER_SIZE];
int buffer_pos;
+ struct vehicle *child;
GList *callbacks;
+
+ int magic;
+ int is_udp;
+ int interval;
+ struct sockaddr_in rem;
};
struct vehicle *vehicle_last;
close(this->fd);
}
+struct packet {
+ int magic __attribute__ ((packed));
+ unsigned char type;
+ union {
+ struct {
+ int x __attribute__ ((packed));
+ int y __attribute__ ((packed));
+ unsigned char speed;
+ unsigned char dir;
+ } pos;
+ } u;
+} __attribute__ ((packed)) ;
+
+static void
+vehicle_udp_recv(struct vehicle *this)
+{
+ struct packet pkt;
+ int size;
+
+ dbg(2,"enter this=%p",this);
+ size=recv(this->fd, &pkt, sizeof(pkt), 0);
+ if (pkt.magic == this->magic) {
+ dbg(3,"magic 0x%x size=%d\n", pkt.magic, size);
+ this->current_pos.x=pkt.u.pos.x;
+ this->current_pos.y=pkt.u.pos.y;
+ this->speed=pkt.u.pos.speed;
+ this->dir=pkt.u.pos.dir*2;
+ vehicle_call_callbacks(this);
+ }
+}
+
+static void
+vehicle_udp_update(struct vehicle *child, void *data)
+{
+ struct vehicle *this=(struct vehicle *)data;
+ struct coord *pos=&child->current_pos;
+ struct packet pkt;
+ int speed=child->speed;
+ int dir=child->dir/2;
+ if (speed > 255)
+ speed=255;
+ pkt.magic=this->magic;
+ pkt.type=1;
+ pkt.u.pos.x=pos->x;
+ pkt.u.pos.y=pos->y;
+ pkt.u.pos.speed=speed;
+ pkt.u.pos.dir=dir;
+ sendto(this->fd, &pkt, sizeof(pkt), 0, (struct sockaddr *)&this->rem, sizeof(this->rem));
+ this->current_pos=child->current_pos;
+ this->speed=child->speed;
+ this->dir=child->dir;
+ vehicle_call_callbacks(this);
+}
+
+static int
+vehicle_udp_query(void *data)
+{
+ struct vehicle *this=(struct vehicle *)data;
+ struct packet pkt;
+ dbg(2,"enter this=%p\n", this);
+ pkt.magic=this->magic;
+ pkt.type=2;
+ sendto(this->fd, &pkt, 5, 0, (struct sockaddr *)&this->rem, sizeof(this->rem));
+ dbg(2,"ret=TRUE\n");
+ return TRUE;
+}
+
+static int
+vehicle_udp_open(struct vehicle *this)
+{
+ char *host,*child,*url,*colon;
+ int port;
+ url=g_strdup(this->url);
+ colon=index(url+6,':');
+ struct sockaddr_in lcl;
+
+ if (! colon || sscanf(colon+1,"%d/%i/%d", &port, &this->magic, &this->interval) != 3) {
+ g_warning("Wrong syntax in %s\n", this->url);
+ return 0;
+ }
+ host=url+6;
+ *colon='\0';
+ this->fd=socket(PF_INET, SOCK_DGRAM, 0);
+ this->is_udp=1;
+ memset(&lcl, 0, sizeof(lcl));
+ lcl.sin_family = AF_INET;
+
+ this->rem.sin_family = AF_INET;
+ inet_aton(host, &this->rem.sin_addr);
+ this->rem.sin_port=htons(port);
+
+ bind(this->fd, (struct sockaddr *)&lcl, sizeof(lcl));
+ child=index(colon+1,' ');
+ if (child) {
+ child++;
+ if (!this->child) {
+ dbg(3,"child=%s\n", child);
+ this->child=vehicle_new(child);
+ vehicle_callback_register(this->child, vehicle_udp_update, this);
+ }
+ } else {
+ vehicle_udp_query(this);
+ g_timeout_add(this->interval*1000, vehicle_udp_query, this);
+ }
+ g_free(url);
+ return 0;
+}
+
static int
vehicle_open(struct vehicle *this)
{
g_warning("No support for gpsd compiled in\n");
return 0;
#endif
+ } else if (! strncmp(this->url,"udp://",6)) {
+ vehicle_udp_open(this);
+ fd=this->fd;
}
this->iochan=g_io_channel_unix_new(fd);
enable_watch(this);
#else
{
#endif
+ if (this->is_udp) {
+ vehicle_udp_recv(this);
+ return TRUE;
+ }
size=read(g_io_channel_unix_get_fd(iochan), this->buffer+this->buffer_pos, BUFFER_SIZE-this->buffer_pos-1);
if (size <= 0) {
vehicle_close(this);
/* prototypes */
+enum projection;
struct coord;
struct vehicle;
enum projection vehicle_projection(struct vehicle *this);
double *vehicle_dir_get(struct vehicle *this);
void vehicle_set_position(struct vehicle *this, struct coord *pos);
struct vehicle *vehicle_new(const char *url);
+int vehicle_get_active(struct vehicle *this);
+void vehicle_set_active(struct vehicle *this, int active);
void *vehicle_callback_register(struct vehicle *this, void (*func)(struct vehicle *, void *data), void *data);
void vehicle_callback_unregister(struct vehicle *this, void *handle);
void vehicle_destroy(struct vehicle *this);
+/* end of prototypes */
const char *s=find_attribute(state, "source", 1);
const char *value;
struct color color;
- int update=1, follow=0;
+ int update=1, follow=0, active;
if (! s)
return 0;
update=convert_number(value);
if ((value=find_attribute(state, "follow", 0)))
follow=convert_number(value);
-
- navit_vehicle_add(state->parent->element_object, state->element_object, &color, update, follow);
+ active=find_boolean(state, "active", 1, 0);
+
+ navit_vehicle_add(state->parent->element_object, state->element_object, &color, update, follow, active);
return 1;
}