/*! \brief ECU specific function to set a value in the representation of ECU memory \param canID is the CAN Identifier \param page is the MTX page(may not be the same as the ECU page) \param offset is the offset in bytes from the beginning of this page \param size is the size representation enumeration \param new_data is the new value to store */ G_MODULE_EXPORT void ms_set_ecu_data(gint canID, gint page, gint offset, DataSize size, gint new_data) { Firmware_Details *firmware = NULL; static gint (*_set_sized_data)(guint8 *, gint, DataSize, gint, gboolean) = NULL; if (!_set_sized_data) get_symbol_f("_set_sized_data",(void **)&_set_sized_data); g_return_if_fail(_set_sized_data); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); _set_sized_data(firmware->ecu_data[page],offset,size,new_data,firmware->bigendian); }
/*! \brief returns the ECU data corresponding to the fields attached to the data object, data can be either a GtkWidget pointer or a gconstpointer \param data pointer to container, should contain the following fields offset, size, and location_id or page \returns the value at that ECU memory location */ G_MODULE_EXPORT gint get_ecu_data(gpointer data) { gint locID = 0; gint page = 0; gint offset = 0; DataSize size = MTX_U08; gint value = 0 ; GtkWidget *widget = NULL; gconstpointer *container = NULL; Firmware_Details *firmware = NULL; static gint (*_get_sized_data)(guint8 *, gint, DataSize, gboolean) = NULL; ENTER(); if (!_get_sized_data) get_symbol_f("_get_sized_data",(void **)&_get_sized_data); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); widget = (GtkWidget *)data; container = (gconstpointer *)data; if (GTK_IS_WIDGET(widget)) { offset = (GINT)OBJ_GET(widget,"offset"); size = (DataSize)(GINT)OBJ_GET(widget,"size"); if (OBJ_GET(widget,"location_id")) { locID = (GINT)OBJ_GET(widget,"location_id"); g_return_val_if_fail(libreems_find_mtx_page(locID, &page),0);; } else if (OBJ_GET(widget,"page")) page = (GINT)OBJ_GET(widget,"page"); } else { offset = (GINT)DATA_GET(container,"offset"); size = (DataSize)(GINT)DATA_GET(container,"size"); if (DATA_GET(container,"location_id")) { locID = (GINT)DATA_GET(container,"location_id"); g_return_val_if_fail(libreems_find_mtx_page(locID, &page),0);; } else if (DATA_GET(container,"page")) page = (GINT)DATA_GET(container,"page"); } /* Sanity checking */ g_return_val_if_fail(firmware,0); g_return_val_if_fail(firmware->page_params,0); g_return_val_if_fail(firmware->page_params[page],0); g_return_val_if_fail((offset >= 0) && (offset < firmware->page_params[page]->length),0); EXIT(); return _get_sized_data(firmware->ecu_data[page],offset,size,firmware->bigendian); }
/*! \brief initializes the plugin, referencing all needed functions \param data is the pointer to the global data container */ G_MODULE_EXPORT void plugin_init(gconstpointer *data) { global_data = data; *(void **)(&error_msg_f) = DATA_GET(global_data,"error_msg_f"); g_assert(error_msg_f); *(void **)(&get_symbol_f) = DATA_GET(global_data,"get_symbol_f"); g_assert(get_symbol_f); get_symbol_f("dbg_func",(void **)&dbg_func_f); ENTER(); /* Initializes function pointers since on Winblows was can NOT call functions within the program that loaded this DLL, so we need to pass pointers over and assign them here. */ register_ecu_enums(); EXIT(); return; }
/*! \brief freeems_get_ecu_data_backup() is a func to return the data requested. \param canID, CANbus ID (unused currently) \param locID, Location ID (internal to ECU) \param offset (RAW BYTE offset) \param size (size to be returned... */ G_MODULE_EXPORT gint freeems_get_ecu_data_backup(gint canID, gint locID, gint offset, DataSize size) { gint page = 0; Firmware_Details *firmware = NULL; static gint (*_get_sized_data)(guint8 *, gint, DataSize, gboolean) = NULL; if (!_get_sized_data) get_symbol_f("_get_sized_data",(void*)&_get_sized_data); firmware = DATA_GET(global_data,"firmware"); g_return_val_if_fail(freeems_find_mtx_page(locID, &page),0); g_return_val_if_fail(firmware,0); g_return_val_if_fail(firmware->page_params,0); g_return_val_if_fail(firmware->page_params[page],0); g_return_val_if_fail((offset >= 0) && (offset < firmware->page_params[page]->length),0); return _get_sized_data(firmware->ecu_data_backup[page],offset,size,firmware->bigendian); }
/*! \brief Sets the ECU data at the coordinates specified in the data pointer \param data is the pointer to either a GtkWidget pointer or a gconstpointer object container the coordinate information as to where to store the new data. \param new is the pointer to the new data to be stored */ G_MODULE_EXPORT void set_ecu_data(gpointer data, gint *new_data) { gint canID = 0; gint page = 0; gint offset = 0; DataSize size = MTX_U08; gint value = 0; gconstpointer *container = NULL; GtkWidget *widget = NULL; Firmware_Details *firmware = NULL; static gint (*_set_sized_data)(guint8 *, gint, DataSize, gint, gboolean) = NULL; if (!_set_sized_data) get_symbol_f("_set_sized_data",(void **)&_set_sized_data); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); g_return_if_fail(firmware); g_return_if_fail(_set_sized_data); widget = (GtkWidget *)data; container = (gconstpointer *)data; if (GTK_IS_WIDGET(widget)) { canID = (GINT)OBJ_GET(widget,"canID"); page = (GINT)OBJ_GET(widget,"page"); offset = (GINT)OBJ_GET(widget,"offset"); size = (DataSize)(GINT)OBJ_GET(widget,"size"); if (new_data) value = *new_data; else value = (GINT)OBJ_GET(widget,"value"); } else { canID = (GINT)DATA_GET(container,"canID"); page = (GINT)DATA_GET(container,"page"); offset = (GINT)DATA_GET(container,"offset"); size = (DataSize)(GINT)DATA_GET(container,"size"); if (new_data) value = *new_data; else value = (GINT)DATA_GET(container,"value"); } _set_sized_data(firmware->ecu_data[page],offset,size,value,firmware->bigendian); }
/*! \brief Megasquirrt specific function to return the data from the "last" buffer \param canID is the CAN Identifier (currently unused) \param page is the ecu firmware page \param offset is the RAW BYTE offset \param size is the size to be returned \returns the value requested or 0 on error */ G_MODULE_EXPORT gint ms_get_ecu_data_last(gint canID, gint page, gint offset, DataSize size) { Firmware_Details *firmware = NULL; static gint (*_get_sized_data)(guint8 *, gint, DataSize, gboolean) = NULL; if (!_get_sized_data) get_symbol_f("_get_sized_data",(void*)&_get_sized_data); g_return_val_if_fail(_get_sized_data,0); firmware = DATA_GET(global_data,"firmware"); g_return_val_if_fail(firmware,0); g_return_val_if_fail(firmware->page_params,0); g_return_val_if_fail(page < firmware->total_pages,0); g_return_val_if_fail(page >= 0,0); g_return_val_if_fail(firmware->page_params[page],0); g_return_val_if_fail(((offset >= 0 ) && (offset < firmware->page_params[page]->length)),0); return _get_sized_data(firmware->ecu_data_last[page],offset,size,firmware->bigendian); }
/*! \brief A generic function to returns the data from the representation of ECU memory. This will call an ECU specific function to do the heavy lifting \param data is either a GtkWidget pointer or a gconstpointer which contains name:value associations describng the location to return \returns the value requested or 0 if error */ G_MODULE_EXPORT gint get_ecu_data(gpointer data) { gint canID = 0; gint page = 0; gint offset = 0; DataSize size = MTX_U08; gint value = 0 ; GtkWidget *widget = NULL; gconstpointer *container = NULL; Firmware_Details *firmware = NULL; static gint (*_get_sized_data)(guint8 *, gint, DataSize, gboolean) = NULL; if (!_get_sized_data) get_symbol_f("_get_sized_data",(void*)&_get_sized_data); g_return_val_if_fail(_get_sized_data,0); firmware = DATA_GET(global_data,"firmware"); /* Sanity checking */ g_return_val_if_fail(data,0); g_return_val_if_fail(firmware,0); g_return_val_if_fail(firmware->page_params,0); g_return_val_if_fail(firmware->page_params[page],0); g_return_val_if_fail(((offset >= 0 ) && (offset < firmware->page_params[page]->length)),0); widget = (GtkWidget *)data; container = (gconstpointer *)data; if (GTK_IS_WIDGET(widget)) { canID = (GINT)OBJ_GET(widget,"canID"); page = (GINT)OBJ_GET(widget,"page"); offset = (GINT)OBJ_GET(widget,"offset"); size = (DataSize)OBJ_GET(widget,"size"); } else { canID = (GINT)DATA_GET(container,"canID"); page = (GINT)DATA_GET(container,"page"); offset = (GINT)DATA_GET(container,"offset"); size = (DataSize)DATA_GET(container,"size"); } return _get_sized_data(firmware->ecu_data[page],offset,size,firmware->bigendian); }
/*! \brief returns the ECU data at the location coordinates provided \param canID is the CANbus ID (unused currently) \param locID is the Location ID (internal to ECU) \param offset is the (RAW BYTE offset) \param size is the (size to be returned) \returns the value at those specific memory coordinates */ G_MODULE_EXPORT gint libreems_get_ecu_data(gint canID, gint locID, gint offset, DataSize size) { Firmware_Details *firmware = NULL; static gint (*_get_sized_data)(guint8 *, gint, DataSize, gboolean) = NULL; gint page = 0; ENTER(); if (!_get_sized_data) get_symbol_f("_get_sized_data",(void **)&_get_sized_data); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); /* Sanity checking */ g_return_val_if_fail(libreems_find_mtx_page(locID, &page),0); g_return_val_if_fail(firmware,0); g_return_val_if_fail(firmware->page_params,0); g_return_val_if_fail(firmware->page_params[page],0); g_return_val_if_fail((offset >= 0) && (offset < firmware->page_params[page]->length),0); EXIT(); return _get_sized_data(firmware->ecu_data[page],offset,size,firmware->bigendian); }
/*! \brief ECU specific function to set a value in the representation of ECU memory \param canID is the CAN Identifier \param locID is the Location ID \param offset is the offset in bytes from thebeginning on this location ID \param size is the size representation enumeration \param newval is the new value to store */ G_MODULE_EXPORT void libreems_set_ecu_data(gint canID, gint locID, gint offset, DataSize size, gint newval) { gint page = 0; Firmware_Details *firmware = NULL; static gint (*_set_sized_data)(guint8 *, gint, DataSize, gint, gboolean) = NULL; ENTER(); if (!_set_sized_data) get_symbol_f("_set_sized_data",(void **)&_set_sized_data); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); g_return_if_fail(libreems_find_mtx_page(locID, &page)); g_return_if_fail(firmware); g_return_if_fail(firmware->page_params); g_return_if_fail(firmware->page_params[page]); g_return_if_fail((offset >= 0) && (offset < firmware->page_params[page]->length)); _set_sized_data(firmware->ecu_data[page],offset,size,newval,firmware->bigendian); EXIT(); return; }
/*! \brief General purpose handler to hide/show Battery calibrate window \param widget is a pointer to the widget clicked \param data is unused \returns TRUE */ G_MODULE_EXPORT gboolean show_battery_calibrator_window(GtkWidget *widget, gpointer data) { static GtkWidget *window = NULL; GtkWidget *item = NULL; GladeXML *main_xml = NULL; GladeXML *xml = NULL; gfloat *tmpf = NULL; Firmware_Details *firmware = NULL; GList ***ecu_widgets; void (*update_widget_f)(gpointer, gpointer) = NULL; ENTER(); if (!update_widget_f) get_symbol_f("update_widget",(void **)&update_widget_f); ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets"); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); main_xml = (GladeXML *)DATA_GET(global_data,"main_xml"); if ((!main_xml) || (DATA_GET(global_data,"leaving"))) { EXIT(); return TRUE; } if (!GTK_IS_WIDGET(window)) { xml = glade_xml_new(main_xml->filename,"battery_calibration_window",NULL); window = glade_xml_get_widget(xml,"battery_calibration_window"); glade_xml_signal_autoconnect(xml); item = glade_xml_get_widget(xml,"batt0_entry"); register_widget_f("batt0_entry",item); OBJ_SET(item,"page",GINT_TO_POINTER(0)); OBJ_SET(item,"offset",GINT_TO_POINTER(522)); OBJ_SET(item,"handler",GINT_TO_POINTER(GENERIC)); OBJ_SET(item,"dl_type",GINT_TO_POINTER(IMMEDIATE)); OBJ_SET(item,"last_value",GINT_TO_POINTER(-G_MAXINT)); OBJ_SET(item,"precision",GINT_TO_POINTER(1)); OBJ_SET(item,"size",GINT_TO_POINTER(MTX_S16)); tmpf = g_new0(gfloat, 1); *tmpf = 0.1; OBJ_SET_FULL(item,"fromecu_mult",tmpf,g_free); ecu_widgets[0][522] = g_list_prepend( ecu_widgets[0][522], (gpointer)item); item = glade_xml_get_widget(xml,"battmax_entry"); register_widget_f("battmax_entry",item); OBJ_SET(item,"page",GINT_TO_POINTER(0)); OBJ_SET(item,"offset",GINT_TO_POINTER(524)); OBJ_SET(item,"handler",GINT_TO_POINTER(GENERIC)); OBJ_SET(item,"dl_type",GINT_TO_POINTER(IMMEDIATE)); OBJ_SET(item,"last_value",GINT_TO_POINTER(-G_MAXINT)); OBJ_SET(item,"precision",GINT_TO_POINTER(1)); OBJ_SET(item,"size",GINT_TO_POINTER(MTX_S16)); tmpf = g_new0(gfloat, 1); *tmpf = 0.1; OBJ_SET_FULL(item,"fromecu_mult",tmpf,g_free); ecu_widgets[0][524] = g_list_prepend( ecu_widgets[0][524], (gpointer)item); /* Force them to update */ g_list_foreach(ecu_widgets[0][522],update_widget_f,NULL); g_list_foreach(ecu_widgets[0][524],update_widget_f,NULL); item = glade_xml_get_widget(xml,"get_data_button"); OBJ_SET(item,"handler",GINT_TO_POINTER(READ_VE_CONST)); OBJ_SET_FULL(item,"bind_to_list",g_strdup("get_data_buttons"),g_free); item = glade_xml_get_widget(xml,"burn_data_button"); OBJ_SET(item,"handler",GINT_TO_POINTER(BURN_FLASH)); OBJ_SET_FULL(item,"bind_to_list",g_strdup("burners"),g_free); bind_to_lists_f(item,"burners"); gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(lookup_widget_f("main_window"))); gtk_widget_show(GTK_WIDGET(window)); EXIT(); return TRUE; } #if GTK_MINOR_VERSION >= 18 if (gtk_widget_get_visible(GTK_WIDGET(window))) #else if (GTK_WIDGET_VISIBLE(GTK_WIDGET(window))) #endif gtk_widget_hide(GTK_WIDGET(window)); else gtk_widget_show(GTK_WIDGET(window)); EXIT(); return TRUE; }
/*! \brief General purpose handler to hide/show Sensor calibrate window \param widget is a pointer to the widget clicked \param data is unused \returns TRUE */ G_MODULE_EXPORT gboolean show_ms2_afr_calibrator_window(GtkWidget *widget, gpointer data) { static GtkWidget *window = NULL; GtkWidget *item = NULL; GtkWidget *item2 = NULL; GladeXML *main_xml = NULL; GladeXML *xml = NULL; Firmware_Details *firmware = NULL; gboolean (*populate_afr_calibrator_combo_f)(GtkWidget *) = NULL; ENTER(); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); main_xml = (GladeXML *)DATA_GET(global_data,"main_xml"); if ((!main_xml) || (DATA_GET(global_data,"leaving"))) { EXIT(); return TRUE; } if (!GTK_IS_WIDGET(window)) { xml = glade_xml_new(main_xml->filename,"ms2_afr_calibrator_window",NULL); window = glade_xml_get_widget(xml,"ms2_afr_calibrator_window"); glade_xml_signal_autoconnect(xml); item = glade_xml_get_widget(xml,"ego_sensor_combo"); register_widget_f("afr_calibrate_ego_sensor_combo",item); if (get_symbol_f("populate_afr_calibrator_combo",(void **)&populate_afr_calibrator_combo_f)) populate_afr_calibrator_combo_f(item); item2 = glade_xml_get_widget(xml,"generic_wideband_frame"); OBJ_SET(item,"generic_controls",item2); item = glade_xml_get_widget(xml,"voltage1_entry"); register_widget_f("voltage1_entry",item); OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free); OBJ_SET_FULL(item,"raw_upper",g_strdup("5"),g_free); OBJ_SET(item,"precision",GINT_TO_POINTER(1)); item = glade_xml_get_widget(xml,"voltage2_entry"); register_widget_f("voltage2_entry",item); OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free); OBJ_SET_FULL(item,"raw_upper",g_strdup("5"),g_free); OBJ_SET(item,"precision",GINT_TO_POINTER(1)); item = glade_xml_get_widget(xml,"afr1_entry"); register_widget_f("afr1_entry",item); OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free); OBJ_SET_FULL(item,"raw_upper",g_strdup("99"),g_free); OBJ_SET(item,"precision",GINT_TO_POINTER(1)); item = glade_xml_get_widget(xml,"afr2_entry"); register_widget_f("afr2_entry",item); OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free); OBJ_SET_FULL(item,"raw_upper",g_strdup("99"),g_free); OBJ_SET(item,"precision",GINT_TO_POINTER(1)); gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(lookup_widget_f("main_window"))); gtk_widget_show(GTK_WIDGET(window)); EXIT(); return TRUE; } #if GTK_MINOR_VERSION >= 18 if (gtk_widget_get_visible(GTK_WIDGET(window))) #else if (GTK_WIDGET_VISIBLE(GTK_WIDGET(window))) #endif gtk_widget_hide(GTK_WIDGET(window)); else gtk_widget_show(GTK_WIDGET(window)); EXIT(); return TRUE; }
/*! \brief initializes the MS2 plugin, connects to all functions needed in core megatunix and registers any needed enumerations \param data is the pointer to the global data container */ G_MODULE_EXPORT void plugin_init(gconstpointer *data) { global_data = data; *(void **)(&error_msg_f) = DATA_GET(global_data,"error_msg_f"); g_assert(error_msg_f); *(void **)(&get_symbol_f) = DATA_GET(global_data,"get_symbol_f"); g_assert(get_symbol_f); get_symbol_f("dbg_func",(void **)&dbg_func_f); ENTER(); /* Initializes function pointers since on Winblows was can NOT call functions within the program that loaded this DLL, so we need to pass pointers over and assign them here. */ get_symbol_f("alter_widget_state",(void **)&alter_widget_state_f); get_symbol_f("bind_to_lists",(void **)&bind_to_lists_f); get_symbol_f("convert_before_download",(void **)&convert_before_download_f); get_symbol_f("calc_value",(void **)&calc_value_f); get_symbol_f("convert_temps",(void **)&convert_temps_f); get_symbol_f("convert_after_upload",(void **)&convert_after_upload_f); get_symbol_f("create_rtv_single_bit_state_watch",(void **)&create_rtv_single_bit_state_watch_f); get_symbol_f("evaluator_create",(void **)&evaluator_create_f); get_symbol_f("evaluator_destroy",(void **)&evaluator_destroy_f); get_symbol_f("evaluator_evaluate_x",(void **)&evaluator_evaluate_x_f); get_symbol_f("f_to_c",(void **)&f_to_c_f); get_symbol_f("f_to_k",(void **)&f_to_k_f); get_symbol_f("get_essential_bits",(void **)&get_essential_bits_f); get_symbol_f("get_extreme_from_size",(void **)&get_extreme_from_size_f); get_symbol_f("get_bitshift",(void **)&get_bitshift_f); get_symbol_f("initialize_gc",(void **)&initialize_gc_f); get_symbol_f("io_cmd",(void **)&io_cmd_f); get_symbol_f("lookup_current_value",(void **)&lookup_current_value_f); get_symbol_f("lookup_widget",(void **)&lookup_widget_f); get_symbol_f("mask_entry_new_with_mask_w",(void **)&mask_entry_new_with_mask_f); get_symbol_f("ms_get_ecu_data",(void **)&ms_get_ecu_data_f); get_symbol_f("ms_send_to_ecu",(void **)&ms_send_to_ecu_f); get_symbol_f("register_widget",(void **)®ister_widget_f); get_symbol_f("remove_from_lists",(void **)&remove_from_lists_f); get_symbol_f("search_model",(void **)&search_model_f); get_symbol_f("signal_read_rtvars",(void **)&signal_read_rtvars_f); get_symbol_f("start_tickler",(void **)&start_tickler_f); get_symbol_f("stop_tickler",(void **)&stop_tickler_f); get_symbol_f("temp_to_host",(void **)&temp_to_host_f); get_symbol_f("update_widget",(void **)&update_widget_f); register_ecu_enums(); EXIT(); return; }
/*! \brief initializes the jimstim plugin, sets up all function references and enumerations \param data is the pointer to the global data structure */ G_MODULE_EXPORT void plugin_init(gconstpointer *data) { global_data = data; /* Initializes function pointers since on Winblows was can NOT call functions within the program that loaded this DLL, so we need to pass pointers over and assign them here. */ *(void **)(&error_msg_f) = DATA_GET(global_data,"error_msg_f"); g_assert(error_msg_f); *(void**)(&get_symbol_f) = DATA_GET(global_data,"get_symbol_f"); g_assert(get_symbol_f); get_symbol_f("convert_after_upload",(void **)&convert_after_upload_f); get_symbol_f("convert_before_download",(void **)&convert_before_download_f); get_symbol_f("dbg_func",(void **)&dbg_func_f); get_symbol_f("get_essential_bits",(void **)&get_essential_bits_f); get_symbol_f("get_list",(void **)&get_list_f); get_symbol_f("initialize_outputdata",(void **)&initialize_outputdata_f); get_symbol_f("io_cmd",(void **)&io_cmd_f); get_symbol_f("lookup_widget",(void **)&lookup_widget_f); get_symbol_f("ms_send_to_ecu",(void **)&ms_send_to_ecu_f); get_symbol_f("search_model",(void **)&search_model_f); get_symbol_f("set_widget_sensitive",(void **)&set_widget_sensitive_f); get_symbol_f("start_tickler",(void **)&start_tickler_f); get_symbol_f("std_combo_handler",(void **)&std_combo_handler_f); get_symbol_f("stop_tickler",(void **)&stop_tickler_f); get_symbol_f("update_logbar",(void **)&update_logbar_f); register_ecu_enums(); }
/*! \brief Sets the ECU data at the coordinates specified in the data pointer \param data is the pointer to either a GtkWidget pointer or a gconstpointer object container the coordinate information as to where to store the new data. \param new is the pointer to the new data to be stored */ G_MODULE_EXPORT void set_ecu_data(gpointer data, gint *newval) { gint canID = 0; gint locID = 0; gint page = 0; gint offset = 0; gint value = 0; DataSize size = MTX_U08; GtkWidget *widget = NULL; gconstpointer *container = NULL; Firmware_Details *firmware = NULL; static gint (*_set_sized_data)(guint8 *, gint, DataSize, gint, gboolean) = NULL; ENTER(); if (!_set_sized_data) get_symbol_f("_set_sized_data",(void **)&_set_sized_data); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); widget = (GtkWidget *)data; container = (gconstpointer *)data; if (GTK_IS_WIDGET(data)) { if (OBJ_GET(widget,"location_id")) { locID = (GINT)OBJ_GET(widget,"location_id"); g_return_if_fail(libreems_find_mtx_page(locID, &page)); } else if (OBJ_GET(widget,"page")) page = (GINT)OBJ_GET(widget,"page"); canID = (GINT)OBJ_GET(widget,"canID"); offset = (GINT)OBJ_GET(widget,"offset"); size = (DataSize)(GINT)OBJ_GET(widget,"size"); if (newval) value = *newval; else value = (GINT)OBJ_GET(widget,"value"); } else { if (DATA_GET(container,"location_id")) { locID = (GINT)DATA_GET(container,"location_id"); g_return_if_fail(libreems_find_mtx_page(locID, &page)); } else if (DATA_GET(container,"page")) page = (GINT)DATA_GET(container,"page"); canID = (GINT)DATA_GET(container,"canID"); offset = (GINT)DATA_GET(container,"offset"); size = (DataSize)(GINT)DATA_GET(container,"size"); if (newval) value = *newval; else value = (GINT)DATA_GET(container,"value"); } g_return_if_fail(firmware); g_return_if_fail(firmware->page_params); g_return_if_fail(firmware->page_params[page]); g_return_if_fail((offset >= 0) && (offset < firmware->page_params[page]->length)); _set_sized_data(firmware->ecu_data[page],offset,size,value,firmware->bigendian); EXIT(); return; }
/*! \brief Sets up the main gui menu with stuff common to this ECU persona. It checks for the presence of an ecu/firmware specific handler and runs that as well \param xml is a pointer to the GladeXML structure for the core Gui */ G_MODULE_EXPORT void common_plugin_menu_setup(GladeXML *xml) { void (*ecu_plugin_menu_setup)(GladeXML *) = NULL; GtkWidget *menu = NULL; GtkWidget *item = NULL; GtkWidget *image = NULL; /* View->Tabs Menu */ /* menu = glade_xml_get_widget (xml, "goto_tab1_menu"); item = gtk_menu_item_new_with_mnemonic("_Boost Tables"); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(jump_to_tab_f),NULL); OBJ_SET(item,"target_tab",GINT_TO_POINTER(BOOSTTABLES_TAB)); if (!check_tab_existance_f(BOOSTTABLES_TAB)) gtk_widget_set_sensitive(item,FALSE); else gtk_widget_set_sensitive(item,TRUE); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); item = gtk_menu_item_new_with_mnemonic("_Staging Tables"); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(jump_to_tab_f),NULL); OBJ_SET(item,"target_tab",GINT_TO_POINTER(STAGING_TAB)); if (!check_tab_existance_f(STAGING_TAB)) gtk_widget_set_sensitive(item,FALSE); else gtk_widget_set_sensitive(item,TRUE); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); item = gtk_menu_item_new_with_mnemonic("_Rotary Tables"); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(jump_to_tab_f),NULL); OBJ_SET(item,"target_tab",GINT_TO_POINTER(ROTARYTABLES_TAB)); if (!check_tab_existance_f(ROTARYTABLES_TAB)) gtk_widget_set_sensitive(item,FALSE); else gtk_widget_set_sensitive(item,TRUE); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); gtk_widget_show_all(menu); */ /* View Menu */ menu = glade_xml_get_widget (xml, "view_menu_menu"); item = gtk_image_menu_item_new_with_mnemonic("ECU _Errors"); image = gtk_image_new_from_stock("gtk-stop",GTK_ICON_SIZE_MENU); g_object_set(item,"image",image,NULL); if (gtk_minor_version >= 16) g_object_set(item,"always-show-image",TRUE,NULL); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(jump_to_tab_f),NULL); OBJ_SET(item,"target_tab",GINT_TO_POINTER(ERROR_STATUS_TAB)); if (!check_tab_existance_f(ERROR_STATUS_TAB)) gtk_widget_set_sensitive(item,FALSE); else gtk_widget_set_sensitive(item,TRUE); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); gtk_widget_show_all(menu); /* Tuning Menu */ /* menu = glade_xml_get_widget (xml, "generate1_menu"); item = gtk_menu_item_new_with_mnemonic("_Ignition Map"); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(show_create_ignition_map_window),NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); gtk_widget_show_all(menu); */ /* Tools Menu */ menu = glade_xml_get_widget (xml, "tools_menu_menu"); item = gtk_image_menu_item_new_with_mnemonic("_Reset ALL Counters"); image = gtk_image_new_from_stock("gtk-execute",GTK_ICON_SIZE_MENU); g_object_set(item,"image",image,NULL); if (gtk_minor_version >= 16) g_object_set(item,"always-show-image",TRUE,NULL); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(reset_counters),NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); item = gtk_image_menu_item_new_with_mnemonic("_Stop HiSpeed Streaming"); image = gtk_image_new_from_stock("gtk-stop",GTK_ICON_SIZE_MENU); g_object_set(item,"image",image,NULL); if (gtk_minor_version >= 16) g_object_set(item,"always-show-image",TRUE,NULL); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(stop_streaming),NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); item = gtk_image_menu_item_new_with_mnemonic("_Start HiSpeed Streaming"); image = gtk_image_new_from_stock("gtk-go-forward",GTK_ICON_SIZE_MENU); g_object_set(item,"image",image,NULL); if (gtk_minor_version >= 16) g_object_set(item,"always-show-image",TRUE,NULL); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(start_streaming),NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); item = gtk_image_menu_item_new_with_mnemonic("_Soft Boot ECU"); image = gtk_image_new_from_stock("gtk-refresh",GTK_ICON_SIZE_MENU); g_object_set(item,"image",image,NULL); if (gtk_minor_version >= 16) g_object_set(item,"always-show-image",TRUE,NULL); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(soft_boot_ecu),NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); item = gtk_image_menu_item_new_with_mnemonic("_Hard Boot ECU"); image = gtk_image_new_from_stock("gtk-help",GTK_ICON_SIZE_MENU); g_object_set(item,"image",image,NULL); if (gtk_minor_version >= 16) g_object_set(item,"always-show-image",TRUE,NULL); g_signal_connect(G_OBJECT(item),"activate",G_CALLBACK(hard_boot_ecu),NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); gtk_widget_show_all(menu); if (get_symbol_f("ecu_plugin_menu_setup",(void **)&ecu_plugin_menu_setup)) ecu_plugin_menu_setup(xml); return; }
/*! \brief General purpose handler to hide/show tps calibrate window \param widget is the pointer to the TPS caliobration window \param data is unused */ G_MODULE_EXPORT gboolean show_tps_calibrator_window(GtkWidget *widget, gpointer data) { static GtkWidget *window = NULL; GtkWidget *item = NULL; GladeXML *main_xml = NULL; GladeXML *xml = NULL; Firmware_Details *firmware = NULL; GList ***ecu_widgets = NULL; void (*update_widget_f)(gpointer, gpointer) = NULL; ENTER(); if (!update_widget_f) get_symbol_f("update_widget",(void **)&update_widget_f); ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets"); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); main_xml = (GladeXML *)DATA_GET(global_data,"main_xml"); if ((!main_xml) || (DATA_GET(global_data,"leaving"))) { EXIT(); return TRUE; } if (!GTK_IS_WIDGET(window)) { xml = glade_xml_new(main_xml->filename,"calibrate_tps_window",NULL); window = glade_xml_get_widget(xml,"calibrate_tps_window"); glade_xml_signal_autoconnect(xml); item = glade_xml_get_widget(xml,"tpsMin_entry"); register_widget_f("tpsMin_entry",item); OBJ_SET(item,"handler",GINT_TO_POINTER(GENERIC)); OBJ_SET(item,"dl_type",GINT_TO_POINTER(IMMEDIATE)); OBJ_SET(item,"last_value",GINT_TO_POINTER(-G_MAXINT)); OBJ_SET(item,"page",GINT_TO_POINTER(0)); if (firmware->capabilities & PIS) OBJ_SET(item,"offset",GINT_TO_POINTER(2676)); else OBJ_SET(item,"offset",GINT_TO_POINTER(518)); OBJ_SET(item,"size",GINT_TO_POINTER(MTX_S16)); OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free); if (firmware->capabilities & PIS) { OBJ_SET_FULL(item,"raw_upper",g_strdup("255"),g_free); OBJ_SET(item,"precision",GINT_TO_POINTER(0)); ecu_widgets[0][2676] = g_list_prepend( ecu_widgets[0][2676], (gpointer)item); } else { OBJ_SET_FULL(item,"raw_upper",g_strdup("2047"),g_free); OBJ_SET(item,"precision",GINT_TO_POINTER(0)); ecu_widgets[0][518] = g_list_prepend( ecu_widgets[0][518], (gpointer)item); } item = glade_xml_get_widget(xml,"tpsMax_entry"); register_widget_f("tpsMax_entry",item); OBJ_SET(item,"handler",GINT_TO_POINTER(GENERIC)); OBJ_SET(item,"dl_type",GINT_TO_POINTER(IMMEDIATE)); OBJ_SET(item,"last_value",GINT_TO_POINTER(-G_MAXINT)); OBJ_SET(item,"page",GINT_TO_POINTER(0)); if (firmware->capabilities & PIS) OBJ_SET(item,"offset",GINT_TO_POINTER(2678)); else OBJ_SET(item,"offset",GINT_TO_POINTER(520)); OBJ_SET(item,"size",GINT_TO_POINTER(MTX_S16)); OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free); if (firmware->capabilities & PIS) { OBJ_SET_FULL(item,"raw_upper",g_strdup("255"),g_free); OBJ_SET(item,"precision",GINT_TO_POINTER(0)); ecu_widgets[0][2678] = g_list_prepend( ecu_widgets[0][2678], (gpointer)item); /* Force them to update */ g_list_foreach(ecu_widgets[0][2676],update_widget_f,NULL); g_list_foreach(ecu_widgets[0][2678],update_widget_f,NULL); } else { OBJ_SET_FULL(item,"raw_upper",g_strdup("2047"),g_free); OBJ_SET(item,"precision",GINT_TO_POINTER(0)); ecu_widgets[0][520] = g_list_prepend( ecu_widgets[0][520], (gpointer)item); /* Force them to update */ g_list_foreach(ecu_widgets[0][518],update_widget_f,NULL); g_list_foreach(ecu_widgets[0][520],update_widget_f,NULL); } item = glade_xml_get_widget(xml,"get_tps_button_min"); OBJ_SET(item,"handler",GINT_TO_POINTER(GET_CURR_TPS)); if (firmware->capabilities & PIS) OBJ_SET_FULL(item,"source",g_strdup("status_adc_tps"),g_free); else OBJ_SET_FULL(item,"source",g_strdup("tpsADC"),g_free); OBJ_SET_FULL(item,"dest_widget",g_strdup("tpsMin_entry"),g_free); item = glade_xml_get_widget(xml,"get_tps_button_max"); OBJ_SET(item,"handler",GINT_TO_POINTER(GET_CURR_TPS)); if (firmware->capabilities & PIS) OBJ_SET_FULL(item,"source",g_strdup("status_adc_tps"),g_free); else OBJ_SET_FULL(item,"source",g_strdup("tpsADC"),g_free); OBJ_SET_FULL(item,"dest_widget",g_strdup("tpsMax_entry"),g_free); gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(lookup_widget_f("main_window"))); gtk_widget_show(GTK_WIDGET(window)); EXIT(); return TRUE; } #if GTK_MINOR_VERSION >=18 if (gtk_widget_get_visible(GTK_WIDGET(window))) #else if (GTK_WIDGET_VISIBLE(GTK_WIDGET(window))) #endif gtk_widget_hide(GTK_WIDGET(window)); else gtk_widget_show(GTK_WIDGET(window)); EXIT(); return TRUE; }
G_MODULE_EXPORT void *serial_repair_thread(gpointer data) { /* We got sent here because of one of the following occurred: * Serial port isn't opened yet (app just fired up) * Serial I/O errors (missing data, or failures reading/writing) * - This includes things like pulling the RS232 cable out of the ECU * Serial port disappeared (i.e. device hot unplugged) * - This includes unplugging the USB side of a USB->Serial adapter * or going out of bluetooth range, for a BT serial device * * Thus we need to handle all possible conditions if possible */ static gboolean serial_is_open = FALSE; /* Assume never opened */ static GAsyncQueue *io_repair_queue = NULL; gchar * potential_ports; gint len = 0; gboolean autodetect = FALSE; guchar buf [1024]; gchar ** vector = NULL; guint i = 0; Serial_Params *serial_params = NULL; void (*unlock_serial_f)(void) = NULL; void (*close_serial_f)(void) = NULL; gboolean (*open_serial_f)(const gchar *,gboolean) = NULL; gboolean (*lock_serial_f)(const gchar *) = NULL; void (*setup_serial_params_f)(void) = NULL; ENTER(); serial_params = (Serial_Params *)DATA_GET(global_data,"serial_params"); get_symbol_f("setup_serial_params",(void **)&setup_serial_params_f); get_symbol_f("open_serial",(void **)&open_serial_f); get_symbol_f("close_serial",(void **)&close_serial_f); get_symbol_f("lock_serial",(void **)&lock_serial_f); get_symbol_f("unlock_serial",(void **)&unlock_serial_f); MTXDBG(THREADS|CRITICAL,_("LibreEMS serial_repair_thread() created!\n")); if (DATA_GET(global_data,"offline")) { g_timeout_add(100,(GSourceFunc)queue_function_f,(gpointer)"kill_conn_warning"); MTXDBG(THREADS|CRITICAL,_("LibreEMS serial_repair_thread() exiting, offline mode!\n")); g_thread_exit(0); } if (!io_repair_queue) io_repair_queue = (GAsyncQueue *)DATA_GET(global_data,"io_repair_queue"); /* IF serial_is_open is true, then the port was ALREADY opened * previously but some error occurred that sent us down here. Thus * first do a simple comms test, if that succeeds, then just cleanup * and return, if not, close the port and essentially start over. */ if (serial_is_open == TRUE) { MTXDBG(SERIAL_RD|SERIAL_WR,_("Port considered open, but throwing errors\n")); libreems_serial_disable(); close_serial_f(); unlock_serial_f(); serial_is_open = FALSE; /* Fall through */ } while (!serial_is_open) { /* If "leaving" flag set, EXIT now */ if (DATA_GET(global_data,"leaving")) g_thread_exit(0); MTXDBG(SERIAL_RD|SERIAL_WR,_("Port NOT considered open yet.\n")); autodetect = (GBOOLEAN) DATA_GET(global_data,"autodetect_port"); if (!autodetect) /* User thinks he/she is S M A R T */ { potential_ports = (gchar *)DATA_GET(global_data, "override_port"); if (potential_ports == NULL) potential_ports = (gchar *)DATA_GET(global_data,"potential_ports"); } else /* Auto mode */ potential_ports = (gchar *)DATA_GET(global_data,"potential_ports"); vector = g_strsplit(potential_ports,",",-1); for (guint i=0;i<g_strv_length(vector);i++) { if (DATA_GET(global_data,"leaving")) { g_strfreev(vector); g_thread_exit(0); } /* Message queue used to exit immediately */ if (g_async_queue_try_pop(io_repair_queue)) { g_timeout_add(300,(GSourceFunc)queue_function_f,(gpointer)"kill_conn_warning"); MTXDBG(THREADS|CRITICAL,_("LibreEMS serial_repair_thread() exiting, told to!\n")); g_thread_exit(0); } if (!g_file_test(vector[i],G_FILE_TEST_EXISTS)) { MTXDBG(SERIAL_RD|SERIAL_WR,_("Port %s does NOT exist\n"),vector[i]); /* Wait 100 ms to avoid deadlocking */ g_usleep(100000); continue; } g_usleep(100000); MTXDBG(SERIAL_RD|SERIAL_WR,_("Attempting to open port %s\n"),vector[i]); thread_update_logbar_f("comms_view",NULL,g_strdup_printf(_("Attempting to open port %s\n"),vector[i]),FALSE,FALSE); if (lock_serial_f(vector[i])) { if (open_serial_f(vector[i],TRUE)) { if (autodetect) thread_update_widget_f("active_port_entry",MTX_ENTRY,g_strdup(vector[i])); MTXDBG(SERIAL_RD|SERIAL_WR,_("Port %s opened\n"),vector[i]); setup_serial_params_f(); libreems_serial_enable(); thread_update_logbar_f("comms_view",NULL,g_strdup_printf(_("Searching for ECU\n")),FALSE,FALSE); MTXDBG(SERIAL_RD|SERIAL_WR,_("Performing ECU comms test via port %s.\n"),vector[i]); if (comms_test()) { /* We have a winner !! Abort loop */ thread_update_logbar_f("comms_view",NULL,g_strdup_printf(_("Search successfull\n")),FALSE,FALSE); serial_is_open = TRUE; break; } else { MTXDBG(SERIAL_RD|SERIAL_WR,_("COMMS test failed, no ECU found, closing port %s.\n"),vector[i]); thread_update_logbar_f("comms_view",NULL,g_strdup_printf(_("No ECU found...\n")),FALSE,FALSE); libreems_serial_disable(); close_serial_f(); unlock_serial_f(); /*g_usleep(100000);*/ } } g_usleep(100000); } else { MTXDBG(SERIAL_RD|SERIAL_WR,_("Port %s is open by another application\n"),vector[i]); thread_update_logbar_f("comms_view","warning",g_strdup_printf(_("Port %s is open by another application\n"),vector[i]),FALSE,FALSE); } } queue_function_f("conn_warning"); } if (serial_is_open) { queue_function_f("kill_conn_warning"); thread_update_widget_f("active_port_entry",MTX_ENTRY,g_strdup(vector[i])); } if (vector) g_strfreev(vector); MTXDBG(THREADS|CRITICAL,_("LibreEMS serial_repair_thread() exiting, device found!\n")); g_thread_exit(0); EXIT(); return NULL; }
G_MODULE_EXPORT void plugin_init(gconstpointer *data) { GAsyncQueue *queue = NULL; GCond *cond = NULL; GThread *thread = NULL; GMutex *mutex = NULL; GHashTable *hash = NULL; global_data = data; /* Initializes function pointers since on Winblows was can NOT call functions within the program that loaded this DLL, so we need to pass pointers over and assign them here. */ error_msg_f = (void *)DATA_GET(global_data,"error_msg_f"); g_assert(error_msg_f); get_symbol_f = (void *)DATA_GET(global_data,"get_symbol_f"); g_assert(get_symbol_f); get_symbol_f("_get_sized_data",(void *)&_get_sized_data_f); get_symbol_f("_set_sized_data",(void *)&_set_sized_data_f); get_symbol_f("check_tab_existance",(void *)&check_tab_existance_f); get_symbol_f("cleanup",(void *)&cleanup_f); get_symbol_f("combo_set_labels",(void *)&combo_set_labels_f); get_symbol_f("combo_toggle_groups_linked",(void *)&combo_toggle_groups_linked_f); get_symbol_f("combo_toggle_labels_linked",(void *)&combo_toggle_labels_linked_f); get_symbol_f("convert_after_upload",(void *)&convert_after_upload_f); get_symbol_f("convert_before_download",(void *)&convert_before_download_f); get_symbol_f("dbg_func",(void *)&dbg_func_f); get_symbol_f("dump_output",(void *)&dump_output_f); get_symbol_f("evaluator_create",(void *)&evaluator_create_f); get_symbol_f("evaluator_destroy",(void *)&evaluator_destroy_f); get_symbol_f("evaluator_evaluate_x",(void *)&evaluator_evaluate_x_f); get_symbol_f("flush_binary_logs",(void *)&flush_binary_logs_f); get_symbol_f("flush_serial",(void *)&flush_serial_f); get_symbol_f("get_colors_from_hue",(void *)&get_colors_from_hue_f); get_symbol_f("get_file_api",(void *)&get_file_api_f); get_symbol_f("get_list",(void *)&get_list_f); get_symbol_f("get_multiplier",(void *)&get_multiplier_f); get_symbol_f("lookup_current_value",(void *)&lookup_current_value_f); get_symbol_f("lookup_widget",(void *)&lookup_widget_f); get_symbol_f("io_cmd",(void *)&io_cmd_f); get_symbol_f("initialize_outputdata",(void *)&initialize_outputdata_f); get_symbol_f("jump_to_tab",(void *)&jump_to_tab_f); get_symbol_f("log_inbound_data",(void *)&log_inbound_data_f); get_symbol_f("log_outbound_data",(void *)&log_outbound_data_f); get_symbol_f("mem_alloc",(void *)&mem_alloc_f); get_symbol_f("parse_keys",(void *)&parse_keys_f); get_symbol_f("queue_function",(void *)&queue_function_f); get_symbol_f("process_rt_vars",(void *)&process_rt_vars_f); get_symbol_f("read_data",(void *)&read_data_f); get_symbol_f("read_wrapper",(void *)&read_wrapper_f); get_symbol_f("recalc_table_limits",(void *)&recalc_table_limits_f); get_symbol_f("set_file_api",(void *)&set_file_api_f); get_symbol_f("set_group_color",(void *)&set_group_color_f); get_symbol_f("set_widget_labels",(void *)&set_widget_labels_f); get_symbol_f("set_widget_sensitive",(void *)&set_widget_sensitive_f); get_symbol_f("set_title",(void *)&set_title_f); get_symbol_f("swap_labels",(void *)&swap_labels_f); get_symbol_f("temp_to_ecu",(void *)&temp_to_ecu_f); get_symbol_f("temp_to_host",(void *)&temp_to_host_f); get_symbol_f("toggle_groups_linked",(void *)&toggle_groups_linked_f); get_symbol_f("thread_refresh_widget_range",(void *)&thread_refresh_widget_range_f); get_symbol_f("thread_refresh_widgets_at_offset",(void *)&thread_refresh_widgets_at_offset_f); get_symbol_f("thread_update_logbar",(void *)&thread_update_logbar_f); get_symbol_f("thread_update_widget",(void *)&thread_update_widget_f); get_symbol_f("thread_widget_set_sensitive",(void *)&thread_widget_set_sensitive_f); get_symbol_f("translate_string",(void *)&translate_string_f); get_symbol_f("update_logbar",(void *)&update_logbar_f); get_symbol_f("warn_user",(void *)&warn_user_f); get_symbol_f("write_wrapper",(void *)&write_wrapper_f); register_common_enums(); /* Packet handling queue */ cond = g_cond_new(); DATA_SET(global_data,"serial_reader_cond",cond); cond = g_cond_new(); DATA_SET(global_data,"packet_handler_cond",cond); /* Packet subscribers */ hash = g_hash_table_new(g_direct_hash,g_direct_equal); DATA_SET(global_data,"sequence_num_queue_hash",hash); hash = g_hash_table_new(g_direct_hash,g_direct_equal); DATA_SET(global_data,"payload_id_queue_hash",hash); mutex = g_mutex_new(); DATA_SET(global_data,"queue_mutex",mutex); queue = g_async_queue_new(); DATA_SET(global_data,"packet_queue",queue); queue = g_async_queue_new(); register_packet_queue(PAYLOAD_ID,queue,RESPONSE_UPDATE_BLOCK_IN_RAM); DATA_SET(global_data,"RAM_write_queue",queue); queue = g_async_queue_new(); register_packet_queue(PAYLOAD_ID,queue,RESPONSE_REPLACE_BLOCK_IN_FLASH); DATA_SET(global_data,"FLASH_write_queue",queue); queue = g_async_queue_new(); register_packet_queue(PAYLOAD_ID,queue,RESPONSE_BURN_BLOCK_FROM_RAM_TO_FLASH); DATA_SET(global_data,"burn_queue",queue); thread = g_thread_create(packet_handler,NULL,TRUE,NULL); DATA_SET(global_data,"packet_handler_thread",thread); return; }
/*! \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); }
/*! \brief validate_and_load_tests() loads the list of tests from the system checks them for validity, populates and array and returns it command tested against the ECU arestored \returns a dynamic GArray for commands */ G_MODULE_EXPORT gboolean validate_and_load_tests(GArray **tests, GHashTable **tests_hash) { ConfigFile *cfgfile; Detection_Test *test = NULL; gchar * filename = NULL; gchar *section = NULL; gchar * tmpbuf = NULL; gchar ** vector = NULL; gint total_tests = 0; gint result = 0; gint major = 0; gint minor = 0; gint i = 0; gint j = 0; filename = get_file(g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),"tests.cfg",NULL),NULL); if (!filename) { update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile tests file %s not found!\n"),filename),FALSE,FALSE,TRUE); return FALSE; } cfgfile = cfg_open_file(filename); if (!cfgfile) return FALSE; get_file_api_f(cfgfile,&major,&minor); if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API)) { update_logbar_f("interr_view","warning",g_strdup_printf(_("Interrogation profile tests API mismatch (%i.%i != %i.%i):\n\tFile %s.\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,filename),FALSE,FALSE,TRUE); return FALSE; } *tests_hash = g_hash_table_new_full(g_str_hash,g_str_equal,NULL,test_cleanup); dbg_func_f(INTERROGATOR,g_strdup_printf(__FILE__": validate_and_load_tests()\n\tfile %s, opened successfully\n",filename)); *tests = g_array_new(FALSE,TRUE,sizeof(Detection_Test *)); cfg_read_int(cfgfile,"interrogation_tests","total_tests",&total_tests); for (i=0;i<total_tests;i++) { test = g_new0(Detection_Test, 1); section = g_strdup_printf("test_%.2i",i); if (!cfg_read_string(cfgfile,section,"test_name",&test->test_name)) { dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": validate_and_load_tests(),\n\ttest_name for %s is NULL\n",section)); g_free(section); break; } if (!cfg_read_string(cfgfile,section,"test_result_type",&tmpbuf)) { dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": validate_and_load_tests(),\n\ttest_result_type for %s is NULL\n",section)); g_free(section); break; } else { test->result_type=translate_string_f(tmpbuf); g_free(tmpbuf); } if (!cfg_read_string(cfgfile,section,"test_func",&test->test_func)) { dbg_func_f(INTERROGATOR|CRITICAL,g_strdup_printf(__FILE__": validate_and_load_tests(),\n\ttest_function for %s is NULL\n",section)); g_free(section); break; } get_symbol_f(test->test_func,(void *)&test->function); cfg_read_string(cfgfile,section,"test_desc", &test->test_desc); g_free(section); g_array_append_val(*tests,test); g_hash_table_insert(*tests_hash,test->test_name,test); } cfg_free(cfgfile); g_free(filename); return TRUE; }
/*! \brief initializes the MegaSquirt plugin via locating and attaching to all needed functions within the core MegaTunix. It also registers any plugin specific enumerations, and registers/sets up any additional resources needed like threads, Queues, memory, etc \param data is a pointer to the global data container. */ G_MODULE_EXPORT void plugin_init(gconstpointer *data) { global_data = data; *(void **)(&error_msg_f) = (void **)DATA_GET(global_data,"error_msg_f"); g_assert(error_msg_f); *(void **)(&get_symbol_f) = (void **)DATA_GET(global_data,"get_symbol_f"); g_assert(get_symbol_f); get_symbol_f("dbg_func",(void **)&dbg_func_f); ENTER(); /* Initializes function pointers since on Winblows was can NOT call functions within the program that loaded this DLL, so we need to pass pointers over and assign them here. */ get_symbol_f("_get_sized_data",(void **)&_get_sized_data_f); get_symbol_f("_set_sized_data",(void **)&_set_sized_data_f); get_symbol_f("add_additional_rtt",(void **)&add_additional_rtt_f); get_symbol_f("alter_widget_state",(void **)&alter_widget_state_f); get_symbol_f("bind_to_lists",(void **)&bind_to_lists_f); get_symbol_f("c_to_k",(void **)&c_to_k_f); get_symbol_f("check_tab_existance",(void **)&check_tab_existance_f); get_symbol_f("cleanup",(void **)&cleanup_f); get_symbol_f("combo_set_labels",(void **)&combo_set_labels_f); get_symbol_f("combo_toggle_groups_linked",(void **)&combo_toggle_groups_linked_f); get_symbol_f("combo_toggle_labels_linked",(void **)&combo_toggle_labels_linked_f); get_symbol_f("convert_after_upload",(void **)&convert_after_upload_f); get_symbol_f("convert_before_download",(void **)&convert_before_download_f); get_symbol_f("create_rtv_value_change_watch",(void **)&create_rtv_value_change_watch_f); get_symbol_f("direct_lookup_data",(void **)&direct_lookup_data_f); get_symbol_f("direct_reverse_lookup",(void **)&direct_reverse_lookup_f); get_symbol_f("entry_changed_handler",(void **)&entry_changed_handler_f); get_symbol_f("evaluator_create_w",(void **)&evaluator_create_f); get_symbol_f("evaluator_destroy_w",(void **)&evaluator_destroy_f); get_symbol_f("evaluator_evaluate_x_w",(void **)&evaluator_evaluate_x_f); get_symbol_f("f_to_k",(void **)&f_to_k_f); get_symbol_f("flush_serial",(void **)&flush_serial_f); get_symbol_f("focus_out_handler",(void **)&focus_out_handler_f); get_symbol_f("get_bitshift",(void **)&get_bitshift_f); get_symbol_f("get_choice_count",(void **)&get_choice_count_f); get_symbol_f("get_colors_from_hue",(void **)&get_colors_from_hue_f); get_symbol_f("get_extreme_from_size",(void **)&get_extreme_from_size_f); get_symbol_f("get_file_api",(void **)&get_file_api_f); get_symbol_f("get_list",(void **)&get_list_f); get_symbol_f("get_multiplier",(void **)&get_multiplier_f); get_symbol_f("get_table",(void **)&get_table_f); get_symbol_f("io_cmd",(void **)&io_cmd_f); get_symbol_f("initialize_outputdata",(void **)&initialize_outputdata_f); get_symbol_f("jump_to_tab",(void **)&jump_to_tab_f); get_symbol_f("key_event",(void **)&key_event_f); get_symbol_f("lookup_current_value",(void **)&lookup_current_value_f); get_symbol_f("lookup_data",(void **)&lookup_data_f); get_symbol_f("lookup_precision",(void **)&lookup_precision_f); get_symbol_f("lookup_widget",(void **)&lookup_widget_f); get_symbol_f("mem_alloc",(void **)&mem_alloc_f); get_symbol_f("parse_keys",(void **)&parse_keys_f); get_symbol_f("process_rt_vars",(void **)&process_rt_vars_f); get_symbol_f("queue_function",(void **)&queue_function_f); get_symbol_f("read_data",(void **)&read_data_f); get_symbol_f("read_wrapper",(void **)&read_wrapper_f); get_symbol_f("recalc_table_limits",(void **)&recalc_table_limits_f); get_symbol_f("register_widget",(void **)®ister_widget_f); get_symbol_f("remove_rtv_watch",(void **)&remove_rtv_watch_f); get_symbol_f("remove_from_lists",(void **)&remove_from_lists_f); get_symbol_f("reverse_lookup",(void **)&reverse_lookup_f); get_symbol_f("search_model",(void **)&search_model_f); get_symbol_f("set_file_api",(void **)&set_file_api_f); get_symbol_f("table_color_refresh_wrapper",(void **)&table_color_refresh_wrapper_f); get_symbol_f("thread_set_group_color",(void **)&thread_set_group_color_f); get_symbol_f("set_reqfuel_color",(void **)&set_reqfuel_color_f); get_symbol_f("set_title",(void **)&set_title_f); get_symbol_f("set_widget_labels",(void **)&set_widget_labels_f); get_symbol_f("set_widget_sensitive",(void **)&set_widget_sensitive_f); get_symbol_f("spin_button_handler",(void **)&spin_button_handler_f); get_symbol_f("start_restore_monitor",(void **)&start_restore_monitor_f); get_symbol_f("start_tickler",(void **)&start_tickler_f); get_symbol_f("std_entry_handler",(void **)&std_entry_handler_f); get_symbol_f("stop_tickler",(void **)&stop_tickler_f); get_symbol_f("swap_labels",(void **)&swap_labels_f); get_symbol_f("temp_to_ecu",(void **)&temp_to_ecu_f); get_symbol_f("temp_to_host",(void **)&temp_to_host_f); get_symbol_f("thread_refresh_widget",(void **)&thread_refresh_widget_f); get_symbol_f("thread_refresh_widget_range",(void **)&thread_refresh_widget_range_f); get_symbol_f("thread_refresh_widgets_at_offset",(void **)&thread_refresh_widgets_at_offset_f); get_symbol_f("thread_update_logbar",(void **)&thread_update_logbar_f); get_symbol_f("thread_update_widget",(void **)&thread_update_widget_f); get_symbol_f("thread_widget_set_sensitive",(void **)&thread_widget_set_sensitive_f); get_symbol_f("translate_string",(void **)&translate_string_f); get_symbol_f("update_current_notebook_page",(void **)&update_current_notebook_page_f); get_symbol_f("update_entry_color",(void **)&update_entry_color_f); get_symbol_f("update_logbar",(void **)&update_logbar_f); get_symbol_f("update_ve3d_if_necessary",(void **)&update_ve3d_if_necessary_f); get_symbol_f("warn_user",(void **)&warn_user_f); get_symbol_f("write_wrapper",(void **)&write_wrapper_f); register_common_enums(); EXIT(); return; }
/*! \brief Initializes the MS1 ecu firmware plugin. This links up to all the needed functions within core MtX, and registers any ecu specific ENUMS or other datastructures \param data is a pointer to the global_data container \see plugin_shutdown */ G_MODULE_EXPORT void plugin_init(gconstpointer *data) { global_data = data; /* Initializes function pointers since on Winblows was can NOT call functions within the program that loaded this DLL, so we need to pass pointers over and assign them here. */ error_msg_f = (void *)DATA_GET(global_data,"error_msg_f"); g_assert(error_msg_f); get_symbol_f = (void *)DATA_GET(global_data,"get_symbol_f"); g_assert(get_symbol_f); get_symbol_f("alter_widget_state",(void *)&alter_widget_state_f); get_symbol_f("convert_after_upload",(void *)&convert_after_upload_f); get_symbol_f("convert_before_download",(void *)&convert_before_download_f); get_symbol_f("dbg_func",(void *)&dbg_func_f); get_symbol_f("entry_changed_handler",(void *)&entry_changed_handler_f); get_symbol_f("get_colors_from_hue",(void *)&get_colors_from_hue_f); get_symbol_f("get_bitshift",(void *)&get_bitshift_f); get_symbol_f("get_ecu_data",(void *)&get_ecu_data_f); get_symbol_f("get_essentials",(void *)&get_essentials_f); get_symbol_f("get_essential_bits",(void *)&get_essential_bits_f); get_symbol_f("get_extreme_from_size",(void *)&get_extreme_from_size_f); get_symbol_f("initialize_gc",(void *)&initialize_gc_f); get_symbol_f("io_cmd",(void *)&io_cmd_f); get_symbol_f("lookup_current_value",(void *)&lookup_current_value_f); get_symbol_f("lookup_widget",(void *)&lookup_widget_f); get_symbol_f("lookuptables_configurator",(void *)&lookuptables_configurator_f); get_symbol_f("ms_get_ecu_data",(void *)&ms_get_ecu_data_f); get_symbol_f("ms_send_to_ecu",(void *)&ms_send_to_ecu_f); get_symbol_f("recalc_table_limits",(void *)&recalc_table_limits_f); get_symbol_f("signal_read_rtvars",(void *)&signal_read_rtvars_f); get_symbol_f("start_tickler",(void *)&start_tickler_f); get_symbol_f("std_entry_handler",(void *)&std_entry_handler_f); get_symbol_f("stop_tickler",(void *)&stop_tickler_f); register_ecu_enums(); }