/*! \brief Pre-loads the dependencies related to a tab/group of tabs \param data is the pointer to a GPtrArray list of tab infos, used to traverse each tab config file to preload the needed interdependancy structures */ gboolean preload_deps(gpointer data) { Firmware_Details *firmware = NULL; GPtrArray *array = (GPtrArray *)data; TabInfo *tabinfo = NULL; GladeInterface *iface = NULL; GladeWidgetInfo *info = NULL; ConfigFile *cfgfile = NULL; guint i = 0; guint j = 0; ENTER(); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); g_return_val_if_fail(firmware,FALSE); for (i=0;i<array->len;i++) { tabinfo = (TabInfo *)g_ptr_array_index(array,i); iface = glade_parser_parse_file(tabinfo->glade_file,NULL); cfgfile = cfg_open_file(tabinfo->datamap_file); if ((!cfgfile) || (!iface)) continue; for(j=0;j<iface->n_toplevels;j++) { info = iface->toplevels[j]; descend_tree(info,cfgfile); } glade_interface_destroy(iface); cfg_free(cfgfile); } io_cmd(firmware->get_all_command,NULL); EXIT(); return FALSE; /* Make it not run again... */ }
/*! \brief Firmware specific function that backs up the ECU to a filename passed \param filename is the filename to backup the ECU to */ G_MODULE_EXPORT void backup_all_ecu_settings(gchar *filename) { ConfigFile *cfgfile; gchar * section = NULL; gchar * tmpbuf = NULL; gint i = 0; gint locID = 0; gint x = 0; gint canID = 0; DataSize size = MTX_U08; /* <<<<< BAD BAD BAD >>>>> */ GString *string = NULL; extern gconstpointer *global_data; Firmware_Details *firmware = NULL; firmware = DATA_GET(global_data,"firmware"); g_return_if_fail(filename); g_return_if_fail(firmware); cfgfile = cfg_open_file(filename); if(!cfgfile) cfgfile = cfg_new(); set_file_api_f(cfgfile,BACKUP_MAJOR_API,BACKUP_MINOR_API); update_logbar_f("tools_view",NULL,g_strdup_printf("%s %s\n",_("Full Backup Commencing to file:\n\t"),filename),FALSE,FALSE,TRUE); cfg_write_string(cfgfile,"Firmware","name",firmware->name); for(i=0;i<firmware->total_pages;i++) { if (firmware->page_params[i]->read_only) continue; string = g_string_sized_new(64); section = g_strdup_printf("page_%i",i); cfg_write_int(cfgfile,section,"num_variables",firmware->page_params[i]->length); for(x=0;x<firmware->page_params[i]->length;x++) { locID = firmware->page_params[i]->phys_ecu_page; g_string_append_printf(string,"%i",freeems_get_ecu_data(canID,locID,x,size)); if (x < (firmware->page_params[i]->length-1)) string = g_string_append(string,","); } cfg_write_string(cfgfile,section,"data",string->str); g_free(section); g_string_free(string,TRUE); } update_logbar_f("tools_view",NULL,_("Full Backup Complete...\n"),FALSE,FALSE,FALSE); cfg_write_file(cfgfile,filename); cfg_free(cfgfile); }
void save_defaults() { ConfigFile *cfgfile; gchar * filename = NULL; gchar * tmpbuf = NULL; filename = g_build_filename(HOME(),"mtx","default","config", NULL); cfgfile = cfg_open_file(filename); if (cfgfile) { tmpbuf = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gtk_builder_get_object ((GtkBuilder *)DATA_GET(global_data,"builder"), "filechooser_button"))); if (tmpbuf) cfg_write_string(cfgfile, (gchar *)"MTXLoader", (gchar *)"last_file", tmpbuf); g_free(tmpbuf); cfg_write_file(cfgfile,filename); cfg_free(cfgfile); g_free(filename); } }
void load_defaults() { GtkBuilder *builder = NULL; ConfigFile *cfgfile; gchar * filename = NULL; gchar * tmpbuf = NULL; GtkFileFilter *filter = NULL; GObject *object = NULL; builder = (GtkBuilder *)DATA_GET(global_data,"builder"); g_return_if_fail(builder); filename = g_build_filename(HOME(),"mtx","default","config", NULL); cfgfile = cfg_open_file(filename); if (cfgfile) { if(cfg_read_string(cfgfile, (gchar *)"Serial", (gchar *)"override_port", &tmpbuf)) { gtk_entry_set_text(GTK_ENTRY(gtk_builder_get_object (builder, "port_entry")),tmpbuf); g_free(tmpbuf); } if(cfg_read_string(cfgfile, (gchar *)"MTXLoader", (gchar *)"last_file", &tmpbuf)) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(gtk_builder_get_object (builder, "filechooser_button")),tmpbuf); filter = gtk_file_filter_new(); gtk_file_filter_add_pattern(filter,"*.s19"); gtk_file_filter_add_pattern(filter,"*.S19"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(gtk_builder_get_object (builder, "filechooser_button")),filter); g_free(tmpbuf); } object = gtk_builder_get_object(builder,"ms1_rbutton"); if (G_IS_OBJECT(object)) OBJ_SET(object,"persona",GINT_TO_POINTER(MS1)); object = gtk_builder_get_object(builder,"ms2_rbutton"); if (G_IS_OBJECT(object)) OBJ_SET(object,"persona",GINT_TO_POINTER(MS2)); object = gtk_builder_get_object(builder,"freeems_rbutton"); if (G_IS_OBJECT(object)) OBJ_SET(object,"persona",GINT_TO_POINTER(FREEEMS)); cfg_free(cfgfile); g_free(filename); } }
// Only for tests. cfg_register_filext() should be used. void cfg_register_fileext_file(const char *filepath, const char *ext, const char *prgm) { char key[15] = "ext."; cfg_open_file(filepath); strncat(key, ext, 15 - 4 - 1); if (cfg_get(key)) { cfg_close(); return; } cfg_close(); FILE *file = fopen(filepath, "a+b"); if (!file) return; fseek(file, 0, SEEK_END); if (ftell(file) > 0) { fseek(file, -1, SEEK_END); if (fgetc(file) != '\n') { fseek(file, 0, SEEK_END); fputc('\n', file); } } fseek(file, 0, SEEK_END); fprintf(file, "%s=%s\n", key, prgm); fclose(file); }
/*! \brief restore_all_ecu_settings() reads the filename passed and if all checks pass the file will be loaded and any values that differ from the values currently in the ECU will be replaced. \param filename (filename to read for ecu restoration WARNING: This function is not yet capable of handling CAN devices, and will always restore to can ID ZERO (which can be BAD!!), backup/restore needs to be rewritten.. */ G_MODULE_EXPORT void restore_all_ecu_settings(gchar *filename) { ConfigFile *cfgfile; /* GArray *pfuncs = NULL; PostFunction *pf = NULL; */ gchar * section = NULL; gchar * msgbuf = NULL; gint canID = 0; DataSize size = MTX_U08; gint page = 0; gint offset = 0; gint tmpi = 0; gint major = 0; gint minor = 0; gboolean restart = FALSE; gchar *tmpbuf = NULL; guint8 *data = NULL; gchar **keys = NULL; gint num_keys = 0; gint dload_val = 0; PostFunction *pf = NULL; GArray *pfuncs = NULL; extern gconstpointer *global_data; Firmware_Details *firmware = NULL; firmware = DATA_GET(global_data,"firmware"); g_return_if_fail(filename); g_return_if_fail(firmware); canID = firmware->canID; cfgfile = cfg_open_file(filename); if (!cfgfile) { update_logbar_f("tools_view","warning",g_strdup_printf(_(":restore_all_ecu_settings()\n\t Unable to open this file (%s)\n"),filename),FALSE,FALSE,TRUE); return; } if (cfgfile) { get_file_api_f(cfgfile,&major,&minor); if (major != BACKUP_MAJOR_API) { update_logbar_f("tools_view","warning",g_strdup_printf(_(":restore_all_ecu_settings()\n\tAPI MAJOR version mismatch: \"%i\" != \"%i\"\n can not load this file for restoration\n"),major,BACKUP_MAJOR_API),FALSE,FALSE,TRUE); cfg_free(cfgfile); return; } if (minor != BACKUP_MINOR_API) update_logbar_f("tools_view","warning",g_strdup_printf(_(": restore_all_ecu_settings()\n\tAPI MINOR version mismatch: \"%i\" != \"%i\"\n Will try to load this file for restoration, expect issues\n"),minor,BACKUP_MINOR_API),FALSE,FALSE,TRUE); cfg_read_string(cfgfile,"Firmware","name",&tmpbuf); if (g_ascii_strcasecmp(g_strdelimit(tmpbuf," ,",'_'),g_strdelimit(firmware->name," ,",'_')) != 0) { dbg_func_f(CRITICAL,g_strdup_printf(__FILE__": restore_all_ecu_settings()\nFirmware name mismatch:\n\"%s\" != \"%s\",\ncannot load this file for restoration\n",tmpbuf,firmware->name)); update_logbar_f("tools_view","warning",g_strdup_printf(_(": restore_all_ecu_settings()\nFirmware name mismatch: \"%s\" != \"%s\"\ncan NOT load this file for restoration!\n"),tmpbuf,firmware->name),FALSE,FALSE,TRUE); if (tmpbuf) g_free(tmpbuf); cfg_free(cfgfile); return; } g_free(tmpbuf); set_title_f(g_strdup(_("Restoring ECU settings from File"))); if (DATA_GET(global_data,"realtime_id")) { stop_tickler_f(RTV_TICKLER); restart = TRUE; } for (page=0;page<firmware->total_pages;page++) { if (!(firmware->page_params[page]->dl_by_default)) continue; section = g_strdup_printf("page_%i",page); if(cfg_read_int(cfgfile,section,"num_variables",&tmpi)) if (tmpi != firmware->page_params[page]->length) { update_logbar_f("tools_view","warning",g_strdup_printf(_(": restore_all_ecu_settings()\n\tNumber of variables in backup \"%i\" and firmware specification \"%i\" do NOT match,\n\tcorruption SHOULD be expected\n"),tmpi,firmware->page_params[page]->length),FALSE,FALSE,TRUE); dbg_func_f(CRITICAL,g_strdup_printf(_(": restore_all_ecu_settings()\n\tNumber of variables in backup \"%i\" and firmware specification \"%i\" do NOT match,\n\tcorruption SHOULD be expected\n"),tmpi,firmware->page_params[page]->length)); } if (cfg_read_string(cfgfile,section,"data",&tmpbuf)) { keys = parse_keys_f(tmpbuf,&num_keys,","); if (num_keys != firmware->page_params[page]->length) { update_logbar_f("tools_view","warning",g_strdup_printf(_(": restore_all_ecu_settings()\n\tNumber of variables in this backup \"%i\" does NOT match the length of the table \"%i\", expect a crash!!!\n"),num_keys,firmware->page_params[page]->length),FALSE,FALSE,TRUE); dbg_func_f(CRITICAL,g_strdup_printf(_(": restore_all_ecu_settings()\n\tNumber of variables in this backup \"%i\" does NOT match the length of the table \"%i\", expect a crash!!!\n"),num_keys,firmware->page_params[page]->length)); } if (firmware->chunk_support) { data = g_new0(guint8, firmware->page_params[page]->length); for (offset=0;offset<num_keys;offset++) data[offset]=(guint8)atoi(keys[offset]); if (DATA_GET(global_data,"offline")) ms_store_new_block(canID,page,0,data,num_keys); else ms_chunk_write(canID,page,0,num_keys,data); } else { if (DATA_GET(global_data,"offline")) { for (offset=0;offset<num_keys;offset++) { dload_val = atoi(keys[offset]); ms_set_ecu_data(canID,page,offset,size,dload_val); } } else { for (offset=0;offset<num_keys;offset++) { dload_val = atoi(keys[offset]); if (dload_val != ms_get_ecu_data_last(canID,page,offset,size)) { /*printf("writing data for page %i, offset %i\n",page,offset);*/ ms_send_to_ecu(canID,page,offset,size,dload_val, FALSE); } } queue_burn_ecu_flash(page); } } g_strfreev(keys); g_free(tmpbuf); } g_free(section); } start_restore_monitor(); cfg_free(cfgfile); } if (DATA_GET(global_data,"offline")) { pfuncs = g_array_new(FALSE,TRUE,sizeof(PostFunction *)); pf = g_new0(PostFunction,1); pf->name = g_strdup("update_ecu_controls_pf"); get_symbol_f(pf->name,(void *)&pf->function); pf->w_arg = FALSE; pfuncs = g_array_append_val(pfuncs,pf); pf = g_new0(PostFunction,1); pf->name = g_strdup("set_store_black_pf"); get_symbol_f(pf->name,(void *)&pf->function); pf->w_arg = FALSE; pfuncs = g_array_append_val(pfuncs,pf); io_cmd_f(NULL,pfuncs); } if (restart) start_tickler_f(RTV_TICKLER); }
gboolean lookuptable_change(GtkCellRenderer *renderer, gchar *path, gchar * new_text, gpointer data) { GtkListStore *store = NULL; GtkTreeIter iter; GtkTreeModel *model = data; ConfigFile *cfgfile = NULL; gchar * int_name = NULL; gchar * old = NULL; gchar * new_name = NULL; gchar ** vector = NULL; gboolean restart_tickler = FALSE; extern gint realtime_id; extern GHashTable *lookuptables; extern GAsyncQueue *io_data_queue; extern Firmware_Details *firmware; gint count = 0; LookupTable *lookuptable = NULL; /* Get combo box model so we can set the combo to this new value */ g_object_get(G_OBJECT(renderer),"model",&store,NULL); gtk_tree_model_get_iter_from_string(model,&iter,path); gtk_tree_model_get(model,&iter,INTERNAL_NAME_COL,&int_name,FILENAME_COL,&old,-1); if (g_strcasecmp(old,new_text) == 0) /* If no change, return */ return TRUE; if (g_strcasecmp(new_text,"Personal") == 0) return TRUE; if (g_strcasecmp(new_text,"System") == 0) return TRUE; if (realtime_id) { restart_tickler = TRUE; stop_tickler(RTV_TICKLER); count = 0; while ((g_async_queue_length(io_data_queue) > 0) && (count < 30)) { dbg_func(CRITICAL,g_strdup_printf(__FILE__": LEAVE() draining I/O Queue, current length %i\n",g_async_queue_length(io_data_queue))); while (gtk_events_pending()) gtk_main_iteration(); count++; } } lookuptable = (LookupTable *)g_hash_table_lookup(lookuptables,int_name); if (!lookuptable) printf(_("No lookuptable found! expect a crash!!\n")); g_free(lookuptable->array); /* Free the old one */ g_free(lookuptable->filename); /* Free the old one */ g_free(lookuptable); /* Free the old one */ get_table(int_name,new_text,NULL); /* Load the new one in it's place */ gtk_list_store_set(GTK_LIST_STORE(model),&iter, FILENAME_COL, new_text,-1); if (restart_tickler) start_tickler(RTV_TICKLER); cfgfile = cfg_open_file(firmware->profile_filename); if (!cfgfile) return FALSE; g_hash_table_foreach(lookuptables,update_lt_config,cfgfile); if (g_strrstr(firmware->profile_filename,".MegaTunix")) cfg_write_file(cfgfile, firmware->profile_filename); else { vector = g_strsplit(firmware->profile_filename,PSEP,-1); new_name = g_build_filename(HOME(),".MegaTunix",INTERROGATOR_DATA_DIR,"Profiles",vector[g_strv_length(vector)-1],NULL); g_strfreev(vector); cfg_write_file(cfgfile, new_name); g_free(firmware->profile_filename); firmware->profile_filename=g_strdup(new_name); g_free(new_name); } cfg_free(cfgfile); /*printf("internal name %s, old table %s, new table %s\n",int_name,old,new_text);*/ return TRUE; }
EXPORT gboolean lookuptables_configurator(GtkWidget *widget, gpointer data) { static gboolean ltc_created = FALSE; static GtkWidget * lookuptables_config_window = NULL; extern Firmware_Details *firmware; GtkListStore *store = NULL; GtkTreeStore *combostore = NULL; GtkTreeIter iter; GtkTreeIter per_iter; GtkTreeIter sys_iter; GtkCellRenderer *renderer = NULL; GtkTreeViewColumn *column = NULL; GtkWidget * vbox = NULL; GtkWidget * tree = NULL; GtkWidget * frame = NULL; ListElement *element = NULL; ConfigFile *cfgfile = NULL; GArray *classes = NULL; GList *p_list = NULL; GList *s_list = NULL; guint i = 0; gchar * tmpbuf = NULL; gchar ** vector = NULL; gchar ** tmpvector = NULL; if ((ltc_created) && (ltc_visible)) return TRUE; if ((ltc_created) && (!ltc_visible)) { gtk_widget_show_all(lookuptables_config_window); return TRUE; } else /* i.e. NOT created, build it */ { lookuptables_config_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(lookuptables_config_window),_("MegaTunix LookupTables")); gtk_window_set_default_size(GTK_WINDOW(lookuptables_config_window),300,200); vbox = gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(lookuptables_config_window),vbox); gtk_container_set_border_width(GTK_CONTAINER(vbox),5); g_signal_connect(G_OBJECT(lookuptables_config_window),"delete_event", G_CALLBACK(lookuptables_configurator_hide),NULL); ltc_created = TRUE; ltc_visible = TRUE; frame = gtk_frame_new("MegaTunix LookupTables"); gtk_box_pack_start (GTK_BOX(vbox),frame,FALSE,TRUE,5); vbox = gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(frame),vbox); store = gtk_list_store_new(N_COLS, /* total cols */ G_TYPE_STRING, /* int name */ G_TYPE_STRING, /* filename combo*/ G_TYPE_BOOLEAN,/* View/Edit */ G_TYPE_BOOLEAN); /* change */ combostore = gtk_tree_store_new(1,G_TYPE_STRING);/* lookuptable filename */ gtk_tree_store_append(combostore,&per_iter,NULL); gtk_tree_store_append(combostore,&sys_iter,NULL); gtk_tree_store_set(combostore,&per_iter, 0,"Personal", -1); gtk_tree_store_set(combostore,&sys_iter, 0,"System", -1); vector = get_files(g_strdup(LOOKUPTABLES_DATA_DIR),g_strdup("inc"),&classes); for (i=0;i<g_strv_length(vector);i++) { tmpvector = g_strsplit(vector[i],PSEP,-1); if (g_array_index(classes,FileClass,i) == PERSONAL) { element = g_new0(ListElement, 1); element->name = g_strdup(tmpvector[g_strv_length(tmpvector)-1]); p_list = g_list_append(p_list,element); } if (g_array_index(classes,FileClass,i) == SYSTEM) { element = g_new0(ListElement, 1); element->name = g_strdup(tmpvector[g_strv_length(tmpvector)-1]); s_list = g_list_append(s_list,element); } g_strfreev(tmpvector); } g_strfreev(vector); g_array_free(classes,TRUE); p_list = g_list_sort(p_list,list_sort); s_list = g_list_sort(s_list,list_sort); for (i=0;i<g_list_length(p_list);i++) { gtk_tree_store_append(combostore,&iter,&per_iter); element = g_list_nth_data(p_list,i); gtk_tree_store_set(combostore,&iter, 0,element->name, -1); } for (i=0;i<g_list_length(s_list);i++) { gtk_tree_store_append(combostore,&iter,&sys_iter); element = g_list_nth_data(s_list,i); gtk_tree_store_set(combostore,&iter, 0,element->name, -1); } g_list_foreach(p_list,free_element,NULL); g_list_foreach(s_list,free_element,NULL); g_list_free(p_list); g_list_free(s_list); cfgfile = cfg_open_file(firmware->profile_filename); if (!cfgfile) return FALSE; cfg_read_string(cfgfile,"lookuptables","tables",&tmpbuf); vector = g_strsplit(tmpbuf,",",-1); g_free(tmpbuf); for (i=0;i<g_strv_length(vector);i++) { cfg_read_string(cfgfile,"lookuptables",vector[i],&tmpbuf); gtk_list_store_append(store,&iter); gtk_list_store_set(store,&iter, INTERNAL_NAME_COL,vector[i], FILENAME_COL,tmpbuf, VIEW_EDIT_COL,FALSE, -1); g_free(tmpbuf); } g_strfreev(vector); tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree),TRUE); gtk_box_pack_start(GTK_BOX(vbox),tree,TRUE,TRUE,0); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("Internal Name",renderer,"text",INTERNAL_NAME_COL,NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column); renderer = gtk_cell_renderer_combo_new(); g_object_set(G_OBJECT(renderer),"editable",TRUE,"model",combostore,"text-column",0,"style",PANGO_STYLE_ITALIC,NULL); g_signal_connect(G_OBJECT(renderer),"edited", G_CALLBACK(lookuptable_change),store); column = gtk_tree_view_column_new_with_attributes("Table Filename",renderer,"text",FILENAME_COL,NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column); /* renderer = gtk_cell_renderer_toggle_new(); column = gtk_tree_view_column_new_with_attributes("View/Edit",renderer,"active",VIEW_EDIT_COL,NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column); */ gtk_widget_show_all (lookuptables_config_window); gtk_tree_view_columns_autosize( GTK_TREE_VIEW(tree)); return TRUE; } }
G_MODULE_EXPORT gboolean load_firmware_details(Firmware_Details *firmware, gchar * filename) { ConfigFile *cfgfile; Location_Details *details = NULL; GList *locations = NULL; gchar *tmpbuf = NULL; gchar *section = NULL; gchar ** list = NULL; gint i = 0; gint major = 0; gint minor = 0; cfgfile = cfg_open_file((gchar *)filename); if (!cfgfile) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": load_firmware_details()\n\tFile \"%s\" NOT OPENED successfully\n",filename)); get_file_api_f(cfgfile,&major,&minor); if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API)) { thread_update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile API mismatch (%i.%i != %i.%i):\n\tFile %s will be skipped\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,filename),FALSE,FALSE); cfg_free(cfgfile); return FALSE; } dbg_func_f(INTERROGATOR,g_strdup_printf(__FILE__": load_firmware_details()\n\tfile:%s opened successfully\n",filename)); firmware->profile_filename = g_strdup(filename); cfg_read_string(cfgfile,"interrogation_profile","name",&firmware->name); if(cfg_read_string(cfgfile,"parameters","EcuTempUnits",&tmpbuf)) { firmware->ecu_temp_units = translate_string_f(tmpbuf); g_free(tmpbuf); } else dbg_func_f(INTERROGATOR,g_strdup_printf(__FILE__": load_firmware_details()\n\tFailed to find EcuTempUnits key in interrogation profile\n")); if(!cfg_read_boolean(cfgfile,"parameters","BigEndian",&firmware->bigendian)) { dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"BigEndian\" key not found in interrogation profile, assuming ECU firmware byte order is big endian, ERROR in interrogation profile\n")); firmware->bigendian = TRUE; } if(!cfg_read_string(cfgfile,"parameters","Capabilities", &tmpbuf)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"Capabilities\" enumeration list not found in interrogation profile, ERROR\n")); else { firmware->capabilities = translate_capabilities(tmpbuf); g_free(tmpbuf); } /* Commands to map against the comm.xml */ if(!cfg_read_string(cfgfile,"parameters","RT_Command",&firmware->rt_command)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"RT_Command\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_int(cfgfile,"parameters","RT_total_bytes", &firmware->rtvars_size)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"RT_total_bytes\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_string(cfgfile,"parameters","Get_All_Command", &firmware->get_all_command)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"Get_All_Command\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_string(cfgfile,"parameters","Read_Command", &firmware->read_command)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"Read_Command\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_string(cfgfile,"parameters","Write_Command", &firmware->write_command)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"Write_Command\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_string(cfgfile,"parameters","Burn_Command", &firmware->burn_command)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"Burn_Command\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_string(cfgfile,"parameters","Burn_All_Command", &firmware->burn_all_command)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"Burn_All_Command\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_boolean(cfgfile,"parameters","ChunkWriteSupport", &firmware->chunk_support)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"ChunkWriteSupport\" flag not found in parameters section in interrogation profile, ERROR\n")); if (firmware->chunk_support) { if(!cfg_read_string(cfgfile,"parameters","Chunk_Write_Command", &firmware->chunk_write_command)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"Chunk_Write_Command\" flag not found in parameters section in interrogation profile, ERROR\n")); } /* Gui Section */ if(!cfg_read_string(cfgfile,"gui","LoadTabs",&tmpbuf)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"LoadTabs\" list not found in interrogation profile, ERROR\n")); else { firmware->tab_list = g_strsplit(tmpbuf,",",0); g_free(tmpbuf); } if(!cfg_read_string(cfgfile,"gui","TabConfs", &tmpbuf)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"TabConfs\" list not found in interrogation profile, ERROR\n")); else { firmware->tab_confs = g_strsplit(tmpbuf,",",0); g_free(tmpbuf); } if(!cfg_read_string(cfgfile,"gui","RealtimeMapFile", &firmware->rtv_map_file)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"RealtimeMapFile\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_string(cfgfile,"gui","SliderMapFile", &firmware->sliders_map_file)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"SliderMapFile\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_string(cfgfile,"gui","RuntimeTextMapFile", &firmware->rtt_map_file)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"RuntimeTextMapFile\" variable not found in interrogation profile, ERROR\n")); if(!cfg_read_string(cfgfile,"gui","StatusMapFile", &firmware->status_map_file)) dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": load_firmware_details()\n\t\"StatusMapFile\" variable not found in interrogation profile, ERROR\n")); /* Megatunix Doesn't yet know how to deal with FreeEMS's locationID's which are semi-analagous to Pages in MS-land */ locations = request_location_ids(NULL); if (locations) { firmware->total_pages = g_list_length(locations); firmware->page_params = g_new0(Page_Params *, firmware->total_pages); for (i=0;i<firmware->total_pages;i++) { firmware->page_params[i] = initialize_page_params(); firmware->page_params[i]->phys_ecu_page = (GINT)g_list_nth_data(locations,i); details = request_location_id_details((GINT)g_list_nth_data(locations,i)); if (details) { firmware->page_params[i]->length = details->length; firmware->page_params[i]->dl_by_default = (details->flags & BLOCK_IS_INDEXABLE); } g_free(details); } g_list_free(locations); } /* MAJOR HACK ALERT, hardcoded for fred! */ firmware->total_tables = 3; firmware->table_params = g_new0(Table_Params *,firmware->total_tables); /* Fuel Table */ firmware->table_params[0] = initialize_table_params(); firmware->table_params[0]->x_page = 0; firmware->table_params[0]->y_page = 0; firmware->table_params[0]->z_page = 0; firmware->table_params[0]->x_bincount = 16; firmware->table_params[0]->y_bincount = 16; firmware->table_params[0]->x_base = 4; firmware->table_params[0]->y_base = 58; firmware->table_params[0]->z_base = 100; firmware->table_params[0]->x_size = MTX_U16; firmware->table_params[0]->y_size = MTX_U16; firmware->table_params[0]->z_size = MTX_U16; firmware->table_params[0]->x_source = g_strdup("RPM"); firmware->table_params[0]->x_fromecu_mult = g_new0(gfloat, 1); firmware->table_params[0]->y_fromecu_mult = g_new0(gfloat, 1); firmware->table_params[0]->z_fromecu_mult = g_new0(gfloat, 1); *(firmware->table_params[0]->x_fromecu_mult) = 0.5; *(firmware->table_params[0]->y_fromecu_mult) = 0.01; *(firmware->table_params[0]->z_fromecu_mult) = 0.001953125; firmware->table_params[0]->y_source = g_strdup("LoadMain"); firmware->table_params[0]->z_source = g_strdup("VEMain"); firmware->table_params[0]->x_suffix = g_strdup("RPM"); firmware->table_params[0]->y_suffix = g_strdup("kPa"); firmware->table_params[0]->z_suffix = g_strdup("%"); firmware->table_params[0]->x_precision = 0; firmware->table_params[0]->y_precision = 1; firmware->table_params[0]->z_precision = 1; firmware->table_params[0]->table_name = g_strdup("FreeEMS very alpha fuel table");; /* Lambda Table */ firmware->table_params[1] = initialize_table_params(); firmware->table_params[1]->x_page = 6; firmware->table_params[1]->y_page = 6; /* Assumes location ID's from 0-6 are contiguous */ firmware->table_params[1]->z_page = 6; firmware->table_params[1]->x_bincount = 16; firmware->table_params[1]->y_bincount = 16; firmware->table_params[1]->x_base = 4; firmware->table_params[1]->y_base = 58; firmware->table_params[1]->z_base = 100; firmware->table_params[1]->x_size = MTX_U16; firmware->table_params[1]->y_size = MTX_U16; firmware->table_params[1]->z_size = MTX_U16; firmware->table_params[1]->x_fromecu_mult = g_new0(gfloat, 1); firmware->table_params[1]->y_fromecu_mult = g_new0(gfloat, 1); firmware->table_params[1]->z_fromecu_mult = g_new0(gfloat, 1); *(firmware->table_params[1]->x_fromecu_mult) = 0.5; *(firmware->table_params[1]->y_fromecu_mult) = 0.01; *(firmware->table_params[1]->z_fromecu_mult) = 0.000030518; firmware->table_params[1]->x_source = g_strdup("RPM"); firmware->table_params[1]->y_source = g_strdup("LoadMain"); firmware->table_params[1]->z_source = g_strdup("Lambda"); firmware->table_params[1]->x_suffix = g_strdup("RPM"); firmware->table_params[1]->y_suffix = g_strdup("kPa"); firmware->table_params[1]->z_suffix = g_strdup("Lambda"); firmware->table_params[1]->x_precision = 0; firmware->table_params[1]->y_precision = 1; firmware->table_params[1]->z_precision = 2; firmware->table_params[1]->table_name = g_strdup("FreeEMS very alpha lambda table");; firmware->table_params[2] = initialize_table_params(); firmware->table_params[2]->x_page = 8; firmware->table_params[2]->y_page = 8; /* Assumes location ID's from 0-8 are contiguous */ firmware->table_params[2]->z_page = 8; firmware->table_params[2]->x_bincount = 16; firmware->table_params[2]->y_bincount = 16; firmware->table_params[2]->x_base = 4; firmware->table_params[2]->y_base = 58; firmware->table_params[2]->z_base = 100; firmware->table_params[2]->x_size = MTX_U16; firmware->table_params[2]->y_size = MTX_U16; firmware->table_params[2]->z_size = MTX_U16; firmware->table_params[2]->x_fromecu_mult = g_new0(gfloat, 1); firmware->table_params[2]->y_fromecu_mult = g_new0(gfloat, 1); firmware->table_params[2]->z_fromecu_mult = g_new0(gfloat, 1); *(firmware->table_params[2]->x_fromecu_mult) = 0.5; *(firmware->table_params[2]->y_fromecu_mult) = 0.01; *(firmware->table_params[2]->z_fromecu_mult) = 0.000976563; firmware->table_params[2]->x_source = g_strdup("RPM"); firmware->table_params[2]->y_source = g_strdup("LoadMain"); firmware->table_params[2]->z_source = g_strdup("Degrees"); firmware->table_params[2]->x_suffix = g_strdup("RPM"); firmware->table_params[2]->y_suffix = g_strdup("kPa"); firmware->table_params[2]->z_suffix = g_strdup("\302\260BTDC"); firmware->table_params[2]->x_precision = 0; firmware->table_params[2]->y_precision = 1; firmware->table_params[2]->z_precision = 3; firmware->table_params[2]->table_name = g_strdup("FreeEMS very alpha spark table");; if (mem_alloc_f) mem_alloc_f(); else dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": load_firmware_details()\n\tFAILED TO LOCATE \"mem_alloc\" function within core/plugins\n")); /* Display firmware version in the window... */ dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": load_firmware_details()\n\tDetected Firmware: %s\n",firmware->name)); thread_update_logbar_f("interr_view","warning",g_strdup_printf(_("Detected Firmware: %s\n"),firmware->name),FALSE,FALSE); thread_update_logbar_f("interr_view","info",g_strdup_printf(_("Loading Settings from: \"%s\"\n"),firmware->profile_filename),FALSE,FALSE); cfg_free(cfgfile); return TRUE; }
void read_config(void) { ConfigFile *cfgfile; gchar *filename; int fd; gchar *temp_cmap = NULL; Color_map.filename = NULL; filename = g_strconcat(g_get_home_dir(), "/.eXtace/config", NULL); cfgfile = cfg_open_file(filename); if (cfgfile) { cfg_read_int(cfgfile, "Global", "major_ver", &major_ver); cfg_read_int(cfgfile, "Global", "minor_ver", &minor_ver); cfg_read_int(cfgfile, "Global", "micro_ver", µ_ver); if ((major_ver == 1) && (minor_ver == 8)) { printf("Config file structure changed. using defaults. \nClosing eXtace will save your NEW settings.\n"); cfg_free(cfgfile); unlink(filename); g_free(filename); return; } cfg_read_string(cfgfile, "Global", "last_colormap", &temp_cmap); if (temp_cmap != NULL) { fd = open(temp_cmap, O_RDONLY); if (fd > 0) { Color_map.filename = g_strdup(temp_cmap); close(fd); } else Color_map.filename = NULL; g_free(temp_cmap); } cfg_read_boolean(cfgfile, "Global", "landtilt", &landtilt); cfg_read_boolean(cfgfile, "Global", "spiketilt", &spiketilt); cfg_read_float(cfgfile, "Global", "low_freq", &low_freq); cfg_read_float(cfgfile, "Global", "high_freq", &high_freq); cfg_read_int(cfgfile, "Window", "width", &width); cfg_read_int(cfgfile, "Window", "height", &height); cfg_read_int(cfgfile, "Window", "main_x_origin", &main_x_origin); cfg_read_int(cfgfile, "Window", "main_y_origin", &main_y_origin); cfg_read_int(cfgfile, "Window", "grad_x_origin", &grad_x_origin); cfg_read_int(cfgfile, "Window", "grad_y_origin", &grad_y_origin); cfg_read_int(cfgfile, "Window", "dir_x_origin", &dir_x_origin); cfg_read_int(cfgfile, "Window", "dir_y_origin", &dir_y_origin); cfg_read_int(cfgfile, "Global", "mode", &mode); { int i; if(cfg_read_int(cfgfile, "Global", "data_source", &i)) data_source=i; } cfg_read_int(cfgfile, "Global", "decimation_factor", &decimation_factor); cfg_read_int(cfgfile, "Global", "fft_signal_source", &fft_signal_source); cfg_read_float(cfgfile, "Global", "scope_zoom", &scope_zoom); cfg_read_int(cfgfile, "Global", "refresh_rate", &refresh_rate); cfg_read_int(cfgfile, "Global", "landflip", &landflip); cfg_read_int(cfgfile, "Global", "spikeflip", &spikeflip); cfg_read_boolean(cfgfile, "Global", "outlined", &outlined); cfg_read_int(cfgfile, "Global", "sub_mode_3D", &sub_mode_3D); cfg_read_int(cfgfile, "Global", "scope_sub_mode", &scope_sub_mode); cfg_read_boolean(cfgfile, "Global", "dir_win_present", &dir_win_present); cfg_read_int(cfgfile, "Global", "nsamp", &nsamp); cfg_read_int(cfgfile, "Global", "window_func", &window_func); cfg_read_int(cfgfile, "Global", "win_width", &win_width); cfg_read_int(cfgfile, "Global", "axis_type", &axis_type); cfg_read_int(cfgfile, "Global", "bands", &bands); cfg_read_int(cfgfile, "Global", "lag", &lag); cfg_read_float(cfgfile, "Global", "noise_floor", &noise_floor); cfg_read_int(cfgfile, "Global", "seg_height", &seg_height); cfg_read_int(cfgfile, "Global", "seg_space", &seg_space); cfg_read_boolean(cfgfile, "Global", "bar_decay", &bar_decay); cfg_read_boolean(cfgfile, "Global", "peak_decay", &peak_decay); cfg_read_int(cfgfile, "Global", "decay_speed", &bar_decay_speed); cfg_read_boolean(cfgfile, "Global", "stabilized", &stabilized); cfg_read_boolean(cfgfile, "Global", "show_graticule", &show_graticule); cfg_read_int(cfgfile, "Global", "peak_decay_speed", &peak_decay_speed); cfg_read_int(cfgfile, "Global", "peak_hold_time", &peak_hold_time); cfg_read_int(cfgfile, "Global", "tape_scroll", &tape_scroll); cfg_read_int(cfgfile, "Global", "xdet_scroll", &xdet_scroll); cfg_read_int(cfgfile, "Global", "zdet_scroll", &zdet_scroll); cfg_read_float(cfgfile, "Global", "xdet_start", &xdet_start); cfg_read_float(cfgfile, "Global", "xdet_end", &xdet_end); cfg_read_float(cfgfile, "Global", "ydet_start", &ydet_start); cfg_read_float(cfgfile, "Global", "ydet_end", &ydet_end); cfg_read_float(cfgfile, "Global", "x3d_start", &x3d_start); cfg_read_float(cfgfile, "Global", "x3d_end", &x3d_end); cfg_read_float(cfgfile, "Global", "y3d_start", &y3d_start); cfg_read_float(cfgfile, "Global", "y3d_end", &y3d_end); cfg_read_float(cfgfile, "Global", "multiplier", &multiplier); cfg_read_int(cfgfile, "Global", "x3d_scroll", &x3d_scroll); cfg_read_int(cfgfile, "Global", "z3d_scroll", &z3d_scroll); cfg_read_boolean(cfgfile, "Global", "show_leader", &show_leader); cfg_read_int(cfgfile, "Global", "scope_sync_source", &scope_sync_source); cfg_read_int(cfgfile, "Global", "horiz_spec_start", &horiz_spec_start); cfg_read_int(cfgfile, "Global", "vert_spec_start", &vert_spec_start); if (horiz_spec_start > width) horiz_spec_start = width-10; if (vert_spec_start > height) vert_spec_start = height-10; if (horiz_spec_start < 60) horiz_spec_start = 60; if (vert_spec_start < 120) vert_spec_start = 120; cfg_free(cfgfile); } else printf("Config file not found, using defaults\n"); g_free(filename); }
/*! \brief personality_choice() is called from a one shot timeout from main in order to open the window to ask the user what ECU family to deal with running. */ G_MODULE_EXPORT gboolean personality_choice(void) { GtkWidget *dialog = NULL; GtkWidget *vbox = NULL; GtkWidget *hbox = NULL; GtkWidget *ebox = NULL; GtkWidget *sep = NULL; GtkWidget *button = NULL; GtkWidget *label = NULL; gchar ** dirs = NULL; gchar * filename = NULL; PersonaElement *element = NULL; gchar *tmpbuf = NULL; gboolean shouldjump = FALSE; gchar *name = NULL; GArray *classes = NULL; GSList *group = NULL; GList *p_list = NULL; GList *s_list = NULL; ConfigFile *cfgfile = NULL; guint i = 0; gint result = 0; gchar * pathstub = NULL; extern gconstpointer *global_data; pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",NULL); dirs = get_dirs((const gchar *)DATA_GET(global_data,"project_name"),pathstub,&classes); if (!dirs) { MTXDBG(CRITICAL,_("NO Interrogation profiles found, was MegaTunix installed properly?\n")); return FALSE; } i = 0; while (dirs[i]) { tmpbuf = g_build_filename(dirs[i],"details.cfg",NULL); cfgfile = cfg_open_file(tmpbuf); if (!cfgfile) { /*MTXDBG(CRITICAL,_("\"%s\" file missing!, was MegaTunix installed properly?\n"),tmpbuf);*/ i++; g_free(tmpbuf); continue; } g_free(tmpbuf); element = g_new0(PersonaElement, 1); cfg_read_string(cfgfile,"Family","sequence",&element->sequence); cfg_read_string(cfgfile,"Family","friendly_name",&element->name); cfg_read_string(cfgfile,"Family","persona",&element->persona); cfg_read_string(cfgfile,"Family","ecu_lib",&element->ecu_lib); cfg_read_string(cfgfile,"Family","common_lib",&element->common_lib); if (!cfg_read_string(cfgfile,"Family","baud",&element->baud_str)) MTXDBG(CRITICAL,_("\"details.cfg\" baud string undefined!, was MegaTunix installed properly?\n")); element->dirname = g_strdup(dirs[i]); element->filename = g_path_get_basename(dirs[i]); if (g_strcasecmp(element->filename,(gchar *)DATA_GET(global_data,"last_ecu_family")) == 0) element->def = TRUE; if ((DATA_GET(global_data,"cli_persona")) && (element->persona)) { if (g_strcasecmp(element->persona, (gchar *)DATA_GET(global_data,"cli_persona")) == 0) { button = gtk_toggle_button_new(); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE); persona_selection(button,(gpointer)element); g_object_ref_sink(button); g_object_unref(button); shouldjump = TRUE; } } if (g_array_index(classes,FileClass,i) == PERSONAL) p_list = g_list_prepend(p_list,(gpointer)element); if (g_array_index(classes,FileClass,i) == SYSTEM) s_list = g_list_prepend(s_list,(gpointer)element); g_free(name); i++; cfg_free(cfgfile); } p_list = g_list_sort(p_list,persona_seq_sort); s_list = g_list_sort(s_list,persona_seq_sort); g_strfreev(dirs); g_array_free(classes,TRUE); if (shouldjump) { g_list_foreach(p_list,free_persona_element,NULL); g_list_foreach(s_list,free_persona_element,NULL); g_list_free(p_list); g_list_free(s_list); DATA_SET(global_data,"cli_persona",NULL); if (DATA_GET(global_data,"offline")) goto jumpahead_offline; else goto jumpahead; } set_title(g_strdup(_("Choose an ECU family?"))); update_logbar("interr_view","warning",_("Prompting user for ECU family to interrogate...\n"),FALSE,FALSE,FALSE); dialog = gtk_dialog_new_with_buttons("Select ECU Personality", GTK_WINDOW(lookup_widget("main_window")), GTK_DIALOG_DESTROY_WITH_PARENT, "Exit MegaTunix", GTK_RESPONSE_CLOSE, "Go Offline", GTK_RESPONSE_CANCEL, "Find my ECU", GTK_RESPONSE_OK, NULL); vbox = gtk_vbox_new(TRUE,2); gtk_container_set_border_width(GTK_CONTAINER(vbox),5); //gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),vbox,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),vbox,TRUE,TRUE,0); if (g_list_length(p_list) > 0) { label = gtk_label_new("Custom (personal) Profiles"); gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0); group = NULL; /* Cycle list for PERSONAL profile files */ for (i=0;i<g_list_length(p_list);i++) { element = (PersonaElement *)g_list_nth_data(p_list,i); ebox = gtk_event_box_new(); gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0); hbox = gtk_hbox_new(FALSE,10); gtk_container_add(GTK_CONTAINER(ebox),hbox); label = gtk_label_new(element->name); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0); if (!check_for_files (element->dirname,"prof")) { gtk_widget_set_sensitive(ebox,FALSE); button = gtk_radio_button_new(NULL); } else { button = gtk_radio_button_new(group); group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)); } g_signal_connect(button, "toggled", G_CALLBACK(persona_selection), element); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0); if (element->def) { gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE); gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(button)); } } sep = gtk_hseparator_new(); gtk_box_pack_start(GTK_BOX(vbox),sep,TRUE,TRUE,0); } label = gtk_label_new("System Wide ECU Profiles"); gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0); /* Cycle list for System interogation files */ for (i=0;i<g_list_length(s_list);i++) { element = (PersonaElement *)g_list_nth_data(s_list,i); ebox = gtk_event_box_new(); gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0); hbox = gtk_hbox_new(FALSE,10); gtk_container_add(GTK_CONTAINER(ebox),hbox); label = gtk_label_new(element->name); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0); if (!check_for_files (element->dirname,"prof")) { gtk_widget_set_sensitive(ebox,FALSE); button = gtk_radio_button_new(NULL); } else { button = gtk_radio_button_new(group); group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)); } g_signal_connect(button, "toggled", G_CALLBACK(persona_selection), element); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0); if (element->def) { gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE); gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(button)); } } gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_list_foreach(p_list,free_persona_element,NULL); g_list_foreach(s_list,free_persona_element,NULL); g_list_free(p_list); g_list_free(s_list); switch (result) { case GTK_RESPONSE_CLOSE: leave(NULL,NULL); break; case GTK_RESPONSE_ACCEPT: case GTK_RESPONSE_OK: /* Normal mode */ jumpahead: plugins_init(); pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),"comm.xml",NULL); filename = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,NULL); g_free(pathstub); load_comm_xml(filename); g_free(filename); io_cmd("interrogation",NULL); break; default: /* Offline */ jumpahead_offline: plugins_init(); pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),"comm.xml",NULL); filename = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,NULL); g_free(pathstub); load_comm_xml(filename); g_free(filename); g_timeout_add(100,(GSourceFunc)set_offline_mode,NULL); return FALSE; } return FALSE; }
void load_rtvars(gchar **files, struct Rtv_Data *rtv_data) { GtkTreeIter iter; ConfigFile *cfgfile; gint total = 0; gpointer orig = NULL; gpointer value = NULL; gchar * tmpbuf = NULL; gchar * section = NULL; gchar ** vector = NULL; gchar *dlog_name = NULL; gchar *int_name = NULL; gchar *element = NULL; gint icount = 0; gint len = 0; gint tmpi = 0; gint i = 0; gint j = 0; guint k = 0; while (files[i]) { cfgfile = cfg_open_file(files[i]); if (cfgfile) { cfg_read_int(cfgfile,"realtime_map", "derived_total",&total); for (j=0;j<total;j++) { section = g_strdup_printf("derived_%i",j); cfg_read_string(cfgfile,section,"dlog_gui_name",&dlog_name); if(cfg_read_string(cfgfile,section,"internal_names",&tmpbuf)) { vector = g_strsplit(tmpbuf,",",-1); g_free(tmpbuf); for (k=0;k<g_strv_length(vector);k++) { if (g_hash_table_lookup_extended(rtv_data->rtv_hash,vector[k],&orig,&value)) { tmpi = (GINT)value + 1; /*printf("Value on pre-existing var %s is %i\n",(gchar *)orig,(gint)value);*/ g_hash_table_replace(rtv_data->rtv_hash,g_strdup(vector[k]),GINT_TO_POINTER(tmpi)); } else { /*printf("inserting var %s with value %i\n",int_name,1);*/ g_hash_table_insert(rtv_data->rtv_hash,g_strdup(vector[k]),GINT_TO_POINTER(1)); g_hash_table_insert(rtv_data->int_ext_hash,g_strdup(dlog_name),g_strdup(vector[k])); rtv_data->rtv_list = g_list_prepend(rtv_data->rtv_list,g_strdup(dlog_name)); } } g_strfreev(vector); } g_free(section); g_free(dlog_name); g_free(int_name); } } cfg_free(cfgfile); i++; } rtv_data->rtv_list = g_list_sort(rtv_data->rtv_list,sort); store = gtk_list_store_new(NUM_COLS,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING); len = g_list_length(rtv_data->rtv_list); /*printf("list length is %i\n",len);*/ for (i=0;i<len;i++) { element = g_list_nth_data(rtv_data->rtv_list,i); /*printf("element %s\n",element);*/ int_name = g_hash_table_lookup(rtv_data->int_ext_hash,element); icount = (GINT)g_hash_table_lookup(rtv_data->rtv_hash,int_name); /*printf("int name %s\n",int_name);*/ gtk_list_store_append(store,&iter); /*printf("var %s, %s, icount %i, total %i\n",element,int_name,icount,rtv_data->total_files);*/ if (icount == rtv_data->total_files) gtk_list_store_set(store,&iter,VARNAME_COL,g_strdup(element),TYPE_COL," (common)",DATASOURCE_COL,g_strdup(int_name),-1); else gtk_list_store_set(store,&iter,VARNAME_COL,g_strdup(element),TYPE_COL," (FW Specific)", DATASOURCE_COL,g_strdup(int_name),-1); } }
//G_MODULE_EXPORT gboolean lookuptable_changed(GtkCellRendererCombo *renderer, gchar *path, gchar * new_text, gpointer data) G_MODULE_EXPORT gboolean lookuptable_changed(GtkCellRendererCombo *renderer, gchar *path, GtkTreeIter *new_iter, gpointer data) { GtkTreeModel *combostore = NULL; GtkTreeIter iter; GtkTreeModel *model = (GtkTreeModel *)data; ConfigFile *cfgfile = NULL; gchar * new_text = NULL; gchar * int_name = NULL; gchar * old = NULL; gchar * new_name = NULL; gchar ** vector = NULL; const gchar * project = NULL; gboolean restart_tickler = FALSE; GAsyncQueue *io_data_queue = NULL; Firmware_Details *firmware = NULL; ENTER(); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); io_data_queue = (GAsyncQueue *)DATA_GET(global_data,"io_data_queue"); /* Get combo box model so we can set the combo to this new value */ g_object_get(G_OBJECT(renderer),"model",&combostore,NULL); gtk_tree_model_get(combostore,new_iter,0,&new_text,-1); /* Get combo box model so we can set the combo to this new value */ gtk_tree_model_get_iter_from_string(model,&iter,path); gtk_tree_model_get(model,&iter,INTERNAL_NAME_COL,&int_name,FILENAME_COL,&old,-1); //printf("New text is %s, int name associated %s, filename %s\n",new_text,int_name,old); if (g_ascii_strcasecmp(old,new_text) == 0) /* If no change, return */ { g_free(int_name); g_free(old); EXIT(); return TRUE; } if (g_ascii_strcasecmp(new_text,"Personal") == 0) { g_free(int_name); g_free(old); EXIT(); return TRUE; } if (g_ascii_strcasecmp(new_text,"System") == 0) { g_free(int_name); g_free(old); EXIT(); return TRUE; } if (DATA_GET(global_data,"realtime_id")) { gint count = 0; restart_tickler = TRUE; stop_tickler(RTV_TICKLER); while ((g_async_queue_length(io_data_queue) > 0) && (count < 30)) { MTXDBG(CRITICAL,_("Draining I/O Queue, current length %i\n"),g_async_queue_length(io_data_queue)); count++; } } get_table(int_name,new_text,NULL); /* Load the new one in it's place */ gtk_list_store_set(GTK_LIST_STORE(model),&iter, FILENAME_COL, new_text,-1); if (restart_tickler) start_tickler(RTV_TICKLER); cfgfile = cfg_open_file(firmware->profile_filename); if (!cfgfile) { g_free(int_name); g_free(old); EXIT(); return FALSE; } g_hash_table_foreach((GHashTable *)DATA_GET(global_data,"lookuptables"),update_lt_config,cfgfile); if (g_strrstr(firmware->profile_filename,"mtx")) cfg_write_file(cfgfile, firmware->profile_filename); else { project = (const gchar *)DATA_GET(global_data,"project_name"); vector = g_strsplit(firmware->profile_filename,PSEP,-1); if (!project) project = DEFAULT_PROJECT; new_name = g_build_filename(HOME(),"mtx",project,INTERROGATOR_DATA_DIR,"Profiles",vector[g_strv_length(vector)-2],vector[g_strv_length(vector)-1],NULL); g_strfreev(vector); cfg_write_file(cfgfile, new_name); g_free(firmware->profile_filename); firmware->profile_filename=g_strdup(new_name); g_free(new_name); } cfg_free(cfgfile); /*printf("internal name %s, old table %s, new table %s\n",int_name,old,new_text);*/ g_free(int_name); g_free(old); EXIT(); return TRUE; }
void cfg_open(void) { char path[300]; if (cfg_locate_cfg_file(path, sizeof(path))) return; cfg_open_file(path); }
/*! \brief load_gui_tabs_pf() is called after interrogation completes successfully. It's purpose is to load all the glade files and datamaps as specified in the interrogation profile of the detected firmware. */ G_MODULE_EXPORT gboolean load_gui_tabs_pf(void) { gint i = 0; gint cur = 0; ConfigFile *cfgfile = NULL; gchar * map_file = NULL; gchar * glade_file = NULL; gchar * tmpbuf = NULL; gchar * tab_name = NULL; gchar * tab_ident = NULL; gboolean tmpi = FALSE; GtkWidget *label = NULL; GtkWidget *container = NULL; GtkWidget *child = NULL; GtkWidget *notebook = NULL; GtkWidget *item = NULL; TabInfo *tabinfo = NULL; GPtrArray *tabinfos = NULL; extern GdkColor red; gboolean * hidden_list = NULL; Firmware_Details *firmware = NULL; CmdLineArgs *args = NULL; gchar * pathstub = NULL; ENTER(); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); args = (CmdLineArgs *)DATA_GET(global_data,"args"); if (DATA_GET(global_data,"tabs_loaded")) { EXIT(); return FALSE; } if (!firmware) { EXIT(); return FALSE; } if (!firmware->tab_list) { EXIT(); return FALSE; } if (!firmware->tab_confs) { EXIT(); return FALSE; } if (args->inhibit_tabs) { EXIT(); return FALSE; } set_title(g_strdup(_("Loading Gui Tabs..."))); notebook = lookup_widget("toplevel_notebook"); hidden_list = (gboolean *)DATA_GET(global_data,"hidden_list"); tabinfos = g_ptr_array_new(); while (firmware->tab_list[i]) { pathstub = g_build_filename(GUI_DATA_DIR,firmware->tab_list[i],NULL); glade_file = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"glade"); g_free(pathstub); pathstub = g_build_filename(GUI_DATA_DIR,firmware->tab_confs[i],NULL); map_file = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"datamap"); g_free(pathstub); if (!g_file_test(glade_file,G_FILE_TEST_EXISTS)) { MTXDBG(TABLOADER|CRITICAL,_("GLADE FILE: \"%s.glade\" NOT FOUND\n"),firmware->tab_list[i]); update_logbar("interr_view","warning",g_strdup(_("Glade File: ")),FALSE,FALSE,TRUE); update_logbar("interr_view","info",g_strdup_printf("\"%s.glade\"",firmware->tab_list[i]),FALSE,FALSE,TRUE); update_logbar("interr_view","warning",g_strdup(_(" is MISSING!\n")),FALSE,FALSE,TRUE); i++; continue; } if (!g_file_test(map_file,G_FILE_TEST_EXISTS)) { MTXDBG(TABLOADER|CRITICAL,_("DATAMAP: \"%s.datamap\" NOT FOUND\n"),firmware->tab_confs[i]); update_logbar("interr_view","warning",g_strdup(_("Datamap File: ")),FALSE,FALSE,TRUE); update_logbar("interr_view","info",g_strdup_printf("\"%s.datamap\"",firmware->tab_confs[i]),FALSE,FALSE,TRUE); update_logbar("interr_view","warning",g_strdup(_(" is MISSING!\n")),FALSE,FALSE,TRUE); i++; continue; } cfgfile = cfg_open_file(map_file); if (cfgfile) { tabinfo = g_new0(TabInfo, 1); tabinfo->glade_file = g_strdup(glade_file); tabinfo->datamap_file = g_strdup(map_file); cfg_read_string(cfgfile,"global","tab_name",&tab_name); label = gtk_label_new(NULL); tabinfo->tab_label = label; gtk_label_set_markup_with_mnemonic(GTK_LABEL(label),tab_name); if (cfg_read_boolean(cfgfile,"global","ellipsize",&tmpi)) { if (tmpi) { OBJ_SET(label,"ellipsize_preferred",GINT_TO_POINTER(TRUE)); if (DATA_GET(global_data,"ellipsize_tabs")) gtk_label_set_ellipsize(GTK_LABEL(label),PANGO_ELLIPSIZE_END); } } if (cfg_read_string(cfgfile,"global","bind_to_list",&tmpbuf)) { OBJ_SET_FULL(label,"bind_to_list",g_strdup(tmpbuf),g_free); bind_to_lists(label,tmpbuf); g_free(tmpbuf); if (cfg_read_string(cfgfile,"global","match_type",&tmpbuf)) { tmpi = translate_string(tmpbuf); g_free(tmpbuf); OBJ_SET(label,"match_type",GINT_TO_POINTER(tmpi)); } } gtk_misc_set_alignment(GTK_MISC(label),0,0.5); container = gtk_vbox_new(1,0); if (cfg_read_string(cfgfile,"topframe","tab_ident",&tab_ident)) { tmpi = translate_string(tab_ident); g_free(tab_ident); OBJ_SET(container,"tab_ident",GINT_TO_POINTER(tmpi)); } g_free(tab_name); OBJ_SET_FULL(label,"glade_file",g_strdup(glade_file),cleanup); OBJ_SET_FULL(label,"datamap_file",g_strdup(map_file),cleanup); OBJ_SET(label,"not_rendered",GINT_TO_POINTER(TRUE)); gtk_notebook_append_page(GTK_NOTEBOOK(notebook),container,label); gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(notebook),container,TRUE); gtk_widget_show(container); cur = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook))-1; tabinfo->page_num = cur; tabinfo->notebook = GTK_NOTEBOOK(notebook); if (hidden_list[cur] == TRUE) { child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),cur); label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook),child); gtk_widget_hide(child); gtk_widget_hide(label); item = lookup_widget("show_tab_visibility_menuitem"); gtk_widget_modify_text(gtk_bin_get_child(GTK_BIN(item)),GTK_STATE_NORMAL,&red); } g_ptr_array_add(tabinfos,(gpointer)tabinfo); } cfg_free(cfgfile); g_free(map_file); g_free(glade_file); i++; if (!firmware) break; } preload_deps(tabinfos); DATA_SET_FULL(global_data,"tabinfos",tabinfos,dealloc_tabinfos); DATA_SET(global_data,"tabs_loaded",GINT_TO_POINTER(TRUE)); MTXDBG(TABLOADER,_("All is well, leaving...\n\n")); set_title(g_strdup(_("Gui Tabs Loaded..."))); gdk_flush(); EXIT(); return TRUE; }
/*! \brief load_gui_tabs_pf() is called after interrogation completes successfully. It's purpose is to load all the glade files and datamaps as specified in the interrogation profile of the detected firmware. \param notebook is the pointer to the notebook the new tab should be placed \param page is the page number to load \returns TRUE on success, FALSE on failure */ G_MODULE_EXPORT gboolean load_actual_tab(GtkNotebook *notebook, gint page) { ConfigFile *cfgfile = NULL; gchar * map_file = NULL; gchar * glade_file = NULL; gchar * tmpbuf = NULL; GladeXML *xml = NULL; GtkWidget *label = NULL; GtkWidget *topframe = NULL; GtkWidget *placeholder = NULL; GHashTable *groups = NULL; GList *tab_widgets = NULL; BindGroup *bindgroup = NULL; extern GdkColor red; ENTER(); placeholder = gtk_notebook_get_nth_page(notebook,page); label = gtk_notebook_get_tab_label(notebook,placeholder); glade_file = (gchar *)OBJ_GET(label,"glade_file"); map_file = (gchar *)OBJ_GET(label,"datamap_file"); xml = glade_xml_new(glade_file,"topframe",NULL); g_return_val_if_fail(xml,FALSE); thread_update_logbar("interr_view",NULL,g_strdup(_("Load of tab: ")),FALSE,FALSE); thread_update_logbar("interr_view","info", g_strdup_printf("\"%s\"",glade_file),FALSE,FALSE); thread_update_logbar("interr_view",NULL,g_strdup(_(" completed.\n")),FALSE,FALSE); thread_update_logbar("interr_view",NULL,g_strdup(_("Load of tabconf: ")),FALSE,FALSE); thread_update_logbar("interr_view","info", g_strdup_printf("\"%s\"",map_file),FALSE,FALSE); cfgfile = cfg_open_file(map_file); if (cfgfile) { topframe = glade_xml_get_widget(xml,"topframe"); if (topframe == NULL) { MTXDBG(TABLOADER|CRITICAL,_("\"topframe\" not found in xml, ABORTING!!\n")); set_title(g_strdup(_("ERROR Gui Tab XML problem, \"topframe\" element not found!!!"))); EXIT(); return FALSE; } OBJ_SET_FULL(topframe,"glade_xml",(gpointer)xml,g_object_unref); // bind_data() is recursive and will take // care of all children bindgroup = g_new0(BindGroup,1); groups = load_groups(cfgfile); bindgroup->cfgfile = cfgfile; bindgroup->groups = groups; bindgroup->map_file = g_strdup(map_file); /* tab_widgets = g_list_prepend(tab_widgets,topframe); OBJ_SET(topframe,"tab_widgets",tab_widgets); */ bindgroup->topframe = topframe; bind_data(topframe,(gpointer)bindgroup); g_free(bindgroup->map_file); if (groups) g_hash_table_destroy(groups); groups = NULL; /* Clear not_rendered flag */ OBJ_SET(label,"not_rendered",NULL); populate_master(topframe,(gpointer)cfgfile); gtk_box_pack_start(GTK_BOX(placeholder),topframe,TRUE,TRUE,0); OBJ_SET(placeholder,"topframe",topframe); glade_xml_signal_autoconnect(xml); g_free(bindgroup); if (cfg_read_string(cfgfile,"global","post_functions",&tmpbuf)) { run_post_functions(tmpbuf); g_free(tmpbuf); } cfg_free(cfgfile); gtk_widget_show(topframe); /*printf("Current length of tab_widgets is %i\n",g_list_length(OBJ_GET(topframe,"tab_widgets")));*/ thread_update_logbar("interr_view",NULL,g_strdup(_(" completed.\n")),FALSE,FALSE); } update_groups_pf(); update_sources_pf(); /* Allow gui to update as it should.... */ gdk_flush(); EXIT(); return TRUE; }
/*! \brief validate_and_load_tests() loads the list of tests from the system checks them for validity, populates and array and returns it command tested against the ECU arestored \returns a dynamic GArray for commands */ G_MODULE_EXPORT gboolean validate_and_load_tests(GArray **tests, GHashTable **tests_hash) { ConfigFile *cfgfile; Detection_Test *test = NULL; gchar * filename = NULL; gchar *section = NULL; gchar * tmpbuf = NULL; gchar ** vector = NULL; gint total_tests = 0; gint result = 0; gint major = 0; gint minor = 0; gint i = 0; gint j = 0; filename = get_file(g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),"tests.cfg",NULL),NULL); if (!filename) { update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile tests file %s not found!\n"),filename),FALSE,FALSE,TRUE); return FALSE; } cfgfile = cfg_open_file(filename); if (!cfgfile) return FALSE; get_file_api_f(cfgfile,&major,&minor); if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API)) { update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile tests API mismatch (%i.%i != %i.%i):\n\tFile %s.\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,filename),FALSE,FALSE,TRUE); return FALSE; } *tests_hash = g_hash_table_new_full(g_str_hash,g_str_equal,NULL,test_cleanup); dbg_func_f(INTERROGATOR,g_strdup_printf(__FILE__": validate_and_load_tests()\n\tfile %s, opened successfully\n",filename)); *tests = g_array_new(FALSE,TRUE,sizeof(Detection_Test *)); cfg_read_int(cfgfile,"interrogation_tests","total_tests",&total_tests); for (i=0;i<total_tests;i++) { test = g_new0(Detection_Test, 1); section = g_strdup_printf("test_%.2i",i); if (!cfg_read_string(cfgfile,section,"test_name",&test->test_name)) { dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": validate_and_load_tests(),\n\ttest_name for %s is NULL\n",section)); g_free(section); break; } if (!cfg_read_string(cfgfile,section,"test_result_type",&tmpbuf)) { dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": validate_and_load_tests(),\n\ttest_result_type for %s is NULL\n",section)); g_free(section); break; } else { test->result_type=translate_string_f(tmpbuf); g_free(tmpbuf); } if (!cfg_read_string(cfgfile,section,"test_func",&test->test_func)) { dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": validate_and_load_tests(),\n\ttest_function for %s is NULL\n",section)); g_free(section); break; } get_symbol_f(test->test_func,(void *)&test->function); cfg_read_string(cfgfile,section,"test_desc", &test->test_desc); g_free(section); g_array_append_val(*tests,test); g_hash_table_insert(*tests_hash,test->test_name,test); } cfg_free(cfgfile); g_free(filename); return TRUE; }
/*! \brief check_for_match() compares the resutls of the interrogation with the ECU to the canidates in turn. When a match occurs TRUE is returned otherwise it returns FALSE \param cmd_array (GArray *) array of commands \param potential (Canidate *) potential \param canidate (Canidate *) Canidate \returns TRUE on match, FALSE on failure */ G_MODULE_EXPORT gboolean check_for_match(GHashTable *tests_hash, gchar *filename) { ConfigFile *cfgfile = NULL; Detection_Test *test = NULL; guint i = 0; gint len = 0; gboolean pass = FALSE; gchar * tmpbuf = NULL; gchar ** vector = NULL; gchar ** match_on = NULL; gint major = 0; gint minor = 0; MatchClass class = 0; cfgfile = cfg_open_file(filename); if (!cfgfile) return FALSE; get_file_api_f(cfgfile,&major,&minor); if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API)) { update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile API mismatch (%i.%i != %i.%i):\n\tFile %s will be skipped\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,filename),FALSE,FALSE,TRUE); cfg_free(cfgfile); return FALSE; } if (cfg_read_string(cfgfile,"interrogation","match_on",&tmpbuf) == FALSE) printf(_("ERROR:!! \"match_on\" key missing from interrogation profile [interrogation] section\n")); match_on = g_strsplit(tmpbuf,",",-1); g_free(tmpbuf); for (i=0;i<g_strv_length(match_on);i++) { pass = FALSE; /*printf("checking for match on %s\n",match_on[i]);*/ test = g_hash_table_lookup(tests_hash,match_on[i]); if (!test) { printf(_("ERROR test data not found for test \"%s\"\n"),match_on[i]); continue; } /* If the test_name is NOT IN the interrogation profile, we * abort as it's NOT match */ if (!cfg_read_string(cfgfile,"interrogation",test->test_name,&tmpbuf)) { dbg_func_f(INTERROGATOR,g_strdup_printf("\n"__FILE__": check_for_match()\n\tMISMATCH,\"%s\" is NOT a match...\n\n",filename)); cfg_free(cfgfile); g_strfreev(match_on); return FALSE; } vector = g_strsplit(tmpbuf,",",-1); g_free(tmpbuf); /* Possible choices are "Count", "submatch" and "fullmatch", so * stringparse to get them into a consistent form */ if (g_strv_length(vector) != 2) printf(_("ERROR interrogation check_for match vector does NOT have two args it has %i\n"),g_strv_length(vector)); class = translate_string_f(vector[0]); /*printf("potential data is %s\n",vector[1]);*/ switch (class) { case COUNT: if (test->num_bytes == atoi(vector[1])) pass=TRUE; break; case NUMMATCH: if ((GINT)(test->result_str[0]) == atoi(vector[1])) pass=TRUE; break; case SUBMATCH: if (strstr(test->result_str,vector[1]) != NULL) pass=TRUE; break; case FULLMATCH: if (g_ascii_strcasecmp(test->result_str,vector[1]) == 0) pass=TRUE; break; case REGEX: if (regex(vector[1],test->result_str,&len)) pass=TRUE; break; default: pass=FALSE; } g_strfreev(vector); if (pass == TRUE) continue; else { dbg_func_f(INTERROGATOR,g_strdup_printf("\n"__FILE__": check_for_match()\n\tMISMATCH,\"%s\" is NOT a match...\n\n",filename)); g_strfreev(match_on); cfg_free(cfgfile); return FALSE; } } g_strfreev(match_on); dbg_func_f(INTERROGATOR,g_strdup_printf("\n"__FILE__": check_for_match()\n\t\"%s\" is a match for all conditions ...\n\n",filename)); cfg_free(cfgfile); return TRUE; }
void save_config(GtkWidget *widget) { gchar *filename; ConfigFile *cfgfile; gint x; gint y; filename = g_strconcat(g_get_home_dir(), "/.eXtace/config", NULL); cfgfile = cfg_open_file(filename); if (!cfgfile) cfgfile = cfg_new(); cfg_write_int(cfgfile, "Global", "major_ver", _MAJOR_); cfg_write_int(cfgfile, "Global", "minor_ver", _MINOR_); cfg_write_int(cfgfile, "Global", "micro_ver", _MICRO_); if (Color_map.filename) cfg_write_string(cfgfile, "Global", "last_colormap", Color_map.filename); else cfg_write_string(cfgfile, "Global", "last_colormap",g_strconcat(g_get_home_dir(),"/.eXtace/ColorMaps/","Default",NULL)); cfg_write_int(cfgfile, "Global", "mode", mode); cfg_write_int(cfgfile, "Global", "data_source", data_source); cfg_write_int(cfgfile, "Global", "decimation_factor", decimation_factor); cfg_write_int(cfgfile, "Global", "fft_signal_source", fft_signal_source); cfg_write_float(cfgfile, "Global", "scope_zoom", scope_zoom); cfg_write_int(cfgfile, "Global", "refresh_rate", refresh_rate); cfg_write_int(cfgfile, "Global", "landflip", landflip); cfg_write_int(cfgfile, "Global", "spikeflip", spikeflip); cfg_write_boolean(cfgfile, "Global", "outlined", outlined); cfg_write_int(cfgfile, "Global", "sub_mode_3D", sub_mode_3D); cfg_write_int(cfgfile, "Global", "scope_sub_mode", scope_sub_mode); cfg_write_boolean(cfgfile, "Global", "dir_win_present", dir_win_present); cfg_write_int(cfgfile, "Global", "nsamp", nsamp); cfg_write_int(cfgfile, "Global", "window_func", window_func); cfg_write_int(cfgfile, "Global", "win_width", win_width); cfg_write_int(cfgfile, "Global", "axis_type", axis_type); cfg_write_int(cfgfile, "Global", "bands", bands); cfg_write_int(cfgfile, "Global", "lag", lag); cfg_write_float(cfgfile, "Global", "noise_floor", noise_floor); cfg_write_int(cfgfile, "Global", "seg_height", seg_height); cfg_write_int(cfgfile, "Global", "seg_space", seg_space); cfg_write_boolean(cfgfile, "Global", "bar_decay", bar_decay); cfg_write_boolean(cfgfile, "Global", "peak_decay", peak_decay); cfg_write_boolean(cfgfile, "Global", "stabilized", stabilized); cfg_write_boolean(cfgfile, "Global", "show_graticule", show_graticule); cfg_write_int(cfgfile, "Global", "decay_speed", bar_decay_speed); cfg_write_int(cfgfile, "Global", "peak_decay_speed", peak_decay_speed); cfg_write_int(cfgfile, "Global", "peak_hold_time", peak_hold_time); cfg_write_int(cfgfile, "Global", "tape_scroll", tape_scroll); cfg_write_int(cfgfile, "Global", "xdet_scroll", xdet_scroll); cfg_write_int(cfgfile, "Global", "zdet_scroll", zdet_scroll); cfg_write_float(cfgfile, "Global", "xdet_start", xdet_start); cfg_write_float(cfgfile, "Global", "xdet_end", xdet_end); cfg_write_float(cfgfile, "Global", "ydet_start", ydet_start); cfg_write_float(cfgfile, "Global", "ydet_end", ydet_end); cfg_write_float(cfgfile, "Global", "x3d_start", x3d_start); cfg_write_float(cfgfile, "Global", "x3d_end", x3d_end); cfg_write_float(cfgfile, "Global", "y3d_start", y3d_start); cfg_write_float(cfgfile, "Global", "y3d_end", y3d_end); cfg_write_float(cfgfile, "Global", "multiplier", multiplier); cfg_write_int(cfgfile, "Global", "horiz_spec_start", horiz_spec_start); cfg_write_int(cfgfile, "Global", "vert_spec_start", vert_spec_start); cfg_write_int(cfgfile, "Global", "x3d_scroll", x3d_scroll); cfg_write_int(cfgfile, "Global", "z3d_scroll", z3d_scroll); cfg_write_boolean(cfgfile, "Global", "show_leader", show_leader); cfg_write_int(cfgfile, "Global", "scope_sync_source", scope_sync_source); cfg_write_boolean(cfgfile, "Global", "landtilt",landtilt); cfg_write_boolean(cfgfile, "Global", "spiketilt", spiketilt); cfg_write_float(cfgfile, "Global", "low_freq", low_freq); cfg_write_float(cfgfile, "Global", "high_freq", high_freq); cfg_write_int(cfgfile, "Window", "width", width); cfg_write_int(cfgfile, "Window", "height", height+22); gdk_window_get_root_origin(widget->window, &x, &y); cfg_write_int(cfgfile, "Window", "main_x_origin", x); cfg_write_int(cfgfile, "Window", "main_y_origin", y); // cfg_write_boolean(cfgfile, "Window", "grad_win_present", grad_win_present); if (grad_win_present) { gdk_window_get_root_origin((gpointer) grad_win_ptr->window, &x, &y); cfg_write_int(cfgfile, "Window", "grad_x_origin", x); cfg_write_int(cfgfile, "Window", "grad_y_origin", y); } if (dir_win_present) { gdk_window_get_root_origin((gpointer) dir_win_ptr->window, &x, &y); cfg_write_int(cfgfile, "Window", "dir_x_origin", x); cfg_write_int(cfgfile, "Window", "dir_y_origin", y); } cfg_write_file(cfgfile, filename); cfg_free(cfgfile); g_free(filename); }
/*! \brief present_firmware_choices() presents a dialog box with the firmware choices. \returns the name of the chosen firmware */ G_MODULE_EXPORT gchar * present_firmware_choices(void) { gchar ** filenames = NULL; GtkWidget *dialog = NULL; GtkWidget *vbox = NULL; GtkWidget *hbox = NULL; GtkWidget *ebox = NULL; GtkWidget *sep = NULL; GtkWidget *dummybutton = NULL; GtkWidget *button = NULL; GtkWidget *label = NULL; ListElement *element = NULL; gchar *tmpbuf = NULL; GArray *classes = NULL; GSList *group = NULL; GList *p_list = NULL; GList *s_list = NULL; ConfigFile *cfgfile = NULL; const gchar * last_file = NULL; gint major = 0; gint minor = 0; guint i = 0; gint result = 0; extern gconstpointer *global_data; gchar * pathstub = NULL; ENTER(); pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),NULL); filenames = get_files((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"prof",&classes); g_free(pathstub); if (!filenames) { MTXDBG(CRITICAL,_("NO Interrogation profiles found, was MegaTunix installed properly?\n")); EXIT(); return NULL; } i = 0; while (filenames[i]) { cfgfile = cfg_open_file(filenames[i]); if (!cfgfile) { MTXDBG(CRITICAL,_("Interrogation profile damaged!, was MegaTunix installed properly?\n")); i++; continue; } get_file_api(cfgfile,&major,&minor); if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API)) { thread_update_logbar("interr_view","warning",g_strdup_printf(_("Interrogation profile API mismatch (%i.%i != %i.%i):\n\tFile %s will be skipped\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,cfgfile->filename),FALSE,FALSE); i++; cfg_free(cfgfile); continue; } cfg_read_string(cfgfile,"interrogation_profile","name",&tmpbuf); cfg_free(cfgfile); last_file = (gchar *)DATA_GET(global_data,"last_offline_profile"); if (g_array_index(classes,FileClass,i) == PERSONAL) { element = g_new0(ListElement, 1); element->filename = g_strdup(filenames[i]); if (g_ascii_strcasecmp(element->filename,last_file) == 0) element->def = TRUE; element->name = g_strdup(tmpbuf); p_list = g_list_append(p_list,(gpointer)element); } if (g_array_index(classes,FileClass,i) == SYSTEM) { element = g_new0(ListElement, 1); element->filename = g_strdup(filenames[i]); if (g_ascii_strcasecmp(element->filename,last_file) == 0) element->def = TRUE; element->name = g_strdup(tmpbuf); s_list = g_list_append(s_list,(gpointer)element); } g_free(tmpbuf); i++; } p_list = g_list_sort(p_list,list_sort); s_list = g_list_sort(s_list,list_sort); dialog = gtk_dialog_new_with_buttons("Select Firmware", GTK_WINDOW(lookup_widget("main_window")), GTK_DIALOG_DESTROY_WITH_PARENT, "Abort", GTK_RESPONSE_CANCEL, "Load", GTK_RESPONSE_OK, NULL); vbox = gtk_vbox_new(TRUE,2); gtk_container_set_border_width(GTK_CONTAINER(vbox),5); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),vbox,TRUE,TRUE,0); /* Dummies */ dummybutton = gtk_radio_button_new(NULL); g_object_ref_sink(dummybutton); group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(dummybutton)); if (g_list_length(p_list) > 0) { label = gtk_label_new("Custom (personal) Profiles"); gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0); /* Cycle list for PERSONAL interogation files */ for (i=0;i<g_list_length(p_list);i++) { element = (ListElement *)g_list_nth_data(p_list,i); ebox = gtk_event_box_new(); gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0); hbox = gtk_hbox_new(FALSE,10); gtk_container_add(GTK_CONTAINER(ebox),hbox); label = gtk_label_new(element->name); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0); button = gtk_radio_button_new(group); g_free(OBJ_GET(button,"filename")); OBJ_SET_FULL(button,"filename",g_strdup(element->filename),g_free); OBJ_SET(button,"handler", GINT_TO_POINTER(OFFLINE_FIRMWARE_CHOICE)); g_signal_connect(button, "toggled", G_CALLBACK(toggle_button_handler), NULL); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0); if (element->def) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),TRUE); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),FALSE); group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)); } sep = gtk_hseparator_new(); gtk_box_pack_start(GTK_BOX(vbox),sep,TRUE,TRUE,0); } label = gtk_label_new("System Wide ECU Profiles"); gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0); /* Cycle list for System interogation files */ for (i=0;i<g_list_length(s_list);i++) { element = (ListElement *)g_list_nth_data(s_list,i); ebox = gtk_event_box_new(); gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0); hbox = gtk_hbox_new(FALSE,10); gtk_container_add(GTK_CONTAINER(ebox),hbox); label = gtk_label_new(element->name); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0); button = gtk_radio_button_new(group); g_free(OBJ_GET(button,"filename")); OBJ_SET_FULL(button,"filename",g_strdup(element->filename),g_free); OBJ_SET(button,"handler", GINT_TO_POINTER(OFFLINE_FIRMWARE_CHOICE)); g_signal_connect(button, "toggled", G_CALLBACK(toggle_button_handler), NULL); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0); if (element->def) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),TRUE); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),FALSE); group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)); } /* if (i==1) gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(button)); else gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE); */ g_strfreev(filenames); g_array_free(classes,TRUE); gtk_widget_show_all(dialog); gtk_window_set_transient_for(GTK_WINDOW(gtk_widget_get_toplevel(dialog)),GTK_WINDOW(lookup_widget("main_window"))); result = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_object_unref(dummybutton); g_list_foreach(p_list,free_element,NULL); g_list_foreach(s_list,free_element,NULL); g_list_free(p_list); g_list_free(s_list); switch (result) { case GTK_RESPONSE_ACCEPT: case GTK_RESPONSE_OK: EXIT(); return (gchar *)DATA_GET(global_data,"offline_firmware_choice"); break; case GTK_RESPONSE_CANCEL: default: EXIT(); return NULL; } EXIT(); return NULL; }