blob: a59372f63d8202beaa18769a7086da58d61871c6 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001/** @file asn1Msd.h
2 *
3 * This file contains the declarations of the ASN1 MSD builder.
4 *
5 * Copyright (C) Sierra Wireless Inc.
6 */
7/*================================================================
8 Copyright (c) 2018 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
9 Quectel Wireless Solution Proprietary and Confidential.
10 =================================================================*/
11/*=================================================================
12
13 EDIT HISTORY FOR MODULE
14
15 This section contains comments describing changes made to the module.
16 Notice that changes are listed in reverse chronological order.
17
18 WHEN WHO WHAT, WHERE, WHY
19 ------------ ------- ---------------------------------------
20 04/12/2018 laurence Init.
21 =================================================================*/
22
23#ifndef _ASN1_MSD_INCLUDE_GUARD_
24#define _ASN1_MSD_INCLUDE_GUARD_
25
26#include <stdint.h>
27#include <stdbool.h>
28#include <string.h>
29
30#ifndef NULL
31#define NULL 0
32#endif
33
34//--------------------------------------------------------------------------------------------------
35// Defines
36//--------------------------------------------------------------------------------------------------
37
38//--------------------------------------------------------------------------------------------------
39/**
40 * Position N-1 and N-2 are delta positions.
41 * Limits as defined in FprEN 15722:2014
42 * These are the max and min values for the msd_VehicleLocationDelta_t members
43 */
44//--------------------------------------------------------------------------------------------------
45#define ASN1_LATITUDE_DELTA_MAX 511
46#define ASN1_LATITUDE_DELTA_MIN -512
47#define ASN1_LONGITUDE_DELTA_MAX 511
48#define ASN1_LONGITUDE_DELTA_MIN -512
49#define ASN1_ECALL_MSD_VERSION_1 1
50#define ASN1_ECALL_MSD_VERSION_2 2
51#define ASN1_ECALL_MSD_VERSION_3 3
52
53
54#define QL_ECALL_MAX_VIN 20
55
56//--------------------------------------------------------------------------------------------------
57// Symbols and enums.
58//--------------------------------------------------------------------------------------------------
59typedef enum
60{
61 QL_ERR_MSD_NONE = 0,
62 QL_ERR_MSD_SUCCESS = QL_ERR_MSD_NONE,
63 QL_ERR_MSD_GENERIC = -(QL_ERR_MSD_NONE+1), /**< MSD Generic ERROR. */
64 QL_ERR_MSD_BADPARM = -(QL_ERR_MSD_NONE+2), /**< MSD Bad parameter ERROR. */
65 QL_ERR_MSD_VERSION = -(QL_ERR_MSD_NONE+3), /**< MSD VERSION ERROR. */
66 QL_ERR_MSD_ISOWMI = -(QL_ERR_MSD_NONE+2), /**< MSD wmi ERROR. */
67 QL_ERR_MSD_ISOVDS = -(QL_ERR_MSD_NONE+4), /**< MSD vds ERROR. */
68 QL_ERR_MSD_ISOVIS_MODELYEAR = -(QL_ERR_MSD_NONE+5), /**< MSD model year ERROR. */
69 QL_ERR_MSD_ISOVIS_SEQPLAN = -(QL_ERR_MSD_NONE+6), /**< MSD seplan ERROR. */
70 QL_ERR_MSD_LATITUDE = -(QL_ERR_MSD_NONE+7), /**< MSD latitude ERROR. */
71 QL_ERR_MSD_LONGITUDE = -(QL_ERR_MSD_NONE+8), /**< MSD longitude ERROR. */
72 QL_ERR_MSD_VEH_DIRECTION = -(QL_ERR_MSD_NONE+9), /**< MSD vehDirection ERROR. */
73 QL_ERR_MSD_VEH_LAT_LOCATION1 = -(QL_ERR_MSD_NONE+10), /**< MSD recentVehLocationN1 latitude ERROR. */
74 QL_ERR_MSD_VEH_LON_LOCATION1 = -(QL_ERR_MSD_NONE+11), /**< MSD recentVehLocationN1 longitude ERROR. */
75 QL_ERR_MSD_VEH_LAT_LOCATION2 = -(QL_ERR_MSD_NONE+12), /**< MSD recentVehLocationN2 latitude ERROR. */
76 QL_ERR_MSD_VEH_LON_LOCATION2 = -(QL_ERR_MSD_NONE+13), /**< MSD recentVehLocationN2 longitude ERROR. */
77 QL_ERR_MSD_VEH_IDENTIFI_NUMBER = -(QL_ERR_MSD_NONE+14), /**< MSD vehIdentification Number ERROR. */
78 QL_ERR_MSD_OPTINAL_DATA_GLONASS = -(QL_ERR_MSD_NONE+15), /**< MSD Optional Data For Era Glonass ERROR. */
79} QL_ERR_MSD_RESULT_E;
80
81//--------------------------------------------------------------------------------------------------
82/**
83 * Enumeration used to specify the type of vehicle.
84 */
85//--------------------------------------------------------------------------------------------------
86typedef enum
87{
88 MSD_VEHICLE_PASSENGER_M1=1, ///< Passenger vehicle (Class M1)
89 MSD_VEHICLE_BUS_M2, ///< Buses and coaches (Class M2)
90 MSD_VEHICLE_BUS_M3, ///< Buses and coaches (Class M3)
91 MSD_VEHICLE_COMMERCIAL_N1, ///< Light commercial vehicles (Class N1)
92 MSD_VEHICLE_HEAVY_N2, ///< Heavy duty vehicles (Class N2)
93 MSD_VEHICLE_HEAVY_N3, ///< Heavy duty vehicles (Class N3)
94 MSD_VEHICLE_MOTORCYCLE_L1E, ///< Motorcycles (Class L1e)
95 MSD_VEHICLE_MOTORCYCLE_L2E, ///< Motorcycles (Class L2e)
96 MSD_VEHICLE_MOTORCYCLE_L3E, ///< Motorcycles (Class L3e)
97 MSD_VEHICLE_MOTORCYCLE_L4E, ///< Motorcycles (Class L4e)
98 MSD_VEHICLE_MOTORCYCLE_L5E, ///< Motorcycles (Class L5e)
99 MSD_VEHICLE_MOTORCYCLE_L6E, ///< Motorcycles (Class L6e)
100 MSD_VEHICLE_MOTORCYCLE_L7E, ///< Motorcycles (Class L7e)
101} MSD_VEHICLE_TYPE_E;
102
103//--------------------------------------------------------------------------------------------------
104/**
105 * Enumeration used to specify the propulsion type.
106 */
107//--------------------------------------------------------------------------------------------------
108typedef enum
109{
110 ECALL_MSD_PROPULSION_TYPE_GASOLINE=0x1,
111 ECALL_MSD_PROPULSION_TYPE_DIESEL=0x2,
112 ECALL_MSD_PROPULSION_TYPE_NATURALGAS=0x4,
113 ECALL_MSD_PROPULSION_TYPE_PROPANE=0x8,
114 ECALL_MSD_PROPULSION_TYPE_ELECTRIC=0x10,
115 ECALL_MSD_PROPULSION_TYPE_HYDROGEN=0x20,
116 ECALL_MSD_PROPULSION_TYPE_OTHER=0x40,
117} ECALL_MSD_PROPULSION_TYPE_E;
118
119//--------------------------------------------------------------------------------------------------
120/**
121 * Enumeration used to specify the type of coordinate system.
122 */
123//--------------------------------------------------------------------------------------------------
124typedef enum
125{
126 MSD_COORDINATE_SYSTEM_TYPE_ABSENT, ///< Coordinate system type is absent
127 MSD_COORDINATE_SYSTEM_TYPE_WGS84, ///< Coordinate system type WGS-84
128 MSD_COORDINATE_SYSTEM_TYPE_PZ90 ///< Coordinate system type PZ-90
129} ECALL_MSD_COORINATE_SYSTEM_TYPE_E;
130
131typedef enum
132{
133 ECALL_SYSTEM_STD_PAN_EUROPEAN, //< PAN-European system.
134 ECALL_SYSTEM_STD_ERA_GLONASS //< ERA-GLONASS system.
135} ECALL_SYSTEM_STD_E;
136//--------------------------------------------------------------------------------------------------
137// Data structures.
138//--------------------------------------------------------------------------------------------------
139
140//--------------------------------------------------------------------------------------------------
141/**
142 * Data structure describing the VIN (Vehicle Identification Number).
143 *
144 */
145//--------------------------------------------------------------------------------------------------
146typedef struct{
147 char isowmi[4];
148 char isovds[7];
149 char isovisModelyear[2];
150 char isovisSeqPlant[8];
151} msd_Vin_t;
152
153/* ControlType */
154//--------------------------------------------------------------------------------------------------
155/**
156 * Data structure describing the main control elements of the MSD.
157 *
158 */
159//--------------------------------------------------------------------------------------------------
160typedef struct {
161 bool automaticActivation;
162 bool testCall;
163 bool positionCanBeTrusted;
164 MSD_VEHICLE_TYPE_E vehType;
165} msd_Control_t;
166
167//--------------------------------------------------------------------------------------------------
168/**
169 * Data structure describing the vehicle propulsion storage type.
170 *
171 */
172//--------------------------------------------------------------------------------------------------
173typedef struct {
174 bool gasolineTankPresent;
175 bool dieselTankPresent;
176 bool compressedNaturalGas;
177 bool liquidPropaneGas;
178 bool electricEnergyStorage;
179 bool hydrogenStorage;
180 bool otherStorage;
181} msd_VehiclePropulsionStorageType_t;
182
183//--------------------------------------------------------------------------------------------------
184/**
185 * Data structure describing the last known vehicle location.
186 *
187 */
188//--------------------------------------------------------------------------------------------------
189typedef struct {
190 int32_t latitude;
191 int32_t longitude;
192} msd_VehicleLocation_t;
193
194//--------------------------------------------------------------------------------------------------
195/**
196 * Data structure describing the location of the vehicle some time before the generation of the data
197 * for the MSD message..
198 *
199 */
200//--------------------------------------------------------------------------------------------------
201typedef struct {
202 int32_t latitudeDelta;
203 int32_t longitudeDelta;
204} msd_VehicleLocationDelta_t;
205
206//--------------------------------------------------------------------------------------------------
207/**
208 * Data structure to gather optional data.
209 *
210 */
211//--------------------------------------------------------------------------------------------------
212typedef struct {
213 uint8_t oidlen;
214 uint8_t dataLen;
215 uint8_t* oid;
216 uint8_t* data;
217} msd_optionalData_t;
218
219//--------------------------------------------------------------------------------------------------
220/**
221 * Data structure describing the MSD without the additional optional data.
222 *
223 */
224//--------------------------------------------------------------------------------------------------
225typedef struct {
226 uint8_t messageIdentifier;
227 msd_Control_t control;
228 msd_Vin_t vehIdentificationNumber;
229 msd_VehiclePropulsionStorageType_t vehPropulsionStorageType;
230 uint32_t timestamp;
231 msd_VehicleLocation_t vehLocation;
232 uint8_t vehDirection;
233 /* Optional */
234 bool recentVehLocationN1Pres;
235 msd_VehicleLocationDelta_t recentVehLocationN1;
236 /* Optional */
237 bool recentVehLocationN2Pres;
238 msd_VehicleLocationDelta_t recentVehLocationN2;
239 /* Optional */
240 bool numberOfPassengersPres;
241 uint8_t numberOfPassengers;
242} msd_Structure_t;
243
244//--------------------------------------------------------------------------------------------------
245/**
246 * Data structure describing the MSD with the additional optional data.
247 *
248 */
249//--------------------------------------------------------------------------------------------------
250typedef struct {
251 msd_Structure_t msdStruct;
252 /* Optional */
253 bool optionalDataPres;
254 msd_optionalData_t optionalData;
255} msd_Message_t;
256
257//--------------------------------------------------------------------------------------------------
258/**
259 * Data structure describing the MSD message.
260 *
261 */
262//--------------------------------------------------------------------------------------------------
263typedef struct {
264 uint8_t version;
265 msd_Message_t msdMsg;
266} msd_t;
267
268
269/* ERA GLONASS specific types for the OptionalData_t parts */
270//--------------------------------------------------------------------------------------------------
271/**
272 * Data structure to gather the ERA GLONASS specific data.
273 *
274 */
275//--------------------------------------------------------------------------------------------------
276
277typedef struct {
278 /*
279 * ERAAdditionalData ::= SEQUENCE {
280 * crashSeverity INTEGER(0..2047) OPTIONAL,
281 * diagnosticResult DiagnosticResult OPTIONAL,
282 * crashInfo CrashInfo OPTIONAL,
283 * coordinateSystemType CoordinateSystemType DEFAULT wgs84,
284 * ...
285 * }
286 */
287 uint8_t msdVersion;
288
289 bool presentCrashSeverity;
290 uint32_t crashSeverity; /* INTEGER(0..2047) OPTIONAL */
291
292 bool presentDiagnosticResult;
293 struct
294 {
295 bool presentMicConnectionFailure;
296 bool micConnectionFailure;
297
298 bool presentMicFailure;
299 bool micFailure;
300
301 bool presentRightSpeakerFailure;
302 bool rightSpeakerFailure;
303
304 bool presentLeftSpeakerFailure;
305 bool leftSpeakerFailure;
306
307 bool presentSpeakersFailure;
308 bool speakersFailure;
309
310 bool presentIgnitionLineFailure;
311 bool ignitionLineFailure;
312
313 bool presentUimFailure;
314 bool uimFailure;
315
316 bool presentStatusIndicatorFailure;
317 bool statusIndicatorFailure;
318
319 bool presentBatteryFailure;
320 bool batteryFailure;
321
322 bool presentBatteryVoltageLow;
323 bool batteryVoltageLow;
324
325 bool presentCrashSensorFailure;
326 bool crashSensorFailure;
327
328 bool presentFirmwareImageCorruption;
329 bool firmwareImageCorruption;
330
331 bool presentCommModuleInterfaceFailure;
332 bool commModuleInterfaceFailure;
333
334 bool presentGnssReceiverFailure;
335 bool gnssReceiverFailure;
336
337 bool presentRaimProblem;
338 bool raimProblem;
339
340 bool presentGnssAntennaFailure;
341 bool gnssAntennaFailure;
342
343 bool presentCommModuleFailure;
344 bool commModuleFailure;
345
346 bool presentEventsMemoryOverflow;
347 bool eventsMemoryOverflow;
348
349 bool presentCrashProfileMemoryOverflow;
350 bool crashProfileMemoryOverflow;
351
352 bool presentOtherCriticalFailures;
353 bool otherCriticalFailures;
354
355 bool presentOtherNotCriticalFailures;
356 bool otherNotCriticalFailures;
357 } diagnosticResult;
358
359 bool presentCrashInfo;
360 struct
361 {
362 bool presentCrashFront;
363 bool crashFront;
364
365 bool presentCrashLeft;
366 bool crashLeft;
367
368 bool presentCrashRight;
369 bool crashRight;
370
371 bool presentCrashRear;
372 bool crashRear;
373
374 bool presentCrashRollover;
375 bool crashRollover;
376
377 bool presentCrashSide;
378 bool crashSide;
379
380 bool presentCrashFrontOrSide;
381 bool crashFrontOrSide;
382
383 bool presentCrashAnotherType;
384 bool crashAnotherType;
385 } crashType;
386
387 bool presentCoordinateSystemTypeInfo;
388 ECALL_MSD_COORINATE_SYSTEM_TYPE_E coordinateSystemType;
389} msd_EraGlonassData_t;
390
391typedef struct ecall ecall_t;
392
393void print_msd_hexstr(uint8_t *msd,uint32_t msd_len);
394
395QL_ERR_MSD_RESULT_E ql_msd_encode
396(
397 uint8_t *pBuiltMsd, //< built MSD
398 uint32_t *pBuiltMsdSize, //< Size of the built MSDvoid
399 ECALL_SYSTEM_STD_E systemStandard,
400 msd_EraGlonassData_t eraGlonassDataObj,
401 msd_t msdContent
402);
403
404bool IsVinValid
405(
406 msd_Vin_t vin
407);
408
409int32_t ConvertDdToDms
410(
411 int32_t ddVal
412);
413
414
415
416#endif // _ASN1_MSD_INCLUDE_GUARD_