5 #include <sys/socket.h>
6 #include <netinet/in.h>
9 #include "socket_thread.h"
10 #include "mf624_io_status.h"
11 #include "mainwindow.h"
12 #include "ui_mainwindow.h"
13 extern mf624_io_status_t mf624_io_status;
16 socket_thread::socket_thread(QObject *parent)
22 void socket_thread::socket_send(const char* str, int val)
26 sprintf(buffer, str, val);
29 n = ::write(sockfd, buffer, strlen(buffer));
34 //qDebug() << "MF624 in Qemu not runnig?";
38 void socket_thread::run()
40 #define STRING_BUFF_SIZE 256
41 qDebug() << "Executing in new independant thread, GUI is NOT blocked";
46 struct sockaddr_in serv_addr;
47 struct hostent *server;
48 char read_buffer[STRING_BUFF_SIZE];
49 char reg[STRING_BUFF_SIZE+1];
54 // fprintf(stderr,"usage %s hostname port\n", argv[0]);
57 //portno = atoi(argv[2]);
58 portno = atoi("55555");
60 sockfd = ::socket(AF_INET, SOCK_STREAM, 0);
66 //server = gethostbyname(argv[1]);
67 server = ::gethostbyname("127.0.0.1");
69 perror("gethostbyname()");
73 memset((char *) &serv_addr, '\0', sizeof(serv_addr));
74 serv_addr.sin_family = AF_INET;
75 bcopy((char *)server->h_addr,
76 (char *)&serv_addr.sin_addr.s_addr,
79 serv_addr.sin_port = htons(portno);
80 if (::connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
86 memset(buffer, '\0', 256);
87 n = read(sockfd, buffer, 255);
93 status = sscanf(buffer, "%[A-Z0-9]=%u", reg, &val);
95 if(!strcmp(reg, "DOUT")) {
96 mf624_io_status.DOUT = val;
98 if(!strcmp(reg, "DA0")) {
99 mf624_io_status.DA0 = val;
101 if(!strcmp(reg, "DA1")) {
102 mf624_io_status.DA1 = val;
104 if(!strcmp(reg, "DA2")) {
105 mf624_io_status.DA2 = val;
107 if(!strcmp(reg, "DA3")) {
108 mf624_io_status.DA3 = val;
110 if(!strcmp(reg, "DA4")) {
111 mf624_io_status.DA4 = val;
113 if(!strcmp(reg, "DA5")) {
114 mf624_io_status.DA5 = val;
116 if(!strcmp(reg, "DA6")) {
117 mf624_io_status.DA6 = val;
119 if(!strcmp(reg, "DA7")) {
120 mf624_io_status.DA7 = val;
125 ((MainWindow*) parent())->ui->checkBox_9->setChecked(false);
126 ((MainWindow*) parent())->ui->checkBox_10->setChecked(false);
127 ((MainWindow*) parent())->ui->checkBox_11->setChecked(false);
128 ((MainWindow*) parent())->ui->checkBox_12->setChecked(false);
129 ((MainWindow*) parent())->ui->checkBox_13->setChecked(false);
130 ((MainWindow*) parent())->ui->checkBox_14->setChecked(false);
131 ((MainWindow*) parent())->ui->checkBox_15->setChecked(false);
132 ((MainWindow*) parent())->ui->checkBox_16->setChecked(false);
133 if (mf624_io_status.DOUT & (1 << 0)) {
134 ((MainWindow*) parent())->ui->checkBox_9->setChecked(true);
136 if (mf624_io_status.DOUT & (1 << 1)) {
137 ((MainWindow*) parent())->ui->checkBox_10->setChecked(true);
139 if (mf624_io_status.DOUT & (1 << 2)) {
140 ((MainWindow*) parent())->ui->checkBox_11->setChecked(true);
142 if (mf624_io_status.DOUT & (1 << 3)) {
143 ((MainWindow*) parent())->ui->checkBox_12->setChecked(true);
145 if (mf624_io_status.DOUT & (1 << 4)) {
146 ((MainWindow*) parent())->ui->checkBox_13->setChecked(true);
148 if (mf624_io_status.DOUT & (1 << 5)) {
149 ((MainWindow*) parent())->ui->checkBox_14->setChecked(true);
151 if (mf624_io_status.DOUT & (1 << 6)) {
152 ((MainWindow*) parent())->ui->checkBox_15->setChecked(true);
154 if (mf624_io_status.DOUT & (1 << 7)) {
155 ((MainWindow*) parent())->ui->checkBox_16->setChecked(true);
159 ((MainWindow*) parent())->ui->dac0_slider->setValue(mf624_io_status.DA0);
160 ((MainWindow*) parent())->ui->dac1_slider->setValue(mf624_io_status.DA1);
161 ((MainWindow*) parent())->ui->dac2_slider->setValue(mf624_io_status.DA2);
162 ((MainWindow*) parent())->ui->dac3_slider->setValue(mf624_io_status.DA3);
163 ((MainWindow*) parent())->ui->dac4_slider->setValue(mf624_io_status.DA4);
164 ((MainWindow*) parent())->ui->dac5_slider->setValue(mf624_io_status.DA5);
165 ((MainWindow*) parent())->ui->dac6_slider->setValue(mf624_io_status.DA6);
166 ((MainWindow*) parent())->ui->dac7_slider->setValue(mf624_io_status.DA7);
168 //printf("%s\n", buffer);