OpcUaCanOpen
CANopen OPC-UA server
NodeGuardingInterval.cpp
Go to the documentation of this file.
1 #include "NodeGuardingInterval.h"
2 //#include "BuildingAutomationTypeIds.h"
3 #include "uadatetime.h"
4 #include "uabasenodes.h"
5 #include "CanBusObject.h"
6 #include "CanNodeObject.h"
7 #include <thread>
8 
9 using namespace UserDevice;
10 namespace CanOpen
11 {
12  /* ----------------------------------------------------------------------------
13  Begin Class BaCommunicationInterface
14  constructor / destructor
15  -----------------------------------------------------------------------------*/
16  NodeGuardingInterval::NodeGuardingInterval(CanBusObject *pCI,OpcUa::BaseVariableType* pVar )
17  {
18  m_stop = OpcUa_False;
19  m_iNgIntervalVariable = pVar;
20  m_pCanIn = pCI;
21 // start();
22  }
23 
24  NodeGuardingInterval::~NodeGuardingInterval()
25  {
26  // Signal Simulation Thread to stop
27  m_stop = OpcUa_True;
28  // Wait until main Thread stopped
29  wait(2);
30  }
31 
32 
38  void NodeGuardingInterval::run()
39  {
40  UaDataValue dSync;
41  while( m_stop == OpcUa_False )
42  {
43 
44  if (m_iNgIntervalVariable != 0) {
45  dSync = m_iNgIntervalVariable->value(NULL);
46  const OpcUa_Variant *vSync = dSync.value();
47  OpcUa_UInt32 tInterval = vSync->Value.UInt32;
48 
49  if (tInterval > 0 ) {
50 
51  for (busNodes::iterator cnoi = m_pCanIn->getListNodes().begin(); cnoi != m_pCanIn->getListNodes().end(); cnoi++)
52  {
53  m_pCanIn->lock();
54  (*cnoi).second->sendNG();
55  (*cnoi).second->decNGCounter();
56  m_pCanIn->unlock();
57  }
58 
59  if (!m_stop) {
60  LOG(Log::DBG, NGMessage) << "Interval =" << tInterval;
61  std::this_thread::sleep_for(std::chrono::milliseconds(tInterval));
62  }
63  }
64  else if (!m_stop)
65  std::this_thread::sleep_for(std::chrono::seconds(10));
66  //UaThread::sleep(10);
67  }
68  else
69  if (!m_stop)
70  std::this_thread::sleep_for(std::chrono::seconds(10));
71  }
72  }
73 }
74