414 lines
11 KiB
C
414 lines
11 KiB
C
//
|
|
// Created by cfif on 05.08.2024.
|
|
//
|
|
|
|
#ifndef SMART_COMPONENTS_UPDATE_CANMAIN_H
|
|
#define SMART_COMPONENTS_UPDATE_CANMAIN_H
|
|
|
|
#include "CanSerialPortFrame.h"
|
|
#include "CmsisRtosThreadUtils.h"
|
|
#include "CanSerialPortFrameTP.h"
|
|
#include "DeviceStorage.h"
|
|
#include "DeviceTestsTable.h"
|
|
#include "ReadDTCInformation_19.h"
|
|
#include "RoutineControl_31.h"
|
|
#include "EgtsTelesataTypes.h"
|
|
#include "SystemMutexCmsis.h"
|
|
#include "SerialPortCanComInt.h"
|
|
#include "GsmWithGnss.h"
|
|
#include "DataStorage.h"
|
|
|
|
extern const uint8_t canTestData[8];
|
|
|
|
|
|
//#define CAN_ADR_REQUEST 0x7ca
|
|
//#define CAN_ADR_RESPONSE 0x7da
|
|
|
|
#define CAN_US_QUEUE_SIZE 3
|
|
|
|
typedef enum {
|
|
UDS_DiagnosticSessionControl = 0x10,
|
|
UDS_ReadDTCInformation = 0x19,
|
|
UDS_ClearDiagnosticInformation = 0x14,
|
|
UDS_TesterPresent = 0x3E,
|
|
UDS_ReadDataByIdentifier = 0x22,
|
|
UDS_WriteDataByIdentifier = 0x2E,
|
|
UDS_RoutineControl = 0x31,
|
|
UDS_ECUResetService = 0x11,
|
|
UDS_SecurityAccess = 0x27
|
|
} eUdsServices;
|
|
|
|
typedef enum {
|
|
UDS_InputStatesRecord = 0x0001,
|
|
UDS_outputStatesRecord = 0x0002,
|
|
UDS_boardVoltage = 0x0003,
|
|
UDS_reserveBatteryCharge = 0x0004,
|
|
UDS_reserveBatteryTemperature = 0x0005,
|
|
UDS_SystemState = 0x0006,
|
|
UDS_vehicleCoordinates = 0x0007,
|
|
UDS_vehicleCoordinatesReliability = 0x0008,
|
|
UDS_MDS_FormatVersion = 0x0009,
|
|
UDS_vehicleFuelType = 0x000A,
|
|
UDS_timeStamp = 0x000B,
|
|
UDS_passengersNumber = 0x000C,
|
|
UDS_TCM_working_mode = 0x000D,
|
|
UDS_TCM_activation_source = 0x000E,
|
|
UDS_TCM_time_calculation = 0x000F,
|
|
UDS_ECALLManualCanCancel = 0x0010,
|
|
UDS_GLONASS_and_GLONASS_GPS_groups = 0x0011,
|
|
UDS_GsmRegistrationState = 0x0012,
|
|
UDS_GsmInnerError = 0x0013,
|
|
UDS_VehicleCoordinatesReliabilityMem = 0x0014,
|
|
UDS_GsmRegistartionStateMem = 0x0015,
|
|
UDS_GsmRegistrationError = 0x0016, // !
|
|
UDS_EcallOn = 0x0017,
|
|
UDS_CrashSignalExternal = 0x0018,
|
|
UDS_TestModeEndDistance = 0x0019,
|
|
UDS_GnssPowerOffTime = 0x001A,
|
|
UDS_AutomaticActivationProhibition = 0x001B,
|
|
UDS_VehicleType = 0x001C,
|
|
UDS_SimIdentifier = 0x001D,
|
|
UDS_CommSimIdentifier = 0x001E,
|
|
UDS_CallAutoAnswerTime = 0x0301,
|
|
UDS_ECALLTestNumber = 0x0302,
|
|
UDS_ECALLToTest = 0x0303,
|
|
UDS_NadDeregistrationTimer = 0x0304,
|
|
UDS_NadRegistrationAtStartup = 0x0305,
|
|
UDS_SMSCenterNumber = 0x0306,
|
|
UDS_SMSFallbackNumber = 0x0307,
|
|
UDS_TestRegistrationPeriod = 0x030E,
|
|
UDS_EcallManualDialAttempts = 0x030F,
|
|
UDS_IntMemTransmitInterval = 0x0310,
|
|
UDS_IntMemTransmitAttempts = 0x0311,
|
|
UDS_GSMSoftwareVersionNumber = 0x0312, // !
|
|
UDS_SmsFallbackTestNumber = 0x0316,
|
|
UDS_EcallAutoDialAttempts = 0x0319,
|
|
UDS_EcallDialDuration = 0x031A,
|
|
UDS_PostTestRegistrationTime = 0x031B,
|
|
UDS_SimProfileAmount = 0x031C,
|
|
UDS_SimProfile = 0x031D,
|
|
UDS_Apn = 0x031E,
|
|
UDS_AudioProfile = 0x0323,
|
|
UDS_AccelerometerRawData = 0x0401,
|
|
UDS_RolloverAngle = 0x0402,
|
|
UDS_RolloverTime = 0x0403,
|
|
UDS_EcallNoAutomaticTriggering = 0x0407,
|
|
UDS_MiddletState = 0x0408,
|
|
UDS_SW_Version = 0x0409,
|
|
UDS_Vehicle_SW_Version = 0x040A,
|
|
UDS_Midlet_SW_Version = 0x040B,
|
|
UDS_Boot_SW_Version = 0x040D,
|
|
UDS_SertState = 0x040E,
|
|
UDS_DirectionAngle = 0x040F,
|
|
UDS_IMEI = 0x0411,
|
|
UDS_ApplicationCheckSum = 0x0412,
|
|
UDS_Audio_HW_Settings = 0x0420,
|
|
UDS_ECALL_EmergencyCallCounter = 0x0422,
|
|
UDS_Avaialble_Networks_List = 0x0430,
|
|
UDS_SavedMSDAmount = 0x01FF,
|
|
UDS_SentMSDAmount = 0x02FF,
|
|
UDS_vehicleManufacturerSparePartNumber = 0xF187,
|
|
UDS_ConfigurationFileReferenceLink = 0xF188,
|
|
UDS_systemSupplierIdentifier = 0xF18A,
|
|
UDS_ECUSerialNumber = 0xF18C,
|
|
UDS_vehicleIdentificationNumber = 0xF190,
|
|
UDS_vehicleManufacturerECUHardwareNumber = 0xF191,
|
|
UDS_systemSupplierECUSoftwareNumber = 0xF194,
|
|
UDS_systemSupplierECUSoftwareVersionNumber = 0xF195,
|
|
UDS_VDIAG = 0xF1A0,
|
|
UDS_AccelCalibrationX = 0x0404,
|
|
UDS_AccelCalibrationY = 0x0405,
|
|
UDS_AccelCalibrationZ = 0x0406,
|
|
UDS_TelematicsSoftwareVersion = 0x0600,
|
|
UDS_ServerAddress = 0x0601,
|
|
UDS_ServerSslEnable = 0x0602,
|
|
UDS_AltServerAddress = 0x0603,
|
|
UDS_TelematicsEnabledDisabled = 0x604,
|
|
UDS_Asi15 = 0x605,
|
|
UDS_LastEventDevice = 0x606,
|
|
UDS_SetDeviceFactoryMode = 0x607,
|
|
UDS_TelematicsEnabledCanGnss = 0x608,
|
|
UDS_TelematicsEnabledCanNav = 0x609,
|
|
|
|
UDS_TASK_INDICATION_START_STOP_CAN_UDS = 0x700,
|
|
UDS_GPIO_ECALL_OUT_CAN_UDS = 0x701,
|
|
UDS_GPIO_GARAGE_CAN_UDS = 0x702,
|
|
UDS_GPIO_MUTE_P_CAN_UDS = 0x703,
|
|
UDS_GPIO_MUTE_N_CAN_UDS = 0x704,
|
|
UDS_GPIO_LED_RED_CAN_UDS = 0x705,
|
|
UDS_GPIO_LED_GREEN_CAN_UDS = 0x706,
|
|
|
|
UDS_AUDIO_PLAY_TEST_CAN_UDS = 0x710,
|
|
|
|
} eUdsReadDataByIdentifier;
|
|
|
|
typedef struct {
|
|
int16_t x;
|
|
int16_t y;
|
|
int16_t z;
|
|
uint16_t angle;
|
|
} tRawAccel;
|
|
|
|
typedef struct {
|
|
tCanSerialPortFrameTp canSerialPortFrameTp;
|
|
tCanTP_Ext_data canTP_Ext_data;
|
|
osMessageQueueId_t queueMain;
|
|
osMessageQueueId_t queueAdditional;
|
|
SystemMutexCmsis txAccessQueue;
|
|
tEgtsTeledata *egtsTeledata;
|
|
|
|
tDeviceTeledataStorageData *deviceTeledataStorageData;
|
|
|
|
uint8_t canUDS_DataSendingBuf[256];
|
|
|
|
tSerialPortFrameIO *CanIO;
|
|
tLoggerToSerialPort *slog;
|
|
tDeviceTestsTable *testsTable;
|
|
tRawAccel *rawAccel;
|
|
|
|
uint8_t filterIdCount;
|
|
uint32_t filterReqId[16];
|
|
uint32_t filterRespId[16];
|
|
uint8_t filterDirReq[16];
|
|
|
|
// Запрос типа функции на устройстве
|
|
eUdsRoutineModes udsRoutineModes;
|
|
// Запрос состояние функции на устройстве
|
|
eUdsRoutineControlType udsRoutineControlType;
|
|
|
|
uint32_t timeID;
|
|
uint32_t time380_1;
|
|
uint32_t time380_2;
|
|
uint32_t time3E8_1;
|
|
uint32_t time3E8_2;
|
|
uint32_t timeCan;
|
|
|
|
uint8_t RND;
|
|
bool invalidKey;
|
|
uint8_t invalidKeyAttempts;
|
|
uint32_t invalidKeyIsDelay;
|
|
|
|
uint32_t isTimeTESTER_REQUEST;
|
|
|
|
tStaticThreadBlock(1024) T_can_Main;
|
|
} tCanMain;
|
|
|
|
|
|
typedef struct {
|
|
SystemMutexCmsis txAccessQueue;
|
|
tSerialPortFrameIO *CanIO;
|
|
tLoggerToSerialPort *slog;
|
|
|
|
tGsmWithGnss *gsm;
|
|
|
|
bool isPassedTestCan;
|
|
|
|
uint8_t GNSS_NMEA1[8];
|
|
uint8_t GNSS_NMEA2[8];
|
|
uint8_t GNSS_NMEA3[8];
|
|
uint8_t GNSS_NMEA4[8];
|
|
uint8_t GNSS_NMEA5[8];
|
|
uint8_t GNSS_NMEA6[8];
|
|
|
|
tStaticThreadBlock(512) T_can_MainMute;
|
|
tStaticThreadBlock(512) T_can_MainNav;
|
|
} tCanMainMute;
|
|
|
|
#define NUM_ACC_COUNT_MAX (5)
|
|
|
|
typedef struct {
|
|
tCanSerialPortFrameTp canSerialPortFrameTp;
|
|
tCanTP_data canTP_data;
|
|
// osMessageQueueId_t queue;
|
|
SystemMutexCmsis txAccessQueue;
|
|
tEgtsTeledata *egtsTeledata;
|
|
|
|
tDeviceTeledataStorageData *deviceTeledataStorageData;
|
|
|
|
tSerialPortFrameIO *CanIO;
|
|
tLoggerToSerialPort *slog;
|
|
tDeviceTestsTable *testsTable;
|
|
volatile tRawAccel *rawAccel;
|
|
|
|
uint8_t filterIdCount;
|
|
uint32_t filterReqId[16];
|
|
uint32_t filterRespId[16];
|
|
uint8_t filterDirReq[16];
|
|
|
|
// Запрос типа функции на устройстве
|
|
eUdsRoutineModes udsRoutineModes;
|
|
// Запрос состояние функции на устройстве
|
|
eUdsRoutineControlType udsRoutineControlType;
|
|
|
|
uint32_t EngineSpeed;
|
|
|
|
uint32_t timeID;
|
|
uint32_t time380_1;
|
|
uint32_t time380_2;
|
|
uint32_t time3E8_1;
|
|
uint32_t time3E8_2;
|
|
uint32_t timeCan;
|
|
|
|
uint8_t RND;
|
|
bool invalidKey;
|
|
uint8_t invalidKeyAttempts;
|
|
uint32_t invalidKeyIsDelay;
|
|
|
|
tCanMainMute *canMainMute;
|
|
|
|
tCanMain *canMain;
|
|
|
|
uint32_t timeAbsSpeedOnSecond;
|
|
uint32_t timeAbsSpeed;
|
|
uint32_t Counter_SENSORS_AN_TripMileage_MM;
|
|
uint32_t Counter_SENSORS_AN_TripMileage_MICRO_L;
|
|
|
|
struct {
|
|
float acc_last[NUM_ACC_COUNT_MAX];
|
|
uint8_t index;
|
|
float old_speed;
|
|
bool data_erase;
|
|
} calc_scoring;
|
|
|
|
struct {
|
|
uint32_t skip_fuel_frames;
|
|
uint32_t pre_filtered_fuel;
|
|
long long int mem_fuel_diff;
|
|
bool ign_on;
|
|
} calc_fuel_lvl;
|
|
|
|
uint32_t fuel_lvlFiltered;
|
|
uint16_t ABS_VehicleSpeed;
|
|
|
|
|
|
struct {
|
|
uint32_t acc_calc_time;
|
|
uint32_t gnss_course_speed;
|
|
uint32_t reference_speed;
|
|
uint32_t diff_speed_up;
|
|
uint32_t diff_speed_down;
|
|
} gnss_config;
|
|
|
|
struct {
|
|
uint32_t trip_braking;
|
|
uint32_t trip_acceleration;
|
|
} state_get;
|
|
|
|
struct {
|
|
uint32_t total_acceleration;
|
|
uint32_t acceleration;
|
|
uint32_t total_braking;
|
|
uint32_t braking;
|
|
} bc_get;
|
|
|
|
|
|
uint32_t isTimeSENSORS_DIG_BodyCanBusStatus;
|
|
|
|
tSerialPortCanComInt *serialPortCanComInt;
|
|
|
|
tEgtsEbuState *ebuState;
|
|
SystemMutexCmsis accessEbu;
|
|
void *envEgtsProcessing;
|
|
volatile tEgtsEbuUdsReady egtsEbuUdsReady;
|
|
|
|
bool *isEnableTelematicaSendPoints;
|
|
|
|
tStaticThreadBlock(1024) T_can_MainAdditional;
|
|
|
|
} tCanMainAdditional;
|
|
|
|
typedef struct {
|
|
tSerialPortFrameIO *CanIO;
|
|
tLoggerToSerialPort *slog;
|
|
tStaticThreadBlock(512) T_can_MainTest;
|
|
} tCanMainTest;
|
|
|
|
void CanMain_Init(
|
|
tCanMain *env,
|
|
tDeviceTeledataStorageData *deviceTeledataStorageData,
|
|
tSerialPortFrameIO *CanIO,
|
|
SystemMutexCmsis txAccessQueue,
|
|
tDeviceTestsTable *testsTable,
|
|
tLoggerToSerialPort *slog,
|
|
volatile tRawAccel *rawAccel,
|
|
tEgtsTeledata *egtsTeledata
|
|
);
|
|
|
|
void CanMain_Start(tCanMain *env);
|
|
|
|
void CanMainAdditional_Init(
|
|
tCanMainAdditional *env,
|
|
tSerialPortFrameIO *CanIO,
|
|
tSerialPortCanComInt *serialPortCanComInt,
|
|
tCanMainMute *canMainMute,
|
|
SystemMutexCmsis txAccessQueue,
|
|
tDeviceTestsTable *testsTable,
|
|
tLoggerToSerialPort *slog,
|
|
volatile tRawAccel *rawAccel,
|
|
tEgtsTeledata *egtsTeledata,
|
|
tEgtsEbuState *ebuState,
|
|
SystemMutexCmsis accessEbu,
|
|
tCanMain *canMain,
|
|
void *envEgtsProcessing,
|
|
bool *isEnableTelematicaSendPoints
|
|
);
|
|
|
|
void CanMainAdditional_Start(tCanMainAdditional *env);
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint8_t VLD: 1;
|
|
uint8_t LAHS: 1;
|
|
uint8_t LOHS: 1;
|
|
uint8_t ALTH: 1;
|
|
uint8_t SATH: 1;
|
|
uint8_t RESERVED_1: 1;
|
|
uint8_t RESERVED_2: 1;
|
|
uint8_t RESERVED_3: 1;
|
|
} tFLG_GNSS_NMEA2;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint16_t SPD: 14;
|
|
uint8_t ALTS: 1;
|
|
uint8_t DIRH: 1;
|
|
} tSPD_GNSS_NMEA2;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint32_t NTM;
|
|
uint32_t LAT;
|
|
} tGNSS_NMEA1;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint32_t LONG;
|
|
tFLG_GNSS_NMEA2 FLG;
|
|
tSPD_GNSS_NMEA2 SPD;
|
|
uint8_t DIR;
|
|
} tGNSS_NMEA2;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint16_t ALT;
|
|
uint8_t SAT;
|
|
uint8_t RESERVED[5];
|
|
} tGNSS_NMEA3;
|
|
|
|
void CanMainMute_Init(
|
|
tCanMainMute *env,
|
|
tSerialPortFrameIO *CanIO,
|
|
SystemMutexCmsis txAccessQueue,
|
|
tGsmWithGnss *gsm,
|
|
tLoggerToSerialPort *slog
|
|
);
|
|
|
|
void CanMainMute_Start(tCanMainMute *env);
|
|
|
|
void CanMainTest_Init(
|
|
tCanMainTest *env,
|
|
tSerialPortFrameIO *CanIO,
|
|
|
|
tLoggerToSerialPort *slog
|
|
);
|
|
|
|
void CanMainTest_Start(tCanMainTest *env);
|
|
|
|
|
|
#endif //SMART_COMPONENTS_UPDATE_CANMAIN_H
|