181 private USingleProcess,
187 const std::string& _prefix =
"opcua" );
188 virtual ~OPCUAExchange();
190 static std::shared_ptr<OPCUAExchange> init_opcuaexchange(
int argc,
const char*
const* argv,
192 const std::string& prefix =
"opcua");
194 static void help_print(
int argc,
const char*
const* argv );
198 static uint8_t firstBit( uint32_t mask );
201 static uint32_t getBits( uint32_t value, uint32_t mask, uint8_t offset );
203 static uint32_t setBits( uint32_t value, uint32_t set, uint32_t mask, uint8_t offset );
205 static uint32_t forceSetBits( uint32_t value, uint32_t set, uint32_t mask, uint8_t offset );
207 using Tick = uint8_t;
209 static const size_t numChannels = 2;
212 std::vector<std::vector<OPCUAClient::ResultVar>> results;
213 std::vector<std::vector<UA_ReadValueId>> ids;
217 std::vector<std::vector<UA_WriteValue>> ids;
225 OPCAttribute(
const OPCAttribute& r ) =
delete;
226 OPCAttribute& operator=(
const OPCAttribute& r) =
delete;
227 OPCAttribute(OPCAttribute&& r ) =
default;
228 OPCAttribute& operator=(OPCAttribute&& r) =
default;
229 OPCAttribute() =
default;
234 uint32_t mask = { 0 };
235 uint8_t offset = { 0 };
236 OPCUAClient::VarType vtype = { OPCUAClient::VarType::Int32 };
242 int32_t set(
float val );
244 std::string attrName = {
""};
247 std::shared_ptr<ReadGroup> gr;
248 size_t grIndex = {0};
249 size_t grNumber = {0};
253 UA_StatusCode status();
254 const UA_ReadValueId& ref();
256 uint32_t subscriptionId = {0U};
257 uint32_t monitoredItemId = {0U};
258 bool subscriptionState = {
false};
264 std::shared_ptr<WriteGroup> gr;
265 size_t grIndex = {0};
266 size_t grNumber = {0};
267 bool set( int32_t val );
268 bool setF(
float val );
270 UA_StatusCode status();
271 const UA_WriteValue& ref();
272 static void init( UA_WriteValue* wval,
const std::string& nodeId,
const std::string& type, int32_t defvalue );
276 friend std::ostream& operator<<(std::ostream& os,
const OPCAttribute& inf );
277 friend std::ostream& operator<<(std::ostream& os,
const std::shared_ptr<OPCAttribute>& inf );
300 typedef std::list<IOBase> ThresholdList;
303 ThresholdList thrlist;
305#ifndef DISABLE_REST_API
307 virtual Poco::JSON::Object::Ptr httpHelp(
const Poco::URI::QueryParameters& p )
override;
308 virtual Poco::JSON::Object::Ptr httpRequest(
const std::string& req,
const Poco::URI::QueryParameters& p )
override;
319 void channel1Thread();
320 void channel2Thread();
321 void channelThread( Channel* ch );
323 void channelExchange( Tick tick, Channel* ch,
bool writeOn );
324 void updateFromChannel( Channel* ch );
325 void updateToChannel( Channel* ch );
328 bool isUpdateSM(
bool wrFunc )
const noexcept;
331 virtual void askSensors( UniversalIO::UIOCommand cmd );
337#ifndef DISABLE_REST_API
339 Poco::JSON::Object::Ptr httpGetParam(
const Poco::URI::QueryParameters& p );
340 Poco::JSON::Object::Ptr httpSetParam(
const Poco::URI::QueryParameters& p );
341 Poco::JSON::Object::Ptr httpStatus();
344 bool httpEnabledSetParams {
true };
349 void readConfiguration();
350 bool initIOItem( UniXML::iterator& it );
351 bool readItem(
const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
355 void createSubscription(
int nchannel);
361 typedef std::vector< std::shared_ptr<OPCAttribute> > IOList;
363 size_t maxItem = { 0 };
364 size_t maxReadItems = { 0 };
365 size_t maxWriteItems = { 0 };
371 std::shared_ptr<OPCUAClient> client;
374 std::atomic_bool status = {
false };
378 std::unordered_map<Tick, std::shared_ptr<ReadGroup>> readValues;
379 std::unordered_map<Tick, std::shared_ptr<WriteGroup>> writeValues;
381 IOController::IOStateList::iterator respond_it;
385 std::atomic_uint32_t currentChannel = { 0 };
387 uniset::timeout_t reconnectPause = { 10000 };
388 int filtersize = { 0 };
389 float filterT = { 0.0 };
392 std::string s_fvalue;
393 std::optional<std::regex> s_fvalue_re;
395 std::shared_ptr<SMInterface> shm;
396 std::string prop_prefix;
397 const std::string argprefix;
399 PassiveTimer ptHeartBeat;
401 int maxHeartBeat = { 10 };
402 IOController::IOStateList::iterator itHeartBeat;
408 bool enableSubscription = {
false};
409 double publishingInterval = { 0.0 };
410 double samplingInterval = { -1.0 };
411 uint16_t timeoutIterate = {100};
414 std::atomic_bool subscription_ok = {
false};
416 std::atomic_bool activated = {
false };
417 std::atomic_bool cancelled = {
false };
418 std::atomic_bool readconf_ok = {
false };
423 IOController::IOStateList::iterator itRespond;
425 std::shared_ptr<LogAgregator> loga;
426 std::shared_ptr<DebugStream> opclog;
427 std::shared_ptr<LogServer> logserv;
428 std::string logserv_host = {
""};
429 int logserv_port = {0};
431 std::shared_ptr< ThreadCreator<OPCUAExchange> > thrChannel[numChannels];
434 IOController::IOStateList::iterator itExchangeMode;