This commit is contained in:
cfif 2025-06-02 14:32:56 +03:00
commit a99781335c
14 changed files with 3995 additions and 0 deletions

1800
CanMain.c Normal file

File diff suppressed because it is too large Load Diff

413
CanMain.h Normal file
View File

@ -0,0 +1,413 @@
//
// 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

1175
CanMainAdditional.c Normal file

File diff suppressed because it is too large Load Diff

224
CanMute.c Normal file
View File

@ -0,0 +1,224 @@
//
// Created by cfif on 15.10.2024.
//
#include <stdlib.h>
#include "CanMain.h"
#include "SystemDelayInterface.h"
#include "ext_telematica.h"
#include "string.h"
#include "Rtc.h"
#include "EgtsTimestamp.h"
#include "math.h"
#define LOG_SIGN "UDS_MUTE"
#define LOGGER &env->slog->logger
extern eDeviceTestingCode deviceTestingCodeCan;
void CanMainMute_Init(
tCanMainMute *env,
tSerialPortFrameIO *CanIO,
SystemMutexCmsis txAccessQueue,
tGsmWithGnss *gsm,
tLoggerToSerialPort *slog
) {
env->CanIO = CanIO;
env->txAccessQueue = txAccessQueue;
env->gsm = gsm;
env->slog = slog;
memset(env->GNSS_NMEA1, 0, sizeof(env->GNSS_NMEA1));
memset(env->GNSS_NMEA2, 0, sizeof(env->GNSS_NMEA2));
memset(env->GNSS_NMEA3, 0, sizeof(env->GNSS_NMEA3));
memset(env->GNSS_NMEA4, 0, sizeof(env->GNSS_NMEA4));
memset(env->GNSS_NMEA5, 0, sizeof(env->GNSS_NMEA5));
memset(env->GNSS_NMEA6, 0, sizeof(env->GNSS_NMEA6));
InitThreadBlock(env->T_can_MainMute, "CanMainMute", osPriorityNormal);
InitThreadBlock(env->T_can_MainNav, "CanMainNav", osPriorityNormal);
}
static double nmeaLocationToDeg(double dec) {
double _dec = dec;
int deg = (int) (_dec / 100);
int min = (int) (_dec) - (deg * 100);
double sec = (double) (_dec - min - 100 * deg) * 60.0;
return deg + min / 60.0 + sec / 3600.0;
}
void CanMainTaskNav(tCanMainMute *env) {
uint16_t sent = 0;
uint8_t countCycle = 0;
uint8_t lcCounter = 0;
for (;;) {
if (!EXT_ENV_TELE.store.device->factoryMode) {
if ((EXT_ENV_TELE.DataToCan != NULL) && (EXT_ENV_TELE.DataToCan->nav_data_ToCan == true)) {
deviceTestingCodeCan = DEVICE_TESTING_CODE_NOT_ACTIVE;
//начало-----------------------------------НАВИГАЦИЯ----------------------------------------------------
tGNSS_NMEA1 *GNSS_NMEA1 = (tGNSS_NMEA1 *) env->GNSS_NMEA1;
tGNSS_NMEA2 *GNSS_NMEA2 = (tGNSS_NMEA2 *) env->GNSS_NMEA2;
tGNSS_NMEA3 *GNSS_NMEA3 = (tGNSS_NMEA3 *) env->GNSS_NMEA3;
time_t timestamp = 0;
RtcGet(env->gsm->Rtc, &timestamp);
tNmeaRmc nmeaRmc;
Gnss_GetFullNavData(env->gsm, &nmeaRmc);
int32_t alt = GnssGgaGetAlt(env->gsm);
uint8_t countSats = GnssGgaGetSat(env->gsm);
GNSS_NMEA1->NTM = Egts_EpochTimestampToEgtsTime(timestamp);
double lat = (fabs(nmeaLocationToDeg(nmeaRmc.location.latitude)) / 90) * 0xFFFFFFFF;
GNSS_NMEA1->LAT = (uint32_t) lat;
double lon = (fabs(nmeaLocationToDeg(nmeaRmc.location.longitude)) / 90) * 0xFFFFFFFF;
GNSS_NMEA2->LONG = (uint32_t) lon;
GNSS_NMEA2->FLG.VLD = (nmeaRmc.status == 'A') ? 1 : 0;
GNSS_NMEA2->FLG.LAHS = (nmeaRmc.location.nsIndicator == 'S') ? 1 : 0;
GNSS_NMEA2->FLG.LOHS = (nmeaRmc.location.ewIndicator == 'W') ? 1 : 0;
GNSS_NMEA2->FLG.ALTH = 1;
GNSS_NMEA2->FLG.SATH = 1;
uint16_t speed = (uint16_t) (nmeaRmc.knotVelocity * 1.82 * 10);
GNSS_NMEA2->SPD.SPD = speed & 0b0011111111111111;
if (alt >= 0) {
GNSS_NMEA2->SPD.ALTS = 0;
} else {
GNSS_NMEA2->SPD.ALTS = 1;
}
uint16_t dir = (uint16_t) nmeaRmc.headingAngle;
GNSS_NMEA2->SPD.DIRH = dir >> 8;
GNSS_NMEA2->DIR = dir;
GNSS_NMEA3->ALT = abs(alt);
GNSS_NMEA3->SAT = countSats;
if (osMutexAcquire(env->txAccessQueue, 3000) == osOK) {
CanSerialPortFrameSetId(env->CanIO->env, 0x5A4);
sent = env->CanIO->transmit(env->CanIO->env, env->GNSS_NMEA1, sizeof(env->GNSS_NMEA1),
WAIT_FRAME_WRITE);
CanSerialPortFrameSetId(env->CanIO->env, 0x5A6);
sent = env->CanIO->transmit(env->CanIO->env, env->GNSS_NMEA2, sizeof(env->GNSS_NMEA2),
WAIT_FRAME_WRITE);
CanSerialPortFrameSetId(env->CanIO->env, 0x5A8);
sent = env->CanIO->transmit(env->CanIO->env, env->GNSS_NMEA3, sizeof(env->GNSS_NMEA3),
WAIT_FRAME_WRITE);
CanSerialPortFrameSetId(env->CanIO->env, 0x5AA);
sent = env->CanIO->transmit(env->CanIO->env, env->GNSS_NMEA4, sizeof(env->GNSS_NMEA4),
WAIT_FRAME_WRITE);
CanSerialPortFrameSetId(env->CanIO->env, 0x5AC);
sent = env->CanIO->transmit(env->CanIO->env, env->GNSS_NMEA5, sizeof(env->GNSS_NMEA5),
WAIT_FRAME_WRITE);
CanSerialPortFrameSetId(env->CanIO->env, 0x5AE);
sent = env->CanIO->transmit(env->CanIO->env, env->GNSS_NMEA6, sizeof(env->GNSS_NMEA6),
WAIT_FRAME_WRITE);
osMutexRelease(env->txAccessQueue);
} else {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка доступа CanMainTaskNav (1)")
}
//конец------------------------------------НАВИГАЦИЯ----------------------------------------------------
SystemDelayMs(50);
++countCycle;
}
}
}
}
void CanMainTaskMute(tCanMainMute *env) {
uint16_t sent = 0;
uint8_t countCycle = 0;
uint8_t lcCounter = 0;
for (;;) {
if (!EXT_ENV_TELE.store.device->factoryMode) {
// if( (EXT_ENV_TELE.DataToCan != NULL) && (EXT_ENV_TELE.DataToCan->gnss_general_ToCan == true) ) {
//начало-----------------------------------ТИШИНА-------------------------------------------------------
if (osMutexAcquire(env->txAccessQueue, 3000) == osOK) {
CanSerialPortFrameSetId(env->CanIO->env, 0x640);
if (lcCounter >= 15) {
lcCounter = 0;
} else {
++lcCounter;
}
EXT_ENV_TELE.GNSS_General->GNSS_LC = lcCounter;
tGNSS_General GNSS_General;
memcpy(&GNSS_General, EXT_ENV_TELE.GNSS_General, sizeof(tGNSS_General));
if (EXT_ENV_TELE.GNSS_General->GNSS_Call_Auto == CAN_GNSS_ROLLOVER_DETECT) {
GNSS_General.GNSS_Call_By_button = CAN_GNSS_CALL;
}
// if (EXT_ENV_TELE.GNSS_General->GNSS_Call_Test == CAN_GNSS_CALL_TEST_ACTIVE) {
// GNSS_General.GNSS_Call_By_button = CAN_GNSS_CALL;
// }
// GNSS_General.GNSS_Call_Test = 0;
GNSS_General.GNSS_Call_Auto = 0;
GNSS_General.Reserved1 = 0;
GNSS_General.Reserved2 = 0;
sent = env->CanIO->transmit(env->CanIO->env, (uint8_t *) &GNSS_General, 2,
WAIT_FRAME_WRITE);
osMutexRelease(env->txAccessQueue);
} else {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка доступа CanMainTaskMute (1)")
}
//конец-----------------------------------ТИШИНА-------------------------------------------------------
SystemDelayMs(100);
++countCycle;
// }
} else {
env->isPassedTestCan = false;
if (osMutexAcquire(env->txAccessQueue, 1000) == osOK) {
CanSerialPortFrameSetId(env->CanIO->env, 0x88);
sent = env->CanIO->transmit(env->CanIO->env, (uint8_t *) canTestData, 8,
WAIT_FRAME_WRITE);
osMutexRelease(env->txAccessQueue);
} else {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка доступа CanMainTaskMute (2)")
}
SystemDelayMs(100);
if (env->isPassedTestCan) {
deviceTestingCodeCan = DEVICE_TESTING_CODE_PASSED;
} else {
deviceTestingCodeCan = DEVICE_TESTING_CODE_ERROR;
}
}
}
}
void CanMainMute_Start(tCanMainMute *env) {
ThreadBlock_Start(env->T_can_MainMute, env, CanMainTaskMute);
ThreadBlock_Start(env->T_can_MainNav, env, CanMainTaskNav);
}

49
CanTestCallBack.c Normal file
View File

@ -0,0 +1,49 @@
//
// Created by cfif on 18.10.2024.
//
#include "CanMain.h"
#include "SystemDelayInterface.h"
#include "ext_telematica.h"
#include "string.h"
#define LOG_SIGN "UDS_TEST"
#define LOGGER &env->slog->logger
void CanMainTest_Init(
tCanMainTest *env,
tSerialPortFrameIO *CanIO,
tLoggerToSerialPort *slog
) {
env->CanIO = CanIO;
env->slog = slog;
InitThreadBlock(env->T_can_MainTest, "CanMainTest", osPriorityNormal);
}
void CanMainTaskTest(tCanMainTest *env) {
can_rx_message_type canFrame;
uint16_t sent;
for (;;) {
uint16_t recv = env->CanIO->receive0(env->CanIO->env, (uint8_t *) &canFrame, 1, 1000);
if (recv > 0) {
if (canFrame.standard_id == 0x88) {
if ((canFrame.dlc == 8) && memcmp(canFrame.data, canTestData, 8) == 0) {
CanSerialPortFrameSetId(env->CanIO->env, 0x88);
sent = env->CanIO->transmit(env->CanIO->env, (uint8_t *) canTestData, 8, WAIT_FRAME_WRITE);
}
}
}
}
}
void CanMainTest_Start(tCanMainTest *env) {
ThreadBlock_Start(env->T_can_MainTest, env, CanMainTaskTest);
}

View File

@ -0,0 +1,18 @@
//
// Created by cfif on 11.02.2025.
//
#ifndef SMART_COMPONENTS_TELEMATICA_V2_CLEARDIAGNOSTICINFORMATION_14_H
#define SMART_COMPONENTS_TELEMATICA_V2_CLEARDIAGNOSTICINFORMATION_14_H
#include "stdint.h"
// Для сброса ошибок DTC
typedef struct __attribute__ ((packed)) {
uint8_t ServiceId;
uint8_t groupOfDTCHighByte;
uint8_t groupOfDTCMiddleByte;
uint8_t groupOfDTCLowByte;
} tClearDiagnosticInformationRequest;
#endif //SMART_COMPONENTS_TELEMATICA_V2_CLEARDIAGNOSTICINFORMATION_14_H

View File

@ -0,0 +1,25 @@
//
// Created by cfif on 06.08.2024.
//
#ifndef SMART_COMPONENTS_UPDATE_DIAGNOSTICSESSIONCONTROL_10_H
#define SMART_COMPONENTS_UPDATE_DIAGNOSTICSESSIONCONTROL_10_H
#include "stdint.h"
// Для готовности загрузки модема
typedef struct __attribute__ ((packed)) {
uint8_t ServiceId;
uint8_t diagnosticSessionType;
uint8_t sessionParameterRecord[4];
} tDiagnosticSessionsType;
// Для запроса сессии
typedef struct __attribute__ ((packed)) {
uint8_t ServiceId;
uint8_t diagnosticSessionType;
} tDiagnosticSessionControlRequest;
#endif //SMART_COMPONENTS_UPDATE_DIAGNOSTICSESSIONCONTROL_10_H

104
ReadDTCInformation_19.c Normal file
View File

@ -0,0 +1,104 @@
//
// Created by cfif on 08.08.2024.
//
#include "ReadDTCInformation_19.h"
const tUDS_DTC_Error UDS_DTC_Error[] = {
// Board voltage error
// 16 - Circuit voltage below threshold (low voltage);
{0x90, 0x11, 0x16},
// 17 - Circuit voltage above threshold (high voltage);
{0x90, 0x11, 0x17},
// 13 - Circuit open.
{0x90, 0x11, 0x13},
// GSM/GPRS and UMTS module error
// UDS_TEST_AUDIO_FILE 46 -Audiofiles error (missing or invalide).
{0x90, 0x21, 0x46},
// UDS_TEST_GSM_AUDIO_CODEC 47 - Audiocodec error.
{0x90, 0x21, 0x47},
// UDS_TEST_MODEM_SOFT_REV 48 - Invalid software version of GSM module.
{0x90, 0x21, 0x48},
// 81 - Invalid serial data received (wrong frame format or data);
{0x90, 0x21, 0x81},
// UDS_TEST_GSM 87 - Missing message (no signals from module).
{0x90, 0x21, 0x87},
// UDS_TEST_CERT_REV 57 - Certificates error (missing or invalidate)
{0x90, 0x21, 0x57},
// GPS/GLONASS module error
// 81 - Invalid serial data received (wrong frame format or data);
{0x90, 0x31, 0x81},
// 87 - Missing message (no signals from module).
{0x90, 0x31, 0x87},
// Antenna error
// UDS_TEST_GNSS_ANT 01 - Antenna not connected
{0x90, 0x32, 0x01},
// Internal Battery error
// UDS_TEST_BAT_VOLTAGE 91 - Parametric (battery charge too low);
{0x90, 0x12, 0x91},
// UDS_TEST_BAT_CONNECT 92 - Performance or incorrect operation (battery is old);
{0x90, 0x12, 0x92},
// UDS_TEST_BAT_CHARGE 97 - Component obstructed or blocked (battery unchargeable)
{0x90, 0x12, 0x97},
// 98 - Component over temperature (battery temperature too high);
{0x90, 0x12, 0x98},
// Voltage Supplier error
// 01 - General Electrical Failure (supplier is defective).
{0x90, 0x13, 0x01},
// Microphone error
// 09 - Component Failures.
{0x90, 0x41, 0x09},
// UDS_TEST_MICROPHONE_CONNECT 13 - Break
{0x90, 0x41, 0x13},
// Load Speaker error
// 09 - Component Failures.
{0x90, 0x42, 0x09},
// UDS_TEST_SPEAKER_CONNECT 13 - Break
{0x90, 0x42, 0x13},
// Vehicle Identification Number error
// UDS_TEST_VIN 02 - General Signal Failures.
{0x90, 0x62, 0x02},
// Error activation
// UDS_TEST_EOL 04 - EOL error
{0x90, 0x63, 0x04},
// SOS button error
// 23 - Signal stuck low (SOS button is stuck)
{0x90, 0x51, 0x23},
// 13 - Break
{0x90, 0x51, 0x13},
// Accelerometer error
// UDS_TEST_ACCEL 02 - no signal from module
{0x90, 0x53, 0x02},
// 09 - initialization error
{0x90, 0x53, 0x09},
// UDS_TEST_ACCEL_CALIB 15 - calibration error
{0x90, 0x53, 0x15},
// SIM-chip error
// UDS_TEST_SIM_ERA 4A - No response from SIM chip
{0x90, 0x71, 0x4A},
// UDS_TEST_SIM_COMERS Commercial SIM-chip error
// 4A - No response from commercial SIM chip
{0x90, 0x72, 0x4A},
// Flash error
// 01 - Incorrect CRC for flash application
{0x90, 0x16, 0x01},
// Amplifier error
// UDS_TEST_AMPLIFIER 05 - Error amplifier.
{0x90, 0x22, 0x05}
};

47
ReadDTCInformation_19.h Normal file
View File

@ -0,0 +1,47 @@
//
// Created by cfif on 07.08.2024.
//
#ifndef SMART_COMPONENTS_TELEMATICA_READDTCINFORMATION_19_H
#define SMART_COMPONENTS_TELEMATICA_READDTCINFORMATION_19_H
#include "stdint.h"
typedef enum {
UDS_TEST_AUDIO_FILE = 3,
UDS_TEST_GSM_AUDIO_CODEC = 4,
UDS_TEST_MODEM_SOFT_REV = 5,
UDS_TEST_GSM = 7,
UDS_TEST_CERT_REV = 8,
UDS_TEST_GNSS_ANT = 11,
UDS_TEST_BAT_VOLTAGE = 12,
UDS_TEST_BAT_CONNECT = 13,
UDS_TEST_BAT_CHARGE = 14,
UDS_TEST_MICROPHONE_CONNECT = 18,
UDS_TEST_SPEAKER_CONNECT = 20,
UDS_TEST_VIN = 21,
UDS_TEST_EOL = 22,
UDS_TEST_ACCEL = 25,
UDS_TEST_ACCEL_CALIB = 27,
UDS_TEST_SIM_ERA = 28,
UDS_TEST_SIM_COMERS = 29,
UDS_TEST_AMPLIFIER = 31
} eUdsErrorDTC;
typedef struct __attribute__ ((packed)) {
uint8_t DTCHighByte;
uint8_t DTCMiddleByte;
uint8_t DTCLowByte;
} tUDS_DTC_Error;
// Для запроса кодов ошибок
typedef struct __attribute__ ((packed)) {
uint8_t ServiceId;
uint8_t reportDTCByStatusMask;
uint8_t DTCStatusMask;
} tReadDTCInformationRequest;
extern const tUDS_DTC_Error UDS_DTC_Error[];
#endif //SMART_COMPONENTS_TELEMATICA_READDTCINFORMATION_19_H

View File

@ -0,0 +1,17 @@
//
// Created by cfif on 31.01.2025.
//
#ifndef SMART_COMPONENTS_TELEMATICA_V2_READDATABYIDENTIFIER_22I_H
#define SMART_COMPONENTS_TELEMATICA_V2_READDATABYIDENTIFIER_22I_H
#include "stdint.h"
// Для запроса чтения идентификаторов
typedef struct __attribute__ ((packed)) {
uint8_t ServiceId;
uint8_t dataIdentifierByte1;
uint8_t dataIdentifierByte2;
} tReadDataByIdentifierRequest;
#endif //SMART_COMPONENTS_TELEMATICA_V2_READDATABYIDENTIFIER_22I_H

71
SerialPortCanComInt.c Normal file
View File

@ -0,0 +1,71 @@
//
// Created by cfif on 12.11.2024.
//
#include "SerialPortCanComInt.h"
#include "SystemDelayInterface.h"
#include "CanSerialPortFrame.h"
void vSerialPortCanComInit(
tSerialPortCanComInt *env,
tSerialPortFrameIO *CanIO,
uint32_t rxBufferLength
) {
env->CanIO = CanIO;
env->queue = osMessageQueueNew(rxBufferLength, 1, NULL);
}
static uint16_t vSerialPortReceiveQueue(tSerialPortCanComInt *env, uint8_t *data, uint16_t size, uint32_t timeout,
osMessageQueueId_t queueId) {
uint16_t received = 0;
if (timeout) {
uint32_t endMs = SystemGetMs() + timeout;
uint32_t leftMs;
while (size && ((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) {
leftMs = endMs - SystemGetMs();
if (osMessageQueueGet(queueId, data, NULL, leftMs) == osOK) {
--size;
++received;
++data;
}
}
} else {
while (size) {
if (osMessageQueueGet(queueId, data, NULL, 0) == osOK) {
--size;
++received;
++data;
} else {
return received;
}
}
}
return received;
}
static uint16_t vSerialPortReceive(tSerialPortCanComInt *env, uint8_t *data, uint16_t size, uint32_t timeout) {
return vSerialPortReceiveQueue(env, data, size, timeout, env->queue);
}
static uint16_t vSerialPortTransmit(tSerialPortCanComInt *env, uint8_t *data, uint16_t size, uint32_t timeout) {
CanSerialPortFrameSetId1(env->CanIO->env, 0x77);
uint16_t sent = env->CanIO->transmit1(env->CanIO->env, data, size, timeout);
return sent;
}
tSerialPortIO vSerialPortCanComIntGetIo(tSerialPortCanComInt *env) {
tSerialPortIO io = {
.env = env,
.receive = (SerialPortIOTransaction) vSerialPortReceive,
.transmit = (SerialPortIOTransaction) vSerialPortTransmit
};
return io;
}

25
SerialPortCanComInt.h Normal file
View File

@ -0,0 +1,25 @@
//
// Created by cfif on 12.11.2024.
//
#ifndef SMART_COMPONENTS_TELEMATICA_V2_SERIALPORTCANCOMINT_H
#define SMART_COMPONENTS_TELEMATICA_V2_SERIALPORTCANCOMINT_H
#include "cmsis_os2.h"
#include "SerialPortIO.h"
#include "SerialPortFrameIO.h"
typedef struct {
tSerialPortFrameIO *CanIO;
osMessageQueueId_t queue;
} tSerialPortCanComInt;
void vSerialPortCanComInit(
tSerialPortCanComInt *env,
tSerialPortFrameIO *CanIO,
uint32_t rxBufferLength
);
tSerialPortIO vSerialPortCanComIntGetIo(tSerialPortCanComInt *env);
#endif //SMART_COMPONENTS_TELEMATICA_V2_SERIALPORTCANCOMINT_H

17
TesterPresent_3e.h Normal file
View File

@ -0,0 +1,17 @@
//
// Created by cfif on 06.08.2024.
//
#ifndef SMART_COMPONENTS_UPDATE_TESTERPRESENT_3E_H
#define SMART_COMPONENTS_UPDATE_TESTERPRESENT_3E_H
#include "stdint.h"
// Для готовности загрузки модема
typedef struct __attribute__ ((packed)) {
uint8_t ServiceId;
uint8_t zeroSubFunction;
} tTesterPresent;
#endif //SMART_COMPONENTS_UPDATE_TESTERPRESENT_3E_H

10
modular.json Normal file
View File

@ -0,0 +1,10 @@
{
"cmake": {
"inc_dirs": [
"./"
],
"srcs": [
"./**.c"
]
}
}