-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.h
83 lines (73 loc) · 2.09 KB
/
mainwindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSerialPort>
#include <QStandardItemModel>
#include <QVector>
#include <QComboBox>
#include <QPushButton>
#include <QTcpSocket>
#include <QHostAddress>
#include <QMap>
#include "delegate.hpp"
#include "tmodel.hpp"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
signals: void click_minus(int);
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
void setModel(TModel& m);
void setDelegate(int index,DataTypeDelegate&x);
void setDelegate(int index,FunctionCodeDelegate&x);
void setDelegate(int index,DeleteDelegate&x);
void setDelegate(int index,LengthDelegate&x);
Ui::MainWindow *ui;
public slots:
void exportData(int);
void setEndianness(bool);
private slots:
// open the selected/input port
void openPort();
// send modbus frame
void sendData();
// void _click_ModbusButton_Test();
// add new row
void _click_PlusButton();
// remove the specified row
void _click_MinusButton(int);
// export data from the table
void _click_ExportButton();
// select the endianness
void _click_EndianButton();
// process the data send back from slave
void _receiveData();
// response to the mode changing
void _changeMode(QString);
// response to the host error
void _hostError();
private:
QSerialPort *serial;
TModel* model;
QTcpSocket * socket;
QByteArray receiveBuf;
int baudRate;
int mode=0;
int tcpCount=0;
int transaction = 0x0000; // TCP transaction identifier
int receive_index = 0;
bool isValidIndex(int x,int y);
void initSetup();
void initTabelview();
void initConnection();
bool constructFrame(int);
bool constructFrame(int,int);
QMap<int,int> row_mp; // transaction -> row_index
bool slave_endianness = 0; // 0 represent little-endian, while 1 represent big-endian
bool master_endianness = 0; // 0 represent little-endian, while 1 represent big-endian
};
#endif // MAINWINDOW_H