PICloud with streampacker
This commit is contained in:
@@ -21,10 +21,17 @@
|
||||
|
||||
|
||||
PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode) : PIIODevice(path, mode), PICloudBase() {
|
||||
PIString name = "PCS_" + PIString::fromNumber(randomi()%1000);
|
||||
PIString server_name = "PCS_" + PIString::fromNumber(randomi()%1000);
|
||||
tcp.setRole(PICloud::TCP::Server);
|
||||
tcp.setServerName(name);
|
||||
setName("cloud_server__" + name);
|
||||
tcp.setServerName(server_name);
|
||||
setName("cloud_server__" + server_name);
|
||||
CONNECTU(&streampacker, packetReceiveEvent, this, _readed);
|
||||
CONNECTL(ð, connected, [this](){tcp.sendStart();});
|
||||
CONNECTL(ð, disconnected, [this](bool){
|
||||
piCoutObj << "disconnected";
|
||||
opened_ = false;
|
||||
piMSleep(100);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -49,15 +56,7 @@ bool PICloudServer::openDevice() {
|
||||
piCout << "PICloudServer open device" << path();
|
||||
bool op = eth.connect(path(), false);
|
||||
if (op) {
|
||||
CONNECTU(ð, threadedReadEvent, this, readed);
|
||||
CONNECTL(ð, connected, [this](){tcp.sendStart(ð);});
|
||||
CONNECTL(ð, disconnected, [this](bool){
|
||||
opened_ = false;
|
||||
eth.close();
|
||||
piCoutObj << "disconnected" << !isOpened() << isClosed();
|
||||
});
|
||||
eth.startThreadedRead();
|
||||
tcp.sendStart(ð);
|
||||
return true;
|
||||
}
|
||||
eth.close();
|
||||
@@ -87,12 +86,12 @@ int PICloudServer::writeDevice(const void * data, int max_size) {
|
||||
|
||||
|
||||
void PICloudServer::clientDisconnect(uint client_id) {
|
||||
tcp.sendDisconnected(ð, client_id);
|
||||
tcp.sendDisconnected(client_id);
|
||||
}
|
||||
|
||||
|
||||
int PICloudServer::sendData(const PIByteArray & data, uint client_id) {
|
||||
return tcp.sendData(ð, data, client_id);
|
||||
return tcp.sendData(data, client_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -138,8 +137,7 @@ void PICloudServer::Client::pushBuffer(const PIByteArray & ba) {
|
||||
}
|
||||
|
||||
|
||||
void PICloudServer::readed(uchar *data, int size) {
|
||||
PIByteArray ba(data, size);
|
||||
void PICloudServer::_readed(PIByteArray & ba) {
|
||||
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
|
||||
if (hdr.second == tcp.role()) {
|
||||
switch (hdr.first) {
|
||||
@@ -147,7 +145,7 @@ void PICloudServer::readed(uchar *data, int size) {
|
||||
uint id = tcp.parseConnect(ba);
|
||||
Client * oc = index_clients.value(id, nullptr);
|
||||
if (oc) {
|
||||
tcp.sendDisconnected(ð, id);
|
||||
tcp.sendDisconnected(id);
|
||||
} else {
|
||||
Client * c = new Client(this, id);
|
||||
clients << c;
|
||||
|
||||
Reference in New Issue
Block a user