15 struct callback_list *cbl;
24 vehicle_demo_destroy(struct vehicle_priv *priv)
30 vehicle_demo_position_attr_get(struct vehicle_priv *priv,
31 enum attr_type type, struct attr *attr)
34 case attr_position_speed:
35 attr->u.numd = &priv->speed;
37 case attr_position_direction:
38 attr->u.numd = &priv->direction;
40 case attr_position_coord_geo:
41 attr->u.coord_geo = &priv->geo;
51 vehicle_demo_set_attr(struct vehicle_priv *priv, struct attr *attr,
54 if (attr->type == attr_navit) {
55 priv->navit = attr->u.navit;
61 struct vehicle_methods vehicle_demo_methods = {
63 vehicle_demo_position_attr_get,
64 vehicle_demo_set_attr,
68 vehicle_demo_timer(struct vehicle_priv *priv)
70 struct route_path_coord_handle *h=NULL;
71 struct coord *c, *pos=NULL, ci;
72 int slen, len, dx, dy;
74 len = (priv->speed * priv->interval / 1000)/ 3.6;
75 dbg(1, "###### Entering simulation loop\n");
77 dbg(1, "vehicle->navit is not set. Can't simulate\n");
80 struct route *vehicle_route = navit_get_route(priv->navit);
82 h = route_path_coord_open(vehicle_route);
84 pos = route_path_coord_get(h);
85 dbg(1, "current pos=%p\n", pos);
88 dbg(1, "current pos=0x%x,0x%x\n", pos->x, pos->y);
89 dbg(1, "last pos=0x%x,0x%x\n", priv->last.x, priv->last.y);
90 if (priv->last.x == pos->x && priv->last.y == pos->y) {
91 dbg(1, "endless loop\n");
95 c = route_path_coord_get(h);
96 dbg(1, "next pos=%p\n", c);
99 dbg(1, "next pos=0x%x,0x%x\n", c->x, c->y);
100 slen = transform_distance(projection_mg, pos, c);
101 dbg(1, "len=%d slen=%d\n", len, slen);
108 ci.x = pos->x + dx * len / slen;
109 ci.y = pos->y + dy * len / slen;
111 transform_get_angle_delta(pos, c, 0);
112 dbg(1, "ci=0x%x,0x%x\n", ci.x, ci.y);
113 transform_to_geo(projection_mg, &ci,
115 callback_list_call_0(priv->cbl);
120 if (priv->position_set)
121 callback_list_call_0(priv->cbl);
128 static struct vehicle_priv *
129 vehicle_demo_new(struct vehicle_methods
130 *meth, struct callback_list
131 *cbl, struct attr **attrs)
133 struct vehicle_priv *ret;
134 struct attr *interval,*speed,*position_coord_geo;
137 ret = g_new0(struct vehicle_priv, 1);
141 if ((speed=attr_search(attrs, NULL, attr_speed)))
142 ret->speed=speed->u.num;
143 if ((interval=attr_search(attrs, NULL, attr_interval)))
144 ret->interval=speed->u.num;
145 if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
146 ret->geo=*(position_coord_geo->u.coord_geo);
148 dbg(0,"position_set %f %f\n", ret->geo.lat, ret->geo.lng);
150 *meth = vehicle_demo_methods;
151 g_timeout_add(ret->interval, (GSourceFunc) vehicle_demo_timer, ret);
159 plugin_register_vehicle_type("demo", vehicle_demo_new);