| /** @file asn1Msd.h |
| * |
| * This file contains the declarations of the ASN1 MSD builder. |
| * |
| * Copyright (C) Sierra Wireless Inc. |
| */ |
| /*================================================================ |
| Copyright (c) 2018 Quectel Wireless Solution, Co., Ltd. All Rights Reserved. |
| Quectel Wireless Solution Proprietary and Confidential. |
| =================================================================*/ |
| /*================================================================= |
| |
| EDIT HISTORY FOR MODULE |
| |
| This section contains comments describing changes made to the module. |
| Notice that changes are listed in reverse chronological order. |
| |
| WHEN WHO WHAT, WHERE, WHY |
| ------------ ------- --------------------------------------- |
| 04/12/2018 laurence Init. |
| =================================================================*/ |
| |
| #ifndef _ASN1_MSD_INCLUDE_GUARD_ |
| #define _ASN1_MSD_INCLUDE_GUARD_ |
| |
| #include <stdint.h> |
| #include <stdbool.h> |
| #include <string.h> |
| |
| #ifndef NULL |
| #define NULL 0 |
| #endif |
| |
| //-------------------------------------------------------------------------------------------------- |
| // Defines |
| //-------------------------------------------------------------------------------------------------- |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Position N-1 and N-2 are delta positions. |
| * Limits as defined in FprEN 15722:2014 |
| * These are the max and min values for the msd_VehicleLocationDelta_t members |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| #define ASN1_LATITUDE_DELTA_MAX 511 |
| #define ASN1_LATITUDE_DELTA_MIN -512 |
| #define ASN1_LONGITUDE_DELTA_MAX 511 |
| #define ASN1_LONGITUDE_DELTA_MIN -512 |
| #define ASN1_ECALL_MSD_VERSION_1 1 |
| #define ASN1_ECALL_MSD_VERSION_2 2 |
| #define ASN1_ECALL_MSD_VERSION_3 3 |
| |
| |
| #define QL_ECALL_MAX_VIN 20 |
| |
| //-------------------------------------------------------------------------------------------------- |
| // Symbols and enums. |
| //-------------------------------------------------------------------------------------------------- |
| typedef enum |
| { |
| QL_ERR_MSD_NONE = 0, |
| QL_ERR_MSD_SUCCESS = QL_ERR_MSD_NONE, |
| QL_ERR_MSD_GENERIC = -(QL_ERR_MSD_NONE+1), /**< MSD Generic ERROR. */ |
| QL_ERR_MSD_BADPARM = -(QL_ERR_MSD_NONE+2), /**< MSD Bad parameter ERROR. */ |
| QL_ERR_MSD_VERSION = -(QL_ERR_MSD_NONE+3), /**< MSD VERSION ERROR. */ |
| QL_ERR_MSD_ISOWMI = -(QL_ERR_MSD_NONE+2), /**< MSD wmi ERROR. */ |
| QL_ERR_MSD_ISOVDS = -(QL_ERR_MSD_NONE+4), /**< MSD vds ERROR. */ |
| QL_ERR_MSD_ISOVIS_MODELYEAR = -(QL_ERR_MSD_NONE+5), /**< MSD model year ERROR. */ |
| QL_ERR_MSD_ISOVIS_SEQPLAN = -(QL_ERR_MSD_NONE+6), /**< MSD seplan ERROR. */ |
| QL_ERR_MSD_LATITUDE = -(QL_ERR_MSD_NONE+7), /**< MSD latitude ERROR. */ |
| QL_ERR_MSD_LONGITUDE = -(QL_ERR_MSD_NONE+8), /**< MSD longitude ERROR. */ |
| QL_ERR_MSD_VEH_DIRECTION = -(QL_ERR_MSD_NONE+9), /**< MSD vehDirection ERROR. */ |
| QL_ERR_MSD_VEH_LAT_LOCATION1 = -(QL_ERR_MSD_NONE+10), /**< MSD recentVehLocationN1 latitude ERROR. */ |
| QL_ERR_MSD_VEH_LON_LOCATION1 = -(QL_ERR_MSD_NONE+11), /**< MSD recentVehLocationN1 longitude ERROR. */ |
| QL_ERR_MSD_VEH_LAT_LOCATION2 = -(QL_ERR_MSD_NONE+12), /**< MSD recentVehLocationN2 latitude ERROR. */ |
| QL_ERR_MSD_VEH_LON_LOCATION2 = -(QL_ERR_MSD_NONE+13), /**< MSD recentVehLocationN2 longitude ERROR. */ |
| QL_ERR_MSD_VEH_IDENTIFI_NUMBER = -(QL_ERR_MSD_NONE+14), /**< MSD vehIdentification Number ERROR. */ |
| QL_ERR_MSD_OPTINAL_DATA_GLONASS = -(QL_ERR_MSD_NONE+15), /**< MSD Optional Data For Era Glonass ERROR. */ |
| } QL_ERR_MSD_RESULT_E; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Enumeration used to specify the type of vehicle. |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef enum |
| { |
| MSD_VEHICLE_PASSENGER_M1=1, ///< Passenger vehicle (Class M1) |
| MSD_VEHICLE_BUS_M2, ///< Buses and coaches (Class M2) |
| MSD_VEHICLE_BUS_M3, ///< Buses and coaches (Class M3) |
| MSD_VEHICLE_COMMERCIAL_N1, ///< Light commercial vehicles (Class N1) |
| MSD_VEHICLE_HEAVY_N2, ///< Heavy duty vehicles (Class N2) |
| MSD_VEHICLE_HEAVY_N3, ///< Heavy duty vehicles (Class N3) |
| MSD_VEHICLE_MOTORCYCLE_L1E, ///< Motorcycles (Class L1e) |
| MSD_VEHICLE_MOTORCYCLE_L2E, ///< Motorcycles (Class L2e) |
| MSD_VEHICLE_MOTORCYCLE_L3E, ///< Motorcycles (Class L3e) |
| MSD_VEHICLE_MOTORCYCLE_L4E, ///< Motorcycles (Class L4e) |
| MSD_VEHICLE_MOTORCYCLE_L5E, ///< Motorcycles (Class L5e) |
| MSD_VEHICLE_MOTORCYCLE_L6E, ///< Motorcycles (Class L6e) |
| MSD_VEHICLE_MOTORCYCLE_L7E, ///< Motorcycles (Class L7e) |
| } MSD_VEHICLE_TYPE_E; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Enumeration used to specify the propulsion type. |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef enum |
| { |
| ECALL_MSD_PROPULSION_TYPE_GASOLINE=0x1, |
| ECALL_MSD_PROPULSION_TYPE_DIESEL=0x2, |
| ECALL_MSD_PROPULSION_TYPE_NATURALGAS=0x4, |
| ECALL_MSD_PROPULSION_TYPE_PROPANE=0x8, |
| ECALL_MSD_PROPULSION_TYPE_ELECTRIC=0x10, |
| ECALL_MSD_PROPULSION_TYPE_HYDROGEN=0x20, |
| ECALL_MSD_PROPULSION_TYPE_OTHER=0x40, |
| } ECALL_MSD_PROPULSION_TYPE_E; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Enumeration used to specify the type of coordinate system. |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef enum |
| { |
| MSD_COORDINATE_SYSTEM_TYPE_ABSENT, ///< Coordinate system type is absent |
| MSD_COORDINATE_SYSTEM_TYPE_WGS84, ///< Coordinate system type WGS-84 |
| MSD_COORDINATE_SYSTEM_TYPE_PZ90 ///< Coordinate system type PZ-90 |
| } ECALL_MSD_COORINATE_SYSTEM_TYPE_E; |
| |
| typedef enum |
| { |
| ECALL_SYSTEM_STD_PAN_EUROPEAN, //< PAN-European system. |
| ECALL_SYSTEM_STD_ERA_GLONASS //< ERA-GLONASS system. |
| } ECALL_SYSTEM_STD_E; |
| //-------------------------------------------------------------------------------------------------- |
| // Data structures. |
| //-------------------------------------------------------------------------------------------------- |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure describing the VIN (Vehicle Identification Number). |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct{ |
| char isowmi[4]; |
| char isovds[7]; |
| char isovisModelyear[2]; |
| char isovisSeqPlant[8]; |
| } msd_Vin_t; |
| |
| /* ControlType */ |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure describing the main control elements of the MSD. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct { |
| bool automaticActivation; |
| bool testCall; |
| bool positionCanBeTrusted; |
| MSD_VEHICLE_TYPE_E vehType; |
| } msd_Control_t; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure describing the vehicle propulsion storage type. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct { |
| bool gasolineTankPresent; |
| bool dieselTankPresent; |
| bool compressedNaturalGas; |
| bool liquidPropaneGas; |
| bool electricEnergyStorage; |
| bool hydrogenStorage; |
| bool otherStorage; |
| } msd_VehiclePropulsionStorageType_t; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure describing the last known vehicle location. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct { |
| int32_t latitude; |
| int32_t longitude; |
| } msd_VehicleLocation_t; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure describing the location of the vehicle some time before the generation of the data |
| * for the MSD message.. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct { |
| int32_t latitudeDelta; |
| int32_t longitudeDelta; |
| } msd_VehicleLocationDelta_t; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure to gather optional data. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct { |
| uint8_t oidlen; |
| uint8_t dataLen; |
| uint8_t* oid; |
| uint8_t* data; |
| } msd_optionalData_t; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure describing the MSD without the additional optional data. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct { |
| uint8_t messageIdentifier; |
| msd_Control_t control; |
| msd_Vin_t vehIdentificationNumber; |
| msd_VehiclePropulsionStorageType_t vehPropulsionStorageType; |
| uint32_t timestamp; |
| msd_VehicleLocation_t vehLocation; |
| uint8_t vehDirection; |
| /* Optional */ |
| bool recentVehLocationN1Pres; |
| msd_VehicleLocationDelta_t recentVehLocationN1; |
| /* Optional */ |
| bool recentVehLocationN2Pres; |
| msd_VehicleLocationDelta_t recentVehLocationN2; |
| /* Optional */ |
| bool numberOfPassengersPres; |
| uint8_t numberOfPassengers; |
| } msd_Structure_t; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure describing the MSD with the additional optional data. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct { |
| msd_Structure_t msdStruct; |
| /* Optional */ |
| bool optionalDataPres; |
| msd_optionalData_t optionalData; |
| } msd_Message_t; |
| |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure describing the MSD message. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| typedef struct { |
| uint8_t version; |
| msd_Message_t msdMsg; |
| } msd_t; |
| |
| |
| /* ERA GLONASS specific types for the OptionalData_t parts */ |
| //-------------------------------------------------------------------------------------------------- |
| /** |
| * Data structure to gather the ERA GLONASS specific data. |
| * |
| */ |
| //-------------------------------------------------------------------------------------------------- |
| |
| typedef struct { |
| /* |
| * ERAAdditionalData ::= SEQUENCE { |
| * crashSeverity INTEGER(0..2047) OPTIONAL, |
| * diagnosticResult DiagnosticResult OPTIONAL, |
| * crashInfo CrashInfo OPTIONAL, |
| * coordinateSystemType CoordinateSystemType DEFAULT wgs84, |
| * ... |
| * } |
| */ |
| uint8_t msdVersion; |
| |
| bool presentCrashSeverity; |
| uint32_t crashSeverity; /* INTEGER(0..2047) OPTIONAL */ |
| |
| bool presentDiagnosticResult; |
| struct |
| { |
| bool presentMicConnectionFailure; |
| bool micConnectionFailure; |
| |
| bool presentMicFailure; |
| bool micFailure; |
| |
| bool presentRightSpeakerFailure; |
| bool rightSpeakerFailure; |
| |
| bool presentLeftSpeakerFailure; |
| bool leftSpeakerFailure; |
| |
| bool presentSpeakersFailure; |
| bool speakersFailure; |
| |
| bool presentIgnitionLineFailure; |
| bool ignitionLineFailure; |
| |
| bool presentUimFailure; |
| bool uimFailure; |
| |
| bool presentStatusIndicatorFailure; |
| bool statusIndicatorFailure; |
| |
| bool presentBatteryFailure; |
| bool batteryFailure; |
| |
| bool presentBatteryVoltageLow; |
| bool batteryVoltageLow; |
| |
| bool presentCrashSensorFailure; |
| bool crashSensorFailure; |
| |
| bool presentFirmwareImageCorruption; |
| bool firmwareImageCorruption; |
| |
| bool presentCommModuleInterfaceFailure; |
| bool commModuleInterfaceFailure; |
| |
| bool presentGnssReceiverFailure; |
| bool gnssReceiverFailure; |
| |
| bool presentRaimProblem; |
| bool raimProblem; |
| |
| bool presentGnssAntennaFailure; |
| bool gnssAntennaFailure; |
| |
| bool presentCommModuleFailure; |
| bool commModuleFailure; |
| |
| bool presentEventsMemoryOverflow; |
| bool eventsMemoryOverflow; |
| |
| bool presentCrashProfileMemoryOverflow; |
| bool crashProfileMemoryOverflow; |
| |
| bool presentOtherCriticalFailures; |
| bool otherCriticalFailures; |
| |
| bool presentOtherNotCriticalFailures; |
| bool otherNotCriticalFailures; |
| } diagnosticResult; |
| |
| bool presentCrashInfo; |
| struct |
| { |
| bool presentCrashFront; |
| bool crashFront; |
| |
| bool presentCrashLeft; |
| bool crashLeft; |
| |
| bool presentCrashRight; |
| bool crashRight; |
| |
| bool presentCrashRear; |
| bool crashRear; |
| |
| bool presentCrashRollover; |
| bool crashRollover; |
| |
| bool presentCrashSide; |
| bool crashSide; |
| |
| bool presentCrashFrontOrSide; |
| bool crashFrontOrSide; |
| |
| bool presentCrashAnotherType; |
| bool crashAnotherType; |
| } crashType; |
| |
| bool presentCoordinateSystemTypeInfo; |
| ECALL_MSD_COORINATE_SYSTEM_TYPE_E coordinateSystemType; |
| } msd_EraGlonassData_t; |
| |
| typedef struct ecall ecall_t; |
| |
| void print_msd_hexstr(uint8_t *msd,uint32_t msd_len); |
| |
| QL_ERR_MSD_RESULT_E ql_msd_encode |
| ( |
| uint8_t *pBuiltMsd, //< built MSD |
| uint32_t *pBuiltMsdSize, //< Size of the built MSDvoid |
| ECALL_SYSTEM_STD_E systemStandard, |
| msd_EraGlonassData_t eraGlonassDataObj, |
| msd_t msdContent |
| ); |
| |
| bool IsVinValid |
| ( |
| msd_Vin_t vin |
| ); |
| |
| int32_t ConvertDdToDms |
| ( |
| int32_t ddVal |
| ); |
| |
| |
| |
| #endif // _ASN1_MSD_INCLUDE_GUARD_ |