68 static ::oETCS::DF::IDMI*
m_pDMI = 0;
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,
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,
110 ::AOdometer* pOdometer(
nullptr);
111 ::AEmergencyBrake* pEmergencyBrake(
nullptr);
112 ::AServiceBrake* pServiceBrake(
nullptr);
113 ::ABaliseDeviceIn* pBaliseIn(
nullptr);
114 ::ABaliseDeviceOut* pBaliseOut(
nullptr);
115 bool bConnected(
true);
117 char** argv(
nullptr);
118 QCoreApplication Application(argc, argv);
119 QDBusConnection Connection = QDBusConnection::sessionBus();
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);
157 ::std::cerr <<
"QAppThread: Could not register all adaptors!" << ::std::endl;
162 *pInitialised =
true;
165 ::std::cout <<
"QAppThread: Executing adaptor event loop ..." << ::std::endl;
168 QCoreApplication::exec();
171 catch (const ::std::bad_alloc& Exception)
174 ::std::cerr <<
"Could not allocate all adaptor objects: " << Exception.what() << ::std::endl;
180 delete (pEmergencyBrake);
181 delete (pServiceBrake);
201 bool bInitialised(
false);
202 ::std::thread* pAppThread(
nullptr);
205 pAppThread = new ::std::thread(
QAppThread, &bInitialised);
208 if (pAppThread->joinable())
211 while (not bInitialised)
214 ::std::this_thread::yield();
219 pAppThread->detach();
235 bool bInitialised(
true);
245 m_pDMI = new ::oETCS::DF::IDMI(::oETCS::DF::IDMI::staticInterfaceName(),
"/oETCS/DMI", QDBusConnection::sessionBus());
248 if (not
m_pDMI->isValid())
251 ::std::cerr <<
"::oETCS::DF::IDDMI had a problem with D-Bus connection: " <<
m_pDMI->lastError().message().toStdString() << ::std::endl;
260 bInitialised =
false;
271 catch (const ::std::bad_alloc& Exception)
274 bInitialised =
false;
282 return (bInitialised);
293 int iHasInput(
false);
294 QDBusPendingReply< bool > AsyncReply;
304 AsyncReply =
m_pDMI->HasInput();
307 AsyncReply.waitForFinished();
310 if (not AsyncReply.isValid())
313 ::std::cerr <<
"error while calling remote method IDMI::HasInput() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
318 iHasInput = AsyncReply.value() ? 1 : 0;
324 ::std::cerr <<
"could not establish connection to DMI adaptor" << ::std::endl;
340 QDBusPendingReply< QString > AsyncReply;
341 const QString NAME(pName);
353 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
355 ::std::cout <<
"DEBUG: in GetDMIOutput() -> calling IDMI::GetDMIOutput(\"" << pName <<
"\")..." << ::std::flush;
359 AsyncReply =
m_pDMI->GetOutputValue(NAME);
362 AsyncReply.waitForFinished();
364 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
366 ::std::cout <<
"done" << ::std::endl;
370 if (not AsyncReply.isValid())
373 ::std::cerr <<
"error while calling remote method IDMI::GetOutputValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
379 if (ppValue !=
nullptr && *ppValue !=
nullptr)
387 *ppValue =
new (
char[AsyncReply.value().size()]);
390 strcpy(*ppValue, AsyncReply.value().toStdString().c_str());
392 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
394 ::std::cout <<
"DEBUG: value of output filed \"" << pName <<
"\": \"" << *ppValue <<
"\"" << ::std::endl;
403 ::std::cerr <<
"could not establish connection to DMI adaptor" << ::std::endl;
416 QDBusPendingReply<> AsyncReply;
426 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
428 ::std::cout <<
"DEBUG: calling IDMI::SetBooleanValue()..." << ::std::flush;
432 AsyncReply =
m_pDMI->SetBooleanValue(pInputName, iValue == 0 ?
false :
true);
435 AsyncReply.waitForFinished();
437 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
439 ::std::cout <<
"done" << ::std::endl;
443 if (not AsyncReply.isValid())
446 ::std::cerr <<
"error while calling remote method IDMI::SetBooleanValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
454 ::std::cerr <<
"could not establish connection to DMI adaptor" << ::std::endl;
467 QDBusPendingReply<> AsyncReply;
478 AsyncReply =
m_pDMI->SetIntegerValue(pInputName, iValue);
481 AsyncReply.waitForFinished();
484 if (not AsyncReply.isValid())
487 ::std::cerr <<
"error while calling remote method IDMI::SetIntegerValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
495 ::std::cerr <<
"could not establish connection to DMI adaptor" << ::std::endl;
508 QDBusPendingReply<> AsyncReply;
519 AsyncReply =
m_pDMI->SetDoubleValue(pInputName, dValue);
522 AsyncReply.waitForFinished();
525 if (not AsyncReply.isValid())
528 ::std::cerr <<
"error while calling remote method IDMI::SetDoubleValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
536 ::std::cerr <<
"could not establish connection to DMI adaptor" << ::std::endl;
549 QDBusPendingReply<> AsyncReply;
561 AsyncReply =
m_pDMI->SetStringValue(pInputName, pValue);
564 AsyncReply.waitForFinished();
567 if (not AsyncReply.isValid())
570 ::std::cerr <<
"error while calling remote method IDMI::SetStringValue() -> " << AsyncReply.error().message().toStdString() << ::std::endl;
578 ::std::cerr <<
"could not establish connection to DMI adaptor" << ::std::endl;
591 ::QBitArray Telegram(iBits,
false);
593 char* pByte(pTelegram);
597 for (x = 0; x < iBits; x++)
600 Telegram[x] = ((*pByte) & (1 << (x - (pTelegram - pByte) * 8))) == 0 ?
false :
true;
603 if (x - (pTelegram - pByte) * 8 == 7)
625 ::QBitArray Telegram(iBits,
false);
633 for (x = 0; x < iBits; x++)
636 Telegram[x] = pTelegram[x] == 0 ?
false :
true;
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;
670 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
672 ::std::cerr <<
"DEBUG: started EvaluateDMIInputs() " << ::std::endl;
682 AsyncReply =
m_pDMI->GetInputs();
685 AsyncReply.waitForFinished();
688 if (not AsyncReply.isValid())
691 ::std::cerr <<
"error while calling remote method IDMI::GetInputs() ->" << AsyncReply.error().message().toStdString() << ::std::endl;
700 CurrentInputs = AsyncReply.value();
702 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
704 ::std::cerr <<
"DEBUG: EvaluateDMIInputs() Current Inputs: " << ::std::flush;
705 for (decltype (CurrentInputs.begin()) y = CurrentInputs.begin(); y != CurrentInputs.end(); y++)
707 ::std::cerr <<
"\"" << (*y).toStdString() <<
"\", ";
710 ::std::cerr << ::std::endl;
714 if (not LastInputs.empty() && not CurrentInputs.empty() && CurrentInputs == LastInputs)
717 if (lp != LastInputs.end())
731 LastInputs = CurrentInputs;
734 if (not LastInputs.empty())
737 CurrentInput = LastInputs[0];
740 lp = LastInputs.begin() + 1;
751 if (CurrentInput.size() != 0)
753 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
755 ::std::cout <<
"DEBUG: EvaluateDMIInputs() -> current evaluated input is \"" << CurrentInput.toStdString() <<
"\"" << ::std::endl;
760 for (x = 0; x < 1 && *pDMIType == -1; x++)
763 if (CurrentInput.toStdString().find(TRAIN_DATA_SUB_STRINGS[x]) != ::std::string::npos)
774 for (x = 0; x < 1 && *pDMIType == -1; x++)
777 if (CurrentInput.toStdString().find(LEVEL_TRANSITION_SUB_STRINGS[x]) != ::std::string::npos)
788 for (x = 0; x < 1 && *pDMIType == -1; x++)
791 if (CurrentInput.toStdString().find(MODE_TRANSITION_SUB_STRINGS[x]) != ::std::string::npos)
802 for (x = 0; x < 1 && *pDMIType == -1; x++)
805 if (CurrentInput.toStdString().find(TRIP_ACKNOWLEDGE_SUB_STRINGS[x]) != ::std::string::npos)
817 *pDMIType = (*pDMIType == -1 ? 4 : *pDMIType);
825 ::std::cerr <<
"could not establish connection to DMI adaptor" << ::std::endl;
832 #ifdef __OETCS_DF_SIM_DEBUG_OUTPUT__
834 ::std::cout <<
"DEBUG: EvaluateDMIInputs() -> evaluated type is " << *pDMIType << ::std::endl;