Woman, Life, Freedom


OBD-II Emulator
Linux ODB-II Emulator public and protected interfaces documentation
obd_service.h
1#ifndef OBD_SERVICE_H
2#define OBD_SERVICE_H
3
4#include <functional>
5#include <stdint.h>
6#include <vector>
7
8namespace ObdEmulator
9{
12 {
13 private:
14 const uint8_t mService;
15
16 public:
18 using CallbackType = std::function<void(const std::vector<uint8_t> &, std::vector<uint8_t> &&, uint8_t)>;
19
20 protected:
23 ObdService(uint8_t service) noexcept;
24
26 using InternalCallbackType = std::function<void(const std::vector<uint8_t> &, std::vector<uint8_t> &&)>;
27
28 InternalCallbackType Callback;
29
30 public:
31 virtual ~ObdService() noexcept;
32
35 uint8_t GetService() const noexcept;
36
39 void SetCallback(CallbackType &&callback);
40
46 virtual bool TryGetResponse(
47 const std::vector<uint8_t> &pid,
48 std::vector<uint8_t> &response) const = 0;
49
54 virtual bool TryGetResponseAsync(
55 const std::vector<uint8_t> &pid) = 0;
56
58 void ResetCallback() noexcept;
59 };
60}
61
62#endif
A class that defines an OBD-II service based on SAE J1979 standard.
Definition: obd_service.h:12
virtual bool TryGetResponse(const std::vector< uint8_t > &pid, std::vector< uint8_t > &response) const =0
Try to get an emulated response based the queried PID.
std::function< void(const std::vector< uint8_t > &, std::vector< uint8_t > &&)> InternalCallbackType
Service specific response ready callback type.
Definition: obd_service.h:26
virtual bool TryGetResponseAsync(const std::vector< uint8_t > &pid)=0
Try to get an emulated response asynchronously based the queried PID.
void ResetCallback() noexcept
Reset the response ready callback.
void SetCallback(CallbackType &&callback)
Set the response ready callback.
uint8_t GetService() const noexcept
Get the service.
std::function< void(const std::vector< uint8_t > &, std::vector< uint8_t > &&, uint8_t)> CallbackType
Response ready callback type.
Definition: obd_service.h:18
ObdService(uint8_t service) noexcept
Constructor.