openETCS
case study for the European Train Control System developed for the authors dissertation
WrapperFunctions.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010-2012
3  Johannes Feuser <feuser@uni-bremen.de>
4  This file is part of the openETCS library.
5 
6  The openETCS library is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  any later version.
10 
11  The openETCS library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with the openETCS library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /*!
21  * \author Johannes Feuser <feuser@uni-bremen.de>
22  * \brief C wrapper functions for the simulative PSM classes
23  */
24 
25 #include "WrapperFunctions.h"
26 
27 
28 
29 
30 /*!
31  * \brief module global odometer object
32  */
33 static ::oETCS::DF::PS::SIM::COdometer* m_pOdometer = 0;
34 
35 
36 
37 /*!
38  * \brief module global emergency brake object
39  */
40 static ::oETCS::DF::PS::SIM::CEmergencyBrake* m_pEmergencyBrake = 0;
41 
42 
43 
44 /*!
45  * \brief module global service brake object
46  */
47 static ::oETCS::DF::PS::SIM::CServiceBrake* m_pServiceBrake = 0;
48 
49 
50 
51 /*!
52  * \brief module global balise out device object
53  */
54 static ::oETCS::DF::PS::SIM::CBaliseDeviceOut* m_pBaliseOutDevice = 0;
55 
56 
57 
58 /*!
59  * \brief module global balise in device object
60  */
61 static ::oETCS::DF::PS::SIM::CBaliseDeviceIn* m_pBaliseInDevice = 0;
62 
63 
64 
65 /*!
66  * \brief module global DMI interface/proxy
67  */
68 static ::oETCS::DF::IDMI* m_pDMI = 0;
69 
70 
71 
72 
73 const int G_TELEGRAM_LEVEL_0_TO_1[] = {1, 0,0,1,0,1,1,1, 0, 0,0,0, 0,0,0, 0,0, 0,0,0,0,0,0,0,1, 0,0,0,0,0,0,0,0,1,1, 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
74  0,0,1,0,1,0,0,1, 1,0, 0,0,0,0,0,0,1,1,1,1,0,0,1, 0,1, 0,0,0,0,0,1,1,1,1,1,0,1,0,0,0, 0,1,0, 0,0,0,0,0,1,1,0,0,1,0,0,0,0,0, 0,0,0,0,0,
75  1,1,1,1,1,1,1,1
76  };
77 
78 
79 
80 
81 
82 
83 const int G_SIZE_TELEGRAM_LEVEL_0_TO_1 = 50 + 63 + 8;
84 
85 
86 
87 
88 
89 
90 const int G_TELEGRAM_LEVEL_STOP_IN_SR[] = {1, 0,0,1,0,1,1,1, 0, 0,0,0, 0,0,0, 0,0, 0,0,0,0,0,0,0,1, 0,0,0,0,0,0,0,0,1,1, 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
91  1,0,0,0,1,0,0,1, 1,0, 0,0,0,0,0,0,1,0,1,0,0,1,0, 0,
92  1,1,1,1,1,1,1,1
93  };
94 
95 
96 
97 
98 
99 
100 const int G_SIZE_TELEGRAM_STOP_IN_SR = 50 + 24 + 8;
101 
102 
103 
104 
105 
106 void QAppThread(bool * pInitialised)
107 
108 {
109  // Bouml preserved body begin 000EFD82
110  ::AOdometer* pOdometer(nullptr);
111  ::AEmergencyBrake* pEmergencyBrake(nullptr);
112  ::AServiceBrake* pServiceBrake(nullptr);
113  ::ABaliseDeviceIn* pBaliseIn(nullptr);
114  ::ABaliseDeviceOut* pBaliseOut(nullptr);
115  bool bConnected(true);
116  int argc(0);
117  char** argv(nullptr);
118  QCoreApplication Application(argc, argv);
119  QDBusConnection Connection = QDBusConnection::sessionBus();
120 
121 
122  try
123  {
124  // create all simulation objects
125  m_pOdometer = new ::oETCS::DF::PS::SIM::COdometer;
126  m_pEmergencyBrake = new ::oETCS::DF::PS::SIM::CEmergencyBrake;
127  m_pServiceBrake = new ::oETCS::DF::PS::SIM::CServiceBrake(m_pOdometer, m_pEmergencyBrake);
128  m_pBaliseOutDevice = new ::oETCS::DF::PS::SIM::CBaliseDeviceOut;
129  m_pBaliseInDevice = new ::oETCS::DF::PS::SIM::CBaliseDeviceIn;
130 
131 
132  // create all adaptors objects
133  pOdometer = new ::AOdometer(m_pOdometer);
134  pEmergencyBrake = new ::AEmergencyBrake(m_pEmergencyBrake);
135  pServiceBrake = new ::AServiceBrake(m_pServiceBrake);
136  pBaliseOut = new ::ABaliseDeviceOut(m_pBaliseOutDevice);
137  pBaliseIn = new ::ABaliseDeviceIn(m_pBaliseInDevice);
138 
139 
140  // register all adaptors
141  bConnected &= Connection.registerService("oETCS.DF.IOdometer");
142  bConnected &= Connection.registerObject("/oETCS/Odometer", m_pOdometer);
143  bConnected &= Connection.registerService("oETCS.DF.IEmergencyBrake");
144  bConnected &= Connection.registerObject("/oETCS/EmergencyBrake", m_pEmergencyBrake);
145  bConnected &= Connection.registerService("oETCS.DF.IServiceBrake");
146  bConnected &= Connection.registerObject("/oETCS/ServiceBrake", m_pServiceBrake);
147  bConnected &= Connection.registerService("oETCS.DF.IBaliseDeviceIn");
148  bConnected &= Connection.registerObject("/oETCS/BaliseDeviceIn", m_pBaliseInDevice);
149  bConnected &= Connection.registerService("oETCS.DF.IBaliseDeviceOut");
150  bConnected &= Connection.registerObject("/oETCS/BaliseDeviceOut", m_pBaliseOutDevice);
151 
152 
153  // check, if all adaptors where registered successfully
154  if (not bConnected)
155  {
156  // print warning to stderr
157  ::std::cerr << "QAppThread: Could not register all adaptors!" << ::std::endl;
158 
159  } // if (not bConnected)
160 
161  // set initialised flag to true
162  *pInitialised = true;
163 
164  // print status to stdout
165  ::std::cout << "QAppThread: Executing adaptor event loop ..." << ::std::endl;
166 
167  // execute core application
168  QCoreApplication::exec();
169 
170  } // try
171  catch (const ::std::bad_alloc& Exception)
172  {
173  // print error to stderr
174  ::std::cerr << "Could not allocate all adaptor objects: " << Exception.what() << ::std::endl;
175 
176  } // catch (const ::std::bad_alloc& Exception)
177 
178  // delete all objects
179  delete (pOdometer);
180  delete (pEmergencyBrake);
181  delete (pServiceBrake);
182  delete (pBaliseIn);
183  delete (pBaliseOut);
184  delete (m_pOdometer);
185  delete (m_pEmergencyBrake);
186  delete (m_pServiceBrake);
187  delete (m_pBaliseOutDevice);
188  delete (m_pBaliseInDevice);
189  delete (m_pDMI);
190  // Bouml preserved body end 000EFD82
191 
192 } // void QAppThread()
193 
194 
195 
196 
197 
198 void InitPSM()
199 {
200  // Bouml preserved body begin 000EAB02
201  bool bInitialised(false);
202  ::std::thread* pAppThread(nullptr);
203 
204  // call thread function for QCoreApplication instance
205  pAppThread = new ::std::thread(QAppThread, &bInitialised);
206 
207  // check, if thread is joinable
208  if (pAppThread->joinable())
209  {
210  // wait until PSM is initialised
211  while (not bInitialised)
212  {
213  // yield this thread
214  ::std::this_thread::yield();
215 
216  } // while (not bInitialised)
217 
218  // detach thread from object
219  pAppThread->detach();
220 
221  // delete thread object
222  delete (pAppThread);
223 
224  } // if (pAppThread->joinable())
225  // Bouml preserved body end 000EAB02
226 
227 } // void WrapperFunctions::InitPSM() throw()
228 
229 
230 
231 
232 int InitDMI()
233 {
234  // Bouml preserved body begin 000F5582
235  bool bInitialised(true);
236 
237 
238 
239  // check, if DMI proxy is not yet created
240  if (m_pDMI == nullptr)
241  {
242  try
243  {
244  // create new interface proxy
245  m_pDMI = new ::oETCS::DF::IDMI(::oETCS::DF::IDMI::staticInterfaceName(), "/oETCS/DMI", QDBusConnection::sessionBus());
246 
247  // check, if proxy could be connected
248  if (not m_pDMI->isValid())
249  {
250  // print error from dbus to stderr
251  ::std::cerr << "::oETCS::DF::IDDMI had a problem with D-Bus connection: " << m_pDMI->lastError().message().toStdString() << ::std::endl;
252 
253  // delete proxy
254  delete m_pDMI;
255 
256  // reset proxy pointer
257  m_pDMI = 0;
258 
259  // set initialised flag to false
260  bInitialised = false;
261 
262  } // if (not m_pDMI->isValid())
263  else
264  {
265  // set timeout for all calls on interface
266  //m_pDMI->setTimeout(10);
267 
268  } // else
269 
270  } // try
271  catch (const ::std::bad_alloc& Exception)
272  {
273  // set initialised flag to false
274  bInitialised = false;
275 
276  } // catch (const ::std::bad_alloc& Exception)
277 
278  } // if (m_pDMI == nullptr)
279 
280 
281  // return init flag
282  return (bInitialised);
283  // Bouml preserved body end 000F5582
284 
285 } // int InitDMI()
286 
287 
288 
289 
291 {
292  // Bouml preserved body begin 000EAB82
293  int iHasInput(false);
294  QDBusPendingReply< bool > AsyncReply;
295 
296 
297  // call init DMI
298  InitDMI();
299 
300  // check, if DMI proxy is available
301  if (m_pDMI != nullptr)
302  {
303  // get HasInput via proxy
304  AsyncReply = m_pDMI->HasInput();
305 
306  // wait for asynchronous call to be finished
307  AsyncReply.waitForFinished();
308 
309  // check, if replay was valid
310  if (not AsyncReply.isValid())
311  {
312  // print error
313  ::std::cerr << "error while calling remote method IDMI::HasInput() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
314 
315  } // if (not AsyncReply.isValid())
316 
317  // get velocity from reply
318  iHasInput = AsyncReply.value() ? 1 : 0;
319 
320  } // if (m_pDMI != nullptr)
321  else
322  {
323  // print error
324  ::std::cerr << "could not establish connection to DMI adaptor" << ::std::endl;
325 
326  } // else
327 
328  // return input flag
329  return (iHasInput);
330  // Bouml preserved body end 000EAB82
331 
332 } // intDMIHasInput()
333 
334 
335 
336 
337 void GetDMIOutput(const char * const pName, char ** const ppValue)
338 {
339  // Bouml preserved body begin 000F6F02
340  QDBusPendingReply< QString > AsyncReply;
341  const QString NAME(pName);
342 
343 
344 
345 
346  // call init DMI
347  InitDMI();
348 
349  // check, if DMI proxy is available
350  if (m_pDMI != nullptr)
351  {
352 
353  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
354  // DEBUG
355  ::std::cout << "DEBUG: in GetDMIOutput() -> calling IDMI::GetDMIOutput(\"" << pName << "\")..." << ::std::flush;
356  #endif
357 
358  // call method via proxy
359  AsyncReply = m_pDMI->GetOutputValue(NAME);
360 
361  // wait for asynchronous call to be finished
362  AsyncReply.waitForFinished();
363 
364  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
365  // DEBUG
366  ::std::cout << "done" << ::std::endl;
367  #endif
368 
369  // check, if reply was valid
370  if (not AsyncReply.isValid())
371  {
372  // print error
373  ::std::cerr << "error while calling remote method IDMI::GetOutputValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
374 
375  } // if (not AsyncReply.isValid())
376  else
377  {
378  // check, if pointer to pointer and pointer are valid
379  if (ppValue != nullptr && *ppValue != nullptr)
380  {
381  // delete pointer
382  delete (*ppValue);
383 
384  } // if (ppValue != nullptr && *ppValue != nullptr)
385 
386  // allocate memory for value pointer
387  *ppValue = new (char[AsyncReply.value().size()]);
388 
389  // store reply in return value
390  strcpy(*ppValue, AsyncReply.value().toStdString().c_str());
391 
392  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
393  // DEBUG
394  ::std::cout << "DEBUG: value of output filed \"" << pName << "\": \"" << *ppValue << "\"" << ::std::endl;
395  #endif
396 
397  } // else
398 
399  } // if (m_pDMI != nullptr)
400  else
401  {
402  // print error
403  ::std::cerr << "could not establish connection to DMI adaptor" << ::std::endl;
404 
405  } // else
406  // Bouml preserved body end 000F6F02
407 
408 } // void WrapperFunctions::GetDMIOutput()
409 
410 
411 
412 
413 void SetDMIBooleanValue(const char * const pInputName, int iValue)
414 {
415  // Bouml preserved body begin 000EE382
416  QDBusPendingReply<> AsyncReply;
417 
418 
419 
420  // call init DMI
421  InitDMI();
422 
423  // check, if DMI proxy is available
424  if (m_pDMI != nullptr)
425  {
426  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
427  // DEBUG
428  ::std::cout << "DEBUG: calling IDMI::SetBooleanValue()..." << ::std::flush;
429  #endif
430 
431  // call method via proxy
432  AsyncReply = m_pDMI->SetBooleanValue(pInputName, iValue == 0 ? false : true);
433 
434  // wait for asynchronous call to be finished
435  AsyncReply.waitForFinished();
436 
437  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
438  // DEBUG
439  ::std::cout << "done" << ::std::endl;
440  #endif
441 
442  // check, if replay was valid
443  if (not AsyncReply.isValid())
444  {
445  // print error
446  ::std::cerr << "error while calling remote method IDMI::SetBooleanValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
447 
448  } // if (not AsyncReply.isValid())
449 
450  } // if (m_pDMI != nullptr)
451  else
452  {
453  // print error
454  ::std::cerr << "could not establish connection to DMI adaptor" << ::std::endl;
455 
456  } // else
457  // Bouml preserved body end 000EE382
458 
459 } // void SetDMIBooleanValue()
460 
461 
462 
463 
464 void SetDMIIntegerValue(const char * const pInputName, int iValue)
465 {
466  // Bouml preserved body begin 000EE402
467  QDBusPendingReply<> AsyncReply;
468 
469 
470 
471  // call init DMI
472  InitDMI();
473 
474  // check, if DMI proxy is available
475  if (m_pDMI != nullptr)
476  {
477  // call method via proxy
478  AsyncReply = m_pDMI->SetIntegerValue(pInputName, iValue);
479 
480  // wait for asynchronous call to be finished
481  AsyncReply.waitForFinished();
482 
483  // check, if replay was valid
484  if (not AsyncReply.isValid())
485  {
486  // print error
487  ::std::cerr << "error while calling remote method IDMI::SetIntegerValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
488 
489  } // if (not AsyncReply.isValid())
490 
491  } // if (m_pDMI != nullptr)
492  else
493  {
494  // print error
495  ::std::cerr << "could not establish connection to DMI adaptor" << ::std::endl;
496 
497  } // else
498  // Bouml preserved body end 000EE402
499 
500 } // void SetDMIIntegerValue()
501 
502 
503 
504 
505 void SetDMIDoubleValue(const char * const pInputName, double dValue)
506 {
507  // Bouml preserved body begin 000F8902
508  QDBusPendingReply<> AsyncReply;
509 
510 
511 
512  // call init DMI
513  InitDMI();
514 
515  // check, if DMI proxy is available
516  if (m_pDMI != nullptr)
517  {
518  // call method via proxy
519  AsyncReply = m_pDMI->SetDoubleValue(pInputName, dValue);
520 
521  // wait for asynchronous call to be finished
522  AsyncReply.waitForFinished();
523 
524  // check, if replay was valid
525  if (not AsyncReply.isValid())
526  {
527  // print error
528  ::std::cerr << "error while calling remote method IDMI::SetDoubleValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
529 
530  } // if (not AsyncReply.isValid())
531 
532  } // if (m_pDMI != nullptr)
533  else
534  {
535  // print error
536  ::std::cerr << "could not establish connection to DMI adaptor" << ::std::endl;
537 
538  } // else
539  // Bouml preserved body end 000F8902
540 
541 } // void SetDMIDoubleValue()
542 
543 
544 
545 
546 void SetDMIStringValue(const char * const pInputName, const char * const pValue)
547 {
548  // Bouml preserved body begin 000F8882
549  QDBusPendingReply<> AsyncReply;
550 
551 
552 
553 
554  // call init DMI
555  InitDMI();
556 
557  // check, if DMI proxy is available
558  if (m_pDMI != nullptr)
559  {
560  // call method via proxy
561  AsyncReply = m_pDMI->SetStringValue(pInputName, pValue);
562 
563  // wait for asynchronous call to be finished
564  AsyncReply.waitForFinished();
565 
566  // check, if replay was valid
567  if (not AsyncReply.isValid())
568  {
569  // print error
570  ::std::cerr << "error while calling remote method IDMI::SetStringValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
571 
572  } // if (not AsyncReply.isValid())
573 
574  } // if (m_pDMI != nullptr)
575  else
576  {
577  // print error
578  ::std::cerr << "could not establish connection to DMI adaptor" << ::std::endl;
579 
580  } // else
581  // Bouml preserved body end 000F8882
582 
583 } // voidSetDMIStringValue()
584 
585 
586 
587 
588 void SetNewInputTelegram(char * pTelegram, int iBits)
589 {
590  // Bouml preserved body begin 000EE302
591  ::QBitArray Telegram(iBits, false);
592  int x(0);
593  char* pByte(pTelegram);
594 
595 
596  // copy telegram bit-wise
597  for (x = 0; x < iBits; x++)
598  {
599  // set current bit from current byte
600  Telegram[x] = ((*pByte) & (1 << (x - (pTelegram - pByte) * 8))) == 0 ? false : true;
601 
602  // check, if 8 bits were copied
603  if (x - (pTelegram - pByte) * 8 == 7)
604  {
605  // increase byte pointer
606  pByte++;
607 
608  } // if (x - (pTelegram - pByte) * 8 == 7)
609 
610  } // for (x = 0; x < iBits; x++)
611 
612 
613  // set telegram in balise in device object
615  // Bouml preserved body end 000EE302
616 
617 } // void SetNewInputTelegram() throw()
618 
619 
620 
621 
622 void SetNewInputTelegramBinary(const int * const pTelegram, int iBits)
623 {
624  // Bouml preserved body begin 000FA282
625  ::QBitArray Telegram(iBits, false);
626  int x(0);
627 
628 
629  // DEBUG
630  //::std::cout << "SetNewInputTelegramBinary() started: " << ::std::flush;
631 
632  // copy telegram bit-wise
633  for (x = 0; x < iBits; x++)
634  {
635  // set current bit from current byte
636  Telegram[x] = pTelegram[x] == 0 ? false : true;
637 
638  // DEBUG
639  //::std::cout << Telegram[x] << " " << ::std::flush;
640 
641  } // for (x = 0; x < iBits; x++)
642 
643  // DEBUG
644  //::std::cout << ::std::endl;
645 
646  // set telegram in balise in device object
648  // Bouml preserved body end 000FA282
649 
650 } // void SetNewInputTelegramBinary()
651 
652 
653 
654 
655 void EvaluateDMIInputs(int * pDMIType)
656 {
657  // Bouml preserved body begin 000EAC02
658  const char* const TRAIN_DATA_SUB_STRINGS[] = {"Driver ID"};
659  const char* const LEVEL_TRANSITION_SUB_STRINGS[] = {"Level Transition"};
660  const char* const MODE_TRANSITION_SUB_STRINGS[] = {"Mode Transition"};
661  const char* const TRIP_ACKNOWLEDGE_SUB_STRINGS[] = {"Acknowledge Trip"};
662  static ::QStringList LastInputs(0);
663  static decltype (LastInputs.begin()) lp;
664  ::QStringList CurrentInputs;
665  ::QDBusPendingReply< ::QStringList > AsyncReply;
666  ::QString CurrentInput;
667  unsigned int x(0);
668 
669 
670  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
671  // DEBUG
672  ::std::cerr << "DEBUG: started EvaluateDMIInputs() " << ::std::endl;
673  #endif
674 
675  // call init DMI
676  InitDMI();
677 
678  // check, if DMI proxy is available
679  if (m_pDMI != nullptr)
680  {
681  // get HasInput via proxy
682  AsyncReply = m_pDMI->GetInputs();
683 
684  // wait for asynchronous call to be finished
685  AsyncReply.waitForFinished();
686 
687  // check, if replay was valid
688  if (not AsyncReply.isValid())
689  {
690  // print error
691  ::std::cerr << "error while calling remote method IDMI::GetInputs() ->" << AsyncReply.error().message().toStdString() << ::std::endl;
692 
693  // set DMI type to optional data
694  *pDMIType = 4;
695 
696  } // if (not AsyncReply.isValid())
697  else
698  {
699  // get new inputs from reply
700  CurrentInputs = AsyncReply.value();
701 
702  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
703  // DEBUG
704  ::std::cerr << "DEBUG: EvaluateDMIInputs() Current Inputs: " << ::std::flush;
705  for (decltype (CurrentInputs.begin()) y = CurrentInputs.begin(); y != CurrentInputs.end(); y++)
706  {
707  ::std::cerr << "\"" << (*y).toStdString() << "\", ";
708 
709  } // for (decltype (CurrentInputs.begin()) y = CurrentInputs.begin(); y != CurrentInputs.end(); y++)
710  ::std::cerr << ::std::endl;
711  #endif
712 
713  // compare current list with last
714  if (not LastInputs.empty() && not CurrentInputs.empty() && CurrentInputs == LastInputs)
715  {
716  // check, if iterator already reached end of list
717  if (lp != LastInputs.end())
718  {
719  // get current input
720  CurrentInput = *lp;
721 
722  // increase iterator
723  lp++;
724 
725  } // if (lp != LastInputs.end())
726 
727  } // if if (not LastInputs.empty() && not CurrentInputs.empty() && CurrentInputs == LastInputs)
728  else
729  {
730  // set last inputs to new list
731  LastInputs = CurrentInputs;
732 
733  // check, if inputs are not empty
734  if (not LastInputs.empty())
735  {
736  // get current input
737  CurrentInput = LastInputs[0];
738 
739  // set iterator to next element
740  lp = LastInputs.begin() + 1;
741 
742  } // if (not LastInputs.empty()
743 
744  } // else
745 
746 
747  // initialise DMI type
748  *pDMIType = -1;
749 
750  // check, if current string is non-empty
751  if (CurrentInput.size() != 0)
752  {
753  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
754  // DEBUG
755  ::std::cout << "DEBUG: EvaluateDMIInputs() -> current evaluated input is \"" << CurrentInput.toStdString() << "\"" << ::std::endl;
756  #endif
757 
758 
759  // check, current input is train data
760  for (x = 0; x < 1 && *pDMIType == -1; x++)
761  {
762  // check, if current input matches current sub string
763  if (CurrentInput.toStdString().find(TRAIN_DATA_SUB_STRINGS[x]) != ::std::string::npos)
764  {
765  // set DMI type to 0
766  *pDMIType = 0;
767 
768  } // if (CurrentInput.toStdString().find(*TRAIN_DATA_SUB_STRINGS[x]) != ::std::string::npos)
769 
770  } // for (x = 0; x < sizeof (TRAIN_DATA_SUB_STRINGS) && *pDMIType == -1; x++)
771 
772 
773  // check, current input is level transition
774  for (x = 0; x < 1 && *pDMIType == -1; x++)
775  {
776  // check, if current input matches current sub string
777  if (CurrentInput.toStdString().find(LEVEL_TRANSITION_SUB_STRINGS[x]) != ::std::string::npos)
778  {
779  // set DMI type to 0
780  *pDMIType = 1;
781 
782  } // if (CurrentInput.toStdString().find(*LEVEL_TRANSITION_SUB_STRINGS[x]) != ::std::string::npos)
783 
784  } // for (x = 0; x < sizeof (LEVEL_TRANSITION_SUB_STRINGS) && *pDMIType == -1; x++)
785 
786 
787  // check, current input is mode transition
788  for (x = 0; x < 1 && *pDMIType == -1; x++)
789  {
790  // check, if current input matches current sub string
791  if (CurrentInput.toStdString().find(MODE_TRANSITION_SUB_STRINGS[x]) != ::std::string::npos)
792  {
793  // set DMI type to 0
794  *pDMIType = 2;
795 
796  } // if (CurrentInput.toStdString().find(*MODE_TRANSITION_SUB_STRINGS[x]) != ::std::string::npos)
797 
798  } // for (x = 0; x < sizeof (MODE_TRANSITION_SUB_STRINGS) && *pDMIType == -1; x++)
799 
800 
801  // check, current input is trip acknowledgement
802  for (x = 0; x < 1 && *pDMIType == -1; x++)
803  {
804  // check, if current input matches current sub string
805  if (CurrentInput.toStdString().find(TRIP_ACKNOWLEDGE_SUB_STRINGS[x]) != ::std::string::npos)
806  {
807  // set DMI type to 0
808  *pDMIType = 3;
809 
810  } // if (CurrentInput.toStdString().find(TRIP_ACKNOWLEDGE_SUB_STRINGS[x]) != ::std::string::npos)
811 
812  } // for (x = 0; x < sizeof (MODE_TRANSITION_SUB_STRINGS) && *pDMIType == -1; x++)
813 
814  } // if (CurrentInput.size() != 0)
815 
816  // set DMI type to other/optional if still is invalid
817  *pDMIType = (*pDMIType == -1 ? 4 : *pDMIType);
818 
819  } // else
820 
821  } // if (m_pDMI != nullptr)
822  else
823  {
824  // print error
825  ::std::cerr << "could not establish connection to DMI adaptor" << ::std::endl;
826 
827  // set DMI type to optional data
828  *pDMIType = 4;
829 
830  } // else
831 
832  #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
833  // DEBUG
834  ::std::cout << "DEBUG: EvaluateDMIInputs() -> evaluated type is " << *pDMIType << ::std::endl;
835  #endif
836  // Bouml preserved body end 000EAC02
837 
838 } // void WrapperFunctions::EvaluateDMIInputs() throw()
839 
840 
841 
842 
843 double GetVelocity()
844 {
845  // Bouml preserved body begin 000EC582
846  // return velocity of odometer object
847  return (m_pOdometer->GetVelocity());
848  // Bouml preserved body end 000EC582
849 
850 } // double WrapperFunctions::GetVelocity() throw()
851 
852 
853 
854 
855 void SetVelocity(double dVelocity)
856 {
857  // Bouml preserved body begin 000EC602
858  // set velocity in odomezer object
859  m_pOdometer->SetVelocity(dVelocity);
860  // Bouml preserved body end 000EC602
861 
862 } // void WrapperFunctions::SetVelocity() throw()
863 
864 
865 
866 
867 void ResetPosition(double dPosition)
868 {
869  // Bouml preserved body begin 000EC682
870  // set position in odometer object
871  m_pOdometer->ResetPosition((dPosition));
872  // Bouml preserved body end 000EC682
873 
874 } // void WrapperFunctions::ResetPosition() throw()
875 
876 
877 
878 
879 double GetPosition()
880 {
881  // Bouml preserved body begin 000FBC02
882  // return position of odometer object
883  return (m_pOdometer->GetAbsolutePosition());
884  // Bouml preserved body end 000FBC02
885 
886 } // double WrapperFunctions::GetPosition() throw()
887 
888 
889 
890 
891 void SetServiceIntensity(double dIntensity)
892 {
893  // Bouml preserved body begin 000EE002
894  // set intensity in service brake object
895  m_pServiceBrake->SetIntensity(dIntensity);
896  // Bouml preserved body end 000EE002
897 
898 } // void WrapperFunctions::SetServiceIntensity() throw()
899 
900 
901 
902 
904 {
905  // Bouml preserved body begin 000EE082
906  // return service brake intensity from object
907  return (m_pServiceBrake->GetIntensity());
908  // Bouml preserved body end 000EE082
909 
910 } // double WrapperFunctions::GetServiceIntensity() throw()
911 
912 
913 
914 
915 void SetMass(double dMass)
916 {
917  // Bouml preserved body begin 000EE102
918  // set train mass in service brake object
919  m_pServiceBrake->SetMass(dMass);
920  // Bouml preserved body end 000EE102
921 
922 } // void WrapperFunctions::SetMass() throw()
923 
924 
925 
926 
927 void SetAdhesion(double dAdhesion)
928 {
929  // Bouml preserved body begin 000EE182
930  // set adhesion factor in service brake object
931  m_pServiceBrake->SetAdhesion(dAdhesion);
932  // Bouml preserved body end 000EE182
933 
934 } // void WrapperFunctions::SetAdhesion() throw()
935 
936 
937 
938 
939 void SetEmergencyActivation(int iActication)
940 {
941  // Bouml preserved body begin 000EE202
942  // set activation in emergency brake object
943  m_pEmergencyBrake->SetActivation(iActication == 0 ? false : true);
944  // Bouml preserved body end 000EE202
945 
946 } // void SetEmergencyActivation()
947 
948 
949 
950 
952 {
953  // Bouml preserved body begin 000EE282
954  // return activation from emergency brake object
955  return (m_pEmergencyBrake->GetActivation() == 0 ? false : true);
956  // Bouml preserved body end 000EE282
957 
958 } // int GetEmergencyActivation()
959 
960 
961 
962 

Copyright (C) 2010-2012 Johannes Feuser (feuser@uni-bremen.de)
The openETCS library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
The openETCS library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the openETCS library. If not, see "http://www.gnu.org/licenses/.