/************************************************************************************
 * @Copyright (c)    :(C)2017, Qindao ieslab Co., Ltd
 * @FileName   	     :nb_driver_bc25.h
 * @Author           :QDIES PLATFORM TEAM
 * @Version          :V1.0
 * @Date             :2020-8-13
 * @Description     :
 ************************************************************************************/

#ifndef __NB_DRIVER_BC25_H
#define	__NB_DRIVER_BC25_H


#include "sys_config.h"
#ifdef NB_MODULE_BC25
#include "type.h"
#include <string.h>
/*----采用宏定义 AT_ORDER_SET 来指定走哪个指令集--*/
//#define M_5310_N    0  //M5310  普通指令集
//#define M_5310_A    1  //M5310A 指令集
//#define AT_ORDER_SET  M_5310_A 
/*------为了简化程序 暂时没有合成到一起----------*/


/*-------模块登录服务器IP表示形式---
 *----IP_PORT       IP形式
 *----DOMAIN_NAME   域名形式  默认域名模式
 *----BOOTSTRAP_ENABLE 启动模式 0-接入机模式  1-引导机模式
 *----接入机模式 IP：183.230.40.40:5683   域名:nbiotacc.heclouds.com:5683 
 *----引导机模式 IP：183.230.40.39:5683   域名:nbiotbt.heclouds.com:5683
 -----------------------------------*/
//#define IP_PORT_TYPE     0
//#define DOMAIN_NAME_TYPE 1  
//#define SEVER_IP_TYPE  DOMAIN_NAME_TYPE
//#define BOOTSTRAP_ENABLE 0


/*--------------------------------------*/

/*-----设置是否打开GSM网络校时--------
 * 1---打开   默认打开
 * 0---关闭
 */

/*------------------------------------*/
  
  
/*-----设置发送数据是否打开ACK--------
 * 1---打开
 * 0---关闭  默认关闭  
 */ 
#define SEND_ACKID_ENABLE 0
/*------------------------------------*/

#if (HARDWARE_VERSION==0x14)//方壳表
#define RSTN_NB_PORT    (GpioPortF)
#define RSTN_NB_PIN     (GpioPin0)

#define BAT_NB_PORT     (GpioPortE)
#define BAT_NB_PIN      (GpioPin4)

#define PWR_NB_PORT     (GpioPortF)
#define PWR_NB_PIN      (GpioPin1)

#define NB_PSM_WAKE_PORT  (GpioPortA)
#define NB_PSM_WAKE_PIN   (GpioPin2)

//PSM 1.8V电压检测 ADC_IN5
#define PSM_CHECK_CHANNEL     5  //AD通道
#define PSM_CHECK_NUM         3  //转换次数
#define PSM_CHECK_INTERVAL    100

#elif (HARDWARE_VERSION==0x18)//圆壳表
#define RSTN_NB_PORT    (GpioPortE)
#define RSTN_NB_PIN     (GpioPin4)

#define BAT_NB_PORT     (GpioPortE)
#define BAT_NB_PIN      (GpioPin5)

#define PWR_NB_PORT     (GpioPortE)
#define PWR_NB_PIN      (GpioPin2)

#define NB_PSM_WAKE_PORT  (GpioPortE)
#define NB_PSM_WAKE_PIN   (GpioPin3)

//PSM 1.8V电压检测 ADC_IN5
#define PSM_CHECK_CHANNEL     12  //AD通道
#define PSM_CHECK_NUM         3  //转换次数
#define PSM_CHECK_INTERVAL    100

#endif
#define RSTN_NB_LOW()    Gpio_WriteOutputIO(RSTN_NB_PORT, RSTN_NB_PIN, GPIO_PIN_SET)
#define RSTN_NB_HIG()    Gpio_WriteOutputIO(RSTN_NB_PORT, RSTN_NB_PIN, GPIO_PIN_RESET) //高电平复位

#define BAT_NB_DISABLE() Gpio_WriteOutputIO(BAT_NB_PORT, BAT_NB_PIN, GPIO_PIN_RESET)
#define BAT_NB_ENABLE()  Gpio_WriteOutputIO(BAT_NB_PORT, BAT_NB_PIN, GPIO_PIN_SET)

#define PWR_NB_LOW()     Gpio_WriteOutputIO(PWR_NB_PORT, PWR_NB_PIN, GPIO_PIN_SET)
#define PWR_NB_HIG()     Gpio_WriteOutputIO(PWR_NB_PORT, PWR_NB_PIN, GPIO_PIN_RESET)

#define NB_PSM_WAKE_LOW()    Gpio_WriteOutputIO(NB_PSM_WAKE_PORT , NB_PSM_WAKE_PIN, GPIO_PIN_SET)
#define NB_PSM_WAKE_HIG()    Gpio_WriteOutputIO(NB_PSM_WAKE_PORT , NB_PSM_WAKE_PIN, GPIO_PIN_RESET) //高电平复位


//查询的状态信息
#define TASK_BUSY                               0                   //BUSY状态
#define TASK_IDLE                               1                   //IDLE状态

//数据发送相关
#define NBIOT_ING                                0xA2                //发送中
#define NBIOT_ONLINE                             0xA3                //NBIOT上线
#define NBIOT_SUCCESS                            0xA4                //发送成功
#define NBIOT_ERROR                              0xA5                //发送失败

//查询CSQ相关
#define CSQ_ING                                 0xA5                //查询中
#define CSQ_SUCCESS                             0xA6                //查询成功
#define CSQ_ERROR                               0xA7                //查询失败

//查询SNR相关
#define ECL_SNR_ING                                 0xA5                //查询中
#define ECL_SNR_SUCCESS                             0xA6                //查询成功
#define ECL_SNR_ERROR                               0xA7                //查询失败

//读取UDP数据相关
#define QIRD_ING                                 0xAA                //查询中
#define QIRD_SUCCESS                             0xAB                //查询成功
#define QIRD_ERROR                               0xAC                //查询失败 
//固件升级相关
#define FRIMWARE_UPDATE_ING                                 0xA5                //查询中
#define FRIMWARE_UPDATE_SUCCESS                             0xA6                //查询成功
#define FRIMWARE_UPDATE_ERROR                               0xA7                //查询失败

//查询ICCID相关
#define ICCID_ING                               0xA5                //查询中
#define ICCID_SUCCESS                           0xA6                //查询成功
#define ICCID_ERROR                             0xA7                //查询失败
#define ICCID_LEN                               0x14                //长度

  
//查询RSRP相关
#define RSRP_ING                               0xA5                //查询中
#define RSRP_SUCCESS                           0xA6                //查询成功
#define RSRP_ERROR                             0xA7                //查询失败
#define RSRP_LEN                               0x14                //长度
  
//任务完成情况
#define TASK_FAIL                               0xA8
#define TASK_SUCCESS                            0xA9
#define TASK_INIT                               0xB0

//任务模式
#define ONLINE_MODE                             0xB1                //NBIOT上线任务
#define SEND_MODE                               0xB2                //NBIOT发送数据任务
#define READ_CSQ                                0xB3                //NBIOT查信号值任务
#define READ_ICCID                              0xB4                //NBIOT查CCID任务
#define NO_NBIOT_TASK                            0xB5                //没有NBIOT任务
#define READ_ECL_SNR                            0xB6                //没有NBIOT任务

//NBIOT网络状态
#define NB_ON_LINE                           0x01                //在线
#define NB_OFF_LINE                          0x00                //不在线

#define CONNECT_ON_LINE                      0x01            
#define CONNECT_OFF_LINE                     0x00            

//工作模式
#define NBIOT_ALWAYS_ON_LINE_MODE                0x81                //一直在线模式
#define NBIOT_TIME_ON_LINE_MODE                  0x80                //阶段一直在线模式在线模式

//NBIOT掉线原因
#define NBIOT_OFFLINE_CLEAR                      0x00                //清除掉线原因
#define NBIOT_OFFLINE_PARA_CHANGE                0x01                //参数更改
#define NBIOT_OFFLINE_STATION_CUT                0x02                //主站下线
#define NBIOT_OFFLINE_SPARE_STATION_START        0x03                //启动备站
#define NBIOT_OFFLINE_SPARE_STATION_CLOSE        0x04                //关闭备站
#define NBIOT_OFFLINE_OPEN_APN                   0x05                //开启APN

//主状态机中的状态号
#define NBIOT_S_IDLE                             0                   //空闲状态
#define NBIOT_POWER_INIT                         1                   //NBIOT模块初始化
#define NBIOT_NET_OPEN                           2                   //配置网络
//#define NBIOT_COAPorONENET_OPEN                   3                   //打开TCP连接
//#define NBIOT_COAPorONENET_DATA_SEND             4                   //发送数据
#define NBIOT_TCP_CLOSE                          5                   //关闭TCP连接
#define NBIOT_NET_CLOSE                          6                   //关闭NBIOT
#define NBIOT_POWER_OFF                          7                   //模块关机
#define NBIOT_HEART_FRAME                        8                   //发送心跳帧
#define NBIOT_READ_CSQ                           9                   //读信号值
#define NBIOT_READ_ICCID                         10                  //读ICCID
#define NBIOT_DATA_REV                           11                  //NBIOT数据接收
#define NBIOT_READ_ECL_SNR                       12                  //读取RSRP  
#define NBIOT_READ_RCV                           13  
#define NBIOT_READ_DATE_TIME                     14
//#define NBIOT_READ_UDP_DATA                      15
#define NBIOT_UDP_OPEN                           16                   //打开UDP连接
#define UDP_DATA_SEND                            17                   //发送UDP数据

#define NBIOT_TCP_OPEN                           18                   //打开TCP连接
#define NBIOT_DATA_SEND                          19                   //发送数据
#define NBIOT_REV_ACK                            20
#define NBIOT_PSM_WAKEUP                         21
#define NBIOT_PSM_SLEEP                          22
//初始化状态机状态号
#define S_START					            0                   //初始状态
#define S_POWER_ON_LOW                      1                   //开机电平相关：高-低-高
#define S_POWER_ON_WAIT                     2                   //开机电平相关：高-低-高
#define S_ATS					            3                   //发送初始化AT指令
#define S_ATS_R				                4                   //判断初始化AT指令返回状态
#define S_CHECK_CGATT			            5                   //Query whether network is activated
#define S_CHECK_CGATT_WAIT        		    6                   //Check whether network is activated
#define S_CHECK_CEREG				        7                   //发送查询网络注册信息 AT指令
#define S_CHECK_CEREG_WAIT        	        8                   //判断查询网络注册信息 AT指令
#define S_CHECK_CSCON				        9                   //Query the signaling connection status
#define S_CHECK_CSCON_WAIT        	        10                  //Check the signaling connection status

//附着NBIOT网络状态机状态号
#define S_CHECK_CIMI			        1                   //发送查询IMSI AT指令
#define S_CHECK_CIMI_WAIT        		2                   //判断查询IMSI AT指令返回状态
#define S_AT_CGDCONT                    3                   //设置APN
#define S_AT_CGDCONT_R                  4                   //判断APN是否设置成功

//唤醒PSM状态机
typedef enum{
	PSM_WKUPSTA_IDLE=0,
	PSM_WKUPSTA_START,
	PSM_WKUPSTA_EINT_LOW,
	PSM_WKUPSTA_EINT_HIGH,
	PSM_WKUPSTA_QLWEVTIND6,
	PSM_WKUPSTA_QSCLK0,
	PSM_WKUPSTA_QSCLK0_R,
	PSM_WKUPSTA_NCDP_CK,
	PSM_WKUPSTA_NCDP_CK_R,
	PSM_WKUPSTA_NPING,
	PSM_WKUPSTA_NPING_R,
	PSM_WKUPSTA_NUESTATS,
	PSM_WKUPSTA_NUESTATS_R,
	PSM_WKUPSTA_WAKE_SUCCESS,
	PSM_WKUPSTA_WAKE_FAIL,
}TYP_PSM_WAKEUP_STATE;

//PSM进入休眠状态
typedef enum{
	PSM_SLPSTA_IDLE=0, 	
	PSM_SLPSTA_START,
	PSM_SLPSTA_CPSMS1_R,
	PSM_SLPSTA_WAIT,
	PSM_CHECK_START,
	PSM_CHECK_WAIT,
}TYP_PSM_SLEEP_STATE;

//PSM状态相关
typedef enum{
	PSM_STATE_OUT=0, 	
	PSM_STATE_WAKE,
	PSM_STATE_SLEEP,   	
}TYP_PSM_STATE;

//接收数据状态号
#define S_AT_NSORF                              1                   //读取数据
#define S_AT_NSORF_R                            2                   //判断是否读取数据成功

//关闭TCP/IP状态机状态号
#define S_AT_NSOCL                              1                   //关闭TCP/IP连接
#define S_AT_NSOCL_R                            2                   //判断TCP/IP是否关闭成功

//关闭NBIOT网络状态机状态号
#define S_POWER_OFF_START                        0
#define S_AT_NETCLOSE                            1                   //关闭NBIOT网络
#define S_AT_NETCLOSE_R                          2                   //判断NBIOT网络是否关闭成功
#define S_AT_QPOWD							     3
#define S_AT_QPOWD_R						     4
#define S_AT_CFUN0                               7
#define S_AT_CFUN0_R                             8
#define S_AT_NCSEARFCN                           9
#define S_AT_NCSEARFCN_R                        10
#define S_AT_CFUN1                              11
#define S_AT_CFUN1_R                            12
#define S_POWER_OFF                             13
#define S_POWER_OFF_WAIT                        14

#define S_AT_MIPLCLOSE                          15                   //关闭onenet网络
#define S_AT_MIPLCLOSE_R                        16                   //判断onenet网络是否关闭成功
#define S_AT_MIPLDELOBJ                         17                   //判断onenet网络是否关闭成功
#define S_AT_MIPLDELOBJ_R                       18                   //判断onenet网络是否关闭成功
#define S_AT_MIPLDEL                            19                   //判断onenet网络是否关闭成功
#define S_AT_MIPLDEL_R                          20                   //判断onenet网络是否关闭成功

#define S_UDP_QICFG0                             21
#define S_UDP_QICFG0_R                           22
//关机状态机状态号
#define S_AT_COPS                               24                  //判断网络是否注销成功
#define S_AT_COPS_R                             25                  //发送关机指令
//#define S_POWER_OFF                           26
//#define S_POWER_OFF_WAIT                      27

//读取信号值状态号
#define S_AT_CSQ                                28
#define S_AT_CSQ_R                              29
#define CSQ_READ_NUM                            4                    //信号值读取次数
//读取ECL、SNR
#define S_AT_ECL                              30
#define S_AT_ECL_R                            31

//读取UDP数据
#define S_AT_QIRD                                1
#define S_AT_QIRD_R                              2

//备站状态
#define OPEN_SPARE_STATION                      0x01
#define CLOSE_SPARE_STATION                     0x00

//通信模式选择
#define SIM_CARD_TELECOM                        0x00 //电信卡
#define SIM_CARD_MOBILE                         0X01 //移动卡
//
//OnenetConnectMachine使用的状态
#define S_ONENET_CONNECT_IDLE	      0                   
#define S_ONENET_CONNECT_START	      1 
#define S_ONENET_MIPLCONFIG           2
#define S_ONENET_MIPLCONFIG_R         3
#define S_ONENET_MIPLCONFIG_CK        4
#define S_ONENET_MIPLCONFIG_CK_R      5
#define S_ONENET_MIPLCREATE           6
#define S_ONENET_MIPLCREATE_R         7
#define S_ONENET_MIPLADDOBJ           8
#define S_ONENET_MIPLADDOBJ_R         9
#define S_ONENET_MIPLOPEN             10
#define S_ONENET_MIPLOPEN_R           11
#define S_ONENET_MIPLDISCOVER         12
#define S_ONENET_MIPLDISCOVER_R       13
#define S_ONENET_ECL                  14
#define S_ONENET_ECL_R                15
#define S_ONENET_CCLK                 16
#define S_ONENET_CCLK_R               17
#define S_ONENET_Wait                 18

//连接通信协议
#define NBIOT_CONNECT_COAP  0
#define NBIOT_CONNECT_UDP1  1
#define NBIOT_CONNECT_UDP2  2
//******************************* 结构体定义*************************************
//参数空间
#ifndef  APN_SIZE
#define APN_SIZE                                32
#endif 
typedef struct
{
    u8 *work_mode; //工作模式，一直在线模式还是时段在线模式
    u8 *ip; //IP
    u8 *spare_ip; //备用IP
    u8 *port; //端口号
    u8 *spare_port; //备用端口号
    u8 *apn; //APN
} CFIG_PARA;

//NBIOT消息

typedef union
{
    struct
    {
        u8 para_change : 1; //参数改变
        u8 station_close : 1; //主站下线
        u8 open_spare_station : 1; //开启备站
        u8 close_spare_station : 1; //关闭备站
        u8 apn_open : 1; //APN开启
        u8 rev_data : 1; //收到数据
    } s;
    u8 info;
} NBIOT_MSG;

//NBIOT相关参数

typedef struct
{
    CFIG_PARA cfig_para; //可配置参数
    u8 csq; //信号值
    u8 net_state; //网络状态
    u8 offline_reason; //掉线原因
    u8 Telecom; //运营商
    u8 spare_station; //备站
	u8 coap_state;
	u8 udp1_state;
	u8 udp2_state;
    char imei[16];//IMEI号码为15 BIT阿拉伯数字 最后一字节为结束符 “\0”
    char imsi[16];//IMSI号码为15 BIT阿拉伯数字 最后一字节为结束符 “\0”
    char iccid[21];//ICCID为20位 数字或者大写字符 
} NBIOT_PARA;

//数据发送相关

typedef struct
{
    u8 *state; //发送申请指针msg
    u8 *buf; //发送数据指针
    u16 len; //发送长度
} NBIOT_SEND_DATA;


//******************************* 外部变量***************************************
extern NBIOT_PARA Nbiot_Para;
extern NBIOT_MSG Nbiot_Msg;

//******************************* 外部接口函数***********************************
void NbiotOnlineTask(u8 *state);
void NbiotSendTask(u8 *addr, u16 len, u8 send_type,u8 *state);
void NbiotUdpOpenTask(void);
void NbiotReadECLSNRTask(u8 *state);
void NB_NetConnectStart(unsigned char* temp_ip, u16 temp_port, u8 connect_type);
u8 ConncetIfOnline(u8 connect_type);
void StartNbiotSendData(void);
u32 sys_get_net_state(void);
void sys_set_net_state(u8 state,u8 data);

u8 NbiotIfIdle(void);
u8 NbiotIfOnline(void);
u8 NbiotIfSleep(void);
void NbiotPreSleep(void);
void NbiotWakeSleep(void);

void NbiotGetCcidTask(u8 **ccid, u8 *state);
void NbiotMainMachine(void);

u8 If_NB_Poweron(void);
void StartPowerOffTask(void);
void set_ip_port(void);
void NbForcePowerOff(void);
u8 GetNbiotSendType(void);
//u8 UdpIfOnline(void);
TYP_PSM_STATE getPsmState(void);
u8 checkPsmEnterMsg(void);
void clearPsmEnterMsg(void);
void NbiotPsmWakeupTask(void);
void NbiotPsmSleepTask(void);
void NbiotPsmCheckTask(void);
u16 get_Send_AckID(void);
//初始化状态机状态号
#define S_INIT_POWER_ON			     0                   //模块送电
#define S_INIT_RESET_LOW             1                   //开始复位模块
#define S_INIT_RESET_HIGH            2                   //模块完成复位
#define S_INIT_POWER_ON_WAIT         3                   //等待模块搜网注册
#define S_INIT_ATS					 4                   //发送初始化AT指令
#define S_INIT_ATS_R				 5                   //判断初始化AT指令返回状态
#define S_INIT_CMEE                  6                   //打开ERROR错误代码显示
#define S_INIT_CMEE_R                7                   //打开ERROR错误代码显示返回状态
#define S_TCP_CPSMS                  8                   //关闭PSM模式
#define S_TCP_CPSMS_R                9
#define S_TCP_NPTWEDRXS              10                  //关闭eDRX模式
#define S_TCP_NPTWEDRXS_R            11
#define S_INIT_ASK_IMEI				 12                   //查询IMEI
#define S_INIT_ASK_IMEI_R			 13                   //查询IMEI返回状态
#define S_INIT_ASK_CIMI				 14                   //查询CIMI
#define S_INIT_ASK_CIMI_R			 15                   //查询CIMI返回状态
#define S_INIT_ASK_CSQ				 16                  //查询CSQ
#define S_INIT_ASK_CSQ_R			 17                  //查询CSQ返回状态
#define S_INIT_ASK_CEREG			 18                  //查询CEREG
#define S_INIT_ASK_CEREG_R			 19                  //查询CEREG返回状态
#define S_INIT_ASK_CGATT			 20                  //查询CGATT
#define S_INIT_ASK_CGATT_R			 21                  //查询CGATT返回状态
#define S_INIT_AT_QSCLK              22                  //临时关闭深度休眠
#define S_INIT_AT_QSCLK_R            23                  //查询临时关闭深度休眠返回状态
#define S_INIT_ASK_ICCID             24                  //查询SIM卡的ICCID
#define S_INIT_ASK_ICCID_R           25                  //查询SIM卡的ICCID返回状态
#define S_INIT_AT_CGDCONT             26                  //查询SIM卡的ICCID
#define S_INIT_AT_CGDCONT_R           27                  //查询SIM卡的ICCID返回状态
//#define S_INIT_AT_CFUN0               28                  //关射频
//#define S_INIT_AT_CFUN0_R             29                  //查询关射频返回状态
//#define S_INIT_AT_CFUN1               30                  //开射频
//#define S_INIT_AT_CFUN1_R             31                  //查询开射频返回状态
#define S_INIT_AT_READ_APN            32                 //查询SIM卡的ICCID
#define S_INIT_AT_READ_APN_R          33                  //查询SIM卡的ICCID返回状态

#define S_INIT_PWRKEY_LOW             34                   //开始复位模块
#define S_INIT_PWRKEY_HIGH            35                   //模块完成复位

#define S_INIT_SET_NCFG              36                   //设置lifetime 平台端的生存周期
#define S_INIT_SET_NCFG_R            37                   //设置lifetime 平台端的生存周期
#define	S_INIT_ASK_NUESTATS          38
#define	S_INIT_ASK_NUESTATS_R        39
#define	S_INIT_ASK_CCLK              40
#define	S_INIT_ASK_CCLK_R            41
//TCP链接状态机
//#define S_COAP_CONNECT_START	      0                   //
//#define S_TCP_CONNECT_DEL           1                 //删除以前的链接

//#define S_TCP_CONNECT_START	        0                   //模块送电

//#define S_UDP_CONNECT_START           0       
#define SEND_TYPE_COAP                0
#define SEND_TYPE_UDP1                1
#define SEND_TYPE_UDP2                2
#define SEND_TYPE_TCP1                3
//CoapConnectMachine
#define S_COAP_CONNECT_START	      0                   
#define S_COAP_NCDP                   1
#define S_COAP_NCDP_R                 2
#define S_COAP_NCDP_CK                3
#define S_COAP_NCDP_CK_R              4
//#define S_COAP_Wait                   5
//#define S_COAP_ECL                    6 //读取ECL、SNR
//#define S_COAP_ECL_R                  7
//#define S_COAP_CCLK                   8 //查询网络时间
//#define S_COAP_CCLK_R                 9 //查询网络时间返回状态
//UdpConnectMachine
#define S_UDP_CONNECT_START           0  
#define S_UDP_QIOPEN                   1
#define S_UDP_QIOPEN_R                 2
#define S_UDP_NCDP_CK                  3
#define S_UDP_NCDP_CK_R                4
#define S_UDP_CCLK                     5
#define S_UDP_CCLK_R                   6
#define S_UDP_NUESTATS                 7
#define S_UDP_NUESTATS_R               8
#define S_UDP_Wait                     9
#define S_UDP_QICFG                    10
#define S_UDP_QICFG_R                  11
//onenet指令集
#define S_TCP_MIPLCONFIG            1
#define S_TCP_MIPLCONFIG_R			2
#define S_TCP_MIPLCREATE            3                   //配置登录信息
#define S_TCP_MIPLCREATE_R          4                   //删除以前的链接返回状态
#define S_TCP_MIPLADDOBJ            5                   //定制对象
#define S_TCP_MIPLADDOBJ_R          6                   //定制对象返回状态
#define S_TCP_MIPLDISCOVERRSP       7                   //订阅资源
#define S_TCP_MIPLDISCOVERRSP_R     8                 //订阅资源返回状态
#define S_TCP_MIPLOPEN 				9
#define S_TCP_MIPLOPEN_R 			10
#define S_TCP_WAIT_DISCOVER     	11	
#define S_TCP_ACK_DISCOVER     		12
//
#define S_TCP_CONNECT_MIPLCONF      12                   //配置登录信息
#define S_TCP_CONNECT_MIPLCONF_R    13                   //配置登录信息返回状态

//发送数据状态机
#define S_SEND_START     0
#define S_SEND_AT        1
#define S_SEND_AT_R      2
#define S_SEND_DATA      3
#define S_SEND_DATA_R    4


//ONENET 应答MIPLWRITE状态机
#define S_ONENET_ACKREV_IDLE          0
#define S_ONENET_ACKREV_START	      1                 
#define S_ONENET_REPLY_REV_ACKID	  2 //应答接收到数据
#define S_ONENET_REPLY_REV_ACKID_R    3 //应答接收到数据--等待响应*/

//关闭onenet网络状态机状态号
//#define S_AT_MIPLCLOSE                           1                   //关闭onenet网络
//#define S_AT_MIPLCLOSE_R                         2                   //判断onenet网络是否关闭成功
//#define S_AT_MIPLDELOBJ                          3                   //判断onenet网络是否关闭成功
//#define S_AT_MIPLDELOBJ_R                        4                   //判断onenet网络是否关闭成功
//#define S_AT_MIPLDEL                             5                   //判断onenet网络是否关闭成功
//#define S_AT_MIPLDEL_R                           6                   //判断onenet网络是否关闭成功
//#define S_AT_CFUN0                               7
//#define S_AT_CFUN0_R                             8
//#define S_AT_NCSEARFCN                           9
//#define S_AT_NCSEARFCN_R                        10
//#define S_AT_CFUN1                              11
//#define S_AT_CFUN1_R                            12
//#define S_POWER_OFF                             13
//#define S_POWER_OFF_WAIT                        14


#define NUM_AT_ERROR            5			//5 
#define NUM_AT_CMEE_ERROR       5			//5
#define NUM_AT_CIMI_ERROR       5			//5
#define NUM_AT_IMEI_ERROR       5			//5 
#define NUM_AT_ICCID_ERROR      5			//5
#define NUM_AT_CSQ_ERROR        5    
#define NUM_AT_CEREG_ERROR      15//15*2=30S
//#define NUM_AT_CGATT_ERROR      30			//20 
#define NUM_AT_CCLK_ERROR       2 

#define NUM_AT_NCDP_ERROR          1
#define NUM_AT_NCDP_CK_ERROR       1

#define NUM_AT_NNMI_ERROR            5			//5
#define NUM_AT_CPSMS_ERROR           5			//5
#define NUM_AT_MIPLDEL_ERROR         5			//5
#define NUM_AT_MIPLCONF_ERROR        2//5沈阳改为2次重试			//5
#define NUM_AT_MIPLCREATE_ERROR      5			//5
#define NUM_AT_MIPLADDOBJ_ERROR      5			//5
#define NUM_AT_MIPLDISCOVERRSP_ERROR 2//5沈阳改为2次重试
#define NUM_AT_ECL_ERROR             2			//5

#define NUM_AT_MIPLNOTIFY_ERROR      5			//5
#define NUM_AT_MIPLOPEN_ERROR        2//5	//5沈阳改为2次重试		//5
#define NUM_AT_MIPLWRITE_ERROR       5			//5
#define NUM_AT_MIPLCLOSE_ERROR       5			//5
#define NUM_M5310_RESTART            5			//5
#define NUM_AT_CFUN_ERROR            3			//5
#define NUM_AT_NCSEARFCN_ERROR       3			//5
#define NUM_AT_NPTWEDRXS_ERROR       3			//5
#define NUM_AT_QICFG_ERROR           3

#define AT_COMMAND_SEND_INTERVAL_TIME 300   //mS
#define AT_COMMAND_RECEIVE_WAIT_TIME  1000  //mS

#endif	

#endif	



