17#ifndef OPCUAExchange_H_
18#define OPCUAExchange_H_
27#include "ThreadCreator.h"
28#include "PassiveTimer.h"
30#include "IONotifyController.h"
31#include "UniSetObject.h"
33#include "MessageType.h"
34#include "SMInterface.h"
36#include "SharedMemory.h"
38#include "DebugStream.h"
39#include "LogAgregator.h"
40#include "OPCUAClient.h"
43#define vmonit( var ) vmon.add( #var, var )
154 static std::shared_ptr<OPCUAExchange> init_opcuaexchange(
int argc,
const char*
const* argv,
156 const std::string& prefix =
"opcua");
158 static void help_print(
int argc,
const char*
const* argv );
162 static uint8_t firstBit( uint32_t mask );
165 static uint32_t getBits( uint32_t value, uint32_t mask, uint8_t offset );
167 static uint32_t setBits( uint32_t value, uint32_t set, uint32_t mask, uint8_t offset );
169 static uint32_t forceSetBits( uint32_t value, uint32_t set, uint32_t mask, uint8_t offset );
171 using Tick = uint8_t;
173 static const size_t numChannels = 2;
176 std::vector<OPCUAClient::ResultVar> results;
177 std::vector<UA_ReadValueId> ids;
181 std::vector<UA_WriteValue> ids;
198 uint32_t mask = { 0 };
199 uint8_t offset = { 0 };
200 OPCUAClient::VarType vtype = { OPCUAClient::VarType::Int32 };
206 int32_t set(
float val );
208 std::string attrName = {
""};
211 std::shared_ptr<ReadGroup> gr;
212 size_t grIndex = {0};
216 UA_StatusCode status();
222 std::shared_ptr<WriteGroup> gr;
223 size_t grIndex = {0};
224 bool set( int32_t val );
225 bool setF(
float val );
227 UA_StatusCode status();
228 const UA_WriteValue& ref();
229 static void init( UA_WriteValue* wval,
const std::string& nodeId,
const std::string& type, int32_t defvalue );
233 friend std::ostream& operator<<(std::ostream& os,
const OPCAttribute& inf );
234 friend std::ostream& operator<<(std::ostream& os,
const std::shared_ptr<OPCAttribute>& inf );
256 void channel1Thread();
257 void channel2Thread();
258 void channelThread( Channel* ch );
260 void channelExchange( Tick tick, Channel* ch,
bool writeOn );
261 void updateFromChannel( Channel* ch );
262 void updateToChannel( Channel* ch );
265 bool isUpdateSM(
bool wrFunc )
const noexcept;
268 virtual void askSensors( UniversalIO::UIOCommand cmd );
275 void readConfiguration();
276 bool initIOItem( UniXML::iterator& it );
277 bool readItem(
const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
279 bool tryConnect(Channel* ch);
286 typedef std::vector< std::shared_ptr<OPCAttribute> > IOList;
288 size_t maxItem = { 0 };
294 std::shared_ptr<OPCUAClient> client;
297 std::atomic_bool status = {
false };
301 std::unordered_map<Tick, std::shared_ptr<ReadGroup>> readValues;
302 std::unordered_map<Tick, std::shared_ptr<WriteGroup>> writeValues;
304 IOController::IOStateList::iterator respond_it;
308 std::atomic_uint32_t currentChannel = { 0 };
310 uniset::timeout_t reconnectPause = { 10000 };
311 int filtersize = { 0 };
312 float filterT = { 0.0 };
315 std::string s_fvalue;
316 std::optional<std::regex> s_fvalue_re;
318 std::shared_ptr<SMInterface> shm;
320 std::string prop_prefix;
322 PassiveTimer ptHeartBeat;
324 int maxHeartBeat = { 10 };
325 IOController::IOStateList::iterator itHeartBeat;
332 std::atomic_bool activated = {
false };
333 std::atomic_bool cancelled = {
false };
334 std::atomic_bool readconf_ok = {
false };
338 IOController::IOStateList::iterator itRespond;
340 std::shared_ptr<LogAgregator> loga;
341 std::shared_ptr<DebugStream> opclog;
342 std::shared_ptr<LogServer> logserv;
343 std::string logserv_host = {
""};
344 int logserv_port = {0};
346 std::shared_ptr< ThreadCreator<OPCUAExchange> > thrChannel[numChannels];
349 IOController::IOStateList::iterator itExchangeMode;
Definition OPCUAExchange.h:149
timeout_t smReadyTimeout
Definition OPCUAExchange.h:330
bool writeToAllChannels
Definition OPCUAExchange.h:329
uniset::ObjectId sidExchangeMode
Definition OPCUAExchange.h:348
bool force
Definition OPCUAExchange.h:327
timeout_t updatetime
Definition OPCUAExchange.h:284
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации)
Definition OPCUAExchange.cc:1219
bool force_out
Definition OPCUAExchange.h:328
xmlNode * confnode
Definition OPCUAExchange.h:282
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
Definition OPCUAExchange.cc:1233
IOList iolist
Definition OPCUAExchange.h:287
timeout_t polltime
Definition OPCUAExchange.h:283
ExchangeMode
Definition OPCUAExchange.h:239
@ emSkipExchange
Definition OPCUAExchange.h:244
@ emNone
Definition OPCUAExchange.h:240
@ emWriteOnly
Definition OPCUAExchange.h:241
@ emSkipSaveToSM
Definition OPCUAExchange.h:243
@ emReadOnly
Definition OPCUAExchange.h:242
long exchangeMode
Definition OPCUAExchange.h:350
Пассивный таймер
Definition PassiveTimer.h:94
Definition MessageType.h:127
Definition MessageType.h:171
Definition MessageType.h:214
Definition UniSetObject.h:80
Definition VMonitor.h:117
Definition Calibration.h:27
const ObjectId DefaultObjectId
Definition UniSetTypes.h:71
long ObjectId
Definition UniSetTypes_i.idl:30
Definition OPCUAExchange.h:291
Definition OPCUAExchange.h:210
Definition OPCUAExchange.h:221
Definition OPCUAExchange.h:186
Definition OPCUAExchange.h:175
Definition OPCUAExchange.h:180
Definition UniSetTypes_i.idl:65