#ifndef __WMH_COMM_DATA_H_
#define __WMH_COMM_DATA_H_
#include "TYW_stdint.h"

#define WMH_COMM_PROTOCOL_VERSION       0x2F;

#define COMM_DATA_UNION_WI_BOX_LENGTH_0X80       13

typedef union {
    struct 
    {
        // ===================== Byte0 =====================
        uint8_t Mileage_H            :8; // 里程高字节

        // ===================== Byte1 =====================
        uint8_t Mileage_M            :8; // 里程中字节

        // ===================== Byte2 =====================
        uint8_t Mileage_L            :8; // 里程低字节

        // ===================== Byte3 =====================
        uint8_t Reserved1            :8; // ~~卡种类 0x01加密卡 0x02未加密卡~~（预留）

        // ===================== Byte4 =====================
        uint8_t Reserved2            :8; // ~~卡序号 0x11、0x22、0x33（预留）~~

        // ===================== Byte5 =====================
        uint8_t Reserved3            :8; // ~~卡ID（预留）~~

        // ===================== Byte6 =====================
        uint8_t Reserved4            :8; // ~~卡ID（预留）~~

        // ===================== Byte7 =====================
        uint8_t Reserved5            :8; // ~~卡ID（预留）~~

        // ===================== Byte8 =====================
        uint8_t Reserved6            :8; // ~~卡ID（预留）~~

        // ===================== Byte9 =====================
        uint8_t Reserved7            :8; // ~~卡总数（预留）~~

        // ===================== Byte10 ====================
        uint8_t Reserved8            :8; // ~~添卡状态：0x01进行中、0x02成功、0x03失败、0x04卡已存在（预留）~~

        // ===================== Byte11 ====================
        uint8_t Reserved9            :8; // ~~删卡状态：0x01进行中、0x02成功、0x03失败（预留）~~

        // ===================== Byte12 ====================
        uint8_t Reserved10           :8; // ~~预留位10~~
    } bits;
    uint8_t Bytes[COMM_DATA_UNION_WI_BOX_LENGTH_0X80];
} COMM_DATA_UNION_WI_BOX_0x80;
extern   COMM_DATA_UNION_WI_BOX_0x80 WMHCommDataWiBox_0x80;

#define COMM_DATA_UNION_WI_BOX_LENGTH_0X90       16
typedef union {
    struct {
        uint8_t Data90_Byte1                 :8;
        uint8_t Data90_Byte2                 :8;
        uint8_t Data90_Byte3                 :8;
        uint8_t Data90_Byte4                 :8;
        uint8_t Data90_Byte5                 :8;
        uint8_t Data90_Byte6                 :8;
        uint8_t Data90_Byte7                 :8;
        uint8_t Data90_Byte8                 :8;
        uint8_t Data90_Byte9                 :8;
        uint8_t Data90_Byte10                :8;
        uint8_t Data90_Byte11                :8;
        uint8_t Data90_Byte12                :8;
        uint8_t Data90_Byte13                :8;
        uint8_t Data90_Byte14                :8;
        uint8_t Data90_Byte15                :8;
        uint8_t Data90_Byte16                :8;
    } bits;
    uint8_t Bytes[COMM_DATA_UNION_WI_BOX_LENGTH_0X90];
} COMM_DATA_UNION_WI_BOX_0x90;
extern   COMM_DATA_UNION_WI_BOX_0x90 WMHCommDataWiBox_0x90;

#define COMM_DATA_UNION_WI_BOX_LENGTH_0X91       12
typedef union {
    struct {
        uint8_t Data91_Byte1     :8; // 预估里程低字节
        uint8_t Data91_Byte2     :8; // 预估里程低字节
        uint8_t Data91_Byte3     :8; // 预估里程低字节
        uint8_t Data91_Byte4     :8; // 预估里程低字节
        uint8_t Data91_Byte5     :8; // 预估里程低字节
        uint8_t Data91_Byte6     :8; // 预估里程低字节
        uint8_t Data91_Byte7     :8; // 预估里程低字节
        uint8_t Data91_Byte8     :8; // 预估里程低字节
        uint8_t Data91_Byte9     :8; // 预估里程低字节
        uint8_t Data91_Byte10     :8; // 预估里程低字节
        uint8_t Data91_Byte11     :8; // 预估里程低字节
        uint8_t Data91_Byte12     :8; // 预估里程低字节
    } bits;
    uint8_t Bytes[COMM_DATA_UNION_WI_BOX_LENGTH_0X91];
} COMM_DATA_UNION_WI_BOX_0x91;
extern   COMM_DATA_UNION_WI_BOX_0x91 WMHCommDataWiBox_0x91;

#define COMM_DATA_UNION_WI_BOX_LENGTH_0X92       5
typedef union {
    struct {
        uint8_t Data92_Byte1     :8; // 预估里程低字节
        uint8_t Data92_Byte2     :8; // 预估里程低字节
        uint8_t Data92_Byte3     :8; // 预估里程低字节
        uint8_t Data92_Byte4     :8; // 预估里程低字节
        uint8_t Data92_Byte5     :8; // 预估里程低字节
    } bits;
    uint8_t Bytes[COMM_DATA_UNION_WI_BOX_LENGTH_0X92];
} COMM_DATA_UNION_WI_BOX_0x92;
extern COMM_DATA_UNION_WI_BOX_0x92 WMHCommDataWiBox_0x92;




#define COMM_DATA_UNION_ICM_LENGTH          13
typedef union {
    struct {
        uint8_t Mileage_H :8;
        uint8_t Mileage_M :8;
        uint8_t Mileage_L :8;

        uint8_t CardKind :8; //卡种类 0x01加密卡 0x02未加密卡
        uint8_t CardNum :8;  //卡序号 0x11 0x22 0x33
        uint8_t CardID1 :8;  //卡ID
        uint8_t CardID2 :8;  //卡ID
        uint8_t CardID3 :8;  //卡ID
        uint8_t CardID4 :8;  //卡ID
        uint8_t CardTotal :8;//卡总数

        uint8_t AddCardStatus:8;   //添卡状态0x01进行中 0x02成功 0x03失败 0x04卡已存在
        uint8_t RemoveCardStatus:8;//删卡状态0x01进行中 0x02成功 0x03失败

        uint8_t Reserved :8;

    } bits;
    uint8_t Bytes[COMM_DATA_UNION_ICM_LENGTH];
} COMM_DATA_UNION_ICM;
extern COMM_DATA_UNION_ICM WMHCommDataIcm;

extern uint8_t WMHCommFrameCheckSumFunc(uint32_t ID, uint8_t DLC, uint8_t ProtocolVersion, uint8_t *data);

extern void WMHCommFrameCallBack_WiBox_0x80(void);
extern void WMHCommFrameCallBack_WiBox_0x90(void);
extern void WMHCommFrameCallBack_WiBox_0x91(void);
extern void WMHCommFrameCallBack_WiBox_0x92(void);
extern void WMHCommFrameTimeoutFunc_WiBox(void);
extern void WMHCommFrameTimeoutFunc_WiBox80(void);

extern void WMHCommFrameCallBack_Icm(void);
extern void WMHCommFrameTimeoutFunc_Icm(void);

#endif

