-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxddpComm.cpp
More file actions
75 lines (55 loc) · 1.51 KB
/
xddpComm.cpp
File metadata and controls
75 lines (55 loc) · 1.51 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
65
66
67
68
69
70
71
72
73
74
75
#include "xddpComm.h"
#include <sys/socket.h>
#include <sys/un.h>
#include<QFile>
#include <unistd.h>
#include "api/myhelper.h"
xddpComm::xddpComm(QObject *parent) : QObject(parent)
{
dataInit();
}
void xddpComm::sendErrFlg()
{
qDebug()<<"get error message!"<< fb;
}
void xddpComm::dataInit()
{
fb = open("/dev/rtp1",O_RDWR | O_NONBLOCK); //读写,非阻态方式打开;
if(fb<0)
{
sendErrFlg();
myHelper::sleep(1500);
dataInit();
return;
}
m_activeNotifier=new QSocketNotifier(fb,QSocketNotifier::Read,this); //创建QSocketNotifier的对象;
connect(m_activeNotifier,SIGNAL(activated(int)),this,SLOT(readSocketData(int)));
m_errorNotifier=new QSocketNotifier(fb,QSocketNotifier::Exception,this); //创建QSocketNotifier的对象;
connect(m_errorNotifier,SIGNAL(activated(int)),this,SLOT(errorSocket(int)));
}
void xddpComm::readSocketData(int)
{
char *read_buf;
int read_buf_size=2000;
read_buf=new char[read_buf_size];
memset(read_buf,0,read_buf_size);
read(fb, read_buf,20000);
qDebug()<<"get replay message!"<< read_buf;
emit sendXddpData(read_buf);
delete[] read_buf;
}
void xddpComm::errorSocket(int)
{
}
void xddpComm::writeToXddp(QByteArray data)
{
int size=data.size();
char *write_buf=data.data();
write(fb,write_buf,size);
}
void xddpComm::testInterface(QByteArray data)
{
int size=data.size();
char *write_buf=data.data();
write(fb,write_buf,size);
}