Merge remote-tracking branch 'remotes/origin/stream_interface'

PIBinaryLog
This commit is contained in:
Бычков Андрей
2022-07-22 15:22:33 +03:00
92 changed files with 1807 additions and 1791 deletions

View File

@@ -148,7 +148,7 @@ int PICAN::readedCANID() const {
PIString PICAN::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << PIString::fromNumber(CANID(),16);
ret += path() + ":" + PIString::fromNumber(CANID(), 16);
return ret;
}

View File

@@ -400,7 +400,7 @@ PIString PIConfig::_readLineDev() {
void PIConfig::_writeDev(const PIString & l) {
//piCout << "write \"" << l << "\"";
if (!dev) return;
if (PIString(dev->className()) == "PIFile") {*((PIFile*)dev) << (l); return;}
if (PIString(dev->className()) == "PIFile") {((PIFile*)dev)->write(l.toUTF8()); return;}
if (PIString(dev->className()) == "PIIOString") {((PIIOString*)dev)->writeString(l); return;}
dev->write(l.toByteArray());
}

View File

@@ -116,9 +116,9 @@ PIEthernet::Address::Address(const PIString & _ip, ushort _port) {
PIString PIEthernet::Address::ipString() const {
PIString ret = PIString::fromNumber(ip_b[0]);
ret << "." << PIString::fromNumber(ip_b[1]);
ret << "." << PIString::fromNumber(ip_b[2]);
ret << "." << PIString::fromNumber(ip_b[3]);
ret += "." + PIString::fromNumber(ip_b[1]);
ret += "." + PIString::fromNumber(ip_b[2]);
ret += "." + PIString::fromNumber(ip_b[3]);
return ret;
}
@@ -930,11 +930,12 @@ void PIEthernet::propertyChanged(const char * name) {
PIString PIEthernet::constructFullPathDevice() const {
PIString ret;
ret << (type() == PIEthernet::UDP ? "UDP" : "TCP") << ":" << readIP() << ":" << readPort();
ret += (type() == PIEthernet::UDP ? "UDP" : "TCP");
ret += ":" + readIP() + ":" + PIString::fromNumber(readPort());
if (type() == PIEthernet::UDP) {
ret << ":" << sendIP() << ":" << sendPort();
ret += ":" + sendIP() + ":" + PIString::fromNumber(sendPort());
piForeachC (PIString & m, multicastGroups())
ret << ":mcast:" << m;
ret += ":mcast:" + m;
}
return ret;
}

View File

@@ -452,7 +452,8 @@ void PIFile::setPrecision(int prec) {
PIFile & PIFile::put(const PIByteArray & v) {
writeBinary((int)v.size_s());
int sz = (int)v.size_s();
write(createMemoryBlock(&sz));
write(v);
return *this;
}
@@ -461,7 +462,7 @@ PIFile & PIFile::put(const PIByteArray & v) {
PIByteArray PIFile::get() {
PIByteArray ret;
int sz(0);
read(&sz, sizeof(sz));
read(createMemoryBlock(&sz));
if (sz > 0) {
ret.resize(sz);
read(ret.data(), sz);
@@ -470,156 +471,6 @@ PIByteArray PIFile::get() {
}
PIFile &PIFile::operator <<(double v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "lf").data(), v);
return *this;
}
PIFile &PIFile::operator >>(double & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lf", &v);
return *this;
}
PIFile &PIFile::operator >>(float & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%f", &v);
return *this;
}
PIFile &PIFile::operator >>(ullong & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lln", &v);
return *this;
}
PIFile &PIFile::operator >>(ulong & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%ln", &v);
return *this;
}
PIFile &PIFile::operator >>(uint & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%n", &v);
return *this;
}
PIFile &PIFile::operator >>(ushort & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hn", &v);
return *this;
}
PIFile &PIFile::operator >>(uchar & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hhn", &v);
return *this;
}
PIFile &PIFile::operator >>(llong & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lln", &v);
return *this;
}
PIFile &PIFile::operator >>(long & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%ln", &v);
return *this;
}
PIFile &PIFile::operator >>(int & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%n", &v);
return *this;
}
PIFile &PIFile::operator >>(short & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hn", &v);
return *this;
}
PIFile &PIFile::operator >>(char & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hhn", &v);
return *this;
}
PIFile &PIFile::operator <<(float v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "f").data(), v);
return *this;
}
PIFile &PIFile::operator <<(ullong v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%llu", v);
return *this;
}
PIFile &PIFile::operator <<(ulong v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%lu", v);
return *this;
}
PIFile &PIFile::operator <<(uint v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%u", v);
return *this;
}
PIFile &PIFile::operator <<(ushort v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%hu", v);
return *this;
}
PIFile &PIFile::operator <<(uchar v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%u", int(v));
return *this;
}
PIFile &PIFile::operator <<(llong v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%lld", v);
return *this;
}
PIFile &PIFile::operator <<(long v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%ld", v);
return *this;
}
PIFile &PIFile::operator <<(int v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%d", v);
return *this;
}
PIFile &PIFile::operator <<(short v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%hd", v);
return *this;
}
PIFile &PIFile::operator <<(const PIByteArray & v) {
if (canWrite() && PRIVATE->fd != 0) write(v.data(), v.size());
return *this;
}
PIFile &PIFile::operator <<(const char v) {
if (canWrite() && PRIVATE->fd != 0) write(&v, 1);
return *this;
}
int PIFile::readDevice(void * read_to, int max_size) {
if (!canRead() || PRIVATE->fd == 0) return -1;
return fread(read_to, 1, max_size, PRIVATE->fd);
@@ -632,13 +483,6 @@ int PIFile::writeDevice(const void * data, int max_size) {
}
PIFile &PIFile::operator <<(const PIString & v) {
if (canWrite() && v.isNotEmpty() && PRIVATE->fd != 0)
*this << v.toCharset(defaultCharset());
return *this;
}
void PIFile::clear() {
close();
PRIVATE->fd = fopen(path().data(), "w");

View File

@@ -260,161 +260,6 @@ public:
//! \~russian Читает из файла размер байтового массива и его содержимое (десериализация)
PIByteArray get();
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const char v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const short v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const int v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const long v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const llong v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const uchar v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const ushort v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const uint v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const ulong v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const ullong v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const float v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const double v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(const char v);
//! \~english Write to file string "v"
//! \~russian Пишет в файл строку "v"
PIFile & operator <<(const PIString & v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(const PIByteArray & v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(short v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(int v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(long v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(llong v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(uchar v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(ushort v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(uint v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(ulong v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(ullong v);
//! \~english Write to file text representation of "v" with precision \a precision()
//! \~russian Пишет в файл текстовое представление "v" с точностью \a precision()
PIFile & operator <<(float v);
//! \~english Write to file text representation of "v" with precision \a precision()
//! \~russian Пишет в файл текстовое представление "v" с точностью \a precision()
PIFile & operator <<(double v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(char & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(short & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(int & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(long & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(llong & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(uchar & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(ushort & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(uint & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(ulong & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(ullong & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(float & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(double & v);
EVENT_HANDLER(void, clear);
EVENT_HANDLER(void, remove);
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
@@ -518,14 +363,19 @@ inline PICout operator <<(PICout s, const PIFile::FileInfo & v) {
//! \relatesalso PIByteArray
//! \~english Store operator
//! \~russian Оператор сохранения
inline PIByteArray & operator <<(PIByteArray & s, const PIFile::FileInfo & v) {s << v.path << v.size << v.time_access << v.time_modification <<
(int)v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;}
BINARY_STREAM_WRITE(PIFile::FileInfo) {
s << v.path << v.size << v.time_access << v.time_modification <<
v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw;
return s;
}
//! \relatesalso PIByteArray
//! \~english Restore operator
//! \~russian Оператор извлечения
inline PIByteArray & operator >>(PIByteArray & s, PIFile::FileInfo & v) {s >> v.path >> v.size >> v.time_access >> v.time_modification >>
*(int*)(&(v.flags)) >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;}
BINARY_STREAM_READ(PIFile::FileInfo) {
s >> v.path >> v.size >> v.time_access >> v.time_modification >>
v.flags >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw;
return s;
}
#endif // PIFILE_H

View File

@@ -276,6 +276,10 @@ public:
//! \~russian Читает из устройства не более "max_size" байт в "read_to"
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
//! \~english Read from device to memory block "mb"
//! \~russian Читает из устройства в блок памяти "mb"
int read(PIMemoryBlock mb) {return readDevice(mb.data(), mb.size());}
//! \~english Read from device maximum "max_size" bytes and returns them as PIByteArray
//! \~russian Читает из устройства не более "max_size" байт и возвращает данные как PIByteArray
PIByteArray read(int max_size);
@@ -357,6 +361,10 @@ public:
EVENT_HANDLER(bool, close);
EVENT_HANDLER1(int, write, PIByteArray, data);
//! \~english Write memory block "mb" to device
//! \~russian Пишет в устройство блок памяти "mb"
int write(const PIMemoryBlock & mb) {return write(mb.data(), mb.size());}
EVENT_VHANDLER(void, flush) {;}
EVENT(opened)

View File

@@ -0,0 +1,99 @@
/*! \file piiostream.h
* \ingroup IO
* \~\brief
* \~english PIBinaryStream functionality for PIIODevice
* \~russian Функциональность PIBinaryStream для PIIODevice
*/
/*
PIP - Platform Independent Primitives
PIBinaryStream functionality for PIIODevice
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIIOSTREAM_H
#define PIIOSTREAM_H
#include "piiostring.h"
#include "pitextstream.h"
//! \ingroup IO
//! \~\brief
//! \~english PIBinaryStream functionality for PIIODevice.
//! \~russian Функциональность PIBinaryStream для PIIODevice.
class PIP_EXPORT PIIOBinaryStream: public PIBinaryStream<PIIOBinaryStream> {
public:
//! \~english Contructs %PIIOBinaryStream for "device" device
//! \~russian Создает %PIIOBinaryStream для устройства "device"
PIIOBinaryStream(PIIODevice * device = nullptr): dev(device) {}
//! \~english Assign "device" device
//! \~russian Назначает устройство "device"
void setDevice(PIIODevice * device) {dev = device;}
bool binaryStreamAppendImp(const void * d, size_t s) {
if (!dev) return false;
return dev->write(d, s);
}
bool binaryStreamTakeImp(void * d, size_t s) {
if (!dev) return false;
return dev->read(d, s);
}
private:
PIIODevice * dev;
};
//! \ingroup IO
//! \~\brief
//! \~english PITextStream functionality for PIIODevice.
//! \~russian Функциональность PITextStream для PIIODevice.
class PIP_EXPORT PIIOTextStream: public PITextStream<PIIOBinaryStream> {
public:
//! \~english Contructs %PIIOTextStream for "device" device
//! \~russian Создает %PIIOTextStream для устройства "device"
PIIOTextStream(PIIODevice * device): PITextStream<PIIOBinaryStream>(&bin_stream), bin_stream(device) {}
//! \~english Contructs %PIIOTextStream for "string" string
//! \~russian Создает %PIIOTextStream для строки "string"
PIIOTextStream(PIString * string): PITextStream<PIIOBinaryStream>(&bin_stream) {
io_string = new PIIOString(string);
bin_stream.setDevice(io_string);
}
~PIIOTextStream() {
if (io_string)
delete io_string;
}
void setDevice(PIIODevice * device) {
bin_stream = PIIOBinaryStream(device);
setStream(&bin_stream);
}
private:
PIIOString * io_string = nullptr;
PIIOBinaryStream bin_stream;
};
#endif // PIIOSTREAM_H

View File

@@ -573,7 +573,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
if (type <= 0 || type >= 4) return true;
PeerInfo pi;
ba >> pi.name;
// piCoutObj << "received mb from" << pi.name << "packet" << type;
//piCout << "received mb from" << pi.name << "packet" << type;
if (pi.name == self_info.name) return true;
PIMutexLocker locker(mc_mutex);
diag_s.received(size);
@@ -789,6 +789,7 @@ void PIPeer::sendPeerInfo(const PeerInfo & info) {
void PIPeer::sendPeerRemove(const PIString & peer) {
//piCout << name() << "sendPeerRemove" << peer;
PIByteArray ba;
ba << int(2) << peer;
sendMBcast(ba);
@@ -858,7 +859,7 @@ void PIPeer::syncPeers() {
PeerInfo & cp(peers[i]);
if (cp.sync > 3) {
pn = cp.name;
//piCoutObj << "sync: remove " << pn;
//piCout << "sync: remove " << pn;
cp.destroy();
addToRemoved(cp);
peers.remove(i);
@@ -967,7 +968,7 @@ void PIPeer::newTcpClient(PIEthernet *client) {
PIString PIPeer::constructFullPathDevice() const {
PIString ret;
ret << self_info.name << ":" << trustPeerName();
ret += self_info.name + ":" + trustPeerName();
return ret;
}

View File

@@ -41,8 +41,7 @@ public:
class PIP_EXPORT PeerInfo {
friend class PIPeer;
friend PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v);
friend PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v);
BINARY_STREAM_FRIEND(PIPeer::PeerInfo);
public:
PeerInfo() {dist = sync = cnt = 0; trace = -1; was_update = false; _data = 0;}
~PeerInfo() {}
@@ -80,9 +79,8 @@ public:
PeerData * _data;
};
friend PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v);
friend PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v);
BINARY_STREAM_FRIEND(PIPeer::PeerInfo);
bool send(const PIString & to, const PIByteArray & data) {return send(to, data.data(), data.size_s());}
bool send(const PIString & to, const PIString & data) {return send(to, data.data(), data.size_s());}
@@ -209,10 +207,10 @@ private:
inline PICout operator <<(PICout c, const PIPeer::PeerInfo::PeerAddress & v) {c.space(); c << "PeerAddress(" << v.address << ", " << v.netmask << ", " << v.ping << ")"; return c;}
inline PICout operator <<(PICout c, const PIPeer::PeerInfo & v) {c.space(); c << "PeerInfo(" << v.name << ", " << v.dist << ", " << v.addresses << ")"; return c;}
inline PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo::PeerAddress & v) {s << v.address << v.netmask << v.ping; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo::PeerAddress & v) {s >> v.address >> v.netmask >> v.ping; return s;}
BINARY_STREAM_WRITE(PIPeer::PeerInfo::PeerAddress) {s << v.address << v.netmask << v.ping; return s;}
BINARY_STREAM_READ (PIPeer::PeerInfo::PeerAddress) {s >> v.address >> v.netmask >> v.ping; return s;}
inline PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v) {s << v.name << v.addresses << v.dist << v.neighbours << v.cnt << v.time; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v) {s >> v.name >> v.addresses >> v.dist >> v.neighbours >> v.cnt >> v.time; return s;}
BINARY_STREAM_WRITE(PIPeer::PeerInfo) {s << v.name << v.addresses << v.dist << v.neighbours << v.cnt << v.time; return s;}
BINARY_STREAM_READ (PIPeer::PeerInfo) {s >> v.name >> v.addresses >> v.dist >> v.neighbours >> v.cnt >> v.time; return s;}
#endif // PIPEER_H

View File

@@ -521,14 +521,14 @@ PIString PISerial::readString(int size, double timeout_ms) {
while (tm_.elapsed_m() < timeout_ms) {
ret = readDevice(td, 1024);
if (ret <= 0) piMinSleep();
else str << PIString((char*)td, ret);
else str += PIString((char*)td, ret);
}
} else {
while (all < size && tm_.elapsed_m() < timeout_ms) {
ret = readDevice(td, size - all);
if (ret <= 0) piMinSleep();
else {
str << PIString((char*)td, ret);
str += PIString((char*)td, ret);
all += ret;
}
}
@@ -537,12 +537,12 @@ PIString PISerial::readString(int size, double timeout_ms) {
} else {
bool br = setOption(BlockingRead, true);
all = readDevice(td, 1);
str << PIString((char*)td, all);
str += PIString((char*)td, all);
while (all < size) {
ret = readDevice(td, size - all);
if (ret <= 0) piMinSleep();
else {
str << PIString((char*)td, ret);
str += PIString((char*)td, ret);
all += ret;
}
}
@@ -862,13 +862,13 @@ bool PISerial::configureDevice(const void * e_main, const void * e_parent) {
PIString PISerial::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << int(inSpeed()) << ":" << dataBitsCount();
ret += path() + ":" + PIString::fromNumber(int(inSpeed())) + ":" + PIString::fromNumber(dataBitsCount());
if (parameters()[ParityControl]) {
if (parameters()[ParityOdd]) ret << ":O";
else ret << ":E";
} else ret << ":N";
if (parameters()[TwoStopBits]) ret << ":2";
else ret << ":1";
if (parameters()[ParityOdd]) ret += ":O";
else ret += ":E";
} else ret += ":N";
if (parameters()[TwoStopBits]) ret += ":2";
else ret += ":1";
return ret;
}

View File

@@ -336,12 +336,12 @@ inline bool operator !=(const PISerial::DeviceInfo & v0, const PISerial::DeviceI
//! \relatesalso PIByteArray
//! \~english Store operator
//! \~russian Оператор сохранения
inline PIByteArray & operator <<(PIByteArray & s, const PISerial::DeviceInfo & v) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
BINARY_STREAM_WRITE(PISerial::DeviceInfo) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
//! \relatesalso PIByteArray
//! \~english Restore operator
//! \~russian Оператор извлечения
inline PIByteArray & operator >>(PIByteArray & s, PISerial::DeviceInfo & v) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
BINARY_STREAM_READ (PISerial::DeviceInfo) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
#endif // PISERIAL_H

View File

@@ -170,7 +170,7 @@ bool PISharedMemory::closeDevice() {
PIString PISharedMemory::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << dsize;
ret += path() + ":" + PIString::fromNumber(dsize);
return ret;
}

View File

@@ -157,7 +157,7 @@ int PISPI::writeDevice(const void * data, int max_size) {
PIString PISPI::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << int(speed()) << ":" << int(bits()) << ":" << (int)parameters();
ret += path() + ":" + PIString::fromNumber((int)speed()) + ":" + PIString::fromNumber((int)bits()) + ":" + PIString::fromNumber((int)parameters());
return ret;
}