-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectionImplRandomstub.cpp
109 lines (102 loc) · 2.89 KB
/
connectionImplRandomstub.cpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "connectionImplRandomStub.h"
//connectionImplRandomStub::connectionImplRandomStub()
//{
// timer_.setInterval(500);
// timer_.setSingleShot(true);
// InputBfr_.reserve(117);
// char * chPtr;
// for(float i=0; i<16; ++i)
// {
// chPtr = (char*)&i;
// for(int cnt=0; cnt<4; ++cnt)
// {
// InputBfr_.push_back(*chPtr);
// ++chPtr;
// }
// }
//}
connectionImplRandomStub::connectionImplRandomStub(const std::string &ip, unsigned short port, const ConnectionCallback *c)
: ConnectionImpl(ip, port, c)
{
timer_.setInterval(500);
timer_.setSingleShot(true);
InputBfr_.reserve(117);
char * chPtr;
for(float i=0; i<16; ++i)
{
chPtr = (char*)&i;
for(int cnt=0; cnt<4; ++cnt)
{
InputBfr_.push_back(*chPtr);
// qDebug() << *chPtr;
++chPtr;
}
}
qDebug() <<" connectionImplRandomStub::connectionImplRandomStub InputBfr_ = "<< InputBfr_.toHex();
}
connectionImplRandomStub::RetType connectionImplRandomStub::getAnsver(int length)
{
qint64 lenCopied = 0;
int size = 0;
BufferType * bfr = nullptr;
qDebug() << "connectionImplRandomStub::getAnsver";
std::auto_ptr< BufferType > res(bfr);
ConnectionImpl::bfr_.clear();
if (!isConnected)
connect_();
if (isConnected)
{
size = InputBfr_.size();
qDebug() << "connectionImplRandomStub::getAnsver trying to seize mutex";
QMutexLocker ml(&mtxInputBuffer_);
bfr = new BufferType;
res.reset(bfr);
res->push_back('\x05');res->push_back('\x05');//dummy bytes
res->push_back('>');
res->push_back('0'); res->push_back('1');
res->push_back('\x20'); res->push_back('\x08');res->push_back('\x00'); res->push_back('\x00');
res->push_back('\x68');
// res->append(InputBfr_);
qDebug() <<" connectionImplRandomStub::getAnsver InputBfr_ = "<< res->toHex() << " size = " << size << " length = " << length;
for(int i = 0; (i<length)&&(i<size);++i)
{
res->push_back(InputBfr_.at(i));
//qDebug()<<InputBfr_.at(i)<<' ';
++lenCopied;
}
// InputBfr_.remove(0, lenCopied);
// clb_->ansverReceived(length);
}
else
{
}
qDebug() <<" connectionImplRandomStub::getAnsver return";
return res;
}
void connectionImplRandomStub::slotReadyRead()
{
clb_->ansverReceived(117);
}
int connectionImplRandomStub::sendCommand(const QByteArray & data)
{
quint64 res;
if (!isConnected)
{
res = -1;
connect_();
}
else
{
res = data.size();
timer_.singleShot(500,this, SLOT(slotReadyRead()));
}
return res;
}
int connectionImplRandomStub::connect_()
{
isConnected = true;
qDebug() << "connectionImplRandomStub::connect_";
for(char i =0; i<16;++i)
InputBfr_.push_back(i);
return 0;
}