Commit f97982552ebf448c99e0236e7f38c8f46cbd60fa

Authored by 김태훈
1 parent d43c6c1724
Exists in master and in 2 other branches fhd, fhd-demo

가상 UDP 패킷 전송 기능 추가

app/gui/packet/mainwindow.cpp
@@ -5,11 +5,6 @@ @@ -5,11 +5,6 @@
5 5
6 #include "tablevalue.h" 6 #include "tablevalue.h"
7 7
8 -typedef struct {  
9 - int header;  
10 - char body[];  
11 -} STRUCT_PACK packet_t;  
12 -  
13 MainWindow::MainWindow(QWidget *parent) : 8 MainWindow::MainWindow(QWidget *parent) :
14 QMainWindow(parent), 9 QMainWindow(parent),
15 ui(new Ui::MainWindow) 10 ui(new Ui::MainWindow)
@@ -19,10 +14,11 @@ MainWindow::MainWindow(QWidget *parent) : @@ -19,10 +14,11 @@ MainWindow::MainWindow(QWidget *parent) :
19 if (!sock->bind(4000)) 14 if (!sock->bind(4000))
20 exit(EXIT_FAILURE); 15 exit(EXIT_FAILURE);
21 16
  17 +
22 connect(sock, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); 18 connect(sock, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
23 19
24 ui->controlTable->setRowCount(sizeof(oven_control_t) / sizeof(U16)); 20 ui->controlTable->setRowCount(sizeof(oven_control_t) / sizeof(U16));
25 - ui->controlTable->setColumnCount(4); 21 + ui->controlTable->setColumnCount(5);
26 ui->controlTable->setHorizontalHeaderLabels(QString("Addr,Value,Value,Description").split(",")); 22 ui->controlTable->setHorizontalHeaderLabels(QString("Addr,Value,Value,Description").split(","));
27 23
28 for (int row = 0; row < ui->controlTable->rowCount(); row++) 24 for (int row = 0; row < ui->controlTable->rowCount(); row++)
@@ -50,7 +46,7 @@ MainWindow::MainWindow(QWidget *parent) : @@ -50,7 +46,7 @@ MainWindow::MainWindow(QWidget *parent) :
50 ui->controlTable->resizeColumnToContents(1); 46 ui->controlTable->resizeColumnToContents(1);
51 47
52 ui->stateTable->setRowCount(sizeof(oven_state_t) / sizeof(U16)); 48 ui->stateTable->setRowCount(sizeof(oven_state_t) / sizeof(U16));
53 - ui->stateTable->setColumnCount(4); 49 + ui->stateTable->setColumnCount(5);
54 ui->stateTable->setHorizontalHeaderLabels(QString("Addr,Value,Value,Description").split(",")); 50 ui->stateTable->setHorizontalHeaderLabels(QString("Addr,Value,Value,Description").split(","));
55 51
56 for (int row = 0; row < ui->stateTable->rowCount(); row++) 52 for (int row = 0; row < ui->stateTable->rowCount(); row++)
@@ -136,6 +132,8 @@ MainWindow::MainWindow(QWidget *parent) : @@ -136,6 +132,8 @@ MainWindow::MainWindow(QWidget *parent) :
136 132
137 ui->controlTable->resizeColumnToContents(3); 133 ui->controlTable->resizeColumnToContents(3);
138 ui->stateTable->resizeColumnToContents(3); 134 ui->stateTable->resizeColumnToContents(3);
  135 +
  136 +
139 } 137 }
140 138
141 MainWindow::~MainWindow() 139 MainWindow::~MainWindow()
@@ -224,3 +222,40 @@ void MainWindow::updateState(oven_state_t *state) @@ -224,3 +222,40 @@ void MainWindow::updateState(oven_state_t *state)
224 } 222 }
225 } 223 }
226 } 224 }
  225 +
  226 +void MainWindow::on_pushControlButton_clicked()
  227 +{
  228 + U16 *base = (U16 *) &this->control;
  229 + for (int row = 0; row < ui->controlTable->rowCount(); row++)
  230 + {
  231 + QTableWidgetItem *val = (QTableWidgetItem *) ui->controlTable->item(row, 4);
  232 + if (val)
  233 + *(base + row) = val->text().toUShort(nullptr, 10);
  234 + }
  235 +
  236 + gui_oven_control_t c;
  237 + c.header = HDR_OVEN_CONTROL;
  238 + memcpy(&c.control, &this->control, sizeof(this->control));
  239 +
  240 + QByteArray datagram = QByteArray::fromRawData((char *) &c, sizeof(c));
  241 + sock->writeDatagram(datagram, QHostAddress("192.168.10.139"), 4000);
  242 +}
  243 +
  244 +void MainWindow::on_pushStateButton_clicked()
  245 +{
  246 + oven_state_t state = this->state;
  247 + U16 *base = (U16 *) &state;
  248 + for (int row = 0; row < ui->stateTable->rowCount(); row++)
  249 + {
  250 + QTableWidgetItem *val = (QTableWidgetItem *) ui->stateTable->item(row, 4);
  251 + if (val)
  252 + *(base + row) = val->text().toUShort(nullptr, 10);
  253 + }
  254 +
  255 + gui_oven_state_t c;
  256 + c.header = HDR_OVEN_STATE;
  257 + memcpy(&c.state, &state, sizeof(state));
  258 +
  259 + QByteArray datagram = QByteArray::fromRawData((char *) &c, sizeof(c));
  260 + sock->writeDatagram(datagram, QHostAddress("192.168.10.139"), 4000);
  261 +}
app/gui/packet/mainwindow.h
@@ -10,6 +10,11 @@ namespace Ui { @@ -10,6 +10,11 @@ namespace Ui {
10 class MainWindow; 10 class MainWindow;
11 } 11 }
12 12
  13 +typedef struct {
  14 + int header;
  15 + char body[];
  16 +} STRUCT_PACK packet_t;
  17 +
13 class MainWindow : public QMainWindow 18 class MainWindow : public QMainWindow
14 { 19 {
15 Q_OBJECT 20 Q_OBJECT
@@ -31,6 +36,8 @@ private slots: @@ -31,6 +36,8 @@ private slots:
31 void processState(oven_state_t *state); 36 void processState(oven_state_t *state);
32 void updateControl(oven_control_t *control); 37 void updateControl(oven_control_t *control);
33 void updateState(oven_state_t *state); 38 void updateState(oven_state_t *state);
  39 + void on_pushControlButton_clicked();
  40 + void on_pushStateButton_clicked();
34 }; 41 };
35 42
36 #endif // MAINWINDOW_H 43 #endif // MAINWINDOW_H
app/gui/packet/mainwindow.ui
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 <x>0</x> 7 <x>0</x>
8 <y>0</y> 8 <y>0</y>
9 <width>818</width> 9 <width>818</width>
10 - <height>300</height> 10 + <height>403</height>
11 </rect> 11 </rect>
12 </property> 12 </property>
13 <property name="windowTitle"> 13 <property name="windowTitle">
@@ -16,10 +16,32 @@ @@ -16,10 +16,32 @@
16 <widget class="QWidget" name="centralWidget"> 16 <widget class="QWidget" name="centralWidget">
17 <layout class="QHBoxLayout" name="horizontalLayout"> 17 <layout class="QHBoxLayout" name="horizontalLayout">
18 <item> 18 <item>
19 - <widget class="QTableWidget" name="controlTable"/> 19 + <layout class="QVBoxLayout" name="verticalLayout">
  20 + <item>
  21 + <widget class="QTableWidget" name="controlTable"/>
  22 + </item>
  23 + <item>
  24 + <widget class="QPushButton" name="pushControlButton">
  25 + <property name="text">
  26 + <string>Push</string>
  27 + </property>
  28 + </widget>
  29 + </item>
  30 + </layout>
20 </item> 31 </item>
21 <item> 32 <item>
22 - <widget class="QTableWidget" name="stateTable"/> 33 + <layout class="QVBoxLayout" name="verticalLayout_2">
  34 + <item>
  35 + <widget class="QTableWidget" name="stateTable"/>
  36 + </item>
  37 + <item>
  38 + <widget class="QPushButton" name="pushStateButton">
  39 + <property name="text">
  40 + <string>Push</string>
  41 + </property>
  42 + </widget>
  43 + </item>
  44 + </layout>
23 </item> 45 </item>
24 </layout> 46 </layout>
25 </widget> 47 </widget>