/*
 * Config.h
 *
 *  Created on: 2019年4月23日
 *      Author: foluswen
 */
#ifndef CONFIG_H_
#define CONFIG_H_

#include <stdbool.h>

typedef unsigned char               byte;


#define MODE_BOOT                   0
#define MODE_IDLE                   1
#define MODE_AUTHORIZING            2
#define MODE_REASSIGN_CHECK         3
#define MODE_REASSIGN               4
#define MODE_PRECHARGE              5
#define MODE_PREPARE_FOR_EV         6
#define MODE_PREPARE_FOR_EVSE       7
#define MODE_CHARGING               8
#define MODE_TERMINATING            9
#define MODE_COMPLETE               10
#define MODE_ALARM                  11
#define MODE_FAULT                  12
#define MODE_RESERVATION            13
#define MODE_BOOKING                14
#define MODE_MAINTAIN               15
#define MODE_DEBUG                  16
#define MODE_CCS_PRECHARGE_STEP0    17 	// ready for ccs precharge processing, For D+ relay to precharge relay
#define MODE_CCS_PRECHARGE_STEP1    18	// waitting for ev board inform to enter to charging, For precharge relay to D+ relay
#define MODE_UPDATE                 19

#define GFD_WAIT                    0
#define GFD_PASS                    1
#define GFD_FAIL                    2
#define GFD_WARNING                 3

#define PRECHARGE_WAIT              0
#define PRECHARGE_READY             1
#define PRECHARGE_PRERELAY_PASS     2
#define PRECHARGE_CHARELAY_PASS     3

#define BOOTTING                    0
#define BOOT_COMPLETE               1

#define uSEC_VAL                    1000000
#define mSEC_VAL                    1000
#define MAX_DISPENSER_QUANTITY      4
#define MAX_GUN_QUANTITY            4
#define MAX_GROUP_QUANTITY          4
#define MAX_PSU_MODULE_QUANTITY     62
#define MAX_MODULE_PER_GROUP        12
#define INFY_SINGLE_PSU_POWER       30000           // unit: 1W
#define SM_ChargerInfoKey           3000
#define MAX_OUTPUT_VOLTAGE          9500

#define SAFETY_TEST_ENABLE          0

#define MAX_SLAVE_CABINET_QUANTITY  4
#define MASTER_ETH1_IP              "192.168.100.1"
#define MASTER_ETH1_SUBMASK         "255.255.255.0"
#define SLAVE_ETH1_IP               "192.168.0.10"
#define SLAVE_ETH1_SUBMASK          "255.255.255.0"

#define AUTHORIZE_COMPLETED_TIME    3
#define STARTTRANSATION_IMMEDIATELY

#define ENABLE_PCBA_TEST            0

#define PARALLEL_RELAY_COUNT        6
#define GRAB_AT_START_CHARGING      0
#define FAN_DUTY_OF_QUIET_MODE      35              // unit:1 %

#define _PHIHONG_PRICE_SPLIT_KEY    ","
#define _AUDI_PRICE_SPLIT_KEY       ";"
#define _OIL_PRICE_SPLIT_KEY        "\n"

// **********  Audi ********** //
// Model Name: DOYC182000D2AD
// Model Name: DDYC182V0UE2AD

// ********** e4you ********** //
// Model Name: DKYE182000D1E4
// Model Name: DXYE182E00E1E4

// ********** xpeng ********** //
// Model Name: DOYE362000D2XP
// Model Name: DDYE362F0KE2XP

// *********** BYD *********** //
// Model Name: DOYE242000D2BD
// Model Name: DDYE242V0UE2BD

// *********** TCC *********** //
// Model Name: DBYE182000D1PH
// Model Name: DBYC182000D1TC
// Model Name: DDYC182V0EE1TC

#define STR_LITTLE_ENDIAN           "Little Endian"
#define STR_BIG_ENDIAN              "Big Endian"

#define STR_MODE_BOOT               "Booting"
#define STR_MODE_IDLE               "Idle"
#define STR_MODE_AUTHORIZING        "Authorizing"
#define STR_MODE_REASSIGN_CHECK     "ReassignCheck"
#define STR_MODE_REASSIGN           "Reassign"
#define STR_MODE_PREPARNING         "Preparing"
#define STR_MODE_PREPARING_EV       "PreparnForEV"
#define STR_MODE_PREPARING_EVSE     "PrepareForEVSE"
#define STR_MODE_CHARGING           "Charging"
#define STR_MODE_TERMINATING        "Terminating"
#define STR_MODE_COMPLETE           "Completed"
#define STR_MODE_ALARM              "Alarm"
#define STR_MODE_FAULT              "Fault"
#define STR_MODE_RESERVATION        "Reservation"
#define STR_MODE_BOOKING            "Booking"
#define STR_MODE_MAINTAIN           "Maintain"
#define STR_MODE_DEBUG              "Debug"
#define STR_MODE_CCS_ST0            "CCS_ST0"
#define STR_MODE_CCS_ST1            "CCS_ST1"
#define STR_MODE_UPDATE             "Update"
#define STR_MODE_NONE               "None"

#define GUN_IDLE_TYPE_NORMAL        0
#define GUN_IDLE_TYPE_WHOLE         1

enum _SYSTEM_STATUS
{
	S_BOOTING =                         0,
    S_IDLE,
	S_AUTHORIZING,
	S_REASSIGN_CHECK,
	S_REASSIGN,
	S_PREPARNING,
	S_PREPARING_FOR_EV,
	S_PREPARING_FOR_EVSE,
    S_CHARGING,
	S_TERMINATING,
	S_COMPLETE,
	S_ALARM,
	S_FAULT,
	S_RESERVATION,
	S_BOOKING,
	S_MAINTAIN,
	S_DEBUG,
	S_CCS_PRECHARGE_ST0,
	S_CCS_PRECHARGE_ST1,
	S_UPDATE,
	S_NONE,
};

#define STR_GUN_TYPE_CHADEMO        "CHAdeMO"
#define STR_GUN_TYPE_CCS            "CCS"
#define STR_GUN_TYPE_GBT            "GBT"
#define STR_GUN_TYPE_AC             "AC"
#define STR_GUN_TYPE_UNKNOWN        "Unknown Type"

enum _GUN_TYPE
{
	_Type_Chademo = 		0,
	_Type_CCS_2,
	_Type_GB,
	_Type_AC,
	_Type_Unknown = 0xFF
};

enum _LCM_INDEX
{
	_LCM_INIT               = 0x00,
	_LCM_IDLE               = 0x01,
	_LCM_AUTHORIZING        = 0x02,
	_LCM_AUTHORIZ_COMP      = 0x03,
	_LCM_AUTHORIZ_FAIL      = 0x04,
	_LCM_WAIT_FOR_PLUG      = 0x05,
	_LCM_PRE_CHARGE         = 0x06,
	_LCM_CHARGING           = 0x07,
	_LCM_COMPLETE           = 0x08,
	_LCM_FIX                = 0x09,
	_LCM_NONE               = 0xFF,
};

enum _DispenserAuthorizeStatus
{
    _AuthorizeStatus_Idle   = 0x00,
    _AuthorizeStatus_Wait   = 0x01,
    _AuthorizeStatus_Busy   = 0x02,
    _AuthorizeStatus_Done   = 0x03,
    _AuthorizeStatus_End    = 0x04,
};

enum _ConnectorAuthorizeResult
{
    _AuthResult_None    = 0x00,
    _AuthResult_Valid   = 0x01,
    _AuthResult_Invalid = 0x02,
};

enum _AuthorizedType
{
    _AuthType_None          = 0x00,
    _AuthType_RFID          = 0x01,
    _AuthType_RemoteStart   = 0x02,
};

enum _SELF_TEST_SEQ
{
	_STEST_VERSION          = 0x00,
	_STEST_CabinetSwitch    = 0x01,
	_STEST_AC_CONTACTOR     = 0x02,
	_STEST_PSU_DETECT       = 0x03,
	_STEST_PSU_CAP          = 0x04,
    _STEST_PSU_RETRY        = 0x05,
    _STEST_EMG_BTN          = 0x06,
	_STEST_FAIL             = 0x07,
	_STEST_COMPLETE         = 0xEE,
};

enum _MODULE_PSU_WORK_STEP
{
	INITIAL_START 		= 		0,
	GET_PSU_COUNT 		= 		1,
	Get_PSU_LOCATION    =       2,
	Get_PSU_VERSION     =       3,
	PSU_COUNT_CONFIRM   =       4,
	GET_SYS_CAP			=		5,
	BOOTING_COMPLETE 	= 		6,

	_WORK_CHARGING 		= 		10,

	_TEST_MODE			=		20,

	_NO_WORKING			= 		254,
	_INIT_PSU_STATUS	= 		255
};

enum _OFFLINE_POLICY
{
	_OFFLINE_POLICY_LOCAL_LIST          = 0x00,
	_OFFLINE_POLICY_PHIHONG_RFID_TAG    = 0x01,
	_OFFLINE_POLICY_FREE_CHARGING       = 0x02,
	_OFFLINE_POLICY_NO_CHARGING         = 0x03,
};

enum _REASSIGNED_RESOURCE_STEP
{
	_REASSIGNED_NONE = 				0,	//
	_REASSIGNED_PREPARE_M_TO_A =	1,	// 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
	_REASSIGNED_GET_NEW_CAP = 		2,	// 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
	_REASSIGNED_ADJUST_M_TO_A = 	3,	// 模塊重新分配完成
	_REASSIGNED_RELAY_M_TO_A =		4,	// 切斷橋接的 Relay

	_REASSIGNED_PREPARE_A_TO_M = 	11,
	_REASSIGNED_ADJUST_A_TO_M = 	12, // 模塊升壓
	_REASSIGNED_RELAY_A_TO_M = 		13,	// 搭接橋接的 Relay
	_REASSIGNED_WAITING = 			14,
	_REASSIGNED_COMP = 				15
};

enum _MAIN_CHARGING_MODE
{
	_MAIN_CHARGING_MODE_MAX = 0,
	_MAIN_CHARGING_MODE_AVER = 1,
};

enum _EXTRA_ERR_PROCESS
{
	_EXTRA_ERR_PROCESS_NONE = 0,
	_EXTRA_ERR_PROCESS_INUVP = 1,
	_EXTRA_ERR_PROCESS_INOVP = 2,
	_EXTRA_ERR_PROCESS_PRIMARY = 3,
};

enum _CHARGER_TYPE
{
	_CHARGER_TYPE_IEC = 0,
	_CHARGER_TYPE_UL = 1,
};

enum _SYS_WIFI_MODE
{
	_SYS_WIFI_MODE_DISABLE = 0,
	_SYS_WIFI_MODE_STATION = 1,
	_SYS_WIFI_MODE_AP = 2
};

enum _LED_INTENSITY_LV
{
	_LED_INTENSITY_DARKEST 	 = 0,
	_LED_INTENSITY_MEDIUM 	 = 1,
	_LED_INTENSITY_BRIGHTEST = 2
};

enum _CCS_COMM_PROTOCOL
{
	_CCS_COMM_V2GMessage_DIN70121 		= 0x01,
	_CCS_COMM_V2GMessage_ISO15118_2014 	= 0x02,
	_CCS_COMM_V2GMessage_ISO15118_2018 	= 0x03
};

enum _ETHERNET_USAGE
{
	_ETHERNET_USAGE_NONE 	= 0,
	_ETHERNET_USAGE_LAN,
	_ETHERNET_USAGE_WIFI,
	_ETHERNET_USAGE_3G_4g
};

enum _SYS_POWER_SHARING_MODE
{
    _SYS_POWER_SHARING_MODE_DISABLE = 0,
    _SYS_POWER_SHARING_MODE_MASTER  = 1,
    _SYS_POWER_SHARING_MODE_SLAVE   = 2,
};

#define STR_CONN_DISABLE            "Disable"
#define STR_CONN_CONNECTED          "Connected"
#define STR_CONN_DISCONNECTED       "Disconnected"

#define STR_DARKEST                 "Darkest"
#define STR_MEDIUM                  "Medium"
#define STR_BRIGHTEST               "Brightest"

#define STR_PAGE_NONE               "PageNone"
#define STR_REMOTE_NO_ID            "PlugInPage"

enum _CONN_STATUS
{
    _Connnection_Disable = 0,
    _Connnection_Connected = 1,
    _Connnection_Disconnected = 2,
};

enum _LED_INDICATION_STATUS
{
    _LED_INDICATION_OFF             = 0,            // all led off
    _LED_INDICATION_RUN             = 1,            // green led on, red led off
    _LED_INDICATION_FAULT           = 2,            // green led off, red led on
    _LED_INDICATION_ON              = 3,            // all led on
    _LED_INDICATION_GREEN_TOGGLE    = 4,            // green led toggle
    _LED_INDICATION_RED_TOGGLE      = 5,            // red led toggle
};

enum _STANDARD_INDICATION_STATUS
{
    _STANDARD_LED_None          = 0,
    _STANDARD_LED_Disconnection = 1,
    _STANDARD_LED_Running       = 2,
    _STANDARD_LED_Alarm         = 3,
};

enum _E4YOU_INDICATION_STATUS
{
    _E4YOU_LED_None             = 0,
    _E4YOU_LED_Disconnection    = 1,
    _E4YOU_LED_Idle             = 2,
    _E4YOU_LED_Charging         = 3,
    _E4YOU_LED_Alarm            = 4,
};

#define STR_QR_DEFAULT              "Default"
#define STR_QR_CUSTOMIZED           "Customized"
#define STR_QR_CHARGEBOXID          "ChargeBoxId"

enum _QR_MODE
{
    _QR_MODE_Default            = 0,
    _QR_MODE_Customized         = 1,
    _QR_MODE_ChargeBoxId        = 2,                // for audi
};

enum _CUSTOMER_CODE
{
    _CUSTOMER_CODE_Phihong      = 0,
    _CUSTOMER_CODE_Audi         = 1,
    _CUSTOMER_CODE_E4U          = 2,
    _CUSTOMER_CODE_UCar         = 3,
    _CUSTOMER_CODE_TCC          = 4,
    _CUSTOMER_CODE_Shell        = 5,
};

#define STR_FAN_AUTO_MODE           "Auto"
#define STR_FAN_QUITE_MODE          "Quite"

enum _FAN_CONTROL_POLICY
{
    _FAN_POLICY_AUTO_MODE               = 0x00,
    _FAN_POLICY_QUITE_MODE              = 0x01,
};

#define STR_CABINET_ROLE_NONE       "Single"
#define STR_CABINET_ROLE_MASTER     "Master"
#define STR_CABINET_ROLE_SLAVE      "Slave"

enum _CABINET_ROLE
{
    _CROLE_SINGLE               = 0,                // single power cabinet mode
    _CROLE_MASTER               = 1,                // power cabinet master mode
    _CROLE_SLAVE                = 2,                // power cabinet slave mode
};

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int SelfTestOK:1;                  // 0: self test not completed,  1: self test ok
        unsigned int NeedSelfTest:1;                // 0: no effect,                1: need execute self test
        unsigned int NeedSoftReset:1;               // 0: no effect,                1: system need soft reset
        unsigned int NeedHardReset:1;               // 0: no effect,                1: system need hard reset
        unsigned int PrimaryDisable:1;              // 0: primary enable,           1: primary disable
        unsigned int RelayBoardDisable:1;           // 0: relay board enable,       1: relay board disable
        unsigned int FanBoardDisable:1;             // 0: fan board enable,         1: fan board disable
        unsigned int LedBoardDisable:1;             // 0: led board enable,         1: led board disable
        unsigned int SecondRelayBoardEnable:1;      // 0: second relay disable,     1: second relay enable
        unsigned int DOLedIndication:1;             // 0: no led indication,        1: enable DO Model led indication
        unsigned int DKLedIndication:1;             // 0: no led indication,        1: enable DK Model led indication
        unsigned int BackendEnable:1;               // 0: backend disable,          1: backend enable
        unsigned int Wifi4gResetEnable:1;           // 0: wifi/4g reset io disable, 1: wifi/4g reset io enable
        unsigned int PsuInit:1;                     // 0: no effect,                1: psu is initialized
        unsigned int Enable6ParallelRelay:1;        // 0: no effect,                1: enable 6 parallel relay
        unsigned int FlashConfigChanged:1;          // 0: no effect,                1: flash content has changed
        unsigned int WriteFlashEnable:1;            // 0: no effect,                1: enable write flash after timeout
        unsigned int WriteFlashBusy:1;              // 0: no effect,                1: flash is writing
        unsigned int WriteFlashImmediately:1;       // 0: no effect,                1: write flash immediately
        unsigned int WriteFlashAndReset:1;          // 0: no effect,                1: write flash and soft reset
        unsigned int res:12;
    }bits;
}SystemControl;

typedef union
{
    unsigned int LibValue;
    struct
    {
        unsigned int InfyPwrLib:1;                  // 0: no effect,                1: infy pwr lib used
        unsigned int PhPwrLib:1;                    // 0: no effect,                1: phihong pwr lib used
        unsigned int res:30;
    }bits;
}LibUse;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int DisableBalance:1;              // 0: no effect,                1: disable announce balance
        unsigned int FastStandbyTime:1;             // 0: no effect,                1: enable fast standby time
        unsigned int ChargingSimulation:1;          // 0: no effect,                1: enable charging simulation
        unsigned int FChargingReleaseExtend:1;      // 0: no effect,                1: enable Release and Extend when Force Charging
        unsigned int TryUndisposedBill:1;           // 0: no effect,                1: enable TryUndisposedBill
        unsigned int res:27;
    }bits;
}TestControl;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int MsgMain:1;                     // 0: no effect,                1: enable debug message in main
        unsigned int MsgPrimaryComm:1;              // 0: no effect,                1: enable debug message in primary comm
        unsigned int MsgPsu:1;                      // 0: no effect,                1: enable debug message in psu
        unsigned int MsgEvComm:1;                   // 0: no effect,                1: enable debug message in ev comm
        unsigned int MsgInternalComm:1;             // 0: no effect,                1: enable debug message in internal comm
        unsigned int res:27;
    }bits;
}DebugControl;

#define MAX_EVCOMM_DEBUG_LEN            4
typedef union
{
    unsigned int DebugVal[MAX_EVCOMM_DEBUG_LEN];
    struct
    {
        // DebugVal[0]
        unsigned int RegDbg_All:1;
        unsigned int RegDbg_ModelName:1;
        unsigned int RegDbg_ConnectorID:1;
        unsigned int RegDbg_PowerCabinetStatus:1;
        unsigned int RegDbg_DispenserStatus:1;
        unsigned int RegDbg_ChargingCapability:1;
        unsigned int RegDbg_ChargingTarget:1;
        unsigned int RegDbg_SoftwareUpdate:1;
        unsigned int RegDbg_PlugInStatus:1;
        unsigned int RegDbg_ConnectorState:1;
        unsigned int RegDbg_UserID:1;
        unsigned int RegDbg_Charging_Permission:1;
        unsigned int RegDbg_MiscControl:1;
        unsigned int RegDbg_DispenserCsuVersion:1;
        unsigned int RegDbg_DispenserOtherVersion:1;
        unsigned int RegDbg_ChargingInfo:1;
        unsigned int RegDbg_QRCodeDate:1;
        unsigned int RegDbg_WaitPlugIn:1;
        unsigned int RegDbg_GroundFaultDetection:1;
        unsigned int RegDbg_Cabinet_CSU_Version:1;
        unsigned int RegDbg_Cabinet_Other_Version:1;
        unsigned int RegDbg_PsuQuantity:1;
        unsigned int RegDbg_PsuVersion:1;
        unsigned int RegDbg_Reservation:1;
        unsigned int RegDbg_Dispenser_Request:1;
        unsigned int RegDbg_RemoteStartNoIDState:1;
        unsigned int RegDbg_RefundAmount:1;
        unsigned int RegDbg_PrepaymentInfo:1;
        unsigned int RegDbg_PaymentFailReason:1;
        unsigned int RegDbg_ConnectorQRCode:1;
        unsigned int RegDbg_StationInfo:1;
        unsigned int RegDbg_DeductResult:1;
        // DebugVal[1]
        unsigned int RegDbg_CabinetSystemID:1;
        unsigned int RegDbg_DefaultPriceString:1;
        unsigned int RegDbg_UserPriceString:1;
        unsigned int RegDbg_Receipt:1;
        unsigned int RegDbg_PowerConsumption:1;
        unsigned int RegDbg_ChargingTimestamp:1;
        unsigned int res:26;
        // DebugVal[2]
        unsigned int DebugVal2:32;
        // DebugVal[3]
        unsigned int DebugVal3:32;
    }bits;
}DebugEvCommMsgFlag;

typedef union
{
    unsigned int DebugVal;
    struct
    {
        // DebugVal[0]
        unsigned int MsgId_None:1;
        unsigned int MsgId_Gun_1:1;
        unsigned int MsgId_Gun_2:1;
        unsigned int MsgId_Gun_3:1;
        unsigned int MsgId_Gun_4:1;
        unsigned int MsgId_Gun_5:1;
        unsigned int MsgId_Gun_6:1;
        unsigned int MsgId_Gun_7:1;
        unsigned int MsgId_Gun_8:1;
        unsigned int res:23;
    }bits;
}DebugEvCommIdFlag;

typedef struct
{
    DebugEvCommMsgFlag MsgFlag;
    DebugEvCommIdFlag IdFlag;
}EvCommCtrlInfo;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int EnableForceCharging:1;         // 0: disable,                  1: enable force charging
        unsigned int StartForceCharging:1;          // 0: disable,                  1: start force charging
        unsigned int EnableReleaseAndExtend:1;      // 0: disable,                  1: enable Release And Extend when force charging
        unsigned int WebApiTrigger:1;               // 0: no effect,                1: force charging is triggered by web api
        unsigned int res:28;
    }bits;
}ForceChargingControl;

typedef struct
{
    ForceChargingControl    FCtrl;
    unsigned short          FTargetVoltage;         // target voltage, unit: 0.1V
    unsigned short          FTargetCurrent;         // target current, unit: 0.1A
}ForceCharging;

typedef union
{
    unsigned int AuthFlag;
    struct
    {
        unsigned int APPEnable:1;                   // 0: disable,                  1: app auth enable
        unsigned int QRCodeEnable:1;                // 0: disable,                  1: qr code auth enable
        unsigned int RFIDEnable:1;                  // 0: disable,                  1: rfid auth enable
        unsigned int res:29;
    }bits;
}AuthModeInfo;

typedef struct
{
    AuthModeInfo  AuthMode;
    unsigned char QRCodeMode;                        // 0: default, 1: customized, 2: audi type
    unsigned char res[3];
}SystemAuthInfoData;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int SelfTestOK:1;                  // 0: self test not completed,  1: self test ok
        unsigned int NeedSelfTest:1;                // 0: no effect,                1: need execute self test
        unsigned int Paused:1;                      // 0: no effect,                1: primary paused
        unsigned int DisableDoorSensor:1;           // 0: door sensor enable,       1: door sensor disable
        unsigned int DisableEmergencyButton:1;      // 0: emergency button enable,  1: emergency button disable
        unsigned int DoorSensorReverse:1;           // 0: the same as ds's,         1: status is different from ds's
        unsigned int AcContactorReverse:1;          // 0: the same as ds's,         1: status is different from ds's
        unsigned int CabinetSwitchDetect:1;         // 0: no effect,                1: need detect cabinet switch
        unsigned int res:24;
    }bits;
}PrimaryControl;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int SelfTestOK:1;                  // 0: self test not completed,  1: self test ok
        unsigned int NeedSelfTest:1;                // 0: no effect,                1: need execute self test
        unsigned int Paused:1;                      // 0: no effect,                1: relay paused
        unsigned int AbnormalRelay:1;               // 0: no effect,                1: relay abnormal control enable
        unsigned int AcContactor:1;                 // 0: ac contactor off,         1: ac contactor on
        unsigned int AcContactorOffByPsu:1;         // 0: no effect,                1: ac contactor off
        unsigned int AcContactorOffByEmergency:1;   // 0: no effect,                1: ac contactor off
        unsigned int StandbyCountdown:1;            // 0: charger is using,         1: start countdown
        unsigned int AcInputDisable:1;              // 0: ac input enable,          1: ac input disable
        unsigned int DcInputEnable:1;               // 0: dc input disable,         1: dc input enable
        unsigned int AutoTest:1;                    // 0: no effect,                1: relay auto test enable
        unsigned int res:21;
    }bits;
}RelayControl;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int SelfTestOK:1;                  // 0: self test not completed,  1: self test ok
        unsigned int NeedSelfTest:1;                // 0: no effect,                1: need execute self test
        unsigned int Paused:1;                      // 0: no effect,                1: fan paused
        unsigned int AbnormalFan:1;                 // 0: no effect,                1: fan abnormal control enable
        unsigned int res:28;
    }bits;
}FanControl;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int SelfTestOK:1;                  // 0: self test not completed,  1: self test ok
        unsigned int NeedSelfTest:1;                // 0: no effect,                1: need execute self test
        unsigned int Paused:1;                      // 0: no effect,                1: led paused
        unsigned int res:29;
    }bits;
}LedFanControl;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int SelfTestOK:1;                  // 0: self test not completed,  1: self test ok
        unsigned int NeedSelfTest:1;                // 0: no effect,                1: need execute self test
        unsigned int Paused:1;                      // 0: no effect,                1: psu paused
        unsigned int FailureResume:1;               // 0: no error,                 1: psu failure, need resume
        unsigned int CommunicationLost:1;           // 0: no error,                 1: psu communication lost
        unsigned int res:27;
    }bits;
}PsuControl;

enum _OCPP_PAGE_INDEX
{
    _OCPP_Page_None             = 0,                // page none
    _OCPP_Page_LineStatus_1     = 1,                // line status 1 page
    _OCPP_Page_LineStatus_2     = 2,                // line status 2 page
    _OCPP_Page_LineStatus_3     = 3,                // line status 3 page
    _OCPP_Page_LineStatus_4     = 4,                // line status 4 page
};

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int RemoteStartNoId:1;             // 0: no effect,                1: trigger remote start without connector id
        unsigned int res:31;
    }bits;
}OcppControl;

typedef struct
{
    int TxCnt;
    int RxCnt;
    int LostCnt;
    int CommCnt;
}DevideCommInfo;

typedef struct
{
    DevideCommInfo PrimaryComm;
    DevideCommInfo Relay1Comm;
    DevideCommInfo Relay2Comm;
    DevideCommInfo FanComm;
    DevideCommInfo LedComm;
    DevideCommInfo PsuComm;
}CommInfoData;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int UpdateReq:1;                   // 0: no effect,                1: update request
        unsigned int UpdateConfirm:1;               // 0: no effect,                1: update confirm
        unsigned int UpdateDone:1;                  // 0: no effect,                1: update done
        unsigned int res:29;
    }bits;
}UpdateControl;

typedef struct
{
    int Pri232Fd;
    int Rs422Fd;
    int PsuCanFd;
    int EvCanFd;
}FdControl;

typedef enum
{
    _TILT_SENSOR_NONE           = 0,
    _TILT_SENSOR_WAIT           = 1,
    _TILT_SENSOR_STEP_1         = 2,
    _TILT_SENSOR_WAIT_STEP_1    = 3,
    _TILT_SENSOR_STEP_2         = 4,
    _TILT_SENSOR_WAIT_STEP_2    = 5,
    _TILT_SENSOR_OUTCOME        = 6,
    _TILT_SENSOR_STOP           = 7,
    _TILT_SENSOR_WAIT_STOP      = 8,
    _TILT_SENSOR_FINISH         = 9,
}_TILT_SENSOR_TEST_STEP;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int StandbyTimeDisable:1;          // 0: no effect,                1: disable standby time
        unsigned int StandbyTimeDisableForTcc:1;    // 0: no effect,                1: disable standby time at specific time for tcc
        unsigned int StandbyImmediately:1;          // 0: no effect,                1: standby immediately
        unsigned int CustomizedStandbyTime:1;       // 0: no effect,                1: enable customized standby time
        unsigned int TiltSensorEnable:1;            // 0: no effect,                1: enable tilt sensor
        unsigned int res:27;
    }bits;
}CustomizedFlagInfo;

typedef struct
{
    int TiltSensorStep;
    int TiltSensorFail;
    int StandbyTime;                                // unit: 1 minute
    CustomizedFlagInfo Flag;
}CustomizedFunctionInfo;

#define DIAGNOSTICS_TYPE_NONE       0
#define DIAGNOSTICS_TYPE_ALL        1

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int Request:1;                     // 0: no effect,                1: diagnostics request
        unsigned int Confirm:1;                     // 0: no effect,                1: diagnostics confirm
        unsigned int Completed:1;                   // 0: no effect,                1: diagnostics completed
        unsigned int Stop:1;                        // 0: no effect,                1: diagnostics stop
        unsigned int res:28;
    }bits;
}DiagnosticsFlagInfo;

typedef struct
{
    int DiagnosticsType;
    DiagnosticsFlagInfo DispenserDiagnostics[MAX_DISPENSER_QUANTITY];
}DiagnosticsInfo;

typedef struct
{
    unsigned char   MaxDispenser;
    unsigned char   MaxConnector;
    unsigned char   CabinetSwitch;
    unsigned char   CabinetRole;
    unsigned char   SelfTestStep;
    unsigned char   CustomerCode;
    unsigned short  ChargerRatingPower;             // unit: 0.1kw, charger rating power, parsing from model name
    unsigned char   PsuQuantityByModel;
    unsigned char   res;
    CommInfoData    CommInfo;
    SystemControl   SysCtrl;
    LibUse          LibCtrl;
    UpdateControl   UpdateCtrl;
    TestControl     TestCtrl;
    DebugControl    DebugCtrl;
    EvCommCtrlInfo  EvCommCtrl;
    PrimaryControl  PrimaryCtrl;
    RelayControl    RelayCtrl;
    FanControl      FanCtrl;
    LedFanControl   LedCtrl;
    PsuControl      PsuCtrl;
    OcppControl     OcppCtrl;
    FdControl       FdCtrl;
    ForceCharging   FCharging[MAX_GROUP_QUANTITY];
    unsigned char   GunAvailable[MAX_GROUP_QUANTITY];
    unsigned char   PsuInitQuantity[MAX_GROUP_QUANTITY];
    char            ResevedIdTag[MAX_GROUP_QUANTITY][32];

    CustomizedFunctionInfo  CustomizedInfo;
    DiagnosticsInfo Diagnostics;
}SysControl;
// ************************************************************************************************* //
typedef struct
{
    bool           CheckIn;
    unsigned char  res;
    unsigned short Full_Address;
    unsigned char  GroupNo;
    unsigned char  GIndex;
}PsuAddressInfoData;

typedef struct
{
    unsigned char  GroupPsuQuantity;
    unsigned char  res;
    unsigned short PsuIndex[MAX_MODULE_PER_GROUP];
}GroupInfoData;

#define PSU_STATUS_FLAG_OUTPUT                      0x00000001
#define PSU_STATUS_FLAG_FAULT                       0x00000002
#define PSU_STATUS_FLAG_ALARM                       0x00000004
#define PSU_STATUS_FLAG_LOCK                        0x00000008

typedef union
{
    unsigned int StatusVal;
    struct
    {
        unsigned int Output:1;                      // 0: no output,                1: psu is output
        unsigned int Fault:1;                       // 0: no fault,                 1: psu is fault
        unsigned int Alarm:1;                       // 0: no alarm,                 1: psu is alarm
        unsigned int Lock:1;                        // 0: no lock,                  1: psu is lock
        unsigned int res:28;
    }bits;
}PsuStatusInfo;

typedef union
{
    unsigned int StatusVal;
    struct
    {
        unsigned int Changed:1;
        unsigned int Indicated:1;
        unsigned int res:30;
    }bits;
}PsuErrorStatusInfo;

typedef struct
{
    int ErrorCount;
    PsuErrorStatusInfo PhPwrStateFlag;
    unsigned char PsuError[8];
}PhPwrStateInfo;

typedef union
{
    unsigned char StateVal[4];
    struct
    {
        //StateVal[0]
        unsigned char OutputShort:1;                // OFF, Red
        unsigned char State_0_1_7:7;
        //StateVal[1]
        unsigned char PsuOff:1;                     // OFF
        unsigned char PsuFault:1;                   // OFF, Red
        unsigned char PsuProtect:1;                 // OFF, Yellow
        unsigned char FanFault:1;                   // OFF, Red Blink
        unsigned char OverTemperature:1;            // OFF, Yellow
        unsigned char OutputOverVoltage:1;          // OFF, Red
        unsigned char WalkInEnable:1;
        unsigned char CanCommInterrupt:1;           // OFF, Yellow Blink
        //StateVal[2]
        unsigned char PowerLimit:1;                 //  ON
        unsigned char PsuIdRepetition:1;            // OFF, Red
        unsigned char LoadUnsharing:1;              //  ON, Red
        unsigned char InputPhaseLost:1;             // OFF, Yellow
        unsigned char InputUnbalance:1;             //
        unsigned char InputUnderVoltage:1;          // OFF, Yellow
        unsigned char InputOverVoltage:1;           // OFF, Yellow
        unsigned char PfcOff:1;                     // OFF
        //StateVal[3]
        unsigned char State_3:8;
    }bits;
}InfyPsuStateFlagInfo;

typedef struct
{
    PsuErrorStatusInfo InfyPwrStateFlag;
    InfyPsuStateFlagInfo InfyPwrState;
}InfyPwrStateInfo;

typedef struct
{
    bool                PsuLocationInit;
    bool                ReInitPsuLocation;
    unsigned char       TotalPsuQuantity;
    GroupInfoData       GroupLocationInfo[MAX_GROUP_QUANTITY];
    PsuAddressInfoData  PsuAddressInfo[MAX_PSU_MODULE_QUANTITY];
    PsuStatusInfo       SinglePsuStatus[MAX_PSU_MODULE_QUANTITY];
    PhPwrStateInfo      SinglePhPsuError[MAX_PSU_MODULE_QUANTITY];
    InfyPwrStateInfo    SingleInfyPwrState[MAX_PSU_MODULE_QUANTITY];
}PsuPositionInfoData;
// ************************************************************************************************* //
typedef enum
{
    _GROLE_IDLE                 = 0,
    _GROLE_MASTER               = 1,
    _GROLE_SLAVE                = 2,
    _GROLE_PREPARE_SWITCH_OFF   = 10,           // reduce output current capability
    _GROLE_SLAVE_POWER_OFF      = 11,           // power off
    _GROLE_SWITCH_OFF_OK        = 12,           // power off completed
    _GROLE_WAIT_IDLE            = 13,           // wait a while to change to idle, open parallel relay at this state
    _GROLE_WAIT_SLAVE           = 14,           // wait a while to change to slave
    _GROLE_PREPARE_ATTACH_ON    = 20,           // raise voltage to master output voltage
    _GROLE_PRECHARGE_READY      = 21,           // extend pre-charge ready
    _GROLE_EXTEND_STOP          = 22,           // extend capability stop
    _GROLE_REQUEST_TO_CHARGING  = 30,
    _GROLE_TERMINATE            = 40,
    _GROLE_WAIT_TERMINATED      = 41,
    _GROLE_DUMMY_MASTER         = 50,
    _GROLE_DUMMY_FAULT          = 51,
    _GROLE_NO_RESOURCE          = 90,
    _GROLE_NONE                 = 99,
}_GROUP_ROLE;

typedef union
{
    unsigned int CtrlValue[7];
    struct
    {
        unsigned int IdleCtrlValue;
        unsigned int MasterCtrlValue;
        unsigned int StopChargingCtrlValue;
        unsigned int DeratingCtrlValue;
        unsigned int ExtendCapabilityCtrlValue;
        unsigned int SlaveCtrlValue;
        unsigned int DummyMasterCtrlValue;
    }RoleCtrl;
    struct
    {
        // IdleCtrlValue
        unsigned int ChargingRequest:1;                         // 0: no effect,                1: charging request from main.c
        unsigned int ChargingRequestConfirmed:1;                // 0: no effect,                1: request confirmed by psu task
        unsigned int GroupShareCheck:1;                         // 0: no effect,                1: check is there any psu can share
        unsigned int ShareConfirmed:1;                          // 0: no effect,                1: psu share confirmed
        unsigned int GrabGroupWait:1;                           // 0: no effect,                1: need to wait grab psu
        unsigned int ShareCheckDone:1;                          // 0: no effect,                1: psu share completed
        unsigned int FindGroupPartner:1;                        // 0: no effect,                1: find available group partner
        unsigned int ParallelRelayOn:1;                         // 0: no effect,                1: set parallel relay on
        unsigned int ParallelRelayConfirmed:1;                  // 0: no effect,                1: parallel relay confirmed
        unsigned int GroupingDone:1;                            // 0: no effect,                1: grouping completed
        unsigned int IdleCtrlRes:22;

        // MasterCtrlValue
        unsigned int CableCheckDone:1;                          // 0: no effect,                1: CableCheck done
        unsigned int InPrechargeMode:1;                         // 0: no effect,                1: system status in PreCharge mode
        unsigned int AlreadyInChargingMode:1;                   // 0: no effect,                1: system status ever enter charging mode
        unsigned int ExtendAvailable:1;                         // 0: no effect,                1: extend capability is available
        unsigned int NeedCurrentBalance:1;                      // 0: no effect,                1: need to current balance
        unsigned int OutputCurrentStable:1;                     // 0: no effect,                1: output current is stable
        unsigned int ReachMaxCurrentDemand:1;                   // 0: no effect,                1: reach ev max current demand
        unsigned int ReachMaxStageCurrent:1;                    // 0: no effect,                1: reach ev max stage current
        unsigned int SmoothDerating:1;                          // 0: no effect,                1: start smooth derating
        unsigned int AlternateMasterStopRequest:1;              // 0: no effect,                1: alternate master need stop
        unsigned int MasterCtrlRes:22;

        // StopChargingCtrlValue
        unsigned int StopChargingRequest:1;                     // 0: no effect,                1: master need to stop
        unsigned int StopChargingConfirmed:1;                   // 0: no effect,                1: stop charging confirmed
        unsigned int AllPowerOffDone:1;                         // 0: no effect,                1: all member power off done
        unsigned int AllParallelRelayOff:1;                     // 0: no effect,                1: all member's parallel relay off
        unsigned int AllParallelRelayConfirmed:1;               // 0: no effect,                1: all member's parallel relay off confirmed
        unsigned int AllMemberStopCompleted:1;                  // 0: no effect,                1: all member stop completed
        unsigned int StopChargingCompleted:1;                   // 0: no effect,                1: stop charging completed
        unsigned int StopChargingCtrlRes:25;

        // DeratingCtrlValue
        unsigned int NeedDerating:1;                            // 0: no effect,                1: need derating
        unsigned int DeratingConfirmed:1;                       // 0: no effect,                1: derating confirmed
        unsigned int DeratingStart:1;                           // 0: no effect,                1: derating start
        unsigned int DeratingPowerOffDone:1;                    // 0: no effect,                1: derating member power off done
        unsigned int DeratingRelayOff:1;                        // 0: no effect,                1: set derating member parallel relay off
        unsigned int DeratingRelayConfirmed:1;                  // 0: no effect,                1: derating member parallel relay confirmed
        unsigned int DeratingCompleted:1;                       // 0: no effect,                1: derating completed
        unsigned int DeratingCtrlRes:25;

        // ExtendCapabilityCtrlValue
        unsigned int MorePowerRequest:1;                        // 0: no effect,                1: need to request more psu
        unsigned int MorePowerConfirmed:1;                      // 0: no effect,                1: request more psu confirmed
        unsigned int ExtendPrecharge:1;                         // 0: no effect,                1: extend group need to pre-charge
        unsigned int ExtendPrechargeDone:1;                     // 0: no effect,                1: extend group pre-charge completed
        unsigned int ExtendRelayOn:1;                           // 0: no effect,                1: extend group parallel relay on
        unsigned int ExtendRelayConfirmed:1;                    // 0: no effect,                1: extend group parallel relay confirmed
        unsigned int ExtendCompleted:1;                         // 0: no effect,                1: extend capability completed
        unsigned int ExtendCapabilityCtrlRes:25;

        // SlaveCtrlValue
        unsigned int SlaveChargingRequest:1;                    // 0: no effect,                1: request slave to charging after power off
        unsigned int CheckSlaveReady:1;                         // 0: no effect,                1: check if slave is ready
        unsigned int WaitSlaveReady:1;                          // 0: no effect,                1: wait slave is ready
        unsigned int WaitDummyMaster:1;                         // 0: no effect,                1: wait dummy master stop
        unsigned int SlavePowerOffRequest:1;                    // 0: no effect,                1: request slave to power off
        unsigned int SlavePowerOffConfirmed:1;                  // 0: no effect,                1: slave power off confirmed
        unsigned int SlaveCtrlRes:26;

        // DummyMasterCtrlValue
        unsigned int DummyMasterRequest:1;                      // 0: no effect,                1: dummy master request process start
        unsigned int DummyMasterReqConfirmed:1;                 // 0: no effect,                1: dummy master request process confirmed
        unsigned int DummyMasterPermission:1;                   // 0: no effect,                1: dummy master permission
        unsigned int DummyMasterGrabCheck:1;                    // 0: no effect,                1: dummy master grab check
        unsigned int DummyMasterWait:1;                         // 0: no effect,                1: wait dummy master ready
        unsigned int DummyMasterReady:1;                        // 0: no effect,                1: dummy master ready
        unsigned int DummyMasterFindPartner:1;                  // 0: no effect,                1: find dummy master
        unsigned int DummyMasterRelayOn:1;                      // 0: no effect,                1: set dummy master parallel relay on
        unsigned int DummyMasterRelayConfirmed:1;               // 0: no effect,                1: dummy master parallel relay confirmed
        unsigned int DummyMasterCompleted:1;                    // 0: no effect,                1: dummy master process is completed
        unsigned int DummyMasterFault:1;                        // 0: no effect,                1: dummy master request fault
        unsigned int DummyMasterCtrlRes:21;
    }bits;
}PsuGroupControl;

typedef struct
{
    unsigned char           Quantity;
    unsigned char           RealQuantity;
    unsigned char           Member[MAX_GROUP_QUANTITY];         // record slave group index
    unsigned short          ParallelFlag[MAX_GROUP_QUANTITY];
}PsuGroupPartner;

typedef struct
{
    unsigned short          Voltage;                            // output voltage limit, unit: 0.1V
    unsigned short          Current;                            // output current limit, unit: 0.1A
    unsigned short          Power;                              // output power limit, unit: 0.1kw
}PsuGroupOutputValue;

typedef struct
{
    unsigned char           Index;
    unsigned char           Role;
    unsigned char           PreRole;
    unsigned char           Location;
    PsuGroupPartner         Partner;                            // record slave group information
    PsuGroupPartner         PossibleMember;                     // record possible slave group information
    unsigned char           TargetGroup;                        // target group index + 1
    unsigned char           ReservedTarget;                     // reserved target group index + 1
    unsigned char           SmoothDeratingTarget;               // group index + 1
    unsigned char           AlternateMaster;                    // alternate target group index + 1
    PsuGroupControl         GroupCtrl;
    unsigned short          ReAssignAvailableCurrent;           // group available current when reassign, unit: 0.1A
    unsigned short          ParallelCheck;
    unsigned char           ParallelConfig[MAX_GROUP_QUANTITY]; // group parallel relay setting
    unsigned short          GunLoading;                         // gun output loading, unit: 0.01%
    unsigned char           GunPsuQuantity;                     // record psu quantity at this gun
    unsigned char           ExtendQuantityLimit;                // limit of extend psu group quantity
    float                   MaxOutputRatio;                     // max output ratio (gun psu quantity / total psu in using)
    float                   DiffPower_Capability;               // unit: 1kW, different power between output power and Capability power
    float                   DiffPower_Available;                // unit: 1kW, different power between output power and Available power
    float                   DiffPower_PhysicalLimit;            // unit: 1kW, different power between output power and PhysicalLimit power
    float                   DiffPower_ConfigLimit;              // unit: 1kW, different power between output power and config power
}PsuGroupCollectionData;

typedef struct
{
    unsigned short          GTargetVoltage;                     // group target voltage config, unit: 0.1V
    unsigned short          GTargetCurrent;                     // group target current config, unit: 0.1A
    unsigned short          OutputLoading;                      // group output loading, unit: 0.01%
}GroupOutputConfigInfo;

typedef union
{
    unsigned short CtrlValue;
    struct
    {
        unsigned short Output_N:1;                              // 0: set Output_N off,         1: set Output_N on
        unsigned short Output_P:1;                              // 0: set Output_P off,         1: set Output_P on
        unsigned short res:14;
    }bits;
}PsuGroupOutputRelay;

typedef union
{
    unsigned short CtrlValue;
    struct
    {
        unsigned short Location_1_2:1;                          // 0: set parallel off,         1: set parallel on
        unsigned short Location_2_3:1;                          // 0: set parallel off,         1: set parallel on
        unsigned short Location_3_4:1;                          // 0: set parallel off,         1: set parallel on
        unsigned short Location_4_1:1;                          // 0: set parallel off,         1: set parallel on
        unsigned short Location_4_2:1;                          // 0: set parallel off,         1: set parallel on
        unsigned short Location_3_1:1;                          // 0: set parallel off,         1: set parallel on
        unsigned short res:10;
    }bits;
}PsuGroupParallelRelay;

typedef struct
{
    byte                    Location[MAX_GROUP_QUANTITY];
    byte                    Layout[MAX_GROUP_QUANTITY];
    PsuGroupCollectionData  GroupCollection[MAX_GROUP_QUANTITY];
    GroupOutputConfigInfo   GroupOutput[MAX_GROUP_QUANTITY];                // for individual group command
    GroupOutputConfigInfo   TotalGroupOutput[MAX_GROUP_QUANTITY];           // for total group command
    PsuGroupOutputRelay     OutputRelayConfig[MAX_GUN_QUANTITY];
    PsuGroupOutputRelay     OutputRelayConfirmed[MAX_GUN_QUANTITY];
    PsuGroupParallelRelay   ParallelRelayConfig;
    PsuGroupParallelRelay   ParallelRelayConfirmed;
    PsuStatusInfo           GroupPsuStatus_OR[MAX_GROUP_QUANTITY];
    PsuStatusInfo           GroupPsuStatus_AND[MAX_GROUP_QUANTITY];
}PsuGroupingInfoData;
// ************************************************************************************************* //

typedef enum
{
    _SCONN_FREE                 = 0,
    _SCONN_WAIT                 = 1,
    _SCONN_MATCHED              = 2,
}_SOCKET_CONN_STATUS;

typedef enum
{
    _DeviceStatus_DisConnect        = 0x00,         // _DS_None                 , slave cabinet in re-connection
    _DeviceStatus_Identification    = 0x01,         // _DS_Identification       , slave cabinet in identification
    _DeviceStatus_Idle              = 0x02,         // _DS_Idle                 , slave cabinet in idle
    _DeviceStatus_Alarm             = 0x03,         // _DS_Alarm                , slave cabinet in alarm
    _DeviceStatus_Charging          = 0x04,         // _DS_Charging             , no use in slave cabinet
    _DeviceStatus_Timeout           = 0x05,         // _DS_Timeout              , no use in slave cabinet
    _DeviceStatus_RetryWait         = 0x06,
}_DEVICE_STATUS;

typedef enum
{
    _Parallel_None              = 0,
    _Parallel_Wait              = 1,                // ac contactor off, 3s
    _Parallel_Working           = 2,                // ac contactor on and start re-initial psu
    _Parallel_Done              = 3,                // re-initial psu done
}_PARALLEL_STATUS;

typedef struct
{
    unsigned char Status;                                       // 0: free, 1: WaitModelName, 2: DispenserMatched
    unsigned char DeviceIndex;                                  // record device index
    unsigned int  IpAddress;                                    // record device ip address
    unsigned char DuplicateIp;                                  // 0: unique ip,    1: duplicate ip
    unsigned char res;
}SocketConnInfoData;

typedef struct
{
    unsigned char   LocalStatus;                // 0: None, 1: Identification, 2: Idle, 3: Alarm, 4: Charging, 5: _DS_Timeout
    unsigned char   SlaveID;
    unsigned char   ModelName[64];              //charger model name
    unsigned char   SerialNumber[64];           //charger system serial number
    unsigned char   SystemId[128];              //charger system ID

    unsigned char   CsuBootLoadFwRev[32];       //CSU board bootloader firmware version
    unsigned char   CsuKernelFwRev[32];         //CSU board OS kernel firmware version
    unsigned char   CsuRootFsFwRev[32];         //CSU board root file system firmware version
    unsigned char   CsuPrimFwRev[32];           //CSU board root file system firmware version
    unsigned char   LcmFwRev[32];               //LCM module firmware version
    unsigned char   PsuPrimFwRev[32];           //PSU primary firmware version
    unsigned char   PsuSecFwRev[32];            //PSU secondary firmware version
    unsigned char   FanModuleFwRev[32];         //Fan  module firmware version
    unsigned char   RelayModuleFwRev[32];       //Relay control  module firmware version
    unsigned char   TelcomModemFwRev[32];       //the 3G/4G modem firmware version
    unsigned char   LedModuleFwRev[32];         //LED control module firmware version
    unsigned char   Connector1FwRev[32];        //Connector1 module firmware version
    unsigned char   Connector2FwRev[32];        //Connector2 module firmware version

    unsigned char   AcContactorSetting;                         // 0: OFF, 1: ON        Master -> Slave
    unsigned char   AcContactorState;                           // 0: OFF, 1: ON        Slave  -> Master
    unsigned char   OutputRelaySetting[MAX_GROUP_QUANTITY];     // 0: OFF, 1: ON        Master -> Slave
    unsigned char   GunOutputRelayState[MAX_GROUP_QUANTITY];    // 0: OFF, 1: ON        Slave  -> Master
    unsigned char   ParallelRelaySetting[MAX_GROUP_QUANTITY];   // 0: OFF, 1: ON        Master -> Slave
    unsigned char   ParallelRelayState[MAX_GROUP_QUANTITY];     // 0: OFF, 1: ON        Slave  -> Master
    unsigned char   UpdateRequest;                              // 0: no effect,        1: need to update
    unsigned char   res;
    char            FwFileName[128];
    unsigned char   SocketChannel;                              // record socket index
    unsigned char   IpDuplicatedFlag;                           // 0: no effect,        1: ip is duplicated
    unsigned char   ParallelRequest;                            // 0: no effect,        1: parallel request
    unsigned char   ParallelConfirm;                            // 0: no effect,        1: parallel confirm
    unsigned short  ParallelPower;                              // parallel power, unit: 0.1kw
}SlaveCabinetInfoData;

typedef struct
{
    unsigned char           ParallelStatus;                     // 0: parallel none, 1: wait, 2: in paralleling, 3: parallel done
    unsigned char           ParallelCabinetQuantity;            // record max dispenser quantity
    unsigned char           PresentParallelCabinetQuantity;     // present slave cabinet quantity
    unsigned char           res;
    SlaveCabinetInfoData    PCabinet[MAX_SLAVE_CABINET_QUANTITY];
    unsigned char           PCUpdateState[MAX_SLAVE_CABINET_QUANTITY];  // 0: Not in Update,    1: Updating,    2: Updated
    unsigned short          TotalParallelPower;                 // max total parallel power, unit: 0.1kw
}ParallelCabinetInfoData;

typedef struct
{
    unsigned char               SCabinetStatus;
    unsigned char               SCabinetID;
    unsigned char               SOutputRelay[MAX_GROUP_QUANTITY];       // parallel cabinet output relay state
    unsigned char               SParallelRelay[MAX_GROUP_QUANTITY];     // parallel cabinet parallel relay state
    unsigned char               SAcContactor;                           // slave cabinet ac contactor state
    unsigned char               NeedUpgrade;                            // 1: Need Upgrade, 2: No Update
    unsigned char               UpgradeState;                           // 0: Not in Update,    1: Updating,    2: Updated
    unsigned char               res;
    char                        FwFileName[128];
}SlaveCabinetControl;
// ************************************************************************************************* //
#define LCM_REQ_REMOTE_START_NO_ID          0x00000001

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        // cabinet -> connector
        unsigned int RemoteStartNoID:1;                 // 0: no request,  1: lcm page change to RemoteStartNoID
        unsigned int res:31;
    }bits;
}ConnectorPageControl;

#define MISC_DISP_CONNECTION_TIMEOUT        0x00000001
#define MISC_DISP_DEFAULT_PRICE             0x00000002
#define MISC_DISP_CURRENCY                  0x00000004
#define MISC_DISP_BACKEND_STATUS            0x00000008
#define MISC_DISP_ETHERNET_STATUS           0x00000010
#define MISC_DISP_WIFI_STATUS               0x00000020
#define MISC_DISP_TELCOM_MODEM_STATUS       0x00000040
#define MISC_DISP_BILLING_STATUS            0x00000080
#define MISC_DISP_STOP_BUTTON_STATUS        0x00000100
#define MISC_DISP_AUTH_MODE_CONFIG          0x00000200
#define MISC_DISP_EVCCID_CONFIG             0x00000400
#define MISC_DISP_LED_INTENSITY             0x00000800
#define MISC_DISP_HARDWARE_REBOOT           0x00001000
#define MISC_DISP_SOFTWARE_RESET            0x00002000
#define MISC_DISP_CHANGE_LCM_INFO           0x00004000
#define MISC_DISP_STATION_INFO              0x00008000
#define MISC_DISP_TIME_OFFSET               0x00010000
#define MISC_DISP_DEFAULT_PRICE_STRING      0x00020000
#define MISC_DISP_PARKING_PRICE             0x00040000
#define MISC_DISP_RFID_CARD_ENDIAN          0x00080000
#define MISC_DISP_RFID_ENABLE               0x00100000

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        // cabinet -> dispenser
        unsigned int ConnectionTimeout:1;               // msic: 0x0001,    0: no request,  1: connection timeout request
        unsigned int DefaultPrice:1;                    // msic: 0x0003,    0: no request,  1: default price request
        unsigned int Currency:1;                        // msic: 0x0004,    0: no request,  1: currency request
        unsigned int BackendStatus:1;                   // msic: 0x0006,    0: no request,  1: backend status request
        unsigned int EthernetStatus:1;                  // msic: 0x0007,    0: no request,  1: ethernet status request
        unsigned int WiFiStatus:1;                      // msic: 0x0008,    0: no request,  1: wifi status request
        unsigned int TelcomModemStatus:1;               // msic: 0x0009,    0: no request,  1: telcom modem status request
        unsigned int BillingStatus:1;                   // msic: 0x000A,    0: no request,  1: billing status request
        unsigned int StopButtonStatus:1;                // msic: 0x000B,    0: no request,  1: stop button status request
        unsigned int AuthModeConfig:1;                  // msic: 0x000C,    0: no request,  1: auth mode config request
        unsigned int EVCCIDConfig:1;                    // msic: 0x000D,    0: no request,  1: EVCCID config request
        unsigned int LEDIntensity:1;                    // msic: 0x000E,    0: no request,  1: led intensity request
        unsigned int HardwareReboot:1;                  // msic: 0x0101,    0: no request,  1: hardware reboot request
        unsigned int SoftwareReset:1;                   // msic: 0x0102,    0: no request,  1: software reset request
        unsigned int ChangeLcmInfo:1;                   // msic: 0x0107,    0: no request,  1: change lcm info request
        unsigned int ChargerStationInfo:1;              // msic: 0x0109,    0: no request,  1: charger station info request
        unsigned int TimeOffset:1;                      // msic: 0x0010,    0: no request,  1: time offset request
        unsigned int DefaultPriceString:1;              // msic: 0x0010,    0: no request,  1: default price string request
        unsigned int ParkingPrice:1;                    // msic: 0x0011,    0: no request,  1: parking price request
        unsigned int RFIDCardEndian:1;                  // msic: 0x0012,    0: no request,  1: RFID card endian request
        unsigned int RFIDEnable:1;                      // msic: 0x0013,    0: no request,  1: RFID enable request
        unsigned int res:11;
    }bits;
}DispenserMiscControl;

#define MISC_CONN_AVAILABILITY              0x00000001
#define MISC_CONN_ACCOUNT_BALANCE           0x00000002
#define MISC_CONN_REMOTE_START              0x00000004
#define MISC_CONN_REMOTE_STOP               0x00000008
#define MISC_CONN_UNLOCK                    0x00000010
#define MISC_CONN_RESERVATION               0x00000020
#define MISC_CONN_QRCODE_INFO               0x00000040
#define MISC_CONN_FINAL_COST                0x00000080
#define MISC_CONN_LINE_STATUS               0x00000100
#define MISC_CONN_USER_PRICE_STRING         0x00000200
#define MISC_CONN_RECEIPT                   0x00000400
#define MISC_CONN_CHARGING_BILL             0x00000800
#define MISC_CONN_PARKING_STATUS            0x00001000

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        // cabinet -> connector
        unsigned int Availability:1;                    // msic: 0x0002,    0: no request,  1: availability request
        unsigned int AccountBalance:1;                  // msic: 0x0005,    0: no request,  1: account balance request
        unsigned int RemoteStart:1;                     // msic: 0x0103,    0: no request,  1: remote start request
        unsigned int RemoteStop:1;                      // msic: 0x0104,    0: no request,  1: remote stop request
        unsigned int Unlock:1;                          // msic: 0x0105,    0: no request,  1: unlock request
        unsigned int Reservation:1;                     // msic: 0x0106,    0: no request,  1: reservation request
        unsigned int QRCodeRequest:1;                   // msic: 0x0108,    0: no request,  1: QR Code request
        unsigned int FinalCostRequest:1;                // msic: 0x010A,    0: no request,  1: Final Cost request
        unsigned int LineStatusRequest:1;               // msic: 0x010B,    0: no request,  1: Line Status request
        unsigned int UserPriceStringRequest:1;          // msic: 0x010D,    0: no request,  1: User Price String request
        unsigned int ReceiptRequest:1;                  // msic: 0x010E,    0: no request,  1: Receipt request
        unsigned int ChargingBillRequest:1;             // msic: 0x010F,    0: no request,  1: charging bill request
        unsigned int ParkingStatusRequest:1;            // msic: 0x0110,    0: no request,  1: parking status request
        unsigned int res:19;
    }bits;
}ConnectorMiscControl;

typedef struct
{
    unsigned int ConnectionTimeout;             // unit: 1s
    float        DefaultPrice;                  // unit: 1 (dollar/kWh)
    unsigned int Currency;                      // currency index
    unsigned int BackendStatus;                 // 0: disable, 1: connected, 2: disconnected
    unsigned int EthernetStatus;                // 0: disable, 1: connected, 2: disconnected
    unsigned int WiFiStatus;                    // 0: disable, 1: connected, 2: disconnected
    unsigned int TelcomModemStatus;             // 0: disable, 1: connected, 2: disconnected
    unsigned int BillingStatus;                 // 0: disable, 1: enable
    unsigned int StopChargingButton;            // 0: disable, 1: enable
    unsigned int HardwareReboot;                // 1: HardwareReboot, Other value: no effect
    unsigned int SoftwareRestart;               // 1: SoftwareRestart, Other value: no effect
    unsigned int AuthModeConfig;                // 0: enable,  1: disable
    unsigned int EVCCIDConfig;                  // 0: disable, 1: enable
    unsigned int LEDIntensity;                  // LED intensity, 0: Darkest  1: Medium   2: Brightest
    int          TimeOffset;                    // time offset value, unit: 1 minute
    float        ParkingPrice;                  // unit: 1 (dollar/minute)
    unsigned int RfidEndian;                    // 0: little endian,  1: big endian
    unsigned int RfidReaderEnable;              // 0: disable,  1: enable
}MiscCommandValue;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        // dispenser -> cabinet
        unsigned int ChargingCancel:1;                  // cmd: 0x0001,     0: no request,  1: charging cancel request
        unsigned int ParkingFeeRequest:1;               // cmd: 0x0002,     0: no request,  1: parking fee request
        unsigned int res:30;
    }bits;
}ConnectorActionFlag;

typedef union
{
    unsigned int CtrlValue[32];
    struct
    {
        // dispenser -> cabinet
        unsigned int Refund;                            // 1: request,      other: no effect
        unsigned int RefundCancel;                      // 1: cancel,       other: no effect
        unsigned int InvoiceIndex;                      // invoice index, start from 1 ~
        unsigned int Res[29];
    }bits;
}ConnectorActionValue;

typedef struct
{
    unsigned char ConnectorId;              // Connector Id
    unsigned char DeductReq;                // 0: no request,       1: deduct request
    unsigned char ReaderStatusReq;          // 0: no request,       1: reader status request
    int TransactionId;
    unsigned char creditNo[20];
    unsigned char DeductResult;             // DeductResult,        0: Fail, 1: Pass
    unsigned char IsDonateInvoice;          // IsDonateInvoice,     0: Do not donate, 1: Donate
    int DeductAmount;                       // DeductAmount,        unit = 0.01 dollar
    char ApprovalNumber[9];                 // ApprovalNumber
    char VemData[64];                       // Vem Data
    char Sn[36];
}DeductResultInfoData;

typedef struct
{
    ConnectorActionFlag Flag;
    ConnectorActionValue ActionValue;
}ConnectorActionRequest;

#define STR_WEATHER_NONE            "None"
#define STR_WEATHER_SUNNY           "Sunny"
#define STR_WEATHER_CLOUDY          "Cloudy"
#define STR_WEATHER_RAIN            "Rain"
#define STR_WEATHER_THUNDERSTORM    "ThunderStorm"
#define STR_WEATHER_SNOW            "Snow"
#define STR_WEATHER_MIST            "Mist"

enum _WEATHER_INFO
{
    _WEATHER_None               = 0,
    _WEATHER_Sunny              = 1,
    _WEATHER_Cloudy             = 2,
    _WEATHER_Rain               = 3,
    _WEATHER_ThunderStorm       = 4,
    _WEATHER_Snow               = 5,
    _WEATHER_Mist               = 6,
};

typedef struct
{
    int StationID;
    char StationName[64];
    char QRCode[MAX_GROUP_QUANTITY][128];
    int WeatherID;
    float Temperature;
}StationInfoData;

typedef struct
{
    int StatusCode[MAX_GROUP_QUANTITY];
}LineApiStatusInfo;

typedef struct
{
    int TransactionId;                      // connector TransactionId
    float UserPrice;                        // connector user's user price, unit: 1 (dollar / kWh)
    float TotalCost;                        // connector user's total cost, unit: 1 dollar
    float AccountBalance;                   // connector user's account balance, unit: 1 dollar
    float CostDiscount;                     // connector user's account balance, unit: 1 dollar
}TransactionInfoData;

enum DeductResult
{
    _Deduct_PreAuth_Fail    = 0x0,          // pre-auth fail
    _Deduct_PreAuth_Pass    = 0x1,          // pre-auth pass
    _Deduct_PreAuth_Cancel  = 0x2,          // pre-auth cancel
    _Deduct_PreAuth         = 0x3,          // pre-auth
    _Deduct_Sale_Fail       = 0x4,          // sale fail
    _Deduct_Sale_Pass       = 0x5,          // sale pass
};

#define STR_DEDUCT_FAIL             "Deduct Fail"
#define STR_DEDUCT_PASS             "Deduct Pass"
#define STR_DEDUCT_CANCEL           "PreAuth Cancel"
#define STR_DEDUCT_PREAUTH          "PreAuth OK"
#define STR_SALE_FAIL               "Sale Fail"
#define STR_SALE_PASS               "Sale Pass"

typedef struct
{
    float CurrentRate;
    float TimeOfDayPricing[24];
    char DefaultPriceString[512];                       // default price string
    char DispenserPriceString[MAX_GUN_QUANTITY][512];   // dispenser user price string
    char UserPriceString[MAX_GUN_QUANTITY][512];        // connector user price string
    char ReceiptUrl[MAX_GUN_QUANTITY][512];             // connector receipt url
}PriceReceiptInfoData;

typedef enum
{
    _Type_Central           = 0x0,
    _Type_eMAID             = 0x1,
    _Type_ISO14443          = 0x2,
    _Type_ISO15693          = 0x3,
    _Type_KeyCode           = 0x4,
    _Type_Local             = 0x5,
    _Type_MacAddress        = 0x6,
    _Type_NoAuthorization   = 0x7,
}UserIdType;

#define STR_ID_TYPE_CENTRAL             "Central"
#define STR_ID_TYPE_EMAID               "eMAID"
#define STR_ID_TYPE_ISO14443            "ISO14443"
#define STR_ID_TYPE_ISO15693            "ISO15693"
#define STR_ID_TYPE_KEYCODE             "KeyCode"
#define STR_ID_TYPE_LOCAL               "Local"
#define STR_ID_TYPE_MAC_ADDRESS         "MacAddress"
#define STR_ID_TYPE_NO_AUTHORIZATION    "NoAuthorization"

typedef struct
{
    float LocalConsumption;                             // power consumption store in cabinet
    float GunConsumption;                               // power consumption store in dispenser
}MeterValueInfoData;

typedef struct
{
    char StartCharging[32];                             // start charging timestamp
    char StopCharging[32];                              // stop charging timestamp
}TimestampInfoData;

typedef struct
{
    char MainVersion[32];
    char SubVersion[32];
}SysMiscInfoData;

typedef struct
{
    unsigned char Status;
}ConnectorConfigAndStatus;

#define MAX_GUN_ERROR_QUANTITY          5

typedef union
{
    unsigned int ErrorValue;
    struct
    {
        unsigned int PsuGroupNoResource:1;              // 0: no effect,    1: psu group all alarm or fault >> group no resource
        unsigned int ParallelRelayWelding:1;            // 0: no effect,    1: Welding
        unsigned int ParallelRelayDrivingFault:1;       // 0: no effect,    1: DrivingFault
        unsigned int OutputRelayWelding:1;              // 0: no effect,    1: Welding
        unsigned int OutputRelayDrivingFault:1;         // 0: no effect,    1: DrivingFault
        unsigned int res:27;
    }bits;
}GunErrorFlag;

typedef struct
{
    GunErrorFlag ErrFlag;
    char GunAlarmCode[7];
}GunError;

typedef struct
{
    int Offline_MaxChargingPower;                       // unit: W, offline max charging power, received from backend
    int GunOfflineMaxPower[MAX_GUN_QUANTITY];           // unit: W, calculate from Offline_MaxChargingPower

    int GunMaxProfilePower[MAX_GUN_QUANTITY];           // unit: W, calculate from MaxChargingProfilePower
    int GunMaxProfileCurrent[MAX_GUN_QUANTITY];         // unit: 0.1A, Calculate from MaxChargingProfilePower

    int GunAbsoluteMaxPower[MAX_GUN_QUANTITY];          // unit: W
    int GunAbsoluteMaxVoltage[MAX_GUN_QUANTITY];        // unit: 0.1V
    int GunAbsoluteMaxCurrent[MAX_GUN_QUANTITY];        // unit: 0.1A

    int GunOtpMaxPower[MAX_GUN_QUANTITY];               // unit: W
    int GunOtpMaxCurrent[MAX_GUN_QUANTITY];             // unit: 0.1A

    int GunDynamicMaxPower[MAX_GUN_QUANTITY];           // unit: W
    int GunDynamicMaxCurrent[MAX_GUN_QUANTITY];         // unit: 0.1A

    int GunManualLimitPower[MAX_GUN_QUANTITY];          // unit: W
    int GunManualLimitVoltage[MAX_GUN_QUANTITY];        // unit: 0.1V
    int GunManualLimitCurrent[MAX_GUN_QUANTITY];        // unit: 0.1A

    // final output limitation
    int GunLimitPower[MAX_GUN_QUANTITY];                // unit: 0.1kW
    int GunLimitVoltage[MAX_GUN_QUANTITY];              // unit: 0.1V
    int GunLimitCurrent[MAX_GUN_QUANTITY];              // unit: 0.1A

    int IndividualLimit[MAX_GUN_QUANTITY];
}OutputLimitation;

typedef enum
{
    _BillStatus_Idle            = 0x00,                 // no final cost received
    _BillStatus_MiscReq         = 0x01,                 // receive final cost and set final cost misc command
    _BillStatus_WaitMiscClean   = 0x02,                 // wait for dispenser to read misc command
    _BillStatus_MiscClean       = 0x03,                 // final cost misc command has update to dispenser, timeout: 3s
    _BillStatus_UpdateDone      = 0x04,                 // dispenser read final cost packet
    _BillStatus_Completed       = 0x05,                 // stay this status 3s
    _BillStatus_Fail            = 0x06,                 // clean bill info and return to idle
    _BillStatus_End             = 0x07,                 // clean bill info and return to idle
}BillStatus;

#define BILL_SATAUS_UNDISPOSED                          -1
#define BILL_SATAUS_UPDATED_FAIL                        0
#define BILL_SATAUS_UPDATED_OK                          1
#define BILL_SATAUS_Bypass_OK                           2

typedef struct
{
    float TotalCost;                                    // connector user's total cost, unit: 1 dollar
    float AccountBalance;                               // connector user's account balance, unit: 1 dollar
    float CostDiscount;                                 // connector user's Discount or couponPoint, unit: 1 point
    float EnergyCost;                                   // connector user's energy cost, unit: 1 dollar
    float ParkingFee;                                   // connector user's parking fee, unit: 1 dollar
    float RemainAmount;                                 // connector user's remain amount, unit: 1 dollar
    float ConnectionFee;                                // connector user's connection fee, unit: 1 dollar
    float SessionFee;                                   // connector user's session fee, unit: 1 dollar

}FeeInfoData;

typedef struct
{
    unsigned char BillStatus;                           // 0: idle, 1: misc request, 2 misc clean, 3: bill update done
    unsigned char PreStatus;                            // 0: idle, 1: misc request, 2 misc clean, 3: bill update done
    unsigned short TryCnt;
    int TxId;
    FeeInfoData FeeInfo;
    char Receipt[512];
}ChargingBillInfoData;

typedef enum
{
    _ParkingAction_None             = 0x00,                 // no action
    _ParkingAction_DisplayButton    = 0x01,                 // Display Occupancy Fee button
    _ParkingAction_CancelOccupancy  = 0x02,                 // Cancel Occupancy Fee button
    _ParkingAction_PaidOnlineOK     = 0x03,                 // Successed to pay occupancy fee with online method, then close Occupancy Fee button
    _ParkingAction_PaidOnlineFail   = 0x04,                 // Failed to pay occupancy fee with online method
}OccupancyAction;

#define STR_OCCUPANCY_ACT_NONE      "NoAction"
#define STR_OCCUPANCY_ACT_DISPLAY   "DisplayButton"
#define STR_OCCUPANCY_ACT_CANCEL    "CancelOccupancy"
#define STR_OCCUPANCY_ACT_PAID_OK   "PaidOnlineOK"
#define STR_OCCUPANCY_ACT_PAID_NG   "PaidOnlineFail"

typedef enum
{
    _Parking_NoOccupancy        = 0x00,                 // no occupancy
    _Parking_SyncOccupancy      = 0x01,                 // sync occupancy with dispenser
    _Parking_Occupied           = 0x02,                 // occupancy start
    _Parking_RequestFee         = 0x03,                 // user request occupancy fee
    _Parking_WaitToPay          = 0x04,                 // wait for user to pay the fee
    _Parking_PaidOnlineOK       = 0x05,                 // user to paid success via online method
    _Parking_PaidOnlineFail     = 0x06,                 // user to paid fail via online method
}OccupancyStatus;

#define STR_NO_OCCUPANCY            "NoOccupancy"
#define STR_SYNC_OCCUPANCY          "SyncOccupancy"
#define STR_OCCUPIED                "Occupied"
#define STR_REQUEST_FEE             "RequestFee"
#define STR_WAIT_TO_PAY             "WaitToPay"
#define STR_PAID_ONLINE_OK          "PaidOK"
#define STR_PAID_ONLINE_FAIL        "PaidFail"

#define STR_NOTIFY_NONE             "Notify None"
#define STR_GET_OCCUPANCY_FEE       "GetOccupancyFee"
#define STR_CANCEL_OCCUPANCY_DEDUCT "CancelDeduction"
#define STR_CANCEL_OCCUPANCY_FEE    "CancelOccupancyFee"

typedef enum
{
    _Notify_None                    = 0x00,             // act: None
    _Notify_GetOccupancyFee         = 0x01,             // act: Get OccupancyFee
    _Notify_CancelLocalDeduction    = 0x02,             // act: Cancel Local Deduction
    _Notify_CancelOccupancyFee      = 0x03,             // act: Cancel Occupancy Fee
}NotifyOccupancyFeeAct;

typedef struct
{
    unsigned char MiscStatus;                           // 0: idle, 1: misc request, 2 misc clean, 3: bill update done
    unsigned char PreStatus;                            // 0: idle, 1: misc request, 2 misc clean, 3: bill update done
    unsigned short TryCnt;
}MiscRequestStatus;

typedef struct
{
    char StartTime[32];
    unsigned int Duration;
    float Fee;
    char Sn[37];
    char res;
}OccupancyBillInfo;

typedef struct
{
    float Fee;
    char Sn[37];
    char res;

    char creditNo[21];
    char ApprovalNumber[10];                // ApprovalNumber
    char VemData[65];                       // Vem Data
}OccupancyDeductInfo;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int DeductReq:1;                       // 0: no request,               1: deduct request
        unsigned int KeepCounting:1;                    // 0: no effect,                1: occupancy keep counting
        unsigned int ForceCancel:1;                     // 0: no effect,                1: force cancel occupancy fee because of charging status
        unsigned int SelfReq:1;                         // 0: no request,               1: self request
        unsigned int res:28;
    }bits;
}OccupancyReqFlag;

typedef struct
{
    unsigned char Status;                               // 0: NoOccupancy, 1: Occupied, 2: RequestFee, 3: WaitToPay
    unsigned char PreStatus;                            // 0: NoOccupancy, 1: Occupied, 2: RequestFee, 3: WaitToPay
    MiscRequestStatus ButtonReqStatus;
    MiscRequestStatus BillReqStatus;
    unsigned char ActionId;
    unsigned char res;
    OccupancyReqFlag OccupancyReq;                      // 0: no request, 1: deduct request
    OccupancyBillInfo OccupancyBill;
    OccupancyDeductInfo OccupancyDeduct;
}OccupancyInfoData;

typedef struct
{
    ChargingBillInfoData DispBill[MAX_DISPENSER_QUANTITY];
    ChargingBillInfoData GunBill[MAX_GUN_QUANTITY];
    OccupancyInfoData OccupancyInfo[MAX_GUN_QUANTITY];
}AllBillInfoData;

#define OCMF_SATAUS_INSERTED                            0
#define OCMF_SATAUS_UPDATED_OK                          1

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int OcmfReceived:1;                    // 0: no request,               1: ocmf info received
        unsigned int res:31;
    }bits;
}GunOcmfFlag;

typedef struct
{
    // ocmf file path: /mnt
    // ocmf file name: Gun_X_TxId_OCMF
    // X: Gun Id
    // TxId: Transaction Id
    char OcmfTxId[36];
    char PublicKey[200];
    GunOcmfFlag OcmfFlag;
}OCMFInfoData;

typedef union
{
    unsigned int CtrlValue;
    struct
    {
        unsigned int OcmfPending:1;                     // 0: no request,               1: exist pending ocmf
        unsigned int OcmfNeedUpload:1;                  // 0: no request,               1: ocmf need upload
        unsigned int OcmfUploading:1;                   // 0: no request,               1: ocmf is uploading
        unsigned int res:29;
    }bits;
}SysOcmfFlag;

typedef struct
{
    int SysOcmfIndex;
    char SysOcmfTxId[36];
    char SysOcmfPublicKey[200];
    char SysOcmfInfo[2048];
    SysOcmfFlag SysOcmfFlag;
    OCMFInfoData GunOcmf[MAX_GUN_QUANTITY];
}SysOCMFInfoData;
// ************************************************************************************************* //

typedef struct
{
    SysMiscInfoData SysMisc;
    SystemAuthInfoData AuthInfo;
    SysControl Control;
    PsuPositionInfoData PsuPosition;
    PsuGroupingInfoData PsuGrouping;
    SocketConnInfoData CabinetConnInfo[MAX_SLAVE_CABINET_QUANTITY];
    ParallelCabinetInfoData ParallelCabinet;
    SlaveCabinetControl SCabinetControl;
    ConnectorPageControl ConnectorPageReq[MAX_GROUP_QUANTITY];
    DispenserMiscControl DispenserMiscReq[MAX_GROUP_QUANTITY];
    ConnectorMiscControl ConnectorMiscReq[MAX_GROUP_QUANTITY];
    MiscCommandValue CabinetMiscValue;
    ConnectorActionRequest ConnectorActReq[MAX_GROUP_QUANTITY];
    StationInfoData StationInfo;
    TransactionInfoData UserTransaction[MAX_GROUP_QUANTITY];
    DeductResultInfoData DeductResultReq[MAX_GROUP_QUANTITY];
    DeductResultInfoData ReDeductReq;
    DeductResultInfoData ReaderStatus[MAX_GROUP_QUANTITY];
    LineApiStatusInfo LineApi;
    ConnectorConfigAndStatus Connector[MAX_GUN_QUANTITY];
    PriceReceiptInfoData PriceAndReceiptInfo;
    MeterValueInfoData MeterValue[MAX_GUN_QUANTITY];
    TimestampInfoData Timestamp[MAX_GUN_QUANTITY];
    GunError GunError[MAX_GUN_QUANTITY];
    OutputLimitation OutputLimit;
    AllBillInfoData AllBill;
    SysOCMFInfoData OcmfInfo;
}ChargerInfoData;

#endif /* CONFIG_H_ */