#ifndef __WMH_COMM_DATA_H_
#define __WMH_COMM_DATA_H_
#include "TYW_stdint.h"
#include "wmhcomm.h"
#include "wmhcommdata.h"
#include "wmhcommdata.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;


// extern   COMM_DATA_UNION_WI_BOX_0x01 WMHCommDataWiBox_0x01;

#define COMM_DATA_UNION_WI_BOX_LENGTH_0X91       12
typedef union {
    struct 
    {
        // // ===================== Byte0 =====================
        // uint8_t Year                  :8; // 年

        // // ===================== Byte1 =====================
        // uint8_t Month                 :8; // 月

        // // ===================== Byte2 =====================
        // uint8_t Day                   :8; // 日

        // // ===================== Byte3 =====================
        // uint8_t Hour                  :8; // 小时

        // // ===================== Byte4 =====================
        // uint8_t Minute                :8; // 分钟

        // // ===================== Byte5 =====================
        // uint8_t Second                :8; // 秒

        // // ===================== Byte6 =====================
        // uint8_t BtDistanceSt          :1; // 蓝牙感应距离状态
        // uint8_t BtConnection          :1; // 蓝牙连接状态
        // uint8_t SignalStrengthOf4G    :3; // LTE网络信号强度格数（CSQ=0或99→0格，CSQ=1-5→1格，CSQ=6-10→2格，CSQ=11-15→3格，CSQ=16-20→4格，CSQ≥21→5格）
        // uint8_t SignalStrengthOfGps   :3; // GPS信号连接格数（3颗→0格，4颗→1格，5颗→2格，6颗→3格，≥7颗→4格）

        // // ===================== Byte7 =====================
        // uint8_t Reserved1             :6; // 预留位1
        // uint8_t MessageWaittingToAnswer :1; // 信息待回复
        // uint8_t PhoneWaittingToAnswer :1; // 电话待接听

        // // ===================== Byte8 =====================
        // uint8_t PositFault            :1; // 定位故障
        // uint8_t MasterControlFault    :1; // 主控故障
        // uint8_t BtFault               :1; // 蓝牙故障
        // uint8_t PowerFault            :1; // 电源故障
        // uint8_t ThreeAxisSensorFault  :1; // 三轴传感器故障
        // uint8_t OneServiceFault       :1; // 一线通故障
        // uint8_t NetWorkFault          :1; // 网络故障
        // uint8_t ACCFault              :1; // ACC故障

        // // ===================== Byte9 =====================
        // uint8_t Reserved2             :6; // 预留位2
        // uint8_t AntennaFault          :1; // 天线故障
        // uint8_t RfFault               :1; // 射频故障

        // // ===================== Byte10 =====================
        // uint8_t EstimateMileage_H     :8; // 预估里程高字节

        // // ===================== Byte11 =====================
        // uint8_t EstimateMileage_L     :8; // 预估里程低字节
        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 
    {
        // // ===================== Byte0 =====================
        // uint8_t Inquire               :8; // 0x00→未查询，0x11→查询里程，~~0x22→查询NFC卡信息~~

        // // ===================== Byte1 =====================
        // uint8_t Reserved1             :8; // ~~0x00→无操作，0x11→添卡，0x22→删卡~~

        // // ===================== Byte2 =====================
        // uint8_t Reserved2             :8; // ~~0x00→暂不响应，0x11~0xFF→卡1~卡15~~

        // // ===================== Byte3 =====================
        // uint8_t Reserved3             :8; // 预留位3

        // // ===================== Byte4 =====================
        // uint8_t Reserved4             :8; // 预留位4
        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 COMM_DATA_UNION_WI_BOX_0x91 WMHCommDataWiBox_0x91;
extern COMM_DATA_UNION_WI_BOX_0x92 WMHCommDataWiBox_0x92;

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_WiBox_90(void);
extern void WMHCommFrameTimeoutFunc_WiBox_91(void);
extern void WMHCommFrameTimeoutFunc_WiBox_92(void);
extern void WMHCommFrameTimeoutFunc_WiBox80(void);

extern void WMHCommFrameCallBack_Icm(void);
extern void WMHCommFrameTimeoutFunc_Icm(void);
/*台铃-黄国庆*/
extern void WMHCommFrameTimeoutFunc_WiBox_01(void);
extern void WMHCommFrameCallBack_WiBox_0x01(void);

#endif

