From c576ed40e2fbdcc64d423b3f8d746c37cadd51f2 Mon Sep 17 00:00:00 2001 From: Rostislav Lisovy Date: Fri, 8 Apr 2011 22:47:42 +0200 Subject: [PATCH] First version of graphical Qt interface to Qemu MF624 hardware. Only DOUT works. --- src/qemu/mf624_interface/untitled/main.cpp | 22 + .../mf624_interface/untitled/mainwindow.cpp | 84 ++ .../mf624_interface/untitled/mainwindow.h | 41 + .../mf624_interface/untitled/mainwindow.ui | 815 ++++++++++++++++++ .../untitled/mf624_io_status.h | 14 + .../untitled/socket_thread.cpp | 136 +++ .../mf624_interface/untitled/socket_thread.h | 17 + .../mf624_interface/untitled/untitled.pro | 22 + 8 files changed, 1151 insertions(+) create mode 100644 src/qemu/mf624_interface/untitled/main.cpp create mode 100644 src/qemu/mf624_interface/untitled/mainwindow.cpp create mode 100644 src/qemu/mf624_interface/untitled/mainwindow.h create mode 100644 src/qemu/mf624_interface/untitled/mainwindow.ui create mode 100644 src/qemu/mf624_interface/untitled/mf624_io_status.h create mode 100644 src/qemu/mf624_interface/untitled/socket_thread.cpp create mode 100644 src/qemu/mf624_interface/untitled/socket_thread.h create mode 100644 src/qemu/mf624_interface/untitled/untitled.pro diff --git a/src/qemu/mf624_interface/untitled/main.cpp b/src/qemu/mf624_interface/untitled/main.cpp new file mode 100644 index 0000000..d0cee8d --- /dev/null +++ b/src/qemu/mf624_interface/untitled/main.cpp @@ -0,0 +1,22 @@ +#include +#include "mainwindow.h" +#include "mf624_io_status.h" + +mf624_io_status_t mf624_io_status; + +int main(int argc, char *argv[]) +{ + mf624_io_status.DIN = 0; + mf624_io_status.DOUT = 0; + mf624_io_status.DA0 = 0; + mf624_io_status.DA1 = 0; + mf624_io_status.AD0 = 0; + mf624_io_status.AD1 = 0; + + + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/src/qemu/mf624_interface/untitled/mainwindow.cpp b/src/qemu/mf624_interface/untitled/mainwindow.cpp new file mode 100644 index 0000000..84bd612 --- /dev/null +++ b/src/qemu/mf624_interface/untitled/mainwindow.cpp @@ -0,0 +1,84 @@ +#include +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "socket_thread.h" +#include "mf624_io_status.h" +extern mf624_io_status_t mf624_io_status; + + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + // Set fixed size for window + this->setFixedSize(this->width(), this->height()); + + // create new thread (on heap) and start it + s_thread = new socket_thread(this); + s_thread->start(); // after this, thread's run() method starts + +} + +MainWindow::~MainWindow() +{ + delete ui; +} + + +void MainWindow::din_set(int bit, int val) +{ + if(val == 0) { + mf624_io_status.DIN &= ~(1 << bit); + } + else if (val == 2) { + mf624_io_status.DIN |= (1 << bit); + } + + s_thread->socket_send("DIN=%d\n", mf624_io_status.DIN); +} + +void MainWindow::on_checkBox_stateChanged(int arg1) +{ + din_set(0, arg1); +} + +void MainWindow::on_checkBox_2_stateChanged(int arg1) +{ + din_set(1, arg1); +} + +void MainWindow::on_checkBox_3_stateChanged(int arg1) +{ + din_set(2, arg1); +} + +void MainWindow::on_checkBox_4_stateChanged(int arg1) +{ + din_set(3, arg1); +} + +void MainWindow::on_checkBox_5_stateChanged(int arg1) +{ + din_set(4, arg1); +} + +void MainWindow::on_checkBox_6_stateChanged(int arg1) +{ + din_set(5, arg1); +} + +void MainWindow::on_checkBox_7_stateChanged(int arg1) +{ + din_set(6, arg1); +} + +void MainWindow::on_checkBox_8_stateChanged(int arg1) +{ + din_set(7, arg1); +} + +void MainWindow::on_horizontalSlider_valueChanged(int value) +{ + s_thread->socket_send("ADC0=%d\n", value); +} diff --git a/src/qemu/mf624_interface/untitled/mainwindow.h b/src/qemu/mf624_interface/untitled/mainwindow.h new file mode 100644 index 0000000..504063e --- /dev/null +++ b/src/qemu/mf624_interface/untitled/mainwindow.h @@ -0,0 +1,41 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "socket_thread.h" + + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + Ui::MainWindow *ui; + +private slots: + void on_checkBox_stateChanged(int arg1); + void on_checkBox_2_stateChanged(int arg1); + void on_checkBox_3_stateChanged(int arg1); + void on_checkBox_4_stateChanged(int arg1); + void on_checkBox_5_stateChanged(int arg1); + void on_checkBox_6_stateChanged(int arg1); + void on_checkBox_7_stateChanged(int arg1); + void on_checkBox_8_stateChanged(int arg1); + + + void on_horizontalSlider_valueChanged(int value); + +private: + int DIN; //DIN register + + void din_set(int bit, int val); + socket_thread *s_thread; +}; + +#endif // MAINWINDOW_H diff --git a/src/qemu/mf624_interface/untitled/mainwindow.ui b/src/qemu/mf624_interface/untitled/mainwindow.ui new file mode 100644 index 0000000..7ab00d1 --- /dev/null +++ b/src/qemu/mf624_interface/untitled/mainwindow.ui @@ -0,0 +1,815 @@ + + + MainWindow + + + + 0 + 0 + 612 + 585 + + + + + 0 + 0 + + + + MainWindow + + + + + + 10 + 10 + 421 + 22 + + + + + 14 + 75 + true + + + + Humusoft MF624 DAQ input/output interface + + + + + + 11 + 41 + 591 + 70 + + + + + 0 + 0 + + + + + 16777213 + 70 + + + + DIN + + + + + 10 + 30 + 574 + 31 + + + + + + + 7 + + + + + + + 6 + + + + + + + 5 + + + + + + + 4 + + + + + + + 3 + + + + + + + 2 + + + + + + + 1 + + + + + + + 0 + + + + + + + + + + 11 + 115 + 591 + 70 + + + + + 0 + 0 + + + + + 16777215 + 70 + + + + DOUT + + + + + 10 + 40 + 571 + 24 + + + + + + + false + + + 7 + + + true + + + + + + + false + + + 6 + + + true + + + + + + + false + + + 5 + + + true + + + + + + + false + + + 4 + + + true + + + + + + + false + + + 3 + + + true + + + + + + + false + + + 2 + + + true + + + + + + + false + + + 1 + + + true + + + + + + + false + + + 0 + + + true + + + + + + + + + + 11 + 189 + 281 + 331 + + + + ADC + + + + + 20 + 30 + 241 + 286 + + + + + + + + + -100 + + + 100 + + + 1 + + + Qt::Horizontal + + + + + + + -100 + + + 100 + + + + + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + -100 + + + 100 + + + + + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + -100 + + + 100 + + + + + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + -100 + + + 100 + + + + + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + -100 + + + 100 + + + + + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + -100 + + + 100 + + + + + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + -100 + + + 100 + + + + + + + + + + + -100 + + + 100 + + + Qt::Horizontal + + + + + + + -100 + + + 100 + + + + + + + + + + + + 300 + 190 + 301 + 331 + + + + DAC + + + + + + + 0 + 0 + 612 + 28 + + + + + + TopToolBarArea + + + false + + + + + + + + + horizontalSlider + valueChanged(int) + spinBox + setValue(int) + + + 437 + 341 + + + 554 + 341 + + + + + horizontalSlider_2 + valueChanged(int) + spinBox_2 + setValue(int) + + + 113 + 348 + + + 234 + 348 + + + + + horizontalSlider_3 + valueChanged(int) + spinBox_3 + setValue(int) + + + 113 + 384 + + + 234 + 384 + + + + + horizontalSlider_4 + valueChanged(int) + spinBox_4 + setValue(int) + + + 113 + 420 + + + 234 + 420 + + + + + horizontalSlider_5 + valueChanged(int) + spinBox_5 + setValue(int) + + + 113 + 456 + + + 234 + 456 + + + + + horizontalSlider_6 + valueChanged(int) + spinBox_6 + setValue(int) + + + 113 + 492 + + + 234 + 492 + + + + + horizontalSlider_7 + valueChanged(int) + spinBox_7 + setValue(int) + + + 113 + 528 + + + 234 + 528 + + + + + horizontalSlider_8 + valueChanged(int) + spinBox_8 + setValue(int) + + + 113 + 564 + + + 180 + 569 + + + + + spinBox + valueChanged(int) + horizontalSlider + setValue(int) + + + 234 + 312 + + + 113 + 312 + + + + + spinBox_2 + valueChanged(int) + horizontalSlider_2 + setValue(int) + + + 234 + 348 + + + 113 + 348 + + + + + spinBox_3 + valueChanged(int) + horizontalSlider_3 + setValue(int) + + + 234 + 384 + + + 113 + 384 + + + + + spinBox_4 + valueChanged(int) + horizontalSlider_4 + setValue(int) + + + 234 + 420 + + + 113 + 420 + + + + + spinBox_5 + valueChanged(int) + horizontalSlider_5 + setValue(int) + + + 234 + 456 + + + 113 + 456 + + + + + spinBox_6 + valueChanged(int) + horizontalSlider_6 + setValue(int) + + + 234 + 492 + + + 113 + 492 + + + + + spinBox_7 + valueChanged(int) + horizontalSlider_7 + setValue(int) + + + 234 + 528 + + + 113 + 528 + + + + + spinBox_8 + valueChanged(int) + horizontalSlider_8 + setValue(int) + + + 180 + 569 + + + 113 + 564 + + + + + diff --git a/src/qemu/mf624_interface/untitled/mf624_io_status.h b/src/qemu/mf624_interface/untitled/mf624_io_status.h new file mode 100644 index 0000000..76406a6 --- /dev/null +++ b/src/qemu/mf624_interface/untitled/mf624_io_status.h @@ -0,0 +1,14 @@ +#ifndef MF624_IO_STATUS_H +#define MF624_IO_STATUS_H + + +typedef struct { + unsigned int DIN; + unsigned int DOUT; + int DA0; + int DA1; + int AD0; + int AD1; +} mf624_io_status_t; + +#endif // MF624_IO_STATUS_H diff --git a/src/qemu/mf624_interface/untitled/socket_thread.cpp b/src/qemu/mf624_interface/untitled/socket_thread.cpp new file mode 100644 index 0000000..2815523 --- /dev/null +++ b/src/qemu/mf624_interface/untitled/socket_thread.cpp @@ -0,0 +1,136 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "socket_thread.h" +#include "mf624_io_status.h" +#include "mainwindow.h" +#include "ui_mainwindow.h" +extern mf624_io_status_t mf624_io_status; + + +socket_thread::socket_thread(QObject *parent) +: QThread(parent) +{ + +} + +void socket_thread::socket_send(const char* str, int val) +{ + int n; + char buffer[256]; + sprintf(buffer, str, val); + + n = ::write(sockfd, buffer, strlen(buffer)); + if (n < 0) { + perror("write()"); + } + printf(str, val); +} + + +void socket_thread::run() +{ +#define STRING_BUFF_SIZE 256 + qDebug() << "Executing in new independant thread, GUI is NOT blocked"; + + int portno; + int n; + int status; + struct sockaddr_in serv_addr; + struct hostent *server; + char read_buffer[STRING_BUFF_SIZE]; + char reg[STRING_BUFF_SIZE+1]; + int val; + char buffer[256]; + + //if (argc < 3) { + // fprintf(stderr,"usage %s hostname port\n", argv[0]); + // exit(0); + //} + //portno = atoi(argv[2]); + portno = atoi("55555"); + + sockfd = ::socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { + perror("socket()"); + exit(0); + } + + //server = gethostbyname(argv[1]); + server = ::gethostbyname("127.0.0.1"); + if (server == NULL) { + perror("gethostbyname()"); + exit(0); + } + + memset((char *) &serv_addr, '\0', sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + bcopy((char *)server->h_addr, + (char *)&serv_addr.sin_addr.s_addr, + server->h_length); + + serv_addr.sin_port = htons(portno); + if (::connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { + perror("connect()"); + } + + + memset(buffer, '\0', 256); + while(1) { + n = read(sockfd, buffer, 255); + if (n < 0) { + perror("read()"); + } + + status = sscanf(buffer, "%[A-Z]=%u", reg, &val); + if (status == 2) { + if(!strcmp(reg, "DOUT")) { + mf624_io_status.DOUT = val; + } + } + + ((MainWindow*) parent())->ui->checkBox_9->setChecked(false); + ((MainWindow*) parent())->ui->checkBox_10->setChecked(false); + ((MainWindow*) parent())->ui->checkBox_11->setChecked(false); + ((MainWindow*) parent())->ui->checkBox_12->setChecked(false); + ((MainWindow*) parent())->ui->checkBox_13->setChecked(false); + ((MainWindow*) parent())->ui->checkBox_14->setChecked(false); + ((MainWindow*) parent())->ui->checkBox_15->setChecked(false); + ((MainWindow*) parent())->ui->checkBox_16->setChecked(false); + if (mf624_io_status.DOUT & (1 << 0)) { + ((MainWindow*) parent())->ui->checkBox_9->setChecked(true); + } + if (mf624_io_status.DOUT & (1 << 1)) { + ((MainWindow*) parent())->ui->checkBox_10->setChecked(true); + } + if (mf624_io_status.DOUT & (1 << 2)) { + ((MainWindow*) parent())->ui->checkBox_11->setChecked(true); + } + if (mf624_io_status.DOUT & (1 << 3)) { + ((MainWindow*) parent())->ui->checkBox_12->setChecked(true); + } + if (mf624_io_status.DOUT & (1 << 4)) { + ((MainWindow*) parent())->ui->checkBox_13->setChecked(true); + } + if (mf624_io_status.DOUT & (1 << 5)) { + ((MainWindow*) parent())->ui->checkBox_14->setChecked(true); + } + if (mf624_io_status.DOUT & (1 << 6)) { + ((MainWindow*) parent())->ui->checkBox_15->setChecked(true); + } + if (mf624_io_status.DOUT & (1 << 7)) { + ((MainWindow*) parent())->ui->checkBox_16->setChecked(true); + } + + //printf("%s\n", buffer); + } + //close(sockfd); + + exec(); +} + diff --git a/src/qemu/mf624_interface/untitled/socket_thread.h b/src/qemu/mf624_interface/untitled/socket_thread.h new file mode 100644 index 0000000..1ff0dd6 --- /dev/null +++ b/src/qemu/mf624_interface/untitled/socket_thread.h @@ -0,0 +1,17 @@ +#ifndef SOCKET_THREAD_H +#define SOCKET_THREAD_H + +#include + +class socket_thread : public QThread +{ + Q_OBJECT + int sockfd; //Socket to server + +public: + socket_thread(QObject *parent); + void run(); // this is virtual method, we must implement it in our subclass of QThread + void socket_send(const char* str, int val); +}; + +#endif // SOCKET_THREAD_H diff --git a/src/qemu/mf624_interface/untitled/untitled.pro b/src/qemu/mf624_interface/untitled/untitled.pro new file mode 100644 index 0000000..fa5e863 --- /dev/null +++ b/src/qemu/mf624_interface/untitled/untitled.pro @@ -0,0 +1,22 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-04-07T12:06:20 +# +#------------------------------------------------- + +#LIBS = -lsocket +QT += core gui + +TARGET = untitled +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + socket_thread.cpp + +HEADERS += mainwindow.h \ + socket_thread.h \ + mf624_io_status.h + +FORMS += mainwindow.ui -- 2.39.2