468 lines
13 KiB
C
468 lines
13 KiB
C
//
|
|
// Created by cfif on 21.05.23.
|
|
//
|
|
|
|
#ifndef SMART_COMPONENTS_EGTSPROCESSING_H
|
|
#define SMART_COMPONENTS_EGTSPROCESSING_H
|
|
|
|
#include <RtcIO.h>
|
|
#include "SocketInterface.h"
|
|
#include "stdint.h"
|
|
#include "stddef.h"
|
|
#include "stdbool.h"
|
|
#include "CmsisRtosThreadUtils.h"
|
|
#include "egtsWorker.h"
|
|
#include "AtCmdBase.h"
|
|
#include "GsmWithGnss.h"
|
|
#include "LoggerToSerialPort.h"
|
|
#include "DeviceStorage.h"
|
|
#include "Nmea0183Parser.h"
|
|
#include "PointEvent.h"
|
|
#include "EraGlonassUveos_Dumper.h"
|
|
#include "EgtsTelesataTypes.h"
|
|
#include "GpioPinInterface.h"
|
|
|
|
|
|
#define AURUS_CHECK_CONNECT 15000
|
|
#define AURUS_CHECK_NAV 5000
|
|
#define AURUS_CHECK_NETWORK_STATUS 30000
|
|
|
|
//начало ---------------------------------ЭБУ-------------------------------------------------------------------------
|
|
//начало ---------------------------------ЭБУ-------------------------------------------------------------------------
|
|
//начало ---------------------------------ЭБУ-------------------------------------------------------------------------
|
|
|
|
#define EBU_STATE_UPDATE 0
|
|
#define EBU_STATE_INIT 0xFFFFFFFF
|
|
|
|
#define EBU_COUNT_ITEMS 38
|
|
#define EBU_COUNT_TEST_ITEMS 20
|
|
|
|
typedef enum {
|
|
EBU_SDM = 0,
|
|
EBU_CGW = 1,
|
|
// Info-CAN
|
|
EBU_ERAG = 2,
|
|
EBU_SVU = 3,
|
|
EBU_IC = 4,
|
|
EBU_PACU = 5,
|
|
EBU_HUD = 6,
|
|
// Body-CAN
|
|
EBU_PTG = 7,
|
|
EBU_TMDTM = 8,
|
|
EBU_DMS = 9,
|
|
EBU_DMFL = 10,
|
|
EBU_DMRL = 11,
|
|
EBU_SMFL = 12,
|
|
EBU_SMRL = 13,
|
|
EBU_VAU = 14,
|
|
EBU_BCM = 15,
|
|
EBU_APU = 16,
|
|
EBU_CCU = 17,
|
|
EBU_DMFR = 18,
|
|
EBU_DMRR = 19,
|
|
EBU_SMFR = 20,
|
|
EBU_SMRR = 21,
|
|
// DA-CAN
|
|
EBU_CDA = 22,
|
|
EBU_FCU = 23,
|
|
//VMS-CAN
|
|
EBU_ACU = 24,
|
|
EBU_EPB = 25,
|
|
EBU_ESP = 26,
|
|
EBU_SCU = 27,
|
|
EBU_OCUFL = 28,
|
|
EBU_OCURL = 29,
|
|
EBU_OCUFR = 30,
|
|
EBU_OCURR = 31,
|
|
//PT-CAN
|
|
EBU_ATC = 32,
|
|
EBU_TCU = 33,
|
|
EBU_EMS = 34,
|
|
EBU_INC = 35,
|
|
EBU_DCDC_INC = 36,
|
|
EBU_BMS = 37
|
|
} eEgtsEbu;
|
|
|
|
typedef enum {
|
|
TS_STATUS_DEEP_SLEEP = 0,
|
|
TS_STATUS_SLEEP = 1,
|
|
TS_STATUS_STANDBY = 2,
|
|
TS_STATUS_IGNITION = 3,
|
|
TS_STATUS_DRIVE = 4,
|
|
TS_STATUS_REMOTE_START = 5,
|
|
TS_STATUS_SERVICE_MODE = 6,
|
|
TS_STATUS_PREHEATING = 8,
|
|
TS_STATUS_COMFORT = 9,
|
|
TS_STATUS_MULTIMEDIA = 10,
|
|
TS_STATUS_UNKNOWN = 15
|
|
} eEgtsTsStatus;
|
|
|
|
typedef struct {
|
|
eEgtsEbu ebu;
|
|
const char *ebuName;
|
|
} tEgtsEbuName;
|
|
|
|
typedef enum {
|
|
CERTS_STATUS_LOAD = 0,
|
|
CERTS_STATUS_UNLOAD = 1,
|
|
CERTS_STATUS_ERROR = 2
|
|
} eEgtsCertsStatus;
|
|
|
|
typedef enum {
|
|
TEST_FIRMWARE = 0,
|
|
TEST_IGNITION = 1,
|
|
TEST_BAT_CONNECT = 2,
|
|
TEST_BAT_CHARGE = 3,
|
|
TEST_BAT_VOLTAGE = 4,
|
|
TEST_GNSS_ANT = 5,
|
|
TEST_SPEAKER_CONNECT = 6,
|
|
TEST_BIP_CONNECT = 7,
|
|
TEST_ACCEL = 8,
|
|
TEST_GSM = 9,
|
|
TEST_AUDIO_CODEC = 10,
|
|
TEST_VIN = 11,
|
|
TEST_ACCEL_CALIB = 12,
|
|
TEST_EOL = 13,
|
|
TEST_TELE = 14,
|
|
TEST_MODEM_SOFT_REV = 15,
|
|
TEST_CERT_REV = 16,
|
|
TEST_AUDIO_FILE = 17,
|
|
TEST_AMPLIFIER = 18,
|
|
TEST_SIM_ERA = 19,
|
|
TEST_SIM_COMERS = 20,
|
|
|
|
} eEgtsTestEbu;
|
|
|
|
|
|
typedef struct {
|
|
eEgtsTestEbu ebu;
|
|
const char *ebuTestName;
|
|
} tEgtsEbuTestName;
|
|
|
|
typedef struct {
|
|
eEgtsEbu ebu;
|
|
uint32_t timestamp;
|
|
} tEgtsEbuItemState;
|
|
|
|
#define VERSION_EBU 3
|
|
|
|
typedef struct {
|
|
uint32_t version;
|
|
tEgtsEbuItemState ebuItemState[EBU_COUNT_ITEMS];
|
|
uint16_t count;
|
|
uint32_t crc;
|
|
} tEgtsEbuState;
|
|
|
|
//начало ---------------------------------ЭБУ-------------------------------------------------------------------------
|
|
//начало ---------------------------------ЭБУ-------------------------------------------------------------------------
|
|
//начало ---------------------------------ЭБУ-------------------------------------------------------------------------
|
|
|
|
//начало ---------------------------------Прошивка ЭБУ------------------------------------------------------------------
|
|
//начало ---------------------------------Прошивка ЭБУ------------------------------------------------------------------
|
|
//начало ---------------------------------Прошивка ЭБУ------------------------------------------------------------------
|
|
|
|
typedef struct {
|
|
uint16_t idPacked;
|
|
bool isReceivedResponse;
|
|
} tEgtsFirmwareAdditionalData;
|
|
|
|
typedef struct {
|
|
uint32_t timestamp;
|
|
uint16_t idFirmware;
|
|
uint16_t partNumber;
|
|
uint16_t countNumber;
|
|
char module[10];
|
|
|
|
uint8_t bufEbu[1024];
|
|
uint16_t bufLen;
|
|
} tEgtsFirmwareDataArgs;
|
|
|
|
//конец ---------------------------------Прошивка ЭБУ------------------------------------------------------------------
|
|
//конец ---------------------------------Прошивка ЭБУ------------------------------------------------------------------
|
|
//конец ---------------------------------Прошивка ЭБУ------------------------------------------------------------------
|
|
|
|
|
|
//начало ---------------------------------Аутентификация---------------------------------------------------------------
|
|
//начало ---------------------------------Аутентификация---------------------------------------------------------------
|
|
//начало ---------------------------------Аутентификация---------------------------------------------------------------
|
|
|
|
typedef struct {
|
|
uint8_t *IMEI;
|
|
uint8_t IMEI_len;
|
|
uint32_t TerminalID;
|
|
} tEgtsIdentityDataArgs;
|
|
|
|
typedef struct {
|
|
tDeviceStorage *deviceStorage;
|
|
} tEgtsIdentityModuleDataArgs;
|
|
|
|
typedef struct {
|
|
uint16_t idPacked;
|
|
bool isReceivedResponse;
|
|
bool isReceivedResultCode;
|
|
uint16_t resultCodeAuth;
|
|
} tEgtsIdentityAdditionaData;
|
|
|
|
//конец ---------------------------------Аутентификация---------------------------------------------------------------
|
|
//конец ---------------------------------Аутентификация---------------------------------------------------------------
|
|
//конец ---------------------------------Аутентификация---------------------------------------------------------------
|
|
|
|
|
|
//начало ---------------------------------Команды-----------------------------------------------------------------------
|
|
//начало ---------------------------------Команды-----------------------------------------------------------------------
|
|
//начало ---------------------------------Команды-----------------------------------------------------------------------
|
|
|
|
#define COMMAND_QUEUE_SIZE 5
|
|
|
|
typedef struct {
|
|
uint16_t ADR;
|
|
uint8_t SZ;
|
|
uint8_t ACT;
|
|
uint16_t CCD;
|
|
uint8_t *DT;
|
|
uint8_t DT_SIZE;
|
|
} tEgtsSrCmdConfirmationExComData;
|
|
|
|
typedef struct {
|
|
uint8_t CT;
|
|
uint8_t CCT;
|
|
uint32_t CID;
|
|
uint32_t SID;
|
|
uint8_t ACFE;
|
|
uint8_t CHSFE;
|
|
uint8_t CHS;
|
|
uint8_t ACL;
|
|
uint16_t AC;
|
|
tEgtsSrCmdConfirmationExComData CmdData;
|
|
} tEgtsCommandConfirmationDataArgs;
|
|
|
|
typedef struct {
|
|
osMessageQueueId_t queue;
|
|
uint16_t idPacked;
|
|
bool isReceivedResponse;
|
|
} tEgtsCommandConfirmationAdditionalData;
|
|
|
|
|
|
typedef struct {
|
|
uint8_t cmdType;
|
|
uint32_t cmdId;
|
|
uint8_t act;
|
|
uint16_t cmd;
|
|
uint8_t commandConfirmationType;
|
|
uint16_t dataSize;
|
|
uint8_t data[32];
|
|
} tEgtsCommand;
|
|
|
|
//конец ---------------------------------Команды------------------------------------------------------------------------
|
|
//конец ---------------------------------Команды------------------------------------------------------------------------
|
|
//конец ---------------------------------Команды------------------------------------------------------------------------
|
|
|
|
typedef struct {
|
|
int16_t x;
|
|
int16_t y;
|
|
int16_t z;
|
|
uint16_t angle;
|
|
} tRawAccel;
|
|
|
|
|
|
typedef struct {
|
|
bool isEbuData;
|
|
uint16_t speed;
|
|
uint32_t dist;
|
|
} tEgtsCanEnv;
|
|
|
|
typedef enum {
|
|
EGTS_WAIT_0 = 0,
|
|
EGTS_WAIT_1 = 1,
|
|
EGTS_WAIT_2 = 2
|
|
} eEgtsSendWait;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint32_t SIZE_ROOT_CA;
|
|
uint32_t SIZE_CLIENT_KEY;
|
|
uint32_t SIZE_CLIENT_CRT;
|
|
uint32_t ENC;
|
|
} tEgtsCertInfo;
|
|
|
|
typedef struct {
|
|
uint32_t timeOutCheckTeledata_IGN_TimeUpdate;
|
|
uint32_t timeOutCheckTeledata_EM_TimeUpdate;
|
|
|
|
uint32_t timeOutCheckTeledata_TimeSpeedUpdate;
|
|
|
|
bool isUpdatePoints;
|
|
|
|
bool isOneNav;
|
|
|
|
bool oneOn;
|
|
bool oneOff;
|
|
bool isBeginEndNav;
|
|
|
|
bool isEVENT_NAVIGATION_START_STOP;
|
|
bool isEVENT_ROTATE_ANGLE_LIMIT;
|
|
bool isEVENT_DISTANCE;
|
|
bool isEVENT_TIMEOUT_ENGINE_OFF;
|
|
bool isEVENT_TIMEOUT_ENGINE_ON;
|
|
bool isEVENT_EMERGENCY_TRACKING_TIMEOUT;
|
|
bool isEVENT_VEH_STATE_CHANGED;
|
|
bool isEVENT_MOVEMENT_ON;
|
|
bool isEVENT_MOVEMENT_OFF;
|
|
|
|
uint16_t beginAngle;
|
|
uint16_t beginDist;
|
|
|
|
} tEgtsPointEnv;
|
|
|
|
typedef struct {
|
|
|
|
tSerialPortIO *log;
|
|
volatile uint16_t egtsPacketId;
|
|
uint16_t counter;
|
|
uint8_t socketId;
|
|
EgtsWorkerEnvironment egtsEnv;
|
|
tLoggerToSerialPort *slog;
|
|
|
|
tGpioPin *ignition;
|
|
|
|
tEgtsPointEnv egtsPointEnv;
|
|
|
|
struct {
|
|
uint32_t stopPositionLimitTime;
|
|
eCarPosition carPosition;
|
|
|
|
tNmeaRmc beginPosition;
|
|
tNmeaRmc movePosition;
|
|
|
|
bool isTimerMoving;
|
|
uint32_t timerMoving;
|
|
|
|
uint16_t dataSpeed[4];
|
|
uint16_t dataSpeedStep;
|
|
|
|
} carEventPosition;
|
|
|
|
tStaticThreadBlock(512) T_processing_Network;
|
|
// tStaticThreadBlock(1024) T_processing_ebu;
|
|
tStaticThreadBlock(512) T_processing_input_command;
|
|
tStaticThreadBlock(512) T_processing_event_teledata;
|
|
tStaticThreadBlock(512) T_processing_teledata;
|
|
tStaticThreadBlock(512) T_processing_main;
|
|
tStaticThreadBlock(1024) T_listener;
|
|
tStaticThreadBlock(1024) T_processing_urc;
|
|
|
|
// uint8_t wb[1024 * 10];
|
|
uint8_t wb[1024];
|
|
// uint8_t wb[1024 * 10];
|
|
|
|
|
|
char hexString[1024];
|
|
|
|
tLocationPointInDegDouble *bleLoc;
|
|
tGsmWithGnss *gsm;
|
|
tRtcIO *rtc;
|
|
|
|
// Теледанные
|
|
volatile tEgtsTeledataAdditionalData egtsTeledataAdditionalData;
|
|
tEgtsTeledata egtsTeledataUveos; // Состояние по запросу от УВЭОС
|
|
tEgtsTeledata egtsTeledataSent; // Последнее отправленное состояние
|
|
tEgtsTeledata egtsTeledataEdit; // Формируемое состояние
|
|
tEgtsTeledata egtsTeledataFix; // Фиксируемое состояние
|
|
|
|
// Прошивка модулей ЭБУ
|
|
volatile tEgtsFirmwareAdditionalData egtsFirmwareAdditionalData;
|
|
tEgtsFirmwareDataArgs egtsFirmwareDataArgs;
|
|
|
|
// tEgtsEbuState ebuState;
|
|
// bool ebuReady;
|
|
|
|
// Аутентификация
|
|
volatile tEgtsIdentityAdditionaData egtsIdentityAdditionalData;
|
|
tEgtsIdentityDataArgs egtsIdentityDataArgs;
|
|
tEgtsIdentityModuleDataArgs egtsModuleDataArgs;
|
|
|
|
// Команды
|
|
volatile tEgtsCommandConfirmationAdditionalData egtsCommandConfirmationAdditionalData;
|
|
tEgtsCommandConfirmationDataArgs egtsCommandConfirmationDataArgs;
|
|
tEgtsCommand egtsCommandSent; // Последняя извлеченная команда
|
|
|
|
tString32 srvAddr;
|
|
uint16_t srvPort;
|
|
|
|
tEgtsCanEnv egtsCanEnv;
|
|
|
|
uint16_t pPointsStorageSent;
|
|
|
|
volatile bool isEnableTelematicaSendPoints;
|
|
uint32_t firstStartTimeUpdateEBU;
|
|
bool fl_firstStartTimeUpdateEBU;
|
|
/*
|
|
uint16_t firmwareBufCrc;
|
|
uint32_t firmwareOffset;
|
|
*/
|
|
tDeviceTeledataStorageData *deviceTeledataStorageData;
|
|
|
|
tDeviceStorage *store;
|
|
|
|
bool rebootFirmware;
|
|
|
|
bool isOneEBU;
|
|
|
|
|
|
// tRawAccel rawAccel;
|
|
|
|
int32_t x1;
|
|
int32_t y1;
|
|
int32_t z1;
|
|
int32_t x2;
|
|
int32_t y2;
|
|
int32_t z2;
|
|
uint8_t count_shot;
|
|
uint8_t count_free;
|
|
uint32_t timeAccelUpdate;
|
|
|
|
|
|
uint32_t timeOutCheckNetworkStatus;
|
|
|
|
} tEgtsProcessing;
|
|
|
|
|
|
bool Gsm_SetProfileINTERNET(tEgtsProcessing *env);
|
|
|
|
void EgtsProcessing_Init(
|
|
tEgtsProcessing *env,
|
|
tDeviceStorage *deviceStorage,
|
|
tGpioPin *ignition,
|
|
tGsmWithGnss *gsm,
|
|
tRtcIO *rtcIO,
|
|
tLoggerToSerialPort *slog
|
|
);
|
|
|
|
char *sendLogHex(tEgtsProcessing *env, uint8_t *data, size_t size);
|
|
|
|
void EgtsProcessing_Start(tEgtsProcessing *env);
|
|
|
|
bool EgtsProcessingSend(tEgtsProcessing *env, uint8_t *egtsRaw, uint16_t egtsRawLength,
|
|
eEgtsSendWait wait, volatile bool *wait1, volatile bool *wait2);
|
|
|
|
void EgtsProcessingCloseConnection(tEgtsProcessing *env);
|
|
|
|
bool isAuth(tEgtsProcessing *env);
|
|
|
|
uint8_t findDelimiter(tString32 *address, char ch);
|
|
|
|
bool EgtsProcessing_SendResponse(tEgtsProcessing *env,
|
|
eEgtsServiceId sourceServiceId,
|
|
eEgtsServiceId recipientServiceId,
|
|
uint8_t srvFlags,
|
|
uint8_t rst,
|
|
uint16_t crn);
|
|
|
|
bool onOffTelematica(tEgtsProcessing *env, bool *oneOn, bool *oneOff, char *task);
|
|
|
|
void receivedUpdateFirmware(tEgtsProcessing *env);
|
|
|
|
|
|
bool Gsm_SetProfileERA(tEgtsProcessing *env);
|
|
|
|
#endif //SMART_COMPONENTS_EGTSPROCESSING_H
|