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>
40 #include <CommandProcessor.h>
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>
59 #include <VwMcdDiagRuntimeSystem.h>
65 #endif // USE_VWMCD_LINK_LIBRARY
69 #include "../../../lib/OpenTestSystem.OtxDiagManager.SystemApi/include/Util.h"
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 if (runtimeManager->IsProtected(ptxFile))
409 std::cout <<
"Enter password: ";
410 std::string password;
411 std::getline(std::cin, password);
413 project = runtimeManager->LoadPtx(ptxFile, password);
417 project = runtimeManager->LoadPtx(ptxFile);
422 catch (std::exception& ex)
424 std::cerr <<
"\t" << ex.what() << std::endl;
430 std::vector<std::shared_ptr<Otx::IProcedure>> procedures = DisplayPtxTree(project);
433 SelectAndExecuteProcedure(runtimeManager, project, procedures);
436 SingletonManager::Get().DestroyAll();
444 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 =
"")
446 for (
int i = 0; i < packages.size(); i++)
448 std::shared_ptr<Otx::IPackage>
package = packages.at(i);
449 std::cout << stringConcat <<
" |- " << package->GetName() <<
" (Package)" << std::endl;
451 procedures = DisplayPtxPackageTree(procedures, package->GetPackages(), stringConcat +
" |");
453 for (
int j = 0; j < package->GetDocuments().size(); j++)
455 std::shared_ptr<Otx::IDocument> document = package->GetDocuments().at(j);
456 document->GetImports();
458 std::cout << stringConcat <<
" | |- " << document->GetName() <<
" (Document)" << std::endl;
459 for (
int k = 0; k < document->GetProcedures().size(); k++)
461 std::shared_ptr<Otx::IProcedure> procedure = document->GetProcedures().at(k);
462 procedures.push_back(procedure);
463 std::cout << stringConcat <<
" | | |- " << procedure->GetName() <<
" (Procedure)" <<
" - code: " << procedures.size() << std::endl;
465 for (
int m = 0; m < procedure->GetParameters().size(); m++)
467 std::shared_ptr<Otx::IProcedureParameter> param = procedure->GetParameters().at(m);
469 std::string name = param->GetName();
470 std::string dataType = param->GetDataType();
472 auto value = param->GetInitValue();
473 std::string valueStr = (value !=
nullptr ? value->ToLiteralString() :
"null");
475 if (std::shared_ptr<Otx::IProcedureInParameter> inParameter = std::dynamic_pointer_cast<Otx::IProcedureInParameter>(param))
478 stringConcat <<
" | | | |- " << name <<
" (" << dataType <<
"): " << valueStr <<
" (InParameter or InOutParameter)" << std::endl;
482 std::cout << stringConcat <<
" | | | |- " << name <<
" (" << dataType <<
"): " << valueStr <<
" (OutParameter)" << std::endl;
491 std::vector < std::shared_ptr<Otx::IProcedure>> DisplayPtxTree(std::shared_ptr<Project::IProject> project)
493 std::vector < std::shared_ptr<Otx::IProcedure>> procedures;
496 std::cout << std::endl <<
"PTX tree: " << std::endl;
498 std::cout <<
"- " << project->GetName() <<
" (Project)" << std::endl;
500 procedures = DisplayPtxPackageTree(procedures, project->GetPackages());
505 void SelectAndExecuteProcedure(std::shared_ptr<IRuntimeManager> runtimeManager, std::shared_ptr<Project::IProject> project, std::vector<std::shared_ptr<Otx::IProcedure>> procedures)
509 std::string procedureFullName;
510 std::cout << std::endl <<
"Enter Procedure (full name, code or 0 - if exit): ";
511 std::getline(std::cin, procedureFullName);
513 std::shared_ptr<Otx::IProcedure> procedure =
nullptr;
516 int idxProcedure = std::stoi(procedureFullName.c_str());
517 if (idxProcedure < 0 || idxProcedure>procedures.size() + 1)
519 std::cout << std::endl <<
"The procedure code is invalid.";
520 goto ReEnterProcedure;
522 else if (idxProcedure == 0 && procedureFullName.size() > 0)
528 procedure = procedures.at(idxProcedure - 1);
531 catch (
const std::exception&)
536 if (procedure !=
nullptr)
539 for (
int i = 0; i < procedure->GetParameters().size(); i++)
541 std::shared_ptr<Otx::IProcedureParameter> procedureParameter = procedure->GetParameters().at(i);
542 if (std::shared_ptr<Otx::IProcedureInParameter> inParameter = std::dynamic_pointer_cast<Otx::IProcedureInParameter>(procedureParameter))
544 bool isValidValue =
false;
551 std::cout <<
"Enter value of " << procedureParameter->GetName() <<
" (" << procedureParameter->GetDataType() <<
"): ";
552 std::getline(std::cin, value);
555 inParameter->SetValue(ValueConverter::String2Value(value, procedureParameter->GetDataType()));
558 catch (std::exception& ex)
560 isValidValue =
false;
561 std::cerr << ex.what() << std::endl;
563 }
while (!isValidValue);
565 else if (std::shared_ptr<Otx::IProcedureInOutParameter> inOutParameter = std::dynamic_pointer_cast<Otx::IProcedureInOutParameter>(procedureParameter))
567 bool isValidValue =
false;
574 std::cout <<
"Enter value of " << procedureParameter->GetName() <<
" (" << procedureParameter->GetDataType() <<
"): ";
575 std::getline(std::cin, value);
578 inOutParameter->SetValue(ValueConverter::String2Value(value, procedureParameter->GetDataType()));
581 catch (std::exception& ex)
583 isValidValue =
false;
584 std::cerr << ex.what() << std::endl;
586 }
while (!isValidValue);
590 isProcedureFinished =
false;
591 std::shared_ptr<IRuntimeContext> runtimeContext = runtimeManager->ExecuteAsync(procedure);
593 while (isProcedureFinished ==
false)
595 std::this_thread::sleep_for(std::chrono::milliseconds(1));
598 if (runtimeContext->HasOtxException())
600 std::cout << std::endl <<
"Otx exception occurred:" <<
"\t";
601 std::cout << runtimeContext->GetOtxException().GetOtxType() <<
":" << runtimeContext->GetOtxException().what() << std::endl;
603 else if (runtimeContext->HasRuntimeException())
605 std::cout << std::endl <<
"Runtime exception occurred:" <<
"\t";
606 std::cout << runtimeContext->GetRuntimeException().what() << std::endl;
611 std::cout <<
"Procedure " << procedureFullName <<
" does not exist!" << std::endl;
614 goto ReEnterProcedure;
617 std::string SelectProject(std::shared_ptr<IDiagConfiguration> diagConfiguration)
619 std::string projectSelected;
620 int indexProjectSelect = 0;
622 std::shared_ptr<IDiagConfiguration> diagConfig = diagConfiguration;
623 if (diagConfig == NULL)
625 diagConfig = CreateRawOtxDiag()->GetDiagConfiguration();
627 std::vector<std::string> projectList = diagConfig->GetDbProjectList();
629 if (projectList.size() > 0)
631 std::cout <<
"Select a ODX-Runtime-Project" << std::endl;
632 std::cout <<
"\t0 - None" << std::endl;
634 for (
size_t indexProjectItem = 0; indexProjectItem < projectList.size(); indexProjectItem++)
636 std::cout <<
"\t" << indexProjectItem + 1 <<
" - " << projectList.at(indexProjectItem) << std::endl;
642 std::cout <<
"Enter a number: ";
643 std::cin >> indexProjectSelect;
645 if (indexProjectSelect > 0 && indexProjectSelect - 1 < projectList.size())
647 projectSelected = projectList.at(indexProjectSelect - 1);
648 diagConfig->SelectProject(projectSelected);
652 return projectSelected;
655 std::string SelectVehicleInformation(std::shared_ptr<IDiagConfiguration> diagConfiguration)
657 std::string vehicleSelected;
658 int indexVehicleInformationSelect = 0;
660 std::shared_ptr<IDiagConfiguration> _diagConfiguration = diagConfiguration;
661 if (_diagConfiguration == NULL)
663 _diagConfiguration = CreateRawOtxDiag()->GetDiagConfiguration();
665 std::vector<std::string> vehicleInformationList = _diagConfiguration->GetDbVehicleInformationList();
667 for (
size_t indexVehicleInformationName = 0; indexVehicleInformationName < vehicleInformationList.size(); indexVehicleInformationName++)
669 std::cout <<
"\t" << indexVehicleInformationName + 1 <<
" - " << vehicleInformationList.at(indexVehicleInformationName) << std::endl;
675 std::cout <<
"Input vehicle information code: ";
676 std::cin >> indexVehicleInformationSelect;
678 if (indexVehicleInformationSelect > 0 && indexVehicleInformationSelect - 1 < vehicleInformationList.size())
680 vehicleSelected = vehicleInformationList.at(indexVehicleInformationSelect - 1);
681 _diagConfiguration->SelectVehicleInformation(vehicleSelected);
683 return vehicleSelected;
686 std::shared_ptr<IOtxDiag> CreateRawOtxDiag()
692 cp =
new CommandProcessor;
695 bool useVwmcdSP =
false;
699 OpenTestSystem::Otx::DiagManager::Client::ClientFactory clientFactory;
700 std::shared_ptr<OpenTestSystem::Otx::DiagManager::Client::Client> rawClient = clientFactory.CreateRawClient(cp);
701 Util::SetLicenseKey(rawClient, licenseKey);
702 const char* kernelPath = getenv(
"VW_MCD_HOME");
705 std::cout <<
"\tCannot read ENVIRONMENT VARIABLE 'VW_MCD_HOME'" << std::endl;
709 const char* configPath = getenv(
"VW_MCD_CONFIG");
712 std::cout <<
"\tCannot read ENVIRONMENT VARIABLE 'VW_MCD_CONFIG'" << std::endl;
716 std::cout <<
"\tVW_MCD_HOME = " << kernelPath << std::endl;
717 std::cout <<
"\tVW_MCD_CONFIG = " << configPath << std::endl;
718 IDiagRuntimeSystem* drs = CreateDiagRuntimeSystem(
"",
"", kernelPath, useVwmcdSP);
721 std::cout <<
"\tInitDiagRuntimeSystem failed!" << std::endl;
724 cp->SetRuntimeSystem(drs);
728 std::string GetLastErrorAsString()
731 DWORD errorMessageID = ::GetLastError();
732 if (errorMessageID == 0) {
733 return std::string();
736 LPSTR messageBuffer =
nullptr;
740 size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
741 NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
744 std::string message(messageBuffer, size);
747 LocalFree(messageBuffer);
753 IDiagRuntimeSystem* CreateDiagRuntimeSystem(
const char* projectName,
const char* vehicleInfo,
const char* kernelPath,
bool useVwmcdSP)
756 typedef IDiagRuntimeSystem* (__cdecl* typeCreateDiagRuntimeSystem)(
const char* projectName,
const char* vehicleInfo);
757 DiagRuntimeSystemDLL = NULL;
760 std::string DiagRuntimeSystem_17_50_FileName =
"OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcd_VC142.dll";
762 std::string DiagRuntimeSystemSP_17_50_FileName =
"OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcdSP_VC142.dll";
764 std::string DiagRuntimeSystem_09_00_FileName =
"OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.dll";
766 std::string DiagRuntimeSystemSP_09_00_FileName =
"OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcd90SP.dll";
769 std::string DiagRuntimeSystemFileName = DiagRuntimeSystem_17_50_FileName;
770 std::string kernelTypeStr =
"VwMcd1750";
774 kernelTypeStr =
"VwMcd1750SP";
775 DiagRuntimeSystemFileName = DiagRuntimeSystemSP_17_50_FileName;
778 if (fs::exists(std::string(kernelPath) +
"/McdKernel_vc120.dll"))
782 kernelTypeStr =
"VwMcd90SP";
783 DiagRuntimeSystemFileName = DiagRuntimeSystemSP_09_00_FileName;
787 kernelTypeStr =
"VwMcd90";
788 DiagRuntimeSystemFileName = DiagRuntimeSystem_09_00_FileName;
792 std::cout <<
"\tKernel Type is " << kernelTypeStr << std::endl;
794 DiagRuntimeSystemDLL = ::LoadLibrary(DiagRuntimeSystemFileName.c_str());
795 if (DiagRuntimeSystemDLL == NULL)
797 std::string errorMessage = GetLastErrorAsString();
798 std::cout << errorMessage << std::endl;
799 throw std::exception(errorMessage.c_str());
802 typedef IDiagRuntimeSystem* (__cdecl* typeCreateDiagRuntimeSystem)(
const char* projectName,
const char* vehicleInfo);
803 typeCreateDiagRuntimeSystem createFunction =
reinterpret_cast<typeCreateDiagRuntimeSystem
>(::GetProcAddress(DiagRuntimeSystemDLL,
"CreateDiagRuntimeSystem"));
805 if (createFunction ==
nullptr)
808 return createFunction(projectName, vehicleInfo);
809 #elif defined(__linux__) || defined(__QNXNTO__)
810 #ifdef USE_VWMCD_LINK_LIBRARY
811 return new VwMcdDiagRuntimeSystem(projectName, vehicleInfo);
813 if (!handle && useVwmcdSP ==
false)
815 std::cout <<
"Kernel Type is VwMcd" << std::endl;
816 handle = dlopen(
"libOpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcd.so", RTLD_NOW);
818 else if (!handle && useVwmcdSP ==
true)
820 std::cout <<
"Kernel Type is VwMcdSP" << std::endl;
821 handle = dlopen(
"libOpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.VwMcdSP.so", RTLD_NOW);
826 std::cout << dlerror() << std::endl;
829 typedef IDiagRuntimeSystem* typeCreateDiagRuntimeSystem(
const char* projectName,
const char* vehicleInfo);
830 typeCreateDiagRuntimeSystem* createFunction =
reinterpret_cast<typeCreateDiagRuntimeSystem*
>(dlsym(handle,
"CreateDiagRuntimeSystem"));
837 IDiagRuntimeSystem* digRuntimeSystem = createFunction(projectName, vehicleInfo);
839 createFunction = NULL;
840 return digRuntimeSystem;