Woman, Life, Freedom


OBD-II Emulator
Linux ODB-II Emulator public and protected interfaces documentation
ObdEmulator::CommunicationLayer Class Referenceabstract

Communication medium abstraction layer to send and receive data. More...

#include <communication_layer.h>

Inheritance diagram for ObdEmulator::CommunicationLayer:
ObdEmulator::SerialCommunication

Public Types

using CallbackType = std::function< bool(std::vector< uint8_t > &&, std::vector< uint8_t > &)>
 Data received callback type. More...
 
using AsyncCallbackType = std::function< void(std::vector< uint8_t > &&)>
 Data received callback type to handle the data asynchronously.
 

Public Member Functions

virtual bool TryStart (std::vector< uint8_t > &&configuration)=0
 Try to start the communication. More...
 
virtual bool TrySendAsync (std::vector< uint8_t > &&data)=0
 Try to buffer data for sending. More...
 
void SetCallback (CallbackType &&callback)
 Set a data received callback and reset the asynchronized callback. More...
 
void SetCallback (AsyncCallbackType &&asyncCallback)
 Set a data received asynchronous callback and reset the synchronized callback. More...
 
void ResetCallback () noexcept
 Reset both data received synchronized and asynchronized callbacks. More...
 
virtual bool TryStop ()=0
 Try to stop the communication. More...
 

Protected Attributes

CallbackType Callback
 Callback to be invoked when data received.
 
AsyncCallbackType AsyncCallback
 Callback to be invoked when data received asynch.
 

Detailed Description

Communication medium abstraction layer to send and receive data.

Member Typedef Documentation

◆ CallbackType

using ObdEmulator::CommunicationLayer::CallbackType = std::function<bool(std::vector<uint8_t> &&, std::vector<uint8_t> &)>

Data received callback type.

The caller moves the received byte array to the callback and expects the handler to return a boolean that indiciates whether or not it fills the other byte array refenrece as the response.

Member Function Documentation

◆ ResetCallback()

void ObdEmulator::CommunicationLayer::ResetCallback ( )
noexcept

Reset both data received synchronized and asynchronized callbacks.

See also
SetCallback(CallbackType)
SetCallback(AsyncCallbackType)

◆ SetCallback() [1/2]

void ObdEmulator::CommunicationLayer::SetCallback ( AsyncCallbackType &&  asyncCallback)

Set a data received asynchronous callback and reset the synchronized callback.

Parameters
asyncCallbackCallback to be invoked when a data is received for asynchronous data handling

◆ SetCallback() [2/2]

void ObdEmulator::CommunicationLayer::SetCallback ( CallbackType &&  callback)

Set a data received callback and reset the asynchronized callback.

Parameters
callbackCallback to be invoked when a data is received

◆ TrySendAsync()

virtual bool ObdEmulator::CommunicationLayer::TrySendAsync ( std::vector< uint8_t > &&  data)
pure virtual

Try to buffer data for sending.

Parameters
dataData to be buffered for sending
Returns
True if the data is buffered successfully, otherwise false

Implemented in ObdEmulator::SerialCommunication.

◆ TryStart()

virtual bool ObdEmulator::CommunicationLayer::TryStart ( std::vector< uint8_t > &&  configuration)
pure virtual

Try to start the communication.

Parameters
configurationConfiguration packet to sent to the endpoint right after the communication start
Returns
True if the communication start was successful, otherwise false

Implemented in ObdEmulator::SerialCommunication.

◆ TryStop()

virtual bool ObdEmulator::CommunicationLayer::TryStop ( )
pure virtual

Try to stop the communication.

Returns
True if the communication stop was successful, otherwise false
Note
As the method side effect, it may clear the send and receive buffer

Implemented in ObdEmulator::SerialCommunication.