code format
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
#include "cdutils_core.h"
|
||||
|
||||
#include "cdutils_parser.h"
|
||||
#include "piconfig.h"
|
||||
#include "pifile.h"
|
||||
#include "piiobytearray.h"
|
||||
#include "piiostring.h"
|
||||
#include "pifile.h"
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
const char CDCore::app_config[] =
|
||||
"include = cd_ip.conf\n\
|
||||
const char CDCore::app_config[] = "include = cd_ip.conf\n\
|
||||
port_rec = 2\n\
|
||||
port_send = 1\n\
|
||||
[connection]\n\
|
||||
@@ -17,8 +17,7 @@ const char CDCore::app_config[] =
|
||||
connectionmodel = AAAM2Xja7VXLTttAFD12QpsikKjUSixYlLbKEpIUtVIlVEfqhk2FWuiGRRolUYtoHgrmpYiv6IItf8AveMMH9E/YsG6Ph3sde5hGoQoblLGuPHfunTPjc49nADxDA110+LTYC7FrPCAPeAO+vZu+aX7c/8PGd45WCJC0OGcfT6FDnmfSTPtwhZFt3HjgDs/Qtu5jPbZHtI/x50XfIzMQbdwEolbg9INP4ku++myPaUtCHYRaT2j1ldIh3VP60/Qff8vSfXLu9BP6JX9K/0TVH6jqVe22P1X/fao/oddWu/paDs1vBf9Jv/EZ91clbyHqv7BL6sscDOd4v4WTqs6jzaHGJ8QJerxlpJSpdZ7IWFJvDW7I2JxZqIM62k6A57RZmMQGmlyrxdV+WGBnmR01mXPI267hBKwp4FeBeo9VPtssxyb7rzHg1B7T9nCMU45U8BZlWuVWtIcD/CRGOqtsbW09851tXsHN0UTlLIAdASjSXnLyLn+H7L2+xbGYvC63Ezqg543egkLmn8qnRF6USbM4Qp9godkhzI777Ne5bCIt/5UtGz2o/yGby0nKpjqmbOa1ynkjmyzIrzvIZUeBPjvlUmbh32EFJbGyJZhR8YcvlS+3TpjhqeWSyvUkpbI9plSWtcKLcsK05beOJVEnhaEFfHEH+RwpeMcpn1JKGqWMNOL+G6wZyahlpdVOtufKfbDS+guLke9O\n\
|
||||
";
|
||||
|
||||
const char CDCore::pult_config[] =
|
||||
"include = cd_ip.conf\n\
|
||||
const char CDCore::pult_config[] = "include = cd_ip.conf\n\
|
||||
port_rec = 1\n\
|
||||
port_send = 2\n\
|
||||
[connection]\n\
|
||||
@@ -55,8 +54,6 @@ __Core_Initializer__::~__Core_Initializer__() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
CDCore::CDCore() {
|
||||
setName("CDCore");
|
||||
x_timer.setName("__S__.CDCore.x_timer");
|
||||
@@ -67,10 +64,10 @@ CDCore::CDCore() {
|
||||
connection.configureFromString(&s);
|
||||
connection.start();*/
|
||||
need_rebuild_x = x_pult_side = false;
|
||||
k_.cd_type_ = CDType::cdK;
|
||||
x_.cd_type_ = CDType::cdX;
|
||||
c_.cd_type_ = CDType::cdC;
|
||||
m_.cd_type_ = CDType::cdM;
|
||||
k_.cd_type_ = CDType::cdK;
|
||||
x_.cd_type_ = CDType::cdX;
|
||||
c_.cd_type_ = CDType::cdC;
|
||||
m_.cd_type_ = CDType::cdM;
|
||||
initRoot(&k_);
|
||||
initRoot(&x_);
|
||||
initRoot(&c_);
|
||||
@@ -89,7 +86,7 @@ CDCore::CDCore() {
|
||||
k_.section(11)[3] = KType(3, "1", "1", "88");
|
||||
k_.section(11)[4] = KType(4, "0", "0", "88");
|
||||
k_.section(11)[6] = KType(6, "0", "0", "88");*/
|
||||
//piCout << s;
|
||||
// piCout << s;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,14 +107,13 @@ void CDCore::cd_write(CDSection * cd, PIIODevice * d) {
|
||||
void CDCore::cd_read(CDSection * cd, PIIODevice * d) {
|
||||
PIConfig conf(d, PIIODevice::ReadOnly);
|
||||
cd->read(&(conf.rootEntry()));
|
||||
if (cd->cd_type_ == CDType::cdX)
|
||||
x_selected = cd->collectX();
|
||||
if (cd->cd_type_ == CDType::cdX) x_selected = cd->collectX();
|
||||
initRoot(cd);
|
||||
raiseChangedGlobal(cd->cd_type_);
|
||||
/*PIVector<PIIODevice * > ds = connection.allDevices();
|
||||
piForeach(PIIODevice * d, ds) {
|
||||
if (d)
|
||||
piCoutObj << d->constructFullPath() << d->isOpened();
|
||||
if (d)
|
||||
piCoutObj << d->constructFullPath() << d->isOpened();
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -134,12 +130,12 @@ void CDCore::cd_update(CDSection * cd, PIIODevice * d, UpdateModeFlags mode) {
|
||||
cd_parse(cd, d);
|
||||
/*bool kn = true;
|
||||
if (!ucd.isEmpty())
|
||||
if (!ucd.isSameStructure(k_)) {
|
||||
piCout << "ask for save names";
|
||||
K_KeepNamesRequest(&kn);
|
||||
}*/
|
||||
if (!ucd.isSameStructure(k_)) {
|
||||
piCout << "ask for save names";
|
||||
K_KeepNamesRequest(&kn);
|
||||
}*/
|
||||
ucd.update(*cd, mode);
|
||||
//piCout << k_.count() << ucd.count();
|
||||
// piCout << k_.count() << ucd.count();
|
||||
*cd = ucd;
|
||||
initRoot(cd);
|
||||
raiseChangedGlobal(cd->cd_type_);
|
||||
@@ -157,7 +153,7 @@ void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) {
|
||||
PIByteArray ba, sba;
|
||||
PIIOByteArray iob(&ba, PIIODevice::ReadWrite);
|
||||
cd_write(cd, &iob);
|
||||
//piCoutObj << PIString(ba);
|
||||
// piCoutObj << PIString(ba);
|
||||
sba = makeHeader(pt, 0);
|
||||
sba << ba;
|
||||
if (direct)
|
||||
@@ -208,7 +204,7 @@ void CDCore::initPult() {
|
||||
|
||||
void CDCore::init(const PIString & configuration, bool pult) {
|
||||
PIString c = configuration;
|
||||
//piCoutObj << "init" << c;
|
||||
// piCoutObj << "init" << c;
|
||||
connection.stop();
|
||||
connection.removeAllDevices();
|
||||
connection.configureFromString(&c);
|
||||
@@ -230,9 +226,8 @@ void CDCore::release() {
|
||||
|
||||
|
||||
void CDCore::startX(double freq) {
|
||||
//piCout << "start x" << x_timer.isRunning() << freq;
|
||||
if (!x_timer.isRunning())
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -242,7 +237,7 @@ void CDCore::stopX() {
|
||||
|
||||
|
||||
void CDCore::sendCommand(const CDType & c) {
|
||||
//piCoutObj << "C_sendCommand" << c;
|
||||
// piCoutObj << "C_sendCommand" << c;
|
||||
PIByteArray sba = makeHeader(CD_Command, 0);
|
||||
sba << c.path();
|
||||
sendDirect(sba);
|
||||
@@ -252,7 +247,7 @@ void CDCore::sendCommand(const CDType & c) {
|
||||
void CDCore::registerCHandler(const CDType & c, PIObject * o, Handler h) {
|
||||
PIString sp = pathToString(c.path());
|
||||
if (sp.isEmpty() || !h) return;
|
||||
//piCout << "register" << sp;
|
||||
// piCout << "register" << sp;
|
||||
c_handlers[sp] = OHPair(o, h);
|
||||
}
|
||||
|
||||
@@ -298,20 +293,20 @@ CDCore * CDCore::instance() {
|
||||
|
||||
bool CDCore::destroy() {
|
||||
if (!__Core_Initializer__::__instance__) return false;
|
||||
// piCout << "delete Core ...";
|
||||
// piCout << "delete Core ...";
|
||||
delete __Core_Initializer__::__instance__;
|
||||
// piCout << "delete Core ok";
|
||||
// piCout << "delete Core ok";
|
||||
__Core_Initializer__::__instance__ = 0;
|
||||
__Core_Initializer__::count_ = 0;
|
||||
__Core_Initializer__::count_ = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CDUtils::CDCore::K_DirectChange(PIDeque<int> path, PIString value) {
|
||||
// piCoutObj << "K_DirectChange";
|
||||
// piCoutObj << "K_DirectChange";
|
||||
PacketKDirectChange p;
|
||||
p.path = path;
|
||||
p.value = value;
|
||||
p.path = path;
|
||||
p.value = value;
|
||||
PIByteArray sba = makeHeader(CD_KDirectChange, 0);
|
||||
sba << p;
|
||||
sendDirect(sba);
|
||||
@@ -325,29 +320,37 @@ void CDCore::sendThread() {
|
||||
bool ok = datatr.send(send_data);
|
||||
switch (h.type) {
|
||||
case CD_KSend:
|
||||
if (ok) K_Sended();
|
||||
else K_SendFail();
|
||||
if (ok)
|
||||
K_Sended();
|
||||
else
|
||||
K_SendFail();
|
||||
break;
|
||||
case CD_KQuery:
|
||||
if (!ok) K_ReceiveFail();
|
||||
break;
|
||||
case CD_XSend:
|
||||
if (ok) X_Sended();
|
||||
else X_SendFail();
|
||||
if (ok)
|
||||
X_Sended();
|
||||
else
|
||||
X_SendFail();
|
||||
break;
|
||||
case CD_XQuery:
|
||||
if (!ok) X_ReceiveFail();
|
||||
break;
|
||||
case CD_CSend:
|
||||
if (ok) C_Sended();
|
||||
else C_SendFail();
|
||||
if (ok)
|
||||
C_Sended();
|
||||
else
|
||||
C_SendFail();
|
||||
break;
|
||||
case CD_CQuery:
|
||||
if (!ok) C_ReceiveFail();
|
||||
break;
|
||||
case CD_MSend:
|
||||
if (ok) M_Sended();
|
||||
else M_SendFail();
|
||||
if (ok)
|
||||
M_Sended();
|
||||
else
|
||||
M_SendFail();
|
||||
break;
|
||||
case CD_MQuery:
|
||||
if (!ok) M_ReceiveFail();
|
||||
@@ -358,25 +361,25 @@ void CDCore::sendThread() {
|
||||
|
||||
|
||||
void CDCore::xTimerTick() {
|
||||
//piCout << "x tick" << x_pult_side;
|
||||
// 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();
|
||||
x_selected = x_.collectX();
|
||||
// piCout << "collectX" << x_selected.size();
|
||||
need_rebuild_x = false;
|
||||
}
|
||||
ba << x_selected;
|
||||
//piCout << "x pult send" << x_selected.size();
|
||||
// piCout << "x pult send" << x_selected.size();
|
||||
} else {
|
||||
ba = makeHeader(CD_XValues, 0);
|
||||
ba << x_selected;
|
||||
piForeachC (PIDeque<int> & p, x_selected) {
|
||||
piForeachC(PIDeque<int> & p, x_selected) {
|
||||
x_[p].writeX(ba);
|
||||
}
|
||||
//piCout << "x app" << x_selected.size();
|
||||
// piCout << "x app" << x_selected.size();
|
||||
}
|
||||
x_mutex.unlock();
|
||||
sendDirect(ba);
|
||||
@@ -385,7 +388,7 @@ void CDCore::xTimerTick() {
|
||||
|
||||
void CDCore::piCoutFinished(int id, PIString * buffer) {
|
||||
if (!buffer || !(id == 1)) return;
|
||||
PIString sp = buffer->takeRange("[", "]");
|
||||
PIString sp = buffer->takeRange("[", "]");
|
||||
PIDeque<int> p = CDCore::stringToPath(sp);
|
||||
sendMessage(m_[p], Log, *buffer);
|
||||
delete buffer;
|
||||
@@ -393,7 +396,7 @@ void CDCore::piCoutFinished(int id, PIString * buffer) {
|
||||
|
||||
|
||||
void CDCore::initRoot(CDSection * r) {
|
||||
r->name = "__root__";
|
||||
r->name = "__root__";
|
||||
r->alias = "root";
|
||||
r->makePath();
|
||||
r->calculate();
|
||||
@@ -402,9 +405,10 @@ void CDCore::initRoot(CDSection * r) {
|
||||
|
||||
PIByteArray CDCore::makeHeader(CDPacketType type, int session_id) const {
|
||||
PacketHeader h;
|
||||
h.type = type;
|
||||
h.type = type;
|
||||
h.session_id = session_id;
|
||||
PIByteArray ret; ret << h;
|
||||
PIByteArray ret;
|
||||
ret << h;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -428,13 +432,11 @@ void CDCore::sendThreaded(PIByteArray & ba) {
|
||||
void CDCore::procReceivedPacket(PIByteArray & ba) {
|
||||
PacketHeader h;
|
||||
ba >> h;
|
||||
switch(h.type) {
|
||||
switch (h.type) {
|
||||
case CD_Ping:
|
||||
//piCoutObj << "ping";
|
||||
break;
|
||||
case CD_KQuery:
|
||||
send(CDType::cdK);
|
||||
// piCoutObj << "ping";
|
||||
break;
|
||||
case CD_KQuery: send(CDType::cdK); break;
|
||||
case CD_KSend: {
|
||||
PIByteArray k;
|
||||
ba >> k;
|
||||
@@ -444,15 +446,13 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
|
||||
cd_read(&k_, &ios);
|
||||
K_Received();
|
||||
piCoutObj << "K received";
|
||||
} break;
|
||||
} break;
|
||||
case CD_KDirectChange: {
|
||||
PacketKDirectChange p;
|
||||
ba >> p;
|
||||
k_[p.path].setValue(p.value);
|
||||
} break;
|
||||
case CD_XQuery:
|
||||
send(CDType::cdX);
|
||||
break;
|
||||
} break;
|
||||
case CD_XQuery: send(CDType::cdX); break;
|
||||
case CD_XSend: {
|
||||
PIByteArray x;
|
||||
ba >> x;
|
||||
@@ -463,34 +463,32 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
|
||||
x_selected = x_.collectX();
|
||||
X_Received();
|
||||
piCoutObj << "X received";
|
||||
} break;
|
||||
} break;
|
||||
case CD_XRequest: {
|
||||
if (x_pult_side) break;
|
||||
//break;
|
||||
// break;
|
||||
x_mutex.lock();
|
||||
x_selected.clear();
|
||||
ba >> x_selected;
|
||||
//piCout << "X req" << x_selected.size();
|
||||
// piCout << "X req" << x_selected.size();
|
||||
x_.setSelectedX(false);
|
||||
piForeachC (PIDeque<int> & p, x_selected) {
|
||||
piForeachC(PIDeque<int> & p, x_selected) {
|
||||
x_[p].x_enabled = true;
|
||||
}
|
||||
x_mutex.unlock();
|
||||
} break;
|
||||
} break;
|
||||
case CD_XValues: {
|
||||
if (!x_pult_side) break;
|
||||
PIVector<PIDeque<int> > x_vals;
|
||||
PIVector<PIDeque<int>> x_vals;
|
||||
ba >> x_vals;
|
||||
x_mutex.lock();
|
||||
piForeachC (PIDeque<int> & p, x_vals) {
|
||||
piForeachC(PIDeque<int> & p, x_vals) {
|
||||
x_[p].readX(ba);
|
||||
}
|
||||
x_mutex.unlock();
|
||||
X_ReceivedX(x_vals);
|
||||
} break;
|
||||
case CD_CQuery:
|
||||
send(CDType::cdC);
|
||||
break;
|
||||
} break;
|
||||
case CD_CQuery: send(CDType::cdC); break;
|
||||
case CD_CSend: {
|
||||
piCoutObj << "C received";
|
||||
PIByteArray c;
|
||||
@@ -500,20 +498,18 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
|
||||
PIIOString ios(&s);
|
||||
cd_read(&c_, &ios);
|
||||
C_Received();
|
||||
} break;
|
||||
} break;
|
||||
case CD_Command: {
|
||||
piCoutObj << "C command";
|
||||
PIDeque<int> p;
|
||||
ba >> p;
|
||||
if (p.isEmpty()) return;
|
||||
PIString sp = pathToString(p);
|
||||
OHPair h = c_handlers.value(sp, OHPair(0, 0));
|
||||
//piCoutObj << "found" << sp << h.first;
|
||||
OHPair h = c_handlers.value(sp, OHPair(0, 0));
|
||||
// piCoutObj << "found" << sp << h.first;
|
||||
if (h.first && h.second) h.second(h.first);
|
||||
} break;
|
||||
case CD_MQuery:
|
||||
send(CDType::cdM);
|
||||
break;
|
||||
} break;
|
||||
case CD_MQuery: send(CDType::cdM); break;
|
||||
case CD_MSend: {
|
||||
piCoutObj << "M received";
|
||||
PIByteArray c;
|
||||
@@ -523,7 +519,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
|
||||
PIIOString ios(&s);
|
||||
cd_read(&m_, &ios);
|
||||
M_Received();
|
||||
} break;
|
||||
} break;
|
||||
case CD_Message: {
|
||||
PIDeque<int> p;
|
||||
ba >> p;
|
||||
@@ -532,10 +528,10 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
|
||||
int t = 0;
|
||||
PIString msg;
|
||||
ba >> t >> msg;
|
||||
//piCoutObj << "found" << sp << h.first;
|
||||
//piCoutObj << "M message invoke";
|
||||
// piCoutObj << "found" << sp << h.first;
|
||||
// piCoutObj << "M message invoke";
|
||||
M_Message(p, t, msg);
|
||||
} break;
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -565,19 +561,19 @@ PIString CDCore::pathToString(const PIDeque<int> & p) {
|
||||
PIDeque<int> CDCore::stringToPath(const PIString & p) {
|
||||
PIDeque<int> ret;
|
||||
PIStringList sl = p.split(".");
|
||||
piForeachC (PIString & s, sl)
|
||||
piForeachC(PIString & s, sl)
|
||||
ret << s.toInt();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
//piCoutObj << "dataReceived" << from << data.size();
|
||||
// piCoutObj << "dataReceived" << from << data.size();
|
||||
PIIODevice * d = connection.deviceByName("cd");
|
||||
if (d && d == connection.deviceByFullPath(from)) {
|
||||
if (data.size() >= sizeof(4)) {
|
||||
PIByteArray ba = data;
|
||||
uchar header = ba.take_front();
|
||||
uchar header = ba.take_front();
|
||||
if (header == header_transfer) {
|
||||
datatr.received(ba);
|
||||
}
|
||||
@@ -592,7 +588,7 @@ void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & da
|
||||
void CDCore::dtSendRequest(PIByteArray & data) {
|
||||
data.push_front(header_transfer);
|
||||
connection.writeByName("cd", data);
|
||||
//piCoutObj << "send" << data.size() << ret;
|
||||
// piCoutObj << "send" << data.size() << ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -601,4 +597,3 @@ void CDCore::dtReceiveFinished(bool ok) {
|
||||
PIByteArray ba = datatr.data();
|
||||
procReceivedPacket(ba);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user