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

This commit is contained in:
2018-12-25 20:29:30 +00:00
parent 340a239f03
commit dc790b44c8
16 changed files with 193 additions and 57 deletions

View File

@@ -464,7 +464,7 @@ PIString PIVariant::toString() const {
case PIVariant::pivDate: {PIDate r; ba >> r; return r.toString();} case PIVariant::pivDate: {PIDate r; ba >> r; return r.toString();}
case PIVariant::pivDateTime: {PIDateTime r; ba >> r; return r.toString();} case PIVariant::pivDateTime: {PIDateTime r; ba >> r; return r.toString();}
case PIVariant::pivString: {PIString r; ba >> r; return r;} case PIVariant::pivString: {PIString r; ba >> r; return r;}
case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return PIString(); return r.front();} case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return PIString(); return r.join(";");}
case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return r.selectedName();} case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return r.selectedName();}
case PIVariant::pivFile: {PIVariantTypes::File r; ba >> r; return r.file;} case PIVariant::pivFile: {PIVariantTypes::File r; ba >> r; return r.file;}
case PIVariant::pivDir: {PIVariantTypes::Dir r; ba >> r; return r.dir;} case PIVariant::pivDir: {PIVariantTypes::Dir r; ba >> r; return r.dir;}

View File

@@ -104,6 +104,28 @@ PIPropertyStorage PIVariantTypes::IODevice::get() const {
} }
PIString PIVariantTypes::IODevice::toString() const {
PIString s;
s << "IODevice(" << prefix << ", ";
int rwc = 0;
if (mode & 1) {s << "r"; ++rwc;}
if (mode & 2) {s << "w"; ++rwc;}
if (rwc == 1) s << "o";
if (options != 0) {
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead])
s << " br";
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite])
s << " bw";
}
PIPropertyStorage ps = get();
piForeachC (PIPropertyStorage::Property & p, ps) {
s << ", " << p.name << "=\"" << p.value.toString() << "\"";
}
s << ")";
return s;
}
PIVariantTypes::Enum & PIVariantTypes::Enum::operator <<(const PIVariantTypes::Enumerator & v) { PIVariantTypes::Enum & PIVariantTypes::Enum::operator <<(const PIVariantTypes::Enumerator & v) {
@@ -123,28 +145,3 @@ 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;
}

View File

@@ -81,6 +81,7 @@ namespace PIVariantTypes {
IODevice(); IODevice();
void set(const PIPropertyStorage & ps); void set(const PIPropertyStorage & ps);
PIPropertyStorage get() const; PIPropertyStorage get() const;
PIString toString() const;
PIString prefix; PIString prefix;
int mode; // PIIODevice::DeviceMode int mode; // PIIODevice::DeviceMode
int options; // PIIODevice::DeviceOptions int options; // PIIODevice::DeviceOptions
@@ -111,7 +112,7 @@ inline PICout operator <<(PICout s, const PIVariantTypes::Color & v) {s.saveCont
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, 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;} 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); inline PICout operator <<(PICout s, const PIVariantTypes::IODevice & v) {s << v.toString(); return s;}
#endif // PIVARIANTYPES_H #endif // PIVARIANTYPES_H

View File

@@ -19,6 +19,7 @@
#include "pibinarylog.h" #include "pibinarylog.h"
#include "pidir.h" #include "pidir.h"
#include "pipropertystorage.h"
/*! \class PIBinaryLog /*! \class PIBinaryLog
* \brief Class for read and write binary data to logfile, and playback this data in realtime, or custom speed * \brief Class for read and write binary data to logfile, and playback this data in realtime, or custom speed
@@ -557,27 +558,6 @@ bool PIBinaryLog::cutBinLog(const PIBinaryLog::BinLogInfo & src, const PIString
} }
PIString PIBinaryLog::constructFullPathDevice() const {
PIString ret;
ret << logDir() << ":" << filePrefix() << ":" << defaultID() << ":";
switch (play_mode) {
case PlayRealTime:
ret << "RT";
break;
case PlayVariableSpeed:
ret << PIString::fromNumber(playSpeed()) << "X";
break;
case PlayStaticDelay:
ret << PIString::fromNumber(playDelay().toMilliseconds()) << "M";
break;
default:
ret << "RT";
break;
}
return ret;
}
bool PIBinaryLog::createIndex() { bool PIBinaryLog::createIndex() {
llong cp = file.pos(); llong cp = file.pos();
file.seekToBegin(); file.seekToBegin();
@@ -635,6 +615,27 @@ bool PIBinaryLog::seek(llong filepos) {
} }
PIString PIBinaryLog::constructFullPathDevice() const {
PIString ret;
ret << logDir() << ":" << filePrefix() << ":" << defaultID() << ":";
switch (play_mode) {
case PlayRealTime:
ret << "RT";
break;
case PlayVariableSpeed:
ret << PIString::fromNumber(playSpeed()) << "X";
break;
case PlayStaticDelay:
ret << PIString::fromNumber(playDelay().toMilliseconds()) << "M";
break;
default:
ret << "RT";
break;
}
return ret;
}
void PIBinaryLog::configureFromFullPathDevice(const PIString & full_path) { void PIBinaryLog::configureFromFullPathDevice(const PIString & full_path) {
PIStringList pl = full_path.split(":"); PIStringList pl = full_path.split(":");
for (int i = 0; i < pl.size_s(); ++i) { for (int i = 0; i < pl.size_s(); ++i) {
@@ -650,7 +651,32 @@ void PIBinaryLog::configureFromFullPathDevice(const PIString & full_path) {
break; break;
} }
} }
// piCoutObj << "configured"; // piCoutObj << "configured";
}
PIPropertyStorage PIBinaryLog::constructVariantDevice() const {
PIPropertyStorage ret;
PIVariantTypes::Enum e;
ret.addProperty("log dir", PIVariantTypes::Dir(logDir()));
ret.addProperty("file prefix", filePrefix());
ret.addProperty("default ID", defaultID());
e << "real-time" << "variable speed" << "static delay";
e.selectValue((int)playMode());
ret.addProperty("play mode", e);
ret.addProperty("play speed", playSpeed());
ret.addProperty("play delay", playDelay().toMilliseconds());
return ret;
}
void PIBinaryLog::configureFromVariantDevice(const PIPropertyStorage & d) {
setLogDir(d.propertyValueByName("log dir").toString());
setFilePrefix(d.propertyValueByName("file prefix").toString());
setDefaultID(d.propertyValueByName("default ID").toInt());
setPlaySpeed(d.propertyValueByName("play speed").toDouble());
setPlayDelay(PISystemTime::fromMilliseconds(d.propertyValueByName("play delay").toDouble()));
setPlayMode((PlayMode)d.propertyValueByName("play mode").toEnum().selectedValue());
} }

View File

@@ -276,6 +276,8 @@ protected:
PIString fullPathPrefix() const {return PIStringAscii("binlog");} PIString fullPathPrefix() const {return PIStringAscii("binlog");}
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);
int readDevice(void *read_to, int max_size); int readDevice(void *read_to, int max_size);
int writeDevice(const void * data, int size) {return writeBinLog(default_id, data, size);} int writeDevice(const void * data, int size) {return writeBinLog(default_id, data, size);}
bool openDevice(); bool openDevice();

View File

@@ -1,4 +1,5 @@
#include "pican.h" #include "pican.h"
#include "pipropertystorage.h"
#include "piincludes_p.h" #include "piincludes_p.h"
#if !defined(WINDOWS) && !defined(MAC_OS) #if !defined(WINDOWS) && !defined(MAC_OS)
# define PIP_CAN # define PIP_CAN
@@ -136,3 +137,17 @@ void PICAN::configureFromFullPathDevice(const PIString & full_path) {
} }
} }
} }
PIPropertyStorage PICAN::constructVariantDevice() const {
PIPropertyStorage ret;
ret.addProperty("path", path());
ret.addProperty("CAN ID", PIString::fromNumber(CANID(),16));
return ret;
}
void PICAN::configureFromVariantDevice(const PIPropertyStorage & d) {
setPath(d.propertyValueByName("path").toString());
setCANID(d.propertyValueByName("CAN ID").toString().toInt(16));
}

View File

@@ -22,6 +22,8 @@ protected:
PIString fullPathPrefix() const {return PIStringAscii("can");} PIString fullPathPrefix() const {return PIStringAscii("can");}
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);
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;} DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
private: private:

View File

@@ -20,6 +20,7 @@
#include "piethernet.h" #include "piethernet.h"
#include "piconfig.h" #include "piconfig.h"
#include "pisysteminfo.h" #include "pisysteminfo.h"
#include "pipropertystorage.h"
#ifdef QNX #ifdef QNX
# include <net/if.h> # include <net/if.h>
# include <net/if_dl.h> # include <net/if_dl.h>
@@ -906,6 +907,39 @@ void PIEthernet::configureFromFullPathDevice(const PIString & full_path) {
} }
PIPropertyStorage PIEthernet::constructVariantDevice() const {
PIPropertyStorage ret;
PIVariantTypes::Enum e;
e << "UDP" << "TCP";
if (type() == PIEthernet::UDP)
e.selectValue(0);
else
e.selectValue(1);
ret.addProperty("protocol", e);
ret.addProperty("read IP", readIP());
ret.addProperty("read port", readPort());
ret.addProperty("send IP", sendIP());
ret.addProperty("send port", sendPort());
ret.addProperty("multicast", multicastGroups());
return ret;
}
void PIEthernet::configureFromVariantDevice(const PIPropertyStorage & d) {
setType(d.propertyValueByName("protocol").toEnum().selectedValue() == 0 ? UDP : TCP_Client);
setReadIP(d.propertyValueByName("read IP").toString());
setReadPort(d.propertyValueByName("read port").toInt());
setSendIP(d.propertyValueByName("send IP").toString());
setSendPort(d.propertyValueByName("send port").toInt());
PIStringList mcgl = d.propertyValueByName("multicast").toStringList();
piForeachC (PIString & g, mcgl) {
joinMulticastGroup(g);
}
}
PIEthernet::InterfaceList PIEthernet::interfaces() { PIEthernet::InterfaceList PIEthernet::interfaces() {
PIEthernet::InterfaceList il; PIEthernet::InterfaceList il;
Interface ci; Interface ci;

View File

@@ -464,6 +464,8 @@ protected:
PIString fullPathPrefix() const {return PIStringAscii("eth");} PIString fullPathPrefix() const {return PIStringAscii("eth");}
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);
int readDevice(void * read_to, int max_size); int readDevice(void * read_to, int max_size);
int writeDevice(const void * data, int max_size); int writeDevice(const void * data, int max_size);

View File

@@ -20,6 +20,7 @@
#include "pipeer.h" #include "pipeer.h"
#include "piconfig.h" #include "piconfig.h"
#include "pidatatransfer.h" #include "pidatatransfer.h"
#include "pipropertystorage.h"
#define _PIPEER_MSG_SIZE 4000 #define _PIPEER_MSG_SIZE 4000
#define _PIPEER_MSG_TTL 100 #define _PIPEER_MSG_TTL 100
@@ -961,13 +962,6 @@ void PIPeer::changeName(const PIString &new_name) {
} }
PIString PIPeer::constructFullPathDevice() const {
PIString ret;
ret << self_info.name << ":" << trustPeerName();
return ret;
}
int PIPeer::readDevice(void *read_to, int max_size) { int PIPeer::readDevice(void *read_to, int max_size) {
read_buffer_mutex.lock(); read_buffer_mutex.lock();
bool empty = read_buffer.isEmpty(); bool empty = read_buffer.isEmpty();
@@ -1010,6 +1004,13 @@ void PIPeer::newTcpClient(PIEthernet *client) {
} }
PIString PIPeer::constructFullPathDevice() const {
PIString ret;
ret << self_info.name << ":" << trustPeerName();
return ret;
}
void PIPeer::configureFromFullPathDevice(const PIString & full_path) { void PIPeer::configureFromFullPathDevice(const PIString & full_path) {
PIStringList pl = full_path.split(":"); PIStringList pl = full_path.split(":");
for (int i = 0; i < pl.size_s(); ++i) { for (int i = 0; i < pl.size_s(); ++i) {
@@ -1022,6 +1023,20 @@ void PIPeer::configureFromFullPathDevice(const PIString & full_path) {
} }
PIPropertyStorage PIPeer::constructVariantDevice() const {
PIPropertyStorage ret;
ret.addProperty("name", self_info.name);
ret.addProperty("trust peer", trustPeerName());
return ret;
}
void PIPeer::configureFromVariantDevice(const PIPropertyStorage & d) {
changeName(d.propertyValueByName("name").toString());
setTrustPeerName(d.propertyValueByName("trust peer").toString());
}
void PIPeer::initNetwork() { void PIPeer::initNetwork() {
// piCoutObj << "initNetwork ..."; // piCoutObj << "initNetwork ...";
eth_send.init(); eth_send.init();

View File

@@ -169,6 +169,8 @@ private:
PIString fullPathPrefix() const {return PIStringAscii("peer");} PIString fullPathPrefix() const {return PIStringAscii("peer");}
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);
int readDevice(void * read_to, int max_size); int readDevice(void * read_to, int max_size);
int writeDevice(const void * data, int size); int writeDevice(const void * data, int size);
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;} DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}

View File

@@ -706,7 +706,7 @@ void PISerial::configureFromFullPathDevice(const PIString & full_path) {
case 1: setProperty("outSpeed", p.toInt()); setProperty("inSpeed", p.toInt()); break; case 1: setProperty("outSpeed", p.toInt()); setProperty("inSpeed", p.toInt()); break;
case 2: setProperty("dataBitsCount", p.toInt()); break; case 2: setProperty("dataBitsCount", p.toInt()); break;
case 3: case 3:
p = p.toLowerCase(); p = p.left(1).toLowerCase();
if (p != "n") setParameter(ParityControl); if (p != "n") setParameter(ParityControl);
if (p == "o") setParameter(ParityOdd); if (p == "o") setParameter(ParityOdd);
break; break;

View File

@@ -18,6 +18,7 @@
*/ */
#include "piincludes_p.h" #include "piincludes_p.h"
#include "pisharedmemory.h" #include "pisharedmemory.h"
#include "pipropertystorage.h"
#if defined(LINUX) || defined(MAC_OS) #if defined(LINUX) || defined(MAC_OS)
# define SHM_POSIX # define SHM_POSIX
#endif #endif
@@ -182,6 +183,20 @@ void PISharedMemory::configureFromFullPathDevice(const PIString & full_path) {
} }
PIPropertyStorage PISharedMemory::constructVariantDevice() const {
PIPropertyStorage ret;
ret.addProperty("path", path());
ret.addProperty("size", dsize);
return ret;
}
void PISharedMemory::configureFromVariantDevice(const PIPropertyStorage & d) {
setPath(d.propertyValueByName("path").toString());
setSize(d.propertyValueByName("size").toInt());
}
void PISharedMemory::initPrivate() { void PISharedMemory::initPrivate() {
#ifdef WINDOWS #ifdef WINDOWS
PRIVATE->map = 0; PRIVATE->map = 0;

View File

@@ -76,6 +76,8 @@ protected:
PIString fullPathPrefix() const {return PIStringAscii("shm");} PIString fullPathPrefix() const {return PIStringAscii("shm");}
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);
int readDevice(void * read_to, int max_size) {return read(read_to, max_size, 0);} int readDevice(void * read_to, int max_size) {return read(read_to, max_size, 0);}
int writeDevice(const void * data, int max_size) {return write(data, max_size, 0);} int writeDevice(const void * data, int max_size) {return write(data, max_size, 0);}
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;} DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}

View File

@@ -1,4 +1,5 @@
#include "pispi.h" #include "pispi.h"
#include "pipropertystorage.h"
#include "piincludes_p.h" #include "piincludes_p.h"
#if !defined(WINDOWS) && !defined(MAC_OS) #if !defined(WINDOWS) && !defined(MAC_OS)
# define PIP_SPI # define PIP_SPI
@@ -145,3 +146,23 @@ void PISPI::configureFromFullPathDevice(const PIString & full_path) {
} }
} }
} }
PIPropertyStorage PISPI::constructVariantDevice() const {
PIPropertyStorage ret;
ret.addProperty("path", path());
ret.addProperty("speed", int(speed()));
ret.addProperty("bits", int(bits()));
ret.addProperty("clock inverse", isParameterSet(ClockInverse));
ret.addProperty("clock phase shift", isParameterSet(ClockPhaseShift));
return ret;
}
void PISPI::configureFromVariantDevice(const PIPropertyStorage & d) {
setPath(d.propertyValueByName("path").toString());
setSpeed(d.propertyValueByName("speed").toInt());
setBits(d.propertyValueByName("bits").toInt());
setParameter(ClockInverse, d.propertyValueByName("clock inverse").toBool());
setParameter(ClockPhaseShift, d.propertyValueByName("clock phase shift").toBool());
}

View File

@@ -45,6 +45,8 @@ protected:
PIString fullPathPrefix() const {return PIStringAscii("spi");} PIString fullPathPrefix() const {return PIStringAscii("spi");}
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);
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Sequential;} DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Sequential;}
private: private: