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; }
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); priv->position_set=1; dbg(1,"position_set %f %f\n", priv->geo.lat, priv->geo.lng); break; case attr_profilename: case attr_source: case attr_name: // Ignore; used by Navit's infrastructure, but not relevant for this vehicle. break; default: dbg(0,"unsupported attribute %s\n",attr_to_name(attr->type)); return 0; } return 1; }
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; }
/** @fn static void vehicle_file_enable_watch(struct vehicle_priv *priv) ***************************************************************************** * @b Description: Enable watch ***************************************************************************** * @param priv : pointer on the private data of the plugin ***************************************************************************** **/ static void vehicle_file_enable_watch(struct vehicle_priv *priv) { dbg(1, "enter\n"); #ifdef _WIN32 // add an event : don't use glib timers and g_timeout_add if (priv->timeout_callback != NULL) priv->timeout = event_add_timeout(500, 1, priv->timeout_callback); else dbg(1, "error : watch not enabled : priv->timeout_callback is null\n"); #else if (! priv->watch) priv->watch = event_add_watch((void *)priv->fd, event_watch_cond_read, priv->cb); #endif }
static int script_set_attr_int(struct script *scr, struct attr *attr) { switch (attr->type) { case attr_refresh_cond: dbg(lvl_debug,"refresh_cond\n"); if (scr->cs) command_saved_destroy(scr->cs); scr->cs=command_saved_attr_new(attr->u.str, &scr->parent, scr->cb, 0); return 1; case attr_update_period: if (scr->timeout) event_remove_timeout(scr->timeout); scr->timeout=event_add_timeout(attr->u.num, 1, scr->cb); return 1; default: return 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; }
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 }
static int vehicle_webos_open(struct vehicle_priv *priv) { PDL_Err err; priv->pdk_version = PDL_GetPDKVersion(); dbg(lvl_debug,"pdk_version(%d)\n", 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)\n", 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)\n", err, PDL_GetError()); // vehicle_webos_close(priv); // return 0; } priv->gps_type = GPS_TYPE_INT; if(!vehicle_webos_bt_open(priv)) return 0; } priv->ev_timeout = event_add_timeout(1000, 1, priv->timeout_cb); return 1; }
/** @fn static int vehicle_file_parse( struct vehicle_priv *priv, * char *buffer) ***************************************************************************** * @b Description: Parse the buffer ***************************************************************************** * @param priv : pointer on the private data of the plugin * @param buffer : data buffer (null terminated) ***************************************************************************** * @return 1 if The GPRMC Sentence is found * 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(2, "enter: buffer='%s'\n", buffer); for (;;) { if (len < 4) { dbg(0, "'%s' too short\n", 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(0, "no leading $ in '%s'\n", buffer); return ret; } if (buffer[len - 3] != '*') { dbg(0, "no *XX in '%s'\n", 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(0, "no checksum in '%s'\n", buffer); return ret; } if (bcsum != csum && priv->checksum_ignore == 0) { dbg(0, "wrong checksum in '%s'\n", 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(0, "nmea buffer overflow, discarding '%s'\n", buffer); } i = 0; p = buffer; while (i < 31) { item[i++] = p; while (*p && *p != ',') p++; if (!*p) break; *p++ = '\0'; } if (!strncmp(buffer, "$GPGGA", 6)) { /* 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 (!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 (!strcasecmp(item[5],"W")) priv->geo.lng=-priv->geo.lng; priv->valid=attr_position_valid_valid; dbg(2, "latitude '%2.4f' longitude %2.4f\n", 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]) strcpy(priv->fixtime, item[1]); 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; #ifndef _WIN32 if (priv->file_type == file_type_file) { if (priv->watch) { vehicle_file_disable_watch(priv); event_add_timeout(priv->time, 0, priv->cbt); } } #endif } if (!strncmp(buffer, "$GPVTG", 6)) { /* 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(2,"direction %lf, speed %2.1lf\n", priv->direction, priv->speed); } } if (!strncmp(buffer, "$GPRMC", 6)) { /* 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; } 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); } 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, "$GPZDA", 6)) { /* 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]) { // priv->fixtime = atof(item[1]); strcpy(priv->fixtime, item[1]); 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(1,"magnetic %d\n", priv->magnetic_direction); } } return ret; }
/** @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; struct attr *state_file; 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; 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; #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 && !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(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); 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; #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; }