git-svn-id: svn://db.shs.com.ru/pip@673 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
8
main.cpp
8
main.cpp
@@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
PIByteArray msg = PIByteArray::fromHex("0110f0f00001020001");
|
/*PIByteArray msg = PIByteArray::fromHex("0110f0f00001020001");
|
||||||
PIByteArray src = PIByteArray::fromHex("836f");
|
PIByteArray src = PIByteArray::fromHex("836f");
|
||||||
ushort s; memcpy(&s, src.data(), 2);
|
ushort s; memcpy(&s, src.data(), 2);
|
||||||
//CRC_16 crc = standardCRC_16();
|
//CRC_16 crc = standardCRC_16();
|
||||||
CRC_16 crc = CRC_16(0x8005, 0xFFFF, 0xFFFF, false);
|
CRC_16 crc = CRC_16(0x8005, 0xFFFF, 0xFFFF, false);
|
||||||
piCout << PICoutManipulators::Hex << s;
|
piCout << PICoutManipulators::Hex << s;
|
||||||
piCout << PICoutManipulators::Hex << crc.calculate(msg);
|
piCout << PICoutManipulators::Hex << crc.calculate(msg);*/
|
||||||
|
PIIODevice * ser = PIIODevice::createFromFullPath("ser://COM3:9600:9:o:2 (wo,bwr)");
|
||||||
|
piCout << ser << ser->constructVariant() << ser->constructFullPath();
|
||||||
|
ser = PIIODevice::createFromVariant(ser->constructVariant());
|
||||||
|
piCout << ser << ser->constructVariant() << ser->constructFullPath();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -741,6 +741,7 @@ REGISTER_NS_VARIANT(PIVariantTypes, Enum)
|
|||||||
REGISTER_NS_VARIANT(PIVariantTypes, File)
|
REGISTER_NS_VARIANT(PIVariantTypes, File)
|
||||||
REGISTER_NS_VARIANT(PIVariantTypes, Dir)
|
REGISTER_NS_VARIANT(PIVariantTypes, Dir)
|
||||||
REGISTER_NS_VARIANT(PIVariantTypes, Color)
|
REGISTER_NS_VARIANT(PIVariantTypes, Color)
|
||||||
|
REGISTER_NS_VARIANT(PIVariantTypes, IODevice)
|
||||||
REGISTER_VARIANT(PIPointd)
|
REGISTER_VARIANT(PIPointd)
|
||||||
REGISTER_VARIANT(PIRectd)
|
REGISTER_VARIANT(PIRectd)
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "pivarianttypes.h"
|
#include "pivarianttypes.h"
|
||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
|
#include "piiodevice.h"
|
||||||
|
|
||||||
|
|
||||||
int PIVariantTypes::Enum::selectedValue() const {
|
int PIVariantTypes::Enum::selectedValue() const {
|
||||||
@@ -83,6 +84,12 @@ PIStringList PIVariantTypes::Enum::names() const {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PIVariantTypes::IODevice::IODevice() {
|
||||||
|
mode = PIIODevice::ReadWrite;
|
||||||
|
options = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIVariantTypes::IODevice::set(const PIPropertyStorage & ps) {
|
void PIVariantTypes::IODevice::set(const PIPropertyStorage & ps) {
|
||||||
props.clear();
|
props.clear();
|
||||||
props << ps;
|
props << ps;
|
||||||
@@ -116,3 +123,28 @@ PIVariantTypes::Enum & PIVariantTypes::Enum::operator <<(const PIStringList & v)
|
|||||||
(*this) << s.trimmed();
|
(*this) << s.trimmed();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PICout operator <<(PICout s, const PIVariantTypes::IODevice & v) {
|
||||||
|
s.setControl(0, true);
|
||||||
|
s << "IODevice(" << v.prefix << ", ";
|
||||||
|
int rwc = 0;
|
||||||
|
if (v.mode & 1) {s << "r"; ++rwc;}
|
||||||
|
if (v.mode & 2) {s << "w"; ++rwc;}
|
||||||
|
if (rwc == 1) s << "o";
|
||||||
|
if (v.options != 0) {
|
||||||
|
if (((PIIODevice::DeviceOptions)v.options)[PIIODevice::BlockingRead])
|
||||||
|
s << " br";
|
||||||
|
if (((PIIODevice::DeviceOptions)v.options)[PIIODevice::BlockingWrite])
|
||||||
|
s << " bw";
|
||||||
|
}
|
||||||
|
PIPropertyStorage ps = v.get();
|
||||||
|
piForeachC (PIPropertyStorage::Property & p, ps) {
|
||||||
|
s << ", " << p.name << "=\"" << p.value.toString() << "\"";
|
||||||
|
}
|
||||||
|
s << ")";
|
||||||
|
s.restoreControl();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|||||||
@@ -78,9 +78,12 @@ namespace PIVariantTypes {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct PIP_EXPORT IODevice {
|
struct PIP_EXPORT IODevice {
|
||||||
IODevice() {}
|
IODevice();
|
||||||
void set(const PIPropertyStorage & ps);
|
void set(const PIPropertyStorage & ps);
|
||||||
PIPropertyStorage get() const;
|
PIPropertyStorage get() const;
|
||||||
|
PIString prefix;
|
||||||
|
int mode; // PIIODevice::DeviceMode
|
||||||
|
int options; // PIIODevice::DeviceOptions
|
||||||
PIByteArray props;
|
PIByteArray props;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,5 +109,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Color &
|
|||||||
inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Color & v) {s >> v.rgba; return s;}
|
inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Color & v) {s >> v.rgba; return s;}
|
||||||
inline PICout operator <<(PICout s, const PIVariantTypes::Color & v) {s.saveControl(); s << PICoutManipulators::Hex << "Color(#" << v.rgba << ")"; s.restoreControl(); return s;}
|
inline PICout operator <<(PICout s, const PIVariantTypes::Color & v) {s.saveControl(); s << PICoutManipulators::Hex << "Color(#" << v.rgba << ")"; s.restoreControl(); return s;}
|
||||||
|
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::IODevice & v) {s << v.prefix << v.mode << v.options << v.props; return s;}
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::IODevice & v) {s >> v.prefix >> v.mode >> v.options >> v.props; return s;}
|
||||||
|
PICout operator <<(PICout s, const PIVariantTypes::IODevice & v);
|
||||||
|
|
||||||
|
|
||||||
#endif // PIVARIANTYPES_H
|
#endif // PIVARIANTYPES_H
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
#include "piconnection.h"
|
#include "piconnection.h"
|
||||||
|
#include "pipropertystorage.h"
|
||||||
|
|
||||||
|
|
||||||
/*! \class PIIODevice
|
/*! \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() {
|
void PIIODevice::terminate() {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
thread_started_ = false;
|
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) {
|
void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * mode, DeviceOptions * opts) {
|
||||||
int dm = 0;
|
int dm = 0;
|
||||||
DeviceOptions op = 0;
|
DeviceOptions op = 0;
|
||||||
@@ -363,17 +393,19 @@ PIString PIIODevice::fullPathOptions() const {
|
|||||||
|
|
||||||
PIIODevice * PIIODevice::createFromFullPath(const PIString & full_path) {
|
PIIODevice * PIIODevice::createFromFullPath(const PIString & full_path) {
|
||||||
PIString prefix = full_path.left(full_path.find(":"));
|
PIString prefix = full_path.left(full_path.find(":"));
|
||||||
if (prefix.isEmpty()) return 0;
|
PIIODevice * nd = newDeviceByPrefix(prefix);
|
||||||
PIVector<const PIObject * > rd(PICollection::groupElements("__PIIODevices__"));
|
if (!nd) return 0;
|
||||||
piForeachC (PIObject * d, rd) {
|
nd->configureFromFullPath(full_path.mid(prefix.length() + 3));
|
||||||
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);
|
cacheFullPath(full_path, nd);
|
||||||
return nd;
|
return nd;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
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);
|
if (ret_func_ != 0) return ret_func_(ret_data_, readed, size);
|
||||||
return true;
|
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());
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
// function executed from threaded read, pass ThreadedReadData, readedData, sizeOfData
|
// function executed from threaded read, pass ThreadedReadData, readedData, sizeOfData
|
||||||
typedef bool (*ReadRetFunc)(void * , uchar * , int );
|
typedef bool (*ReadRetFunc)(void * , uchar * , int );
|
||||||
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
#ifdef DOXYGEN
|
||||||
|
|
||||||
//! \relatesalso PIIODevice \brief Use this macro to enable automatic creation instances of your class with \a createFromFullPath() function
|
//! \relatesalso PIIODevice \brief Use this macro to enable automatic creation instances of your class with \a createFromFullPath() function
|
||||||
@@ -229,17 +230,28 @@ public:
|
|||||||
//! Reimplement to construct full unambiguous string prefix. \ref PIIODevice_sec7
|
//! Reimplement to construct full unambiguous string prefix. \ref PIIODevice_sec7
|
||||||
virtual PIString fullPathPrefix() const {return PIString();}
|
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;
|
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);
|
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.
|
//! \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() + "://".
|
//! \details To function \a configureFromFullPath() "full_path" passed without \a fullPathPrefix() + "://".
|
||||||
//! See \ref PIIODevice_sec7
|
//! See \ref PIIODevice_sec7
|
||||||
static PIIODevice * createFromFullPath(const PIString & full_path);
|
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);
|
static PIString normalizeFullPath(const PIString & full_path);
|
||||||
|
|
||||||
static void splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * mode = 0, DeviceOptions * opts = 0);
|
static void splitFullPath(PIString fpwm, PIString * full_path, DeviceMode * mode = 0, DeviceOptions * opts = 0);
|
||||||
@@ -347,11 +359,13 @@ protected:
|
|||||||
//! Reimplement to configure your device with parameters of full unambiguous string. Default implementation does nothing
|
//! 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);}
|
virtual void configureFromFullPathDevice(const PIString & full_path) {setPath(full_path);}
|
||||||
|
|
||||||
//! Reimplement to construct full unambiguous string, describes this device. Default implementation returns \a path()
|
//! Reimplement to construct device properties.
|
||||||
virtual PIVariantTypes::IODevice constructPropertyStorage() const {return PIVariantTypes::IODevice();}
|
//! 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
|
//! Reimplement to configure your device from PIPropertyStorage. Options and mode already applied.
|
||||||
virtual void configureFromPropertyStorage(const PIVariantTypes::IODevice & d) {}
|
//! Default implementation apply \"path\" entry
|
||||||
|
virtual void configureFromVariantDevice(const PIPropertyStorage & d);
|
||||||
|
|
||||||
//! Reimplement to apply new device options
|
//! Reimplement to apply new device options
|
||||||
virtual void optionsChanged() {;}
|
virtual void optionsChanged() {;}
|
||||||
@@ -362,6 +376,7 @@ protected:
|
|||||||
//! Reimplement to apply new \a threadedReadBufferSize()
|
//! Reimplement to apply new \a threadedReadBufferSize()
|
||||||
virtual void threadedReadBufferSizeChanged() {;}
|
virtual void threadedReadBufferSizeChanged() {;}
|
||||||
|
|
||||||
|
static PIIODevice * newDeviceByPrefix(const PIString & prefix);
|
||||||
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "piserial.h"
|
#include "piserial.h"
|
||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
#include "pidir.h"
|
#include "pidir.h"
|
||||||
|
#include "pipropertystorage.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <winreg.h>
|
# 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> PISerial::availableSpeeds() {
|
||||||
PIVector<int> spds;
|
PIVector<int> spds;
|
||||||
spds << 50 << 75 << 110 << 300 << 600 << 1200 << 2400 << 4800 <<
|
spds << 50 << 75 << 110 << 300 << 600 << 1200 << 2400 << 4800 <<
|
||||||
|
|||||||
@@ -203,6 +203,8 @@ protected:
|
|||||||
PIString fullPathPrefix() const {return PIStringAscii("ser");}
|
PIString fullPathPrefix() const {return PIStringAscii("ser");}
|
||||||
PIString constructFullPathDevice() const;
|
PIString constructFullPathDevice() const;
|
||||||
void configureFromFullPathDevice(const PIString & full_path);
|
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);
|
bool configureDevice(const void * e_main, const void * e_parent = 0);
|
||||||
void optionsChanged();
|
void optionsChanged();
|
||||||
void threadedReadBufferSizeChanged();
|
void threadedReadBufferSizeChanged();
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#define PIVERSION_H
|
#define PIVERSION_H
|
||||||
|
|
||||||
#define PIP_VERSION_MAJOR 1
|
#define PIP_VERSION_MAJOR 1
|
||||||
#define PIP_VERSION_MINOR 8
|
#define PIP_VERSION_MINOR 9
|
||||||
#define PIP_VERSION_REVISION 1
|
#define PIP_VERSION_REVISION 0
|
||||||
#define PIP_VERSION_SUFFIX ""
|
#define PIP_VERSION_SUFFIX "_alpha"
|
||||||
|
|
||||||
#endif // PIVERSION_H
|
#endif // PIVERSION_H
|
||||||
|
|||||||
Reference in New Issue
Block a user