Exemplo n.º 1
0
/*!
  \brief close_serial() closes the serial port, and sets several gui widgets
  to reflect the port closing (textview/connected indicator)
  */
G_MODULE_EXPORT void close_serial(void)
{
	GMutex *serio_mutex = NULL;
	Serial_Params *serial_params = NULL;
	serial_params = DATA_GET(global_data,"serial_params");
	serio_mutex = DATA_GET(global_data,"serio_mutex");
	if (!serial_params)
		return;
	if (serial_params->open == FALSE)
		return;

	g_mutex_lock(serio_mutex);

	/*printf("Closing serial port\n");*/
#ifndef __WIN32__
	/* OLD PIS stuff disabled
	if (ioctl(serial_params->fd, TIOCSSERIAL, &serial_params->oldctl) != 0)
		MTXDBG(SERIAL_RD|SERIAL_WR|CRITICAL,_("Error restoring serial line config\n"));
	else
		MTXDBG(SERIAL_RD|SERIAL_WR,_("Serial line settings restored OK\n"));
	*/

	tcsetattr(serial_params->fd,TCSANOW,&serial_params->oldtio);
#endif /* __WIN32___ */

	close(serial_params->fd);
	serial_params->fd = -1;
	serial_params->open = FALSE;
	if (serial_params->port_name)
		g_free(serial_params->port_name);
	serial_params->port_name = NULL;
	DATA_SET(global_data,"connected",GINT_TO_POINTER(FALSE));

	/* An Closing the comm port */
	MTXDBG(SERIAL_RD|SERIAL_WR,_("Serial Port Closed\n"));
	if (!DATA_GET(global_data,"leaving"))
		thread_update_logbar("comms_view",NULL,g_strdup_printf(_("Serial Port Closed\n")),FALSE,FALSE);
	g_mutex_unlock(serio_mutex);
	return;
}
Exemplo n.º 2
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;
	}
}
Exemplo n.º 3
0
/*!
  \brief load_gui_tabs_pf() is called after interrogation completes 
  successfully. It's purpose is to load all the glade files and datamaps 
  as specified in the interrogation profile of the detected firmware. 
  \param notebook is the pointer to the notebook the new tab should be placed
  \param page is the page number to load
  \returns TRUE on success, FALSE on failure
  */
G_MODULE_EXPORT gboolean load_actual_tab(GtkNotebook *notebook, gint page)
{
	ConfigFile *cfgfile = NULL;
	gchar * map_file = NULL;
	gchar * glade_file = NULL;
	gchar * tmpbuf = NULL;
	GladeXML *xml = NULL;
	GtkWidget *label = NULL;
	GtkWidget *topframe = NULL;
	GtkWidget *placeholder = NULL;
	GHashTable *groups = NULL;
	GList *tab_widgets = NULL;
	BindGroup *bindgroup = NULL;
	extern GdkColor red;

	ENTER();
	placeholder =  gtk_notebook_get_nth_page(notebook,page);
	label = gtk_notebook_get_tab_label(notebook,placeholder);

	glade_file = (gchar *)OBJ_GET(label,"glade_file");
	map_file = (gchar *)OBJ_GET(label,"datamap_file");
	xml = glade_xml_new(glade_file,"topframe",NULL);
	g_return_val_if_fail(xml,FALSE);
	thread_update_logbar("interr_view",NULL,g_strdup(_("Load of tab: ")),FALSE,FALSE);
	thread_update_logbar("interr_view","info", g_strdup_printf("\"%s\"",glade_file),FALSE,FALSE);
	thread_update_logbar("interr_view",NULL,g_strdup(_(" completed.\n")),FALSE,FALSE);
	thread_update_logbar("interr_view",NULL,g_strdup(_("Load of tabconf: ")),FALSE,FALSE);
	thread_update_logbar("interr_view","info", g_strdup_printf("\"%s\"",map_file),FALSE,FALSE);
	cfgfile = cfg_open_file(map_file);
	if (cfgfile)
	{
		topframe = glade_xml_get_widget(xml,"topframe");
		if (topframe == NULL)
		{
			MTXDBG(TABLOADER|CRITICAL,_("\"topframe\" not found in xml, ABORTING!!\n"));
			set_title(g_strdup(_("ERROR Gui Tab XML problem, \"topframe\" element not found!!!")));
			EXIT();
			return FALSE;
		}
		OBJ_SET_FULL(topframe,"glade_xml",(gpointer)xml,g_object_unref);
		// bind_data() is recursive and will take 
		// care of all children

		bindgroup = g_new0(BindGroup,1);
		groups = load_groups(cfgfile);
		bindgroup->cfgfile = cfgfile;
		bindgroup->groups = groups;
		bindgroup->map_file = g_strdup(map_file);
/*		tab_widgets = g_list_prepend(tab_widgets,topframe);
		OBJ_SET(topframe,"tab_widgets",tab_widgets);
		*/
		bindgroup->topframe = topframe;
		bind_data(topframe,(gpointer)bindgroup);
		g_free(bindgroup->map_file);
		if (groups)
			g_hash_table_destroy(groups);
		groups = NULL;
		/* Clear not_rendered flag */
		OBJ_SET(label,"not_rendered",NULL);

		populate_master(topframe,(gpointer)cfgfile);

		gtk_box_pack_start(GTK_BOX(placeholder),topframe,TRUE,TRUE,0);
		OBJ_SET(placeholder,"topframe",topframe);
		glade_xml_signal_autoconnect(xml);
		g_free(bindgroup);
		if (cfg_read_string(cfgfile,"global","post_functions",&tmpbuf))
		{
			run_post_functions(tmpbuf);
			g_free(tmpbuf);
		}
		cfg_free(cfgfile);
		gtk_widget_show(topframe);
		/*printf("Current length of tab_widgets is %i\n",g_list_length(OBJ_GET(topframe,"tab_widgets")));*/
		thread_update_logbar("interr_view",NULL,g_strdup(_(" completed.\n")),FALSE,FALSE);
	}
	update_groups_pf();
	update_sources_pf();
	/* Allow gui to update as it should.... */
	gdk_flush();
	EXIT();
	return TRUE;
}
Exemplo n.º 4
0
/*!
  \brief thread_dispatcher() runs continuously as a thread listening to the 
  io_data_queue and running handlers as messages come in. After they are done it
  passes the message back to the gui via the dispatch_queue for further
  gui handling (for things that can't run in a thread context)
  \param data is unused
  */
G_MODULE_EXPORT void *thread_dispatcher(gpointer data)
{
	GThread * repair_thread = NULL;
	Serial_Params *serial_params = NULL;
	Io_Message *message = NULL;	
	GAsyncQueue *io_data_queue = NULL;
	CmdLineArgs *args  = NULL;
	void *(*network_repair_thread)(gpointer data) = NULL;
	void *(*serial_repair_thread)(gpointer data) = NULL;
	/*	GTimer *clock;*/

	ENTER();
	io_data_queue = (GAsyncQueue *)DATA_GET(global_data,"io_data_queue");
	serial_params = (Serial_Params *)DATA_GET(global_data,"serial_params");
	get_symbol("serial_repair_thread",(void **)&serial_repair_thread);
	args = (CmdLineArgs *)DATA_GET(global_data,"args");
	if (args->network_mode)
		get_symbol("network_repair_thread",(void **)&network_repair_thread);

	g_return_val_if_fail(args,NULL);
	g_return_val_if_fail(io_data_queue,NULL);
	g_return_val_if_fail(serial_params,NULL);
	g_async_queue_ref(io_data_queue);
	/*	clock = g_timer_new();*/
	/* Endless Loop, wait for message, processs and repeat... */
	while (TRUE)
	{
		if (DATA_GET(global_data,"thread_dispatcher_exit"))
		{
fast_exit:
			/* drain queue and exit thread */
			while ((message = (Io_Message *)g_async_queue_try_pop(io_data_queue)) != NULL)
				dealloc_io_message(message);
			g_async_queue_unref(io_data_queue);

			EXIT();
			g_thread_exit(0);
		}
		message = (Io_Message *)g_async_queue_timeout_pop(io_data_queue,1000000);
		if (!message) /* NULL message */
		{
			MTXDBG(THREADS|IO_MSG,_("No message received...\n"));
			continue;
		}
		else
			MTXDBG(THREADS|IO_MSG,_("MESSAGE ARRIVED on IO queue...\n"));

		if ((!DATA_GET(global_data,"offline")) && 
				(((!DATA_GET(global_data,"connected")) && 
				  (serial_params->open)) || 
				 (!(serial_params->open))))
		{
			/*printf("somehow somethign went wrong,  connected is %i, offline is %i, serial_params->open is %i\n",DATA_GET(global_data,"connected"),DATA_GET(global_data,"offline"),serial_params->open);*/
			if (args->network_mode)
			{
				MTXDBG(THREADS,_("LINK DOWN, Initiating NETWORK repair thread!\n"));
				repair_thread = g_thread_new("Network Repair thread",network_repair_thread,NULL);
			}
			else
			{
				MTXDBG(THREADS,_("LINK DOWN, Initiating serial repair thread!\n"));
				repair_thread = g_thread_new("Serial Repair thread",serial_repair_thread,NULL);
			}
			g_thread_join(repair_thread);
		}
		if ((!serial_params->open) && (!DATA_GET(global_data,"offline")))
		{
			MTXDBG(THREADS,_("LINK DOWN, Can't process requested command, aborting call\n"));
			thread_update_logbar("comm_view","warning",g_strdup("Disconnected Serial Link. Check Communications link/cable...\n"),FALSE,FALSE);
			thread_update_widget("titlebar",MTX_TITLE,g_strdup("Disconnected link, check Communications tab..."));
			message->status = FALSE;
			continue;
		}
		switch ((CmdType)message->command->type)
		{
			case FUNC_CALL:
				if (!message->command->function)
					MTXDBG(CRITICAL|THREADS,_("CRITICAL ERROR, function \"%s()\" is not found!!\n"),message->command->func_call_name);
				else
				{
					/*printf("Calling FUNC_CALL, function \"%s()\" \n",message->command->func_call_name);*/
					message->status = message->command->function(message->command,message->command->func_call_arg);
					/*
					   if (!result)
					   message->command->defer_post_functions=TRUE;
					   */
				}
				break;
			case WRITE_CMD:
				/*g_timer_start(clock);*/
				message->status = write_data(message);
				if (!message->status)
					DATA_SET(global_data,"connected",GINT_TO_POINTER(FALSE));

				/*printf("Write command elapsed time %f\n",g_timer_elapsed(clock,NULL));*/
				if (message)
				{
					if (message->command)
					{
						if (message->command->helper_function)
						{
							message->command->helper_function(message, message->command->helper_func_arg);
						}
					}
				}

				/*printf("Write command with post function time %f\n",g_timer_elapsed(clock,NULL));*/
				break;
			case NULL_CMD:
				/*printf("null_cmd, just passing thru\n");*/
				break;

			default:
				MTXDBG(THREADS|CRITICAL,_("Hit default case, this SHOULD NOT HAPPEN it's a bug, notify author! \n"));

				break;

		}
		/* If set to defer post functions, it means they were passed 
		   via a function fall, thus dealloc it here., Otherwise
		   push up the queue to the postfunction dispatcher
		   */
		if (message->command->defer_post_functions)
			dealloc_io_message(message);
		else
			g_idle_add(process_pf_message,message);
	}
	EXIT();
	return 0;
}
Exemplo n.º 5
0
/*!
  \brief present_firmware_choices() presents a dialog box with the firmware
  choices.
  \returns the name of the chosen firmware
  */
G_MODULE_EXPORT gchar * present_firmware_choices(void)
{
	gchar ** filenames = NULL;
	GtkWidget *dialog = NULL;
	GtkWidget *vbox = NULL;
	GtkWidget *hbox = NULL;
	GtkWidget *ebox = NULL;
	GtkWidget *sep = NULL;
	GtkWidget *dummybutton = NULL;
	GtkWidget *button = NULL;
	GtkWidget *label = NULL;
	ListElement *element = NULL;
	gchar *tmpbuf = NULL;
	GArray *classes = NULL;
	GSList *group = NULL;
	GList *p_list = NULL;
	GList *s_list = NULL;
	ConfigFile *cfgfile = NULL;
	const gchar * last_file = NULL;
	gint major = 0;
	gint minor = 0;
	guint i = 0;
	gint result = 0;
	extern gconstpointer *global_data;
	gchar * pathstub = NULL;

	ENTER();
	pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),NULL);
	filenames = get_files((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"prof",&classes);
	g_free(pathstub);
	if (!filenames)
	{
		MTXDBG(CRITICAL,_("NO Interrogation profiles found, was MegaTunix installed properly?\n"));
		EXIT();
		return NULL;
	}
	i = 0;
	while (filenames[i]) 
	{
		cfgfile = cfg_open_file(filenames[i]);
		if (!cfgfile)
		{
			MTXDBG(CRITICAL,_("Interrogation profile damaged!, was MegaTunix installed properly?\n"));
			i++;
			continue;
		}
		get_file_api(cfgfile,&major,&minor);
		if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API))
		{
			thread_update_logbar("interr_view","warning",g_strdup_printf(_("Interrogation profile API mismatch (%i.%i != %i.%i):\n\tFile %s will be skipped\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,cfgfile->filename),FALSE,FALSE);
			i++;
			cfg_free(cfgfile);
			continue;
		}
		cfg_read_string(cfgfile,"interrogation_profile","name",&tmpbuf);
		cfg_free(cfgfile);
		last_file = (gchar *)DATA_GET(global_data,"last_offline_profile");

		if (g_array_index(classes,FileClass,i) == PERSONAL)
		{
			element = g_new0(ListElement, 1);
			element->filename = g_strdup(filenames[i]);
			if (g_ascii_strcasecmp(element->filename,last_file) == 0)
				element->def = TRUE;

			element->name = g_strdup(tmpbuf);
			p_list = g_list_append(p_list,(gpointer)element);
		}
		if (g_array_index(classes,FileClass,i) == SYSTEM)
		{
			element = g_new0(ListElement, 1);
			element->filename = g_strdup(filenames[i]);
			if (g_ascii_strcasecmp(element->filename,last_file) == 0)
				element->def = TRUE;
			element->name = g_strdup(tmpbuf);
			s_list = g_list_append(s_list,(gpointer)element);
		}
		g_free(tmpbuf);
		i++;
	}
	p_list = g_list_sort(p_list,list_sort);
	s_list = g_list_sort(s_list,list_sort);


	dialog = gtk_dialog_new_with_buttons("Select Firmware",
			GTK_WINDOW(lookup_widget("main_window")),
			GTK_DIALOG_DESTROY_WITH_PARENT,
			"Abort",
			GTK_RESPONSE_CANCEL,
			"Load",
			GTK_RESPONSE_OK,
			NULL);

	vbox = gtk_vbox_new(TRUE,2);
	gtk_container_set_border_width(GTK_CONTAINER(vbox),5);
	gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),vbox,TRUE,TRUE,0);
	/* Dummies */
	dummybutton = gtk_radio_button_new(NULL);
	g_object_ref_sink(dummybutton);
	group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(dummybutton));
	if (g_list_length(p_list) > 0)
	{
		label = gtk_label_new("Custom (personal) Profiles");
		gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);

		/* Cycle list for PERSONAL interogation files */
		for (i=0;i<g_list_length(p_list);i++)
		{
			element = (ListElement *)g_list_nth_data(p_list,i);

			ebox = gtk_event_box_new();
			gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0);
			hbox = gtk_hbox_new(FALSE,10);
			gtk_container_add(GTK_CONTAINER(ebox),hbox);
			label = gtk_label_new(element->name);
			gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0);
			button = gtk_radio_button_new(group);
			g_free(OBJ_GET(button,"filename"));
			OBJ_SET_FULL(button,"filename",g_strdup(element->filename),g_free);
			OBJ_SET(button,"handler",
					GINT_TO_POINTER(OFFLINE_FIRMWARE_CHOICE));
			g_signal_connect(button,
					"toggled",
					G_CALLBACK(toggle_button_handler),
					NULL);
			gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0);
			if (element->def)
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),TRUE);
			else
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),FALSE);
			group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button));
		}

		sep = gtk_hseparator_new();
		gtk_box_pack_start(GTK_BOX(vbox),sep,TRUE,TRUE,0);
	}
	label = gtk_label_new("System Wide ECU Profiles");
	gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);
	/* Cycle list for System interogation files */
	for (i=0;i<g_list_length(s_list);i++)
	{
		element = (ListElement *)g_list_nth_data(s_list,i);
		ebox = gtk_event_box_new();
		gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0);
		hbox = gtk_hbox_new(FALSE,10);
		gtk_container_add(GTK_CONTAINER(ebox),hbox);
		label = gtk_label_new(element->name);
		gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0);
		button = gtk_radio_button_new(group);
		g_free(OBJ_GET(button,"filename"));
		OBJ_SET_FULL(button,"filename",g_strdup(element->filename),g_free);
		OBJ_SET(button,"handler",
				GINT_TO_POINTER(OFFLINE_FIRMWARE_CHOICE));
		g_signal_connect(button,
				"toggled",
				G_CALLBACK(toggle_button_handler),
				NULL);
		gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0);
		if (element->def)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),TRUE);
		else
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),FALSE);
		group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button));
	}
	/*
	   if (i==1)
	   gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(button));
	   else
	   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE);
	   */

	g_strfreev(filenames);
	g_array_free(classes,TRUE);

	gtk_widget_show_all(dialog);
	gtk_window_set_transient_for(GTK_WINDOW(gtk_widget_get_toplevel(dialog)),GTK_WINDOW(lookup_widget("main_window")));

	result = gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
	g_object_unref(dummybutton);
	g_list_foreach(p_list,free_element,NULL);
	g_list_foreach(s_list,free_element,NULL);
	g_list_free(p_list);
	g_list_free(s_list);
	switch (result)
	{
		case GTK_RESPONSE_ACCEPT:
		case GTK_RESPONSE_OK:
			EXIT();
			return (gchar *)DATA_GET(global_data,"offline_firmware_choice");
			break;
		case GTK_RESPONSE_CANCEL:
		default:
			EXIT();
			return NULL;
	}
	EXIT();
	return NULL;
}
Exemplo n.º 6
0
/*!
  \brief open_serial() called to open the serial port, updates textviews on the
  comms page on success/failure
  \param port_name is the name of the port to open
  \param nonblock is a flag if we should open hte port in nonblocking mode
  */
G_MODULE_EXPORT gboolean open_serial(gchar * port_name, gboolean nonblock)
{
	/* We are using DOS/Win32 style com port numbers instead of unix
	 * style as its easier to think of COM1 instead of /dev/ttyS0
	 * thus com1=/dev/ttyS0, com2=/dev/ttyS1 and so on 
	 */
	static GMutex *serio_mutex = NULL;
	gboolean port_open = FALSE;
	Serial_Params *serial_params = NULL;
	gint fd = -1;
	gchar * err_text = NULL;
	serial_params = DATA_GET(global_data,"serial_params");
	serio_mutex = DATA_GET(global_data,"serio_mutex");

	g_mutex_lock(serio_mutex);
	/*printf("Opening serial port %s\n",port_name);*/
	/* Open Read/Write and NOT as the controlling TTY */
	/* Blocking mode... */
	if (nonblock)
	{
#ifdef __WIN32__
		fd = open(port_name, O_RDWR | O_BINARY);
//		serial_params->comm_handle = CreateFile(port_name,
//				GENERIC_READ|GENERIC_WRITE, /* Access */
//				0, /* not shared */
//				0, /* No security */
//				OPEN_EXISTING, /* Don't create a file */
//				FILE_FLAG_OVERLAPPED, /* Overlapped IO */
//				0 /* No templates... */
//				);
//		fd = _open_osfhandle(serial_params->comm_handle, 0);
#else
		fd = open(port_name, O_RDWR | O_NOCTTY | O_NDELAY);
#endif
		DATA_SET(global_data,"serial_nonblock",GINT_TO_POINTER(TRUE));
	}
	else
	{
#ifdef __WIN32__
		fd = open(port_name, O_RDWR | O_BINARY );
#else
		fd = open(port_name, O_RDWR | O_NOCTTY );
#endif
	}
	if (fd > 0)
	{
		/* SUCCESS */
		/* NO Errors occurred opening the port */
		serial_params->port_name = g_strdup(port_name); 
		serial_params->open = TRUE;
		port_open = TRUE;
		serial_params->fd = fd;
		MTXDBG(SERIAL_RD|SERIAL_WR,_("\"%s\" Opened Successfully\n"),port_name);
		thread_update_logbar("comms_view",NULL,g_strdup_printf(_("%s Opened Successfully\n"),port_name),FALSE,FALSE);

	}
	else
	{
		/* FAILURE */
		/* An Error occurred opening the port */
		port_open = FALSE;
		if (serial_params->port_name)
			g_free(serial_params->port_name);
		serial_params->port_name = NULL;
		serial_params->open = FALSE;
		serial_params->fd = -1;
		err_text = (gchar *)g_strerror(errno);
		MTXDBG(SERIAL_RD|SERIAL_WR|CRITICAL,_("Error Opening \"%s\", Error Code: \"%s\"\n"),port_name,err_text);
		thread_update_widget("titlebar",MTX_TITLE,g_strdup_printf(_("Error Opening \"%s\", Error Code: \"%s\""),port_name,err_text));

		thread_update_logbar("comms_view","warning",g_strdup_printf(_("Error Opening \"%s\", Error Code: %s \n"),port_name,err_text),FALSE,FALSE);
	}

	/*printf("open_serial returning\n");*/
	g_mutex_unlock(serio_mutex);
	return port_open;
}