#ifndef _NB_UPLOAD_MONITOR_H_
#define	_NB_UPLOAD_MONITOR_H_

#include "sys_config.h"
#if UPLOAD_MODE_1
#include "type.h"
#include "UWater_rtcc_driver.h"
#pragma pack(1) //1字节对齐

//等待下行数据时间
#define NB_WAIT_TIME_5S   50  //50*100
#define NB_WAIT_TIME_10S  100 //100*100

//时间秒数
#define HOUR_TO_SECOND      3600
#define MINITE_TO_SECOND    60

//表计设计寿命
#define HOURS_OF_7YEARS     61320   //7年使用寿命转成小时

//电池满电可用电量
#if MODULE_ML307A_TCP 
#define ENERGY_OF_26500    11400000 //19000mAhx60%,转uAH
#else 
#define ENERGY_OF_26500     5100000 //8500mAhx60%,转uAH
#endif
//待机预留总电量
#define ENERGY_OF_IDLE      2146000 //按35uA待机7年
//表计功耗分类
#define ONE_HOUR_STATIC_ENERGY  35//1小时待机功耗 35uAH
#define ONE_MIN_WAKE_ENERGY     21//唤醒或检定状态电流1.28mA, 唤醒1分钟的功耗1240/60, 21uAH
#define VAVLE_WORK_ENERGY       42//阀门工作功耗,按150mA计算,每秒42uAH

//不同信号强度对应NB每秒功耗
/*#define NB_UPLOAD_RSRP_110_ONE_SECOND_ENERGY    7.23//待测
#define NB_UPLOAD_RSRP_100_ONE_SECOND_ENERGY    7.23
#define NB_UPLOAD_RSRP_90_ONE_SECOND_ENERGY     7.23
#define NB_UPLOAD_RSRP_80_ONE_SECOND_ENERGY     7.23
#define NB_UPLOAD_RSRP_70_ONE_SECOND_ENERGY     7.23*/
/*
NB上报信号强度和平均电流对应表
BC25模组	            BC28模组	            MN316模组
RSRP	电流mA	程序值	RSRP	电流mA	程序值	RSRP	电流mA	程序值
<90	    24	    6.7uAH	 <90	  22	6.1	    <90  	22	    6.1
<105	28	    7.8	     <105	  26	7.2	    <105	26	    7.2
<115	32	    8.9  	 <115	  32	8.9	    <115	32	    8.9
<120	53	    14.7	 <120	  92	25.6	<120	62	   17.2
>120	60	    16.7	 >120	  98	27.2	>120	72	   20
符网失败28	     7.8	符网失败   24    6.7   符网失败	45	   12.5
*/
#if NB_MODULE_BC25
#define NB_UPLOAD_RSRP_90_ONE_SECOND_ENERGY     6.7
#define NB_UPLOAD_RSRP_105_ONE_SECOND_ENERGY    7.8
#define NB_UPLOAD_RSRP_115_ONE_SECOND_ENERGY    8.9
#define NB_UPLOAD_RSRP_120_ONE_SECOND_ENERGY    14.7
#define NB_UPLOAD_RSRP_WEAK_ONE_SECOND_ENERGY   16.7
#define NB_UPLOAD_RSRP_FAIL_ONE_SECOND_ENERGY   7.8
//余量参数 “计算的NB可用日功耗/实际每日NB功耗”
#define NB_BAT_PARA  (float)3 //BC25按中场单次上报0.285mAH计算, 1.14/0.285=4
#elif NB_MODULE_MN316
#define NB_UPLOAD_RSRP_90_ONE_SECOND_ENERGY     6.1
#define NB_UPLOAD_RSRP_105_ONE_SECOND_ENERGY    7.2
#define NB_UPLOAD_RSRP_115_ONE_SECOND_ENERGY    8.9
#define NB_UPLOAD_RSRP_120_ONE_SECOND_ENERGY    17.2
#define NB_UPLOAD_RSRP_WEAK_ONE_SECOND_ENERGY   20
#define NB_UPLOAD_RSRP_FAIL_ONE_SECOND_ENERGY   12.5
#define NB_BAT_PARA  (float)3 //MN316 按中场单次上报0.223mAH计算, 1.14/0.223=5.1,取5
#elif NB_MODULE_BC28
#define NB_UPLOAD_RSRP_90_ONE_SECOND_ENERGY     6.1
#define NB_UPLOAD_RSRP_105_ONE_SECOND_ENERGY    7.2
#define NB_UPLOAD_RSRP_115_ONE_SECOND_ENERGY    8.9
#define NB_UPLOAD_RSRP_120_ONE_SECOND_ENERGY    25.6
#define NB_UPLOAD_RSRP_WEAK_ONE_SECOND_ENERGY   27.2
#define NB_UPLOAD_RSRP_FAIL_ONE_SECOND_ENERGY   6.7
#define NB_BAT_PARA  (float)3 //BC28 按中场单次上报0.196mAH计算, 1.14/0.196=5.8,取5
#elif MODULE_ML307A_TCP 
#define NB_UPLOAD_RSRP_90_ONE_SECOND_ENERGY     17
#define NB_UPLOAD_RSRP_105_ONE_SECOND_ENERGY    18
#define NB_UPLOAD_RSRP_115_ONE_SECOND_ENERGY    21
#define NB_UPLOAD_RSRP_120_ONE_SECOND_ENERGY    25
#define NB_UPLOAD_RSRP_WEAK_ONE_SECOND_ENERGY   25
#define NB_UPLOAD_RSRP_FAIL_ONE_SECOND_ENERGY   12
#define NB_BAT_PARA  (float)3 //ML307A 按中场单次上报21x30=0.63mAH计算, 3.62/0.63=5.7,取5
#elif MODULE_ML302_TCP 
#define NB_UPLOAD_RSRP_90_ONE_SECOND_ENERGY     17
#define NB_UPLOAD_RSRP_105_ONE_SECOND_ENERGY    18
#define NB_UPLOAD_RSRP_115_ONE_SECOND_ENERGY    21
#define NB_UPLOAD_RSRP_120_ONE_SECOND_ENERGY    25
#define NB_UPLOAD_RSRP_WEAK_ONE_SECOND_ENERGY   25
#define NB_UPLOAD_RSRP_FAIL_ONE_SECOND_ENERGY   12
#define NB_BAT_PARA  (float)3 //ML307A 按中场单次上报21x30=0.63mAH计算, 3.62/0.63=5.7,取5
#endif



//升级标志
#define UPDATE_MODE_DIFF     0x77
#define UPDATE_MODE_NORMAL   0x55

//AT指令精简标志
#define AT_SIMPLE_NULL       0
#define AT_SIMPLE_M1         1
#define AT_SIMPLE_M2         2

typedef struct
{
    u8 up_retry_num;//重试次数
	u8 up_delay_time1;//等下行延时时间
	u8 up_delay_count;//偏移时间
	u8 up_day_count;//间隔多少天上报
	u8 up_pass_flag;//本次上报是否成功标志
}STR_UPLOAD_CONTROL;

typedef enum
{
    UP_RETRY_NUM = 0,//重试次数
	UP_DELAY_TIME1,//等下行延时时间
	UP_DELAY_COUNT,//延时上报时间参数
	UP_DAY_COUNT,//间隔多少天上报
	UP_CGATT_FAIL,//本次联网是否成功标志
	UP_AT_SIMPLE,//AT是否精简
	UP_WITH_UDP,//是否带UDP上报
	UP_ONLY_REV,//是否只接收数据
	UP_BOOT_MSG,//进BOOT消息
	UP_BAT_STATE,//状态字显示电量
	UP_AT_ALL_MSG,//上报失败正常指令
	
	UP_PARA_NUM//参数总数
}ENUM_UPLOAD_CONTROL;

typedef enum
{
    APP_LIFE_CNT_S0 = 0,
	APP_LIFE_CNT_S1,
	APP_LIFE_CNT_S2,
	APP_LIFE_CNT_S3,
	APP_LIFE_CNT_S4
}ENUM_APP_LIFE_CNT;

void AppLifeTimeCountMachine(void);
u8 AppLifeTimeCountMachineIfIdle(void);
void NbUploadParaSet(void);
void setUploadControlPara(ENUM_UPLOAD_CONTROL paraId, u8 paraData);
u8 getUploadControlPara(ENUM_UPLOAD_CONTROL paraId);

#elif UPLOAD_MODE_2

#include "type.h"
#include "UWater_rtcc_driver.h"
#pragma pack(1) //1字节对齐

//时间秒数
#define HOUR_TO_SECOND      3600
#define MINITE_TO_SECOND    60

//表计设计寿命
#define HOURS_OF_7YEARS     61320   //7年使用寿命转成小时

//电池满电可用电量
#if MODULE_ML307A_TCP 
#define ENERGY_OF_26500    11400000 //19000mAhx60%,转uAH
#else 
#define ENERGY_OF_26500     5100000 //8500mAhx60%,转uAH
#endif

//表计功耗分类
#define ONE_HOUR_STATIC_ENERGY  35//1小时待机功耗 35uAH
#define ONE_MIN_WAKE_ENERGY     21//唤醒或检定状态电流1.28mA, 唤醒1分钟的功耗1240/60, 21uAH
#define VAVLE_WORK_ENERGY       42//阀门工作功耗,按150mA计算,每秒42uAH
#define BLE_ONE_MIN_ENERGY      25//蓝牙连接1.5mA,每秒功耗25uAH

typedef enum
{
    APP_LIFE_CNT_S0 = 0,
	APP_LIFE_CNT_S1,
	APP_LIFE_CNT_S2,
	APP_LIFE_CNT_S3,
	APP_LIFE_CNT_S4
}ENUM_APP_LIFE_CNT;

typedef enum
{
    UP_RETRY_NUM = 0,//重试次数
	UP_DELAY_TIME1,//等下行延时时间
	UP_DELAY_COUNT,//延时上报时间参数
	UP_DAY_COUNT,//间隔多少天上报
	UP_CGATT_FAIL,//本次联网是否成功标志
	UP_AT_SIMPLE,//AT是否精简
	UP_WITH_UDP,//是否带UDP上报
	UP_ONLY_REV,//是否只接收数据
	UP_BOOT_MSG,//进BOOT消息
	UP_BAT_STATE,//状态字显示电量
	UP_AT_ALL_MSG,//上报失败正常指令
	
	UP_PARA_NUM//参数总数
}ENUM_UPLOAD_CONTROL;

void AppLifeTimeCountMachine(void);
u8 AppLifeTimeCountMachineIfIdle(void);
u8 getUploadControlPara(ENUM_UPLOAD_CONTROL paraId);

#endif

#endif

