git-svn-id: svn://db.shs.com.ru/pip@673 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2018-12-18 19:13:09 +00:00
parent 5df8ae18a3
commit 8d37dc453e
9 changed files with 157 additions and 29 deletions

View File

@@ -20,6 +20,7 @@
#include "piiodevice.h"
#include "piconfig.h"
#include "piconnection.h"
#include "pipropertystorage.h"
/*! \class PIIODevice
@@ -199,6 +200,18 @@ void PIIODevice::write_func() {
}
PIIODevice * PIIODevice::newDeviceByPrefix(const PIString & prefix) {
if (prefix.isEmpty()) return 0;
PIVector<const PIObject * > rd(PICollection::groupElements("__PIIODevices__"));
piForeachC (PIObject * d, rd) {
if (prefix == ((const PIIODevice * )d)->fullPathPrefix()) {
return ((const PIIODevice * )d)->copy();
}
}
return 0;
}
void PIIODevice::terminate() {
timer.stop();
thread_started_ = false;
@@ -321,6 +334,23 @@ void PIIODevice::configureFromFullPath(const PIString & full_path) {
}
PIVariantTypes::IODevice PIIODevice::constructVariant() const {
PIVariantTypes::IODevice ret;
ret.prefix = fullPathPrefix();
ret.mode = mode();
ret.options = options();
ret.set(constructVariantDevice());
return ret;
}
void PIIODevice::configureFromVariant(const PIVariantTypes::IODevice & d) {
setMode((DeviceMode)d.mode);
setOptions((DeviceOptions)d.options);
configureFromVariantDevice(d.get());
}
void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * mode, DeviceOptions * opts) {
int dm = 0;
DeviceOptions op = 0;
@@ -363,17 +393,19 @@ PIString PIIODevice::fullPathOptions() const {
PIIODevice * PIIODevice::createFromFullPath(const PIString & full_path) {
PIString prefix = full_path.left(full_path.find(":"));
if (prefix.isEmpty()) return 0;
PIVector<const PIObject * > rd(PICollection::groupElements("__PIIODevices__"));
piForeachC (PIObject * d, rd) {
if (prefix == ((const PIIODevice * )d)->fullPathPrefix()) {
PIIODevice * nd = ((const PIIODevice * )d)->copy();
if (nd) nd->configureFromFullPath(full_path.mid(prefix.length() + 3));
cacheFullPath(full_path, nd);
return nd;
}
}
return 0;
PIIODevice * nd = newDeviceByPrefix(prefix);
if (!nd) return 0;
nd->configureFromFullPath(full_path.mid(prefix.length() + 3));
cacheFullPath(full_path, nd);
return nd;
}
PIIODevice * PIIODevice::createFromVariant(const PIVariantTypes::IODevice & d) {
PIIODevice * nd = newDeviceByPrefix(d.prefix);
if (!nd) return 0;
nd->configureFromVariant(d);
return nd;
}
@@ -405,3 +437,15 @@ bool PIIODevice::threadedRead(uchar *readed, int size) {
if (ret_func_ != 0) return ret_func_(ret_data_, readed, size);
return true;
}
PIPropertyStorage PIIODevice::constructVariantDevice() const {
PIPropertyStorage ret;
ret.addProperty("path", path());
return ret;
}
void PIIODevice::configureFromVariantDevice(const PIPropertyStorage & d) {
setPath(d.propertyValueByName("path").toString());
}

View File

@@ -32,6 +32,7 @@
// function executed from threaded read, pass ThreadedReadData, readedData, sizeOfData
typedef bool (*ReadRetFunc)(void * , uchar * , int );
#ifdef DOXYGEN
//! \relatesalso PIIODevice \brief Use this macro to enable automatic creation instances of your class with \a createFromFullPath() function
@@ -229,16 +230,27 @@ public:
//! Reimplement to construct full unambiguous string prefix. \ref PIIODevice_sec7
virtual PIString fullPathPrefix() const {return PIString();}
//! Reimplement to construct full unambiguous string, describes this device, default returns \a fullPathPrefix() + "://" + \a path()
//! Returns full unambiguous string, describes this device, \a fullPathPrefix() + "://"
PIString constructFullPath() const;
//! Reimplement to configure your device with parameters of full unambiguous string. Default implementation does nothing
//! Configure device with parameters of full unambiguous string
void configureFromFullPath(const PIString & full_path);
//! Returns PIVariantTypes::IODevice, describes this device
PIVariantTypes::IODevice constructVariant() const;
//! Configure device from PIVariantTypes::IODevice
void configureFromVariant(const PIVariantTypes::IODevice & d);
//! \brief Try to determine suitable device, create new one, configure it with \a configureFromFullPath() and returns it.
//! \details To function \a configureFromFullPath() "full_path" passed without \a fullPathPrefix() + "://".
//! See \ref PIIODevice_sec7
static PIIODevice * createFromFullPath(const PIString & full_path);
//! \brief Try to determine suitable device, create new one, configure it with \a configureFromVariant() and returns it.
//! \details To function \a configureFromFullPath() "full_path" passed without \a fullPathPrefix() + "://".
//! See \ref PIIODevice_sec7
static PIIODevice * createFromVariant(const PIVariantTypes::IODevice & d);
static PIString normalizeFullPath(const PIString & full_path);
@@ -347,11 +359,13 @@ protected:
//! Reimplement to configure your device with parameters of full unambiguous string. Default implementation does nothing
virtual void configureFromFullPathDevice(const PIString & full_path) {setPath(full_path);}
//! Reimplement to construct full unambiguous string, describes this device. Default implementation returns \a path()
virtual PIVariantTypes::IODevice constructPropertyStorage() const {return PIVariantTypes::IODevice();}
//! Reimplement to construct device properties.
//! Default implementation return PIPropertyStorage with \"path\" entry
virtual PIPropertyStorage constructVariantDevice() const;
//! Reimplement to configure your device with parameters of full unambiguous string. Default implementation does nothing
virtual void configureFromPropertyStorage(const PIVariantTypes::IODevice & d) {}
//! Reimplement to configure your device from PIPropertyStorage. Options and mode already applied.
//! Default implementation apply \"path\" entry
virtual void configureFromVariantDevice(const PIPropertyStorage & d);
//! Reimplement to apply new device options
virtual void optionsChanged() {;}
@@ -362,7 +376,8 @@ protected:
//! Reimplement to apply new \a threadedReadBufferSize()
virtual void threadedReadBufferSizeChanged() {;}
static PIIODevice * newDeviceByPrefix(const PIString & prefix);
void terminate();

View File

@@ -20,6 +20,7 @@
#include "piserial.h"
#include "piconfig.h"
#include "pidir.h"
#include "pipropertystorage.h"
#include <errno.h>
#ifdef WINDOWS
# include <winreg.h>
@@ -716,6 +717,28 @@ void PISerial::configureFromFullPathDevice(const PIString & full_path) {
}
PIPropertyStorage PISerial::constructVariantDevice() const {
PIPropertyStorage ret;
ret.addProperty("path", path());
ret.addProperty("speed", (int)inSpeed());
ret.addProperty("bits", dataBitsCount());
ret.addProperty("parity", parameters()[ParityControl]);
ret.addProperty("parityEven", !parameters()[ParityOdd]);
ret.addProperty("twoStopBits", parameters()[TwoStopBits]);
return ret;
}
void PISerial::configureFromVariantDevice(const PIPropertyStorage & d) {
setPath(d.propertyValueByName("path").toString());
setSpeed((Speed)d.propertyValueByName("speed").toInt());
setDataBitsCount(d.propertyValueByName("bits").toInt());
setParameter(ParityControl, d.propertyValueByName("parity").toBool());
setParameter(ParityOdd , !d.propertyValueByName("parityEven").toBool());
setParameter(TwoStopBits , d.propertyValueByName("twoStopBits").toBool());
}
PIVector<int> PISerial::availableSpeeds() {
PIVector<int> spds;
spds << 50 << 75 << 110 << 300 << 600 << 1200 << 2400 << 4800 <<

View File

@@ -203,6 +203,8 @@ protected:
PIString fullPathPrefix() const {return PIStringAscii("ser");}
PIString constructFullPathDevice() const;
void configureFromFullPathDevice(const PIString & full_path);
PIPropertyStorage constructVariantDevice() const;
void configureFromVariantDevice(const PIPropertyStorage & d);
bool configureDevice(const void * e_main, const void * e_parent = 0);
void optionsChanged();
void threadedReadBufferSizeChanged();