PICloud connect/disconnect
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "picloudtcp.h"
|
||||
|
||||
|
||||
DispatcherClient::DispatcherClient(PIEthernet * eth_) : eth(eth_), authorised(false) {
|
||||
DispatcherClient::DispatcherClient(PIEthernet * eth_, int id) : eth(eth_), authorised(false), client_id(id) {
|
||||
CONNECTU(&disconnect_tm, tickEvent, eth, close);
|
||||
CONNECTU(eth, threadedReadEvent, this, readed);
|
||||
CONNECTU(eth, disconnected, this, disconnected);
|
||||
@@ -12,7 +12,7 @@ DispatcherClient::DispatcherClient(PIEthernet * eth_) : eth(eth_), authorised(fa
|
||||
|
||||
void DispatcherClient::start() {
|
||||
eth->startThreadedRead();
|
||||
disconnect_tm.start(10000);
|
||||
//disconnect_tm.start(10000);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,16 @@ void DispatcherClient::close() {
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::sendConnected() {
|
||||
tcp.sendConnected(eth, client_id);
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::sendData(const PIByteArray & data) {
|
||||
tcp.sendData(eth, data);
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::disconnected(bool withError) {
|
||||
piCoutObj << "client disconnected" << eth->sendAddress();
|
||||
disconnectEvent(this);
|
||||
@@ -37,7 +47,7 @@ void DispatcherClient::disconnected(bool withError) {
|
||||
|
||||
|
||||
void DispatcherClient::readed(uchar *data, int size) {
|
||||
piCout << size;
|
||||
// piCout << size;
|
||||
PIByteArray ba(data, size);
|
||||
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
|
||||
if (hdr.first == PICloud::TCP::Invalid) {
|
||||
@@ -61,6 +71,7 @@ void DispatcherClient::readed(uchar *data, int size) {
|
||||
} else {
|
||||
switch (hdr.first) {
|
||||
case PICloud::TCP::Connect: {
|
||||
tcp.setRole(hdr.second);
|
||||
PIString sn = tcp.parseConnect(ba);
|
||||
if (hdr.second == PICloud::TCP::Server) registerServer(sn, this);
|
||||
if (hdr.second == PICloud::TCP::Client) registerClient(sn, this);
|
||||
|
||||
Reference in New Issue
Block a user