Пример #1
0
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", &micro_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);

}
Пример #2
0
/*! 
  \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;
}
Пример #3
0
/*!
 \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);
}
Пример #4
0
/*!
 \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;
}
Пример #5
0
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;
}
Пример #6
0
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);
	}
}
Пример #7
0
/*!
  \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;
}
Пример #8
0
/*!
  \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;
}
Пример #9
0
/*!
  \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;
}
Пример #10
0
/*!
  \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;
}