picloud data send and receive, not tested
This commit is contained in:
@@ -63,7 +63,7 @@ void PICloudClient::setKeepConnection(bool on) {
|
||||
|
||||
bool PICloudClient::openDevice() {
|
||||
PIString p = path();
|
||||
piCout << "PICloudClient open device" << p;
|
||||
// piCout << "PICloudClient open device" << p;
|
||||
bool op = eth.connect(p, false);
|
||||
if (op) {
|
||||
mutex_buff.lock();
|
||||
@@ -97,7 +97,7 @@ bool PICloudClient::closeDevice() {
|
||||
|
||||
|
||||
int PICloudClient::readDevice(void * read_to, int max_size) {
|
||||
piCoutObj << "readDevice";
|
||||
// piCoutObj << "readDevice";
|
||||
if (!is_connected) return -1;
|
||||
mutex_buff.lock();
|
||||
cond_buff.wait(mutex_buff, [this](){return !buff.isEmpty();});
|
||||
@@ -110,7 +110,7 @@ int PICloudClient::readDevice(void * read_to, int max_size) {
|
||||
|
||||
|
||||
int PICloudClient::writeDevice(const void * data, int size) {
|
||||
piCoutObj << "writeDevice";
|
||||
// piCoutObj << "writeDevice";
|
||||
return tcp.sendData(PIByteArray(data, size));
|
||||
}
|
||||
|
||||
|
||||
@@ -71,14 +71,14 @@ bool PICloudServer::closeDevice() {
|
||||
|
||||
|
||||
int PICloudServer::readDevice(void * read_to, int max_size) {
|
||||
piCoutObj << "readDevice";
|
||||
//piCoutObj << "readDevice";
|
||||
piMSleep(eth.readTimeout());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int PICloudServer::writeDevice(const void * data, int max_size) {
|
||||
piCoutObj << "writeDevice";
|
||||
//piCoutObj << "writeDevice";
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -94,23 +94,37 @@ int PICloudServer::sendData(const PIByteArray & data, uint client_id) {
|
||||
|
||||
|
||||
PICloudServer::Client::Client(PICloudServer * srv, uint id) : server(srv), client_id(id) {
|
||||
is_connected = true;
|
||||
}
|
||||
|
||||
|
||||
PICloudServer::Client::~Client() {
|
||||
if (is_connected) {
|
||||
is_connected = false;
|
||||
cond_buff.notifyOne();
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
bool PICloudServer::Client::openDevice() {
|
||||
return true;
|
||||
return is_connected;
|
||||
}
|
||||
|
||||
|
||||
bool PICloudServer::Client::closeDevice() {
|
||||
server->clientDisconnect(client_id);
|
||||
if (is_connected) {
|
||||
is_connected = false;
|
||||
cond_buff.notifyOne();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int PICloudServer::Client::readDevice(void * read_to, int max_size) {
|
||||
//piCoutObj << "readDevice";
|
||||
if (!is_connected) return -1;
|
||||
mutex_buff.lock();
|
||||
cond_buff.wait(mutex_buff, [this](){return !buff.isEmpty();});
|
||||
int sz = piMini(max_size, buff.size());
|
||||
@@ -127,6 +141,7 @@ int PICloudServer::Client::writeDevice(const void * data, int size) {
|
||||
|
||||
|
||||
void PICloudServer::Client::pushBuffer(const PIByteArray & ba) {
|
||||
if (!is_connected) return;
|
||||
mutex_buff.lock();
|
||||
buff.append(ba);
|
||||
cond_buff.notifyOne();
|
||||
|
||||
@@ -47,7 +47,7 @@ void PICloud::TCP::setServerName(const PIString & server_name) {
|
||||
|
||||
|
||||
void PICloud::TCP::sendStart() {
|
||||
piCout << "sendStart";
|
||||
//piCout << "sendStart";
|
||||
header.type = PICloud::TCP::Connect;
|
||||
PIByteArray ba;
|
||||
ba << header << sname;
|
||||
|
||||
@@ -37,11 +37,11 @@ public:
|
||||
|
||||
void setServerName(const PIString & server_name);
|
||||
void setKeepConnection(bool on);
|
||||
bool isConnected() const {return is_connected;}
|
||||
|
||||
protected:
|
||||
bool openDevice();
|
||||
bool closeDevice();
|
||||
bool isConnected() const {return is_connected;}
|
||||
int readDevice(void * read_to, int max_size);
|
||||
int writeDevice(const void * data, int size);
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
friend class PICloudServer;
|
||||
public:
|
||||
Client(PICloudServer * srv = nullptr, uint id = 0);
|
||||
virtual ~Client();
|
||||
protected:
|
||||
bool openDevice();
|
||||
bool closeDevice();
|
||||
@@ -53,6 +54,7 @@ public:
|
||||
PIByteArray buff;
|
||||
PIMutex mutex_buff;
|
||||
PIConditionVariable cond_buff;
|
||||
std::atomic_bool is_connected;
|
||||
};
|
||||
|
||||
void setServerName(const PIString & server_name);
|
||||
|
||||
Reference in New Issue
Block a user