OTX-Runtime for DotNet  
Own Command Processor

The interchangeable command processor sequences and optimizes Commands for access to the diagnostic runtime system. The command processor has the following functionalities:

  1. Receives commands and sends them to the DiagRuntimeSystem
  2. Manages one thread per client (sequencing)
  3. Manages the interface handling
  4. Manages the lifetime of diagnostic runtime objects, e.g. Caching, limitation and prioritization of ComChannel and DiagService objects
  5. Manages target system specific functions, e.g. ComChannel reservation or negative response handling

Note: The CommandProcessor must be implemented in C++.

Note: For more information to implement an own CommandProcessor, please contact the tool supplier.

Integration

  1. The own implementation must implement the interface ICommandProcessor
  2. Implement all relevant OTX and none OTX Commands for vehicle diagnostics, see methods of related OTX extensions in IOtxDiag and INoneOtxDiag
  3. Build the binary of the own implementation
  4. The own implementation must have an DiagRuntimeSystem attribute

Sample Implementation

The sections shows a sample implementation of the CommandProcessor.

Note: A complete example in C++ can be found inside the archive file below.

OwnCommandProcessorImplementationSample.rar

Sample OwnCommandProcessor Header File

#include "OwnCommandProcessorDefs.h"
#include <ICommandProcessor.h>
#include <IDiagRuntimeSystem.h>
#include <ISerializable.h>
#include <mutex>
#include <queue>
#include <Command.h>
class OwnCommandProcessor : public OpenTestSystem::Otx::DiagManager::Common::ICommandProcessor
{
private:
OpenTestSystem::Otx::DiagManager::Common::IDiagRuntimeSystem * _diagRuntimeSystem;
static std::mutex _mutex;
// <summary>
// A queue of command, this queue will be used when execute Async.
// </summary>
static std::queue <OpenTestSystem::Otx::DiagManager::Common::Command> _cmdQueue;
// <summary>
// True when executing commands in the queue.
// </summary>
static bool _isExecuting;
void AddCommandToQueue(const OpenTestSystem::Otx::DiagManager::Common::Command & command);
OpenTestSystem::Otx::DiagManager::Common::Command PopCommandFromQueue();
std::size_t GetCommandQueueSize();
public:
OwnCommandProcessor();
OwnCommandProcessor(OpenTestSystem::Otx::DiagManager::Common::IDiagRuntimeSystem * drs);
virtual ~OwnCommandProcessor();
OpenTestSystem::Otx::DiagManager::Common::Result * Execute(const OpenTestSystem::Otx::DiagManager::Common::Command & command) override;
OpenTestSystem::Otx::DiagManager::Common::Result * ExecuteAsync(const OpenTestSystem::Otx::DiagManager::Common::Command & command) override;
void SetAsyncResultHandler(std::function<void(const OpenTestSystem::Otx::DiagManager::Common::Result&)> handler) override;
void SetExceptionHandler(std::function<void(const OpenTestSystem::Otx::DiagManager::Common::Exception&)> handler) override;
};

Sample OwnCommandProcessor Cpp File

#include "OwnCommandProcessor.h"
// ProtoGenWrapper
#include <ComChannel.h>
bool OwnCommandProcessor::_isExecuting = false;
std::queue <OpenTestSystem::Otx::DiagManager::Common::Command> OwnCommandProcessor::_cmdQueue;
std::mutex OwnCommandProcessor::_mutex;
OwnCommandProcessor::OwnCommandProcessor()
: OwnCommandProcessor(nullptr)
{
}
OwnCommandProcessor::OwnCommandProcessor(OpenTestSystem::Otx::DiagManager::Common::IDiagRuntimeSystem * drs)
: _diagRuntimeSystem(drs)
{
}
OwnCommandProcessor::~OwnCommandProcessor()
{
delete _diagRuntimeSystem;
}
Result * OwnCommandProcessor::Execute(const Command & command)
{
if (_diagRuntimeSystem != nullptr)
return _diagRuntimeSystem->Execute(command);
return nullptr;
}
Result * OwnCommandProcessor::ExecuteAsync(const Command & command)
{
AddCommandToQueue(command);
if (_isExecuting == false)
{
do
{
_isExecuting = true;
if (_diagRuntimeSystem != nullptr)
{
Command cmd = PopCommandFromQueue();
_diagRuntimeSystem->ExecuteAsync(cmd);
}
}
while (GetCommandQueueSize() != 0);
_isExecuting = false;
}
return nullptr;
}
void OwnCommandProcessor::SetAsyncResultHandler(std::function<void(const Result&)> handler)
{
if (_diagRuntimeSystem != nullptr)
_diagRuntimeSystem->SetAsyncResultHandler(handler);
}
void OwnCommandProcessor::SetExceptionHandler(std::function<void(const Exception&)> handler)
{
if (_diagRuntimeSystem != nullptr)
_diagRuntimeSystem->SetExceptionHandler(handler);
}
void OwnCommandProcessor::AddCommandToQueue(const Command & command)
{
std::unique_lock<std::mutex> lock(_mutex);
_cmdQueue.push(command);
}
Command OwnCommandProcessor::PopCommandFromQueue()
{
std::unique_lock<std::mutex> lock(_mutex);
Command cmd = _cmdQueue.front();
_cmdQueue.pop();
return cmd;
}
std::size_t OwnCommandProcessor::GetCommandQueueSize()
{
std::unique_lock<std::mutex> lock(_mutex);
return _cmdQueue.size();
}
Namespace containing all common methods for the DiagManage