Exemplo n.º 1
0
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();



}
Exemplo n.º 2
0
int main(int argc, char** argv){
	CONFIG cfg;

	cfg_init(&cfg);

	//read commandline args
	if(!arg_parse(&cfg, argc-1, argv+1)){
		return -1;
	}

	//read config file
	if(!cfg.cfg_file){
		fprintf(stderr, "No config file supplied\n");
		return -1;
	}
	if(!cfg_read(&cfg, cfg.cfg_file)){
		cfg_free(&cfg);
		return -1;
	}

	//if not using pgpass, ask for database password
	if(!cfg.db.use_pgpass){
		cfg.db.pass=calloc(sizeof(char),MAX_PASSWORD_LENGTH+1);
		if(!cfg.db.pass){
			fprintf(stderr, "Failed to allocate memory\n");
			cfg_free(&cfg);
			return -1;
		}
		fprintf(stderr, "DB Password: "******"\fWaiting...");
		ask_password(cfg.db.pass, MAX_PASSWORD_LENGTH);
	}

	//check for sane config
	if(!cfg_sane(&cfg)){
		cfg_free(&cfg);
		return -1;
	}

	//connect to database if persistent
	if(cfg.db.persist_connection){
		if(!pq_connect(&(cfg.db))){
			cfg_free(&cfg);
			return -1;
		}
		if(cfg.verbosity>2){
			fprintf(stderr, "Database connection established\n");	
		}
	}

	//connect to remote devices
	if(!comms_open(&cfg)){
		comms_close(&cfg);
		pq_close(&(cfg.db));
		cfg_free(&cfg);
		return -1;
	}
	
	//set up signal handlers
	signal(SIGINT, sig_interrupt);
	signal(SIGTERM, sig_terminate);

	//run the state machine
	garfield_pos(&cfg);

	comms_close(&cfg);
	pq_close(&(cfg.db));
	cfg_free(&cfg);
	return 0;
}