PICloud with streampacker

This commit is contained in:
2021-04-07 14:38:32 +03:00
parent fcf9f0f80e
commit 1fd9851068
13 changed files with 90 additions and 67 deletions

View File

@@ -2,9 +2,9 @@
#include "picloudtcp.h"
DispatcherClient::DispatcherClient(PIEthernet * eth_, int id) : eth(eth_), authorised(false), client_id(id) {
DispatcherClient::DispatcherClient(PIEthernet * eth_, int id) : authorised(false), eth(eth_), streampacker(eth_), tcp(&streampacker), client_id(id) {
CONNECTU(&disconnect_tm, tickEvent, eth, close);
CONNECTU(eth, threadedReadEvent, this, readed);
CONNECTU(&streampacker, packetReceiveEvent, this, readed);
CONNECTU(eth, disconnected, this, disconnected);
piCoutObj << "client connected" << eth->sendAddress();
}
@@ -31,18 +31,19 @@ void DispatcherClient::close() {
void DispatcherClient::sendConnected() {
tcp.sendConnected(eth, client_id);
piCoutObj << "sendConnected";
tcp.sendConnected(1);
}
void DispatcherClient::sendData(const PIByteArray & data) {
if (tcp.role() == PICloud::TCP::Client) tcp.sendData(eth, data);
if (tcp.role() == PICloud::TCP::Client) tcp.sendData(data);
else piCoutObj << "error sendData, invalid role";
}
void DispatcherClient::sendDataToClient(const PIByteArray & data, uint client_id) {
if (tcp.role() == PICloud::TCP::Server) tcp.sendData(eth, data, client_id);
if (tcp.role() == PICloud::TCP::Server) tcp.sendData(data, client_id);
else piCoutObj << "error sendDataToClient, invalid role";
}
@@ -53,11 +54,10 @@ void DispatcherClient::disconnected(bool withError) {
}
void DispatcherClient::readed(uchar *data, int size) {
void DispatcherClient::readed(PIByteArray & ba) {
// piCout << size;
PIByteArray ba(data, size);
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
if (hdr.first == PICloud::TCP::Invalid) {
if (hdr.first == PICloud::TCP::InvalidType) {
disconnected(true);
return;
}