picloud next iteration

This commit is contained in:
2021-04-05 17:42:02 +03:00
parent 8eff5d24c9
commit f0d4801d3c
13 changed files with 237 additions and 90 deletions

View File

@@ -4,10 +4,14 @@
DispatcherClient::DispatcherClient(PIEthernet * eth_) : eth(eth_), authorised(false) {
CONNECTU(&disconnect_tm, tickEvent, eth, close);
eth->startThreadedRead();
CONNECTU(eth, threadedReadEvent, this, readed);
CONNECTU(eth, disconnected, this, disconnected);
piCoutObj << "client connected" << eth->sendAddress();
}
void DispatcherClient::start() {
eth->startThreadedRead();
disconnect_tm.start(10000);
}
@@ -33,18 +37,40 @@ void DispatcherClient::disconnected(bool withError) {
void DispatcherClient::readed(uchar *data, int size) {
piCout << size;
PIByteArray ba(data, size);
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
if (hdr.first == PICloud::TCP::Invalid) {
disconnected(true);
return;
}
if (authorised) {
dataReaded(ba);
} else {
if (ba.size() < 4) return;
PICloud::Header hdr;
ba >> hdr;
if ((PICloud::HeaderType)hdr.type == PICloud::Server) {
registerServer(hdr.sname, this);
switch (hdr.first) {
case PICloud::TCP::Connect:
return;
case PICloud::TCP::Disconnect:
disconnected(false);
return;
case PICloud::TCP::Data:
dataReaded(tcp.parseData(ba));
return;
default:
disconnected(true);
return;
}
if ((PICloud::HeaderType)hdr.type == PICloud::Client) {
registerClient(hdr.sname, this);
} else {
switch (hdr.first) {
case PICloud::TCP::Connect: {
PIString sn = tcp.parseConnect(ba);
if (hdr.second == PICloud::TCP::Server) registerServer(sn, this);
if (hdr.second == PICloud::TCP::Client) registerClient(sn, this);
return;}
case PICloud::TCP::Disconnect:
disconnected(false);
return;
default:
disconnected(true);
return;
}
}
}