コード例 #1
0
ファイル: host.cpp プロジェクト: craig-unilectric/pdp
Host::Host(QWidget *ParentMainWin, USB_VCP *usbObj) :
    QWidget(ParentMainWin)
{

    // Rename obj pointers for convenience
    mainWin = (MainWindow*)ParentMainWin;
    ui = (Ui::MainWindow*)mainWin->ui;
    usb_vcp = (USB_VCP*)usbObj;



    // Comms
    connect(ui->pushButton_comms_open, SIGNAL(clicked()), this, SLOT(comms_open()));
    connect(ui->pushButton_comms_test, SIGNAL(clicked()), this, SLOT(comms_test()));
    //ui->listWidget_comms_list->hide();
    connect(ui->listWidget_comms_list, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(comms_open_selected(QListWidgetItem*)));



    // PDP
    connect(ui->pushButton_read_DMA, SIGNAL(clicked()), this, SLOT(read_DMA()));
    ui->pushButton_read_DMA->setVisible(false);


    connect(ui->pushButton_read_AC, SIGNAL(clicked()), this, SLOT(read_channelDMA()));
    ui->pushButton_read_AC->setVisible(false);
    connect(ui->pushButton_read_AC_filtered, SIGNAL(clicked()), this, SLOT(read_channelDMA_filtered()));

    connect(ui->pushButton_write_command, SIGNAL(clicked()), this, SLOT(write_command()));
    connect(ui->pushButton_read_status, SIGNAL(clicked()), this, SLOT(read_status()));


    connect(ui->pushButton_read_relay, SIGNAL(clicked()), this, SLOT(relay_read()));
    connect(ui->radioButton_relayOn, SIGNAL(clicked()), this, SLOT(relay_on()));
    connect(ui->radioButton_relayOff, SIGNAL(clicked()), this, SLOT(relay_off()));





    QGridLayout *gbox = new QGridLayout(ui->groupBox_relaySelect);
    int i = 0;
    for(int x = 0;x < 4; x++)
    {
        for(int y = 0;y < 4; y++)
        {
            relaySelectButton[i] = new QRadioButton(IntToStr(i));
            gbox->addWidget(relaySelectButton[i], y, x);
            connect(relaySelectButton[i], SIGNAL(clicked()), this, SLOT(relay_selected()));
            i++;
        }
    }
    ui->groupBox_relaySelect->setLayout(gbox);
    relayNumberSelected = 0;
    relaySelectButton[relayNumberSelected]->setChecked(true);



    // PDP graph init
    graph_init();



}
コード例 #2
0
ファイル: libreems_comms.c プロジェクト: JacobD10/MegaTunix
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;
}