/*
 * @Author       : ChenJie
 * @Date         : 2021-10-14 09:27:15
 * @Version      : V3.0
 * @LastEditors  : ChenJie
 * @LastEditTime : 2021-10-29 16:23:13
 * @Description  : file content
 * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppFunc.h
 */
/****************************************************************************
 *
 * Copy right:   RL.Chen J and Zhen C
 * File name:    AppFunc.h
 * Description:  应用层函数调用文件
 * History:      2021-07-15
 * Version:      V3.0
 ****************************************************************************/
#include "hal_module_adapter.h"
#include "flash_ec616_rt.h"
#include "commontypedef.h"
#include "flash_ec616_rt.h"
#include "mem_map.h"
#include "AppConfig.h"
#include "ec_tcpip_api.h"
#include "AppSignal.h"
typedef struct _Fota_Type
{
    BOOL Fota_update_error;
    UINT32 Fota_All_Data_Len;
    UINT32 Fota_Current_Addres;
    UINT8 Fota_Recv_Data_Len;
    UINT8 Fota_Recv_Data[100];
    UINT32 Fota_Flash_Addres;
    UINT8 Fota_CRC;

} Fota_Type;
BOOL BattHeaterSwitch(UINT8 *heaterSwitch, UINT8 HeatForceControl);
BOOL uartBattInfoDecode(UINT8 *dataPtr);
BOOL UDSAskforDownLoadData();
BOOL UDSClearFotaDownloadRegion();
INT8 rentalEndDetectFunc(void);
static UINT8 bcc_chk_fota(UINT8 *data, UINT8 length);
static UINT8 BmsErrorDecode(UINT32 battWarningState);
static UINT8 Fota_crc_chk(UINT8 *data, UINT8 length);
static void setDefaultAppConfigData(void);
static void setDefaultAppDataInfo(void);
static void setDefaultBcuDataInfo(void);
UINT16 encryptionAlgorithm(UINT16 plainText);
UINT16 GetErrorNum(UINT16 *ErrorArray, UINT8 Errorlen);
UINT8 bcc_chk(UINT8 *data, UINT16 length);
UINT8 LookUpRTtable(UINT32 R_value);
UINT8 PutErrorNum(UINT16 *ErrorArray, UINT8 Errorlen, UINT16 ErrorNum);
UINT8 UDSNegtiveAnswer(UINT8 answerLen, UINT8 messageIndex, UINT32 negCode);
UINT8 UDSPositiveAnswer(UINT8 answerLen, UINT8 messageIndex, UINT32 posCode);
void BattLockFunc(void);
void BattWorkDelayFunc(UINT8 battWorkCurrentState);
void CANEncodeFunction(UINT32 ID, UINT8 *msgData);
void CanMsgTx1000ms(void);
void ErrorNumHandleFunc(void);
void ExpiryTimeCal(UINT8 *StartTimeArray, UINT16 rentalDays, UINT8 *ExpiryTimeArray);
void Fota_Func(UINT8 *DataPtr, INT32 connectId);
void LEDDisplay(void);
void LoadAppConfig(void);
void LoadAppData(void);
void LoadBcuData(void);
void relayControlFunc(UINT16 BuzzerPeriod, float DutyRatio);
void SaveAppConfig(void);
void SaveAppData(void);
void SaveBcuData(void);
void UDS_Service(CAN_Msg_Type *CanRxMsg);