forked from guodong/cloudwarehub-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipchanneldisplay.cpp
More file actions
64 lines (57 loc) · 2.19 KB
/
cipchanneldisplay.cpp
File metadata and controls
64 lines (57 loc) · 2.19 KB
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
#include "cipchanneldisplay.h"
#include "cip_protocol.h"
#include "mainwindow.h"
extern MainWindow *mainwindow;
CipChannelDisplay::CipChannelDisplay(QString ip, quint16 port) : CipChannel(ip, port)
{
this->type = CIP_CHANNEL_DISPLAY;
this->ev = NULL;
connect(this->socket, SIGNAL(readyRead()), this, SLOT(onData()));
}
void CipChannelDisplay::onData()
{
qDebug("ondata display:%d",this->socket->bytesAvailable());
int res;
if (this->ev == NULL) { /* read head first, then frame data */
if (this->socket->bytesAvailable() >= sizeof(cip_event_window_frame_t)) {
this->ev = (cip_event_window_frame_t*)malloc(sizeof(cip_event_window_frame_t));
this->read((char*)this->ev, sizeof(cip_event_window_frame_t));
qDebug("%d", this->ev->length);
if (this->socket->bytesAvailable() >= this->ev->length) { /* if frame data is ready to read */
qDebug("still");
char buf[this->ev->length];
res = this->read(buf, this->ev->length);
qDebug("res:%d",res);
if(mainwindow->windows.contains(this->ev->wid))
mainwindow->windows[this->ev->wid]->decode((const unsigned char*)buf, this->ev->length);
if(this->ev) {
free(this->ev);
this->ev = NULL;
}
this->onData();
}
}
} else { /* header already read */
if (this->socket->bytesAvailable() >= this->ev->length) { /* if frame data is ready to read */
char buf[this->ev->length];
this->read(buf, this->ev->length);
if(mainwindow->windows.contains(this->ev->wid))
mainwindow->windows[this->ev->wid]->decode((const unsigned char*)buf, this->ev->length);
if(this->ev) {
free(this->ev);
this->ev = NULL;
}
this->onData();
}
}
}
void CipChannelDisplay::run()
{
this->connectServer();
cip_message_connect_t conn;
conn.version = 0;
conn.channel_type = this->type;
conn.session_length = 6;
this->write((char*)&conn, sizeof(conn));
this->write("hello", 6);
}