git-svn-id: svn://db.shs.com.ru/libs@389 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2018-05-28 11:32:38 +00:00
parent f2581cd605
commit 46d6928ebe
12 changed files with 85 additions and 115 deletions

View File

@@ -7,20 +7,6 @@ CInterface C;
CInterface::CInterface(): Interface(CDType::cdC) { CInterface::CInterface(): Interface(CDType::cdC) {
CONNECTU(core, C_Sended, this, sended);
CONNECTU(core, C_SendFail, this, sendFailed);
CONNECTU(core, C_Received, this, received);
CONNECTU(core, C_ReceiveFail, this, receiveFailed);
}
void CInterface::send() {
core->C_Send();
}
void CInterface::request() {
core->C_Request();
} }

View File

@@ -9,18 +9,10 @@ namespace CDUtils {
class CInterface: public Interface class CInterface: public Interface
{ {
PIOBJECT(CDUtils::CInterface) PIOBJECT_SUBCLASS(CInterface, Interface)
public: public:
CInterface(); CInterface();
EVENT(sended)
EVENT(sendFailed)
EVENT(received)
EVENT(receiveFailed)
EVENT1(keepNamesRequest, bool*, cn)
EVENT_HANDLER(void, send);
EVENT_HANDLER(void, request);
void sendCommand(const CDType & c); void sendCommand(const CDType & c);
void connect(const CDType & c, PIObject * o, Handler eh); void connect(const CDType & c, PIObject * o, Handler eh);
void autoConnect(PIObject * o, const PIString & prefix = PIStringAscii("c_")); void autoConnect(PIObject * o, const PIString & prefix = PIStringAscii("c_"));

View File

@@ -106,6 +106,8 @@ void CDCore::cd_write(CDSection * cd, PIIODevice * d) {
void CDCore::cd_read(CDSection * cd, PIIODevice * d) { void CDCore::cd_read(CDSection * cd, PIIODevice * d) {
PIConfig conf(d, PIIODevice::ReadOnly); PIConfig conf(d, PIIODevice::ReadOnly);
cd->read(&(conf.rootEntry())); cd->read(&(conf.rootEntry()));
if (cd->cd_type_ == CDType::cdX)
x_selected = cd->collectX();
initRoot(cd); initRoot(cd);
K_ChangedGlobal(); K_ChangedGlobal();
/*PIVector<PIIODevice * > ds = connection.allDevices(); /*PIVector<PIIODevice * > ds = connection.allDevices();
@@ -147,6 +149,7 @@ void CDCore::cd_calculate(CDSection * cd) {
void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) { void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) {
if (!cd) return;
PIByteArray ba, sba; PIByteArray ba, sba;
PIIOByteArray iob(&ba, PIIODevice::ReadWrite); PIIOByteArray iob(&ba, PIIODevice::ReadWrite);
cd_write(cd, &iob); cd_write(cd, &iob);
@@ -160,6 +163,33 @@ void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) {
} }
void CDCore::send(CDType::cdT cdt) {
CDPacketType pt = CD_Ping;
switch (cdt) {
case CDType::cdK: pt = CD_KSend; break;
case CDType::cdX: pt = CD_XSend; break;
case CDType::cdC: pt = CD_CSend; break;
default: break;
}
piCoutObj << "send" << typeLetter(cdt);
cd_send(root(cdt), pt);
}
void CDCore::request(CDType::cdT cdt) {
CDPacketType pt = CD_Ping;
switch (cdt) {
case CDType::cdK: pt = CD_KQuery; break;
case CDType::cdX: pt = CD_XQuery; break;
case CDType::cdC: pt = CD_CQuery; break;
default: break;
}
piCoutObj << "request" << typeLetter(cdt);
PIByteArray sba = makeHeader(pt, 0);
sendThreaded(sba);
}
void CDCore::initApp() { void CDCore::initApp() {
init(appConfig(), false); init(appConfig(), false);
} }
@@ -243,19 +273,6 @@ CDCore * CDCore::instance() {
} }
void CDCore::K_Send() {
piCoutObj << "K_Send";
cd_send(&k_, CD_KSend);
}
void CDCore::K_Request() {
piCoutObj << "K_Request";
PIByteArray sba = makeHeader(CD_KQuery, 0);
sendThreaded(sba);
}
void CDUtils::CDCore::K_DirectChange(PIDeque<int> path, PIString value) { void CDUtils::CDCore::K_DirectChange(PIDeque<int> path, PIString value) {
piCoutObj << "K_DirectChange"; piCoutObj << "K_DirectChange";
PacketKDirectChange p; PacketKDirectChange p;
@@ -267,32 +284,6 @@ void CDUtils::CDCore::K_DirectChange(PIDeque<int> path, PIString value) {
} }
void CDCore::X_Send() {
piCoutObj << "X_Send";
cd_send(&x_, CD_XSend);
}
void CDCore::X_Request() {
piCoutObj << "X_Request";
PIByteArray sba = makeHeader(CD_XQuery, 0);
sendThreaded(sba);
}
void CDCore::C_Send() {
piCoutObj << "C_Send";
cd_send(&c_, CD_CSend);
}
void CDCore::C_Request() {
piCoutObj << "C_Request";
PIByteArray sba = makeHeader(CD_CQuery, 0);
sendThreaded(sba);
}
void CDCore::sendThread() { void CDCore::sendThread() {
if (send_data.size_s() < 4) return; if (send_data.size_s() < 4) return;
PacketHeader h; PacketHeader h;
@@ -392,7 +383,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
//piCoutObj << "ping"; //piCoutObj << "ping";
break; break;
case CD_KQuery: case CD_KQuery:
K_Send(); send(CDType::cdK);
break; break;
case CD_KSend: { case CD_KSend: {
piCoutObj << "K received"; piCoutObj << "K received";
@@ -410,7 +401,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
k_[p.path].setValue(p.value); k_[p.path].setValue(p.value);
} break; } break;
case CD_XQuery: case CD_XQuery:
X_Send(); send(CDType::cdX);
break; break;
case CD_XSend: { case CD_XSend: {
piCoutObj << "X received"; piCoutObj << "X received";
@@ -420,6 +411,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
PIString s = PIString::fromUTF8((const char *)x.data()); PIString s = PIString::fromUTF8((const char *)x.data());
PIIOString ios(&s); PIIOString ios(&s);
cd_read(&x_, &ios); cd_read(&x_, &ios);
x_selected = x_.collectX();
X_Received(); X_Received();
} break; } break;
case CD_XRequest: { case CD_XRequest: {
@@ -447,7 +439,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
X_ReceivedX(x_vals); X_ReceivedX(x_vals);
} break; } break;
case CD_CQuery: case CD_CQuery:
C_Send(); send(CDType::cdC);
break; break;
case CD_CSend: { case CD_CSend: {
piCoutObj << "C received"; piCoutObj << "C received";

View File

@@ -36,24 +36,20 @@ public:
EVENT(K_Received) EVENT(K_Received)
EVENT(K_ReceiveFail) EVENT(K_ReceiveFail)
EVENT(K_ChangedGlobal) EVENT(K_ChangedGlobal)
EVENT_HANDLER(void, K_Send);
EVENT_HANDLER(void, K_Request);
EVENT_HANDLER2(void, K_DirectChange, PIDeque<int>, path, PIString, value); EVENT_HANDLER2(void, K_DirectChange, PIDeque<int>, path, PIString, value);
EVENT(X_Sended) EVENT(X_Sended)
EVENT(X_SendFail) EVENT(X_SendFail)
EVENT(X_Received) EVENT(X_Received)
EVENT(X_ReceiveFail) EVENT(X_ReceiveFail)
EVENT(X_ChangedGlobal)
EVENT1(X_ReceivedX, PIVector<PIDeque<int> >, pathes) EVENT1(X_ReceivedX, PIVector<PIDeque<int> >, pathes)
EVENT_HANDLER(void, X_Send);
EVENT_HANDLER(void, X_Request);
EVENT(C_Sended) EVENT(C_Sended)
EVENT(C_SendFail) EVENT(C_SendFail)
EVENT(C_Received) EVENT(C_Received)
EVENT(C_ReceiveFail) EVENT(C_ReceiveFail)
EVENT_HANDLER(void, C_Send); EVENT(C_ChangedGlobal)
EVENT_HANDLER(void, C_Request);
void cd_write (CDSection * cd, PIIODevice * d); void cd_write (CDSection * cd, PIIODevice * d);
void cd_read (CDSection * cd, PIIODevice * d); void cd_read (CDSection * cd, PIIODevice * d);
@@ -61,6 +57,8 @@ public:
void cd_update (CDSection * cd, PIIODevice * d, UpdateModeFlags mode); void cd_update (CDSection * cd, PIIODevice * d, UpdateModeFlags mode);
void cd_calculate(CDSection * cd); void cd_calculate(CDSection * cd);
void cd_send (CDSection * cd, CDPacketType pt, bool direct = false); void cd_send (CDSection * cd, CDPacketType pt, bool direct = false);
void send(CDType::cdT cdt);
void request(CDType::cdT cdt);
void initApp(); void initApp();
void initPult(); void initPult();
void init(const PIString & configuration, bool pult = false); void init(const PIString & configuration, bool pult = false);

View File

@@ -13,6 +13,27 @@ Interface::Interface(CDType::cdT type_) {
//piCoutObj << (void*)this << core; //piCoutObj << (void*)this << core;
file_ = core->typeLetter(type_) + PIStringAscii(".dat"); file_ = core->typeLetter(type_) + PIStringAscii(".dat");
file_size = 0; file_size = 0;
switch (type) {
case CDType::cdK:
CONNECTU(core, K_Sended, this, sended);
CONNECTU(core, K_SendFail, this, sendFailed);
CONNECTU(core, K_Received, this, received);
CONNECTU(core, K_ReceiveFail, this, receiveFailed);
break;
case CDType::cdX:
CONNECTU(core, X_Sended, this, sended);
CONNECTU(core, X_SendFail, this, sendFailed);
CONNECTU(core, X_Received, this, received);
CONNECTU(core, X_ReceiveFail, this, receiveFailed);
break;
case CDType::cdC:
CONNECTU(core, C_Sended, this, sended);
CONNECTU(core, C_SendFail, this, sendFailed);
CONNECTU(core, C_Received, this, received);
CONNECTU(core, C_ReceiveFail, this, receiveFailed);
break;
default: break;
}
} }
@@ -164,3 +185,13 @@ void Interface::writeFile() {
bool Interface::inProgress() { bool Interface::inProgress() {
return core->inProgress(); return core->inProgress();
} }
void Interface::send() {
core->send(type);
}
void Interface::request() {
core->request(type);
}

View File

@@ -50,6 +50,14 @@ public:
void writeFile(); void writeFile();
bool inProgress(); bool inProgress();
EVENT(sended)
EVENT(sendFailed)
EVENT(received)
EVENT(receiveFailed)
EVENT(changedGlobal)
EVENT_HANDLER(void, send);
EVENT_HANDLER(void, request);
protected: protected:
CDCore * core; CDCore * core;
CDSection * s; CDSection * s;

View File

@@ -7,20 +7,6 @@ KInterface K;
KInterface::KInterface(): Interface(CDType::cdK) { KInterface::KInterface(): Interface(CDType::cdK) {
CONNECTU(core, K_Sended, this, sended);
CONNECTU(core, K_SendFail, this, sendFailed);
CONNECTU(core, K_Received, this, received);
CONNECTU(core, K_ReceiveFail, this, receiveFailed);
}
void KInterface::send() {
core->K_Send();
}
void KInterface::request() {
core->K_Request();
} }

View File

@@ -9,17 +9,11 @@ namespace CDUtils {
class KInterface: public Interface class KInterface: public Interface
{ {
PIOBJECT(CDUtils::KInterface) PIOBJECT_SUBCLASS(KInterface, Interface)
public: public:
KInterface(); KInterface();
EVENT(sended)
EVENT(sendFailed)
EVENT(received)
EVENT(receiveFailed)
EVENT1(keepNamesRequest, bool*, kn) EVENT1(keepNamesRequest, bool*, kn)
EVENT_HANDLER(void, send);
EVENT_HANDLER(void, request);
void directChange(const CDType & k, double v); void directChange(const CDType & k, double v);

View File

@@ -440,6 +440,8 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
d->write(l.toUTF8()); d->write(l.toUTF8());
l.clear(); l << ck.index() << ".avg = " << ck.avg() << " #n " << "\n"; l.clear(); l << ck.index() << ".avg = " << ck.avg() << " #n " << "\n";
d->write(l.toUTF8()); d->write(l.toUTF8());
l.clear(); l << ck.index() << ".sel = " << (ck.isSelectedX() ? "1" : "0") << " #n " << "\n";
d->write(l.toUTF8());
break; break;
case CDType::cdC: case CDType::cdC:
l.clear(); l << ck.index() << ".name = " << ck.name() << " #s " << ck.comment() << " \n"; l.clear(); l << ck.index() << ".name = " << ck.name() << " #s " << ck.comment() << " \n";
@@ -495,6 +497,7 @@ void CDSection::read(const void * ep) {
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_); c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_);
c.setXMode((CDType::XMode)e->getValue("mode", int(CDType::X_Current)).value().toInt()); c.setXMode((CDType::XMode)e->getValue("mode", int(CDType::X_Current)).value().toInt());
c.setAvg((CDType::XMode)e->getValue("avg", 1).value().toInt()); c.setAvg((CDType::XMode)e->getValue("avg", 1).value().toInt());
c.x_enabled = e->getValue("sel", false).value().toBool();
break; break;
case CDType::cdC: case CDType::cdC:
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_); c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_);

View File

@@ -7,24 +7,10 @@ XInterface X;
XInterface::XInterface(): Interface(CDType::cdX) { XInterface::XInterface(): Interface(CDType::cdX) {
CONNECTU(core, X_Sended, this, sended);
CONNECTU(core, X_SendFail, this, sendFailed);
CONNECTU(core, X_Received, this, received);
CONNECTU(core, X_ReceiveFail, this, receiveFailed);
CONNECTU(core, X_ReceivedX, this, receivedX); CONNECTU(core, X_ReceivedX, this, receivedX);
} }
void XInterface::send() {
core->X_Send();
}
void XInterface::request() {
core->X_Request();
}
void XInterface::setEnabled(const CDType & x, bool en) { void XInterface::setEnabled(const CDType & x, bool en) {
core->x_mutex.lock(); core->x_mutex.lock();
CDType & t((*s)[x.path()]); CDType & t((*s)[x.path()]);

View File

@@ -9,17 +9,11 @@ namespace CDUtils {
class XInterface: public Interface class XInterface: public Interface
{ {
PIOBJECT(CDUtils::XInterface) PIOBJECT_SUBCLASS(XInterface, Interface)
public: public:
XInterface(); XInterface();
EVENT(sended)
EVENT(sendFailed)
EVENT(received)
EVENT(receiveFailed)
EVENT1(keepNamesRequest, bool*, xn) EVENT1(keepNamesRequest, bool*, xn)
EVENT_HANDLER(void, send);
EVENT_HANDLER(void, request);
EVENT1(receivedX, PIVector<PIDeque<int> >, pathes) EVENT1(receivedX, PIVector<PIDeque<int> >, pathes)
void enable(const CDType & x) {setEnabled(x, true);} void enable(const CDType & x) {setEnabled(x, true);}

View File

@@ -13,7 +13,7 @@
#include <cmath> #include <cmath>
inline QByteArray QString2QByteArray(const QString & string) {return qUncompress(QByteArray::fromBase64(string.toLatin1()));} inline QByteArray QString2QByteArray(const QString & string) {return string.isEmpty() ? QByteArray() : qUncompress(QByteArray::fromBase64(string.toLatin1()));}
int QString2int(const QString & string); int QString2int(const QString & string);
inline QColor QString2QColor(const QString & string) {return (string.left(1) == "#" ? QColor(string.right(string.length() - 1).toInt(0, 16)) : QColor(QString2int(string)));} inline QColor QString2QColor(const QString & string) {return (string.left(1) == "#" ? QColor(string.right(string.length() - 1).toInt(0, 16)) : QColor(QString2int(string)));}
QRect QString2QRect(const QString & string); QRect QString2QRect(const QString & string);
@@ -24,7 +24,7 @@ QPointF QString2QPointF(const QString & string);
inline QString QColor2QString(const QColor & color) {QString s = color.name(); return "0x" + QString::number(color.alpha(), 16).rightJustified(2, '0') + s.right(s.length() - 1);} inline QString QColor2QString(const QColor & color) {QString s = color.name(); return "0x" + QString::number(color.alpha(), 16).rightJustified(2, '0') + s.right(s.length() - 1);}
inline QString QPoint2QString(const QPoint & point) {return QString::number(point.x()) + ";" + QString::number(point.y());} inline QString QPoint2QString(const QPoint & point) {return QString::number(point.x()) + ";" + QString::number(point.y());}
inline QString QPointF2QString(const QPointF & point) {return QString::number(point.x()) + ";" + QString::number(point.y());} inline QString QPointF2QString(const QPointF & point) {return QString::number(point.x()) + ";" + QString::number(point.y());}
inline QString QByteArray2QString(const QByteArray & array) {return QString(qCompress(array, 9).toBase64());} inline QString QByteArray2QString(const QByteArray & array) {return array.isEmpty() ? QString() : QString(qCompress(array, 9).toBase64());}
QString QRect2QString(const QRect & rect); QString QRect2QString(const QRect & rect);
QString QRectF2QString(const QRectF & rect); QString QRectF2QString(const QRectF & rect);