/** @fn static void vehicle_priv vehicle_file_destroy(struct vehicle_priv *priv) ***************************************************************************** * @b Description: Function called to uninitialize the plugin ***************************************************************************** * @param priv : pointer on the private data of the plugin ***************************************************************************** * @remarks private data is freed by this function (g_free) ***************************************************************************** **/ static void vehicle_file_destroy(struct vehicle_priv *priv) { if (priv->statefile && priv->nmea_data) { struct attr readwrite={attr_readwrite}; struct attr create={attr_create}; struct attr *attrs[]={&readwrite,&create,NULL}; struct file *f; readwrite.u.num=1; create.u.num=1; f=file_create(priv->statefile, attrs); if (f) { file_data_write(f, 0, strlen(priv->nmea_data), priv->nmea_data); file_destroy(f); } } vehicle_file_close(priv); callback_destroy(priv->cb); callback_destroy(priv->cbt); if (priv->statefile) g_free(priv->statefile); if (priv->source) g_free(priv->source); if (priv->buffer) g_free(priv->buffer); g_free(priv); }
/** @fn static void vehicle_priv vehicle_file_destroy(struct vehicle_priv *priv) ***************************************************************************** * @b Description: Function called to uninitialize the plugin ***************************************************************************** * @param priv : pointer on the private data of the plugin ***************************************************************************** * @remarks private data is freed by this function (g_free) ***************************************************************************** **/ static void vehicle_file_destroy(struct vehicle_priv *priv) { vehicle_file_close(priv); callback_destroy(priv->cb); callback_destroy(priv->cbt); if (priv->source) g_free(priv->source); if (priv->buffer) g_free(priv->buffer); g_free(priv); }
/** @fn static void vehicle_file_io(struct vehicle_priv *priv) ***************************************************************************** * @b Description: function to get data from GPS ***************************************************************************** * @param priv : pointer on the private data of the plugin ***************************************************************************** * @remarks Not used on WIN32 operating system ***************************************************************************** **/ static void vehicle_file_io(struct vehicle_priv *priv) { dbg(1, "vehicle_file_io : enter\n"); #ifndef _WIN32 int size, rc = 0; char *str, *tok; size = read(priv->fd, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1); if (size <= 0) { switch (priv->on_eof) { case 0: vehicle_file_close(priv); vehicle_file_open(priv); break; case 1: vehicle_file_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_file_parse(priv, str); str = tok; } if (str != priv->buffer) { size = priv->buffer + priv->buffer_pos - str; memmove(priv->buffer, str, size + 1); priv->buffer_pos = size; dbg(1, "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); #endif }
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; }
/** @fn static void vehicle_file_io(struct vehicle_priv *priv) ***************************************************************************** * @b Description: function to get data from GPS ***************************************************************************** * @param priv : pointer on the private data of the plugin ***************************************************************************** * @remarks ***************************************************************************** **/ static void vehicle_file_io(struct vehicle_priv *priv) { int size, rc = 0; char *str, *tok; dbg(1, "vehicle_file_io : enter\n"); if (priv->process_statefile) { unsigned char *data; priv->process_statefile=0; if (file_get_contents(priv->statefile, &data, &size)) { if (size > buffer_size) size=buffer_size; memcpy(priv->buffer, data, size); priv->buffer_pos=0; g_free(data); } else return; } else { size = read(priv->fd, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1); } if (size <= 0) { switch (priv->on_eof) { case 0: vehicle_file_close(priv); vehicle_file_open(priv); break; case 1: vehicle_file_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_file_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(1, "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); }