git-svn-id: svn://db.shs.com.ru/libs@97 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -15,8 +15,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
|
||||
if (DEBUG)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||
endif ()
|
||||
set(CPPS_UTILS "cdutils.cpp")
|
||||
set(HDRS_UTILS "cdutils.h")
|
||||
set(CPPS_UTILS "cdutils_core.cpp")
|
||||
set(HDRS_UTILS "cdutils_core.h")
|
||||
if (DEFINED ENV{QNX_HOST})
|
||||
add_library(${PROJECT_NAME} STATIC ${CPPS_UTILS} ${HDRS_UTILS})
|
||||
else ()
|
||||
@@ -24,7 +24,7 @@ else ()
|
||||
endif ()
|
||||
target_link_libraries(${PROJECT_NAME} ${PIP_LIBRARY})
|
||||
|
||||
add_executable(cdutilsngtest WIN32 "cdutilstest.cpp")
|
||||
add_executable(cdutilsngtest "cdutilstest.cpp")
|
||||
target_link_libraries(cdutilsngtest ${PIP_LIBRARY} ${PROJECT_NAME})
|
||||
|
||||
# if (NOT DEFINED ENV{QNX_HOST})
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef CDUTILS_H
|
||||
#define CDUTILS_H
|
||||
|
||||
#include "piconnection.h"
|
||||
#include "pidatatransfer.h"
|
||||
|
||||
|
||||
#define KX_COUNT 16384
|
||||
|
||||
extern volatile double X[KX_COUNT];
|
||||
extern volatile PIMap<int, double> K;
|
||||
|
||||
class CDUtils : public PIObject
|
||||
{
|
||||
PIOBJECT(CDUtils)
|
||||
public:
|
||||
CDUtils();
|
||||
void test();
|
||||
|
||||
private:
|
||||
PIConnection connection;
|
||||
|
||||
};
|
||||
|
||||
#endif // CDUTILS_H
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "cdutils.h"
|
||||
#include "cdutils_core.h"
|
||||
|
||||
volatile double X[KX_COUNT];
|
||||
volatile PIMap<int, double> K;
|
||||
using namespace CDUtils;
|
||||
|
||||
static const char connection_config[] =
|
||||
"include = ip.conf\n\
|
||||
@@ -18,23 +17,54 @@ device.k_eth = eth://UDP:${ip_kx}:26102:${ip_kxpult}:26101 #s\n\
|
||||
device.k_eth.disconnectTimeout = 3.00000000 #f\n\
|
||||
device.x_eth = eth://UDP:${ip_kx}:16102:${ip_kxpult}:16101 #s\n\
|
||||
device.x_eth.disconnectTimeout = 3.00000000 #f\n\
|
||||
channel.0.from = eth://UDP:127.0.0.1:16102:127.0.0.1:16101 #s\n\
|
||||
channel.0.to = eth://UDP:${ip_kx}:16102:${ip_kxpult}:16101 #s\n\
|
||||
channel.1.from = eth://UDP:127.0.0.1:26102:127.0.0.1:26101 #s\n\
|
||||
channel.1.to = eth://UDP:${ip_kx}:26102:${ip_kxpult}:26101 #s\n\
|
||||
channel.2.from = eth://UDP:127.0.0.1:36102:127.0.0.1:36101 #s\n\
|
||||
channel.2.to = eth://UDP:${ip_kx}:36102:${ip_kxpult}:36101 #s\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"
|
||||
;
|
||||
;
|
||||
|
||||
CDUtils::CDUtils() {
|
||||
|
||||
int __Core_Initializer__::count_(0);
|
||||
Core * __Core_Initializer__::__instance__(0);
|
||||
|
||||
|
||||
__Core_Initializer__::__Core_Initializer__() {
|
||||
count_++;
|
||||
if (count_ > 1) return;
|
||||
//piCout << "create PIInit";
|
||||
__instance__ = new Core();
|
||||
}
|
||||
|
||||
|
||||
__Core_Initializer__::~__Core_Initializer__() {
|
||||
count_--;
|
||||
if (count_ > 1) return;
|
||||
//piCout << "delete PIInit";
|
||||
if (__instance__ != 0) {
|
||||
delete __instance__;
|
||||
__instance__ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Core::Core() {
|
||||
CONNECTU(&connection, dataReceivedEvent, this, dataReceived);
|
||||
PIString s(connection_config);
|
||||
connection.configureFromString(&s);
|
||||
// connection.start();
|
||||
connection.start();
|
||||
}
|
||||
|
||||
void CDUtils::test() {
|
||||
//piCoutObj << connection.makeConfig();
|
||||
piCoutObj << connection.boundedDevices().size();
|
||||
|
||||
void CDUtils::Core::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
piCout << from << data;
|
||||
}
|
||||
|
||||
|
||||
void Core::K_Send() {
|
||||
|
||||
}
|
||||
49
cd_utils/cdutils_core.h
Normal file
49
cd_utils/cdutils_core.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef CDUTILS_CORE_H
|
||||
#define CDUTILS_CORE_H
|
||||
|
||||
#include "cdutils_k_types.h"
|
||||
#include "piconnection.h"
|
||||
#include "pidatatransfer.h"
|
||||
|
||||
|
||||
namespace CDUtils {
|
||||
|
||||
class Core;
|
||||
|
||||
|
||||
class __Core_Initializer__ {
|
||||
public:
|
||||
__Core_Initializer__();
|
||||
~__Core_Initializer__();
|
||||
static int count_;
|
||||
static Core * __instance__;
|
||||
};
|
||||
|
||||
|
||||
class Core: public PIObject
|
||||
{
|
||||
PIOBJECT(CDUtils::Core)
|
||||
friend class __Core_Initializer__;
|
||||
public:
|
||||
static Core * instance() {return __Core_Initializer__::__instance__;}
|
||||
|
||||
EVENT(K_Received)
|
||||
EVENT_HANDLER(void, K_Send);
|
||||
|
||||
private:
|
||||
Core();
|
||||
EVENT_HANDLER2(void, dataReceived, const PIString &, from, const PIByteArray &, data);
|
||||
|
||||
PIConnection connection;
|
||||
|
||||
KSection k_plain;
|
||||
PIMap<int, PIMap<int, KSection> > k_sections; // [enum KSection][index] = CDUtils::KSection
|
||||
|
||||
};
|
||||
|
||||
|
||||
static __Core_Initializer__ __Core_initializer__;
|
||||
|
||||
}
|
||||
|
||||
#endif // CDUTILS_CORE_H
|
||||
59
cd_utils/cdutils_k_types.h
Normal file
59
cd_utils/cdutils_k_types.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef CDUTILS_K_TYPES_H
|
||||
#define CDUTILS_K_TYPES_H
|
||||
|
||||
#include "pistring.h"
|
||||
|
||||
namespace CDUtils {
|
||||
|
||||
|
||||
class KType {
|
||||
public:
|
||||
KType() {
|
||||
value_d = 0.;
|
||||
value_i = 0;
|
||||
value_b = false;
|
||||
}
|
||||
KType(const PIString & v, const PIString & f, const PIString & c) {
|
||||
value_s = v;
|
||||
formula_ = f;
|
||||
comment_ = c;
|
||||
value_d = v.toDouble();
|
||||
value_i = v.toInt();
|
||||
value_b = v.toBool();
|
||||
}
|
||||
|
||||
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:
|
||||
PIString value_s, formula_, comment_;
|
||||
double value_d;
|
||||
int value_i;
|
||||
bool value_b;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class KSection {
|
||||
friend class Core;
|
||||
public:
|
||||
bool test(int v) {return k.value(v).toBool();}
|
||||
KType operator [](int v) const {return k[v];}
|
||||
|
||||
private:
|
||||
KSection(PIMap<int, KType> k_ = PIMap<int, KType>()) {k = k_;}
|
||||
|
||||
PIMap<int, KType> k;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // CDUTILS_K_TYPES_H
|
||||
@@ -1,9 +1,13 @@
|
||||
#include "cdutils.h"
|
||||
#include "cdutils_core.h"
|
||||
#include "piethernet.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
CDUtils cd;
|
||||
PIEthernet eth;
|
||||
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:36102", PIByteArray("data\n", 5));
|
||||
piMSleep(1000);
|
||||
cd.test();
|
||||
//CDUtils::Core::instance()->test();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user