169 lines
5.5 KiB
C++
169 lines
5.5 KiB
C++
#include "cdutils_core.h"
|
|
#include "cdutils_k_parser.h"
|
|
#include "piconfig.h"
|
|
#include "cdutils_protocol.h"
|
|
#include "piiodevice.h"
|
|
#include "piiostring.h"
|
|
#include "pifile.h"
|
|
|
|
using namespace CDUtils;
|
|
|
|
const char CDCore::app_config[] =
|
|
"include = cd_ip.conf\n\
|
|
port_rec = 2\n\
|
|
port_send = 1\n\
|
|
[connection]\n\
|
|
device.cd = eth://UDP:127.0.0.1:2616${port_rec}:127.0.0.1:2616${port_send} #s\n\
|
|
device.cd.disconnectTimeout = 3.00000000 #f\n\
|
|
device.cd_eth = eth://UDP:${ip_app}:2616${port_rec}:${ip_pult}:2616${port_send} #s\n\
|
|
device.cd_eth.disconnectTimeout = 3.00000000 #f\n\
|
|
device.cd_mcast = eth://UDP:0.0.0.0:2616${port_rec}:234.1.1.1:2616${port_send}:mcast:234.1.1.1 #s\n\
|
|
device.cd_mcast.disconnectTimeout = 3.00000000 #f\n\
|
|
channel.0.from = cd_eth #s\n\
|
|
channel.0.to = cd #s\n\
|
|
channel.1.from = cd_mcast #s\n\
|
|
channel.1.to = cd #s\n\
|
|
[]\n\
|
|
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\
|
|
port_rec = 1\n\
|
|
port_send = 2\n\
|
|
[connection]\n\
|
|
device.cd = eth://UDP:127.0.0.1:2616${port_rec}:127.0.0.1:2616${port_send} #s\n\
|
|
device.cd.disconnectTimeout = 3.00000000 #f\n\
|
|
device.cd_eth = eth://UDP:${ip_app}:2616${port_rec}:${ip_pult}:2616${port_send} #s\n\
|
|
device.cd_eth.disconnectTimeout = 3.00000000 #f\n\
|
|
device.cd_mcast = eth://UDP:0.0.0.0:2616${port_rec}:234.1.1.1:2616${port_send}:mcast:234.1.1.1 #s\n\
|
|
device.cd_mcast.disconnectTimeout = 3.00000000 #f\n\
|
|
channel.0.from = cd_eth #s\n\
|
|
channel.0.to = cd #s\n\
|
|
channel.1.from = cd_mcast #s\n\
|
|
channel.1.to = cd #s\n\
|
|
[]\n\
|
|
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\
|
|
";
|
|
|
|
|
|
int __Core_Initializer__::count_(0);
|
|
CDCore * __Core_Initializer__::__instance__(0);
|
|
|
|
|
|
__Core_Initializer__::__Core_Initializer__() {
|
|
count_++;
|
|
//piCout << "try create Core" << count_;
|
|
if (count_ > 1) return;
|
|
//piCout << "create Core";
|
|
__instance__ = new CDCore();
|
|
}
|
|
|
|
|
|
__Core_Initializer__::~__Core_Initializer__() {
|
|
count_--;
|
|
//piCout << "try delete Core" << count_;
|
|
if (count_ > 0) return;
|
|
//piCout << "delete Core";
|
|
if (__instance__ != 0) {
|
|
delete __instance__;
|
|
__instance__ = 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
CDCore::CDCore(const char * conf) {
|
|
CONNECTU(&connection, dataReceivedEvent, this, dataReceived);
|
|
PIString s(conf);
|
|
connection.configureFromString(&s);
|
|
datatr.setPacketSize(960);
|
|
connection.start();
|
|
|
|
/*k_[1] = KType(1, "123", "120+3", "comment");
|
|
k_[2] = KType(2, "1", "2", "comm");
|
|
k_[4] = KType(4, "-0.6", "-6/10", "mment");
|
|
k_.section(10)[5] = KType(5, "8", "2*2*2", "88");
|
|
k_.section(10).section(50)[100] = KType(100, "8", "2*2*2", "88");
|
|
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;
|
|
}
|
|
|
|
|
|
void CDCore::k_rec(const PIByteArray & data) {
|
|
|
|
}
|
|
|
|
|
|
void CDCore::x_rec(const PIByteArray & data) {
|
|
|
|
}
|
|
|
|
|
|
void CDCore::c_rec(const PIByteArray & data) {
|
|
|
|
}
|
|
|
|
|
|
void CDCore::k_write(PIIODevice * d) {
|
|
k_.write(d, PIString());
|
|
}
|
|
|
|
|
|
void CDCore::k_read(PIIODevice * d) {
|
|
PIConfig conf(d, PIIODevice::ReadOnly);
|
|
k_.read(&(conf.rootEntry()));
|
|
}
|
|
|
|
|
|
void CDCore::k_parse(PIIODevice * d) {
|
|
k_ = CDParser::parse(d, CDType::cdK);
|
|
}
|
|
|
|
|
|
void CDCore::k_update(PIIODevice * d) {
|
|
CDSection uk = k_;
|
|
k_parse(d);
|
|
bool kn = false;
|
|
if (!uk.isEmpty())
|
|
if (!uk.isSameStructure(k_)) {
|
|
piCout << "ask for save names";
|
|
K_KeepNamesRequest(&kn);
|
|
}
|
|
uk.update(k_, kn);
|
|
//piCout << k_.count() << uk.count();
|
|
k_ = uk;
|
|
}
|
|
|
|
|
|
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
|
|
piCout << from << data.size();
|
|
if (from == "cd") {
|
|
datatr.received(data);
|
|
}
|
|
}
|
|
|
|
void CDCore::K_Send() {
|
|
piCoutObj << "K_Send";
|
|
PIString s;
|
|
PIIOString ios(&s);
|
|
k_write(&ios);
|
|
// ios.close();
|
|
piCout << s;
|
|
//PIByteArray ba = PIByteArray::fromString(s);
|
|
PIFile pf("k.txt", PIIODevice::ReadWrite);
|
|
pf.resize(0);
|
|
pf.write(s.dataAscii(), s.lengthAscii());
|
|
//k_write(&pf);
|
|
//piCout << pf.readLine();
|
|
}
|
|
|
|
|
|
void CDCore::K_Request() {
|
|
piCoutObj << "K_Request";
|
|
|
|
}
|