Exemple #1
0
G_MODULE_EXPORT gboolean load_firmware (GtkButton *button)
{
	GtkWidget *widget = NULL;
	gchar *port;
	gchar *filename = NULL;
	gint port_fd = 0;
	gint file_fd = 0;
	FirmwareType type = MS1;

	widget = GTK_WIDGET(gtk_builder_get_object((GtkBuilder *)DATA_GET(global_data,"builder"), "port_entry"));
	port = (gchar *)gtk_entry_get_text(GTK_ENTRY(widget));
	widget = GTK_WIDGET(gtk_builder_get_object ((GtkBuilder *)DATA_GET(global_data,"builder"), "filechooser_button"));
	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));

	if (g_utf8_strlen(port, -1) == 0)
		return FALSE;
	if (filename == NULL)
		return FALSE;

	/* If we got this far, all is good argument wise */
	if (!lock_port(port))
	{
		output((gchar *)"Could NOT LOCK Serial Port,\nYou should check for other programs using the serial port\n",FALSE);
		return FALSE;
	}
	port_fd = open_port(port);
	if (port_fd > 0)
		output((gchar *)"Port successfully opened\n",FALSE);
	else
	{
		output((gchar *)"Could NOT open Port, You should check perms\n",FALSE);
		unlock_port();
		return FALSE;
	}
#ifdef __WIN32__
	file_fd = open(filename, O_RDWR | O_BINARY );
#else
	file_fd = g_open(filename,O_RDONLY,S_IRUSR);
#endif
	if (file_fd > 0 )
		output((gchar *)"Firmware file successfully opened\n",FALSE);
	else
	{
		output((gchar *)"Could NOT open firmware file, check permissions/paths\n",FALSE);
		close_port(port_fd);
		unlock_port();
		return FALSE;
	}
	lock_buttons();
	if ((GINT)DATA_GET(global_data,"persona") == MS1)
	{
		setup_port(port_fd, 9600);
		do_ms1_load(port_fd,file_fd);
	}
	else if ((GINT)DATA_GET(global_data,"persona") == MS2)
	{
		setup_port(port_fd, 115200);
		do_ms2_load(port_fd,file_fd);
	}
	else if ((GINT)DATA_GET(global_data,"persona") == FREEEMS)
	{
		setup_port(port_fd, 115200);
		do_freeems_load(port_fd,file_fd);
	}
	unlock_buttons();
	close_port(port_fd);
	unlock_port();
	return TRUE;
}
Exemple #2
0
/*!
 \brief main() is the typical main function in a C program, it performs
 all core initialization, loading of all main parameters, initializing handlers
 and entering gtk_main to process events until program close
 \param argc (gint) count of command line arguments
 \param argv (char **) array of command line args
 \returns TRUE
 */
gint main(gint argc, gchar ** argv)
{
	gint port_fd = 0;
	gint file_fd = 0;
	
	verify_args(argc, argv);

	output(g_strdup_printf("MegaTunix msloader %s\n",VERSION),TRUE);

	/* If we got this far, all is good argument wise */
	if (!lock_port(argv[2]))
	{
		output("Could NOT LOCK Serial Port\nCheck for already running serial apps using the port\n",FALSE);
		exit(-1);
	}

	port_fd = open_port(argv[2]);
	if (port_fd > 0)
		output("Port successfully opened\n",FALSE);
	else
	{
		output("Could NOT open Port check permissions\n",FALSE);
		unlock_port();
		exit(-1);
	}
#ifdef __WIN32__
	file_fd = open(argv[3], O_RDWR | O_BINARY );
#else
	file_fd = g_open(argv[3],O_RDONLY,S_IRUSR);
#endif
	if (file_fd > 0 )
		output("Firmware file successfully opened\n",FALSE);
	else
	{
		output("Could NOT open firmware file, check permissions/paths\n",FALSE);
		close_port(port_fd);
		unlock_port();
		exit(-1);
	}
	if (type == MS1)
	{
		setup_port(port_fd, 9600);
		do_ms1_load(port_fd,file_fd);
	}
	else if (type == MS2)
	{
		setup_port(port_fd,115200);
		do_ms2_load(port_fd,file_fd);
	}

	else if (type == FREEEMS)
	{
		setup_port(port_fd,115200);
		do_freeems_load(port_fd,file_fd);
	}

	flush_serial(port_fd,BOTH);
	close_port(port_fd);
	unlock_port();
	return (0) ;
}