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

This commit is contained in:
2018-05-23 12:18:47 +00:00
parent 1f81d2dadd
commit e76a5fde23
16 changed files with 276 additions and 89 deletions

View File

@@ -182,7 +182,14 @@ void CDCore::init(const PIString & configuration, bool pult) {
void CDCore::startX(double freq) {
x_timer.start(1000. / piMaxd(freq, 0.01));
piCout << "start x" << x_timer.isRunning() << freq;
if (!x_timer.isRunning())
x_timer.start(1000. / piMaxd(freq, 0.01));
}
void CDCore::stopX() {
x_timer.stop();
}
@@ -314,24 +321,28 @@ void CDCore::sendThread() {
void CDCore::xTimerTick() {
x_mutex.lock();
//piCout << "x tick" << x_pult_side;
PIByteArray ba;
x_mutex.lock();
if (x_pult_side) {
ba = makeHeader(CD_XRequest, 0);
if (need_rebuild_x) {
x_selected = x_.collectX();
//piCout << "collectX" << x_selected.size();
need_rebuild_x = false;
}
ba << x_selected;
//piCout << "x pult send" << x_selected.size();
} else {
ba = makeHeader(CD_XValues, 0);
ba << x_selected;
piForeachC (PIDeque<int> & p, x_selected) {
x_[p].writeX(ba);
}
//piCout << "x app" << x_selected.size();
}
x_mutex.unlock();
connection.writeByName("cd", ba);
sendDirect(ba);
}
@@ -393,10 +404,26 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
ba >> p;
k_[p.path].setValue(p.value);
} break;
case CD_XQuery:
X_Send();
break;
case CD_XSend: {
piCoutObj << "X received";
PIByteArray x;
ba >> x;
x << uchar(0);
PIString s = PIString::fromUTF8((const char *)x.data());
PIIOString ios(&s);
cd_read(&x_, &ios);
X_Received();
} break;
case CD_XRequest: {
if (x_pult_side) break;
//break;
x_mutex.lock();
x_selected.clear();
ba >> x_selected;
//piCout << "X req" << x_selected.size();
x_.setSelectedX(false);
piForeachC (PIDeque<int> & p, x_selected) {
x_[p].x_enabled = true;
@@ -404,12 +431,14 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
x_mutex.unlock();
} break;
case CD_XValues: {
if (!x_pult_side) break;
x_mutex.lock();
x_selected.clear();
ba >> x_selected;
piForeachC (PIDeque<int> & p, x_selected) {
PIVector<PIDeque<int> > x_vals;
ba >> x_vals;
piForeachC (PIDeque<int> & p, x_vals) {
x_[p].readX(ba);
}
X_ReceivedX(x_vals); /// WARNING! under mutex
x_mutex.unlock();
} break;
case CD_CQuery:

View File

@@ -44,7 +44,7 @@ public:
EVENT(X_SendFail)
EVENT(X_Received)
EVENT(X_ReceiveFail)
EVENT(X_ChangedGlobal)
EVENT1(X_ReceivedX, PIVector<PIDeque<int> >, pathes)
EVENT_HANDLER(void, X_Send);
EVENT_HANDLER(void, X_Request);
@@ -52,7 +52,6 @@ public:
EVENT(C_SendFail)
EVENT(C_Received)
EVENT(C_ReceiveFail)
EVENT(C_ChangedGlobal)
EVENT_HANDLER(void, C_Send);
EVENT_HANDLER(void, C_Request);
@@ -66,6 +65,7 @@ public:
void initPult();
void init(const PIString & configuration, bool pult = false);
void startX(double freq = 20.);
void stopX();
void sendCommand(const CDType & c);
void registerCHandler(const CDType & c, PIObject * o, Handler h);
bool inProgress() {return sendt.isRunning();}

View File

@@ -125,14 +125,16 @@ void CDType::readX(PIByteArray & ba) {
switch ((XMode)t) {
case X_Current:
ba >> value_d;
value_i = value_d;
value_b = value_d > 0.;
break;
case X_All_Avg:
ba >> history;
if (!history.isEmpty())
value_d = history.back();
break;
default: break;
}
value_i = value_d;
value_b = value_d > 0.;
}

View File

@@ -11,6 +11,7 @@ XInterface::XInterface(): Interface(CDType::cdX) {
CONNECTU(core, X_SendFail, this, sendFailed);
CONNECTU(core, X_Received, this, received);
CONNECTU(core, X_ReceiveFail, this, receiveFailed);
CONNECTU(core, X_ReceivedX, this, receivedX);
}
@@ -25,15 +26,39 @@ void XInterface::request() {
void XInterface::setEnabled(const CDType & x, bool en) {
CDType & t((*s)[x.path()]);
if (t.cd_type() != CDType::cdX) return;
core->x_mutex.lock();
CDType & t((*s)[x.path()]);
if (t.cd_type() != CDType::cdX) {
core->x_mutex.unlock();
return;
}
t.x_enabled = en;
//piCout << t << "x_enabled" << en;
core->need_rebuild_x = true;
core->x_mutex.unlock();
}
PIVector<PIDeque<int> > XInterface::enabledList() const {
return CDCore::instance()->x_selected;
}
void XInterface::lock() {
CDCore::instance()->x_mutex.lock();
}
void XInterface::unlock() {
CDCore::instance()->x_mutex.unlock();
}
void XInterface::start(double freq) {
core->startX(freq);
}
void XInterface::stop() {
core->stopX();
}

View File

@@ -20,13 +20,18 @@ public:
EVENT1(keepNamesRequest, bool*, xn)
EVENT_HANDLER(void, send);
EVENT_HANDLER(void, request);
EVENT1(receivedX, PIVector<PIDeque<int> >, pathes)
void enable(const CDType & x) {setEnabled(x, true);}
void disable(const CDType & x) {setEnabled(x, false);}
void setEnabled(const CDType & x, bool en);
void setDisabled(const CDType & x, bool dis) {setEnabled(x, !dis);}
PIVector<PIDeque<int> > enabledList() const;
void lock();
void unlock();
void start(double freq = 20.);
void stop();
};

View File

@@ -15,9 +15,10 @@ class Core : public PIObject
Core() {
CDCore::instance()->initApp();
// piCout << "testCore";
CONNECTU(&t, tickEvent, this, timerDone);
CONNECTU(&timer, tickEvent, this, timerDone);
CONNECTU(&X, received, this, xrecv);
CONNECTU(&C, received, this, crecv);
t.start(1000);
t = 0.;
}
void load() {
@@ -48,6 +49,11 @@ class Core : public PIObject
}
void test() {
X.lock();
X[KD::Frequency] = 100;
X.section(KD::Spectrometer)[KD::Temperature_default] = sin(t);
t += 0.01;
X.unlock();
/*piCout << "count" << K.count();
piCout << K[First];
piCout << K[Second];*/
@@ -59,6 +65,11 @@ class Core : public PIObject
C.connect(C.section(KD::Logs).section(KD::Spec).section(KD::Formats)[KD::Binary], this, HANDLER(cmd));
C.autoConnect(this);
}
EVENT_HANDLER(void, xrecv) {
piCout << "received x";
if (!timer.isRunning()) timer.start(10);
X.start();
}
EVENT_HANDLER(void, timerDone) {test();}
EVENT_HANDLER(void, cmd) {piCout << "command cmd";}
EVENT_HANDLER(void, c_Pause) {piCout << "command pause";}
@@ -66,7 +77,8 @@ class Core : public PIObject
private:
PIFile rf;
PITimer t;
PITimer timer;
double t;
};