GONEC_ARTERY_Modem_Main/Inc/ModemMain.h

403 lines
10 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Created by cfif on 04.10.2022.
//
#ifndef MODEMMAIN_H
#define MODEMMAIN_H
#include <CmsisRtosThreadUtils.h>
#include <SerialPortIO.h>
#include <DeviceStorageIni.h>
#include <Gnss.h>
#include "ModemGonec.h"
#include "fs_interface.h"
#include "RtcIO.h"
#include "ModemGnss.h"
#include "httpd_types.h"
#include "file_logger.h"
#include "stdbool.h"
#include "GonetsReedSalmon.h"
#include "md5alg.h"
#include "Gpios.h"
#include "GonetsAlmanac.h"
//#define DEBUG_MODEM 1
//#define DEBUG_EXT_MODEM 1
#define maxFilesOutBox 128
typedef enum {
TYPE_FILE_MESSAGE = 0,
TYPE_FILE_TRACERT = 1,
TYPE_FILE_KVITIN = 2,
TYPE_FILE_AMS_RADAR = 3,
TYPE_FILE_LORA_WAN = 4
} tTypeFile;
typedef enum {
BUF_NO_RECEIVE = 0,
BUF_NO_RECEIVE_KV = 1,
BUF_RECEIVE = 2
} tBufFreeFillState;
typedef enum {
SLOT_FREE = 0,
SLOT_READY_READ_OR_WRITE = 1,
SLOT_READY_SENDING = 2,
SLOT_INIT = 3
} tStatusModem;
typedef struct {
char path_mask_fileName[MAX_LEN_PATH_FS];
} tModemStatusFile;
typedef struct {
uint32_t sendFrom[32];
uint32_t sendLen[32];
uint32_t idMessage[32];
uint32_t urgency[32];
uint8_t type[32];
uint8_t sos[32];
uint8_t id[32];
tStatusModem status[32];
} tModemStatus;
typedef struct {
uint32_t receive; // Смещение доставленных пакетов
uint32_t no_receive; // Смещение не доставленных пакетов
} tStructReceiveOffset;
typedef struct {
tTypeFile typeFile;
uint32_t from;
uint32_t mnum;
char to[MAX_LEN_PATH_FS];
uint32_t urgency;
uint32_t chSv;
char subj[MAX_LEN_PATH_FS];
uint32_t kvs;
char fileName[MAX_LEN_PATH_FS];
uint32_t dateDay;
uint32_t dateMon;
uint32_t offsetMsg;
uint32_t sizeFileRep;
uint32_t isSendAll;
uint32_t bytes_sending;
uint32_t bytes_no_sending;
uint32_t sos;
uint32_t kvt_num;
uint32_t kvt_mon;
uint32_t kvt_day;
uint32_t crc32_MSK;
uint32_t crc32_REP;
} tFileSendInfo;
typedef struct {
uint32_t bytes_sending;
uint32_t bytes_no_sending;
uint32_t mnum;
uint8_t kvs;
uint8_t valid;
uint8_t isSendAll;
} tFileSendInfoForJson;
typedef struct {
uint32_t from;
uint32_t mnumFrom;
uint32_t to;
uint32_t chSv;
uint32_t kvs;
uint32_t mnum;
uint32_t dateDay;
uint32_t dateMon;
uint32_t fileSize;
uint32_t isEnd;
uint32_t isRecvInbox;
uint32_t crc32_MSK;
uint32_t crc32_REP;
} tFileRecvInfo;
typedef enum {
StateReqAlmaNoSendStatus = 0,
StateReqAlmaSendStatus = 1,
StateReqAlmaReady = 3
} tStateReqAlma;
typedef enum {
StateReqSosStatusOff = 0,
StateReqSosStatusOn = 1
} tStateReqSos;
typedef enum {
StateReqRegNoSendStatus = 0,
StateReqRegSendStatus = 1,
} tStateReqReg;
typedef enum {
StateReqAlmaWebStop = 0,
StateReqAlmaWebRun = 1,
StateReqAlmaWebRunInit = 3
} tStateReqAlmaWebRunStop;
typedef enum {
StateReqExtNone = 0,
StateReqExtForDel = 1,
StateReqExtForCreate = 2
} tStateReqExt;
typedef enum {
MODEM_WORKING_NONE,
MODEM_WORKING_REG,
MODEM_WORKING_ALMA,
MODEM_WORKING_MSG
} tModemWorkingState;
typedef struct {
time_t EVENT_OUTBOX;
time_t EVENT_INBOX;
time_t EVENT_SENTBOX;
time_t EVENT_ALMA;
time_t EVENT_TRACERT;
} tEventWebState;
#define LEN_TRANS_PACKET 1300
typedef struct {
uint32_t numberSender;
uint32_t numberMessage;
uint32_t dataType;
uint32_t dataCreationDay;
uint32_t dataCreationMon;
bool isEnabled;
bool isCrcUpdate;
} tPacketDataForKvitin;
typedef struct {
tFs *fs;
tDeviceStorageIni *store;
tGnss *gnss;
tGpios *gpios;
tLoggerInterface *logger;
tAtCmd modemAt;
tAtCmd modemAtGsm;
tRtcIO *rtcIo;
tModemWorkingState modemWorkingState;
uint32_t stepRssi;
int32_t dataRssi[10];
uint32_t timestamp_start_block;
uint32_t timestamp_start_block_work;
uint32_t timestamp_start_block_work_add;
tModemNavData location;
tFileLogger *flog;
tPacketDataForKvitin packetDataForKvitin[16];
// tFileSendInfoForJson fileSendInfoForJson[maxFilesOutBox];
osMutexId_t accessHTTP;
osMutexId_t accessMODEM;
osMutexId_t accessMODEM_GSM;
tModemStatus modemStatus;
tStatusModem modemStatusOld[32];
bool isModemStart;
bool isRequestModemRecvSlots;
bool modemSlotSendStatusReload;
bool modemSlotReceivedStatusReload;
uint32_t testOne;
struct {
uint8_t modemRx[2048];
uint8_t modemTx[2048];
} memGonec;
struct {
uint8_t modemRx[2048];
uint8_t modemTx[2048];
} memGsm;
struct {
tStateReqExt stateReqDelExtW;
tStateReqExt stateReqCreateExtW;
tStateReqExt stateReqDelExtT;
tStateReqExt stateReqCreateExtT;
tStateReqAlma stateReqAlma;
tStateReqReg stateReqReg;
tStateReqSos stateReqSos;
tStateReqAlmaWebRunStop stateReqAlmaWebRunStop;
} stateRequest;
struct {
osThreadId_t id;
uint32_t stack[6144];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} thread;
// uint32_t timeStuckGetMs;
uint32_t mnumBufScan[128];
uint32_t mnumBufScanCount;
int32_t rssi;
int32_t temp;
uint32_t state;
uint32_t pwramp;
char bufLog[1024];
osMutexId_t accessTracert;
uint8_t bufReceivedPacket[LEN_TRANS_PACKET];
uint32_t bufReceivedPacketLen;
uint8_t bufSendPacketKvitin[LEN_TRANS_PACKET * 6];
uint32_t timeUpdateModemRegion;
uint8_t bufSendPacket[LEN_TRANS_PACKET];
tStructReceiveOffset structReceiveOffset[250];
tEventWebState eventWebState;
tGalois256 galois256;
tGonetsReedSalmon GonetsReedSalmonParity4;
md5a_context md5ctx_t;
md5a_context md5ctx_r;
int32_t msgId;
char gsmIMEI[32];
char gsmSimId[32];
tGonetsAlmanac alms[50];
int countAlmanac;
bool isModemCheck;
uint32_t isEnableTracerTimeStamp;
struct {
bool pbDone;
} urc;
tStaticThreadBlock(512) urcT;
} tModemMain;
typedef struct __attribute__ ((packed)) {
uint8_t versionProtocol; // Версия протокола
uint8_t classMessage; // Класс сообщения
uint8_t typeMessage; // Тип сообщения
uint32_t typeCodingNoise: 4; // Тип помехоустойчивого кодирования
uint32_t typeTransformation: 4; // Тип преобразования сообщения
uint32_t typeCompression: 4; // Тип сжатия сообщения
uint32_t typeCrc: 4; // Тип контрольной суммы
uint32_t reserve; // Резерв
uint8_t crc8; // crc
uint32_t rc; // Р-С
} tStructRepresentationPacket;
typedef struct __attribute__ ((packed)) {
//#pragma scalar_storage_order big-endian
//#pragma pack(push, 1)
//typedef struct {
uint32_t versionProtocol: 4; // Версия протокола
uint32_t dataType: 4; // Тип данных
uint32_t numberSender: 24; // Номер отправителя
uint32_t dateCreateTransportPacketDay: 5; // Дата формирования транспортного пакета
uint32_t dateCreateTransportPacketMon: 4; // Дата формирования транспортного пакета
uint32_t numberMessage: 15; // Номер сообщения
uint32_t offsetPacket: 23; // Смещение пакета в сообщении
uint32_t isEnd: 1; // Признак последнего пакета
} tStructTransportPacket;
//#pragma pack(pop)
//#pragma scalar_storage_order little-endian
typedef struct __attribute__ ((packed)) {
//#pragma scalar_storage_order big-endian
//#pragma pack(push, 1)
//typedef struct {
uint32_t d1: 5; // Признак последнего пакета
uint32_t d2: 3; // Признак последнего пакета
uint32_t d3: 4; // Признак последнего пакета
uint32_t d4: 4; // Признак последнего пакета
uint32_t d5: 8; // Признак последнего пакета
} tGGG;
//#pragma pack(pop)
//#pragma scalar_storage_order little-endian
typedef struct __attribute__ ((packed)) {
uint32_t offsetKvitPacket: 24; // Смещение доставленных пакетов
} tStructTransportKvitPacketData;
typedef struct __attribute__ ((packed)) {
uint32_t versionProtocol: 4; // Версия протокола
uint32_t dataType: 4; // Тип данных
uint32_t numberSender: 24; // Номер отправителя
uint32_t dateCreateTransportPacketDay: 5; // Дата формирования транспортного пакета
uint32_t dateCreateTransportPacketMon: 4; // Дата формирования транспортного пакета
uint32_t numberMessage: 15; // Номер сообщения
} tStructTransportKvitPacket;
typedef struct __attribute__ ((packed)) {
uint8_t packetType; // Тип пакета
uint16_t sizeTransportPacket; // Размер транспортного служебного пакета
uint8_t numberRecipient[3]; // Номер получателя
uint8_t idArray; // Идентификатор массива
uint16_t offsetByteArray; // Смещение первого байта сегмента в массиве
uint8_t isEndSegment; // Признак последнего сегмент в массиве
uint8_t typeArray; // Тип массива
} tStructTransportPacketService;
void ModemMain_Init(
tModemMain *env,
tGpios *gpios,
tSerialPortIO *ioGonec,
tSerialPortIO *ioGsm,
tGnss *gnss,
tDeviceStorageIni *store,
tFileLogger *flog,
tFs *fs,
tRtcIO *rtcIo,
osMutexId_t accessMODEM_GSM,
osMutexId_t accessMODEM,
osMutexId_t accessHTTP,
osMutexId_t accessTracert
);
void ModemMain_StartThread(tModemMain *env);
bool stuckModem(tModemMain *env);
void getDelFilesDirScanCrc(tModemMain *env);
void controlFiles(tFs *fs, char *ext, char *path);
void sendMsd(tModemMain *env);
//void sendAmsRadar(tModemMain *env, char *buf, uint32_t buf_len);
bool almac_load_from_file(tModemMain *env);
void sendExtProtokolPack(tModemMain *env, tTypeFile typeFile, char *buf, uint32_t buf_len);
#endif //MODEMMAIN_H