OpcUaCanOpen
CANopen OPC-UA server
SyncInterval.cpp
Go to the documentation of this file.
1 #include "SyncInterval.h"
2 #include "uadatetime.h"
3 #include "CanBusObject.h"
4 #include <thread>
5 
6 namespace CanOpen
7 {
13  SyncInterval::SyncInterval(CanBusObject *pCI,OpcUa::BaseVariableType* pVar )
14  {
15  m_stop = OpcUa_False;
16  m_iSyncIntervalVariable = pVar; //sync interval
17  m_pCanIn = pCI; // can bus
18 // start();
19  }
20 
22  {
23  // Signal SyncInterval Thread to stop
24  m_stop = OpcUa_True;
25  // Wait until SyncInterval Thread stopped
26  wait(1);
27  }
28 
29 
36  {
37  UaDataValue dSync;
38  // UaDateTime lastSimulation = UaDateTime::now();
39  while( m_stop == OpcUa_False )
40  {
41  if (m_iSyncIntervalVariable != 0) {
42 
43  dSync = m_iSyncIntervalVariable->value(NULL);
44  const OpcUa_Variant *vSync = dSync.value();
45  OpcUa_Int32 tInterval = vSync->Value.Int32;
46  if (tInterval != 0 ) {
47  m_pCanIn->lock();
48  m_pCanIn->sendSync();
49  m_pCanIn->unlock();
50  if (!m_stop)
51  std::this_thread::sleep_for(std::chrono::milliseconds(tInterval));
52 
53 // if (!m_stop) UaThread::msleep(tInterval);
54  }
55  else if (!m_stop)
56  std::this_thread::sleep_for(std::chrono::seconds(10));
57 // UaThread::sleep(10);
58  }
59  else
60  if (!m_stop)
61  std::this_thread::sleep_for(std::chrono::seconds(10));
62 // UaThread::sleep(10);
63  }
64  }
65 }