some fixes for picloud, but still not working correctly

This commit is contained in:
Бычков Андрей
2022-11-08 14:43:52 +03:00
parent 36ff427e0d
commit 897f03f3d0
10 changed files with 60 additions and 55 deletions

View File

@@ -3,7 +3,6 @@
DispatcherClient::DispatcherClient(PIEthernet * eth_, int id) : authorised(false), eth(eth_), streampacker(eth_), tcp(&streampacker), client_id(id) {
CONNECTU(&disconnect_tm, tickEvent, eth, close);
CONNECTU(&streampacker, packetReceiveEvent, this, readed);
CONNECTU(eth, disconnected, this, disconnected);
piCoutObj << "client connected" << client_id << eth->sendAddress();
@@ -12,7 +11,6 @@ DispatcherClient::DispatcherClient(PIEthernet * eth_, int id) : authorised(false
void DispatcherClient::start() {
eth->startThreadedRead();
//disconnect_tm.start(10000);
}
@@ -27,18 +25,18 @@ PIString DispatcherClient::address() {
void DispatcherClient::close() {
eth->softStopThreadedRead();
eth->interrupt();
eth->stopAndWait();
}
void DispatcherClient::sendConnected(uint client_id) {
//piCoutObj << "sendConnected";
piCoutObj << "sendConnected" << client_id;
tcp.sendConnected(client_id);
}
void DispatcherClient::sendDisconnected(uint client_id) {
piCoutObj << "sendDisconnected" << client_id;
tcp.sendDisconnected(client_id);
}
@@ -61,7 +59,7 @@ void DispatcherClient::authorise(bool ok) {
void DispatcherClient::disconnected(bool withError) {
//piCoutObj << "client disconnected" << eth->sendAddress();
piCoutObj << "client disconnected" << withError << eth->sendAddress();
disconnectEvent(this);
}
@@ -70,16 +68,18 @@ void DispatcherClient::readed(PIByteArray & ba) {
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
// piCoutObj << "readed" << hdr.first << hdr.second;
if (hdr.first == PICloud::TCP::InvalidType) {
disconnected(true);
piCoutObj << "invalid message";
disconnected(true);
return;
}
if (authorised) {
if (hdr.second == tcp.role()) {
switch (hdr.first) {
case PICloud::TCP::Connect:
piCoutObj << "PICloud::TCP::Connect";
return;
case PICloud::TCP::Disconnect:
piCoutObj << "PICloud::TCP::Disconnect";
disconnected(false);
return;
case PICloud::TCP::Data:
@@ -113,9 +113,11 @@ void DispatcherClient::readed(PIByteArray & ba) {
return;
}
case PICloud::TCP::Disconnect:
piCoutObj << "unauthorised PICloud::TCP::Disconnect";
disconnected(false);
return;
default:
piCoutObj << "authorised invalid message";
disconnected(true);
return;
}