picloud add server logics

This commit is contained in:
2021-04-06 17:49:07 +03:00
parent be0db84147
commit fcf9f0f80e
9 changed files with 178 additions and 26 deletions

View File

@@ -24,6 +24,7 @@
PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode) : PIIODevice(path, mode) {
tcp.setRole(PICloud::TCP::Client);
setName("cloud_client");
is_connected = false;
}
@@ -67,6 +68,7 @@ bool PICloudClient::openDevice() {
bool PICloudClient::closeDevice() {
is_connected = false;
eth.stop();
eth.close();
return true;
@@ -95,11 +97,25 @@ void PICloudClient::readed(uchar *data, int size) {
mutex_buff.lock();
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
if (hdr.second == tcp.role()) {
piCoutObj << "readed" << ba.toHex();
buff.append(data, size);
cond_buff.notifyOne();
switch (hdr.first) {
case PICloud::TCP::Connect:
if (tcp.parseConnect(ba) == 0) is_connected = true;
break;
case PICloud::TCP::Disconnect:
is_connected = false;
eth.stop();
eth.close();
break;
case PICloud::TCP::Data:
buff.append(data, size);
cond_buff.notifyOne();
break;
default:
break;
}
//piCoutObj << "readed" << ba.toHex();
}
mutex_buff.unlock();
while (buff.size() > threadedReadBufferSize()) piMSleep(100);
while (buff.size_s() > threadedReadBufferSize()) piMSleep(100);
}