This commit is contained in:
2020-08-27 19:40:11 +03:00
parent e1f2c90790
commit 234d4e73be
9 changed files with 101 additions and 20 deletions

View File

@@ -1,8 +1,8 @@
#include "dispatcherclient.h"
#include "picloudtcp.h"
DispatcherClient::DispatcherClient(PIEthernet * eth_) {
eth = eth_;
DispatcherClient::DispatcherClient(PIEthernet * eth_) : eth(eth_), authorised(false) {
CONNECTU(&disconnect_tm, tickEvent, eth, close);
eth->startThreadedRead();
CONNECTU(eth, threadedReadEvent, this, readed);
@@ -21,6 +21,10 @@ PIString DispatcherClient::address() {
return eth->path();
}
void DispatcherClient::close() {
eth->close();
}
void DispatcherClient::disconnected(bool withError) {
piCoutObj << "client disconnected" << eth->sendAddress();
@@ -30,7 +34,18 @@ void DispatcherClient::disconnected(bool withError) {
void DispatcherClient::readed(uchar *data, int size) {
PIByteArray ba(data, size);
piCoutObj << "readed" << ba.toHex();
eth->write(ba);
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);
}
if ((PICloud::HeaderType)hdr.type == PICloud::Client) {
registerClient(hdr.sname, this);
}
}
}