Example #1
0
/*!
 \brief create_rtt() creates the rt_text from the passed data, and attaches
 it the the gui.
 \param parent (GtkWidget *) parent widget
 \param ctrl_name (gchar *) name of the rt_text as defined in the config file
 \param source (gchar *) data source for this rt_text 
 \returns a Struct Rt_Text *
 */
G_MODULE_EXPORT Rt_Text * create_rtt(gchar *ctrl_name, gchar *source, gboolean show_prefix)
{
	Rt_Text *rtt = NULL;
	Rtv_Map *rtv_map = NULL;
	gconstpointer *object = NULL;

	rtv_map = DATA_GET(global_data,"rtv_map");


	if (!rtv_map)
	{
		dbg_func(CRITICAL,g_strdup_printf(__FILE__": create_rtt()\n\tBad things man, rtv_map is null!!\n"));
		return NULL;
	}
	object = g_hash_table_lookup(rtv_map->rtv_hash,source);
	if (!(object))
	{
		dbg_func(CRITICAL,g_strdup_printf(__FILE__": create_rtt()\n\tBad things man, object doesn't exist for %s\n",source));
		return NULL;
	}

	rtt = g_malloc0(sizeof(Rt_Text));
	rtt->show_prefix = show_prefix;
	rtt->ctrl_name = g_strdup(ctrl_name);
	rtt->friendly_name = (gchar *) DATA_GET(object,"dlog_gui_name");
	rtt->object = object;

	return rtt;
}
Example #2
0
/*!
 \brief start_tickler() starts up a GTK+ timeout function based on the
 enum passed to it.
 \param type (TicklerType enum) is an enum passed which is used to know 
 which timeout to fire up.
 \see signal_read_rtvars_thread signal_read_rtvars
 */
G_MODULE_EXPORT void start_tickler(TicklerType type)
{
	gint id = 0;
	GThread *realtime_id = NULL;
	switch (type)
	{
		case RTV_TICKLER:
			if (DATA_GET(global_data,"offline"))
				break;
			if (!DATA_GET(global_data,"rtvars_loaded"))
				break;
			if (DATA_GET(global_data,"restart_realtime"))
			{
				update_logbar("comms_view",NULL,_("TTM is active, Realtime Reader suspended\n"),FALSE,FALSE,FALSE);
				break;
			}
			if (!DATA_GET(global_data,"realtime_id"))
			{
				flush_rt_arrays();

				realtime_id = g_thread_create(signal_read_rtvars_thread,
						NULL, /* Thread args */
						TRUE, /* Joinable */
						NULL); /*GError Pointer */
				DATA_SET(global_data,"realtime_id",realtime_id);
				update_logbar("comms_view",NULL,_("Realtime Reader started\n"),FALSE,FALSE,FALSE);
			}
			else
				update_logbar("comms_view","warning",_("Realtime Reader ALREADY started\n"),FALSE,FALSE,FALSE);
			break;
		case LV_PLAYBACK_TICKLER:
			if (!DATA_GET(global_data,"playback_id"))
			{
				id = gdk_threads_add_timeout((GINT)DATA_GET(global_data,"lv_scroll_delay"),(GSourceFunc)pb_update_logview_traces,GINT_TO_POINTER(FALSE));
				DATA_SET(global_data,"playback_id",GINT_TO_POINTER(id));
			}
			else
				dbg_func(CRITICAL,g_strdup(__FILE__": start_tickler()\n\tPlayback already running \n"));
			break;
		case SCOUNTS_TICKLER:
			if (DATA_GET(global_data,"offline"))
				break;
			if (!((DATA_GET(global_data,"connected")) && 
						(DATA_GET(global_data,"interrogated"))))
				break;
			if (!DATA_GET(global_data,"statuscounts_id"))
			{
				id = g_timeout_add(100,(GSourceFunc)update_errcounts,NULL);
				DATA_SET(global_data,"statuscounts_id",GINT_TO_POINTER(id));
			}
			else
				dbg_func(CRITICAL,g_strdup(__FILE__": start_tickler()\n\tStatuscounts tickler already active \n"));
			break;
		default:
			/* Search for registered handlers from plugins */
			break;

	}
}
Example #3
0
/* Adds bul entry to both hashes and adds a timer for expiry / resend. 
   Caller must fill all non-private fields of bule */
int bul_add(struct bulentry *bule)
{
	int ret = 0;
	struct timespec timer_expire;
	struct home_addr_info *hai = bule->home;

	assert(bule && tsisset(bule->lifetime) && hai);
	
	if ((ret = hash_add(&bul_hash, bule, &bule->hoa, &bule->peer_addr)) < 0)
		return ret;
	if ((ret = hash_add(&hai->bul, bule, NULL, &bule->peer_addr)) < 0)
		goto bul_free;

	clock_gettime(CLOCK_REALTIME, &bule->lastsent);
	if (bule->type == BUL_ENTRY) {
		if ((ret = pre_bu_bul_update(bule)) < 0)
			goto home_bul_free;
	} else if (bule->type == NON_MIP_CN_ENTRY) {
		if (bule->flags & IP6_MH_BU_HOME) {
			if (xfrm_block_hoa(hai) < 0)
				goto home_bul_free;
		}
	}
	tsadd(bule->delay, bule->lastsent, timer_expire);
	dbg("Adding bule\n");
	dbg_func(bule, dump_bule);
	add_task_abs(&timer_expire, &bule->tqe, bule->callback);
	return 0;
home_bul_free:
	hash_delete(&hai->bul, &bule->hoa, &bule->peer_addr);
bul_free:
	hash_delete(&bul_hash, &bule->hoa, &bule->peer_addr);
	return ret; 
}
Example #4
0
/*
 * need to be separated into two phase:
 * phase 1: before sending BU
 * 		add policy/state for BU
 * phase 2: after sending BU
 * 		add policy/state for RO
 */
void bul_update_timer(struct bulentry *bule)
{
	struct timespec timer_expire;
	tsadd(bule->delay, bule->lastsent, timer_expire);
	dbg("Updating timer\n");
	dbg_func(bule, dump_bule);
	add_task_abs(&timer_expire, &bule->tqe, bule->callback);
}
Example #5
0
/*!
 \brief load_table() physically handles loading the table datafrom disk, 
 populating and array and sotring a pointer to that array in the lookuptables
 hashtable referenced by the table_name passed
 \param table_name (gchar *) key to lookuptables hashtable
 \param filename (gchar *) filename to load table data from
 \returns TRUE on success, FALSE on failure
 */
gboolean load_table(gchar *table_name, gchar *filename)
{
	GIOStatus status;
	GIOChannel *iochannel;
	gboolean done = FALSE;
	gchar * str = NULL;
	gchar * tmp = NULL;
	gchar * end = NULL;
	GString *a_line; 
	LookupTable *lookuptable = NULL;
	gint tmparray[2048]; /* bad idea being static!!*/
	gchar ** vector = NULL;
	gint i = 0;

	iochannel = g_io_channel_new_file(filename,"r", NULL);
	status = g_io_channel_seek_position(iochannel,0,G_SEEK_SET,NULL);
	if (status != G_IO_STATUS_NORMAL)
	{
		dbg_func(CRITICAL,g_strdup(__FILE__": load_lookuptables()\n\tError seeking to beginning of the file\n"));
	}
	while (!done)	
	{
		a_line = g_string_new("\0");
		status = g_io_channel_read_line_string(iochannel, a_line, NULL, NULL);
		if (status == G_IO_STATUS_EOF)
			done = TRUE;
		else
		{
		/*	str = g_strchug(g_strdup(a_line->str));*/
			str = g_strchug(a_line->str);
			if (g_str_has_prefix(str,"DB"))
			{
				str+=2; /* move 2 places in	*/
				end = g_strrstr(str,"T");
				tmp = g_strndup(str,end-str);
				tmparray[i]=atoi(tmp);
				g_free(tmp);
				i++;
			}
		}
		g_string_free(a_line,TRUE);
	}
	g_io_channel_shutdown(iochannel,TRUE,NULL);
	g_io_channel_unref(iochannel);

	vector = g_strsplit(filename,PSEP,-1);
	lookuptable = g_new0(LookupTable, 1);
	lookuptable->array = g_memdup(&tmparray,i*sizeof(gint));
	lookuptable->filename = g_strdup(vector[g_strv_length(vector)-1]);
	g_strfreev(vector);
	if (!lookuptables)
		lookuptables = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,dealloc_lookuptable);
	g_hash_table_insert(lookuptables,g_strdup(table_name),lookuptable);
	/*g_hash_table_foreach(lookuptables,dump_lookuptables,NULL);*/

	return TRUE;
}
Example #6
0
/*! 
 \brief load_logviewer_file() loads a datalog file for playback
 \param iochannel The IO channel representing the source file
 */
G_MODULE_EXPORT void load_logviewer_file(GIOChannel *iochannel)
{
	Log_Info *log_info = NULL;
	if (!iochannel)
	{
		dbg_func(CRITICAL,g_strdup(__FILE__": load_logviewer_file()\n\tIo_File pointer NULL,returning!!\n"));
		return;
	}
	log_info = initialize_log_info();
	DATA_SET(global_data,"log_info",log_info);
	read_log_header(iochannel, log_info);
	read_log_data(iochannel, log_info);
	populate_limits(log_info);
	return;
}
Example #7
0
EXPORT void post_single_burn_pf(void *data)
{
	Io_Message *message = (Io_Message *)data;
	OutputData *output = (OutputData *)message->payload;
	extern Firmware_Details * firmware;
	gint page = (GINT)OBJ_GET(output->object,"page");

	/* sync temp buffer with current burned settings */
	if (!firmware->page_params[page]->dl_by_default)
		return;
	backup_current_data(firmware->canID,page);

	dbg_func(SERIAL_WR,g_strdup(__FILE__": post_single_burn_pf()\n\tBurn to Flash Completed\n"));

	return;
}
Example #8
0
/*!
 \brief post_burn_pf() handles post burn ecu data mgmt
 */
EXPORT void post_burn_pf()
{
	gint i = 0;
	extern Firmware_Details * firmware;

	/* sync temp buffer with current burned settings */
	for (i=0;i<firmware->total_pages;i++)
	{
		if (!firmware->page_params[i]->dl_by_default)
			continue;
		backup_current_data(firmware->canID,i);
	}

	dbg_func(SERIAL_WR,g_strdup(__FILE__": post_burn_pf()\n\tBurn to Flash Completed\n"));

	return;
}
Example #9
0
/*!
 \brief lookup_data() returns the value represented by the lookuptable 
 associated with the passed object and offset
 \param object (GObject *) container of parameters we need to do the lookup
 \param offset (gint) offset into lookuptable
 \returns the value at that offset of the lookuptable
 */
gfloat lookup_data(GObject *object, gint offset)
{
	extern GHashTable *lookuptables;
	GObject *dep_obj = NULL;
	LookupTable *lookuptable = NULL;
	gchar *table = NULL;
	gchar *alt_table = NULL;
	gboolean state = FALSE;

	table = (gchar *)OBJ_GET(object,"lookuptable");
	alt_table = (gchar *)OBJ_GET(object,"alt_lookuptable");
	dep_obj = (GObject *)OBJ_GET(object,"dep_object");
	
	/*
	   if (GTK_IS_OBJECT(dep_obj))
	   printf("checking dependancy %s\n",OBJ_GET(object,"internal_names"));
	   else
	   printf("no dependancy\n");
	   */

	if (dep_obj)
	{
		state = check_dependancies(dep_obj);
	}
	if (state)
	{
		/*printf("ALTERNATE\n");*/
		lookuptable = (LookupTable *)g_hash_table_lookup(lookuptables,alt_table);	
	}
	else
	{
		/*printf("NORMAL\n");*/
		lookuptable = (LookupTable *)g_hash_table_lookup(lookuptables,table);	
	}

	if (!lookuptable)
	{
		dbg_func(CRITICAL,g_strdup_printf(__FILE__": lookup_data()\n\t Lookuptable is NULL for control %s\n",(gchar *) OBJ_GET(object,"internal_names")));
		return 0.0;
	}
	return lookuptable->array[offset];
}
Example #10
0
/* bul_delete - deletes a bul entry */
void bul_delete(struct bulentry *bule)
{
	struct home_addr_info *hai = bule->home;

	del_task(&bule->tqe);
	hash_delete(&bul_hash, &bule->hoa, &bule->peer_addr);
	hash_delete(&hai->bul, NULL, &bule->peer_addr);

	if (!IN6_ARE_ADDR_EQUAL(&bule->hoa, &bule->coa)) {
		bule->last_coa = bule->coa;
		bule->coa = bule->hoa;
		bule->coa_changed = 1;
	}
	if (bule->type == BUL_ENTRY) {
		xfrm_del_bule(bule);
		if (!(bule->flags & IP6_MH_BU_HOME))
			mn_rr_delete_bule(bule);
	}
	if (bule->flags & IP6_MH_BU_HOME) {
		if (bule->type == UNREACH_ENTRY) {
			pthread_mutex_lock(&hai->ha_list.c_lock);
			if (IN6_ARE_ADDR_EQUAL(&bule->peer_addr, 
					       &hai->ha_list.last_ha))
				hai->ha_list.last_ha = in6addr_any;
			pthread_mutex_unlock(&hai->ha_list.c_lock);
		} else {
			if (hai->home_block & HOME_LINK_BLOCK)
				xfrm_unblock_link(hai);
			if (hai->home_block & HOME_ADDR_BLOCK)
				xfrm_unblock_hoa(hai);
		}
	}
	while (bule->ext_cleanup)
		bule->ext_cleanup(bule);
	dbg("Deleting bule\n");
	dbg_func(bule, dump_bule);
	free_bule(bule);
}
Example #11
0
/*!
 \brief get_table() gets a valid filehandle of the lookuptable from 
 get_file and passes it to load_table()
 \see load_table
 \see get_File
 \param table_name (gpointer) textual name of the table to use as the key
 to the lookuptables hashtable
 \param fname (gpointer) textual name of the filename to load
 \param user_data (gpointer) unused
 */
void get_table(gpointer table_name, gpointer fname, gpointer user_data)
{
	gboolean status = FALSE;
	gchar * filename = NULL;
	gchar ** vector = NULL;
	
	vector = g_strsplit(fname,".",2);

	filename = get_file(g_strconcat(LOOKUPTABLES_DATA_DIR,PSEP,vector[0],NULL),g_strdup(vector[1]));
	g_strfreev(vector);

	if (filename)
	{
		status = load_table((gchar *)table_name,filename);
		g_free(filename);
	}
	if (!status)
	{
		dbg_func(CRITICAL,g_strdup_printf(__FILE__": load_lookuptables()\n\tFAILURE loading \"%s\" lookuptable, EXITING!!\n",(gchar *)table_name));
		exit (-2);
	}

}
Example #12
0
G_MODULE_EXPORT gboolean load_rtt_xml_elements(xmlNode *a_node, GtkListStore *store, GtkWidget *parent)
{
	xmlNode *cur_node = NULL;

	/* Iterate though all nodes... */
	for (cur_node = a_node;cur_node;cur_node = cur_node->next)
	{
		if (cur_node->type == XML_ELEMENT_NODE)
		{
			if (g_strcasecmp((gchar *)cur_node->name,"api") == 0)
				if (!xml_api_check(cur_node,RT_TEXT_MAJOR_API,RT_TEXT_MINOR_API))
				{
					dbg_func(CRITICAL,g_strdup_printf(__FILE__": load_rtt_xml_elements()\n\tAPI mismatch, won't load this file!!\n"));
					return FALSE;
				}
			if (g_strcasecmp((gchar *)cur_node->name,"rtt") == 0)
				load_rtt(cur_node,store,parent);
		}
		if (!load_rtt_xml_elements(cur_node->children,store,parent))
			return FALSE;
	}
	return TRUE;
}
Example #13
0
gboolean lookuptable_change(GtkCellRenderer *renderer, gchar *path, gchar * new_text, gpointer data)
{
	GtkListStore *store = NULL;
	GtkTreeIter iter;
	GtkTreeModel *model = data;
	ConfigFile *cfgfile = NULL;
	gchar * int_name = NULL;
	gchar * old = NULL;
	gchar * new_name = NULL;
	gchar ** vector = NULL;
	gboolean restart_tickler = FALSE;
	extern gint realtime_id;
	extern GHashTable *lookuptables;
	extern GAsyncQueue *io_data_queue;
	extern Firmware_Details *firmware;
	gint count = 0;
	LookupTable *lookuptable = NULL;

	/* Get combo box model so we can set the combo to this new value */
	g_object_get(G_OBJECT(renderer),"model",&store,NULL);
	gtk_tree_model_get_iter_from_string(model,&iter,path);
	gtk_tree_model_get(model,&iter,INTERNAL_NAME_COL,&int_name,FILENAME_COL,&old,-1);
	if (g_strcasecmp(old,new_text) == 0) /* If no change, return */
		return TRUE;
	
	if (g_strcasecmp(new_text,"Personal") == 0)
		return TRUE;
	if (g_strcasecmp(new_text,"System") == 0)
		return TRUE;
	if (realtime_id)
	{
		restart_tickler = TRUE;
		stop_tickler(RTV_TICKLER);
		count = 0;
		while ((g_async_queue_length(io_data_queue) > 0) && (count < 30))
		{
			dbg_func(CRITICAL,g_strdup_printf(__FILE__": LEAVE() draining I/O Queue,  current length %i\n",g_async_queue_length(io_data_queue)));
			while (gtk_events_pending())
				gtk_main_iteration();
			count++;
		}

	}
	lookuptable = (LookupTable *)g_hash_table_lookup(lookuptables,int_name);
	if (!lookuptable)
		printf(_("No lookuptable found! expect a crash!!\n"));
	g_free(lookuptable->array); /* Free the old one */
	g_free(lookuptable->filename); /* Free the old one */
	g_free(lookuptable); /* Free the old one */
	get_table(int_name,new_text,NULL); /* Load the new one in it's place */
	gtk_list_store_set(GTK_LIST_STORE(model),&iter, FILENAME_COL, new_text,-1);
	if (restart_tickler)
		start_tickler(RTV_TICKLER);

		cfgfile = cfg_open_file(firmware->profile_filename);
		if (!cfgfile)
			return FALSE;
		g_hash_table_foreach(lookuptables,update_lt_config,cfgfile);
	if (g_strrstr(firmware->profile_filename,".MegaTunix"))
		cfg_write_file(cfgfile, firmware->profile_filename);
	else
	{
		vector = g_strsplit(firmware->profile_filename,PSEP,-1);
		new_name = g_build_filename(HOME(),".MegaTunix",INTERROGATOR_DATA_DIR,"Profiles",vector[g_strv_length(vector)-1],NULL);
		g_strfreev(vector);
		cfg_write_file(cfgfile, new_name);
		g_free(firmware->profile_filename);
		firmware->profile_filename=g_strdup(new_name);
		g_free(new_name);
	}
	cfg_free(cfgfile);
		
	/*printf("internal name %s, old table %s, new table %s\n",int_name,old,new_text);*/
	return TRUE;

}
Example #14
0
/*!
 \brief signal_read_rtvars_thread() is thread which fires off the read msg
 to get a new set of realtiem variables.  It does so by queing messages to
 a thread which handles I/O.  This function will check the queue depth and 
 if the queue is backed up it will skip sending a request for data, as that 
 will only aggravate the queue roadblock.
 \returns 0 on signal to exit
 */
G_MODULE_EXPORT void * signal_read_rtvars_thread(gpointer data)
{
	static void (*signal_read_rtvars)(void);
	static gboolean (*setup_rtv)(void);
	static gboolean (*teardown_rtv)(void);
	Serial_Params *serial_params;
	GMutex * mutex = g_mutex_new();
	GTimeVal time;
	GAsyncQueue *io_data_queue = NULL;
	GAsyncQueue *pf_dispatch_queue = NULL;
	GCond *rtv_thread_cond = NULL;
	GMutex *rtv_thread_mutex = NULL;

	serial_params = DATA_GET(global_data,"serial_params");
	io_data_queue = DATA_GET(global_data,"io_data_queue");
	pf_dispatch_queue = DATA_GET(global_data,"pf_dispatch_queue");
	rtv_thread_cond = DATA_GET(global_data,"rtv_thread_cond");
	rtv_thread_mutex = DATA_GET(global_data,"rtv_thread_mutex");
	get_symbol("signal_read_rtvars",(void *)&signal_read_rtvars);
	get_symbol("setup_rtv",(void *)&setup_rtv);
	get_symbol("teardown_rtv",(void *)&teardown_rtv);

	g_return_val_if_fail(serial_params,NULL);
	g_return_val_if_fail(signal_read_rtvars,NULL);
	g_return_val_if_fail(io_data_queue,NULL);
	g_return_val_if_fail(pf_dispatch_queue,NULL);
	g_return_val_if_fail(rtv_thread_cond,NULL);
	g_return_val_if_fail(rtv_thread_mutex,NULL);

	if (setup_rtv)
		if (!setup_rtv())
			g_thread_exit(NULL);
	g_mutex_lock(mutex);
	g_async_queue_ref(io_data_queue);
	g_async_queue_ref(pf_dispatch_queue);
	g_mutex_lock(rtv_thread_mutex);
	while (TRUE)
	{
		dbg_func(IO_MSG|THREADS,g_strdup(__FILE__": signal_read_rtvars_thread()\n\tsending message to thread to read RT vars\n"));

		signal_read_rtvars();

		/* Auto-throttling if gui gets sluggish */
		while (( g_async_queue_length(io_data_queue) > 2) || 
				(g_async_queue_length(pf_dispatch_queue) > 3))
		{
			g_get_current_time(&time);
			g_time_val_add(&time,1000*g_async_queue_length(pf_dispatch_queue));
			if (g_cond_timed_wait(rtv_thread_cond,rtv_thread_mutex,&time))
				goto breakout;
		}
		g_get_current_time(&time);
		g_time_val_add(&time,serial_params->read_wait*1000);
		if (g_cond_timed_wait(rtv_thread_cond,rtv_thread_mutex,&time))
			goto breakout;
	}
breakout:
	g_mutex_unlock(rtv_thread_mutex);
	g_async_queue_unref(io_data_queue);
	g_async_queue_unref(pf_dispatch_queue);
	g_mutex_unlock(mutex);
	g_mutex_free(mutex);
	if (teardown_rtv)
		teardown_rtv();
	g_thread_exit(0);
	return NULL;
}
Example #15
0
/*!
 \brief convert_before_download() converts the value passed using the
 conversions bound to the widget
 \param widget (GtkWidget *) widget to extract the conversion info from
 \param value (gfloat *) the "real world" value from the tuning gui before
 translation to MS-units
 \returns the integere ms-units form after conversion
 */
G_MODULE_EXPORT gint convert_before_download(GtkWidget *widget, gfloat value)
{
	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
	gint return_value = 0;
	gint tmpi = 0;
	gchar * conv_expr = NULL;
	void *evaluator = NULL;
	DataSize size = MTX_U08;
	float lower = 0.0;
	float upper = 0.0;
	gfloat *multiplier = NULL;
	gfloat *adder = NULL;
	guint i = 0;
	GHashTable *mhash = NULL;
	GHashTable *ahash = NULL;
	gchar *key_list = NULL;
	gchar *mult_list = NULL;
	gchar *add_list = NULL;
	gchar **keys = NULL;
	gchar **mults = NULL;
	gchar **adds = NULL;
	gint table_num = 0;
	gchar *tmpbuf = NULL;
	gchar * source_key = NULL;
	gchar * hash_key = NULL;
	gint *algorithm = NULL;
	GHashTable *sources_hash = NULL;

	sources_hash = DATA_GET(global_data,"sources_hash");
	algorithm = DATA_GET(global_data,"algorithm");

	g_static_mutex_lock(&mutex);


	if (!OBJ_GET(widget,"size"))
		printf(__FILE__"%s %s\n",_(": convert_before_download, FATAL ERROR, size undefined for widget %s "),glade_get_widget_name(widget));

	size = (DataSize)OBJ_GET(widget,"size");
	if (OBJ_GET(widget,"raw_lower"))
		lower = (gfloat)strtol(OBJ_GET(widget,"raw_lower"),NULL,10);
	else
		lower = (gfloat)get_extreme_from_size(size,LOWER);
	if (OBJ_GET(widget,"raw_upper"))
		upper = (gfloat)strtol(OBJ_GET(widget,"raw_upper"),NULL,10);
	else
		upper = (gfloat)get_extreme_from_size(size,UPPER);

	/* MULTI EXPRESSION ONLY! */
	if (OBJ_GET(widget,"multi_expr_keys"))
	{
		if ((!OBJ_GET(widget,"mhash")) && (!OBJ_GET(widget,"ahash")))
		{
			mhash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
			ahash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
			key_list = OBJ_GET(widget,"multi_expr_keys");
			mult_list = OBJ_GET(widget,"fromecu_mults");
			add_list = OBJ_GET(widget,"fromecu_addds");
			keys = g_strsplit(key_list,",",-1);
			mults = g_strsplit(mult_list,",",-1);
			adds = g_strsplit(add_list,",",-1);
			for (i=0;i<MIN(g_strv_length(keys),g_strv_length(mults));i++)
			{
				multiplier = g_new0(gfloat, 1);
				*multiplier = (gfloat)g_strtod(mults[i],NULL);
				g_hash_table_insert(mhash,g_strdup(keys[i]),multiplier);
				adder = g_new0(gfloat, 1);
				*adder = (gfloat)g_strtod(adds[i],NULL);
				g_hash_table_insert(ahash,g_strdup(keys[i]),adder);
			}
			g_strfreev(keys);
			g_strfreev(mults);
			g_strfreev(adds);

			OBJ_SET_FULL(widget,"mhash",mhash,g_hash_table_destroy);
			OBJ_SET_FULL(widget,"ahash",ahash,g_hash_table_destroy);
		}
		mhash = OBJ_GET(widget,"mhash");
		ahash = OBJ_GET(widget,"ahash");
		source_key = OBJ_GET(widget,"source_key");
		if (!source_key)
			printf(_("big problem, source key is undefined!!\n"));
		hash_key = (gchar *)g_hash_table_lookup(sources_hash,source_key);
		tmpbuf = (gchar *)OBJ_GET(widget,"table_num");
		if (tmpbuf)
			table_num = (GINT)strtol(tmpbuf,NULL,10);
		if (table_num == -1) /* Not a table */
		{
			if (!hash_key)
			{
				multiplier = g_hash_table_lookup(mhash,"DEFAULT");
				adder = g_hash_table_lookup(ahash,"DEFAULT");
			}
			else
			{
				multiplier = g_hash_table_lookup(mhash,(gchar *)hash_key);
				adder = g_hash_table_lookup(ahash,(gchar *)hash_key);
			}
		}
		else /* This is a 3d table */
		{
			switch (algorithm[table_num])
			{
				case SPEED_DENSITY:
					if (!hash_key)
					{
						multiplier = g_hash_table_lookup(mhash,"DEFAULT");
						adder = g_hash_table_lookup(ahash,"DEFAULT");
					}
					else
					{
						multiplier = g_hash_table_lookup(mhash,hash_key);
						adder = g_hash_table_lookup(ahash,hash_key);
					}
					break;
				case ALPHA_N:
					multiplier = g_hash_table_lookup(mhash,"DEFAULT");
					adder = g_hash_table_lookup(ahash,"DEFAULT");
					break;
				case MAF:
					multiplier = g_hash_table_lookup(mhash,"AFM_VOLTS");
					adder = g_hash_table_lookup(ahash,"AFM_VOLTS");
					break;
			}
		}
		/* Reverse calc due to this being TO the ecu */
		if ((multiplier) && (adder))
			return_value = (GINT)((value - (*adder))/(*multiplier));
		else if (multiplier)
			return_value = (GINT)(value/(*multiplier));
		else
			return_value = (GINT)value;
	}
	else /* NON Multi Expression */
	{
		conv_expr = (gchar *)OBJ_GET(widget,"toecu_conv_expr");

		/* Expression is NOT multi expression but has more complex math*/
		if (conv_expr)
		{
			evaluator = (void *)OBJ_GET(widget,"dl_evaluator");
			if (!evaluator)
			{
				evaluator = evaluator_create(conv_expr);
				assert(evaluator);
				OBJ_SET_FULL(widget,"dl_evaluator",(gpointer)evaluator,evaluator_destroy);
			}
			return_value = (GINT)evaluator_evaluate_x(evaluator,value); 
		}
		else
		{
			multiplier = (gfloat *)OBJ_GET(widget,"fromecu_mult");
			adder = (gfloat *)OBJ_GET(widget,"fromecu_add");
			/* Handle all cases of with or without multiplier/adder*/
			if ((multiplier) && (adder))
				return_value = (GINT)((value - (*adder))/(*multiplier));
			else if (multiplier)
				return_value = (GINT)(value/(*multiplier));
			else
				return_value = (GINT)value;
		}
	}
	dbg_func(CONVERSIONS,g_strdup_printf(__FILE__": convert_before_dl():\n\t widget %s raw %.2f, sent %i\n",glade_get_widget_name(widget),value,return_value));
	if (return_value > upper) 
	{
		dbg_func(CONVERSIONS|CRITICAL,g_strdup_printf(__FILE__": convert_before_download()\n\t WARNING value clamped at %f (%f <- %f -> %f)!!\n",upper,lower,value,upper));
		return_value = upper;
	}
	if (return_value < lower)
	{
		dbg_func(CONVERSIONS|CRITICAL,g_strdup_printf(__FILE__": convert_before_download()\n\t WARNING value clamped at %f (%f <- %f -> %f)!!\n",lower,lower,value,upper));
		return_value = lower;
	}

	tmpi = return_value;
	if (OBJ_GET(widget,"lookuptable"))
		return_value = (GINT)reverse_lookup_obj(G_OBJECT(widget),tmpi);

	g_static_mutex_unlock(&mutex);
	return (return_value);
}
Example #16
0
EXPORT void simple_read_pf(void * data, XmlCmdType type)
{
	Io_Message *message  = NULL;
	OutputData *output  = NULL;
	gint count = 0;
	gchar *tmpbuf = NULL;
	gint page = -1;
	gint canID = -1;
	guint16 curcount = 0;
	static guint16 lastcount = 0;
	extern Firmware_Details *firmware;
	extern gint ms_ve_goodread_count;
	extern gint ms_reset_count;
	extern gint ms_goodread_count;
	guint8 *ptr8 = NULL;
	guint16 *ptr16 = NULL;
	static gboolean just_starting = TRUE;
	extern gboolean forced_update;
	extern gboolean force_page_change;
	extern volatile gboolean offline;


	message = (Io_Message *)data;
	output = (OutputData *)message->payload;

	switch (type)
	{
		case WRITE_VERIFY:
			printf(_("MS2_WRITE_VERIFY not written yet\n"));
			break;
		case MISMATCH_COUNT:
			printf(_("MS2_MISMATCH_COUNT not written yet\n"));
			break;
		case MS1_CLOCK:
			printf(_("MS1_CLOCK not written yet\n"));
			break;
		case MS2_CLOCK:
			printf(_("MS2_CLOCK not written yet\n"));
			break;
		case NUM_REV:
			if (offline)
				break;
			count = read_data(-1,&message->recv_buf,FALSE);
			ptr8 = (guchar *)message->recv_buf;
			firmware->ecu_revision=(gint)ptr8[0];
			if (count > 0)
				thread_update_widget("ecu_revision_entry",MTX_ENTRY,g_strdup_printf("%.1f",((gint)ptr8[0]/10.0)));
			else
				thread_update_widget("ecu_revision_entry",MTX_ENTRY,g_strdup(""));
			break;
		case TEXT_REV:
			if (offline)
				break;
			count = read_data(-1,&message->recv_buf,FALSE);
			if (count > 0)
			{
				thread_update_widget("text_version_entry",MTX_ENTRY,g_strndup(message->recv_buf,count));
				 firmware->txt_rev_len = count;
				firmware->text_revision = g_strndup(message->recv_buf,count);
			}
			break;
		case SIGNATURE:
			if (offline)
				break;
			 count = read_data(-1,&message->recv_buf,FALSE);
                         if (count > 0)
			 {
				 thread_update_widget("ecu_signature_entry",MTX_ENTRY,g_strndup(message->recv_buf,count));
				 firmware->signature_len = count;
				 firmware->actual_signature = g_strndup(message->recv_buf,count);
			 }
			break;
		case MS1_VECONST:
		case MS2_VECONST:
			page = (GINT)OBJ_GET(output->object,"page");
			canID = (GINT)OBJ_GET(output->object,"canID");
			count = read_data(firmware->page_params[page]->length,&message->recv_buf,TRUE);
			if (count != firmware->page_params[page]->length)
				break;
			store_new_block(canID,page,0,
					message->recv_buf,
					firmware->page_params[page]->length);
			backup_current_data(canID,page);
			ms_ve_goodread_count++;
			break;
		case MS1_RT_VARS:
			count = read_data(firmware->rtvars_size,&message->recv_buf,TRUE);
			if (count != firmware->rtvars_size)
				break;
			ptr8 = (guchar *)message->recv_buf;
			/* Test for MS reset */
			if (just_starting)
			{
				lastcount = ptr8[0];
				just_starting = FALSE;
			}
			/* Check for clock jump from the MS, a 
			 * jump in time from the MS clock indicates 
			 * a reset due to power and/or noise.
			 */
			if ((lastcount - ptr8[0] > 1) && \
					(lastcount - ptr8[0] != 255))
			{
				ms_reset_count++;
				printf(_("MS1 Reset detected!, lastcount %i, current %i\n"),lastcount,ptr8[0]);
				gdk_threads_enter();
				gdk_beep();
				gdk_threads_leave();
			}
			else
				ms_goodread_count++;
			lastcount = ptr8[0];
			/* Feed raw buffer over to post_process()
			 * as a void * and pass it a pointer to the new
			 * area for the parsed data...
			 */
			process_rt_vars((void *)message->recv_buf);
			break;
		case MS2_RT_VARS:
			page = (GINT)OBJ_GET(output->object,"page");
			canID = (GINT)OBJ_GET(output->object,"canID");
			count = read_data(firmware->rtvars_size,&message->recv_buf,TRUE);
			if (count != firmware->rtvars_size)
				break;
			store_new_block(canID,page,0,
					message->recv_buf,
					firmware->page_params[page]->length);
			backup_current_data(canID,page);
			ptr16 = (guint16 *)message->recv_buf;
			/* Test for MS reset */
			if (just_starting)
			{
				lastcount = GUINT16_TO_BE(ptr16[0]);
				curcount = GUINT16_TO_BE(ptr16[0]);
				just_starting = FALSE;
			}
			else
				curcount = GUINT16_TO_BE(ptr16[0]);
			/* Check for clock jump from the MS, a 
			 * jump in time from the MS clock indicates 
			 * a reset due to power and/or noise.
			 */
			if ((lastcount - curcount > 1) && \
					(lastcount - curcount != 65535))
			{
				ms_reset_count++;
				printf(_("MS2 rtvars reset detected, lastcount is %i, current %i"),lastcount,curcount);
				gdk_threads_enter();
				gdk_beep();
				gdk_threads_leave();
			}
			else
				ms_goodread_count++;
			lastcount = curcount;
			/* Feed raw buffer over to post_process()
			 * as a void * and pass it a pointer to the new
			 * area for the parsed data...
			 */
			process_rt_vars((void *)message->recv_buf);
			break;
		case MS2_BOOTLOADER:
			printf(_("MS2_BOOTLOADER not written yet\n"));
			break;
		case MS1_GETERROR:
			forced_update = TRUE;
			force_page_change = TRUE;
			count = read_data(-1,&message->recv_buf,FALSE);
			if (count <= 10)
			{
				thread_update_logbar("error_status_view",NULL,g_strdup(_("No ECU Errors were reported....\n")),FALSE,FALSE);
				break;
			}
			if (g_utf8_validate(((gchar *)message->recv_buf)+1,count-1,NULL))
			{
				thread_update_logbar("error_status_view",NULL,g_strndup(((gchar *)message->recv_buf+7)+1,count-8),FALSE,FALSE);
				if (dbg_lvl & (IO_PROCESS|SERIAL_RD))
				{
					tmpbuf = g_strndup(((gchar *)message->recv_buf)+1,count-1);
					dbg_func(IO_PROCESS|SERIAL_RD,g_strdup_printf(__FILE__"\tECU  ERROR string: \"%s\"\n",tmpbuf));
					g_free(tmpbuf);
				}

			}
			else
				thread_update_logbar("error_status_view",NULL,g_strdup("The data came back as gibberish, please try again...\n"),FALSE,FALSE);
			break;
		default:
			break;
	}
}
Example #17
0
/*!
 \brief add_rtt() creates the rt_text from the passed data, and attaches
 it the the gui.
 \param parent (GtkWidget *) parent widget
 \param ctrl_name (gchar *) name of the rt_text as defined in the config file
 \param source (gchar *) data source for this rt_text 
 \returns a Struct Rt_Text *
 */
G_MODULE_EXPORT Rt_Text * add_rtt(GtkWidget *parent, gchar *ctrl_name, gchar *source, gboolean show_prefix)
{
	Rt_Text *rtt = NULL;
	GtkWidget *label = NULL;
	GtkWidget *hbox = NULL;
	Rtv_Map *rtv_map = NULL;
	gconstpointer *object = NULL;

	rtv_map = DATA_GET(global_data,"rtv_map");

	rtt = g_malloc0(sizeof(Rt_Text));

	if (!rtv_map)
	{
		dbg_func(CRITICAL,g_strdup_printf(__FILE__": add_rtt()\n\tBad things man, rtv_map is null!!\n"));
		return NULL;
	}

	object = g_hash_table_lookup(rtv_map->rtv_hash,source);
	if (!(object))
	{
		dbg_func(CRITICAL,g_strdup_printf(__FILE__": add_rtt()\n\tBad things man, object doesn't exist for %s\n",source));
		return NULL;
	}

	rtt->show_prefix = show_prefix;
	rtt->ctrl_name = g_strdup(ctrl_name);
	rtt->friendly_name = (gchar *) DATA_GET(object,"dlog_gui_name");
	rtt->markup = (GBOOLEAN)OBJ_GET(parent,"markup");
	rtt->label_prefix = OBJ_GET(parent,"label_prefix");
	rtt->label_suffix = OBJ_GET(parent,"label_suffix");
	rtt->object = object;
	

	hbox = gtk_hbox_new(FALSE,5);

	/* Static prefix label.... */
	if (show_prefix)
	{
		label = gtk_label_new(NULL);
		rtt->name_label = label;
		gtk_label_set_markup(GTK_LABEL(label),rtt->friendly_name);
		gtk_misc_set_alignment(GTK_MISC(label),0.0,0.5);
		gtk_box_pack_start(GTK_BOX(hbox),label,TRUE,TRUE,0);
	}

	/* Value label */
	label = gtk_label_new(NULL);

	//set_fixed_size(label,11);
	rtt->textval = label;
	if (show_prefix)
		gtk_misc_set_alignment(GTK_MISC(label),1,0.5);
	else
		gtk_misc_set_alignment(GTK_MISC(label),0.5,0.5);
	gtk_box_pack_start(GTK_BOX(hbox),label,TRUE,TRUE,0);

	gtk_box_pack_start(GTK_BOX(parent),hbox,TRUE,TRUE,0);

	rtt->parent = hbox;
	gtk_widget_show_all(rtt->parent);

	return rtt;
}
Example #18
0
/*!
 \brief load_rt_text_pf() is called to load up the runtime text configurations
 from the file specified in the firmware's interrogation profile, and populate
 a new window with the runtiem vars text value box.
 */
G_MODULE_EXPORT void load_rt_text_pf(void)
{
	GtkWidget *treeview = NULL; 
	GtkWidget *window = NULL;
	GtkWidget *parent = NULL;
	gint x = 0;
	gint y = 0;
	GtkListStore *store = NULL;
	gchar *filename = NULL;
	GladeXML *main_xml = NULL;
	GladeXML *xml = NULL;
	gboolean xml_result = FALSE;
	CmdLineArgs *args = DATA_GET(global_data,"args");
	xmlDoc *doc = NULL;
	xmlNode *root_element = NULL;
	Firmware_Details *firmware = NULL;

	firmware = DATA_GET(global_data,"firmware");

	if (!(DATA_GET(global_data,"interrogated")))
		return;
	if (!firmware->rtt_map_file)
	{
		dbg_func(CRITICAL,g_strdup_printf(__FILE__": firmware->rtt_map_file is UNDEFINED,\n\texiting runtime text window creation routine!!!!\n"));
		return;
	}

	main_xml = (GladeXML *)DATA_GET(global_data,"main_xml");
	if ((!main_xml) || (DATA_GET(global_data,"leaving")))
		return;

	if (!DATA_GET(global_data,"rtvars_loaded"))
	{
		dbg_func(CRITICAL,g_strdup(__FILE__": load_rt_text_pf()\n\tCRITICAL ERROR, Realtime Variable definitions NOT LOADED!!!\n\n"));
		return;
	}
	gdk_threads_enter();
	set_title(g_strdup(_("Loading RT Text...")));

	filename = get_file(g_build_path(PSEP,RTTEXT_DATA_DIR,firmware->rtt_map_file,NULL),g_strdup("xml"));
	if (!filename)
	{
		dbg_func(RTMLOADER|CRITICAL,g_strdup_printf(__FILE__": load_rt_text_pf()\n\t File \"%s.xml\" not found!!, exiting function\n",firmware->rtt_map_file));
		set_title(g_strdup(_("ERROR RunTimeText Map XML file DOES NOT EXIST!!!")));
		gdk_threads_leave();
		return; 
	}

	/* Create window */
	xml = glade_xml_new(main_xml->filename,"rtt_window",NULL);
	window = glade_xml_get_widget(xml,"rtt_window");
	register_widget("rtt_window",window);
	x = (GINT)DATA_GET(global_data,"rtt_x_origin");
	y = (GINT)DATA_GET(global_data,"rtt_y_origin");
	gtk_window_move(GTK_WINDOW(window),x,y);
	gtk_window_set_default_size(GTK_WINDOW(window),-1,-1);
	g_object_set(window, "resizable", TRUE, NULL);
	parent = glade_xml_get_widget(xml,"rtt_vbox");
	glade_xml_signal_autoconnect(xml);

	LIBXML_TEST_VERSION

		doc = xmlReadFile(filename, NULL, 0);
	g_free(filename);
	if (doc == NULL)
	{
		printf(_("error: could not parse file %s\n"),filename);
		gdk_threads_leave();
		return;
	}

	/*Get the root element node */
	store = gtk_list_store_new(RTT_NUM_COLS,G_TYPE_POINTER,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_FLOAT);
	DATA_SET(global_data,"rtt_model",store);
	treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
	gtk_box_pack_start(GTK_BOX(parent),treeview,TRUE,TRUE,0);
	setup_rtt_treeview(treeview);

	root_element = xmlDocGetRootElement(doc);
	xml_result = load_rtt_xml_elements(root_element,store,parent);
	xmlFreeDoc(doc);
	xmlCleanupParser();

	if (xml_result == FALSE)
		gtk_widget_destroy(window);
	else if ((!args->hide_rttext) && (xml_result))
		gtk_widget_show_all(window);

	set_title(g_strdup(_("RT Text Loaded...")));
	gdk_threads_leave();
	return;
}
Example #19
0
/*!
 \brief convert_after_upload() converts the ms-units data to the real world
 units for display on the GUI
 \param widget (GtkWidget *) to extract the conversion info from to perform
 the necessary math
 \returns the real world value for the GUI
 */
G_MODULE_EXPORT gfloat convert_after_upload(GtkWidget * widget)
{
	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
	static gint (*get_ecu_data_f)(gpointer);
	static void (*send_to_ecu_f)(gpointer, gint, gboolean) = NULL;
	gfloat return_value = 0.0;
	gchar * conv_expr = NULL;
	void *evaluator = NULL;
	gint tmpi = 0;
	DataSize size = 0;
	gfloat lower = 0.0;
	gfloat upper = 0.0;
	gboolean fromecu_complex = FALSE;
	guint i = 0;
	gint table_num = -1;
	GHashTable *mhash = NULL;
	GHashTable *ahash = NULL;
	gchar *key_list = NULL;
	gchar *mult_list = NULL;
	gchar *add_list = NULL;
	gchar **keys = NULL;
	gchar **mults = NULL;
	gchar **adds = NULL;
	gchar * tmpbuf = NULL;
	gchar * source_key = NULL;
	gchar * hash_key = NULL;
	gfloat *multiplier = NULL;
	gfloat *adder = NULL;
	gint *algorithm = NULL;
	GHashTable *sources_hash = NULL;
	extern gconstpointer *global_data;


	if (!get_ecu_data_f)
		get_symbol("get_ecu_data",(void *)&get_ecu_data_f);
	if (!send_to_ecu_f)
		get_symbol("send_to_ecu",(void *)&send_to_ecu_f);
	g_return_val_if_fail(get_ecu_data_f,0.0);
	g_return_val_if_fail(send_to_ecu_f,0.0);

	g_static_mutex_lock(&mutex);

	size = (DataSize)OBJ_GET(widget,"size");
	if (size == 0)
	{
		printf(_("BIG PROBLEM, size undefined! widget %s, default to U08 \n"),(gchar *)glade_get_widget_name(widget));
		size = MTX_U08;
	}

	if (OBJ_GET(widget,"raw_lower"))
		lower = (gfloat)strtol(OBJ_GET(widget,"raw_lower"),NULL,10);
	else
		lower = (gfloat)get_extreme_from_size(size,LOWER);
	if (OBJ_GET(widget,"raw_upper"))
		upper = (gfloat)strtol(OBJ_GET(widget,"raw_upper"),NULL,10);
	else
		upper = (gfloat)get_extreme_from_size(size,UPPER);

	fromecu_complex = (GBOOLEAN)OBJ_GET(widget,"fromecu_complex");
	if (fromecu_complex)
	{
		g_static_mutex_unlock(&mutex);
		/*printf("Complex upload conversion for widget at page %i, offset %i, name %s\n",(GINT)OBJ_GET(widget,"page"),(GINT)OBJ_GET(widget,"offset"),glade_get_widget_name(widget));
		  */
		return handle_complex_expr_obj(G_OBJECT(widget),NULL,UPLOAD);
	}

	if (OBJ_GET(widget,"lookuptable"))
		tmpi = lookup_data_obj(G_OBJECT(widget),get_ecu_data_f(widget));
	else
		tmpi = get_ecu_data_f(widget);
	if (tmpi < lower)
	{
		dbg_func(CONVERSIONS|CRITICAL,g_strdup_printf(__FILE__": convert_after_upload()\n\t WARNING RAW value  out of range for widget %s, clamped at %.1f (%.1f <- %i -> %.1f), updating ECU with valid value within limits!!\n",(gchar *)glade_get_widget_name(widget),lower,lower,tmpi,upper));
		tmpi = lower;
		send_to_ecu_f(widget,tmpi,TRUE);
	}
	if (tmpi > upper)
	{
		dbg_func(CONVERSIONS|CRITICAL,g_strdup_printf(__FILE__": convert_after_upload()\n\t WARNING RAW value out of range for widget %s, clamped at %.1f (%.1f <- %i -> %.1f), updating ECU with valid value within limits!!\n",(gchar *)glade_get_widget_name(widget),lower,lower,tmpi,upper));
		tmpi = upper;
		send_to_ecu_f(widget,tmpi,TRUE);
	}
	/* MULTI EXPRESSION ONLY! */
	if (OBJ_GET(widget,"multi_expr_keys"))
	{
		sources_hash = DATA_GET(global_data,"sources_hash");
		if ((!OBJ_GET(widget,"mhash")) && (!OBJ_GET(widget,"ahash")))
		{
			mhash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
			ahash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
			key_list = OBJ_GET(widget,"multi_expr_keys");
			mult_list = OBJ_GET(widget,"fromecu_mults");
			add_list = OBJ_GET(widget,"fromecu_adds");
			if (!mult_list)
				printf("BUG, widget %s is multi_expression but doesn't have fromecu_mults defined!\n",glade_get_widget_name(widget));
			if (!add_list)
				printf("BUG, widget %s is multi_expression but doesn't have fromecu_adds defined!\n",glade_get_widget_name(widget));
			keys = g_strsplit(key_list,",",-1);
			mults = g_strsplit(mult_list,",",-1);
			adds = g_strsplit(add_list,",",-1);
			for (i=0;i<MIN(g_strv_length(keys),g_strv_length(mults));i++)
			{
				multiplier = g_new0(gfloat, 1);
				*multiplier = (gfloat)g_strtod(mults[i],NULL);
				g_hash_table_insert(mhash,g_strdup(keys[i]),multiplier);
				adder = g_new0(gfloat, 1);
				*adder = (gfloat)g_strtod(adds[i],NULL);
				g_hash_table_insert(ahash,g_strdup(keys[i]),adder);
			}
			g_strfreev(keys);
			g_strfreev(mults);
			g_strfreev(adds);

			OBJ_SET_FULL(widget,"mhash",mhash,g_hash_table_destroy);
			OBJ_SET_FULL(widget,"ahash",ahash,g_hash_table_destroy);
		}
		mhash = OBJ_GET(widget,"mhash");
		ahash = OBJ_GET(widget,"ahash");
		source_key = OBJ_GET(widget,"source_key");
		if (!source_key)
			printf(_("big problem, source key is undefined!!\n"));
		hash_key = (gchar *)g_hash_table_lookup(sources_hash,source_key);
		tmpbuf = (gchar *)OBJ_GET(widget,"table_num");
		if (tmpbuf)
			table_num = (GINT)strtol(tmpbuf,NULL,10);
		if (table_num == -1)
		{
			if (!hash_key)
			{
				multiplier = g_hash_table_lookup(mhash,"DEFAULT");
				adder = g_hash_table_lookup(ahash,"DEFAULT");
			}
			else
			{
				multiplier = g_hash_table_lookup(mhash,(gchar *)hash_key);
				adder = g_hash_table_lookup(ahash,(gchar *)hash_key);
			}
		}
		else
		{
			algorithm = DATA_GET(global_data,"algorithm");
			switch (algorithm[table_num])
			{
				case SPEED_DENSITY:
					if (!hash_key)
					{
						multiplier = g_hash_table_lookup(mhash,"DEFAULT");
						adder = g_hash_table_lookup(ahash,"DEFAULT");
					}
					else
					{
						multiplier = g_hash_table_lookup(mhash,hash_key);
						adder = g_hash_table_lookup(ahash,hash_key);
					}
					break;
				case ALPHA_N:
					multiplier = g_hash_table_lookup(mhash,"DEFAULT");
					adder = g_hash_table_lookup(ahash,"DEFAULT");
					break;
				case MAF:
					multiplier = g_hash_table_lookup(mhash,"AFM_VOLTS");
					adder = g_hash_table_lookup(ahash,"AFM_VOLTS");
					break;
			}
		}
		if ((multiplier) && (adder))
			return_value = (((gfloat)tmpi * (*multiplier)) + (*adder));
		else if (multiplier)
			return_value = (gfloat)tmpi * (*multiplier);
		else
			return_value = (gfloat)tmpi;
	}
	else
	{
		conv_expr = (gchar *)OBJ_GET(widget,"fromecu_conv_expr");
		if (conv_expr)
		{
			evaluator = (void *)OBJ_GET(widget,"ul_evaluator");
			if (!evaluator)
			{
				evaluator = evaluator_create(conv_expr);
				assert(evaluator);
				OBJ_SET_FULL(widget,"ul_evaluator",(gpointer)evaluator,evaluator_destroy);
			}
			return_value = evaluator_evaluate_x(evaluator,tmpi);
		}
		else
		{
			multiplier = OBJ_GET(widget,"fromecu_mult");
			adder = OBJ_GET(widget,"fromecu_add");
			if ((multiplier) && (adder))
				return_value = (((gfloat)tmpi * (*multiplier)) + (*adder));
			else if (multiplier)
				return_value = (gfloat)tmpi * (*multiplier);
			else
				return_value = (gfloat)tmpi;
			/*dbg_func(CONVERSIONS,g_strdup_printf(__FILE__": convert_after_ul():\n\tNo/Fast CONVERSION defined for  widget %s, value %f\n",(gchar *)glade_get_widget_name(widget), return_value));*/
		}

	}
//	dbg_func(CONVERSIONS,g_strdup_printf(__FILE__": convert_after_ul()\n\t page %i,offset %i, raw %i, val %f\n",page,offset,tmpi,return_value));
	g_static_mutex_unlock(&mutex);
	return (return_value);
}
Example #20
0
/*!
 \brief present_viewer_choices() presents the user with the a list of 
 variables from EITHER the realtime vars (if in realtime mode) or from a 
 datalog (playback mode)
 */
void present_viewer_choices(void)
{
	GtkWidget *window = NULL;
	GtkWidget *table = NULL;
	GtkWidget *frame = NULL;
	GtkWidget *vbox = NULL;
	GtkWidget *hbox = NULL;
	GtkWidget *button = NULL;
	GtkWidget *label = NULL;
	GtkWidget *sep = NULL;
	GtkWidget *darea = NULL;
	GList *list = NULL;
	GObject * object = NULL;
	extern GtkTooltips *tip;
	gint i = 0;
	gint j = 0;
	gint k = 0;
	gint table_rows = 0;
	gint table_cols = 5;
	gchar * name = NULL;
	gchar * tooltip = NULL;
	extern Rtv_Map *rtv_map;

	darea = lookup_widget("logviewer_trace_darea");
	lv_data->darea = darea;

	if (!darea)
	{
		dbg_func(CRITICAL,g_strdup(__FILE__": present_viewer_choices()\n\tpointer to drawing area was NULL, returning!!!\n"));
		return;
	}

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
	/* Playback mode..... */
	if (playback_mode)
	{
		gtk_window_set_title(GTK_WINDOW(window),
				_("Playback Mode: Logviewer Choices"));
		frame = gtk_frame_new(_("Select Variables to playback from the list below..."));
		max_viewables = log_info->field_count;
	}
	else
	{
		/* Realtime Viewing mode... */
		gtk_window_set_title(GTK_WINDOW(window),
				_("Realtime Mode: Logviewer Choices"));
		frame = gtk_frame_new(_("Select Realtime Variables to view from the list below..."));
		max_viewables = rtv_map->derived_total;

	}
	g_signal_connect_swapped(G_OBJECT(window),"destroy_event",
			G_CALLBACK(reenable_select_params_button),
			NULL);
	g_signal_connect_swapped(G_OBJECT(window),"destroy_event",
			G_CALLBACK(save_default_choices),
			NULL);
	g_signal_connect_swapped(G_OBJECT(window),"destroy_event",
			G_CALLBACK(gtk_widget_destroy),
			(gpointer)window);
	g_signal_connect_swapped(G_OBJECT(window),"delete_event",
			G_CALLBACK(reenable_select_params_button),
			NULL);
	g_signal_connect_swapped(G_OBJECT(window),"delete_event",
			G_CALLBACK(save_default_choices),
			NULL);
	g_signal_connect_swapped(G_OBJECT(window),"delete_event",
			G_CALLBACK(gtk_widget_destroy),
			(gpointer)window);

	gtk_container_set_border_width(GTK_CONTAINER(window),5);
	gtk_container_add(GTK_CONTAINER(window),frame);

	vbox = gtk_vbox_new(FALSE,0);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
	gtk_container_add(GTK_CONTAINER(frame),vbox);

	table_rows = ceil((float)max_viewables/(float)table_cols);
	table = gtk_table_new(table_rows,table_cols,TRUE);
	gtk_table_set_row_spacings(GTK_TABLE(table),2);
	gtk_table_set_col_spacings(GTK_TABLE(table),5);
	gtk_container_set_border_width(GTK_CONTAINER(table),0);
	gtk_box_pack_start(GTK_BOX(vbox),table,FALSE,FALSE,0);

	j = 0;
	k = 0;
	if(get_list("viewables"))
	{
		g_list_free(get_list("viewables"));
		store_list("viewables",NULL);
	}

	for (i=0;i<max_viewables;i++)
	{
		if (playback_mode)
			list = g_list_prepend(list,(gpointer)g_array_index(log_info->log_list,GObject *,i));
		else
			list = g_list_prepend(list,(gpointer)g_array_index(rtv_map->rtv_list,GObject *,i));
	}
Example #21
0
/*!
 \brief convert_temps() changes the values of controls based on the currently
 selected temperature scale.  IT works for labels, spinbuttons, etc...
 \param widget (gpointer) pointer to the widget that contains the necessary
 paramaters re temp (Alt label, etc)
 \param units (gpointer) the temp scale selected
 */
G_MODULE_EXPORT void convert_temps(gpointer widget, gpointer units)
{
	static void (*update_widget_f)(gpointer, gpointer);
	static gboolean (*check_deps)(gconstpointer *) = NULL;
	gconstpointer *dep_obj = NULL;
	gfloat upper = 0.0;
	gfloat lower = 0.0;
	gfloat value = 0.0;
	gchar * text = NULL;
	GtkAdjustment * adj = NULL;
	gboolean state = FALSE;
	gint widget_temp = -1;
	/*extern GdkColor black;*/
	extern gconstpointer *global_data;

	/* If this widgt depends on anything call check_dependancy which will
	 * return TRUE/FALSE.  True if what it depends on is in the matching
	 * state, FALSE otherwise...
	 */
	if ((!widget) || (DATA_GET(global_data,"leaving")))
		return;
	if (!check_deps)
		if (!get_symbol("check_dependancies",(void *)&check_deps))
			dbg_func(CRITICAL|CONVERSIONS,g_strdup_printf(__FILE__": convert_temps()\n\tCan NOT locate \"check_dependancies\" function pointer in plugins, BUG!\n"));
	if (!update_widget_f)
		if(!get_symbol("update_widget",(void *)&update_widget_f))
			dbg_func(CRITICAL|CONVERSIONS,g_strdup_printf(__FILE__": convert_temps()\n\tCan NOT locate \"update_widget\" function pointer in plugins, BUG!\n"));
	dep_obj = (gconstpointer *)OBJ_GET(widget,"dep_object");
	widget_temp = (GINT)OBJ_GET(widget,"widget_temp");
	if (dep_obj)
	{
		if (check_deps)
			state = check_deps(dep_obj);
		else
			dbg_func(CRITICAL|CONVERSIONS,g_strdup_printf(__FILE__": convert_temps()\n\tWidget %s has dependant object bound but can't locate function ptr for \"check_dependancies\" from plugins, BUG!\n",glade_get_widget_name(widget)));
	}

	switch ((TempUnits)units)
	{
		case FAHRENHEIT:
			/*printf("fahr %s\n",glade_get_widget_name(widget));*/
			if (GTK_IS_LABEL(widget))
			{
				if ((dep_obj) && (state))	
					text = (gchar *)OBJ_GET(widget,"alt_f_label");
				else
					text = (gchar *)OBJ_GET(widget,"f_label");
				gtk_label_set_text(GTK_LABEL(widget),text);
				//gtk_widget_modify_text(widget,GTK_STATE_NORMAL,&black);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));

			}
			if ((GTK_IS_SPIN_BUTTON(widget)) && (widget_temp != FAHRENHEIT))
			{

				adj = (GtkAdjustment *) gtk_spin_button_get_adjustment(
						GTK_SPIN_BUTTON(widget));
				upper = adj->upper;
				value = adj->value;
				lower = adj->lower;
				if (widget_temp == CELSIUS)
				{
					adj->value = c_to_f(value);
					adj->lower = c_to_f(lower);
					adj->upper = c_to_f(upper);
				}
				else /* Previous is kelvin */
				{
					adj->value = k_to_f(value);
					adj->lower = k_to_f(lower);
					adj->upper = k_to_f(upper);
				}

				gtk_adjustment_changed(adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_ENTRY(widget)) && (widget_temp != FAHRENHEIT))
			{
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_RANGE(widget)) && (widget_temp != FAHRENHEIT))
			{
				adj = (GtkAdjustment *) gtk_range_get_adjustment(
						GTK_RANGE(widget));
				upper = adj->upper;
				lower = adj->lower;
				value = adj->value;
				if (widget_temp == CELSIUS)
				{
					adj->value = c_to_f(value);
					adj->lower = c_to_f(lower);
					adj->upper = c_to_f(upper);
				}
				else /* Previous is kelvin */
				{
					adj->value = k_to_f(value);
					adj->lower = k_to_f(lower);
					adj->upper = k_to_f(upper);
				}

				gtk_range_set_adjustment(GTK_RANGE(widget),adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
			}
			break;
		case CELSIUS:
			/*printf("fahr %s\n",glade_get_widget_name(widget));*/
			if (GTK_IS_LABEL(widget))
			{
				if ((dep_obj) && (state))	
					text = (gchar *)OBJ_GET(widget,"alt_c_label");
				else
					text = (gchar *)OBJ_GET(widget,"c_label");
				gtk_label_set_text(GTK_LABEL(widget),text);
				//gtk_widget_modify_text(widget,GTK_STATE_NORMAL,&black);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));

			}
			if ((GTK_IS_SPIN_BUTTON(widget)) && (widget_temp != CELSIUS))
			{

				adj = (GtkAdjustment *) gtk_spin_button_get_adjustment(
						GTK_SPIN_BUTTON(widget));
				upper = adj->upper;
				value = adj->value;
				lower = adj->lower;
				if (widget_temp == FAHRENHEIT)
				{
					adj->value = f_to_c(value);
					adj->lower = f_to_c(lower);
					adj->upper = f_to_c(upper);
				}
				else /* Previous is kelvin */
				{
					adj->value = k_to_c(value);
					adj->lower = k_to_c(lower);
					adj->upper = k_to_c(upper);
				}

				gtk_adjustment_changed(adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_ENTRY(widget)) && (widget_temp != CELSIUS))
			{
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_RANGE(widget)) && (widget_temp != CELSIUS))
			{
				adj = (GtkAdjustment *) gtk_range_get_adjustment(
						GTK_RANGE(widget));
				upper = adj->upper;
				lower = adj->lower;
				value = adj->value;
				if (widget_temp == FAHRENHEIT)
				{
					adj->value = f_to_c(value);
					adj->lower = f_to_c(lower);
					adj->upper = f_to_c(upper);
				}
				else /* Previous is kelvin */
				{
					adj->value = k_to_c(value);
					adj->lower = k_to_c(lower);
					adj->upper = k_to_c(upper);
				}

				gtk_range_set_adjustment(GTK_RANGE(widget),adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
			}
			break;
		case KELVIN:
			/*printf("fahr %s\n",glade_get_widget_name(widget));*/
			if (GTK_IS_LABEL(widget))
			{
				if ((dep_obj) && (state))	
					text = (gchar *)OBJ_GET(widget,"alt_k_label");
				else
					text = (gchar *)OBJ_GET(widget,"k_label");
				gtk_label_set_text(GTK_LABEL(widget),text);
				//gtk_widget_modify_text(widget,GTK_STATE_NORMAL,&black);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));

			}
			if ((GTK_IS_SPIN_BUTTON(widget)) && (widget_temp != KELVIN))
			{

				adj = (GtkAdjustment *) gtk_spin_button_get_adjustment(
						GTK_SPIN_BUTTON(widget));
				upper = adj->upper;
				value = adj->value;
				lower = adj->lower;
				if (widget_temp == FAHRENHEIT)
				{
					adj->value = f_to_k(value);
					adj->lower = f_to_k(lower);
					adj->upper = f_to_k(upper);
				}
				else /* Previous is celsius */
				{
					adj->value = c_to_k(value);
					adj->lower = c_to_k(lower);
					adj->upper = c_to_k(upper);
				}

				gtk_adjustment_changed(adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_ENTRY(widget)) && (widget_temp != KELVIN))
			{
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_RANGE(widget)) && (widget_temp != KELVIN))
			{
				adj = (GtkAdjustment *) gtk_range_get_adjustment(
						GTK_RANGE(widget));
				upper = adj->upper;
				lower = adj->lower;
				value = adj->value;
				if (widget_temp == FAHRENHEIT)
				{
					adj->value = f_to_k(value);
					adj->lower = f_to_k(lower);
					adj->upper = f_to_k(upper);
				}
				else /* Previous is celsius */
				{
					adj->value = c_to_k(value);
					adj->lower = c_to_k(lower);
					adj->upper = c_to_k(upper);
				}

				gtk_range_set_adjustment(GTK_RANGE(widget),adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
			}
			break;
	}
}
Example #22
0
/*!
 \brief load_status_pf() is called to create the ECU status window, load the 
 settings from the StatusMapFile.
 */
G_MODULE_EXPORT void load_status_pf(void)
{
	gchar *filename = NULL;
	gint x = 0;
	gint y = 0;
	gint w = 0;
	gint h = 0;
	GtkWidget * window;
	GtkWidget * parent;
	GladeXML *xml = NULL;
	gboolean xml_result = FALSE;
	xmlDoc *doc = NULL;
	xmlNode *root_element = NULL;
	GladeXML *main_xml;
	Firmware_Details *firmware = NULL;
	CmdLineArgs *args =  NULL;
	
	args = DATA_GET(global_data,"args");
	firmware = DATA_GET(global_data,"firmware");

	g_return_if_fail(firmware);
	g_return_if_fail(args);

	if (!(DATA_GET(global_data,"interrogated")))
		return;
	if (!firmware->status_map_file)
	{
		//dbg_func(CRITICAL,g_strdup_printf(__FILE__": firmware->status_map_file is UNDEFINED,\n\texiting status window creation routine!!!!\n"));
		return;
	}

	gdk_threads_enter();
	set_title(g_strdup(_("Loading RT Status...")));
	filename = get_file(g_build_path(PSEP,RTSTATUS_DATA_DIR,firmware->status_map_file,NULL),g_strdup("xml"));
	if (!filename)
	{
		dbg_func(CRITICAL,g_strdup_printf(__FILE__": load_runtime_status()\n\t File \"%s.xml\" not found!!, exiting function\n",firmware->status_map_file));
		set_title(g_strdup(_("ERROR RT Statusfile DOES NOT EXIST!!!")));
		gdk_threads_leave();
		return;
	}
	main_xml = (GladeXML *)DATA_GET(global_data,"main_xml");
	xml = glade_xml_new(main_xml->filename,"status_window",NULL);
	window = glade_xml_get_widget(xml,"status_window");
	register_widget("status_window",window);
	gtk_window_set_focus_on_map((GtkWindow *)window,FALSE);
	gtk_window_set_title(GTK_WINDOW(window),_("ECU Status"));
	x = (GINT)DATA_GET(global_data,"status_x_origin");
	y = (GINT)DATA_GET(global_data,"status_y_origin");
	gtk_window_move(GTK_WINDOW(window),x,y);
	w = (GINT)DATA_GET(global_data,"status_width");
	h = (GINT)DATA_GET(global_data,"status_height");
	gtk_window_set_default_size(GTK_WINDOW(window),w,h);
	/*
	if (g_strcasecmp(firmware->actual_signature,DATA_GET(global_data,"last_signature")) == 0)
		gtk_window_set_default_size(GTK_WINDOW(window),w,h);
	else
		gtk_window_set_default_size(GTK_WINDOW(window),-1,-1);
		*/
//	gtk_window_resize(GTK_WINDOW(window),w,h);
//	g_object_set(window, "resizable", FALSE, NULL);
	parent = glade_xml_get_widget(xml,"status_vbox");
	glade_xml_signal_autoconnect(xml);

	LIBXML_TEST_VERSION

		doc = xmlReadFile(filename, NULL, 0);
	g_free(filename);
	if (doc == NULL)
	{
		printf(_("error: could not parse file %s\n"),filename);
		gdk_threads_leave();
		return;
	}

	root_element = xmlDocGetRootElement(doc);
	xml_result = load_status_xml_elements(root_element,parent);
	xmlFreeDoc(doc);
	xmlCleanupParser();

	if (xml_result == FALSE)
		gtk_widget_destroy(window);
	else if ((!args->hide_status) && (xml_result))
		gtk_widget_show_all(window);

	set_title(g_strdup(_("RT Status Loaded...")));
	gdk_threads_leave();
	return;
}