The Sample program demonstrates the main functionality of the OTX-Runtime API. It can be used as a reference for the expected runtime behavior of the API and the source code below is like a reference guide about the proper programming of the API.
9 #include <RuntimeManagerFactory.h>
10 #include <IRuntimeContext.h>
11 #include <RuntimeConfig.h>
12 #include <Project/IProject.h>
13 #include <Otx/IPackage.h>
14 #include <Otx/IDocument.h>
15 #include <Otx/IContextVariable.h>
16 #include <Otx/IStateVariable.h>
17 #include <Otx/IProcedure.h>
18 #include <Otx/IProcedureParameter.h>
19 #include <Otx/IProcedureInParameter.h>
20 #include <Otx/IProcedureInOutParameter.h>
21 #include <DataTypes/Object.h>
22 #include <DataTypes/ValueConverter.h>
23 #include <Exceptions/Exception.h>
27 #include <SingletonManager.h>
28 using OpenTestSystem::Otx::Common::SingletonManager;
30 #include <License/LicenseManager.h>
36 #include <IDiagConfiguration.h>
37 #include <OtxDiagFactory.h>
38 using namespace OpenTestSystem::Otx::DiagManager::OtxDiagApi;
40 #include <CommandProcessor.h>
41 using OpenTestSystem::Otx::DiagManager::CommandProcessor::CommandProcessor;
44 #include <filesystem.h>
45 namespace fs = otx::filesystem;
47 HMODULE DiagRuntimeSystemDLL = NULL;
48 std::string GetLastErrorAsString();
49 #elif defined(__linux__) || defined(__QNXNTO__)
51 #include <sys/types.h>
54 #ifdef USE_VWMCD_LINK_LIBRARY
56 #include <VwMcdSPDiagRuntimeSystem.h>
57 typedef OpenTestSystem::Otx::DiagManager::DiagRuntimeSystem::VwMcdSPDiagRuntimeSystem VwMcdDiagRuntimeSystem;
59 #include <VwMcdDiagRuntimeSystem.h>
60 typedef OpenTestSystem::Otx::DiagManager::DiagRuntimeSystem::VwMcdDiagRuntimeSystem VwMcdDiagRuntimeSystem;
67 using OpenTestSystem::Otx::DiagManager::Common::IDiagRuntimeSystem;
69 #include "../../../lib/OpenTestSystem.OtxDiagManager.SystemApi/include/Util.h"
70 using OpenTestSystem::Otx::DiagManager::SystemApi::Util;
74 #include <DefaultMeasureImplementation.h>
75 #include <StateVariableImplementation.h>
76 #include <ContextVariableImplementation.h>
77 #include <DefaultCustomScreenImplementation.h>
78 #include <DefaultExternalServiceProviderImplementation.h>
82 #include "ExecutionState.h"
83 #include <ClientFactory.h>
85 bool isProcedureFinished =
false;
86 CommandProcessor* cp =
nullptr;
87 std::shared_ptr<IRuntimeManager> runtimeManager;
88 std::vector<std::shared_ptr<Otx::IProcedure>> DisplayPtxTree(std::shared_ptr<Project::IProject> project);
89 std::shared_ptr<Otx::IProcedure> GetProcedure(std::shared_ptr<Project::IProject> project, std::string procedureFullName);
90 void SelectAndExecuteProcedure(std::shared_ptr<IRuntimeManager> runtimeManager, std::shared_ptr<Project::IProject> project, std::vector<std::shared_ptr<Otx::IProcedure>> procedures);
91 std::string SelectProject(std::shared_ptr<IDiagConfiguration> diagConfiguration);
92 std::string SelectVehicleInformation(std::shared_ptr<IDiagConfiguration> diagConfiguration);
93 std::shared_ptr<IOtxDiag> CreateRawOtxDiag();
95 std::string licenseKey;
96 bool IsLicenseValid(std::string);
97 void ReadAndSetOtxRuntimeLicense();
99 IDiagRuntimeSystem* CreateDiagRuntimeSystem(
const char* projectName,
const char* vehicleInfo,
const char* kernelPath,
bool useVwmcdSP);
101 std::shared_ptr<DefaultCustomScreenImplementation> customScreenImplementation = std::make_shared<DefaultCustomScreenImplementation>();
102 std::shared_ptr<DefaultMeasureImplementation> measureImplementation = std::make_shared<DefaultMeasureImplementation>();
103 std::shared_ptr<StateVariableImplementation> stateVariableImplementation = std::make_shared<StateVariableImplementation>();
104 std::shared_ptr<ContextVariableImplementation> contextVariableImplementation = std::make_shared<ContextVariableImplementation>();
105 std::shared_ptr<DefaultExternalServiceProviderImplementation> externalServiceProviderImplementation = std::make_shared<DefaultExternalServiceProviderImplementation>();
109 std::cout << std::endl <<
"Procedure '" << context.
GetProcedure()->GetFullName() <<
"' started" << std::endl;
114 std::cout << std::endl <<
"Procedure '" << context.
GetProcedure()->GetFullName() <<
"' finished" << std::endl;
116 for (
size_t i = 0; i < context.
GetProcedure()->GetParameters().size(); i++)
118 std::shared_ptr<Otx::IProcedureParameter> procedureParameter = context.
GetProcedure()->GetParameters().at(i);
120 std::cout << std::endl <<
"\tParameterValueFinished(" << procedureParameter->GetDataType() <<
", " << procedureParameter->GetName() <<
" = " << procedureParameter->GetValue()->ToLiteralString() <<
")";
122 std::cout << std::endl;
124 isProcedureFinished =
true;
129 std::cout << std::endl <<
"Procedure '" << context.
GetProcedure()->GetFullName() <<
"' aborted" << std::endl;
130 isProcedureFinished =
true;
135 std::cout << std::endl <<
"Procedure '" << context.
GetProcedure()->GetFullName() <<
"' stopped" << std::endl;
137 isProcedureFinished =
true;
143 std::cout << std::endl <<
"Procedure '" << context.
GetProcedure()->GetFullName() <<
"' timeout expired" << std::endl;
146 void InOutParameterValueChanged(
const IRuntimeContext& context,
const IProcedureInOutParameter& parameter)
148 std::string separator =
" || ";
149 time_t now = time(0);
150 tm* ltm = localtime(&now);
151 std::stringstream ss;
152 ss << ltm->tm_hour <<
":" << ltm->tm_min <<
":" << ltm->tm_sec;
154 std::string outputLog =
"InOutParameterValueChanged(" + parameter.GetDataType() +
", " + parameter.GetName() +
" = " + parameter.GetValue()->ToLiteralString() +
")";
156 std::cout <<
"\t" << ss.str() << separator << outputLog << std::endl;
159 void ContextVariableRead(std::shared_ptr<IContextVariable> contextVariable, std::shared_ptr<Object> value)
161 std::string separator =
" || ";
162 time_t now = time(0);
163 tm* ltm = localtime(&now);
164 std::stringstream ss;
165 ss << ltm->tm_hour <<
":" << ltm->tm_min <<
":" << ltm->tm_sec;
167 std::string mappingStr = contextVariable->GetMappingName().empty() ?
"" : (
" [MappedTo: " + contextVariable->GetMappingName() + (contextVariable->GetMappingIndex() > -1 ? (
"[" + std::to_string(contextVariable->GetMappingIndex()) +
"]") :
"") +
"]");
168 std::string outputLog =
"ContextVariableRead(" + contextVariable->GetDataType() +
", " + contextVariable->GetDocument()->GetFullName() +
"." + contextVariable->GetName() + mappingStr +
" = " + value->ToLiteralString() +
")";
170 std::cout <<
"\t" << ss.str() << separator << outputLog << std::endl;
172 void StateVariableValueChanged(std::shared_ptr<IStateVariable> stateVariable, std::shared_ptr<Object> value)
174 std::string mappingStr = stateVariable->GetMappingName().empty() ?
"" : (
" [MappedTo: " + stateVariable->GetMappingName() + (stateVariable->GetMappingIndex() > -1 ? (
"[" + std::to_string(stateVariable->GetMappingIndex()) +
"]") :
"") +
"]");
175 std::string outputLog =
"StateVariableChanged(" + stateVariable->GetDataType() +
", " + stateVariable->GetDocument()->GetFullName() +
"." + stateVariable->GetName() + mappingStr +
" = " + value->ToLiteralString() +
")";
176 std::string separator =
" || ";
177 time_t now = time(0);
178 tm* ltm = localtime(&now);
179 std::stringstream ss;
180 ss << ltm->tm_hour <<
":" << ltm->tm_min <<
":" << ltm->tm_sec;
182 std::cout <<
"\t" << ss.str() << separator << outputLog << std::endl;
185 std::vector<std::string> SplitString(std::string str,
char delimiter)
188 std::istringstream ss(str);
189 std::vector<std::string> tokens;
190 while (std::getline(ss, token, delimiter))
192 tokens.push_back(token);
199 bool IsLicenseValid(std::string licenseKey)
208 catch (
const std::exception& e)
210 std::cout << e.what() << std::endl;
215 void ReadAndSetOtxRuntimeLicense()
219 std::cout <<
"Please enter your OtxRuntime license key here (enter empty to exit): ";
220 std::getline(std::cin, licenseKey);
222 if (licenseKey.empty())
227 std::regex pattern(
"^[0-9a-zA-Z]{5}-[0-9a-zA-Z]{5}-[0-9a-zA-Z]{5}-[0-9a-zA-Z]{5}-[0-9a-zA-Z]{5}$|^$");
229 if (std::regex_match(licenseKey, pattern))
231 if (!IsLicenseValid(licenseKey))
242 std::cout <<
"License key does not match the desired format XXXXX-XXXXX-XXXXX-XXXXX-XXXXX. Enter empty to exit.\n";
247 int main(
int argc,
char** argv)
249 ReadAndSetOtxRuntimeLicense();
251 std::string runtimeManagerType;
255 std::cout <<
"Select a RuntimeManager:" << std::endl <<
"\t1 or empty - Raw." << std::endl <<
"\t2 - Socket." << std::endl <<
"\t3 - Pipe." << std::endl;
256 std::cout <<
"Enter a number: ";
257 std::getline(std::cin, runtimeManagerType);
258 if (runtimeManagerType ==
"" || runtimeManagerType ==
"1")
260 std::shared_ptr<IOtxDiag> otxDiag =
nullptr;
263 otxDiag = CreateRawOtxDiag();
270 std::cout <<
"\tRawRuntimeManager is created." << std::endl;
271 std::shared_ptr<IDiagConfiguration> diagConfiguration = otxDiag->GetDiagConfiguration();
272 std::string projectName, vehicleInformationName;
273 projectName = SelectProject(diagConfiguration);
274 if (!projectName.empty())
276 vehicleInformationName = SelectVehicleInformation(diagConfiguration);
279 catch (
const std::exception& ex)
281 std::cerr << ex.what() << std::endl;
287 else if (runtimeManagerType ==
"2")
289 int otxRunnerPort, diagManagerPort;
292 std::cout <<
"Enter OtxRunnerPort and DiagManagerPort, separated by space: ";
294 std::getline(std::cin, input);
295 std::vector<std::string> tokens = SplitString(input,
' ');
298 otxRunnerPort = atoi(tokens.at(0).c_str());
299 diagManagerPort = atoi(tokens.at(1).c_str());
302 catch (
const std::exception& ex)
304 std::cerr << ex.what() << std::endl;
308 std::cout <<
"Wrong numbers!" << std::endl;
316 catch (
const std::exception& ex)
318 std::cerr << ex.what() << std::endl;
322 std::cout <<
"\tSocketRuntimeManager(otxRunnerPort=" << otxRunnerPort <<
", diagManagerPort=" << diagManagerPort <<
") was created." << std::endl;
325 else if (runtimeManagerType ==
"3")
327 std::string otxRunnerPipeName, diagManagerPipeName;
330 std::cout <<
"Enter OtxRunnerPipeName and DiagManagerPipeName, separated by space: ";
332 std::getline(std::cin, input);
333 std::vector<std::string> tokens = SplitString(input,
' ');
336 otxRunnerPipeName = tokens.at(0);
337 diagManagerPipeName = tokens.at(1);
340 catch (
const std::exception& ex)
342 std::cerr << ex.what() << std::endl;
346 std::cout <<
"Wrong names!" << std::endl;
354 catch (
const std::exception& ex)
356 std::cerr << ex.what() << std::endl;
360 std::cout <<
"\tPipeRuntimeManager(otxRunnerPipeName=\"" << otxRunnerPipeName <<
"\", diagManagerPipeName=\"" << diagManagerPipeName <<
"\") was created." << std::endl;
364 std::cout <<
"Wrong number!" << std::endl;
370 runtimeManager->SetCustomImplementation(customScreenImplementation);
371 runtimeManager->SetCustomImplementation(measureImplementation);
372 runtimeManager->SetCustomImplementation(externalServiceProviderImplementation);
373 stateVariableImplementation->SetStateVariableValueChangedHandler(std::make_shared<std::function<
void(std::shared_ptr<IStateVariable>, std::shared_ptr<Object>)>>(StateVariableValueChanged));
374 runtimeManager->SetCustomImplementation(stateVariableImplementation);
375 contextVariableImplementation->SetContextVariableReadHandler(std::make_shared<std::function<
void(std::shared_ptr<IContextVariable>, std::shared_ptr<Object>)>>(ContextVariableRead));
376 runtimeManager->SetCustomImplementation(contextVariableImplementation);
379 std::shared_ptr<std::function<void(
const IRuntimeContext&)>> procedureStartListener = std::make_shared<std::function<void(
const IRuntimeContext&)>>(ProcedureStarted);
380 std::shared_ptr<std::function<void(
const IRuntimeContext&)>> procedureFinishedListener = std::make_shared<std::function<void(
const IRuntimeContext&)>>(ProcedureFinished);
381 std::shared_ptr<std::function<void(
const IRuntimeContext&)>> procedureAbortedListener = std::make_shared<std::function<void(
const IRuntimeContext&)>>(ProcedureAborted);
382 std::shared_ptr<std::function<void(
const IRuntimeContext&)>> procedureStoppedListener = std::make_shared<std::function<void(
const IRuntimeContext&)>>(ProcedureStopped);
383 std::shared_ptr<std::function<void(
const IRuntimeContext&,
const IProcedureInOutParameter&)>> parameterChangedListener = std::make_shared<std::function<void(
const IRuntimeContext&,
const IProcedureInOutParameter&)>>(InOutParameterValueChanged);
384 std::shared_ptr<std::function<void(
const IRuntimeContext&)>> procedureTimeoutListener = std::make_shared<std::function<void(
const IRuntimeContext&)>>(ProcedureTimeout);
386 runtimeManager->AddProcedureStartedListener(procedureStartListener);
387 runtimeManager->AddProcedureFinishedListener(procedureFinishedListener);
388 runtimeManager->AddProcedureTimeoutListener(procedureTimeoutListener);
389 runtimeManager->AddProcedureAbortedListener(procedureAbortedListener);
390 runtimeManager->AddProcedureStoppedListener(procedureStoppedListener);
391 runtimeManager->AddInOutParameterValueChangedListener(parameterChangedListener);
393 std::shared_ptr<Project::IProject> project =
nullptr;
397 std::cout <<
"Enter PTX: ";
399 std::getline(std::cin, ptxFile);
402 if (ptxFile.at(0) ==
'"' && ptxFile.at(ptxFile.size() - 1) ==
'"')
404 ptxFile = ptxFile.substr(1, ptxFile.size() - 2);
407 project = runtimeManager->LoadPtx(ptxFile);
411 catch (std::exception& ex)
413 std::cerr <<
"\t" << ex.what() << std::endl;
419 std::vector<std::shared_ptr<Otx::IProcedure>> procedures = DisplayPtxTree(project);
422 SelectAndExecuteProcedure(runtimeManager, project, procedures);
425 SingletonManager::Get().DestroyAll();
433 std::vector < std::shared_ptr<Otx::IProcedure>> DisplayPtxPackageTree(std::vector < std::shared_ptr<Otx::IProcedure>> procedures, std::vector < std::shared_ptr<Otx::IPackage>> packages, std::string stringConcat =
"")
435 for (
int i = 0; i < packages.size(); i++)
437 std::shared_ptr<Otx::IPackage>
package = packages.at(i);
438 std::cout << stringConcat <<
" |- " << package->GetName() <<
" (Package)" << std::endl;
440 procedures = DisplayPtxPackageTree(procedures, package->GetPackages(), stringConcat +
" |");
442 for (
int j = 0; j < package->GetDocuments().size(); j++)
444 std::shared_ptr<Otx::IDocument> document = package->GetDocuments().at(j);
445 document->GetImports();
447 std::cout << stringConcat <<
" | |- " << document->GetName() <<
" (Document)" << std::endl;
448 for (
int k = 0; k < document->GetProcedures().size(); k++)
450 std::shared_ptr<Otx::IProcedure> procedure = document->GetProcedures().at(k);
451 procedures.push_back(procedure);
452 std::cout << stringConcat <<
" | | |- " << procedure->GetName() <<
" (Procedure)" <<
" - code: " << procedures.size() << std::endl;
454 for (
int m = 0; m < procedure->GetParameters().size(); m++)
456 std::shared_ptr<Otx::IProcedureParameter> param = procedure->GetParameters().at(m);
458 std::string name = param->GetName();
459 std::string dataType = param->GetDataType();
461 auto value = param->GetInitValue();
462 std::string valueStr = (value !=
nullptr ? value->ToLiteralString() :
"null");
464 if (std::shared_ptr<Otx::IProcedureInParameter> inParameter = std::dynamic_pointer_cast<Otx::IProcedureInParameter>(param))
467 stringConcat <<
" | | | |- " << name <<
" (" << dataType <<
"): " << valueStr <<
" (InParameter or InOutParameter)" << std::endl;
471 std::cout << stringConcat <<
" | | | |- " << name <<
" (" << dataType <<
"): " << valueStr <<
" (OutParameter)" << std::endl;
480 std::vector < std::shared_ptr<Otx::IProcedure>> DisplayPtxTree(std::shared_ptr<Project::IProject> project)
482 std::vector < std::shared_ptr<Otx::IProcedure>> procedures;
485 std::cout << std::endl <<
"PTX tree: " << std::endl;
487 std::cout <<
"- " << project->GetName() <<
" (Project)" << std::endl;
489 procedures = DisplayPtxPackageTree(procedures, project->GetPackages());
494 void SelectAndExecuteProcedure(std::shared_ptr<IRuntimeManager> runtimeManager, std::shared_ptr<Project::IProject> project, std::vector<std::shared_ptr<Otx::IProcedure>> procedures)
498 std::string procedureFullName;
499 std::cout << std::endl <<
"Enter Procedure (full name, code or 0 - if exit): ";
500 std::getline(std::cin, procedureFullName);
502 std::shared_ptr<Otx::IProcedure> procedure =
nullptr;
505 int idxProcedure = std::stoi(procedureFullName.c_str());
506 if (idxProcedure < 0 || idxProcedure>procedures.size() + 1)
508 std::cout << std::endl <<
"The procedure code is invalid.";
509 goto ReEnterProcedure;
511 else if (idxProcedure == 0 && procedureFullName.size() > 0)
517 procedure = procedures.at(idxProcedure - 1);
520 catch (
const std::exception&)
525 if (procedure !=
nullptr)
528 for (
int i = 0; i < procedure->GetParameters().size(); i++)
530 std::shared_ptr<Otx::IProcedureParameter> procedureParameter = procedure->GetParameters().at(i);
531 if (std::shared_ptr<Otx::IProcedureInParameter> inParameter = std::dynamic_pointer_cast<Otx::IProcedureInParameter>(procedureParameter))
533 bool isValidValue =
false;
540 std::cout <<
"Enter value of " << procedureParameter->GetName() <<
" (" << procedureParameter->GetDataType() <<
"): ";
541 std::getline(std::cin, value);
544 inParameter->SetValue(ValueConverter::String2Value(value, procedureParameter->GetDataType()));
547 catch (std::exception& ex)
549 isValidValue =
false;
550 std::cerr << ex.what() << std::endl;
552 }
while (!isValidValue);
554 else if (std::shared_ptr<Otx::IProcedureInOutParameter> inOutParameter = std::dynamic_pointer_cast<Otx::IProcedureInOutParameter>(procedureParameter))
556 bool isValidValue =
false;
563 std::cout <<
"Enter value of " << procedureParameter->GetName() <<
" (" << procedureParameter->GetDataType() <<
"): ";
564 std::getline(std::cin, value);
567 inOutParameter->SetValue(ValueConverter::String2Value(value, procedureParameter->GetDataType()));
570 catch (std::exception& ex)
572 isValidValue =
false;
573 std::cerr << ex.what() << std::endl;
575 }
while (!isValidValue);
579 isProcedureFinished =
false;
580 std::shared_ptr<IRuntimeContext> runtimeContext = runtimeManager->ExecuteAsync(procedure);
582 while (isProcedureFinished ==
false)
584 std::this_thread::sleep_for(std::chrono::milliseconds(1));
587 if (runtimeContext->HasOtxException())
589 std::cout << std::endl <<
"Otx exception occurred:" <<
"\t";
590 std::cout << runtimeContext->GetOtxException().GetOtxType() <<
":" << runtimeContext->GetOtxException().what() << std::endl;
592 else if (runtimeContext->HasRuntimeException())
594 std::cout << std::endl <<
"Runtime exception occurred:" <<
"\t";
595 std::cout << runtimeContext->GetRuntimeException().what() << std::endl;
600 std::cout <<
"Procedure " << procedureFullName <<
" does not exist!" << std::endl;
603 goto ReEnterProcedure;
606 std::string SelectProject(std::shared_ptr<IDiagConfiguration> diagConfiguration)
608 std::string projectSelected;
609 int indexProjectSelect = 0;
611 std::shared_ptr<IDiagConfiguration> diagConfig = diagConfiguration;
612 if (diagConfig == NULL)
614 diagConfig = CreateRawOtxDiag()->GetDiagConfiguration();
616 std::vector<std::string> projectList = diagConfig->GetDbProjectList();
618 if (projectList.size() > 0)
620 std::cout <<
"Select a ODX-Runtime-Project" << std::endl;
621 std::cout <<
"\t0 - None" << std::endl;
623 for (
size_t indexProjectItem = 0; indexProjectItem < projectList.size(); indexProjectItem++)
625 std::cout <<
"\t" << indexProjectItem + 1 <<
" - " << projectList.at(indexProjectItem) << std::endl;
631 std::cout <<
"Enter a number: ";
632 std::cin >> indexProjectSelect;
634 if (indexProjectSelect > 0 && indexProjectSelect - 1 < projectList.size())
636 projectSelected = projectList.at(indexProjectSelect - 1);
637 diagConfig->SelectProject(projectSelected);
641 return projectSelected;
644 std::string SelectVehicleInformation(std::shared_ptr<IDiagConfiguration> diagConfiguration)
646 std::string vehicleSelected;
647 int indexVehicleInformationSelect = 0;
649 std::shared_ptr<IDiagConfiguration> _diagConfiguration = diagConfiguration;
650 if (_diagConfiguration == NULL)
652 _diagConfiguration = CreateRawOtxDiag()->GetDiagConfiguration();
654 std::vector<std::string> vehicleInformationList = _diagConfiguration->GetDbVehicleInformationList();
656 for (
size_t indexVehicleInformationName = 0; indexVehicleInformationName < vehicleInformationList.size(); indexVehicleInformationName++)
658 std::cout <<
"\t" << indexVehicleInformationName + 1 <<
" - " << vehicleInformationList.at(indexVehicleInformationName) << std::endl;
664 std::cout <<
"Input vehicle information code: ";
665 std::cin >> indexVehicleInformationSelect;
667 if (indexVehicleInformationSelect > 0 && indexVehicleInformationSelect - 1 < vehicleInformationList.size())
669 vehicleSelected = vehicleInformationList.at(indexVehicleInformationSelect - 1);
670 _diagConfiguration->SelectVehicleInformation(vehicleSelected);
672 return vehicleSelected;
675 std::shared_ptr<IOtxDiag> CreateRawOtxDiag()
677 OpenTestSystem::Otx::DiagManager::OtxDiagApi::OtxDiagFactory factory;
681 cp =
new CommandProcessor;
684 bool useVwmcdSP =
false;
688 OpenTestSystem::Otx::DiagManager::Client::ClientFactory clientFactory;
689 std::shared_ptr<OpenTestSystem::Otx::DiagManager::Client::Client> rawClient = clientFactory.CreateRawClient(cp);
690 Util::SetLicenseKey(rawClient, licenseKey);
691 const char* kernelPath = getenv(
"VW_MCD_HOME");
694 std::cout <<
"\tCannot read ENVIRONMENT VARIABLE 'VW_MCD_HOME'" << std::endl;
698 const char* configPath = getenv(
"VW_MCD_CONFIG");
701 std::cout <<
"\tCannot read ENVIRONMENT VARIABLE 'VW_MCD_CONFIG'" << std::endl;
705 std::cout <<
"\tVW_MCD_HOME = " << kernelPath << std::endl;
706 std::cout <<
"\tVW_MCD_CONFIG = " << configPath << std::endl;
707 IDiagRuntimeSystem* drs = CreateDiagRuntimeSystem(
"",
"", kernelPath, useVwmcdSP);
710 std::cout <<
"\tInitDiagRuntimeSystem failed!" << std::endl;
713 cp->SetRuntimeSystem(drs);
714 return factory.CreateRawOtxDiag(cp);
717 std::string GetLastErrorAsString()
720 DWORD errorMessageID = ::GetLastError();
721 if (errorMessageID == 0) {
722 return std::string();
725 LPSTR messageBuffer =
nullptr;
729 size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
730 NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
733 std::string message(messageBuffer, size);
736 LocalFree(messageBuffer);
742 IDiagRuntimeSystem* CreateDiagRuntimeSystem(
const char* projectName,
const char* vehicleInfo,
const char* kernelPath,
bool useVwmcdSP)
745 typedef IDiagRuntimeSystem* (__cdecl* typeCreateDiagRuntimeSystem)(
const char* projectName,
const char* vehicleInfo);
746 DiagRuntimeSystemDLL = NULL;
749 std::string DiagRuntimeSystem_17_50_FileName =
"OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcd_VC142.dll";
751 std::string DiagRuntimeSystemSP_17_50_FileName =
"OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcdSP_VC142.dll";
753 std::string DiagRuntimeSystem_09_00_FileName =
"OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.dll";
755 std::string DiagRuntimeSystemSP_09_00_FileName =
"OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcd90SP.dll";
758 std::string DiagRuntimeSystemFileName = DiagRuntimeSystem_17_50_FileName;
759 std::string kernelTypeStr =
"VwMcd1750";
763 kernelTypeStr =
"VwMcd1750SP";
764 DiagRuntimeSystemFileName = DiagRuntimeSystemSP_17_50_FileName;
767 if (fs::exists(std::string(kernelPath) +
"/McdKernel_vc120.dll"))
771 kernelTypeStr =
"VwMcd90SP";
772 DiagRuntimeSystemFileName = DiagRuntimeSystemSP_09_00_FileName;
776 kernelTypeStr =
"VwMcd90";
777 DiagRuntimeSystemFileName = DiagRuntimeSystem_09_00_FileName;
781 std::cout <<
"\tKernel Type is " << kernelTypeStr << std::endl;
783 DiagRuntimeSystemDLL = ::LoadLibrary(DiagRuntimeSystemFileName.c_str());
784 if (DiagRuntimeSystemDLL == NULL)
786 std::string errorMessage = GetLastErrorAsString();
787 std::cout << errorMessage << std::endl;
788 throw std::exception(errorMessage.c_str());
791 typedef IDiagRuntimeSystem* (__cdecl* typeCreateDiagRuntimeSystem)(
const char* projectName,
const char* vehicleInfo);
792 typeCreateDiagRuntimeSystem createFunction =
reinterpret_cast<typeCreateDiagRuntimeSystem
>(::GetProcAddress(DiagRuntimeSystemDLL,
"CreateDiagRuntimeSystem"));
794 if (createFunction ==
nullptr)
797 return createFunction(projectName, vehicleInfo);
798 #elif defined(__linux__) || defined(__QNXNTO__)
799 #ifdef USE_VWMCD_LINK_LIBRARY
800 return new VwMcdDiagRuntimeSystem(projectName, vehicleInfo);
802 if (!handle && useVwmcdSP ==
false)
804 std::cout <<
"Kernel Type is VwMcd" << std::endl;
805 handle = dlopen(
"libOpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcd.so", RTLD_NOW);
807 else if (!handle && useVwmcdSP ==
true)
809 std::cout <<
"Kernel Type is VwMcdSP" << std::endl;
810 handle = dlopen(
"libOpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcdSP.so", RTLD_NOW);
815 std::cout << dlerror() << std::endl;
818 typedef IDiagRuntimeSystem* typeCreateDiagRuntimeSystem(
const char* projectName,
const char* vehicleInfo);
819 typeCreateDiagRuntimeSystem* createFunction =
reinterpret_cast<typeCreateDiagRuntimeSystem*
>(dlsym(handle,
"CreateDiagRuntimeSystem"));
826 IDiagRuntimeSystem* digRuntimeSystem = createFunction(projectName, vehicleInfo);
828 createFunction = NULL;
829 return digRuntimeSystem;
Contains information of a Runner instance.
Definition: IRuntimeContext.h:30
virtual std::shared_ptr< Otx::IProcedure > GetProcedure() const =0
Gets Procedure which created this RuntimeContext by starting an execution.
static void SetLicenseKey(const std::string &licenseKey)
Sets a valid license key to release the API.
static RuntimeConfig & GetInstance()
Get RuntimeConfig Instance
static std::shared_ptr< IRuntimeManager > CreateSocketRuntimeManager(unsigned short otxRunnerPort, unsigned short diagManagerPort)
Creates SocketRuntimeManager with Socket DiagManager.
static std::shared_ptr< IRuntimeManager > CreatePipeRuntimeManager(const std::string &otxRunnerPipeName, const std::string &diagManagerPipeName)
Creates PipeRuntimeManager with Pipe DiagManager.
static std::shared_ptr< IRuntimeManager > CreateRawRuntimeManager()
Creates RawRuntimeManager without DiagManager.
Namespace containing custom implementations
Definition: IRuntimeManager.h:32
Namespace containing all objects related to licensing
Definition: LicenseManager.h:22
Namespace containing the programming interface for browsing and execution of OTX procedures in own ap...
Definition: ClampState.h:7