Woman, Life, Freedom


OBD-II Emulator
Linux ODB-II Emulator public and protected interfaces documentation
ObdEmulator::SerialCommunication Class Reference

Serial port communication layer. More...

#include <serial_communication.h>

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

Public Member Functions

 SerialCommunication (std::string serialPort, speed_t baudrate, int timeout=1)
 Constructor. More...
 
bool TryStart (std::vector< uint8_t > &&configuration) override
 Try to start the communication. More...
 
bool TrySendAsync (std::vector< uint8_t > &&data) override
 Try to buffer data for sending. More...
 
bool TryStop () override
 Try to stop the communication. More...
 
- Public Member Functions inherited from ObdEmulator::CommunicationLayer
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...
 

Additional Inherited Members

- Public Types inherited from ObdEmulator::CommunicationLayer
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.
 
- Protected Attributes inherited from ObdEmulator::CommunicationLayer
CallbackType Callback
 Callback to be invoked when data received.
 
AsyncCallbackType AsyncCallback
 Callback to be invoked when data received asynch.
 

Detailed Description

Serial port communication layer.

Constructor & Destructor Documentation

◆ SerialCommunication()

ObdEmulator::SerialCommunication::SerialCommunication ( std::string  serialPort,
speed_t  baudrate,
int  timeout = 1 
)

Constructor.

Parameters
serialPortSerial port address
baudrateSerial communication baud rate
timeoutPolling timeout in milliseconds (1 ms by default)
Exceptions
std::runtime_errorThrows if the flow control signal creation failed

Member Function Documentation

◆ TrySendAsync()

bool ObdEmulator::SerialCommunication::TrySendAsync ( std::vector< uint8_t > &&  data)
overridevirtual

Try to buffer data for sending.

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

Implements ObdEmulator::CommunicationLayer.

◆ TryStart()

bool ObdEmulator::SerialCommunication::TryStart ( std::vector< uint8_t > &&  configuration)
overridevirtual

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

Implements ObdEmulator::CommunicationLayer.

◆ TryStop()

bool ObdEmulator::SerialCommunication::TryStop ( )
overridevirtual

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

Implements ObdEmulator::CommunicationLayer.