コード例 #1
0
ファイル: dialog.cpp プロジェクト: tanhangbo/myshell
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    /* UTF-8 support */
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    ui->setupUi(this);

    QString title = "MyShell 0.4 - tanhangbo build " + tr(__DATE__);
    this->setWindowTitle(title);
    this->setWindowFlags(this->windowFlags() | Qt::WindowMinMaxButtonsHint);



    serial = new QSerialPort(this);
    connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(handleError(QSerialPort::SerialPortError)));
    connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));



    standardItemModel = new QStandardItemModel(this);
    ui->history_list->setModel(standardItemModel);

    ui->status->setText("");

    /* arrow up and down event */
    ui->sendcontent->installEventFilter(this);
    ui->receive_content->installEventFilter(this);
    history_index = 0;
    current_index = 0;


    log_current_file_name = "";
    log_is_logging = false;
    cur_file = NULL;

    receive_buffer = "";

    error_closed = 0;

    need_add_time = false;
    find_serial();




    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timer_update()));
    timer->start(10);



}
コード例 #2
0
ファイル: angeld.c プロジェクト: kevinriehm/evt-black-box
void monitor() {
	static const int bufsize = 1024;

	int nready;
	int reading;
	ssize_t nread;
	char buf[bufsize];
	struct pollfd pollfd;

	pollfd.fd = serialfd;
	pollfd.events = POLLIN | POLLHUP;

	while(1) {
		nready = poll(&pollfd,1,-1);
		if(nready < 0) syslog(LOG_WARNING,"poll error (%m)");

		if(pollfd.revents & POLLIN) {
			buf[0] = '\0';
			reading = nread = 0;
			while(nread >= 0
				&& (!strchr(buf,'{') || !strchr(buf,'}'))) {
				nread += read(serialfd,buf + nread,nready);

				if(!reading && !strchr(buf,'{')) break;
				else reading = 1;

				if(nread >= bufsize) {
					buf[bufsize - 1] = '\0';
					break;
				}
				if(nread >= 0) buf[nread] = '\0';

				nready = 1;
			}
			if(nread < 0) syslog(LOG_WARNING,"read error (%m)");

			parse(buf);
		}

		if(pollfd.revents & POLLHUP) {
			syslog(LOG_NOTICE,"serial device removed");

			close(serialfd);
			find_serial();
			pollfd.fd = serialfd;
		}
	}
}
コード例 #3
0
ファイル: angeld.c プロジェクト: kevinriehm/evt-black-box
void init_com() {
	char *msg;
	int err, fd;
	struct stat stat;
	char *dbname, *keyname;

	umask(0);

	/* XBee serial device */
	inotifyfd = inotify_init();
	find_serial();

	/* SQLite3 database */
	dbname = getenv("ANGEL_DB");
	if(!dbname) dbname = "/var/opt/staevt.com/angel/angel.sqlite3";
	err = sqlite3_open(dbname,&db);
	if(err != SQLITE_OK) die("cannot open database '%s'",dbname);

	sqlite3_exec(db,"PRAGMA journal_mode=WAL",NULL,NULL,&msg);
	if(msg) die(msg);
	sqlite3_exec(db,"CREATE TABLE IF NOT EXISTS cars ("
		"car TEXT, time_received TIMESTAMP"
			" DEFAULT (strftime('%s','now')),"
		"time INTEGER, amperage REAL, voltage REAL, latitude REAL,"
		"longitude REAL, speed REAL, PRIMARY KEY (car, time_received)"
	")",NULL,NULL,&msg);
	if(msg) die(msg);

	/* HMAC key */
	keyname = getenv("ANGEL_KEY");
	if(!keyname) keyname = "/var/opt/staevt.com/angel/hmac.key";
	fd = open(keyname,O_RDONLY);
	if(fd < 0) die("cannot open HMAC key file '%s'",keyname);
	fstat(fd,&stat);
	hmackeysize = stat.st_size;
	hmackey = malloc(hmackeysize);
	if(!hmackey) die("cannot allocate memory for HMAC key");
	read(fd,hmackey,hmackeysize);
	close(fd);
}