1. add parser binary data from uart for parse struct data. All works
This commit is contained in:
53
src/core/crc8.cpp
Normal file
53
src/core/crc8.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "crc8.h"
|
||||
|
||||
static const unsigned char RMAP_CRCTable[] = {
|
||||
0x00, 0x91, 0xe3, 0x72, 0x07, 0x96, 0xe4, 0x75,
|
||||
0x0e, 0x9f, 0xed, 0x7c, 0x09, 0x98, 0xea, 0x7b,
|
||||
0x1c, 0x8d, 0xff, 0x6e, 0x1b, 0x8a, 0xf8, 0x69,
|
||||
0x12, 0x83, 0xf1, 0x60, 0x15, 0x84, 0xf6, 0x67,
|
||||
0x38, 0xa9, 0xdb, 0x4a, 0x3f, 0xae, 0xdc, 0x4d,
|
||||
0x36, 0xa7, 0xd5, 0x44, 0x31, 0xa0, 0xd2, 0x43,
|
||||
0x24, 0xb5, 0xc7, 0x56, 0x23, 0xb2, 0xc0, 0x51,
|
||||
0x2a, 0xbb, 0xc9, 0x58, 0x2d, 0xbc, 0xce, 0x5f,
|
||||
0x70, 0xe1, 0x93, 0x02, 0x77, 0xe6, 0x94, 0x05,
|
||||
0x7e, 0xef, 0x9d, 0x0c, 0x79, 0xe8, 0x9a, 0x0b,
|
||||
0x6c, 0xfd, 0x8f, 0x1e, 0x6b, 0xfa, 0x88, 0x19,
|
||||
0x62, 0xf3, 0x81, 0x10, 0x65, 0xf4, 0x86, 0x17,
|
||||
0x48, 0xd9, 0xab, 0x3a, 0x4f, 0xde, 0xac, 0x3d,
|
||||
0x46, 0xd7, 0xa5, 0x34, 0x41, 0xd0, 0xa2, 0x33,
|
||||
0x54, 0xc5, 0xb7, 0x26, 0x53, 0xc2, 0xb0, 0x21,
|
||||
0x5a, 0xcb, 0xb9, 0x28, 0x5d, 0xcc, 0xbe, 0x2f,
|
||||
0xe0, 0x71, 0x03, 0x92, 0xe7, 0x76, 0x04, 0x95,
|
||||
0xee, 0x7f, 0x0d, 0x9c, 0xe9, 0x78, 0x0a, 0x9b,
|
||||
0xfc, 0x6d, 0x1f, 0x8e, 0xfb, 0x6a, 0x18, 0x89,
|
||||
0xf2, 0x63, 0x11, 0x80, 0xf5, 0x64, 0x16, 0x87,
|
||||
0xd8, 0x49, 0x3b, 0xaa, 0xdf, 0x4e, 0x3c, 0xad,
|
||||
0xd6, 0x47, 0x35, 0xa4, 0xd1, 0x40, 0x32, 0xa3,
|
||||
0xc4, 0x55, 0x27, 0xb6, 0xc3, 0x52, 0x20, 0xb1,
|
||||
0xca, 0x5b, 0x29, 0xb8, 0xcd, 0x5c, 0x2e, 0xbf,
|
||||
0x90, 0x01, 0x73, 0xe2, 0x97, 0x06, 0x74, 0xe5,
|
||||
0x9e, 0x0f, 0x7d, 0xec, 0x99, 0x08, 0x7a, 0xeb,
|
||||
0x8c, 0x1d, 0x6f, 0xfe, 0x8b, 0x1a, 0x68, 0xf9,
|
||||
0x82, 0x13, 0x61, 0xf0, 0x85, 0x14, 0x66, 0xf7,
|
||||
0xa8, 0x39, 0x4b, 0xda, 0xaf, 0x3e, 0x4c, 0xdd,
|
||||
0xa6, 0x37, 0x45, 0xd4, 0xa1, 0x30, 0x42, 0xd3,
|
||||
0xb4, 0x25, 0x57, 0xc6, 0xb3, 0x22, 0x50, 0xc1,
|
||||
0xba, 0x2b, 0x59, 0xc8, 0xbd, 0x2c, 0x5e, 0xcf
|
||||
};
|
||||
|
||||
unsigned char crc8(const void * data, int size)
|
||||
{
|
||||
// INCRC - the intermediate RMAP CRC byte value
|
||||
unsigned char INCRC = 0;
|
||||
// INBYTE - The RMAP Header or Data byte
|
||||
unsigned char * INBYTE = (unsigned char *) data;
|
||||
|
||||
unsigned char * end = INBYTE + size;
|
||||
|
||||
while (INBYTE < end)
|
||||
{
|
||||
INCRC = RMAP_CRCTable[INCRC ^ *INBYTE];
|
||||
INBYTE++;
|
||||
}
|
||||
return INCRC;
|
||||
}
|
||||
10
src/core/crc8.h
Normal file
10
src/core/crc8.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef CRC8_H
|
||||
#define CRC8_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// CRC-8-CCIT, generator polynomial: x**8 + x**2 + x**1 + x**0
|
||||
unsigned char crc8(const void * data, int size);
|
||||
|
||||
#endif // CRC8_H
|
||||
@@ -22,11 +22,13 @@
|
||||
#include <QVariant>
|
||||
#include <QVariantList>
|
||||
#include <QVector>
|
||||
#include <QtEndian> // Для qbswap
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "loggingCategories.h"
|
||||
#include "html_report.h"
|
||||
#include "crc8.h"
|
||||
|
||||
struct comSet_t {
|
||||
int addrRS485;
|
||||
@@ -64,5 +66,336 @@ typedef struct {
|
||||
|
||||
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t replyAddrLength: 2; ///< reply address length field (for path addressing):
|
||||
///< \arg 0b00 - 0 bytes,
|
||||
///< \arg 0b01 - 4 bytes,
|
||||
///< \arg 0b10 - 8 bytes,
|
||||
///< \arg 0b11 - 12 bytes
|
||||
uint8_t increment: 1; ///< 1 - incrementing address
|
||||
uint8_t reply: 1; ///< 1 - transmit reply, 0 - not transmit reply
|
||||
uint8_t checkData: 1; ///< 1 - checking data before write
|
||||
uint8_t operationType: 1; ///< 1 - write data, 0 - read data
|
||||
uint8_t packetTypeField: 2; ///< 0b00 - logical address, 0b01 - physical address - for MIL layer
|
||||
///< 0b01 - command, 0b00 - reply for RMAP layer
|
||||
|
||||
} RMAP_instruct_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef union
|
||||
{
|
||||
uint8_t all;
|
||||
RMAP_instruct_t bit;
|
||||
} RMAP_instruct_u;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t targetLogAddr;
|
||||
uint8_t protocolID;
|
||||
RMAP_instruct_u instruct;
|
||||
uint8_t key;
|
||||
uint8_t initiatorLogAddr;
|
||||
uint8_t transactID[2];
|
||||
uint8_t addr[5];
|
||||
uint8_t dataLength[3];
|
||||
uint8_t headerCRC;
|
||||
} RMAP_cmdWriteReadHeadLogAddr_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t initiatorLogAddr;
|
||||
uint8_t protocolID;
|
||||
uint8_t instruct;
|
||||
uint8_t status;
|
||||
uint8_t targetLogAddr;
|
||||
uint16_t transactID;
|
||||
uint8_t headerCRC;
|
||||
} RMAP_WriteReplyHead_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t initiatorLogAddr;
|
||||
uint8_t protocolID;
|
||||
uint8_t instruct;
|
||||
uint8_t status;
|
||||
uint8_t targetLogAddr;
|
||||
uint16_t transactID;
|
||||
uint8_t reserved;
|
||||
uint32_t dataLength;
|
||||
uint8_t headerCRC;
|
||||
} RMAP_ReadReplyHead_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t targetSpwAddr[2];
|
||||
uint8_t targetLogAddr;
|
||||
uint8_t protocolID;
|
||||
RMAP_instruct_u instruct;
|
||||
uint8_t key;
|
||||
uint8_t replyAddr[4];
|
||||
uint8_t initiatorLogAddr;
|
||||
uint16_t transactID;
|
||||
uint8_t extendAddr;
|
||||
uint32_t addr;
|
||||
uint8_t dataLength[3];
|
||||
uint8_t headerCRC;
|
||||
} RMAP_cmdWriteReadHeadPathAddr_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RMAP_success = 0, ///< 00
|
||||
RMAP_errGeneral, ///< 01
|
||||
RMAP_errUnusePackType, ///< 02
|
||||
RMAP_errInvalKey, ///< 03
|
||||
RMAP_errInvalDataCRC, ///< 04
|
||||
RMAP_errDataEarlyEOP, ///< 05
|
||||
RMAP_errTooMuchData, ///< 06
|
||||
RMAP_errDataEEP, ///< 07
|
||||
RMAP_errReserved, ///< 08
|
||||
RMAP_errVerifyBufOver, ///< 09
|
||||
RMAP_errCmdNotImplement, ///< 10
|
||||
RMAP_errDataLengthErr, ///< 11
|
||||
RMAP_errInvalTargLogAddr, ///< 12
|
||||
RMAP_errHeaderEarlierEOP, ///< 13
|
||||
RMAP_errInvalHeaderCRC, ///< 14
|
||||
RMAP_errNotRMAP, ///< 15
|
||||
RMAP_errReplyTimeout, ///< 16
|
||||
RMAP_errUnknownTransactID, ///< 17
|
||||
RMAP_spwReconnectFailed, ///< 18
|
||||
RMAP_errInputParam, ///< 19
|
||||
RMAP_unknownInitiatorLogAddrInReply,///< 20
|
||||
RMAP_errTxTimeout, ///< 21
|
||||
RMAP_errRxReplyTimeout, ///< 22
|
||||
COUNT_ERR_MAX_ELEMENTS_RMAP = 30
|
||||
} RMAP_errFlag_en;
|
||||
|
||||
/**
|
||||
* \brief structure with exchange error status counters
|
||||
* according to RMAP protocol (ECSS-E-ST-50-52C), table 5-4
|
||||
*/
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint16_t success; ///< 00
|
||||
uint16_t general; ///< 01
|
||||
uint16_t unusePackType; ///< 02
|
||||
uint16_t invalKey; ///< 03
|
||||
uint16_t invalDataCRC; ///< 04
|
||||
uint16_t dataEarlyEOP; ///< 05
|
||||
uint16_t tooMuchData; ///< 06
|
||||
uint16_t dataEEP; ///< 07
|
||||
uint16_t reserved; ///< 08
|
||||
uint16_t verifyBufOver; ///< 09
|
||||
uint16_t cmdNotImplement; ///< 10
|
||||
uint16_t dataLengthErr; ///< 11
|
||||
uint16_t invalTargLogAddr; ///< 12
|
||||
uint16_t headerEarlierEOP; ///< 13
|
||||
uint16_t invalHeaderCRC; ///< 14
|
||||
uint16_t notRMAP; ///< 15
|
||||
uint16_t replyTimeout; ///< 16
|
||||
uint16_t unknownTransactID; ///< 17
|
||||
uint16_t spwReconnectFailed; ///< 18
|
||||
uint16_t invalInputParam; ///< 19
|
||||
uint16_t unknownInitiatorLogAddrInReply; ///< 20
|
||||
uint16_t txTimeout; ///< 21
|
||||
uint16_t rxReplyTimeout; ///< 22
|
||||
uint16_t reserve[7];
|
||||
} RMAP_countErr_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
rmapNone = 0,
|
||||
rmapRunTxCmd,
|
||||
rmapTxCmdCmplt,
|
||||
rmapWaitReply,
|
||||
rmapRxReplyCmplt,
|
||||
} RMAP_stateMachine_en;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RMAP_notRunOperation = 0,
|
||||
RMAP_runOperation = 1,
|
||||
RMAP_compltOperation = 2,
|
||||
RMAP_abortOperation = 3
|
||||
} RMAP_operStatus_en;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t spwPort; // 0 or 1
|
||||
RMAP_cmdWriteReadHeadLogAddr_t cmdWRheadLogAddr;
|
||||
RMAP_WriteReplyHead_t writeReplyHead;
|
||||
RMAP_ReadReplyHead_t readReplyHead;
|
||||
RMAP_cmdWriteReadHeadPathAddr_t cmdWRheadPathAddr;
|
||||
uint32_t timeTxCmd;
|
||||
uint32_t timeTxReply;
|
||||
uint32_t timeWaitRxReply;
|
||||
uint32_t rxReplyTimeout;
|
||||
uint32_t txTimeout;
|
||||
uint32_t timerPeriod;
|
||||
volatile RMAP_stateMachine_en stateMachine;
|
||||
volatile RMAP_errFlag_en errorCodeOperation;
|
||||
volatile RMAP_operStatus_en operationStatus;
|
||||
} RMAP_protocol_t;
|
||||
|
||||
extern RMAP_protocol_t RMAPcontrol;
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t reserve[11];
|
||||
uint8_t repeatWriteCmd;
|
||||
uint8_t repeatWriteCmdMax;
|
||||
uint8_t targetLogAddr;
|
||||
uint8_t initiatorLogAddr;
|
||||
uint8_t targetSpwAddr[2];
|
||||
uint16_t transactID;
|
||||
RMAP_instruct_u instruction;
|
||||
uint8_t errorLastOperation; //RMAP_errFlag_en
|
||||
uint16_t error[COUNT_ERR_MAX_ELEMENTS_RMAP];
|
||||
} RMAP_HK_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
extern RMAP_HK_t RMAP_HK;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UART_errNone = 0, ///< 00
|
||||
UART_errRxUnknownData, ///< 01
|
||||
UART_errTxDMAfail, ///< 02
|
||||
UART_errTxTimeout, ///< 03
|
||||
UART_errOverflowFIFO, ///< 04
|
||||
UART_errLineBreak, ///< 05
|
||||
RMAP_errParityErr, ///< 06
|
||||
RMAP_errFrameErr, ///< 07
|
||||
RMAP_errRxTimeout, ///< 08
|
||||
COUNT_ERR_MAX_ELEMENTS = 20,
|
||||
} UART_operErrCode_enum;
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t reserve[9];
|
||||
volatile uint8_t errorLastOperation; // UART_operErrCode_enum
|
||||
volatile uint16_t error[COUNT_ERR_MAX_ELEMENTS];
|
||||
} UART_HK_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
extern UART_HK_t UART_HK;
|
||||
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t stack: 1;
|
||||
uint8_t ram: 1;
|
||||
uint8_t pFunc_start: 1;
|
||||
uint8_t pFunc_end: 1;
|
||||
uint8_t reserve: 4;
|
||||
} Guard_memory_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef union
|
||||
{
|
||||
uint8_t all;
|
||||
Guard_memory_t bit;
|
||||
} Guard_memory_u;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
operationBeginOk = 0,
|
||||
operationOk = 1,
|
||||
unknownOperType = 2,
|
||||
wrongNANDaddr = 3,
|
||||
wrongInputParameters = 4,
|
||||
DMAchannelBusy = 5,
|
||||
RDYnotSet0 = 6,
|
||||
RDYnotSetBackTo1 = 7,
|
||||
DMAnotRun = 8,
|
||||
DMAnotIRQ = 9,
|
||||
DMAtimeout = 10,
|
||||
DMAruntimeError = 11,
|
||||
readStatusFail = 12,
|
||||
featuresNotSet = 13,
|
||||
repeatOperationFail = 14,
|
||||
COUNT_ERR_NAND_FLASH_MAX = 20,
|
||||
} NAND_operErrCode_enum;
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint16_t column;
|
||||
uint8_t page;
|
||||
uint16_t block;
|
||||
uint8_t LUN;
|
||||
uint8_t numTarget[2]; ///< numTarg[0] - target Flash number with main data,
|
||||
///< numTarg[1] - target Flash number with control data
|
||||
} NAND_address_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t reserve[11];
|
||||
NAND_address_t addr;
|
||||
volatile uint32_t timeEraseBlock;
|
||||
volatile uint16_t timeReadPage;
|
||||
volatile uint16_t timeProgPage;
|
||||
volatile uint8_t lastOperation; // NAND_operType_enum
|
||||
volatile uint8_t lastOperationStatus; // NAND_operStatus_enum
|
||||
volatile uint8_t errorLastOperation; // NAND_operErrCode_enum
|
||||
uint16_t error[COUNT_ERR_NAND_FLASH_MAX];
|
||||
} NAND_HK_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
extern NAND_HK_t NAND_HK;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
system_ok = 0,
|
||||
memory_overflow = 1,
|
||||
MAX_SYSTEM_ERROR = 255,
|
||||
} system_error_enum;
|
||||
|
||||
#define HK_VERSION 1
|
||||
#define HK_MAGIC 0x484B3031u // "HK01"
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t magic;
|
||||
uint64_t version;
|
||||
uint16_t size;
|
||||
uint32_t counter;
|
||||
|
||||
uint8_t system_error;
|
||||
Guard_memory_u guard;
|
||||
|
||||
UART_HK_t uart;
|
||||
RMAP_HK_t rmap;
|
||||
NAND_HK_t nand;
|
||||
|
||||
uint8_t crc;
|
||||
|
||||
} Snapshot_HK_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
|
||||
#endif // DECLARATIONS_H
|
||||
|
||||
Reference in New Issue
Block a user