#ifndef UWATER_FRAME_FUNC_REPLAY_SHENSHUI_H
#define	UWATER_FRAME_FUNC_REPLAY_SHENSHUI_H

#include "sys_config.h"
#ifdef PRODUCT_SS
//////////////////////////////////////////规约控制字/////////////////////////////////////////////////////////
/*NB新增通信规约*/
//深水读取历史数据
#define SS_READ_HIS_CTRL                        0x27     
#define SS_ACK_READ_HIS_CTRL                    0xa7
#define SS_READ_HIS_CTRL_ID0                    0x35
#define SS_READ_HIS_CTRL_ID1                    0xA0

#define QZ_READ_HIS_MONTH_CTRL_ID1              0x30 //月冻结数据
#define QZ_READ_HIS_DAILY_CTRL_ID1              0x31 //日冻结信息

//深水上传数据报文
#define SS_UPLOAD_CTRL                          0x67            
#define SS_ACK_UPLOAD_CTRL                      0xD6            
#define SS_UPLOAD_CTRL_ID0                      0x43          
#define SS_UPLOAD_CTRL_ID1                      0xA1           
#define SS_UPLOAD_CTRL_UDP_ID0                  0x31  //UDP上报数据数据标识
//短帧上报数据
#define SHORT_UPLOAD_CTRL                       0x9A           
#define SHORT_ACK_UPLOAD_CTRL                   0xEF            
#define SHORT_UPLOAD_CTRL_ID0                   0x02      
#define SHORT_UPLOAD_CTRL_ID1                   0x10     

//新补报规约上报数据
#define SUPP_UPLOAD_CTRL                       0x9B           
#define SUPP_ACK_UPLOAD_CTRL                   0xF1            
#define SUPP_UPLOAD_CTRL_ID0                   0x01      
#define SUPP_UPLOAD_CTRL_ID1                   0x10   

//深水登录帧
#define SS_SIGN_IN_CTRL                         0x8f          
#define SS_ACK_SIGN_IN_CTRL                     0xe8         
#define SS_SIGN_IN_CTRL_ID0                     0x55           
#define SS_SIGN_IN_CTRL_ID1                     0xa1              

//清除失败次数
#define SS_CLEAR_FAIL_TIMES_CTRL                0x94            
#define SS_ACK_CLEAR_FAIL_TIMES_CTRL            0xEC
#define SS_CLEAR_FAIL_TIMES_CTRL_DI0            0x59 
#define SS_CLEAR_FAIL_TIMES_CTRL_DI1            0xA1 

enum{
	SUPPLEMENT_DATA_FRAME_S0 = 0,
	SUPPLEMENT_DATA_FRAME_S1,
	SUPPLEMENT_DATA_FRAME_S2,
	SUPPLEMENT_DATA_FRAME_S3,
	SUPPLEMENT_DATA_FRAME_S4,
	SUPPLEMENT_DATA_FRAME_S5,
	SUPPLEMENT_DATA_FRAME_S6,
	SUPPLEMENT_DATA_FRAME_S7
};
#define SUPPLEMENT_DATA_MAX_NUM		19		//一帧补报数据里最多19条日冻结

typedef enum
{
	SS_StoreMsg0  = 0u,                
	SS_StoreMsg1  = 1u,    
	SS_StoreMsg2  = 2u,                
	SS_StoreMsg3  = 3u,
	SS_StoreMsg4  = 4u,                
	SS_StoreMsg5  = 5u,
	SS_StoreMsg6  = 6u,                
	SS_StoreMsg7  = 7u
}SS_StoreMsgType;

/***************************************长帧上报数据格式*********************/
#define PACK_NUM_GPRS                            155 //周期上报部分数据长度
#define PACK_NUM_GPRS_INTEN                      199 //24小时的30min间隔流量数据长度,48*4+7
#define PACK_NUM_GPRS_TOTAL       (PACK_NUM_GPRS+PACK_NUM_GPRS_INTEN)    //周期上报的数据总长度
#define CURRENT_DATA_INFO_LEN  36
#define STEP_FLOW_START_ADDR   (0+CURRENT_DATA_INFO_LEN)
/**************************规约应答相关函数**********************************/
u8 up_deal_code_ShenShui(void);
u8 crack_frame_ShenShui(u16 frame_lenth,u8 *frame_buffer);
void Frame_ResetDealState_ShenShui(void);
void Frame_ack_ShenShui(u8* p_send_buf, u16* p_send_len);
/**************************上报相关函数***************************************/
#define PERIOD_DATA_NUM  32 //周期数据记录总报数

void GetUploadDataResetState_SS(void);
u8 GetUploadDataCheckIdle_SS(void);
u8 GetUploadDataCheckTask_SS(void);
void GetUploadDataMachine_SS(u8 data_step, u8* p_send_buf, u16* p_send_len);
/**************************存储相关函数***************************************/
void DataStoreInit(void);
void DataStoreMachine(void);
u8 DataStoreIfIdle(void);
/*****************************************************************************/
#define MAIN_CONNECT_TYPE      NBIOT_CONNECT_COAP
#define MAIN_SEND_TYPE         SEND_TYPE_COAP
#define SLAVE_CONNECT_TYPE     NBIOT_CONNECT_UDP1
#define SLAVE_SEND_TYPE        SEND_TYPE_UDP1
//主上报10秒，副上报5秒
#define COAP_UPLOAD_WAIT_ACK_TIME  100 //10秒   
#define UDP_UPLOAD_WAIT_ACK_TIME   50 
#define NB_ONLINE_KEEP_TIME  50

#endif

#endif	


