Exemplo n.º 1
0
/*!
  \brief processes commen runtime variables
  \param object is the pointer to the object containing the info abot the 
  complex expression
  \param symbol is the name of the symbol
  \param type is the type of rtv expression
  \returns the result
  */
G_MODULE_EXPORT gdouble common_rtv_processor(gconstpointer *object, gchar *symbol, ComplexExprType type)
{
	static Firmware_Details *firmware = NULL;
	gint canID = 0;
	gint page = 0;
	gint offset = 0;
	DataSize size = MTX_U08;
	gint bitmask = 0;
	gint bitshift = 0;
	gchar *tmpbuf = NULL;

	if (!firmware)
		firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	switch (type)
	{
		case ECU_EMB_BIT:
			tmpbuf = g_strdup_printf("%s_canID",symbol);
			canID = (GINT) DATA_GET(object,tmpbuf);
			g_free(tmpbuf);
			tmpbuf = g_strdup_printf("%s_page",symbol);
			page = (GINT) DATA_GET(object,tmpbuf);
			g_free(tmpbuf);
			tmpbuf = g_strdup_printf("%s_offset",symbol);
			offset = (GINT) DATA_GET(object,tmpbuf);
			g_free(tmpbuf);
			tmpbuf = g_strdup_printf("%s_bitmask",symbol);
			bitmask = (GINT) DATA_GET(object,tmpbuf);
			g_free(tmpbuf);
			bitshift = get_bitshift_f(bitmask);
			/*
			   printf("raw ecu at page %i, offset %i is %i\n",page,offset,ms_get_ecu_data(canID,page,offset,size));
			   printf("value masked by %i, shifted by %i is %i\n",bitmask,bitshift,(ms_get_ecu_data(canID,page,offset,size) & bitmask) >> bitshift);
			 */
			return ((ms_get_ecu_data(canID,page,offset,size) & bitmask) >> bitshift);
			break;
		case ECU_VAR:
			tmpbuf = g_strdup_printf("%s_page",symbol);
			page = (GINT) DATA_GET(object,tmpbuf);
			g_free(tmpbuf);
			tmpbuf = g_strdup_printf("%s_offset",symbol);
			offset = (GINT) DATA_GET(object,tmpbuf);
			g_free(tmpbuf);
			tmpbuf = g_strdup_printf("%s_canID",symbol);
			canID = (GINT) DATA_GET(object,tmpbuf);
			g_free(tmpbuf);
			tmpbuf = g_strdup_printf("%s_size",symbol);
			size = (DataSize)(GINT) DATA_GET(object,tmpbuf);
			g_free(tmpbuf);
			return (gdouble)ms_get_ecu_data(canID,page,offset,size);
			break;
		default:
			return 0.0;
			break;
	}
	return 0.0;
}
Exemplo n.º 2
0
/*!
 \brief revert_to_previous_data() reverts the VEX import by using the backup
 of the internal datastructures.
 */
G_MODULE_EXPORT void revert_to_previous_data(void)
{
	gint canID=0;
	gint page=0;
	gint offset=0;
	gint total = 0;
	guchar *data = NULL;
	GModule *module = NULL;
	PostFunction *pf = NULL;
	GArray *pfuncs = NULL;
	guint8 **ecu_data_backup = NULL;
	/* Called to back out a load of a VEtable from VEX import */
	Firmware_Details *firmware = NULL;

	firmware = DATA_GET(global_data,"firmware");
	ecu_data_backup = firmware->ecu_data_backup;

	for (page=0;page<firmware->total_pages;page++)
	{
		if (!firmware->page_params[page]->dl_by_default)
			continue;
		if (firmware->chunk_support)
		{
			total = firmware->page_params[page]->length;
			data = g_new0(guchar,total);
			for (offset=0;offset<total;offset++)
				data[offset]=ms_get_ecu_data_backup(canID,page,offset,MTX_U08);
			ms_chunk_write(canID,page,0,total,data);

		}
		else
		{
			for (offset = 0;offset<firmware->page_params[page]->length;offset++)
			{
				if (ms_get_ecu_data_backup(canID,page,offset,MTX_U08) != ms_get_ecu_data(canID,page,offset,MTX_U08))
				{
					ms_send_to_ecu(canID,page,offset,MTX_U08,ecu_data_backup[page][offset], FALSE);
				}
			}
		}
	}
	module = g_module_open(NULL,G_MODULE_BIND_LAZY);
	pfuncs = g_array_new(FALSE,TRUE,sizeof(PostFunction *));

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("update_ecu_controls_pf");
	if (module)
		g_module_symbol(module,pf->name,(void *)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);
	g_module_close(module);
	io_cmd_f(NULL,pfuncs);

	gtk_widget_set_sensitive(lookup_widget_f("tools_undo_vex_button"),FALSE);
	update_logbar_f("tools_view","warning",_("Reverting to previous settings....\n"),FALSE,FALSE,FALSE);
	io_cmd_f(firmware->burn_all_command,NULL);
}
Exemplo n.º 3
0
/*!
 \brief backup_all_ecu_settings() backs up the ECU to a filename passed
 \param filename (gchar *) filename to backup the ECU to
 */
G_MODULE_EXPORT void backup_all_ecu_settings(gchar *filename)
{
	ConfigFile *cfgfile;
	gchar * section = NULL;
	gchar * tmpbuf = NULL;
	gint i = 0;
	gint x = 0;
	gint canID = 0;
	DataSize size = MTX_U08;	 /* <<<<< BAD BAD BAD >>>>> */
	GString *string = NULL;
	extern gconstpointer *global_data;
	Firmware_Details *firmware = NULL;

	firmware = DATA_GET(global_data,"firmware");
	g_return_if_fail(filename);
	g_return_if_fail(firmware);

	cfgfile = cfg_open_file(filename);
	if(!cfgfile)
		cfgfile = cfg_new();

	set_file_api_f(cfgfile,BACKUP_MAJOR_API,BACKUP_MINOR_API);

	update_logbar_f("tools_view",NULL,g_strdup_printf("%s %s\n",_("Full Backup Commencing to file:\n\t"),filename),FALSE,FALSE,TRUE);
	cfg_write_string(cfgfile,"Firmware","name",firmware->name);
	for(i=0;i<firmware->total_pages;i++)
	{
		if (!firmware->page_params[i]->dl_by_default)
			continue;
		string = g_string_sized_new(64);
		section = g_strdup_printf("page_%i",i);
		cfg_write_int(cfgfile,section,"num_variables",firmware->page_params[i]->length);
		for(x=0;x<firmware->page_params[i]->length;x++)
		{
			g_string_append_printf(string,"%i",ms_get_ecu_data(canID,i,x,size));
			if (x < (firmware->page_params[i]->length-1))
				string = g_string_append(string,",");
		}
		cfg_write_string(cfgfile,section,"data",string->str);
		g_free(section);
		g_string_free(string,TRUE);
	}
	update_logbar_f("tools_view",NULL,_("Full Backup Complete...\n"),FALSE,FALSE,FALSE);
	cfg_write_file(cfgfile,filename);
	cfg_free(cfgfile);
}
Exemplo n.º 4
0
/*!
 \brief single_table_export() is the export function to dump one Tables
 to a "vex" file.  
 \param iochannel a pointer to the output channel 
 \param table_num, integer number of table to export
 \see single_table_import
 \returns TRUE on success, FALSE on failure
 */
G_MODULE_EXPORT void single_table_export(GIOChannel *iochannel, gint table_num)
{
	struct tm *tm = NULL;
	time_t *t = NULL;
	gint i = 0;
	gint j = 0;
	gint table = -1;
	gsize count = 0;
	gint index = 0;
	gint x_page = 0;
	gint y_page = 0;
	gint z_page = 0;
	gint x_base = 0;
	gint y_base = 0;
	gint z_base = 0;
	DataSize x_size = 0;
	DataSize y_size = 0;
	DataSize z_size = 0;
	gint x_mult = 0;
	gint y_mult = 0;
	gint z_mult = 0;
	gint x_bincount = 0;
	gint y_bincount = 0;
	GIOStatus status;
	GString *output = NULL;
	gint canID = 0;
	Firmware_Details *firmware = NULL;

	firmware = DATA_GET(global_data,"firmware");
	canID = firmware->canID;


	/* For Page 0.... */
	output = g_string_sized_new(64); /*pre-allocate 64 chars */
	/*printf("total tables %i\n",firmware->total_tables);*/
	table = table_num;
	x_page = firmware->table_params[table]->x_page;
	y_page = firmware->table_params[table]->y_page;
	z_page = firmware->table_params[table]->z_page;
	x_base = firmware->table_params[table]->x_base;
	y_base = firmware->table_params[table]->y_base;
	z_base = firmware->table_params[table]->z_base;
	x_size = firmware->table_params[table]->x_size;
	y_size = firmware->table_params[table]->y_size;
	z_size = firmware->table_params[table]->z_size;
	x_mult = get_multiplier_f(x_size);
	y_mult = get_multiplier_f(y_size);
	z_mult = get_multiplier_f(z_size);
	x_bincount = firmware->table_params[table]->x_bincount;
	y_bincount = firmware->table_params[table]->y_bincount;

	t = g_malloc(sizeof(time_t));
	time(t);
	tm = localtime(t);
	g_free(t);
	if (vex_comment == NULL)
		vex_comment = g_strdup("No comment given");

	g_string_append_printf(output, "EVEME 1.0\n");
	g_string_append_printf(output, "UserRev: 1.00\n");
	g_string_append_printf(output, "UserComment: Table %i; (%s) %s\n",table,firmware->table_params[table]->table_name,vex_comment);
	g_string_append_printf(output, "Date: %i-%.2i-%i\n",1+(tm->tm_mon),tm->tm_mday,1900+(tm->tm_year));

	g_string_append_printf(output, "Time: %.2i:%.2i\n",tm->tm_hour,tm->tm_min);
	g_string_append_printf(output, "Page %i\n",z_page);
	g_string_append_printf(output, "VE Table RPM Range              [%2i]\n",x_bincount);

	for (i=0;i<x_bincount;i++)
		g_string_append_printf(output,"   [%3d] = %3d\n",i,ms_get_ecu_data(canID,x_page,x_base+(i*x_mult),x_size));

	g_string_append_printf(output, "VE Table Load Range (MAP)       [%2i]\n",y_bincount);
	for (i=0;i<y_bincount;i++)
		g_string_append_printf(output, "   [%3d] = %3d\n",i,ms_get_ecu_data(canID,y_page,y_base+(i*y_mult),y_size));

	g_string_append_printf(output, "VE Table                        [%3i][%3i]\n",x_bincount,y_bincount);
	g_string_append_printf(output, "           ");
	for (i=0;i<x_bincount;i++)
	{
		g_string_append_printf(output, "[%3d]",i);
		if (i < (x_bincount-1))
			g_string_append_printf(output, " ");
	}
	g_string_append_printf(output, "\n");
	index = 0;
	for (i=0;i<x_bincount;i++)
	{
		g_string_append_printf(output, "   [%3d] =",i);
		for (j=0;j<y_bincount;j++)
		{
			if (j == 0)
				g_string_append_printf (output, "  %3d",ms_get_ecu_data(canID,z_page,z_base+(index*z_mult),z_size));
			else
				g_string_append_printf (output, "   %3d",ms_get_ecu_data(canID,z_page,z_base+(index*z_mult),z_size));
			index++;
		}
		g_string_append_printf(output,"\n");
	}
	status = g_io_channel_write_chars(
			iochannel,output->str,output->len,&count,NULL);
	if (status != G_IO_STATUS_NORMAL)
	{
		dbg_func_f(CRITICAL,g_strdup(__FILE__": all_table_export()\n\tError exporting VEX file\n"));
	}
	g_string_free(output,TRUE);

	update_logbar_f("tools_view",NULL,_("VE-Table(s) Exported Successfully\n"),FALSE,FALSE,FALSE);

	if (vex_comment)
		g_free(vex_comment);
	vex_comment = NULL;
	return; /* return TRUE on success, FALSE on failure */
}