Merge branch 'master' into pico_sdk
This commit is contained in:
@@ -150,6 +150,67 @@ void PIBaseTransfer::received(PIByteArray data) {
|
||||
}
|
||||
mutex_header.unlock();
|
||||
break;
|
||||
case pt_Start:
|
||||
mutex_header.lock();
|
||||
if (is_pause && (is_sending || is_receiving)) {
|
||||
if (header.session_id == h.session_id) {
|
||||
is_pause = false;
|
||||
mutex_header.unlock();
|
||||
resumed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (is_sending && header.session_id != h.session_id) {
|
||||
sendBreak(h.session_id);
|
||||
mutex_header.unlock();
|
||||
return;
|
||||
}
|
||||
if (is_receiving) {
|
||||
if (header.session_id != h.session_id) {
|
||||
piCoutObj << "restart receive"_tr("PIBaseTransfer");
|
||||
mutex_header.unlock();
|
||||
finish_receive(false, true);
|
||||
} else {
|
||||
header.id = 0;
|
||||
sendReply(pt_ReplySuccess);
|
||||
mutex_header.unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
mutex_header.unlock();
|
||||
if (data.size() == sizeof(StartRequest)) {
|
||||
StartRequest sr;
|
||||
data >> sr;
|
||||
mutex_header.lock();
|
||||
mutex_session.lock();
|
||||
bytes_cur = 0;
|
||||
state_string = "start request";
|
||||
bytes_all = sr.size;
|
||||
header.session_id = h.session_id;
|
||||
header.id = 0;
|
||||
packets_count = 10;
|
||||
session.clear();
|
||||
replies.clear();
|
||||
session.resize(sr.packets);
|
||||
replies.resize(sr.packets + 1);
|
||||
replies.fill(pt_Unknown);
|
||||
pm_string.resize(replies.size(), '-');
|
||||
diag.reset();
|
||||
is_receiving = true;
|
||||
break_ = false;
|
||||
mutex_send.lock();
|
||||
send_queue = 0;
|
||||
mutex_send.unlock();
|
||||
beginReceive();
|
||||
receiveStarted();
|
||||
state_string = "receiving";
|
||||
replies[0] = pt_ReplySuccess;
|
||||
pm_string[0] = '#';
|
||||
mutex_session.unlock();
|
||||
sendReply(pt_ReplySuccess);
|
||||
mutex_header.unlock();
|
||||
}
|
||||
break;
|
||||
case pt_ReplySuccess:
|
||||
case pt_ReplyInvalid:
|
||||
mutex_header.lock();
|
||||
@@ -216,70 +277,8 @@ void PIBaseTransfer::received(PIByteArray data) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case pt_Start:
|
||||
mutex_header.lock();
|
||||
if (is_pause && (is_sending || is_receiving)) {
|
||||
if (header.session_id == h.session_id) {
|
||||
is_pause = false;
|
||||
mutex_header.unlock();
|
||||
resumed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (is_sending && header.session_id != h.session_id) {
|
||||
sendBreak(h.session_id);
|
||||
mutex_header.unlock();
|
||||
return;
|
||||
}
|
||||
if (is_receiving) {
|
||||
if (header.session_id != h.session_id) {
|
||||
piCoutObj << "restart receive"_tr("PIBaseTransfer");
|
||||
mutex_header.unlock();
|
||||
finish_receive(false, true);
|
||||
} else {
|
||||
header.id = 0;
|
||||
sendReply(pt_ReplySuccess);
|
||||
mutex_header.unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
mutex_header.unlock();
|
||||
if (data.size() == sizeof(StartRequest)) {
|
||||
StartRequest sr;
|
||||
data >> sr;
|
||||
mutex_session.lock();
|
||||
mutex_header.lock();
|
||||
bytes_cur = 0;
|
||||
state_string = "start request";
|
||||
bytes_all = sr.size;
|
||||
header.session_id = h.session_id;
|
||||
header.id = 0;
|
||||
packets_count = 10;
|
||||
session.clear();
|
||||
replies.clear();
|
||||
session.resize(sr.packets);
|
||||
replies.resize(sr.packets + 1);
|
||||
replies.fill(pt_Unknown);
|
||||
pm_string.resize(replies.size(), '-');
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.reset();
|
||||
#endif
|
||||
// piCoutObj << "receiveStarted()";
|
||||
is_receiving = true;
|
||||
break_ = false;
|
||||
mutex_send.lock();
|
||||
send_queue = 0;
|
||||
mutex_send.unlock();
|
||||
beginReceive();
|
||||
receiveStarted();
|
||||
state_string = "receiving";
|
||||
replies[0] = pt_ReplySuccess;
|
||||
pm_string[0] = '#';
|
||||
mutex_session.unlock();
|
||||
sendReply(pt_ReplySuccess);
|
||||
mutex_header.unlock();
|
||||
}
|
||||
break;
|
||||
case pt_Pause:
|
||||
mutex_header.lock();
|
||||
if (header.session_id == h.session_id) {
|
||||
@@ -449,8 +448,8 @@ int PIBaseTransfer::checkSession() {
|
||||
|
||||
|
||||
void PIBaseTransfer::buildSession(PIVector<Part> parts) {
|
||||
mutex_session.lock();
|
||||
mutex_header.lock();
|
||||
mutex_session.lock();
|
||||
state_string = "calculating parts ... ";
|
||||
session.clear();
|
||||
header.session_id = randomi();
|
||||
@@ -503,8 +502,8 @@ void PIBaseTransfer::buildSession(PIVector<Part> parts) {
|
||||
}
|
||||
}
|
||||
if (cur_size > min_size) session << lfi;
|
||||
mutex_header.unlock();
|
||||
mutex_session.unlock();
|
||||
mutex_header.unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "picrc.h"
|
||||
#include "pidiagnostics.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
//! \~\ingroup IO-Utils
|
||||
//! \~\brief
|
||||
@@ -303,7 +305,7 @@ protected:
|
||||
bool send_process();
|
||||
|
||||
uint packet_header_size, part_header_size;
|
||||
bool break_, is_sending, is_receiving, is_pause;
|
||||
std::atomic<bool> break_{true}, is_sending{false}, is_receiving{false}, is_pause{false};
|
||||
PIString state_string;
|
||||
llong bytes_all, bytes_cur;
|
||||
|
||||
|
||||
@@ -574,6 +574,8 @@ bool PIConnection::removeFilter(const PIString & name_) {
|
||||
|
||||
|
||||
void PIConnection::removeAllFilters() {
|
||||
PIVector<Extractor *> to_delete;
|
||||
PIVector<PIDiagnostics *> diags_to_delete;
|
||||
__device_pool__->lock();
|
||||
for (auto i = extractors.begin(); i != extractors.end(); i++) {
|
||||
if (!i.value()) continue;
|
||||
@@ -583,14 +585,18 @@ void PIConnection::removeAllFilters() {
|
||||
it.value().removeAll(i.value()->extractor);
|
||||
}
|
||||
if (diags_.value(i.value()->extractor)) {
|
||||
delete diags_.value(i.value()->extractor);
|
||||
diags_to_delete << diags_.value(i.value()->extractor);
|
||||
diags_.remove(i.value()->extractor);
|
||||
}
|
||||
diags_.remove(i.value()->extractor);
|
||||
delete i.value();
|
||||
to_delete << i.value();
|
||||
}
|
||||
extractors.clear();
|
||||
bounded_extractors.clear();
|
||||
__device_pool__->unlock();
|
||||
for (auto e: to_delete)
|
||||
delete e;
|
||||
for (auto d: diags_to_delete)
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
@@ -996,6 +1002,7 @@ PIIODevice * PIConnection::DevicePool::addDevice(PIConnection * parent, const PI
|
||||
if (pmode == mode || pmode == PIIODevice::ReadWrite) return dd->dev;
|
||||
if ((mode & PIIODevice::ReadOnly) > 0) {
|
||||
if (dd->rthread) {
|
||||
dd->rthread->stopAndWait();
|
||||
delete dd->rthread;
|
||||
dd->rthread = nullptr;
|
||||
dd->started = false;
|
||||
@@ -1135,10 +1142,13 @@ PIConnection::DevicePool::DeviceData::~DeviceData() {
|
||||
void PIConnection::DevicePool::run() {
|
||||
PIVector<PIConnection *> conns(PIConnection::allConnections());
|
||||
for (PIConnection * c: conns) {
|
||||
if (!c) continue;
|
||||
__device_pool__->lock();
|
||||
for (auto d = c->diags_.begin(); d != c->diags_.end(); d++) {
|
||||
if (!d.value()) continue;
|
||||
d.value()->tick(1);
|
||||
}
|
||||
__device_pool__->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1229,9 +1239,14 @@ void PIConnection::Sender::tick(int) {
|
||||
if (data.isEmpty()) return;
|
||||
// piCoutObj << "write"<<data.size()<<"bytes to"<<devices.size()<<"devices";
|
||||
for (PIIODevice * d: devices) {
|
||||
int ret = d->write(data);
|
||||
PIDiagnostics * diag = parent->diags_.value(d, nullptr);
|
||||
if (diag && ret > 0) diag->sended(ret);
|
||||
int ret = d->write(data);
|
||||
if (ret > 0) {
|
||||
PIDiagnostics * diag = nullptr;
|
||||
__device_pool__->lock();
|
||||
diag = parent->diags_.value(d, nullptr);
|
||||
__device_pool__->unlock();
|
||||
if (diag) diag->sended(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user