Beispiel #1
0
void load_rtv_defaults(xmlNode *node, Rtv_Data *rtv_data, Persona_Info **persona_info)
{
    Persona_Info *info = NULL;
    gpointer orig = NULL;
    gpointer value = NULL;
    gchar * persona = NULL;
    if (!generic_xml_gchar_find(node,"persona",&persona))
    {
        printf("MISSING \"persona\" key in RTV XML, contact author!\n");
        return;
    }

    if (g_hash_table_lookup_extended(rtv_data->persona_hash,persona,&orig,&value))
        info = (Persona_Info *)value;
    else /* We just disovered this persona,  CREATE the hashtable for it and store */
    {
        info = g_new0(Persona_Info, 1);
        info->hash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL);
        info->int_ext_hash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
        info->rtv_list = NULL;
        info->persona = g_strdup(persona);
        g_hash_table_insert(rtv_data->persona_hash,g_strdup(persona),(gpointer)info);
        g_array_append_val(rtv_data->persona_array,info);
    }
    g_free(persona);
    *persona_info = info;
}
Beispiel #2
0
void parse_derived_var(xmlNode *node, Rtv_Data *rtv_data, Persona_Info *info)
{
    gpointer orig = NULL;
    gpointer value = NULL;
    gchar *dlog_gui_name = NULL;
    gchar * tmpbuf = NULL;
    gchar ** vector = NULL;
    guint k = 0;
    gint tmpi = 0;

    g_return_if_fail(info);
    generic_xml_gchar_find(node,"dlog_gui_name",&dlog_gui_name);
    if(generic_xml_gchar_find(node,"internal_names",&tmpbuf))
    {
        vector = g_strsplit(tmpbuf,",",-1);
        g_free(tmpbuf);
        for (k=0; k<g_strv_length(vector); k++)
        {
            /* If we know about it, increase it's ref count */
            if (g_hash_table_lookup_extended(info->hash,vector[k],&orig,&value))
            {
                tmpi = (GINT)value + 1;
                g_hash_table_replace(info->hash,g_strdup(vector[k]),GINT_TO_POINTER(tmpi));
            }
            else
            {
                /*printf("inserting var %s with value %i\n",vector[k],1);*/
                g_hash_table_insert(info->hash,g_strdup(vector[k]),GINT_TO_POINTER(1));
                g_hash_table_insert(info->int_ext_hash,g_strdup(dlog_gui_name),g_strdup(vector[k]));
                info->rtv_list = g_list_prepend(info->rtv_list,g_strdup(dlog_gui_name));
            }
        }
        g_strfreev(vector);
        g_free(dlog_gui_name);
    }
    info->rtv_list = g_list_sort(info->rtv_list,sort);
}
/*!
  \brief load_rtv_xml_multi_expressions() is called when a "multi_expr_keys" key is found in
  a realtime map, and triggers the loading of al lthe keys/values that
  will allow megatunix to process a special variable that requires handling of
  multiple circumstances
  \param object is the place to store the retrieved data
  \param node is the xml node that contains the data
  \see check_dependancies
  */
G_MODULE_EXPORT void load_rtv_xml_multi_expressions(gconstpointer *object, xmlNode *node)
{
	gchar *tmpbuf = NULL;
	gchar ** keys = NULL;
	gchar ** l_limits = NULL;
	gchar ** u_limits = NULL;
	gchar ** ltables = NULL;
	gchar ** ul_mults = NULL;
	gchar ** ul_adds = NULL;
	gint num_keys = 0;
	gint i = 0;
	gint lowest = 0;
	gint highest = 0;
	GHashTable *hash = NULL;
	MultiExpr *multi = NULL;

	if (!generic_xml_gchar_find(node,"multi_expr_keys",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("Can't find \"multi_expr_keys\" in the xml, exiting!\n"));
		exit (-4);
	}
	else
	{
		keys = parse_keys(tmpbuf,&num_keys,",");
		g_free(tmpbuf);
	}

	if (!generic_xml_gchar_find(node,"lower_limits",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("Key \"lower_limits\" NOT FOUND in xml, EXITING!!\n"));
		exit (-4);
	}
	else
	{
		l_limits = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
	}
	if (!generic_xml_gchar_find(node,"upper_limits",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("Key \"upper_limits\" NOT FOUND in xml, EXITING!!\n"));
		exit (-4);
	}
	else
	{
		u_limits = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
	}
	if (!generic_xml_gchar_find(node,"multi_lookuptables",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("Key \"multi_lookuptables\" NOT FOUND in xml, EXITING!!\n"));
		exit (-4);
	}
	else
	{
		ltables = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
	}
	if (!generic_xml_gchar_find(node,"fromecu_mults",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("Key \"fromecu_mults\" NOT FOUND in xml, EXITING!!\n"));
		exit (-4);
	}
	else
	{
		ul_mults = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
	}
	if (!generic_xml_gchar_find(node,"fromecu_adds",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("Key \"fromecu_adds\" NOT FOUND in xml, EXITING!!\n"));
		exit (-4);
	}
	else
	{
		ul_adds = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
	}
	if (!generic_xml_gchar_find(node,"source_key",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("Key \"source_key\" NOT FOUND in xml, EXITING!!\n"));
		exit (-4);
	}
	else
	{
		DATA_SET_FULL(object,"source_key",g_strdup(tmpbuf),g_free);
		g_free(tmpbuf);
	}
	/* Create hash table to store structures for each one */
	hash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,free_multi_expr);
	lowest = G_MAXINT32;
	highest = G_MININT32;
	for (i=0;i<num_keys;i++)
	{
		multi = g_new0(MultiExpr, 1);
		multi->lower_limit = (GINT)strtol(l_limits[i],NULL,10);
		multi->upper_limit = (GINT)strtol(u_limits[i],NULL,10);
		if (multi->lower_limit < lowest)
			lowest = multi->lower_limit;
		if (multi->upper_limit > highest)
			highest = multi->upper_limit;

		if (strlen(ltables[i]) == 0)
			multi->lookuptable = NULL;
		else
			multi->lookuptable = g_strdup(ltables[i]);
		multi->fromecu_mult = g_new0(gfloat, 1);
		multi->fromecu_add = g_new0(gfloat, 1);
		*multi->fromecu_mult = (gfloat)g_strtod(ul_mults[i],NULL);
		*multi->fromecu_add = (gfloat)g_strtod(ul_adds[i],NULL);

		g_hash_table_insert(hash,g_strdup(keys[i]),multi);
	}
	DATA_SET_FULL(object,"real_lower",g_strdup_printf("%i",lowest),g_free);
	DATA_SET_FULL(object,"real_upper",g_strdup_printf("%i",highest),g_free);
	g_strfreev(l_limits);
	g_strfreev(u_limits);
	g_strfreev(ltables);
	g_strfreev(ul_mults);
	g_strfreev(ul_adds);
	g_strfreev(keys);
	DATA_SET_FULL(object,"multi_expr_hash",hash,g_hash_table_destroy);
}
/*! 
  \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(gconstpointer *object, xmlNode *node, 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 (!generic_xml_gint_find(node,name,&tmpi))
				MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_EMB_BIT, failure looking for:%s\n"),name);
			DATA_SET(object,name,GINT_TO_POINTER(tmpi));
			g_free(name);
			name=NULL;
			name=g_strdup_printf("%s_offset",symbol);
			if (!generic_xml_gint_find(node,name,&tmpi))
				MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_EMB_BIT, failure looking for:%s\n"),name);
			DATA_SET(object,name,GINT_TO_POINTER(tmpi));
			g_free(name);
			name=NULL;
			name=g_strdup_printf("%s_canID",symbol);
			if (!generic_xml_gint_find(node,name,&tmpi))
				tmpi = firmware->canID;
			DATA_SET(object,name,GINT_TO_POINTER(tmpi));
			g_free(name);
			name=NULL;
			name=g_strdup_printf("%s_bitmask",symbol);
			if (!generic_xml_gint_find(node,name,&tmpi))
				MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_EMB_BIT, failure looking for:%s\n"),name);
			DATA_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 (!generic_xml_gint_find(node,name,&tmpi))
				tmpi = firmware->canID;

			DATA_SET(object,name,GINT_TO_POINTER(tmpi));
			g_free(name);
			name=NULL;
			name=g_strdup_printf("%s_page",symbol);
			if (!generic_xml_gint_find(node,name,&tmpi))
				MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_VAR, failure looking for:%s\n"),name);
			DATA_SET(object,name,GINT_TO_POINTER(tmpi));
			g_free(name);
			name=NULL;
			name=g_strdup_printf("%s_offset",symbol);
			if (!generic_xml_gint_find(node,name,&tmpi))
				MTXDBG(RTMLOADER|COMPLEX_EXPR|CRITICAL,_("ECU_VAR, failure looking for:%s\n"),name);
			DATA_SET(object,name,GINT_TO_POINTER(tmpi));
			g_free(name);
			name=NULL;
			name=g_strdup_printf("%s_size",symbol);
			if (!generic_xml_gchar_find(node,name,&tmpbuf))
				tmpi = MTX_U08;
			else
			{
				tmpi = translate_string_f(tmpbuf);
				g_free(tmpbuf);
			}
			DATA_SET(object,name,GINT_TO_POINTER(tmpi));
			g_free(name);
			name=NULL;
			break;
		default:
			EXIT();
			return;
			break;
	}
	EXIT();
	return;
}