version 4.0.0_alpha
in almost all methods removed timeouts in milliseconds, replaced to PISystemTime PITimer rewrite, remove internal impl, now only thread implementation, API similar to PIThread PITimer API no longer pass void* PIPeer, PIConnection improved stability on reinit and exit PISystemTime new methods pisd now exit without hanging
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "piconfig.h"
|
||||
#include "piiostream.h"
|
||||
#include "piliterals_time.h"
|
||||
#include "pitime.h"
|
||||
|
||||
/** \class PIConnection
|
||||
* \brief Complex Input/Output point
|
||||
@@ -160,7 +162,9 @@ bool PIConnection::configure(PIConfig & conf, const PIString & name_) {
|
||||
PIConfig::Entry de = ce.getValue("device." + n);
|
||||
dev->setThreadedReadBufferSize(de.getValue("bufferSize", dev->threadedReadBufferSize()).toInt());
|
||||
PIDiagnostics * diag = diags_.value(dev, nullptr);
|
||||
if (diag) diag->setDisconnectTimeout(de.getValue("disconnectTimeout", diag->disconnectTimeout()).toFloat());
|
||||
if (diag)
|
||||
diag->setDisconnectTimeout(
|
||||
PISystemTime::fromSeconds(de.getValue("disconnectTimeout", diag->disconnectTimeout().toSeconds()).toFloat()));
|
||||
}
|
||||
int added(0), padded(-1), tries(0);
|
||||
bool pdebug = debug();
|
||||
@@ -223,9 +227,11 @@ bool PIConnection::configure(PIConfig & conf, const PIString & name_) {
|
||||
}
|
||||
}
|
||||
PIDiagnostics * diag = diags_.value(pe, nullptr);
|
||||
if (diag) diag->setDisconnectTimeout(e->getValue("disconnectTimeout", diag->disconnectTimeout()).toFloat());
|
||||
if (diag)
|
||||
diag->setDisconnectTimeout(
|
||||
PISystemTime::fromSeconds(e->getValue("disconnectTimeout", diag->disconnectTimeout().toSeconds()).toFloat()));
|
||||
pe->setPayloadSize(e->getValue("payloadSize", pe->payloadSize()).toInt());
|
||||
pe->setTimeout(e->getValue("timeout", pe->timeout()).toDouble());
|
||||
pe->setTimeout(PISystemTime::fromMilliseconds(e->getValue("timeout", pe->timeout().toMilliseconds()).toDouble()));
|
||||
pe->setHeader(PIByteArray::fromUserInput(e->getValue("header", "").toString()));
|
||||
pe->setFooter(PIByteArray::fromUserInput(e->getValue("footer", "").toString()));
|
||||
}
|
||||
@@ -271,7 +277,7 @@ PIString PIConnection::makeConfig() const {
|
||||
ts << "device." << dname << " = " << d->constructFullPath() << " #s\n";
|
||||
ts << "device." << dname << ".bufferSize = " << d->threadedReadBufferSize() << " #n\n";
|
||||
PIDiagnostics * diag = diags_.value(const_cast<PIIODevice *>(d), nullptr);
|
||||
if (diag) ts << "device." << dname << ".disconnectTimeout = " << diag->disconnectTimeout() << " #f\n";
|
||||
if (diag) ts << "device." << dname << ".disconnectTimeout = " << diag->disconnectTimeout().toSeconds() << " #f\n";
|
||||
}
|
||||
}
|
||||
auto ite = extractors.makeIterator();
|
||||
@@ -285,7 +291,7 @@ PIString PIConnection::makeConfig() const {
|
||||
ts << prefix << ".device." << i << " = " << dname << " #s\n";
|
||||
}
|
||||
PIDiagnostics * diag = diags_.value(ite.value()->extractor, nullptr);
|
||||
if (diag) ts << prefix << ".disconnectTimeout = " << diag->disconnectTimeout() << " #f\n";
|
||||
if (diag) ts << prefix << ".disconnectTimeout = " << diag->disconnectTimeout().toSeconds() << " #f\n";
|
||||
ts << prefix << ".splitMode = ";
|
||||
switch (ite.value()->extractor->splitMode()) {
|
||||
case PIPacketExtractor::None: ts << "none"; break;
|
||||
@@ -297,7 +303,7 @@ PIString PIConnection::makeConfig() const {
|
||||
}
|
||||
ts << " #s\n";
|
||||
ts << prefix << ".payloadSize = " << ite.value()->extractor->payloadSize() << " #n\n";
|
||||
ts << prefix << ".timeout = " << ite.value()->extractor->timeout() << " #f\n";
|
||||
ts << prefix << ".timeout = " << ite.value()->extractor->timeout().toMilliseconds() << " #f\n";
|
||||
ts << prefix << ".header = " << ite.value()->extractor->header().toString() << " #s\n";
|
||||
ts << prefix << ".footer = " << ite.value()->extractor->footer().toString() << " #s\n";
|
||||
}
|
||||
@@ -324,8 +330,8 @@ PIString PIConnection::makeConfig() const {
|
||||
if (dname.isEmpty()) dname = devPath(its.value()->devices[i]);
|
||||
ts << prefix << ".device." << i << " = " << dname << " #s\n";
|
||||
}
|
||||
double int_ = its.value()->int_;
|
||||
if (int_ > 0.) ts << prefix << ".frequency = " << (1000. / int_) << " #f\n";
|
||||
auto int_ = its.value()->int_;
|
||||
if (!int_.isNull()) ts << prefix << ".frequency = " << (1. / int_.toSeconds()) << " #f\n";
|
||||
if (!its.value()->sdata.isEmpty()) ts << prefix << ".fixedData = " << its.value()->sdata.toString() << " #s\n";
|
||||
}
|
||||
ts << "[]\n";
|
||||
@@ -342,7 +348,7 @@ PIIODevice * PIConnection::addDevice(const PIString & full_path, PIIODevice::Dev
|
||||
__device_pool__->lock();
|
||||
if (!diags_.value(dev, nullptr)) {
|
||||
PIDiagnostics * d = new PIDiagnostics(false);
|
||||
d->setInterval(100.);
|
||||
d->setInterval(10_Hz);
|
||||
diags_[dev] = d;
|
||||
CONNECT2(void, PIDiagnostics::Quality, PIDiagnostics::Quality, d, qualityChanged, this, diagQualityChanged);
|
||||
__device_pool__->init();
|
||||
@@ -476,7 +482,7 @@ PIPacketExtractor * PIConnection::addFilter(const PIString & name_, const PIStri
|
||||
__device_pool__->lock();
|
||||
if (!diags_.value(e->extractor, nullptr)) {
|
||||
PIDiagnostics * d = new PIDiagnostics(false);
|
||||
d->setInterval(100.);
|
||||
d->setInterval(10_Hz);
|
||||
diags_[e->extractor] = d;
|
||||
CONNECT2(void, PIDiagnostics::Quality, PIDiagnostics::Quality, d, qualityChanged, this, diagQualityChanged);
|
||||
}
|
||||
@@ -514,7 +520,7 @@ PIPacketExtractor * PIConnection::addFilter(PIPacketExtractor * filter, const PI
|
||||
__device_pool__->lock();
|
||||
if (diags_.value(e->extractor, 0) == 0) {
|
||||
PIDiagnostics * d = new PIDiagnostics(false);
|
||||
d->setInterval(100.);
|
||||
d->setInterval(10_Hz);
|
||||
diags_[e->extractor] = d;
|
||||
CONNECT2(void, PIDiagnostics::Quality, PIDiagnostics::Quality, d, qualityChanged, this, diagQualityChanged);
|
||||
}
|
||||
@@ -728,7 +734,7 @@ void PIConnection::addSender(const PIString & name_, const PIString & full_path_
|
||||
if (!s) {
|
||||
s = new Sender(this);
|
||||
s->setName(fname_);
|
||||
s->int_ = 1000. / frequency;
|
||||
s->int_ = PISystemTime::fromSeconds(1. / frequency);
|
||||
senders[fname_] = s;
|
||||
}
|
||||
PIIODevice * dev = devByString(full_path_name);
|
||||
@@ -797,9 +803,9 @@ PIByteArray PIConnection::senderFixedData(const PIString & name) const {
|
||||
float PIConnection::senderFrequency(const PIString & name) const {
|
||||
Sender * s = senders.value(name, nullptr);
|
||||
if (!s) return -1.f;
|
||||
double i = s->interval();
|
||||
if (i == 0.) return 0.f;
|
||||
return 1000. / s->interval();
|
||||
auto i = s->interval();
|
||||
if (i.isNull()) return 0.f;
|
||||
return 1. / s->interval().toSeconds();
|
||||
}
|
||||
|
||||
|
||||
@@ -865,14 +871,14 @@ void PIConnection::stopAllThreadedReads() {
|
||||
void PIConnection::stopSender(const PIString & name) {
|
||||
Sender * s = senders.value(name, nullptr);
|
||||
if (!s) return;
|
||||
if (s->isRunning()) s->stop();
|
||||
if (s->isRunning()) s->stopAndWait();
|
||||
}
|
||||
|
||||
|
||||
void PIConnection::stopAllSenders() {
|
||||
for (auto s = senders.begin(); s != senders.end(); s++) {
|
||||
if (!s.value()) continue;
|
||||
if (s.value()->isRunning()) s.value()->stop();
|
||||
if (s.value()->isRunning()) s.value()->stopAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,7 +955,7 @@ bool PIConnection::isFakeMode() {
|
||||
}
|
||||
|
||||
|
||||
PIConnection::DevicePool::DevicePool(): PIThread(false, 10) {
|
||||
PIConnection::DevicePool::DevicePool(): PIThread(false, 100_Hz) {
|
||||
setName("PIConnection::DevicePool");
|
||||
needLockRun(true);
|
||||
fake = false;
|
||||
@@ -960,7 +966,7 @@ PIConnection::DevicePool::~DevicePool() {}
|
||||
|
||||
|
||||
void PIConnection::DevicePool::init() {
|
||||
if (!isRunning()) start(100);
|
||||
if (!isRunning()) start(10_Hz);
|
||||
}
|
||||
|
||||
|
||||
@@ -1111,7 +1117,7 @@ PIConnection::DevicePool::DeviceData::~DeviceData() {
|
||||
if (rthread) {
|
||||
rthread->stop();
|
||||
if (dev) dev->interrupt();
|
||||
if (!rthread->waitForFinish(1000)) rthread->terminate();
|
||||
if (!rthread->waitForFinish(1_s)) rthread->terminate();
|
||||
delete rthread;
|
||||
rthread = nullptr;
|
||||
}
|
||||
@@ -1128,7 +1134,7 @@ void PIConnection::DevicePool::run() {
|
||||
for (PIConnection * c: conns) {
|
||||
for (auto d = c->diags_.begin(); d != c->diags_.end(); d++) {
|
||||
if (!d.value()) continue;
|
||||
d.value()->tick(0, 1);
|
||||
d.value()->tick(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1143,9 +1149,9 @@ void __DevicePool_threadReadDP(void * ddp) {
|
||||
}
|
||||
if (dev->isClosed()) {
|
||||
if (!dev->open()) {
|
||||
auto timeout = dev->reopenTimeout();
|
||||
PITimeMeasurer tm;
|
||||
int timeout = dev->reopenTimeout();
|
||||
while (tm.elapsed_m() < timeout) {
|
||||
while (tm.elapsed() < timeout) {
|
||||
if (dd->rthread->isStopping()) return;
|
||||
piMSleep(50);
|
||||
}
|
||||
@@ -1204,13 +1210,13 @@ PIConnection::Extractor::~Extractor() {
|
||||
}
|
||||
|
||||
|
||||
PIConnection::Sender::Sender(PIConnection * parent_): parent(parent_), int_(0.f) {
|
||||
PIConnection::Sender::Sender(PIConnection * parent_): parent(parent_) {
|
||||
setName("__S__.PIConnection.Sender");
|
||||
needLockRun(true);
|
||||
}
|
||||
|
||||
|
||||
void PIConnection::Sender::tick(void *, int) {
|
||||
void PIConnection::Sender::tick(int) {
|
||||
if (!parent) return;
|
||||
PIByteArray data;
|
||||
if (!sdata.isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user