/*
 * @file: 
 * @Author: Lida
 * @Date: 2022-11-30 09:43:13
 * @LastEditors: Lida
 * @LastEditTime: 2023-03-22 09:33:08
 */


/*
 * @Description: 云模块-svc层
 * @Author: yangsw
 * @Date: 2021-05-21 16:27:42
 * @LastEditTime: 2022-06-06 11:40:13
 * @LastEditors: yangsw
 * @Reference: 
 */
#ifndef H_SVC_CLOUD_H
#define H_SVC_CLOUD_H

#include "../../com/svc/svc_com.h"


/*失败重发间隔，单位：s*/
#define CLOUD_RESEND_CYCLE  20     
/*失败重发次数*/
#define CLOUD_RESEND_TIMES  3

typedef enum{
    E_Cloud_Event_No=0,
    E_Cloud_Event_Rsp_Set=0x0001,
    E_Cloud_Event_Upload=0x0002,    
    E_Cloud_Event_Rsp_Info=0x0004,
    E_Cloud_Event_Upload_Historical=0x0008,
    E_Cloud_Event_Rsp_Historical=0x0010,
    E_Cloud_Event_Req_Ota_Data=0x0020,
    E_Cloud_Event_Req_Ota_Data_Large=0x0004,    
    E_Cloud_Event_All=0x00FF
}E_Cloud_Event;

typedef struct {
    /*上一次上报成功的时间戳*/
    gw_u32  u32LastUploadTime;   
    /*重发时间计时*/
    gw_u16  resend_time_cnt;
    /*重发计数*/
    gw_u8   resend_cnt;
    /*发送时间计时*/
    //gw_u16  send_time_cnt;
    /*应答失败计数*/
    //gw_u8   rsp_fail_cnt;
    /*保持网络活跃时间*/
    gw_u8   u8KeepAliveTime;
}S_Cloud_Manage;


typedef struct{   
    /*上报事件*/
    gw_u16           cloud_event;                     
    /*正在处理的上报事件*/
    E_Cloud_Event    e_cloud_sending_event;   
    /*管理相关数据*/
    S_Cloud_Manage   s_manage;
}S_Cloud;
void Svc_Cloud_Reset_Manage_Send_Time(void);
void Svc_Cloud_Init(void);
void Svc_Cloud_Resend_Clear(void);
void Svc_Cloud_Resend_Reset(void);	
void Svc_Cloud_Resend_Check(void);
E_Result_Check Svc_Cloud_Event_Fail_Check(void);
void Svc_Cloud_Post_Event(E_Cloud_Event cloud_event);
void Svc_Cloud_Lock_Event(E_Cloud_Event cloud_event);
void Svc_Cloud_Clear_Event(E_Cloud_Event cloud_event);
void Svc_Cloud_Unlock_All_Event(void);
gw_u16 Svc_Cloud_Get_Event(void);
gw_u16 Svc_Cloud_Get_Sending_Event(void);
E_Cloud_Event Svc_Cloud_Get_Pending_Event(void);
E_Result_Check Svc_Cloud_Event_Is_Changed(E_Cloud_Event e_event);
void Svc_Cloud_Set_Keep_Alive_Time(gw_u8 u8Time);
void Svc_Cloud_Timer_Callback(void);
gw_u8 Svc_Cloud_Time_Is_Calibrate(void);
void Svc_Cloud_Time_Calibrate(gw_u32 u32Time);
void Svc_Cloud_Time_Set_Calibrate(void);
void Svc_Cloud_Check_Timing_Event(void);
gw_u8 Svc_Cloud_Wait_Cmd(void);
E_Result_Check Svc_Cloud_Is_Busy(void);
#endif