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 )
185 const std::string& _prefix =
"opcua" );
188 static std::shared_ptr<OPCUAExchange> init_opcuaexchange(
int argc,
const char*
const* argv,
190 const std::string& prefix =
"opcua");
192 static void help_print(
int argc,
const char*
const* argv );
196 static uint8_t firstBit( uint32_t mask );
199 static uint32_t getBits( uint32_t value, uint32_t mask, uint8_t offset );
201 static uint32_t setBits( uint32_t value, uint32_t set, uint32_t mask, uint8_t offset );
203 static uint32_t forceSetBits( uint32_t value, uint32_t set, uint32_t mask, uint8_t offset );
205 using Tick = uint8_t;
207 static const size_t numChannels = 2;
210 std::vector<std::vector<OPCUAClient::ResultVar>> results;
211 std::vector<std::vector<UA_ReadValueId>> ids;
215 std::vector<std::vector<UA_WriteValue>> ids;
232 uint32_t mask = { 0 };
233 uint8_t offset = { 0 };
234 OPCUAClient::VarType vtype = { OPCUAClient::VarType::Int32 };
240 int32_t set(
float val );
242 std::string attrName = {
""};
245 std::shared_ptr<ReadGroup> gr;
246 size_t grIndex = {0};
247 size_t grNumber = {0};
251 UA_StatusCode status();
252 const UA_ReadValueId& ref();
254 uint32_t subscriptionId = {0U};
255 uint32_t monitoredItemId = {0U};
256 bool subscriptionState = {
false};
262 std::shared_ptr<WriteGroup> gr;
263 size_t grIndex = {0};
264 size_t grNumber = {0};
265 bool set( int32_t val );
266 bool setF(
float val );
268 UA_StatusCode status();
269 const UA_WriteValue& ref();
270 static void init( UA_WriteValue* wval,
const std::string& nodeId,
const std::string& type, int32_t defvalue );
274 friend std::ostream& operator<<(std::ostream& os,
const OPCAttribute& inf );
275 friend std::ostream& operator<<(std::ostream& os,
const std::shared_ptr<OPCAttribute>& inf );
298 typedef std::list<IOBase> ThresholdList;
301 ThresholdList thrlist;
311 void channel1Thread();
312 void channel2Thread();
313 void channelThread( Channel* ch );
315 void channelExchange( Tick tick, Channel* ch,
bool writeOn );
316 void updateFromChannel( Channel* ch );
317 void updateToChannel( Channel* ch );
320 bool isUpdateSM(
bool wrFunc )
const noexcept;
323 virtual void askSensors( UniversalIO::UIOCommand cmd );
330 void readConfiguration();
331 bool initIOItem( UniXML::iterator& it );
332 bool readItem(
const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
334 bool tryConnect(Channel* ch);
336 void createSubscription(
int nchannel);
342 typedef std::vector< std::shared_ptr<OPCAttribute> > IOList;
344 size_t maxItem = { 0 };
345 size_t maxReadItems = { 0 };
346 size_t maxWriteItems = { 0 };
352 std::shared_ptr<OPCUAClient> client;
355 std::atomic_bool status = {
false };
359 std::unordered_map<Tick, std::shared_ptr<ReadGroup>> readValues;
360 std::unordered_map<Tick, std::shared_ptr<WriteGroup>> writeValues;
362 IOController::IOStateList::iterator respond_it;
366 std::atomic_uint32_t currentChannel = { 0 };
368 uniset::timeout_t reconnectPause = { 10000 };
369 int filtersize = { 0 };
370 float filterT = { 0.0 };
373 std::string s_fvalue;
374 std::optional<std::regex> s_fvalue_re;
376 std::shared_ptr<SMInterface> shm;
377 std::string prop_prefix;
378 const std::string argprefix;
380 PassiveTimer ptHeartBeat;
382 int maxHeartBeat = { 10 };
383 IOController::IOStateList::iterator itHeartBeat;
389 bool enableSubscription = {
false};
390 double publishingInterval = { 0.0 };
391 double samplingInterval = { -1.0 };
392 uint16_t timeoutIterate = {100};
395 std::atomic_bool subscription_ok = {
false};
397 std::atomic_bool activated = {
false };
398 std::atomic_bool cancelled = {
false };
399 std::atomic_bool readconf_ok = {
false };
404 IOController::IOStateList::iterator itRespond;
406 std::shared_ptr<LogAgregator> loga;
407 std::shared_ptr<DebugStream> opclog;
408 std::shared_ptr<LogServer> logserv;
409 std::string logserv_host = {
""};
410 int logserv_port = {0};
412 std::shared_ptr< ThreadCreator<OPCUAExchange> > thrChannel[numChannels];
415 IOController::IOStateList::iterator itExchangeMode;
Definition OPCUAExchange.h:181
timeout_t smReadyTimeout
Definition OPCUAExchange.h:388
bool writeToAllChannels
Definition OPCUAExchange.h:387
uniset::ObjectId sidExchangeMode
Definition OPCUAExchange.h:414
bool force
Definition OPCUAExchange.h:385
timeout_t updatetime
Definition OPCUAExchange.h:340
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации)
Definition OPCUAExchange.cc:1371
bool force_out
Definition OPCUAExchange.h:386
uint16_t stopOnError
Definition OPCUAExchange.h:393
xmlNode * confnode
Definition OPCUAExchange.h:338
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
Definition OPCUAExchange.cc:1385
IOList iolist
Definition OPCUAExchange.h:343
uint32_t connectCount
Definition OPCUAExchange.h:394
timeout_t polltime
Definition OPCUAExchange.h:339
StopMode
Definition OPCUAExchange.h:291
@ smFirstOnly
Definition OPCUAExchange.h:293
@ smAny
Definition OPCUAExchange.h:294
@ smNone
Definition OPCUAExchange.h:292
ExchangeMode
Definition OPCUAExchange.h:280
@ emSkipExchange
Definition OPCUAExchange.h:285
@ emNone
Definition OPCUAExchange.h:281
@ emWriteOnly
Definition OPCUAExchange.h:282
@ emSkipSaveToSM
Definition OPCUAExchange.h:284
@ emReadOnly
Definition OPCUAExchange.h:283
long exchangeMode
Definition OPCUAExchange.h:416
Пассивный таймер
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:349
Definition OPCUAExchange.h:244
Definition OPCUAExchange.h:261
Definition OPCUAExchange.h:220
Definition OPCUAExchange.h:209
Definition OPCUAExchange.h:214
Definition UniSetTypes_i.idl:65