/*************************** (C) COPYRIGHT 2017 CXHY ****************************
 * 文件名  ：at_proc.h
 * 描  述  ：GSM AT指令解析  
 * 版  本  ：V1.0
 * 作  者  ：XuZhongPing
 * 日  期  ：2017/02/05 
*********************************************************************************/
#ifndef  _AT_PROC_H_
#define  _AT_PROC_H_

#include "stm32f10x.h"
#include "stdio.h" 

#define AT_CMD_COMMON_ERROR  					"+CME ERROR:"

#define AT_CMD_SEND_OK								"SEND OK"	
#define AT_CMD_AT_OK									"OK"	
#define AT_CMD_AT_AT									"AT"
#define AT_CMD_AT_ATE0								"ATE0\r"
#define AT_CMD_AT_CREG								"+CREG: 0,5"
#define AT_CMD_AT_CGREG								"+CGREG: 0,5"
#define AT_CMD_AT_ERROR								"ERROR"

//GPRS数据发送过程应答字符
#define SEND_STATUS_READY							">"
#define SEND_STATUS_SEND_OK						"SEND OK"
#define SEND_STATUS_SEND_FAIL					"SEND FAIL"
#define SEND_STATUS_CLOSED						"CLOSED"

//GPRS工作状态
#define CIPSTATUS_IP_INITIAL					"STATE: IP INITIAL"
#define CIPSTATUS_IP_START						"STATE: IP START"
#define CIPSTATUS_IP_CONFIG						"STATE: IP CONFIG"
#define CIPSTATUS_IP_GPRSACT					"STATE: IP GPRSACT"
#define CIPSTATUS_IP_STATUS						"STATE: IP STATUS"
#define CIPSTATUS_TCP_CONNECTING			"STATE: TCP CONNECTING"
#define CIPSTATUS_CONNECT_OK					"STATE: CONNECT OK"
#define CIPSTATUS_TCP_CLOSING					"STATE: TCP CLOSING"
#define CIPSTATUS_TCP_CLOSED					"STATE: TCP CLOSED"
#define CIPSTATUS_PDP_DEACT						"STATE: PDP DEACT"

//模块上报URC
#define RECEIVE_URC										"+QIURC: "							//模块上报URC
#define RECEIVE_SERVER_DATA						"+QIURC: \"recv\""			//数据接收URC

typedef enum
{
	AT_CMD_AT_NO = 1,							//AT测试指令
  AT_CMD_ATE0_NO,								//回显设置指令
  AT_CMD_CGSN_NO,								//IMEI号查询指令
	AT_CMD_CPIN_NO,								//查询SIM卡状态
  AT_CMD_ICCID_NO,							//查询SIM卡的ICCID卡号
  AT_CMD_CSQ_NO,								//查询信号强度
  AT_CMD_CREG_NO,								//查询网络注册状态			
  AT_CMD_CGREG_NO,							//查询GPRS附着状态
	AT_CMD_COPS_NO,								//查询运营商
  AT_CMD_QICSGP_NO,							//配置TCP/IP场景参数
  AT_CMD_QIACT_NO,							//激活PDP场景		
  AT_CMD_QIDEACT_NO,						//反激活PDP场景
  AT_CMD_CHECK_QIACT_NO,				//查询PDP场景状态
  AT_CMD_QIOPEN,								//建立TCP客户端连接
	AT_CMD_QICLOSE_NO,						//关闭连接
  AT_CMD_QISEND,								//发送数据
  AT_CMD_CHECK_QISEND_NO,				//查询数据发送状态
  AT_CMD_QIRD_NO,								//读取接收到的数据
	AT_CMD_QNTP_NO,								//同步NTP服务器时间
	AT_CMD_CCLK_NO,								//查询时间
}_AT_CMD_Number;


//GPRS发送命令后模块应答的结果
typedef enum
{    
  AT_CMD_SUCCESS = 1,  
	AT_CMD_CIPSEND_READY = 10,
	AT_CMD_CIPSEND_OK = 11,
	AT_CMD_SEND_FAIL = 12,
	TCP_STATUS_CLOSED = 13,
	
  AT_CMD_FAILED = 100,
  AT_CMD_TIMEOUE = 101,
  AT_CMD_UNKNOWN = 255 

}AT_CMD_RESULT;

//GPRS工作状态
typedef enum
{    
	GPRS_STATUS_IP_INITIAL = 20,
	GPRS_STATUS_IP_START,
	GPRS_STATUS_IP_CONFIG,
	GPRS_STATUS_IP_GPRSACT,
	GPRS_STATUS_IP_STATUS,
	GPRS_STATUS_TCP_CONNECTING,
	GPRS_STATUS_CONNECT_OK,
	GPRS_STATUS_TCP_CLOSING,
	GPRS_STATUS_TCP_CLOSED,
	GPRS_STATUS_PDP_DEACT,
}AT_CMD_RESULT_GPRS_STATUS;

typedef struct
{
	uint8_t cmdNo;
	uint8_t cmd[64];
	uint8_t success[15];
	uint8_t failed[15]; 
	uint8_t result;
}AT_CMD_PARAM;

extern uint8_t sendAtCmdNo;
extern  uint8_t networkIsReg;

extern uint8_t receiveDataReady;
extern uint8_t receiveDataLen;

#define CMD_TABLE_LENGTH  30

extern AT_CMD_PARAM at_cmd_table[CMD_TABLE_LENGTH];

void GSM_SendAtCmd(char *cmd, uint8_t atCmdNo);
void getCommand_CIPSEND(uint16_t len);
void AT_Protocol(uint8_t* pCdmStr, uint8_t length);				//AT返回值解析函数


#endif
/******************** (C) COPYRIGHT 2017 CXHY *****END OF FILE*******************/ 
