-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOBD.Service.Types.pas
245 lines (228 loc) · 7.54 KB
/
OBD.Service.Types.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//------------------------------------------------------------------------------
// UNIT : OBD.Service.Types.pas
// CONTENTS : OBD Service Types
// VERSION : 1.0
// TARGET : Embarcadero Delphi 11 or higher
// AUTHOR : Ernst Reidinga (ERDesigns)
// STATUS : Open source under Apache 2.0 library
// COMPATIBILITY : Windows 7, 8/8.1, 10, 11
// RELEASE DATE : 15/03/2024
//------------------------------------------------------------------------------
unit OBD.Service.Types;
interface
uses
System.SysUtils, System.Classes, System.Generics.Defaults, System.Generics.Collections;
//------------------------------------------------------------------------------
// COMPARERS
//------------------------------------------------------------------------------
type
/// <summary>
/// Comparer for supported PID's
/// </summary>
TOBDServiceSupportedPIDComparer = class(TInterfacedObject, IComparer<Byte>)
public
function Compare(const Left, Right: Byte): Integer;
end;
//------------------------------------------------------------------------------
// OTHER
//------------------------------------------------------------------------------
type
/// <summary>
/// OBD Service 01 Parameter 01 (Engine Type)
/// </summary>
TOBDServiceEngineType = (etUnknown, etSparkIgnition, etCompressionIgnition);
/// <summary>
/// OBD Service 01 Parameter 03 (Fuel system status)
/// </summary>
TOBDServiceFuelSystemStatus = (fsUnknown, fssMotorOff, fssOpenLoopInsufficientTemp, fssClosedLoop, fssOpenLoopEngineLoad, fssOpenLoopSystemFailure, fssClosedLoopFault);
/// <summary>
/// OBD Service 01 Parameter 12 (Commanded secondary air status)
/// </summary>
TOBDServiceCommandedSecondaryAirStatus = (sasUnknown, sasUpstream, sasDownstream, sasAtmosphereOff, sasDiagnostics);
/// <summary>
/// OBD Service 01 Parameter 1E (Auxiliary input status)
/// </summary>
TOBDServiceAuxilaryInputStatus = (aisUnknown, aisPowerTakeOff, aisActive);
/// <summary>
/// OBD Service 03 (Diagnostic Trouble Codes) Category
/// </summary>
TOBDServiceDTCCategory = (ccUnknown, ccPowerTrain, ccChassis, ccBody, ccNetwork);
/// <summary>
/// OBD Service 03 (Diagnostic Trouble Codes) Origin
/// </summary>
TOBDServiceDTCOrigin = (coUnknown, coGeneric, coManufacturer);
//------------------------------------------------------------------------------
// EVENTS
//------------------------------------------------------------------------------
type
/// <summary>
/// Service Error Response event
/// </summary>
/// <param name="Sender">
/// Object calling this event
/// </param>
/// <param name="Error">
/// Error (NSC) Byte.
/// </param>
/// <param name="AdditionalData">
/// Additional data bytes (optional) - Manufacturer specific
/// </param>
TOBDServiceErrorResponseEvent = procedure(Sender: TObject; Error: Byte; AdditionalData: TBytes) of object;
/// <summary>
/// OBD Service Data event
/// </summary>
/// <param name="Sender">
/// Object calling this event
/// </param>
/// <param name="SID">
/// Service ID
/// </param>
/// <param name="PID">
/// Parameter ID
/// </param>
TOBDServiceDataEvent = procedure(Sender: TObject; SID: Byte; PID: Integer) of object;
//------------------------------------------------------------------------------
// INTERFACES
//------------------------------------------------------------------------------
type
/// <summary>
/// OBD Service Diagnostic Trouble Code (INTERFACE)
/// </summary>
IOBDServiceDiagnosticTroubleCode = interface
['{42764FB3-12D3-4711-B9A5-42D9A3F1AD3B}']
/// <summary>
/// Get the category
/// </summary>
function GetCategory: TOBDServiceDTCCategory;
/// <summary>
/// Get the origin
/// </summary>
function GetOrigin: TOBDServiceDTCOrigin;
/// <summary>
/// Get the Diagnostic Trouble Code String
/// </summary>
function GetDTC: string;
/// <summary>
/// DTC category
/// </summary>
property Category: TOBDServiceDTCCategory read GetCategory;
/// <summary>
/// DTC origin
/// </summary>
property Origin: TOBDServiceDTCOrigin read GetOrigin;
/// <summary>
/// DTC string
/// </summary>
property DTC: string read GetDTC;
end;
//------------------------------------------------------------------------------
// CLASSES
//------------------------------------------------------------------------------
type
/// <summary>
/// OBD Service Diagnostic Trouble Code (CLASS)
/// </summary>
TOBDServiceDiagnosticTroubleCode = class
private
/// <summary>
/// Category
/// </summary>
FCategory: TOBDServiceDTCCategory;
/// <summary>
/// Origin
/// </summary>
FOrigin: TOBDServiceDTCOrigin;
/// <summary>
/// DTC string
/// </summary>
FDTC: string;
protected
/// <summary>
/// Get the category
/// </summary>
function GetCategory: TOBDServiceDTCCategory;
/// <summary>
/// Get the origin
/// </summary>
function GetOrigin: TOBDServiceDTCOrigin;
/// <summary>
/// Get the Diagnostic Trouble Code String
/// </summary>
function GetDTC: string;
public
/// <summary>
/// Constructor
/// </summary>
constructor Create(DTC: string); virtual;
/// <summary>
/// DTC category
/// </summary>
property Category: TOBDServiceDTCCategory read GetCategory;
/// <summary>
/// DTC origin
/// </summary>
property Origin: TOBDServiceDTCOrigin read GetOrigin;
/// <summary>
/// DTC string
/// </summary>
property DTC: string read GetDTC;
end;
implementation
//------------------------------------------------------------------------------
// COMPARE SUPPORTED PID
//------------------------------------------------------------------------------
function TOBDServiceSupportedPIDComparer.Compare(const Left, Right: Byte): Integer;
begin
if Left < Right then
Result := -1
else if Left > Right then
Result := 1
else
Result := 0;
end;
//------------------------------------------------------------------------------
// DTC: GET CATEGORY
//------------------------------------------------------------------------------
function TOBDServiceDiagnosticTroubleCode.GetCategory: TOBDServiceDTCCategory;
begin
Result := FCategory;
end;
//------------------------------------------------------------------------------
// DTC: GET ORIGIN
//------------------------------------------------------------------------------
function TOBDServiceDiagnosticTroubleCode.GetOrigin: TOBDServiceDTCOrigin;
begin
Result := FOrigin;
end;
//------------------------------------------------------------------------------
// DTC: GET DTC STRING
//------------------------------------------------------------------------------
function TOBDServiceDiagnosticTroubleCode.GetDTC: string;
begin
Result := FDTC;
end;
//------------------------------------------------------------------------------
// DTC: CONSTRUCTOR
//------------------------------------------------------------------------------
constructor TOBDServiceDiagnosticTroubleCode.Create(DTC: string);
begin
// Call inherited constructor
inherited Create;
// Set DTC string
FDTC := DTC;
// Set category
case DTC[1] of
'P': FCategory := ccPowerTrain;
'C': FCategory := ccChassis;
'B': FCategory := ccBody;
'U': FCategory := ccNetwork;
else FCategory := ccUnknown;
end;
// Set origin
case DTC[2] of
'0': FOrigin := coGeneric;
'1': FOrigin := coManufacturer;
else FOrigin := coUnknown;
end;
end;
end.