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); } }
/*! \brief populate_master() stores a pointer to all of the glade loaded widgets into a master hashtable so that it can be recalled by name anywhere in the program. \param widget is the pointer to Widget \param user_data is the pointer to ConfigFile structure */ G_MODULE_EXPORT void populate_master(GtkWidget *widget, gpointer user_data ) { gchar *name = NULL; gchar *fullname = NULL; gchar *prefix = NULL; GHashTable *dynamic_widgets = NULL; ConfigFile *cfg = (ConfigFile *) user_data; /*! Populates a big master hashtable of all dynamic widgets so that various functions can do a lookup for the widgets name and get it's GtkWidget * for manipulation. We do NOT insert the topframe widgets from the XML tree as if more than 1 tab loads there will be a clash, and there's no need to store the top frame widget anyways... */ if (GTK_IS_CONTAINER(widget)) gtk_container_foreach(GTK_CONTAINER(widget),populate_master,user_data); if (!cfg_read_string(cfg,"global","id_prefix",&prefix)) prefix = g_strdup(""); name = (char *)glade_get_widget_name(widget); /*printf("name of widget stored is %s\n",name);*/ if (name == NULL) { g_free(prefix); return; } if (g_strrstr((gchar *)name,"topframe")) { g_free(prefix); return; } dynamic_widgets = DATA_GET(global_data,"dynamic_widgets"); if(!dynamic_widgets) { dynamic_widgets = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL); DATA_SET_FULL(global_data,"dynamic_widgets",dynamic_widgets,g_hash_table_destroy); } fullname = g_strdup_printf("%s%s",prefix,name); OBJ_SET_FULL(widget,"fullname",g_strdup(fullname),g_free); OBJ_SET(widget,"last_value",GINT_TO_POINTER(-G_MAXINT)); if (!g_hash_table_lookup(dynamic_widgets,fullname)) g_hash_table_insert(dynamic_widgets,g_strdup(fullname),(gpointer)widget); else MTXDBG(CRITICAL,_("Key %s for widget %s from file %s already exists in master table\n"),name,fullname,cfg->filename); g_free(prefix); g_free(fullname); }
/*! \brief read logviewer defaults from file \param cfgfile is the pointer to ConfigFile structure to read the settings from */ G_MODULE_EXPORT void read_logviewer_defaults(ConfigFile *cfgfile) { gchar *tmpbuf = NULL; GList *defaults = NULL; gchar **vector = NULL; gint i = 0; cfg_read_string(cfgfile,"Logviewer","defaults",&tmpbuf); if (!tmpbuf) return; vector = g_strsplit(tmpbuf,",",-1); g_free(tmpbuf); for (i=0;i<g_strv_length(vector);i++) defaults = g_list_append(defaults,g_strdup(vector[i])); g_strfreev(vector); if (defaults) store_list("logviewer_defaults",defaults); }
/*! \brief handles runtime variables with complex ECU/Family specific handlers \param object is a pointer to the object to store the data within \param cfgfile is a pointer to the ConfigFile structure \param section is the section within the file \param symbol is the symbol name within the section \param type is an enumeration representing the type of RT var */ G_MODULE_EXPORT void common_rtv_loader_obj(GObject *object, ConfigFile *cfgfile, gchar * section, gchar *symbol, ComplexExprType type) { static Firmware_Details *firmware = NULL; gchar * name = NULL; gint tmpi = 0; gchar *tmpbuf = NULL; ENTER(); if (!firmware) firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); switch (type) { case ECU_EMB_BIT: /* ECU Embedded bitfield 4 params */ name=NULL; name=g_strdup_printf("%s_page",symbol); if (!cfg_read_int(cfgfile,section,name,&tmpi)) MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_EMB_BIT, failure looking for:%s\n"),name); OBJ_SET(object,name,GINT_TO_POINTER(tmpi)); g_free(name); name=NULL; name=g_strdup_printf("%s_offset",symbol); if (!cfg_read_int(cfgfile,section,name,&tmpi)) MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_EMB_BIT, failure looking for:%s\n"),name); OBJ_SET(object,name,GINT_TO_POINTER(tmpi)); g_free(name); name=NULL; name=g_strdup_printf("%s_canID",symbol); if (!cfg_read_int(cfgfile,section,name,&tmpi)) tmpi = firmware->canID; OBJ_SET(object,name,GINT_TO_POINTER(tmpi)); g_free(name); name=NULL; name=g_strdup_printf("%s_bitmask",symbol); if (!cfg_read_int(cfgfile,section,name,&tmpi)) MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_EMB_BIT, failure looking for:%s\n"),name); OBJ_SET(object,name,GINT_TO_POINTER(tmpi)); g_free(name); name=NULL; break; case ECU_VAR: /* ECU std variable, canID/page/offset/size */ name=NULL; name=g_strdup_printf("%s_canID",symbol); if (!cfg_read_int(cfgfile,section,name,&tmpi)) tmpi = firmware->canID; OBJ_SET(object,name,GINT_TO_POINTER(tmpi)); g_free(name); name=NULL; name=g_strdup_printf("%s_page",symbol); if (!cfg_read_int(cfgfile,section,name,&tmpi)) MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_VAR, failure looking for:%s\n"),name); OBJ_SET(object,name,GINT_TO_POINTER(tmpi)); g_free(name); name=NULL; name=g_strdup_printf("%s_offset",symbol); if (!cfg_read_int(cfgfile,section,name,&tmpi)) MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_VAR, failure looking for:%s\n"),name); OBJ_SET(object,name,GINT_TO_POINTER(tmpi)); g_free(name); name=NULL; name=g_strdup_printf("%s_size",symbol); if (!cfg_read_string(cfgfile,section,name,&tmpbuf)) tmpi = MTX_U08; else { tmpi = translate_string_f(tmpbuf); g_free(tmpbuf); } OBJ_SET(object,name,GINT_TO_POINTER(tmpi)); g_free(name); name=NULL; break; default: EXIT(); return; break; } EXIT(); return; }
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; }
/*! \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; }
/*! \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 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; }
/*! \brief Binds remaing keys in cfgfile to the object \param object is the pointer to object where we bind the data to \param cfgfile is the pointer to configfile where we pull the data from \param section is the section name within cfgfile to gt the data from \param keys is the array of char *'s, list of keys to read and store \param num_keys is the number of elements in the keys array */ G_MODULE_EXPORT void bind_keys(GObject *object, ConfigFile *cfgfile, gchar *section, gchar ** keys, gint num_keys) { gint i = 0; gint tmpi = 0; gfloat tmpf = 0.0; gfloat *newfloat = NULL; gchar * tmpbuf = NULL; gchar * tmpstr = NULL; DataType keytype = MTX_STRING; for (i=0;i<num_keys;i++) { keytype = translate_string(keys[i]); switch(keytype) { case MTX_INT: if (cfg_read_int(cfgfile,section,keys[i],&tmpi)) { MTXDBG(KEYPARSER,_("Binding INT \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section); OBJ_SET(object, keys[i], GINT_TO_POINTER(tmpi)); } else MTXDBG(KEYPARSER|CRITICAL,_("MTX_INT: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename); break; case MTX_ENUM: if (cfg_read_string(cfgfile,section,keys[i],&tmpbuf)) { tmpi = translate_string(tmpbuf); MTXDBG(KEYPARSER,_("Binding ENUM \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section); OBJ_SET(object, keys[i], GINT_TO_POINTER(tmpi)); g_free(tmpbuf); } else MTXDBG(KEYPARSER|CRITICAL,_("MTX_ENUM: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename); break; case MTX_BOOL: if (cfg_read_boolean(cfgfile,section,keys[i],&tmpi)) { MTXDBG(KEYPARSER,_("Binding BOOL \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section); if (tmpi) { OBJ_SET(object, keys[i], GINT_TO_POINTER(tmpi)); if (strstr(keys[i],"fromecu_complex")) load_complex_params_obj(object,cfgfile,section); } } else MTXDBG(KEYPARSER|CRITICAL,_("MTX_BOOL: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename); break; case MTX_FLOAT: if (cfg_read_float(cfgfile,section,keys[i],&tmpf)) { newfloat = NULL; newfloat = g_new0(gfloat, 1); *newfloat = tmpf; OBJ_SET_FULL(object, keys[i], (gpointer)newfloat,g_free); } else MTXDBG(KEYPARSER|CRITICAL,_("MTX_FLOAT: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename); break; case MTX_STRING: if(cfg_read_string(cfgfile,section,keys[i],&tmpbuf)) { MTXDBG(KEYPARSER,_("Binding STRING key:\"%s\" value:\"%s\" to widget \"%s\"\n"),keys[i],tmpbuf,section); tmpstr = DATA_GET(object,keys[i]); /* If data already on widget, append * new data and store */ if ((tmpstr) && (g_strrstr(keys[i],"bind_to_list")!= NULL)) { tmpstr = g_strconcat(tmpstr,",",tmpbuf,NULL); OBJ_SET_FULL(object, keys[i], g_strdup(tmpstr), g_free); g_free(tmpstr); } else OBJ_SET_FULL(object,keys[i],g_strdup(tmpbuf),g_free); g_free(tmpbuf); } else MTXDBG(KEYPARSER|CRITICAL,_("MTX_STRING: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename); break; default: break; } } return; }
/*! \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 bind_data() is a recursive function that is called for every container widget in a glade frame and it's purpose is to search the datamap file passed for the widget names in the glade file and if it's fond in the datamap to load all the attribues listed and bind them to the object using GTK+'s object model. \param widget is the widget passed to load attributes on \param user_data is the pointer to a BingGroup structure. */ G_MODULE_EXPORT void bind_data(GtkWidget *widget, gpointer user_data) { BindGroup *bindgroup = (BindGroup *)user_data; ConfigFile *cfgfile = bindgroup->cfgfile; GHashTable *groups = bindgroup->groups; gchar * tmpbuf = NULL; gchar * section = NULL; gchar ** keys = NULL; gint num_keys = 0; gint offset = 0; gint page = 0; gint index = 0; gchar * initializer = NULL; GdkColor color; gchar *size = NULL; gint count = 0; gint tmpi = 0; gboolean hidden = FALSE; gchar *ptr = NULL; gchar **vector = NULL; gchar **vec2 = NULL; void (*func)(void) = NULL; GList *list = NULL; GList *list2 = NULL; const gchar *name = NULL; gboolean indexed = FALSE; Firmware_Details *firmware = NULL; GList ***ecu_widgets = NULL; GList *tab_widgets = NULL; void (*load_dep_obj)(GObject *, ConfigFile *,const gchar *,const gchar *) = NULL; ENTER(); MTXDBG(TABLOADER,_("Entered")); ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets"); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); g_return_if_fail(ecu_widgets); g_return_if_fail(firmware); if (!GTK_IS_WIDGET(widget)) { EXIT(); return; } if (GTK_IS_WIDGET(widget)) if (GTK_IS_CONTAINER(widget)) gtk_container_foreach(GTK_CONTAINER(widget),bind_data,user_data); name = gtk_widget_get_name(widget); if (!name) { EXIT(); return; } if (NULL != (ptr = g_strrstr_len(name,strlen(name),"_of_"))) { indexed = TRUE; ptr = g_strrstr_len(name,ptr-name,"_"); tmpbuf = g_strdelimit(g_strdup(ptr),"_",' '); section = g_strndup(name,ptr-name); /*printf("(indexed) section is %s\n",section);*/ gint result = sscanf(tmpbuf,"%d of %d",&index,&count); /*printf("sscanf result %i\n",result);* * printf("Found indexed value for \"%s\", index %i, count %i\n",tmpbuf,index,count); */ g_free(tmpbuf); } else section = g_strdup(name); if(cfg_read_string(cfgfile, section, "keys", &tmpbuf)) { keys = parse_keys(tmpbuf,&num_keys,","); MTXDBG(TABLOADER,_("Number of keys for %s is %i\n"),section,num_keys); g_free(tmpbuf); } else { g_free(section); EXIT(); return; } page = -1; /* Store ptr to self in qdata, needed for bind_to_lists from groups*/ OBJ_SET(widget,"self",widget); /* Bind the data in the "defaults" group per tab to EVERY var in that * tab */ page = bind_group_data(cfgfile, G_OBJECT(widget), groups, "defaults"); if(cfg_read_string(cfgfile, section, "group", &tmpbuf)) { page = bind_group_data(cfgfile,G_OBJECT(widget),groups,tmpbuf); g_free(tmpbuf); } if ((!cfg_read_int(cfgfile, section, "page", &page)) && (page == -1)) { MTXDBG(TABLOADER|CRITICAL,_("Object %s doesn't have a page assigned!!!!\n"),section); } /* Bind widgets to lists if they have the bind_to_list flag set... */ tmpbuf = NULL; if (cfg_read_string(cfgfile, section, "bind_to_list", &tmpbuf)) { bind_to_lists(widget, tmpbuf); g_free(tmpbuf); } if (cfg_read_boolean(cfgfile,section,"ellipsize",&tmpi)) { if ((GTK_IS_LABEL(widget)) && (tmpi)) { OBJ_SET(widget,"ellipsize_preferred",GINT_TO_POINTER(TRUE)); if (DATA_GET(global_data,"ellipsize_tabs")) gtk_label_set_ellipsize(GTK_LABEL(widget),PANGO_ELLIPSIZE_END); } } /* Color selections */ if (cfg_read_string(cfgfile, section, "active_fg", &tmpbuf)) { gdk_color_parse(tmpbuf, &color); gtk_widget_modify_fg(widget, GTK_STATE_NORMAL, &color); g_free(tmpbuf); } if (cfg_read_string(cfgfile, section, "inactive_fg", &tmpbuf)) { gdk_color_parse(tmpbuf, &color); gtk_widget_modify_fg(widget, GTK_STATE_INSENSITIVE, &color); g_free(tmpbuf); } /* If this widget has a "depend_on" tag we need to load the dependancy * information and store it for use when needed... */ if (cfg_read_string(cfgfile,section,"depend_on",&tmpbuf)) { if (get_symbol("load_dependencies_obj",(void **)&load_dep_obj)) load_dep_obj(G_OBJECT(widget),cfgfile,section,"depend_on"); g_free(tmpbuf); } /* If this widget (a textview) has "create_tags" we call a special * handler just for that.. */ if (cfg_read_string(cfgfile,section,"create_tags",&tmpbuf)) { load_tags(G_OBJECT(widget),cfgfile,section); g_free(tmpbuf); } /* If this widget has "tooltip" set the tip on the widget */ if (cfg_read_string(cfgfile,section,"tooltip",&tmpbuf)) { gtk_widget_set_tooltip_text(widget,tmpbuf); g_free(tmpbuf); } /* If this widget (a label) has "set_label" we set the label on it */ if (cfg_read_string(cfgfile,section,"set_label",&tmpbuf)) { /* printf("setting label on %s to \"%s\"\n",glade_get_widget_name(widget),tmpbuf);*/ gtk_label_set_text(GTK_LABEL(widget),tmpbuf); g_free(tmpbuf); } /* If this widget is temp dependant, set the current units on it */ if (cfg_read_string(cfgfile,section,"temp_dep",&tmpbuf)) { OBJ_SET(widget,"widget_temp",DATA_GET(global_data,"mtx_temp_units")); g_free(tmpbuf); } /* If this widget has "register_as", register it with the supplied name */ if (cfg_read_string(cfgfile,section,"register_as",&tmpbuf)) { register_widget(tmpbuf,widget); g_free(tmpbuf); } /* If this widget has visible_functions defined */ if (cfg_read_string(cfgfile,section,"visible_functions",&tmpbuf)) { vector = g_strsplit(tmpbuf,",",-1); g_free(tmpbuf); for (guint i=0;i<g_strv_length(vector);i++) { vec2 = g_strsplit(vector[i],":",2); if (g_strv_length(vec2) != 2) { printf("ERROR in %s, visible_functions param is missing the framerate parameter (func:fps)\n",cfgfile->filename); g_strfreev(vec2); continue; } gint fps = (GINT)g_strtod(vec2[1],NULL); get_symbol(vec2[0],(void **)&func); if (func) { list = g_list_prepend(list,(gpointer)func); list2 = g_list_prepend(list2,GINT_TO_POINTER(fps)); } g_strfreev(vec2); } g_strfreev(vector); OBJ_SET_FULL(widget,"func_list",list,g_list_free); OBJ_SET_FULL(widget,"func_fps_list",list2,g_list_free); } /* If this widget has "initializer" there's a global variable * with it's name on it */ if (cfg_read_string(cfgfile,section,"initializer",&initializer)) { gint widget_type = 0; if (!cfg_read_string(cfgfile,section,"widget_type",&tmpbuf)) MTXDBG(TABLOADER|CRITICAL,_("Object %s has initializer, but no widget_type!!!!\n"),section); else widget_type = translate_string(tmpbuf); g_free(tmpbuf); switch (widget_type) { case MTX_RANGE: gtk_range_set_value(GTK_RANGE(widget),(GINT)DATA_GET(global_data,initializer)); break; case MTX_SPINBUTTON: gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),(GINT)DATA_GET(global_data,initializer)); break; case MTX_ENTRY: gtk_entry_set_text(GTK_ENTRY(widget),(gchar *)DATA_GET(global_data,initializer)); default: break; } g_free(initializer); } /* Hidden widgets have special handlers and should NOT be updated normally */ cfg_read_boolean(cfgfile,section, "hidden", &hidden); offset = -1; cfg_read_int(cfgfile,section, "offset", &offset); if (offset >= 0 && indexed) { /*printf("indexed widget %s\n",name); */ if (cfg_read_string(cfgfile, section, "size", &size)) { offset += index * get_multiplier ((DataSize)translate_string (size)); g_free(size); } else { if(OBJ_GET(widget, "size")) { offset += index * get_multiplier ((DataSize)(GINT)OBJ_GET(widget, "size")); } else { MTXDBG(TABLOADER|CRITICAL,_("Indexed Object %s has index and offset, but no size!!!!\n"),section); g_free(section); EXIT(); return; } } /*printf("widget %s, offset %i\n",name,offset);*/ OBJ_SET(widget,"offset",GINT_TO_POINTER(offset)); } if (offset >= 0) { /* The way we do it now is to STORE widgets in LISTS for each * offset, thus we can have multiple on screen controls bound * to single data offset in the ECU */ if (page < 0) { MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap widget %s, page %i, at offset %i...\n\n"),section,page,offset); g_free(section); EXIT(); return; } if (page < firmware->total_pages) { if (offset >= firmware->page_params[page]->length) MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap widget %s, at offset %i...\n\n"),section,offset); else if (!hidden) { tab_widgets = OBJ_GET(bindgroup->topframe,"tab_widgets"); tab_widgets = g_list_prepend(tab_widgets, widget); OBJ_SET(bindgroup->topframe,"tab_widgets",tab_widgets); ecu_widgets[page][offset] = g_list_prepend( ecu_widgets[page][offset], (gpointer)widget); } } else MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap for widget %s, at page %i offset %i...\n\n"),section,page,offset); } /* If there is a "group" key in a section it means that it gets the * rest of it's setting from the groupname listed. This reduces * redundant keys all throughout the file... */ bind_keys(G_OBJECT(widget), cfgfile, section, keys, num_keys); g_strfreev(keys); /* If this widget has the "choices" key (combobox) */ if (cfg_read_string(cfgfile,section,"choices",&tmpbuf)) { combo_setup(G_OBJECT(widget),cfgfile,section); g_free(tmpbuf); } if (cfg_read_string(cfgfile,section,"post_functions_with_arg",&tmpbuf)) { run_post_functions_with_arg(tmpbuf,widget); g_free(tmpbuf); } if (cfg_read_string(cfgfile,section,"post_functions",&tmpbuf)) { run_post_functions(tmpbuf); g_free(tmpbuf); } if (cfg_read_boolean(cfgfile,section,"show_widget",&tmpi)) { if (tmpi) gtk_widget_show(widget); else gtk_widget_hide(widget); } if (cfg_read_string(cfgfile,section,"set_tab_labels",&tmpbuf)) { if (GTK_IS_NOTEBOOK(widget)) { vector=g_strsplit(tmpbuf,",",-1); if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(widget)) == g_strv_length(vector)) { for (int i=0;i<g_strv_length(vector);i++) { gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(widget), gtk_notebook_get_nth_page(GTK_NOTEBOOK(widget),i), vector[i]); } } g_strfreev(vector); } g_free(tmpbuf); } g_free(section); MTXDBG(TABLOADER,_("Leaving")); EXIT(); return; }
/*! \brief Called from the load_gui_tabs_pf function in order to load common settings for a group of controls. \param cfgfile is the pointer to the configuration file to read the group information from. \see group_free \see load_gui_tabs_pf \returns a GHashTable * to a newly created hashtable of the groups that were loaded. The groups are indexed in the hashtable by group name. */ G_MODULE_EXPORT GHashTable * load_groups(ConfigFile *cfgfile) { gint x = 0; gint tmpi = 0; gchar * tmpbuf = NULL; gchar **groupnames = NULL; gchar *section = NULL; gint num_groups = 0; Group *group = NULL; GHashTable *groups = NULL; void (*load_dep_obj)(GObject *,ConfigFile *,const gchar *,const gchar *) = NULL; ENTER(); if(cfg_read_string(cfgfile,"global","groups",&tmpbuf)) { groupnames = parse_keys(tmpbuf,&num_groups,","); MTXDBG(TABLOADER,_("Number of groups to load settings for is %i\n"),num_groups); g_free(tmpbuf); } else { EXIT(); return NULL; } groups = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,group_free); for (x=0;x<num_groups;x++) { /* Create structure and allocate ram for it */ group = g_new0(Group, 1); section = g_strdup(groupnames[x]); if(cfg_read_string(cfgfile,section,"keys",&tmpbuf)) { group->keys = parse_keys(tmpbuf,&group->num_keys,","); MTXDBG(TABLOADER,_("Number of keys for section %s is %i\n"),section,group->num_keys); g_free(tmpbuf); } else { MTXDBG(TABLOADER,_("\"keys\" key in section \"%s\" NOT found, aborting this group.\n"),section); g_free(group); g_free(section); continue; } group->object = (GObject *)g_object_new(GTK_TYPE_INVISIBLE,NULL); g_object_ref_sink(group->object); /* If this widget has a "depend_on" tag we need to * load the dependency information and store it for * use when needed... */ if (cfg_read_string(cfgfile,section,"depend_on",&tmpbuf)) { if (get_symbol("load_dependencies_obj",(void **)&load_dep_obj)) load_dep_obj(group->object,cfgfile,section,"depend_on"); g_free(tmpbuf); } /* Adds on "default" options to any other groups */ if (g_ascii_strcasecmp(section,"defaults") != 0) group->page = bind_group_data(cfgfile, group->object, groups, "defaults"); if (cfg_read_int(cfgfile,section,"page",&tmpi)) group->page = tmpi; /* Binds the rest of the settings, overriding any defaults */ bind_keys(group->object,cfgfile,section,group->keys,group->num_keys); /* Store it in the hashtable... */ g_hash_table_insert(groups,g_strdup(section),(gpointer)group); g_free(section); } g_strfreev(groupnames); if (group) { EXIT(); return groups; } EXIT(); return NULL; }
/*! \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 descends into a GladeWidgetInfo tree looking for special case widgets to handle \param info is the pointer to a GladeWidgetInfo structure \param cfgfile is the pointer to the corresponding datamap file \returns TRUE, unless eat end of the tree */ gboolean descend_tree(GladeWidgetInfo *info,ConfigFile *cfgfile) { static GHashTable *widget_2_tab_hash = NULL; static ConfigFile *last_cfgfile = NULL; static gchar * prefix = NULL; gchar *groups = NULL; gchar *bitvals = NULL; gchar *source_key = NULL; gchar *source_values = NULL; gint bitval = 0; gint bitmask = 0; gint offset = 0; gint page = 0; /*gint canID = 0;*/ DataSize size = MTX_U08; GObject *object = NULL; GList *list = NULL; guint i = 0; ENTER(); if (!widget_2_tab_hash) { widget_2_tab_hash = (GHashTable *)DATA_GET(global_data,"widget_2_tab_hash"); g_return_val_if_fail(widget_2_tab_hash,FALSE); } /* if (!info->parent) printf("%s is a TOPLEVEL\n",info->name); else if (info->n_children == 0) { printf("%s is a BOTTOM WIDGET\n",info->name); EXIT(); return FALSE; } else printf("%s\n",info->name); printf("widget %s has %i children\n",info->name,info->n_children); */ for (i=0;i<info->n_children;i++) descend_tree(info->children[i].child,cfgfile); if (last_cfgfile != cfgfile) { if (prefix) cleanup(prefix); if(!cfg_read_string(cfgfile,"global","id_prefix", &prefix)) prefix = NULL; last_cfgfile = cfgfile; } if (cfg_find_section(cfgfile,info->name)) // This widget exists { if (prefix) g_hash_table_insert(widget_2_tab_hash,g_strdup_printf("%s%s",prefix,info->name),g_strdup(cfgfile->filename)); else g_hash_table_insert(widget_2_tab_hash,g_strdup(info->name),g_strdup(cfgfile->filename)); } if (cfg_read_string(cfgfile,info->name,"source_values",&source_values)) { if (!cfg_read_string(cfgfile,info->name,"source_key",&source_key)) { MTXDBG(TABLOADER|CRITICAL,_("%s needs source_key\n"),info->name); EXIT(); return TRUE; } if (!cfg_read_int(cfgfile,info->name,"offset",&offset)) { MTXDBG(TABLOADER|CRITICAL,_("%s needs offset\n"),info->name); EXIT(); return TRUE; } if (!cfg_read_int(cfgfile,info->name,"bitmask",&bitmask)) { MTXDBG(TABLOADER|CRITICAL,_("%s needs bitmask\n"),info->name); EXIT(); return TRUE; } if (!cfg_read_string(cfgfile,info->name,"bitvals",&bitvals)) { if (!cfg_read_int(cfgfile,info->name,"bitval",&bitval)) { MTXDBG(TABLOADER|CRITICAL,_("%s needs bitvals or bitval\n"),info->name); EXIT(); return TRUE; } } if (!cfg_read_int(cfgfile,info->name,"page",&page)) { if (!cfg_read_int(cfgfile,"defaults","page",&page)) { MTXDBG(TABLOADER|CRITICAL,_("%s has no page defined!\n"),info->name); EXIT(); return TRUE; } } object = (GObject *)g_object_new(GTK_TYPE_INVISIBLE,NULL); g_object_ref_sink(object); /*OBJ_SET(object,"canID",GINT_TO_POINTER(canID));*/ OBJ_SET(object,"page",GINT_TO_POINTER(page)); OBJ_SET(object,"offset",GINT_TO_POINTER(offset)); OBJ_SET(object,"size",GINT_TO_POINTER(size)); OBJ_SET(object,"bitmask",GINT_TO_POINTER(bitmask)); if (bitvals) OBJ_SET_FULL(object,"bitvals",g_strdup(bitvals),g_free); else OBJ_SET(object,"bitval",GINT_TO_POINTER(bitval)); OBJ_SET_FULL(object,"source_key",g_strdup(source_key),g_free); OBJ_SET_FULL(object,"source_values",g_strdup(source_values),g_free); list = (GList *)DATA_GET(global_data,"source_list"); list = g_list_prepend(list,object); DATA_SET(global_data,"source_list",(gpointer)list); cleanup(groups); cleanup(bitvals); cleanup(source_key); cleanup(source_values); } if (cfg_read_string(cfgfile,info->name,"toggle_groups",&groups)) { if (!cfg_read_int(cfgfile,info->name,"offset",&offset)) { MTXDBG(TABLOADER|CRITICAL,_("%s needs offset\n"),info->name); EXIT(); return TRUE; } if (!cfg_read_int(cfgfile,info->name,"bitmask",&bitmask)) { MTXDBG(TABLOADER|CRITICAL,_("%s needs bitmask\n"),info->name); EXIT(); return TRUE; } if (!cfg_read_string(cfgfile,info->name,"bitvals",&bitvals)) { if (!cfg_read_int(cfgfile,info->name,"bitval",&bitval)) { MTXDBG(TABLOADER|CRITICAL,_("%s needs bitvals or bitval\n"),info->name); EXIT(); return TRUE; } } if (!cfg_read_int(cfgfile,info->name,"page",&page)) { if (!cfg_read_int(cfgfile,"defaults","page",&page)) { MTXDBG(TABLOADER|CRITICAL,_("%s has no page defined!\n"),info->name); EXIT(); return TRUE; } } /* if (!cfg_read_int(cfgfile,info->name,"canID",&canID)) { if (!cfg_read_int(cfgfile,"defaults","canID",&canID)) { printf("%s has no canID defined!\n",info->name); EXIT(); return TRUE; } } */ object = (GObject *)g_object_new(GTK_TYPE_INVISIBLE,NULL); g_object_ref_sink(object); /*OBJ_SET(object,"canID",GINT_TO_POINTER(canID));*/ OBJ_SET(object,"page",GINT_TO_POINTER(page)); OBJ_SET(object,"offset",GINT_TO_POINTER(offset)); OBJ_SET(object,"size",GINT_TO_POINTER(size)); OBJ_SET(object,"bitmask",GINT_TO_POINTER(bitmask)); if (bitvals) OBJ_SET_FULL(object,"bitvals",g_strdup(bitvals),g_free); else OBJ_SET(object,"bitval",GINT_TO_POINTER(bitval)); OBJ_SET_FULL(object,"toggle_groups",g_strdup(groups),g_free); list = (GList *)DATA_GET(global_data,"toggle_group_list"); list = g_list_prepend(list,object); DATA_SET(global_data,"toggle_group_list",(gpointer)list); cleanup(groups); cleanup(bitvals); cleanup(source_key); cleanup(source_values); } EXIT(); 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; } }
/*! \brief Sets up a megatunix comboboxentry widget. Reads the data from the passed ConfigFile *, and sets up the choices as well as the combo model and an entry completion/regex alloing textual based entry. \param object is the pointer to combo widget object \param cfgfile is the pointer to datamap file assocated with this widget \param section is the section within the cfgfile */ G_MODULE_EXPORT void combo_setup(GObject *object, ConfigFile *cfgfile, gchar * section) { gchar *tmpbuf = NULL; gchar ** choices = NULL; gchar ** vector = NULL; gint num_choices = 0; gint num_bitvals = 0; gint i = 0; gchar *tmpstr = NULL; gchar *regex = NULL; const gchar *name = NULL; GtkListStore *store = NULL; GtkTreeIter iter; GtkEntryCompletion *completion = NULL; GtkWidget *entry = NULL; extern gconstpointer *global_data; cfg_read_string(cfgfile,section,"choices",&tmpbuf); choices = parse_keys(tmpbuf,&num_choices,","); tmpbuf = g_strdelimit(tmpbuf,",",'|'); tmpstr = g_utf8_normalize(tmpbuf,-1,G_NORMALIZE_DEFAULT); regex = g_utf8_casefold(tmpbuf,-1); g_free(tmpbuf); g_free(tmpstr); if (!cfg_read_string(cfgfile,section,"bitvals",&tmpbuf)) { MTXDBG(CRITICAL,_("\"bitvals\" key is MISSING, critical fault, not setting up control \n")); return; } vector = parse_keys(tmpbuf,&num_bitvals,","); g_free(tmpbuf); if (num_bitvals != num_choices) { name = glade_get_widget_name(GTK_WIDGET(object)); MTXDBG(CRITICAL,_("\"bitvals\" BIG PROBLEM, combobox %s choices %i and bits %i don't match up\n"),(name == NULL ? "undefined" : name),num_choices,num_bitvals); return; } store = gtk_list_store_new(COMBO_COLS,G_TYPE_STRING,G_TYPE_UCHAR); for (i=0;i<num_choices;i++) { gtk_list_store_append(store,&iter); assert(choices[i]); assert(vector[i]); gtk_list_store_set(store,&iter,CHOICE_COL,choices[i],BITVAL_COL,(guchar)g_ascii_strtoull(vector[i],NULL,10),-1); } OBJ_SET_FULL(object,"model",store,gtk_list_store_clear); g_strfreev(vector); g_strfreev(choices); gtk_combo_box_set_model(GTK_COMBO_BOX(object),GTK_TREE_MODEL(store)); if (GTK_IS_COMBO_BOX_ENTRY(object)) { gint width = 0; gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(object),CHOICE_COL); entry = mask_entry_new_with_mask(regex); /* Nasty hack, but otherwise the entry is an obnoxious size.. */ if ((width = (GINT)OBJ_GET((GtkWidget *)object,"max_chars")) > 0) gtk_entry_set_width_chars(GTK_ENTRY(entry),width); else gtk_entry_set_width_chars(GTK_ENTRY(entry),12); gtk_widget_set_size_request(GTK_WIDGET(object),-1,(3*(GINT)DATA_GET(global_data,"font_size"))); gtk_container_remove (GTK_CONTAINER (object), gtk_bin_get_child(GTK_BIN (object))); gtk_container_add (GTK_CONTAINER (object), entry); completion = gtk_entry_completion_new(); OBJ_SET_FULL(object,"completion",completion,g_object_unref); gtk_entry_set_completion(GTK_ENTRY(entry),completion); gtk_entry_completion_set_model(completion,GTK_TREE_MODEL(store)); gtk_entry_completion_set_text_column(completion,CHOICE_COL); gtk_entry_completion_set_inline_completion(completion,TRUE); gtk_entry_completion_set_inline_selection(completion,TRUE); gtk_entry_completion_set_popup_single_match(completion,FALSE); OBJ_SET(object,"arrow-size",GINT_TO_POINTER(1)); } g_free(regex); }
/*! \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); }
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); } }
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 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; }