git-svn-id: svn://db.shs.com.ru/libs@112 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -15,8 +15,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||||
endif ()
|
endif ()
|
||||||
set(CPPS_UTILS "cdutils_core.cpp" "cdutils_k_types.cpp" "cdutils_k_parser.cpp" "cdutils_k.cpp")
|
file(GLOB HDRS_UTILS "*.h")
|
||||||
set(HDRS_UTILS "cdutils_core.h" "cdutils_k_types.h" "cdutils_k_parser.h" "cdutils_k.h")
|
file(GLOB CPPS_UTILS "*.cpp")
|
||||||
|
#set(CPPS_UTILS "cdutils_core.cpp" "cdutils_k_types.cpp" "cdutils_k_parser.cpp" "cdutils_k.cpp")
|
||||||
|
#set(HDRS_UTILS "cdutils_core.h" "cdutils_k_types.h" "cdutils_k_parser.h" "cdutils_k.h")
|
||||||
if (DEFINED ENV{QNX_HOST})
|
if (DEFINED ENV{QNX_HOST})
|
||||||
add_library(${PROJECT_NAME} STATIC ${CPPS_UTILS} ${HDRS_UTILS})
|
add_library(${PROJECT_NAME} STATIC ${CPPS_UTILS} ${HDRS_UTILS})
|
||||||
else ()
|
else ()
|
||||||
|
|||||||
10
cd_utils/cdtest.h
Normal file
10
cd_utils/cdtest.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef CDTEST_H
|
||||||
|
#define CDTEST_H
|
||||||
|
|
||||||
|
|
||||||
|
enum KDescription {
|
||||||
|
First, //f
|
||||||
|
Second, //b
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CDTEST_H
|
||||||
@@ -1,72 +1,68 @@
|
|||||||
#include "cdutils_core.h"
|
#include "cdutils_core.h"
|
||||||
#include "cdutils_k_parser.h"
|
#include "cdutils_k_parser.h"
|
||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
|
#include "cdutils_protocol.h"
|
||||||
|
#include "piiodevice.h"
|
||||||
|
#include "piiostring.h"
|
||||||
|
#include "pifile.h"
|
||||||
|
|
||||||
using namespace CDUtils;
|
using namespace CDUtils;
|
||||||
|
|
||||||
const char Core::app_config[] =
|
const char CDCore::app_config[] =
|
||||||
"include = cd_ip.conf\n\
|
"include = cd_ip.conf\n\
|
||||||
port_rec = 2\n\
|
port_rec = 2\n\
|
||||||
port_send = 1\n\
|
port_send = 1\n\
|
||||||
[connection]\n\
|
[connection]\n\
|
||||||
device.c = eth://UDP:127.0.0.1:3610${port_rec}:127.0.0.1:3610${port_send} #s\n\
|
device.cd = eth://UDP:127.0.0.1:2616${port_rec}:127.0.0.1:2616${port_send} #s\n\
|
||||||
device.c.disconnectTimeout = 3.00000000 #f\n\
|
device.cd.disconnectTimeout = 3.00000000 #f\n\
|
||||||
device.k = eth://UDP:127.0.0.1:2610${port_rec}:127.0.0.1:2610${port_send} #s\n\
|
device.cd_eth = eth://UDP:${ip_app}:2616${port_rec}:${ip_pult}:2616${port_send} #s\n\
|
||||||
device.k.disconnectTimeout = 3.00000000 #f\n\
|
device.cd_eth.disconnectTimeout = 3.00000000 #f\n\
|
||||||
device.x = eth://UDP:127.0.0.1:1610${port_rec}:127.0.0.1:1610${port_send} #s\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.x.disconnectTimeout = 3.00000000 #f\n\
|
device.cd_mcast.disconnectTimeout = 3.00000000 #f\n\
|
||||||
device.c_eth = eth://UDP:${ip_app}:3610${port_rec}:${ip_pult}:3610${port_send} #s\n\
|
channel.0.from = cd_eth #s\n\
|
||||||
device.c_eth.disconnectTimeout = 3.00000000 #f\n\
|
channel.0.to = cd #s\n\
|
||||||
device.k_eth = eth://UDP:${ip_app}:2610${port_rec}:${ip_pult}:2610${port_send} #s\n\
|
channel.1.from = cd_mcast #s\n\
|
||||||
device.k_eth.disconnectTimeout = 3.00000000 #f\n\
|
channel.1.to = cd #s\n\
|
||||||
device.x_eth = eth://UDP:${ip_app}:1610${port_rec}:${ip_pult}:1610${port_send} #s\n\
|
[]\n\
|
||||||
device.x_eth.disconnectTimeout = 3.00000000 #f\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\
|
||||||
channel.0.from = c_eth #s\n\
|
";
|
||||||
channel.0.to = c #s\n\
|
|
||||||
channel.1.from = k_eth #s\n\
|
|
||||||
channel.1.to = k #s\n\
|
|
||||||
channel.2.from = x_eth #s\n\
|
|
||||||
channel.2.to = x #s\n\
|
|
||||||
[]\n\
|
|
||||||
connectionmodel = AAAWNHja7ZbfShtBFMa/Xf9UrYLSXnqhErxrdSNYKBRXEMQbEVGhBBRJgob4J6SxSZBC38ELb32UBR/AV/ARfAP9MjmzyQ7TGGkaGzeznMycmTNnZn/zLRkAH5HGOc74ZNkqIac8YBhwLlk7tEHUi1trP7KwHqCN+AhLLeYHpqC7HEeFqbLygJal3XHfPjxE2/kX69UxYK32en62vnqwIXvJwOr7m1JLvPZZ3tGmBR0ErSNYXY20gbuPvxl/eSaKuxxY/RC/xPfxdwb/3u8o7u+w+iF+ie/j7wj+IBXFH+zD6mvcOr7L+PXW3xz+nIH7KLD6If4c+urvIP6qgb96Y/VD/NW/xa/W5rj7SeImg2Jg5nRlji7M4dwJk1U9jzaOAz4lVFHgHUuOsjEHo9IXnrceXJe+cbXQGQ5xak3wgTYG9ZPnSlmudWykuo7sJ8OYn7zppa3pDnS6PUn1FQt8dnkYW2wncMmpBYblUcEv9iSxDA+LrM3RAi5wwhzNUZ6xtW+Rtzzl9TPTGtOAkSAlCeZpc5yc48cQvdPusK+G7pzbKVlST6gT90ciX9Rgk8TnZdIYyigyWUntEGrHRbYPkWkIq0k0CfSCaCqvIRqvLdF48RONX7jvBdGkX0M0S22JZik2opk1RaP/Ev8gmttOimalTdG816fsElE0xdULxJLSabatYvEoii/4zGOvm2fIpdV4jISi7zH/uVDy3RVK8hmhJGMolAR6QSiV7grFe0YoMbivPAGq7YwD\n\
|
|
||||||
";
|
|
||||||
|
|
||||||
const char Core::pult_config[] =
|
const char CDCore::pult_config[] =
|
||||||
"include = cd_ip.conf\n\
|
"include = cd_ip.conf\n\
|
||||||
port_rec = 1\n\
|
port_rec = 1\n\
|
||||||
port_send = 2\n\
|
port_send = 2\n\
|
||||||
[connection]\n\
|
[connection]\n\
|
||||||
device.c = eth://UDP:127.0.0.1:3610${port_rec}:127.0.0.1:3610${port_send} #s\n\
|
device.cd = eth://UDP:127.0.0.1:2616${port_rec}:127.0.0.1:2616${port_send} #s\n\
|
||||||
device.c.disconnectTimeout = 3.00000000 #f\n\
|
device.cd.disconnectTimeout = 3.00000000 #f\n\
|
||||||
device.k = eth://UDP:127.0.0.1:2610${port_rec}:127.0.0.1:2610${port_send} #s\n\
|
device.cd_eth = eth://UDP:${ip_app}:2616${port_rec}:${ip_pult}:2616${port_send} #s\n\
|
||||||
device.k.disconnectTimeout = 3.00000000 #f\n\
|
device.cd_eth.disconnectTimeout = 3.00000000 #f\n\
|
||||||
device.x = eth://UDP:127.0.0.1:1610${port_rec}:127.0.0.1:1610${port_send} #s\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.x.disconnectTimeout = 3.00000000 #f\n\
|
device.cd_mcast.disconnectTimeout = 3.00000000 #f\n\
|
||||||
device.c_eth = eth://UDP:${ip_pult}:3610${port_rec}:${ip_app}:3610${port_send} #s\n\
|
channel.0.from = cd_eth #s\n\
|
||||||
device.c_eth.disconnectTimeout = 3.00000000 #f\n\
|
channel.0.to = cd #s\n\
|
||||||
device.k_eth = eth://UDP:${ip_pult}:2610${port_rec}:${ip_app}:2610${port_send} #s\n\
|
channel.1.from = cd_mcast #s\n\
|
||||||
device.k_eth.disconnectTimeout = 3.00000000 #f\n\
|
channel.1.to = cd #s\n\
|
||||||
device.x_eth = eth://UDP:${ip_pult}:1610${port_rec}:${ip_app}:1610${port_send} #s\n\
|
[]\n\
|
||||||
device.x_eth.disconnectTimeout = 3.00000000 #f\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\
|
||||||
[]\n\
|
";
|
||||||
connectionmodel = AAAWNHja7ZbfShtBFMa/Xf9UrYLSXnqhErxrdSNYKBRXEMQbEVGhBBRJgob4J6SxSZBC38ELb32UBR/AV/ARfAP9MjmzyQ7TGGkaGzeznMycmTNnZn/zLRkAH5HGOc74ZNkqIac8YBhwLlk7tEHUi1trP7KwHqCN+AhLLeYHpqC7HEeFqbLygJal3XHfPjxE2/kX69UxYK32en62vnqwIXvJwOr7m1JLvPZZ3tGmBR0ErSNYXY20gbuPvxl/eSaKuxxY/RC/xPfxdwb/3u8o7u+w+iF+ie/j7wj+IBXFH+zD6mvcOr7L+PXW3xz+nIH7KLD6If4c+urvIP6qgb96Y/VD/NW/xa/W5rj7SeImg2Jg5nRlji7M4dwJk1U9jzaOAz4lVFHgHUuOsjEHo9IXnrceXJe+cbXQGQ5xak3wgTYG9ZPnSlmudWykuo7sJ8OYn7zppa3pDnS6PUn1FQt8dnkYW2wncMmpBYblUcEv9iSxDA+LrM3RAi5wwhzNUZ6xtW+Rtzzl9TPTGtOAkSAlCeZpc5yc48cQvdPusK+G7pzbKVlST6gT90ciX9Rgk8TnZdIYyigyWUntEGrHRbYPkWkIq0k0CfSCaCqvIRqvLdF48RONX7jvBdGkX0M0S22JZik2opk1RaP/Ev8gmttOimalTdG816fsElE0xdULxJLSabatYvEoii/4zGOvm2fIpdV4jISi7zH/uVDy3RVK8hmhJGMolAR6QSiV7grFe0YoMbivPAGq7YwD\n\
|
|
||||||
";
|
|
||||||
|
|
||||||
|
|
||||||
int __Core_Initializer__::count_(0);
|
int __Core_Initializer__::count_(0);
|
||||||
Core * __Core_Initializer__::__instance__(0);
|
CDCore * __Core_Initializer__::__instance__(0);
|
||||||
|
|
||||||
|
|
||||||
__Core_Initializer__::__Core_Initializer__() {
|
__Core_Initializer__::__Core_Initializer__() {
|
||||||
count_++;
|
count_++;
|
||||||
|
//piCout << "try create Core" << count_;
|
||||||
if (count_ > 1) return;
|
if (count_ > 1) return;
|
||||||
//piCout << "create Core";
|
//piCout << "create Core";
|
||||||
__instance__ = new Core();
|
__instance__ = new CDCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__Core_Initializer__::~__Core_Initializer__() {
|
__Core_Initializer__::~__Core_Initializer__() {
|
||||||
count_--;
|
count_--;
|
||||||
|
//piCout << "try delete Core" << count_;
|
||||||
if (count_ > 0) return;
|
if (count_ > 0) return;
|
||||||
//piCout << "delete Core";
|
//piCout << "delete Core";
|
||||||
if (__instance__ != 0) {
|
if (__instance__ != 0) {
|
||||||
@@ -78,11 +74,13 @@ __Core_Initializer__::~__Core_Initializer__() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Core::Core(const char * conf) {
|
CDCore::CDCore(const char * conf) {
|
||||||
CONNECTU(&connection, dataReceivedEvent, this, dataReceived);
|
CONNECTU(&connection, dataReceivedEvent, this, dataReceived);
|
||||||
PIString s(conf);
|
PIString s(conf);
|
||||||
connection.configureFromString(&s);
|
connection.configureFromString(&s);
|
||||||
|
datatr.setPacketSize(960);
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
/*k_[1] = KType(1, "123", "120+3", "comment");
|
/*k_[1] = KType(1, "123", "120+3", "comment");
|
||||||
k_[2] = KType(2, "1", "2", "comm");
|
k_[2] = KType(2, "1", "2", "comm");
|
||||||
k_[4] = KType(4, "-0.6", "-6/10", "mment");
|
k_[4] = KType(4, "-0.6", "-6/10", "mment");
|
||||||
@@ -95,39 +93,39 @@ Core::Core(const char * conf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Core::k_rec(const PIByteArray & data) {
|
void CDCore::k_rec(const PIByteArray & data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Core::x_rec(const PIByteArray & data) {
|
void CDCore::x_rec(const PIByteArray & data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Core::c_rec(const PIByteArray & data) {
|
void CDCore::c_rec(const PIByteArray & data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Core::k_write(PIIODevice * d) {
|
void CDCore::k_write(PIIODevice * d) {
|
||||||
k_.write(d, PIString());
|
k_.write(d, PIString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Core::k_read(PIIODevice * d) {
|
void CDCore::k_read(PIIODevice * d) {
|
||||||
PIConfig conf(d, PIIODevice::ReadOnly);
|
PIConfig conf(d, PIIODevice::ReadOnly);
|
||||||
k_.read(&(conf.rootEntry()));
|
k_.read(&(conf.rootEntry()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Core::k_parse(PIIODevice * d) {
|
void CDCore::k_parse(PIIODevice * d) {
|
||||||
k_ = KParser::parse(d);
|
k_ = CDParser::parse(d, CDType::cdK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Core::k_update(PIIODevice * d) {
|
void CDCore::k_update(PIIODevice * d) {
|
||||||
KSection uk = k_;
|
CDSection uk = k_;
|
||||||
k_parse(d);
|
k_parse(d);
|
||||||
bool kn = false;
|
bool kn = false;
|
||||||
if (!uk.isEmpty())
|
if (!uk.isEmpty())
|
||||||
@@ -136,26 +134,33 @@ void Core::k_update(PIIODevice * d) {
|
|||||||
K_KeepNamesRequest(&kn);
|
K_KeepNamesRequest(&kn);
|
||||||
}
|
}
|
||||||
uk.update(k_, kn);
|
uk.update(k_, kn);
|
||||||
piCout << k_.count() << uk.count();
|
//piCout << k_.count() << uk.count();
|
||||||
k_ = uk;
|
k_ = uk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CDUtils::Core::dataReceived(const PIString & from, const PIByteArray & data) {
|
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||||
piCout << from << data;
|
piCout << from << data.size();
|
||||||
if (data.size_s() < 4) return;
|
if (from == "cd") {
|
||||||
if (from == "k") k_rec(data);
|
datatr.received(data);
|
||||||
if (from == "x") x_rec(data);
|
}
|
||||||
if (from == "c") c_rec(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDCore::K_Send() {
|
||||||
void Core::K_Send() {
|
|
||||||
piCoutObj << "K_Send";
|
piCoutObj << "K_Send";
|
||||||
|
PIString s;
|
||||||
|
PIIOString ios(&s);
|
||||||
|
k_write(&ios);
|
||||||
|
ios.close();
|
||||||
|
//PIByteArray ba = PIByteArray::fromString(s);
|
||||||
|
PIFile pf("k.txt", PIIODevice::ReadWrite);
|
||||||
|
pf.write(s.toUTF8());
|
||||||
|
//k_write(&pf);
|
||||||
|
piCout << pf.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Core::K_Request() {
|
void CDCore::K_Request() {
|
||||||
piCoutObj << "K_Request";
|
piCoutObj << "K_Request";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#ifndef CDUTILS_CORE_H
|
#ifndef CDUTILS_CORE_H
|
||||||
#define CDUTILS_CORE_H
|
#define CDUTILS_CORE_H
|
||||||
|
|
||||||
#include "cdutils_k_types.h"
|
#include "cdutils_types.h"
|
||||||
#include "piconnection.h"
|
#include "piconnection.h"
|
||||||
#include "pidatatransfer.h"
|
#include "pidatatransfer.h"
|
||||||
|
|
||||||
|
|
||||||
namespace CDUtils {
|
namespace CDUtils {
|
||||||
|
|
||||||
class Core;
|
class CDCore;
|
||||||
|
|
||||||
|
|
||||||
class __Core_Initializer__ {
|
class __Core_Initializer__ {
|
||||||
@@ -16,16 +16,16 @@ public:
|
|||||||
__Core_Initializer__();
|
__Core_Initializer__();
|
||||||
~__Core_Initializer__();
|
~__Core_Initializer__();
|
||||||
static int count_;
|
static int count_;
|
||||||
static Core * __instance__;
|
static CDCore * __instance__;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Core: public PIObject
|
class CDCore: public PIObject
|
||||||
{
|
{
|
||||||
PIOBJECT(CDUtils::Core)
|
PIOBJECT(CDUtils::CDCore)
|
||||||
friend class __Core_Initializer__;
|
friend class __Core_Initializer__;
|
||||||
public:
|
public:
|
||||||
static Core * instance() {return __Core_Initializer__::__instance__;}
|
static CDCore * instance() {return __Core_Initializer__::__instance__;}
|
||||||
|
|
||||||
EVENT(K_Sended)
|
EVENT(K_Sended)
|
||||||
EVENT(K_Received)
|
EVENT(K_Received)
|
||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
EVENT_HANDLER(void, K_Send);
|
EVENT_HANDLER(void, K_Send);
|
||||||
EVENT_HANDLER(void, K_Request);
|
EVENT_HANDLER(void, K_Request);
|
||||||
|
|
||||||
KSection k_;
|
CDSection k_;
|
||||||
|
|
||||||
void k_write(PIIODevice * d);
|
void k_write(PIIODevice * d);
|
||||||
void k_read(PIIODevice * d);
|
void k_read(PIIODevice * d);
|
||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
void k_update(PIIODevice * d);
|
void k_update(PIIODevice * d);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core(const char * conf =
|
CDCore(const char * conf =
|
||||||
#ifdef CDPULT
|
#ifdef CDPULT
|
||||||
pult_config
|
pult_config
|
||||||
#else
|
#else
|
||||||
@@ -55,7 +55,7 @@ private:
|
|||||||
|
|
||||||
static const char app_config[], pult_config[];
|
static const char app_config[], pult_config[];
|
||||||
PIConnection connection;
|
PIConnection connection;
|
||||||
|
PIDataTransfer datatr;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ using namespace CDUtils;
|
|||||||
|
|
||||||
|
|
||||||
KInterface::KInterface() {
|
KInterface::KInterface() {
|
||||||
core = Core::instance();
|
core = CDCore::instance();
|
||||||
piCoutObj << core;
|
//piCoutObj << core;
|
||||||
k_file = PIStringAscii("k.dat");
|
k_file = PIStringAscii("k.dat");
|
||||||
k_file_size = 0;
|
k_file_size = 0;
|
||||||
CONNECTU(core, K_Sended, this, sended);
|
CONNECTU(core, K_Sended, this, sended);
|
||||||
@@ -22,27 +22,27 @@ bool KInterface::test(int v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KType & KInterface::operator [](int v) {
|
CDType & KInterface::operator [](int v) {
|
||||||
return core->k_[v];
|
return core->k_[v];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const KType KInterface::operator [](int v) const {
|
const CDType KInterface::operator [](int v) const {
|
||||||
return core->k_[v];
|
return core->k_[v];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSection & KInterface::section(int v) {
|
CDSection & KInterface::section(int v) {
|
||||||
return core->k_.section(v);
|
return core->k_.section(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const KSection KInterface::section(int v) const {
|
const CDSection KInterface::section(int v) const {
|
||||||
return core->k_.section(v);
|
return core->k_.section(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const KSection & KInterface::root() const {
|
const CDSection & KInterface::root() const {
|
||||||
return core->k_;
|
return core->k_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#ifndef CDUTILS_K_H
|
#ifndef CDUTILS_K_H
|
||||||
#define CDUTILS_K_H
|
#define CDUTILS_K_H
|
||||||
|
|
||||||
#include "cdutils_k_types.h"
|
#include "cdutils_types.h"
|
||||||
#include "piobject.h"
|
#include "piobject.h"
|
||||||
|
|
||||||
|
|
||||||
namespace CDUtils {
|
namespace CDUtils {
|
||||||
|
|
||||||
class Core;
|
class CDCore;
|
||||||
|
|
||||||
|
|
||||||
class KInterface: public PIObject
|
class KInterface: public PIObject
|
||||||
@@ -17,11 +17,11 @@ public:
|
|||||||
KInterface();
|
KInterface();
|
||||||
|
|
||||||
bool test(int v);
|
bool test(int v);
|
||||||
KType & operator [](int v);
|
CDType & operator [](int v);
|
||||||
const KType operator [](int v) const;
|
const CDType operator [](int v) const;
|
||||||
KSection & section(int v);
|
CDSection & section(int v);
|
||||||
const KSection section(int v) const;
|
const CDSection section(int v) const;
|
||||||
const KSection & root() const;
|
const CDSection & root() const;
|
||||||
|
|
||||||
int count(bool recursive = true) const;
|
int count(bool recursive = true) const;
|
||||||
const PIString file() const {return k_file;}
|
const PIString file() const {return k_file;}
|
||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
void writeFile();
|
void writeFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core * core;
|
CDCore * core;
|
||||||
PIString k_file;
|
PIString k_file;
|
||||||
int k_file_size;
|
int k_file_size;
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef CDUTILS_K_PARSER_H
|
|
||||||
#define CDUTILS_K_PARSER_H
|
|
||||||
|
|
||||||
class PIIODevice;
|
|
||||||
|
|
||||||
namespace CDUtils {
|
|
||||||
|
|
||||||
class KSection;
|
|
||||||
|
|
||||||
namespace KParser {
|
|
||||||
|
|
||||||
KSection parse(PIIODevice * d);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // CDUTILS_K_PARSER_H
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
#ifndef CDUTILS_K_TYPES_H
|
|
||||||
#define CDUTILS_K_TYPES_H
|
|
||||||
|
|
||||||
#include "pistring.h"
|
|
||||||
#include "pimap.h"
|
|
||||||
|
|
||||||
class PIIODevice;
|
|
||||||
class CD_Pult;
|
|
||||||
|
|
||||||
namespace CDUtils {
|
|
||||||
|
|
||||||
class KSection;
|
|
||||||
|
|
||||||
class KType {
|
|
||||||
friend class KSection;
|
|
||||||
friend class ::CD_Pult;
|
|
||||||
public:
|
|
||||||
KType();
|
|
||||||
KType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c);
|
|
||||||
int index() const {return index_;}
|
|
||||||
PIString name() const {return name_;}
|
|
||||||
PIString type() const {return type_;}
|
|
||||||
PIString value() const {return value_s;}
|
|
||||||
PIString formula() const {return formula_;}
|
|
||||||
PIString comment() const {return comment_;}
|
|
||||||
double toDouble() const {return value_d;}
|
|
||||||
int toInt() const {return value_i;}
|
|
||||||
bool toBool() const {return value_b;}
|
|
||||||
|
|
||||||
operator double() const {return value_d;}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
int index_;
|
|
||||||
PIString name_, type_;
|
|
||||||
PIString value_s, formula_, comment_;
|
|
||||||
double value_d;
|
|
||||||
int value_i;
|
|
||||||
bool value_b;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class KSection {
|
|
||||||
friend class Core;
|
|
||||||
friend class KInterface;
|
|
||||||
friend class ::CD_Pult;
|
|
||||||
public:
|
|
||||||
KSection() {}
|
|
||||||
|
|
||||||
bool test(int v) {return k.value(v).toBool();}
|
|
||||||
KType & operator [](int v) {return k[v];}
|
|
||||||
const KType operator [](int v) const {return k[v];}
|
|
||||||
KSection & section(int v) {return s[v];}
|
|
||||||
const KSection section(int v) const {return s[v];}
|
|
||||||
|
|
||||||
bool isEmpty() const {return k.isEmpty() && s.isEmpty();}
|
|
||||||
int count(bool recursive = true) const;
|
|
||||||
PIVector<int> indexes() const {return k.keys();}
|
|
||||||
PIStringList index_names() const;
|
|
||||||
|
|
||||||
PIString name;
|
|
||||||
PIString alias;
|
|
||||||
|
|
||||||
private:
|
|
||||||
KSection(PIMap<int, KType> k_, PIMap<int, KSection> s_) {
|
|
||||||
k = k_;
|
|
||||||
s = s_;
|
|
||||||
}
|
|
||||||
void write(PIIODevice * d, const PIString & prefix = PIString());
|
|
||||||
void read(const void * ep);
|
|
||||||
void update(KSection & v, bool keep_names);
|
|
||||||
bool isSameStructure(KSection & v);
|
|
||||||
|
|
||||||
mutable PIMap<int, KType> k;
|
|
||||||
PIMap<int, KSection> s;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
inline PICout operator <<(PICout s, const CDUtils::KType & v) {s.space(); s.setControl(0, true); s << "K[" << v.name() << " (" << v.index() << ")] = " << v.value(); s.restoreControl(); return s;}
|
|
||||||
|
|
||||||
#endif // CDUTILS_K_TYPES_H
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "cdutils_k_parser.h"
|
#include "cdutils_parser.h"
|
||||||
#include "cdutils_k_types.h"
|
#include "cdutils_types.h"
|
||||||
#include "piiostring.h"
|
#include "piiostring.h"
|
||||||
#include "pifile.h"
|
#include "pifile.h"
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ enum Phase {
|
|||||||
void removeComment(PIString & line, PIString * type, PIString * comment) {
|
void removeComment(PIString & line, PIString * type, PIString * comment) {
|
||||||
int ci = line.find("//");
|
int ci = line.find("//");
|
||||||
if (ci >= 0) {
|
if (ci >= 0) {
|
||||||
if (comment) *comment = line.right(line.size_s() - ci - 2).trim();
|
if (comment) *comment = line.right(line.size_s() - ci - 2);
|
||||||
line.cutRight(line.size_s() - ci).trim();
|
line.cutRight(line.size_s() - ci).trim();
|
||||||
if (type && comment && !line.isEmpty()) {
|
if (type && comment && !line.isEmpty()) {
|
||||||
*type = comment->takeLeft(1);
|
*type = comment->takeLeft(1);
|
||||||
@@ -58,7 +58,7 @@ void parseInsert(PIString line, PIString & alias, PIStringList & out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIVector<int> enumValues(const PIString & e, const PIMap<PIString, KSection> & sections, PIStringList & enames) {
|
PIVector<int> enumValues(const PIString & e, const PIMap<PIString, CDSection> & sections, PIStringList & enames) {
|
||||||
PIVector<int> ret;
|
PIVector<int> ret;
|
||||||
enames.clear();
|
enames.clear();
|
||||||
if (sections.contains(e)) {
|
if (sections.contains(e)) {
|
||||||
@@ -76,13 +76,14 @@ PIVector<int> enumValues(const PIString & e, const PIMap<PIString, KSection> & s
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSection KParser::parse(PIIODevice * d) {
|
CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||||
if (!d) return KSection();
|
CDType::cdT et = (CDType::cdT)cdsection_type;
|
||||||
if (!d->canRead()) return KSection();
|
if (!d) return CDSection();
|
||||||
KSection cs;
|
if (!d->canRead()) return CDSection();
|
||||||
KType ck;
|
CDSection cs;
|
||||||
PIMap<PIString, KSection> sections;
|
CDType ck;
|
||||||
PIMap<PIString, int> enum_values, cevalues;
|
PIMap<PIString, CDSection> sections;
|
||||||
|
PIMap<PIString, int> enum_values;
|
||||||
PIString content, line, alias, type, comment;
|
PIString content, line, alias, type, comment;
|
||||||
PIStringList iarr;
|
PIStringList iarr;
|
||||||
if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) {
|
if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) {
|
||||||
@@ -110,11 +111,11 @@ KSection KParser::parse(PIIODevice * d) {
|
|||||||
cind += 4;
|
cind += 4;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cs = KSection();
|
cs = CDSection();
|
||||||
cs.name = line;
|
cs.name = line;
|
||||||
//piCout << "enum" << cs.name;
|
//piCout << "enum" << cs.name;
|
||||||
int cev = 0;
|
int cev = 0;
|
||||||
cevalues.clear();
|
// cevalues.clear();
|
||||||
while (!ios.isEnd()) {
|
while (!ios.isEnd()) {
|
||||||
line = ios.readLine().trim();
|
line = ios.readLine().trim();
|
||||||
comment.clear();
|
comment.clear();
|
||||||
@@ -124,17 +125,18 @@ KSection KParser::parse(PIIODevice * d) {
|
|||||||
if (comment.find("=") >= 0) {
|
if (comment.find("=") >= 0) {
|
||||||
parseInsert(comment, alias, iarr);
|
parseInsert(comment, alias, iarr);
|
||||||
if (!iarr.isEmpty()) {
|
if (!iarr.isEmpty()) {
|
||||||
|
// piCout << "#" << enum_values;
|
||||||
if (!enum_values.contains(alias)) {
|
if (!enum_values.contains(alias)) {
|
||||||
piCout << "Parse error: can`t find section alias \"" << alias << "\"!";
|
piCout << "Parse error: can`t find section alias \"" << alias << "\"!";
|
||||||
return KSection();
|
return CDSection();
|
||||||
}
|
}
|
||||||
if (!sections.contains(iarr.front())) {
|
if (!sections.contains(iarr.front())) {
|
||||||
piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!";
|
piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!";
|
||||||
return KSection();
|
return CDSection();
|
||||||
}
|
}
|
||||||
//piCout << "insert" << alias << iarr;
|
//piCout << "insert" << alias << iarr;
|
||||||
int aval = enum_values.value(alias);
|
int aval = enum_values.value(alias);
|
||||||
KSection is = sections.value(iarr.take_front()), ts;
|
CDSection is = sections.value(iarr.take_front()), ts;
|
||||||
int ibpos = is.name.size_s();
|
int ibpos = is.name.size_s();
|
||||||
piForeachRC (PIString & a, iarr) {
|
piForeachRC (PIString & a, iarr) {
|
||||||
PIStringList enames;
|
PIStringList enames;
|
||||||
@@ -147,7 +149,7 @@ KSection KParser::parse(PIIODevice * d) {
|
|||||||
ts.name = is.name;
|
ts.name = is.name;
|
||||||
ts.name.insert(ibpos, PIString("[") << a << "]");
|
ts.name.insert(ibpos, PIString("[") << a << "]");
|
||||||
is = ts;
|
is = ts;
|
||||||
ts = KSection();
|
ts = CDSection();
|
||||||
}
|
}
|
||||||
is.alias = alias;
|
is.alias = alias;
|
||||||
cs.section(aval) = is;
|
cs.section(aval) = is;
|
||||||
@@ -156,16 +158,23 @@ KSection KParser::parse(PIIODevice * d) {
|
|||||||
} else {
|
} else {
|
||||||
parseEnumLine(line, &cev, &type, &comment);
|
parseEnumLine(line, &cev, &type, &comment);
|
||||||
//piCout << line << "=" << cev << "//" << type << comment;
|
//piCout << line << "=" << cev << "//" << type << comment;
|
||||||
ck = KType(cev, line, type, "", "", comment);
|
ck = CDType(cev, line, type, "", "", comment, et);
|
||||||
cs[cev] = ck;
|
cs[cev] = ck;
|
||||||
cevalues[line] = cev;
|
//cevalues[line] = cev;
|
||||||
|
enum_values[line] = cev;
|
||||||
++cev;
|
++cev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//piCout << cs.name << cs.k;
|
//piCout << cs.name << cs.k;
|
||||||
sections[cs.name] = cs;
|
sections[cs.name] = cs;
|
||||||
enum_values << cevalues;
|
// piCout << "#" << cevalues;
|
||||||
|
// enum_values << cevalues;
|
||||||
cind += 4;
|
cind += 4;
|
||||||
}
|
}
|
||||||
return sections.value("KDescription");
|
switch (et) {
|
||||||
|
case CDType::cdK : return sections.value("KDescription");
|
||||||
|
case CDType::cdX : return sections.value("XDescription");
|
||||||
|
case CDType::cdC : return sections.value("CDescription");
|
||||||
|
}
|
||||||
|
return CDSection();
|
||||||
}
|
}
|
||||||
19
cd_utils/cdutils_parser.h
Normal file
19
cd_utils/cdutils_parser.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef CDUTILS_PARSER_H
|
||||||
|
#define CDUTILS_PARSER_H
|
||||||
|
|
||||||
|
|
||||||
|
class PIIODevice;
|
||||||
|
|
||||||
|
namespace CDUtils {
|
||||||
|
|
||||||
|
class CDSection;
|
||||||
|
|
||||||
|
namespace CDParser {
|
||||||
|
|
||||||
|
CDSection parse(PIIODevice * d, int cdsection_type);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CDUTILS_PARSER_H
|
||||||
24
cd_utils/cdutils_protocol.h
Normal file
24
cd_utils/cdutils_protocol.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef CDUTILS_PROTOCOL_H
|
||||||
|
#define CDUTILS_PROTOCOL_H
|
||||||
|
|
||||||
|
#include "pibytearray.h"
|
||||||
|
|
||||||
|
namespace CDUtils {
|
||||||
|
|
||||||
|
enum CDPacketType {CD_Ping, CD_Pong, CD_KQuery, CD_KSend, CD_Command, CD_XData, CD_XQuery};
|
||||||
|
|
||||||
|
# pragma pack(push,1)
|
||||||
|
struct PacketHeader {
|
||||||
|
int session_id;
|
||||||
|
int type; // CDPacketType
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PacketKSend : PacketHeader {
|
||||||
|
PIByteArray kdata; // file k.dat
|
||||||
|
};
|
||||||
|
|
||||||
|
# pragma pack(pop)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CDUTILS_PROTOCOL_H
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
#include "cdutils_k_types.h"
|
#include "cdutils_types.h"
|
||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
|
|
||||||
using namespace CDUtils;
|
using namespace CDUtils;
|
||||||
|
|
||||||
|
|
||||||
KType::KType() {
|
CDType::CDType() {
|
||||||
index_ = -1;
|
index_ = -1;
|
||||||
value_d = 0.;
|
value_d = 0.;
|
||||||
value_i = 0;
|
value_i = 0;
|
||||||
value_b = false;
|
value_b = false;
|
||||||
|
cd_type_ = cdNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KType::KType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c) {
|
CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t) {
|
||||||
index_ = i;
|
index_ = i;
|
||||||
name_ = n;
|
name_ = n;
|
||||||
type_ = t;
|
type_ = t;
|
||||||
@@ -22,13 +23,14 @@ KType::KType(int i, const PIString & n, const PIString & t, const PIString & v,
|
|||||||
value_d = v.toDouble();
|
value_d = v.toDouble();
|
||||||
value_i = v.toInt();
|
value_i = v.toInt();
|
||||||
value_b = v.toBool();
|
value_b = v.toBool();
|
||||||
|
cd_type_ = cd_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int KSection::count(bool recursive) const {
|
int CDSection::count(bool recursive) const {
|
||||||
int ret = k.size_s();
|
int ret = k.size_s();
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
PIMap<int, KSection>::const_iterator i;
|
PIMap<int, CDSection>::const_iterator i;
|
||||||
for (i = s.begin(); i != s.end(); ++i)
|
for (i = s.begin(); i != s.end(); ++i)
|
||||||
ret += i->second.count(recursive);
|
ret += i->second.count(recursive);
|
||||||
}
|
}
|
||||||
@@ -36,16 +38,16 @@ int KSection::count(bool recursive) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIStringList KSection::index_names() const {
|
PIStringList CDSection::index_names() const {
|
||||||
PIStringList ret;
|
PIStringList ret;
|
||||||
PIMap<int, KType>::iterator i;
|
PIMap<int, CDType>::iterator i;
|
||||||
for (i = k.begin(); i != k.end(); ++i)
|
for (i = k.begin(); i != k.end(); ++i)
|
||||||
ret << i.value().name();
|
ret << i.value().name();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KSection::write(PIIODevice * d, const PIString & prefix) {
|
void CDSection::write(PIIODevice * d, const PIString & prefix) {
|
||||||
if (!d) return;
|
if (!d) return;
|
||||||
if (k.isEmpty() && s.isEmpty()) return;
|
if (k.isEmpty() && s.isEmpty()) return;
|
||||||
PIString l;
|
PIString l;
|
||||||
@@ -54,19 +56,19 @@ void KSection::write(PIIODevice * d, const PIString & prefix) {
|
|||||||
else l = "[" + prefix + ".k]";
|
else l = "[" + prefix + ".k]";
|
||||||
l += "\n";
|
l += "\n";
|
||||||
d->write(l.toUTF8());
|
d->write(l.toUTF8());
|
||||||
PIMap<int, KType>::iterator i;
|
PIMap<int, CDType>::iterator i;
|
||||||
for (i = k.begin(); i != k.end(); ++i) {
|
for (i = k.begin(); i != k.end(); ++i) {
|
||||||
KType & ck(i.value());
|
CDType & ck(i.value());
|
||||||
l.clear();
|
l.clear();
|
||||||
l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << "\n";
|
l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << "\n";
|
||||||
l << ck.index() << ".v = " << ck.value() << " #s " << ck.type() << " " << ck.name() << "\n";
|
l << ck.index() << ".v = " << ck.value() << " #" << ck.type() << " " << ck.name() << "\n";
|
||||||
d->write(l.toUTF8());
|
d->write(l.toUTF8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!s.isEmpty()) {
|
if (!s.isEmpty()) {
|
||||||
if (prefix.isEmpty()) l = "s";
|
if (prefix.isEmpty()) l = "s";
|
||||||
else l = prefix + ".s";
|
else l = prefix + ".s";
|
||||||
PIMap<int, KSection>::iterator j;
|
PIMap<int, CDSection>::iterator j;
|
||||||
for (j = s.begin(); j != s.end(); ++j) {
|
for (j = s.begin(); j != s.end(); ++j) {
|
||||||
j.value().write(d, l + "." + PIString::fromNumber(j.key()));
|
j.value().write(d, l + "." + PIString::fromNumber(j.key()));
|
||||||
}
|
}
|
||||||
@@ -78,7 +80,7 @@ void KSection::write(PIIODevice * d, const PIString & prefix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KSection::read(const void * ep) {
|
void CDSection::read(const void * ep) {
|
||||||
k.clear();
|
k.clear();
|
||||||
s.clear();
|
s.clear();
|
||||||
PIConfig::Entry & e(*(PIConfig::Entry*)ep);
|
PIConfig::Entry & e(*(PIConfig::Entry*)ep);
|
||||||
@@ -88,23 +90,23 @@ void KSection::read(const void * ep) {
|
|||||||
int kid = ke->name().toInt();
|
int kid = ke->name().toInt();
|
||||||
PIString n = ke->getValue("v").comment();
|
PIString n = ke->getValue("v").comment();
|
||||||
PIString t = n.takeLeft(1);
|
PIString t = n.takeLeft(1);
|
||||||
k[kid] = KType(kid, n.trim(), t, ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment());
|
k[kid] = CDType(kid, n.trim(), t, ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment(), CDType::cdK);
|
||||||
}
|
}
|
||||||
PIConfig::Entry & sl = e.getValue("s");
|
PIConfig::Entry & sl = e.getValue("s");
|
||||||
for (int i = 0; i < sl.childCount(); ++i) {
|
for (int i = 0; i < sl.childCount(); ++i) {
|
||||||
const PIConfig::Entry * se(sl.child(i));
|
const PIConfig::Entry * se(sl.child(i));
|
||||||
int sid = se->name().toInt();
|
int sid = se->name().toInt();
|
||||||
KSection cs;
|
CDSection cs;
|
||||||
cs.read(se);
|
cs.read(se);
|
||||||
s[sid] = cs;
|
s[sid] = cs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KSection::update(KSection & v, bool keep_names) {
|
void CDSection::update(CDSection & v, bool keep_names) {
|
||||||
PIMap<PIString, PIString> vk_ids;
|
PIMap<PIString, PIString> vk_ids;
|
||||||
PISet<int> used;
|
PISet<int> used;
|
||||||
PIMap<int, KType>::iterator i;
|
PIMap<int, CDType>::iterator i;
|
||||||
for (i = v.k.begin(); i != v.k.end(); ++i)
|
for (i = v.k.begin(); i != v.k.end(); ++i)
|
||||||
vk_ids[i.value().name()] = i.value().formula();
|
vk_ids[i.value().name()] = i.value().formula();
|
||||||
for (i = k.begin(); i != k.end(); ++i) {
|
for (i = k.begin(); i != k.end(); ++i) {
|
||||||
@@ -124,7 +126,7 @@ void KSection::update(KSection & v, bool keep_names) {
|
|||||||
k[i.key()] = i.value();
|
k[i.key()] = i.value();
|
||||||
}
|
}
|
||||||
used.clear();
|
used.clear();
|
||||||
PIMap<int, KSection>::iterator j;
|
PIMap<int, CDSection>::iterator j;
|
||||||
for (j = s.begin(); j != s.end(); ++j) {
|
for (j = s.begin(); j != s.end(); ++j) {
|
||||||
if (v.s.contains(j.key()))
|
if (v.s.contains(j.key()))
|
||||||
j.value().update(v.s[j.key()], keep_names);
|
j.value().update(v.s[j.key()], keep_names);
|
||||||
@@ -137,9 +139,9 @@ void KSection::update(KSection & v, bool keep_names) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KSection::isSameStructure(KSection & v) {
|
bool CDSection::isSameStructure(CDSection & v) {
|
||||||
PIMap<PIString, int> k_ids;
|
PIMap<PIString, int> k_ids;
|
||||||
PIMap<int, KType>::iterator i;
|
PIMap<int, CDType>::iterator i;
|
||||||
for (i = k.begin(); i != k.end(); ++i)
|
for (i = k.begin(); i != k.end(); ++i)
|
||||||
k_ids[i.value().name()] = i.key();
|
k_ids[i.value().name()] = i.key();
|
||||||
for (i = v.k.begin(); i != v.k.end(); ++i) {
|
for (i = v.k.begin(); i != v.k.end(); ++i) {
|
||||||
@@ -148,7 +150,7 @@ bool KSection::isSameStructure(KSection & v) {
|
|||||||
if (k[k_ids[i.value().name()]].index() != i.key())
|
if (k[k_ids[i.value().name()]].index() != i.key())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PIMap<int, KSection>::iterator j;
|
PIMap<int, CDSection>::iterator j;
|
||||||
for (j = v.s.begin(); j != v.s.end(); ++j) {
|
for (j = v.s.begin(); j != v.s.end(); ++j) {
|
||||||
if (!s.contains(j.key())) continue;
|
if (!s.contains(j.key())) continue;
|
||||||
if (!s[j.key()].isSameStructure(j.value()))
|
if (!s[j.key()].isSameStructure(j.value()))
|
||||||
@@ -156,3 +158,5 @@ bool KSection::isSameStructure(KSection & v) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
99
cd_utils/cdutils_types.h
Normal file
99
cd_utils/cdutils_types.h
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#ifndef CDUTILS_TYPES_H
|
||||||
|
#define CDUTILS_TYPES_H
|
||||||
|
|
||||||
|
#include "pistring.h"
|
||||||
|
#include "pimap.h"
|
||||||
|
|
||||||
|
class PIIODevice;
|
||||||
|
class CD_Pult;
|
||||||
|
|
||||||
|
namespace CDUtils {
|
||||||
|
|
||||||
|
class CDSection;
|
||||||
|
|
||||||
|
class CDType {
|
||||||
|
friend class CDSection;
|
||||||
|
friend class ::CD_Pult;
|
||||||
|
public:
|
||||||
|
enum cdT {cdNull, cdK, cdX, cdC};
|
||||||
|
CDType();
|
||||||
|
CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t);
|
||||||
|
int index() const {return index_;}
|
||||||
|
PIString name() const {return name_;}
|
||||||
|
PIString type() const {return type_;}
|
||||||
|
PIString value() const {return value_s;}
|
||||||
|
PIString formula() const {return formula_;}
|
||||||
|
PIString comment() const {return comment_;}
|
||||||
|
double toDouble() const {return value_d;}
|
||||||
|
int toInt() const {return value_i;}
|
||||||
|
bool toBool() const {return value_b;}
|
||||||
|
cdT cd_type() const {return cd_type_;}
|
||||||
|
|
||||||
|
operator double() const {return value_d;}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
cdT cd_type_;
|
||||||
|
int index_;
|
||||||
|
PIString name_, type_;
|
||||||
|
PIString value_s, formula_, comment_;
|
||||||
|
double value_d;
|
||||||
|
int value_i;
|
||||||
|
bool value_b;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class CDSection {
|
||||||
|
friend class CDCore;
|
||||||
|
friend class ::CD_Pult;
|
||||||
|
public:
|
||||||
|
|
||||||
|
CDSection() {}
|
||||||
|
|
||||||
|
bool test(int v) {return k.value(v).toBool();}
|
||||||
|
CDType & operator [](int v) {return k[v];}
|
||||||
|
const CDType operator [](int v) const {return k[v];}
|
||||||
|
CDSection & section(int v) {return s[v];}
|
||||||
|
const CDSection section(int v) const {return s[v];}
|
||||||
|
|
||||||
|
bool isEmpty() const {return k.isEmpty() && s.isEmpty();}
|
||||||
|
int count(bool recursive = true) const;
|
||||||
|
PIVector<int> indexes() const {return k.keys();}
|
||||||
|
PIStringList index_names() const;
|
||||||
|
|
||||||
|
PIString name;
|
||||||
|
PIString alias;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CDSection(PIMap<int, CDType> k_, PIMap<int, CDSection> s_) {
|
||||||
|
k = k_;
|
||||||
|
s = s_;
|
||||||
|
}
|
||||||
|
void write(PIIODevice * d, const PIString & prefix = PIString());
|
||||||
|
void read(const void * ep);
|
||||||
|
void update(CDSection & v, bool keep_names);
|
||||||
|
bool isSameStructure(CDSection & v);
|
||||||
|
|
||||||
|
mutable PIMap<int, CDType> k;
|
||||||
|
PIMap<int, CDSection> s;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inline PICout operator <<(PICout s, const CDUtils::CDType & v) {
|
||||||
|
s.space();
|
||||||
|
s.setControl(0, true);
|
||||||
|
switch (v.cd_type()) {
|
||||||
|
case CDUtils::CDType::cdK : s << "K["; break;
|
||||||
|
case CDUtils::CDType::cdX : s << "X["; break;
|
||||||
|
case CDUtils::CDType::cdC : s << "C["; break;
|
||||||
|
default : s << "Null["; break;
|
||||||
|
}
|
||||||
|
s << v.name() << "(" << v.index() << ")] = " << v.value();
|
||||||
|
s.restoreControl();
|
||||||
|
return s;\
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CDUTILS_TYPES_H
|
||||||
@@ -3,13 +3,48 @@
|
|||||||
#include "piethernet.h"
|
#include "piethernet.h"
|
||||||
#include "piiostring.h"
|
#include "piiostring.h"
|
||||||
#include "pifile.h"
|
#include "pifile.h"
|
||||||
|
#include "cdtest.h"
|
||||||
|
|
||||||
|
using namespace CDUtils;
|
||||||
|
|
||||||
|
class Core : public PIObject
|
||||||
|
{
|
||||||
|
PIOBJECT(Core)
|
||||||
|
public:
|
||||||
|
Core() {
|
||||||
|
// piCout << "testCore";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void load() {
|
||||||
|
rf.open("k.dat", PIIODevice::ReadWrite);
|
||||||
|
K.read(&rf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test() {
|
||||||
|
piCoutObj << "count" << K.count();
|
||||||
|
piCoutObj << "First" << (int)First << K[First];
|
||||||
|
piCoutObj << "Second" << (int)Second << K[Second];
|
||||||
|
piCoutObj << "test Second" << K.test(Second);
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_HANDLER(void, ksend) {piCoutObj << "sended k";}
|
||||||
|
EVENT_HANDLER(void, krecv) {piCoutObj << "received k";}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PIFile rf;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#include "piscreen.h"
|
||||||
|
#include "piscreentiles.h"
|
||||||
|
PIScreen screen(false);
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
PIEthernet eth;
|
// PIEthernet eth;
|
||||||
eth.send("127.0.0.1:16102", PIByteArray("data\n", 5));
|
// eth.send("127.0.0.1:16102", PIByteArray("data\n", 5));
|
||||||
eth.send("127.0.0.1:26102", PIByteArray("data\n", 5));
|
// eth.send("127.0.0.1:26102", PIByteArray("data\n", 5));
|
||||||
eth.send("127.0.0.1:36102", PIByteArray("data\n", 5));
|
// eth.send("127.0.0.1:36102", PIByteArray("data\n", 5));
|
||||||
PIString s;/* = "[k]\n\
|
/*PIString s; = "[k]\n\
|
||||||
1.f = 120+3 #s comment\n\
|
1.f = 120+3 #s comment\n\
|
||||||
1.v = 123\n\
|
1.v = 123\n\
|
||||||
2.f = 2 #s comm\n\
|
2.f = 2 #s comm\n\
|
||||||
@@ -37,20 +72,34 @@ int main(int argc, char *argv[]) {
|
|||||||
PIIOString iosw(&s);
|
PIIOString iosw(&s);
|
||||||
CDUtils::K.write(&iosw);
|
CDUtils::K.write(&iosw);
|
||||||
piCout << s;*/
|
piCout << s;*/
|
||||||
|
// piCout << K.count();
|
||||||
|
// PIFile rf("1.txt", PIIODevice::ReadWrite);
|
||||||
|
// K.read(&rf);
|
||||||
|
|
||||||
PIFile rf("1.txt", PIIODevice::ReadWrite);
|
// PIFile f;
|
||||||
CDUtils::K.read(&rf);
|
// f.open("SH_base.h", PIIODevice::ReadOnly);
|
||||||
|
// CDUtils::K.update(&f);
|
||||||
|
|
||||||
PIFile f;
|
// PIFile wf("2.txt", PIIODevice::ReadWrite);
|
||||||
f.open("SH_base.h", PIIODevice::ReadOnly);
|
// CDUtils::K.write(&wf);
|
||||||
CDUtils::K.update(&f);
|
|
||||||
|
|
||||||
PIFile wf("2.txt", PIIODevice::ReadWrite);
|
|
||||||
CDUtils::K.write(&wf);
|
|
||||||
//PIIOString iosw(&s);
|
//PIIOString iosw(&s);
|
||||||
piCout << s;
|
//piCout << s;
|
||||||
//piMSleep(1000);
|
//piMSleep(1000);
|
||||||
//CDUtils::Core::instance()->test();
|
//CDUtils::Core::instance()->test();
|
||||||
|
//return 0;
|
||||||
|
// piCout << "init";
|
||||||
|
//screen.rootTile()->addTile(new TilePICout());
|
||||||
|
screen.enableExitCapture('q');
|
||||||
|
//screen.start();
|
||||||
|
piCout << "start";
|
||||||
|
|
||||||
|
Core core;
|
||||||
|
core.load();
|
||||||
|
core.test();
|
||||||
|
K.send();
|
||||||
|
|
||||||
|
|
||||||
|
//screen.waitForFinish();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -200,29 +200,29 @@ QString CD_Pult::typeName(const QString & n) const {
|
|||||||
case 'F': return trUtf8("file"); break;
|
case 'F': return trUtf8("file"); break;
|
||||||
case 'D': return trUtf8("dir"); break;
|
case 'D': return trUtf8("dir"); break;
|
||||||
}
|
}
|
||||||
return "";
|
return trUtf8("double");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CD_Pult::makeTreeSection(KSection & ks, QTreeWidgetItem * pi) {
|
void CD_Pult::makeTreeSection(CDSection & ks, QTreeWidgetItem * pi) {
|
||||||
PIMap<int, KType>::iterator ki;
|
PIMap<int, CDType>::iterator ki;
|
||||||
for (ki = ks.k.begin(); ki != ks.k.end(); ++ki) {
|
for (ki = ks.k.begin(); ki != ks.k.end(); ++ki) {
|
||||||
QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
|
QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
|
||||||
const KType & ck(ki.value());
|
const CDType & ck(ki.value());
|
||||||
ti->setText(0, QString::number(ck.index()));
|
ti->setText(0, QString::number(ck.index()));
|
||||||
ti->setText(1, PI2QString(ck.name()));
|
ti->setText(1, PI2QString(ck.name()));
|
||||||
ti->setText(2, typeName(PI2QString(ck.type())));
|
ti->setText(2, typeName(PI2QString(ck.type())));
|
||||||
ti->setText(3, PI2QString(ck.formula()));
|
ti->setText(3, PI2QString(ck.formula()));
|
||||||
ti->setText(5, PI2QString(ck.comment()));
|
ti->setText(5, PI2QString(ck.comment()));
|
||||||
}
|
}
|
||||||
PIMap<int, KSection>::iterator si;
|
PIMap<int, CDSection>::iterator si;
|
||||||
for (si = ks.s.begin(); si != ks.s.end(); ++si) {
|
for (si = ks.s.begin(); si != ks.s.end(); ++si) {
|
||||||
QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
|
QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
|
||||||
const KSection & cs(si.value());
|
const CDSection & cs(si.value());
|
||||||
ti->setText(0, QString("[%1]").arg(si.key()));
|
ti->setText(0, QString("[%1]").arg(si.key()));
|
||||||
ti->setText(1, PI2QString(cs.alias));
|
ti->setText(1, PI2QString(cs.alias));
|
||||||
ti->setText(2, PI2QString(cs.name));
|
ti->setText(2, PI2QString(cs.name));
|
||||||
makeTreeSection(const_cast<KSection&>(cs), ti);
|
makeTreeSection(const_cast<CDSection&>(cs), ti);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ void CD_Pult::on_buttonSetKDesc_clicked() {
|
|||||||
kdesc_file = Q2PIString(QDir::current().relativeFilePath(ret));
|
kdesc_file = Q2PIString(QDir::current().relativeFilePath(ret));
|
||||||
PIFile f(kdesc_file, PIIODevice::ReadOnly);
|
PIFile f(kdesc_file, PIIODevice::ReadOnly);
|
||||||
piCout << "open description:" << Q2PIString(ret);
|
piCout << "open description:" << Q2PIString(ret);
|
||||||
K.update(&f);
|
//K.update(&f);
|
||||||
updateKDesc(true);
|
updateKDesc(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,6 +393,7 @@ void CD_Pult::updateDiag() {
|
|||||||
void CD_Pult::updateKDesc(bool ask_move) {
|
void CD_Pult::updateKDesc(bool ask_move) {
|
||||||
addToList(trUtf8("Update K description file \"%1\"").arg(PI2QString(kdesc_file)), Qt::darkMagenta);
|
addToList(trUtf8("Update K description file \"%1\"").arg(PI2QString(kdesc_file)), Qt::darkMagenta);
|
||||||
PIFile f(kdesc_file, PIIODevice::ReadOnly);
|
PIFile f(kdesc_file, PIIODevice::ReadOnly);
|
||||||
|
//piCout << "call K.update():";
|
||||||
K.update(&f);
|
K.update(&f);
|
||||||
updateTree(ask_move);
|
updateTree(ask_move);
|
||||||
}
|
}
|
||||||
@@ -418,7 +419,7 @@ void CD_Pult::updateTree(bool move) {
|
|||||||
ui->treeK->clear();
|
ui->treeK->clear();
|
||||||
ui->treeK->setUpdatesEnabled(false);
|
ui->treeK->setUpdatesEnabled(false);
|
||||||
eval.clearCustomVariables();
|
eval.clearCustomVariables();
|
||||||
makeTreeSection(const_cast<KSection&>(K.root()), ui->treeK->invisibleRootItem());
|
makeTreeSection(const_cast<CDSection&>(K.root()), ui->treeK->invisibleRootItem());
|
||||||
/*for (int i = 0; i < K.size_s(); ++i) {
|
/*for (int i = 0; i < K.size_s(); ++i) {
|
||||||
QTreeWidgetItem * ti = new QTreeWidgetItem();
|
QTreeWidgetItem * ti = new QTreeWidgetItem();
|
||||||
KDesc kd = kdesc[i];
|
KDesc kd = kdesc[i];
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ using namespace CDUtils;
|
|||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class CD_Pult;
|
class CD_Pult;
|
||||||
};
|
}
|
||||||
|
|
||||||
class CD_Pult: public QMainWindow, public PIObject
|
class CD_Pult: public QMainWindow, public PIObject
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ private:
|
|||||||
void progress(int val, int max);
|
void progress(int val, int max);
|
||||||
void clearSelected();
|
void clearSelected();
|
||||||
QString typeName(const QString & n) const;
|
QString typeName(const QString & n) const;
|
||||||
void makeTreeSection(KSection & ks, QTreeWidgetItem * pi);
|
void makeTreeSection(CDSection & ks, QTreeWidgetItem * pi);
|
||||||
|
|
||||||
EVENT_HANDLER1(void, received, bool, ok);
|
EVENT_HANDLER1(void, received, bool, ok);
|
||||||
EVENT_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();}
|
EVENT_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include "cd_pult.h"
|
#include "cd_pult.h"
|
||||||
|
|
||||||
class A {public: A() {} ~A() {} private: void a() {}};
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
PIFile::setDefaultCharset("UTF-8");
|
PIFile::setDefaultCharset("UTF-8");
|
||||||
|
|||||||
Reference in New Issue
Block a user