[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/at_demo/Makefile b/ap/app/at_demo/Makefile
new file mode 100644
index 0000000..afb6fdb
--- /dev/null
+++ b/ap/app/at_demo/Makefile
@@ -0,0 +1,40 @@
+#*******************************************************************************

+# include ZTE application makefile

+#*******************************************************************************

+include $(zte_app_mak)

+

+

+####################################################################

+# ±àÒëÐèÒªµÄһЩÅäÖÃÐÅÏ¢

+####################################################################

+mdir_y += com

+mdir_y += at_client

+mdir_y += user_demo

+

+####################################################################

+# ¾ßÌå±àÒëÄ¿±ê¶¨Òå

+####################################################################

+

+#*******************************************************************************

+# targets

+#*******************************************************************************

+all:

+	@echo "==========> zte FOTA compile <=========="	

+	@for i in $(mdir_y) ; do \

+		[ ! -d "$$i" ] || $(MAKE) -C $$i || exit $$?; \

+	done

+	

+romfs:

+	@for i in $(mdir_y) ; do \

+		[ ! -d "$$i" ] || $(MAKE) -C $$i romfs || exit $$?; \

+	done

+

+clean:

+	@echo "==========> zte FOTA clean <=========="

+	@rm -rvf ./libs/*

+	@rm -rvf ./bins/*

+	@for i in $(mdir_y) ; do \

+		[ ! -d "$$i" ] || $(MAKE) -C $$i clean || exit $$?; \

+	done

+

+

diff --git a/ap/app/at_demo/at_client/Makefile b/ap/app/at_demo/at_client/Makefile
new file mode 100644
index 0000000..1a3a95c
--- /dev/null
+++ b/ap/app/at_demo/at_client/Makefile
@@ -0,0 +1,32 @@
+#*******************************************************************************

+# include ZTE application makefile

+#*******************************************************************************

+include $(zte_app_mak)

+

+##############USER COMIZE BEGIN################

+EXEC = at_client

+OBJS = $(patsubst %.c,%.o,$(wildcard *.c))

+

+

+CFLAGS += -I$(zte_app_path)/include

+CFLAGS += -I../com 

+

+LDLIBS += -lpthread 

+LDLIBS += -lcom -L../com

+

+##############USER COMIZE END##################

+

+#*******************************************************************************

+# targets

+#*******************************************************************************

+all: $(EXEC)

+

+$(EXEC): $(OBJS)

+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group

+	@cp $@ $@.elf

+

+romfs:

+	$(ROMFSINST) $(EXEC) /sbin/$(EXEC)

+

+clean:

+	-rm -f $(EXEC) *.elf *.gdb *.o
diff --git a/ap/app/at_demo/at_client/at_arch.c b/ap/app/at_demo/at_client/at_arch.c
new file mode 100644
index 0000000..8d60d34
--- /dev/null
+++ b/ap/app/at_demo/at_client/at_arch.c
@@ -0,0 +1,129 @@
+/************************************************************************************

+demoÓ¦Óà ϵͳ½Ó¿ÚÊÊÅä²ã

+***************************************************************************************/

+#include "at_com.h"

+

+#define _LINUX_OS

+#ifdef _LINUX_OS

+#include <stdio.h>

+#include <string.h>

+#include <stdlib.h>

+#include <assert.h>

+#include <syslog.h>

+#include <sys/klog.h>

+#include <sys/msg.h>

+#include <sys/socket.h>

+#include <linux/sockios.h>

+#include <sys/un.h>

+#include <errno.h>

+#include <sys/types.h>

+#include <sys/wait.h>

+#include <sys/msg.h>

+#include <fcntl.h>

+//ͨµÀ´ò¿ª½Ó¿Ú£¬·µ»ØÉ豸¾ä±ú

+int at_open(char *name)

+{	

+	int fd = open(name, O_RDWR);

+    ioctl(fd, (('R'<<8)|1|(0x4004<<16)), 0x800);

+    ioctl(fd, (('R'<<8)|4|(0x4004<<16)), 0);

+	return fd;

+}

+//¶ÁͨµÀ£¬Í¨¹ýÉ豸¾ä±ú¶ÁÈ¡Êý¾Ý

+int at_read(int fd, char *buf, int len)

+{	

+	return read(fd, buf, len);

+}

+//дͨµÀ£¬Í¨¹ýÉ豸¾ä±úдÈëÊý¾Ý

+int at_write(int fd, char *buf, int len)

+{	

+	return write(fd, buf, len);

+}

+//¹Ø±Õ½Ó¿Ú£¬¹Ø±ÕÉ豸£¬ÔÝʱδʹÓÃ

+int at_close(int handle)

+{	

+	return close(handle);

+}

+//´´½¨ÏûÏ¢¶ÓÁÐ

+int at_create_msg_queue(int id)

+{

+    return msgget(id, IPC_CREAT|0600);

+}

+

+//×èÈû½ÓÊÕÏûÏ¢½Ó¿Ú

+int at_recv_msg(int msqid, void *msgp, int msgsz, int timeout)

+{

+	return msgrcv(msqid, msgp, msgsz, 0, 0);

+}

+//´´½¨Ï߳̽ӿÚ

+int at_create_thread(start_fnc entry_fnc,void *arg)

+{

+	pthread_t  thread_id;

+	pthread_attr_t attr;

+	int  result = 0;

+

+	pthread_attr_init(&attr);

+	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

+	result = pthread_create(&thread_id, &attr, (void *)entry_fnc, arg);

+	pthread_attr_destroy(&attr);

+	return result;

+}

+//sleep½Ó¿Ú£¬µ¥Î»Ãë

+void at_sleep(unsigned int seconds)

+{

+	sleep(seconds);

+}

+//¶ÏÑÔ½Ó¿Ú

+/*void at_assert(int exp)

+{

+	assert(exp);

+}*/

+//»ñÈ¡µ±Ç°ÏµÍ³ÔËÐÐʱ¼ä½Ó¿Ú£¬µ¥Î»Ãë

+int at_get_currtime(void)

+{

+	struct timeval now;

+	unsigned char  timestr[60] = {0};

+	unsigned char  uptimestr[30] = {0};

+	unsigned char * dotaddr;

+	unsigned long second;

+	char error = 0;

+	FILE * timefile = NULL;

+

+	timefile = fopen("/proc/uptime", "r");

+	if (!timefile) {

+		printf("[%s:line:%d] error opening '/proc/uptime'", __FILE__, __LINE__);

+		error = 1;

+		goto out;

+	}

+

+	if ((fread(timestr, sizeof(char), 60, timefile)) == 0) {

+		printf("[%s:line:%d] read '/proc/uptime' error", __FILE__, __LINE__);

+		error = 1;

+		goto out;

+	}

+

+	dotaddr = strchr(timestr, '.');

+	if ((dotaddr - timestr + 2) < 30)

+		memcpy(uptimestr, timestr, dotaddr - timestr + 2);

+	else {

+		printf("[%s:line:%d] uptime string is too long", __FILE__, __LINE__);

+		error = 1;

+		goto out;

+	}

+	uptimestr[dotaddr - timestr + 2] = '\0';

+

+out:

+	if (error) {

+		now.tv_sec  = 0;

+		now.tv_usec = 0;

+	} else {

+		now.tv_sec  = atol(uptimestr);

+		now.tv_usec = 0;

+	}

+

+	fclose(timefile);

+	return now.tv_sec;

+}

+#else

+

+#endif

+

diff --git a/ap/app/at_demo/at_client/at_client.c b/ap/app/at_demo/at_client/at_client.c
new file mode 100644
index 0000000..dfd039f
--- /dev/null
+++ b/ap/app/at_demo/at_client/at_client.c
@@ -0,0 +1,661 @@
+/************************************************************************************

+demoÓ¦Óà AT¿Í»§¶ËÖ÷¿ò¼Ü

+***************************************************************************************/

+

+#define _LINUX_OS

+#ifdef _LINUX_OS

+#include <sys/time.h>

+#include <signal.h>

+#endif

+//#include "at_api.h"

+#include "at_context.h"

+

+//char g_curr_at_cmd[640] = {0};		//¼Ç¼µ±Ç°ÕýÔÚ´¦ÀíµÄATÇëÇó×Ö·û´®,µ±ÏìÓ¦Éϱ¨ºóÐèÊÍ·ÅÇå¿Õ

+//char g_whole_at_cmd[AT_CMD_MAX] = {0};//µ±ATÏìÓ¦Éϱ¨²»ÍêÕûʱ,»º´æATÏìÓ¦,ÓÃÓÚ×é°ü

+int g_is_log_state = 0;				//¼Ç¼µ±Ç°ÊÇ·ñÇл»ÎªATÍÂLOG״̬£¬0ΪÕý³£Ì¬£¬1ΪLOG̬£¬ÔÚLOG̬ʱ²»Ö§³ÖATÃüÁîÏìÓ¦½ÓÊÕ

+int g_is_poweron = 0;				//¼Ç¼ÖÐÐË΢SOCÊÇ·ñÒѾ­Æô¶¯£¬0ΪδÆô¶¯£¬1ΪÒÑÆô¶¯

+int g_fd = 0;						//µ±Ç°µÄͨµÀ¾ä±ú£¬ÓÃÓÚATÃüÁîµÄ·¢ËͺͽÓÊÕ

+//int g_atsend_timeid = 0;            //¼Ç¼·¢ËÍATÇëÇóµÄ¶¨Ê±Æ÷

+

+/*ÅжÏÊÇ·ñµ½ÁËATÃüÁîµÄ½áβ»ò×Ö·û´®½áβ*/

+int is_at_cmd_end(const char * pstrAtCmd)

+{

+    if('\0' == *pstrAtCmd)

+    {

+        return 1;

+    }

+    if('\r' == *pstrAtCmd)

+    {

+        return 1;

+    }

+    return 0;

+}

+

+/*Ìø¹ý´¦Àí×Ö·ûµÄ¿Õ¸ñ£¬·µ»ØÈ¥µô¿ªÍ·ËùÓпոñµÄ×Ö·û*/

+const char *skip_at_cmd_head_blanks(const char * pstrAtCmd)

+{

+    const char * pstrCur = pstrAtCmd;

+

+    for(; !is_at_cmd_end(pstrCur); pstrCur++)

+    {

+        if(' ' != *pstrCur)

+        {

+            break;

+        }

+    }

+    return pstrCur;

+}

+//½âÎöÏìӦΪOK\ERROR»¹ÊÇÖмä½á¹û¡¢Ö÷¶¯Éϱ¨»ò¶ÌÐÅPDU

+int parase_at_cmd(char *at_str, void **at_cmd_prefix, int* prefix_len, void ** at_cmd_paras, int * paras_len)

+{

+    char *pszAtHead = NULL;

+    char *pstrCur = NULL;

+    char *ptemstr = NULL;

+

+	pstrCur = (char *)skip_at_cmd_head_blanks(at_str);  

+        

+    pszAtHead = pstrCur;

+

+	if(at_strncmp(pszAtHead,"at",2) == 0)

+    {

+        if(isalpha(*(pszAtHead+2)))

+        {

+            *at_cmd_prefix = NULL;

+			*prefix_len = 0;

+        }

+		else

+		{

+			ptemstr = pszAtHead+2;

+		

+			for(;*ptemstr != '\0'; ptemstr++)

+			{

+				if(*ptemstr == '=' || *ptemstr == '?' || *ptemstr == '\r')

+				{

+					*at_cmd_prefix = pszAtHead+2;

+					*prefix_len = ptemstr-pszAtHead-1;

+					return AT_TYPE_REQUEST;

+				}

+			}

+		}

+    }

+   

+    if(strcmp(pszAtHead, "OK") == 0)

+    {

+        *at_cmd_prefix = NULL;

+        *prefix_len = 0;

+        *at_cmd_paras = NULL;

+        *paras_len = 0;

+        return AT_TYPE_RESPONSE_OK;

+    }

+    if(strcmp(pszAtHead, "ERROR") == 0

+		|| strstr(pszAtHead, "+CME ERROR:") != NULL 

+		|| strstr(pszAtHead, "+CMS ERROR:") != NULL )

+    {

+        *at_cmd_prefix = NULL;

+        *prefix_len = 0;

+        *at_cmd_paras = NULL;

+        *paras_len = 0;

+        return AT_TYPE_RESPONSE_ERR;

+    }	

+    if((ptemstr = strchr(pszAtHead, ':')) != NULL)

+    {

+        *at_cmd_prefix = pszAtHead;

+        *prefix_len = (int)(ptemstr-pszAtHead);

+        *at_cmd_paras = (char *)skip_at_cmd_head_blanks(++ptemstr);

+        *paras_len = strlen(*at_cmd_paras);

+        return AT_TYPE_INFORM;

+    }

+    if(strstr(at_str, "> ") != NULL)

+    {

+        *at_cmd_prefix = pstrCur;

+        *prefix_len = strlen(pstrCur);

+        *at_cmd_paras = NULL;

+        *paras_len = 0;

+        return AT_TYPE_INFORM;

+    }

+    if(strstr(at_str, "0") != NULL)

+    {

+        *at_cmd_prefix = NULL;

+        *prefix_len = 0;

+        *at_cmd_paras = at_str;   

+        *paras_len = strlen(at_str);

+        return AT_TYPE_PDU;

+    }

+    else

+    {

+        *at_cmd_prefix = at_str;

+        *prefix_len = strlen(at_str);

+        *at_cmd_paras = NULL;

+        *paras_len = 0;

+        return AT_TYPE_INFORM;

+    }

+}

+

+

+/* ֪ͨÀàATÃüÁî´¦Àí*/

+static void rcv_at_inform_handle(int at_fd, char *at_str, void *at_cmd_prefix, int prefix_len, void * at_cmd_paras, int paras_len)

+{

+    void   *res_msg = NULL;

+    int    res_msglen = 0;

+	struct at_context *context = find_context_by_fd(NEAR_PS, at_fd);

+

+	//ͨ¹ýfd²éÕÒÉÏÏÂÎÄ£¬Èç¹û¿ÉÒÔÕÒµ½£¬²¢ÇÒǰ׺¿ÉÒÔÆ¥Å䣬˵Ã÷ÊÇget_modem_infoµÄÖмä½á¹û£¬ÐèҪͨ¹ýÏûÏ¢·µ»ØÆäÖмä½á¹û

+	if(context != NULL && at_strncmp(context->send_req_cmd_prefix,(char *)at_cmd_prefix, prefix_len) == 0)	

+		at_send_msg(MODULE_ID_AT_CLIENT, context->clt_source_id, MSG_CMD_SEND_AT_MSG_RSP, strlen(at_str), at_str, 0); 			

+	else//·ñÔòÊÓΪÖ÷¶¯Éϱ¨£¬È»ºóͨ¹ý²éÕÒÖ÷¶¯Éϱ¨µÄ×¢²áº¯Êý½øÐд¦Àí

+	{

+		struct ind_ops_t *rcv_inform = find_autoinfo_by_prefix(at_cmd_prefix, prefix_len);

+		

+	    if(rcv_inform && rcv_inform->inform_act)

+	    {

+	        rcv_inform->inform_act(at_cmd_paras);

+	    }

+	}

+}

+

+//ÇëÇóÀàÖ»´¦Àí·þÎñ¶ËÃüÁÆäËûÃüÁî²»´¦Àí

+static int rcv_at_req_handle(int at_fd, char *at_str, void *at_cmd_prefix, int prefix_len, void * at_cmd_paras, int paras_len)

+{

+    

+	if(ext_req_to_app(at_fd, at_str, at_cmd_prefix, prefix_len,at_cmd_paras))

+    {

+        return 0;

+    }

+	return 0;

+}

+

+

+/* ´ÓÖÐÐË΢SOCÊÕµ½²ð·ÖºóµÄµ¥ÌõATÃüÁîµÄ´¦Àí*/

+void rcv_at_str_handle(int at_fd, char *at_str)

+{

+	/* atÀàÐÍ*/

+    int at_str_type;

+    /* atǰ׺ÆðʼλÖã¬Ö±½ÓÖ¸ÏòatÃüÁîËùÔÚÄڴ棬Òò´Ëatǰ׺½áÊøÎ»ÖúóÃæµÄ×Ö·û²»Ò»¶¨Ê±'\0'£¬Óëatǰ׺³¤¶È±ØÐëÒ»ÆðʹÓã¬È·¶¨Ç°×º³¤¶È*/

+    void * at_cmd_prefix = NULL;

+    /* atǰ׺³¤¶È£¬¶ÔÓÚpduÐÅÏ¢£¬Ç°×º³¤¶ÈΪ0£¬´Ëʱat_cmd_prefixΪ¿Õ*/

+    int prefix_len = 0;

+    /* atÃüÁî²ÎÊýÆðʼλÖã¬Ö±½ÓÖ¸ÏòatÃüÁîËùÔÚÄڴ棬µ±atÃüÁî²»´æÔÚ²ÎÊýʱ£¬at_cmd_parasΪnull£¬paras_lenΪ0*/

+    void * at_cmd_paras = NULL;

+    /* atÃüÁî²ÎÊý³¤¶È£¬¿ÉÒÔΪ0*/

+    int paras_len = 0;

+    /* ½âÎöATÃüÁîǰ׺ÐÅÏ¢£¬Ê¶±ð³öǰ׺ÄÚÈݼ°ATÀàÐÍ*/

+    at_str_type = parase_at_cmd(at_str, &at_cmd_prefix, &prefix_len, &at_cmd_paras, &paras_len);

+	printf("\r\nat_demo rcv_at_str_handle type=%d AT=%s\r\n", at_str_type, at_str);

+

+	if(at_str_type == AT_TYPE_REQUEST)//ÇëÇóÀàÃüÁî´¦Àí

+	{

+		rcv_at_req_handle(at_fd, at_str, at_cmd_prefix, prefix_len, at_cmd_paras, paras_len);

+		return;

+	}

+	//ÏìÓ¦ÀàÃüÁî´¦Àí

+	if(at_str_type == AT_TYPE_RESPONSE_OK || at_str_type == AT_TYPE_RESPONSE_ERR)

+	{

+		//ͨ¹ýfd²éÕÒÉÏÏÂÎÄ£¬Èç¹û¿ÉÒÔÕÒµ½ËµÃ÷Êǵ÷ÓÃget_modem_info½Ó¿ÚµÄÃüÁîµÄÏìÓ¦£¬ÐèÒª·µ»ØÏìÓ¦ÏûÏ¢

+		struct at_context *context = find_context_by_fd(NEAR_PS, at_fd);

+		if(context != NULL && strlen(context->send_req_cmd_prefix) != 0)

+		{

+			at_send_msg(MODULE_ID_AT_CLIENT, context->clt_source_id, MSG_CMD_SEND_AT_MSG_RSP, strlen(at_str), at_str, 0); 			

+				

+			struct itimerval val;

+			memset(context->send_req_cmd_prefix, 0x00, sizeof(context->send_req_cmd_prefix));

+			context->state ^= SEND_REQ_NOW; //Çå¿Õλͼ

+			context->clt_source_id = 0;

+			//ÆÁ±Î¶¨Ê±Æ÷,it_valueºÍit_interval¶¼ÇåÁ㣬±íʾ¶¨Ê±Æ÷È¡Ïû

+			val.it_value.tv_usec = 0;

+			val.it_value.tv_sec = 0;

+			val.it_interval = val.it_value;				

+			setitimer(ITIMER_REAL, &val, 0);

+			//µ±¿Í»§¶ËÉÏÏÂÎı»ÊÍ·Åʱ£¬±éÀú´ýÉêÇëÉÏÏÂÎĵĻº´æÏûÏ¢Á´±í

+			cache_msg_proc();

+		}

+		return;

+	}

+    else if(at_str_type == AT_TYPE_INFORM)//Öмä½á¹ûÒÔ¼°Ö÷¶¯Éϱ¨ÃüÁî´¦Àí

+    {

+    	rcv_at_inform_handle(at_fd, at_str, at_cmd_prefix, prefix_len, at_cmd_paras, paras_len);

+		return;

+    }

+    else if(at_str_type == AT_TYPE_PDU)

+    {

+        //sms

+        return;

+    }

+	/*ÊÕµ½µÚÒ»ÌõATÃüÁî²»ÊÇzmsri˵Ã÷mcuÖØÆôÁË£¬µ«socÃ»ÖØÆô*/

+	at_assert(g_is_poweron);

+}

+

+static char *find_sub_str(const char *pStr, const char *pSubStr,const int strLen)

+{

+    int subStrLen = 0;

+    //int bInSideQuote = FALSE; /* ±ê¼ÇÊÇ·ñÔÚË«ÒýºÅÄÚ */

+    int wIndex = 0;

+    char *pTmpStr = (char *)pStr;

+

+    if ((pStr == NULL) || (pSubStr == NULL) || (strLen <= 0))

+    {

+        return NULL;

+    }

+

+    subStrLen = strlen(pSubStr);

+

+    if (strLen < subStrLen)

+    {

+        return NULL;

+    }

+

+    for (wIndex=0; wIndex<((strLen-subStrLen)+1); wIndex++)

+    {

+        /* ×Ó´®±È½Ï */

+        if (*pTmpStr == *pSubStr)

+        {

+            if (at_strncmp(pTmpStr, pSubStr, (int)subStrLen) == 0)

+            {

+                return pTmpStr;

+            }

+        }

+        pTmpStr++;

+    }

+    return NULL;

+}

+

+static char *is_whole_atcmd(int fd, char *at_str, int len)

+{

+	int totallen = 0;

+	char *whole_store_cmd = NULL;

+	struct at_context *context = find_context_by_fd(NEAR_PS, fd);

+	if(context == NULL)

+		return NULL;

+	

+	totallen = strlen(context->store_cmd)+len;

+	//µ±×ܳ¤¶È´óÓÚ2kʱºò£¬Ö±½Ó½øÈë´íÎó´¦Àí

+	if(totallen >= AT_CMD_MAX)

+	{

+		printf("recv data is too long and abandon!!!!\n");

+		//·µ»Ø´íÎó¸øÍⲿ

+		char *err_str = at_err_build(ATERR_STR_TOO_LONG);

+		at_write(fd, err_str, strlen(err_str));

+		free(err_str);

+		memset(context->store_cmd, 0, AT_CMD_MAX);

+		return NULL;

+	}

+	whole_store_cmd = (char *)malloc(totallen+1);

+	if(whole_store_cmd == NULL)

+	{

+		at_assert(0);

+	}

+	memset(whole_store_cmd, 0, totallen+1);

+	//ÊÕµ½µÄÊý¾ÝºÍ»º´æµÄÊý¾Ý½øÐÐÆ´½Ó

+	memcpy(whole_store_cmd, context->store_cmd, strlen(context->store_cmd));

+	memcpy(whole_store_cmd+strlen(whole_store_cmd), at_str, len);

+	memset(context->store_cmd, 0, AT_CMD_MAX);

+	return whole_store_cmd;

+

+}

+

+/* ´ÓÖÐÐË΢SOCÊÕµ½ATÃüÁî²ð·ÖºÍ»º´æ´¦Àíº¯Êý*/

+int rcv_at_str_proc(int at_fd, char *at_str, int at_len)

+{

+	char *whole_cmd_str = NULL;

+    char *next_str = at_str;

+    char *next_str_rn = NULL;

+	char *pdu_str = NULL;

+    char *next_str_r = NULL;

+    char *next_str_n = NULL;

+    char *pdu_data = NULL;

+

+    printf("rcv_at_str_proc recv fd:%d,len:%d,data:%s\n", at_fd, at_len, at_str);

+    /*Óë֮ǰµÄ·Ö¶ÎAT×Ö·û´®½øÐд®Áª*/

+    if((whole_cmd_str = is_whole_atcmd(at_fd, at_str, at_len)) == NULL)

+    {

+        //at_print(AT_ERR,"ERR: recv incompleted cmd and stored!!\n");

+        return 0;

+    }

+    /*ÒÔ"\r\n""\n""\r"µÈΪ±ß½ç£¬Öð¸öÌáȡÿ¸öATÃüÁ½øÐд¦Àí.ÇëÇóÀàµÄÃüÁî´ø"\r\n"»ò

+    "\r"»ò"\n"½á⣬ÏìÓ¦ÀàÃüÁî¶¼ÊÇÒÔ"\r\n"½áβ*/

+	next_str = whole_cmd_str;

+	while(next_str < whole_cmd_str + strlen(whole_cmd_str))

+    {

+        char *single_at;

+

+        next_str_rn = find_sub_str(next_str,"\r\n",strlen(next_str));

+        next_str_r = find_sub_str(next_str,"\r",strlen(next_str));

+        next_str_n = find_sub_str(next_str,"\n",strlen(next_str));

+		if(next_str_n > (whole_cmd_str + strlen(whole_cmd_str)))

+		{

+			at_assert(0);

+		}

+        //ÏÂÒ»¸öATÃüÁîÊÇÒÔ"\r\n"½áβ

+        if((next_str_rn!=NULL)&&(next_str_r!=NULL)&&(next_str_rn==next_str_r)&&(next_str_rn<next_str_n))

+        {

+            //AT´®Í·²¿Îª"\r\n"£¬Ìø¹ý

+            if(next_str == next_str_rn)

+            {               

+                next_str += 2;

+				continue;

+            }

+            single_at = (char *)malloc(next_str_rn-next_str+1);

+			memset(single_at, 0x00, next_str_rn-next_str+1);

+            memcpy(single_at, next_str,next_str_rn-next_str);           

+			rcv_at_str_handle(at_fd, single_at);

+			free(single_at);

+            next_str = next_str_rn+2;

+        }

+        //ÏÂÒ»¸öATÃüÁîÊÇÒÔ"\n"½áβ

+        else if((next_str_n!=NULL)&&(next_str_rn>next_str_n || next_str_rn==NULL)&&(next_str_r>next_str_n || next_str_r==NULL))

+        {

+            //¿ÕµÄ"\n"Ìø¹ý£¬³£¼ûÓÚÉϴνضÏΪ'\r'Ϊ½áÊøÇé¿ö

+            if(next_str == next_str_n)

+            {

+                next_str++;

+                continue;

+            }

+            single_at = (char *)malloc(next_str_n-next_str+1);

+			memset(single_at, 0x00, next_str_n-next_str+1);

+			memcpy(single_at, next_str,next_str_n-next_str);

+			rcv_at_str_handle(at_fd, single_at);

+			free(single_at);

+            next_str = next_str_n+1;

+        }

+        //ÏÂÒ»¸öATÃüÁîÊÇÒÔ"\r"½áβ,ºóÃæµÄ'\n'»¹Ã»ÊÕµ½£¬´ËʱҲµ±³ÉÍê³ÉATµ¥ÌõÃüÁî´¦Àí£¬²»ÖªÊÇ·ñÓÐÎÊÌâ

+        else if((next_str_r!=NULL)&&(next_str_rn>next_str_r || next_str_rn==NULL)&&(next_str_r<next_str_n || next_str_n==NULL))

+        {

+            //¿ÕµÄ"\r"Ìø¹ý£¬³£¼ûÓÚ×îºóÒ»¸öAT´®½Ø¶Ï£¬Ï´ÎÊ××Ö·ûΪ'\n'

+            if(next_str == next_str_r)

+            {

+                next_str ++;

+                continue;

+            }

+            single_at = (char *)malloc(next_str_r-next_str+1);

+			memset(single_at, 0x00, next_str_r-next_str+1);

+			memcpy(single_at, next_str,next_str_r-next_str);

+			rcv_at_str_handle(at_fd, single_at);

+			free(single_at);

+            next_str = next_str_r+1;

+        }

+		

+		else if(next_str_rn == NULL && next_str_r == NULL && next_str_n == NULL)//Ç°ÃæÓÐ/r/nµ«ºóÃæÃ»ÓеÄ

+		{

+			break;

+		}

+		else

+		{

+			at_assert(0);

+		}

+    }

+    //µ±×îºóµÄβ²¿Îª"\r\n"»ò"\r"ʱ£¬ÐèÒª½«¸Ãβ²¿±£´æ

+    if(whole_cmd_str+strlen(whole_cmd_str)-next_str > 0)

+    {

+		struct at_context *context = find_context_by_fd(NEAR_PS, at_fd);

+		if(context == NULL)

+			at_assert(0);

+		unsigned int store_len = whole_cmd_str+strlen(whole_cmd_str)-next_str;

+		store_len = store_len<(AT_CMD_MAX)?store_len:(AT_CMD_MAX-1);

+		memcpy(context->store_cmd, next_str, store_len);

+    }

+	return 0;

+}

+

+//µÈ´ýAT½á¹û³¬Ê±´¦Àíº¯Êý

+void at_timeout_handle(int signo)

+{

+	//·¢Ëͳ¬Ê±´¦ÀíÏûÏ¢¸øÖ÷Ï̴߳¦Àí

+	at_send_msg(MODULE_ID_AT_CLIENT, MODULE_ID_AT_CLIENT, MSG_CMD_SEND_WAIT_RSP_TIMEOUT, 0, NULL, 0);			

+}

+

+

+//¼ì²éÊÇ·ñÊÇÌØÊâÃüÁî

+static int check_special_cmd(struct at_context *context, char *at_str)

+{

+	if(strstr(at_str,"AT+ZSETOUT"))//Çл»AT¿ÚΪLOGÊä³ö¿Ú

+	{	

+		int opt = 0;

+		void *p[1] = {&opt};

+		struct itimerval val;

+		parse_param("%d", at_str+strlen("AT+ZSETOUT")+1, p);

+

+		if(1 == opt)//Çл»µ½AT¿ÚÍÂLOG״̬

+		{

+			g_is_log_state = 1;

+			//Çå³ýµ±Ç°Í¨µÀ¼Ç¼µÄATÃüÁîÐÅÏ¢

+			if(strlen(context->send_req_cmd_prefix) != 0)

+			{

+				memset(context->send_req_cmd_prefix, 0x00, sizeof(context->send_req_cmd_prefix));

+				context->clt_source_id = 0;

+				//ÆÁ±Î¶¨Ê±Æ÷

+				val.it_value.tv_usec = 0;

+				val.it_value.tv_sec = 0;

+				val.it_interval = val.it_value;				

+				setitimer(ITIMER_REAL, &val, 0);	

+			}

+		}

+		else if(g_is_log_state && 0 == opt)//ͨµÀ״̬»¹Ô­Îª¿É·¢ËÍATÃüÁî̬				

+		{

+			g_is_log_state = 0;

+		}					

+		at_write(context->fd, at_str, strlen(at_str));

+		return 1;

+	}

+	return 0;

+}

+

+

+/* ´ÓÖÐÐË΢SOCÊÕµ½ATÃüÁî²ð·ÖºÍ»º´æ´¦Àíº¯Êý*/

+void rcv_app_req_proc(MSG_BUF stMsg)

+{

+	struct app_req *appReq = (struct app_req*)(stMsg.aucDataBuf);

+	char *at_str = (char*)appReq->atstr;

+	long timeout_ms = appReq->timeout;//µ¥Î»ÎªºÁÃë

+	struct at_context *context = NULL;

+

+	//Ïòsoc·¢ËÍÃüÁîʱÉêÇëÉÏÏÂÎÄ

+	context = alloc_context_by_position(NEAR_PS, SEND_REQ_NOW);

+	

+	if(context == NULL)

+	{

+		printf("at_context_clt_req_resend \n");

+		/* Èç¹ûͨµÀ¼°ÉÏÏÂÎĽڵãÉêÇëʧ°Ü£¬ÔòÌí¼ÓÏûÏ¢µ½»º´æµÈ´ýÁ´±íÖÐ*/

+		add_one_cache_msg(&stMsg);

+		return;

+	}

+

+	//ÅжÏÊÇ·ñÊÇÌØÊâ´¦ÀíµÄÃüÁÈç¹ûÊÇÔòÖ±½Ó´¦Àíºó·µ»Ø

+	if(check_special_cmd(context, at_str))

+	{

+		return;

+	}

+	else//·ñÔò°´ÕÕÒ»°ãÃüÁî½øÐд¦Àí

+	{

+		void * at_cmd_prefix = NULL;

+	    /* atǰ׺³¤¶È£¬¶ÔÓÚpduÐÅÏ¢£¬Ç°×º³¤¶ÈΪ0£¬´Ëʱat_cmd_prefixΪ¿Õ*/

+	    int prefix_len = 0;

+	    /* atÃüÁî²ÎÊýÆðʼλÖã¬Ö±½ÓÖ¸ÏòatÃüÁîËùÔÚÄڴ棬µ±atÃüÁî²»´æÔÚ²ÎÊýʱ£¬at_cmd_parasΪnull£¬paras_lenΪ0*/

+	    void * at_cmd_paras = NULL;

+	    /* atÃüÁî²ÎÊý³¤¶È£¬¿ÉÒÔΪ0*/

+	    int paras_len = 0;

+		struct itimerval val;

+		/*ATÃüÁî±ØÐë°üº¬»Ø³µ·û*/

+		at_assert(strstr(at_str,"\r") != NULL); 

+		//½âÎö³öǰ׺

+		parase_at_cmd(at_str, &at_cmd_prefix, &prefix_len, &at_cmd_paras, &paras_len);

+		//±£´æÇ°×º£¬Ô´Ä£¿éid

+		memcpy(context->send_req_cmd_prefix, (char *)at_cmd_prefix, prefix_len);

+		context->clt_source_id = stMsg.usSourceModuleID;

+		//ÍùͨµÀдÊý¾Ý

+		at_write_by_ctx(context, at_str, strlen(at_str));

+

+		//×¢²áÐźÅ

+		signal(SIGALRM, at_timeout_handle);

+		//ÉèÖö¨Ê±Æ÷

+		val.it_value.tv_usec = timeout_ms%1000*1000;

+		val.it_value.tv_sec = timeout_ms/1000;

+		val.it_interval.tv_usec = 0;

+		val.it_interval.tv_sec = 0;//¶¨Ê±Æ÷½öÆôÒ»´Î

+		setitimer(ITIMER_REAL, &val, 0);		

+	}

+

+}

+

+

+//¶ÁÏß³ÌÖ÷º¯Êý£¬½«´ÓÖÐÐË΢SOC¶Áµ½µÄATÊý¾ÝÏûÏ¢·¢Ë͸øÖ÷Ïß³Ì

+void recv_mainloop(int fd)

+{

+    char buf[AT_CMD_MAX] = {0};

+    struct at_msg_data msg = {0};

+    int ret = 0;

+    int datalen = 0;

+	while(1)

+	{

+	    datalen = at_read(fd, buf, sizeof(buf));

+	    if(datalen <= 0)

+	    {

+	        printf("\r\nat_demo read %d fd=%d ret= %d", g_fd, fd, datalen);

+			continue;

+	    }

+	    

+	    msg.at_str = malloc(datalen+1);

+	    if(NULL == msg.at_str)

+	    {

+	        at_assert(0);

+	    }

+	    memset(msg.at_str, 0x00, datalen+1);

+	    memcpy(msg.at_str, buf, datalen);

+	    msg.at_len = datalen;

+		msg.at_fd = fd;

+		printf("\r\nat_demo read at=%s", msg.at_str);

+		//½«ÊÕµ½µÄÊý¾Ý·¢¸øÖ÷Ï̴߳¦Àí

+	    ret = at_send_msg(MODULE_ID_AT_CLIENT, MODULE_ID_AT_CLIENT, MSG_CMD_RCV_TTY_STR, sizeof(struct at_msg_data), (unsigned char *)&msg, 0);

+	    if(ret < 0)

+	    {

+	        at_assert(0);

+	    }

+	}

+}

+

+//mcuÖÐÓ¦ÓÃÏòÖÐÐË΢soc·¢ËÍÏìÓ¦½á¹û»òÕßÖ÷¶¯Éϱ¨ÃüÁîµÄ´¦Àíº¯Êý

+static void proc_send_rsp_msg(MSG_BUF *pMsg)

+{

+	char *at_str = (char*)(pMsg->aucDataBuf);

+	int at_len = pMsg->usDataLen;

+

+	struct at_context *ser_ctx = NULL;

+	//¸ù¾ÝÄ£¿éid£¬Ñ°ÕÒÉÏÏÂÎÄ

+	ser_ctx = find_context_by_moduleid(NEAR_PS, pMsg->usSourceModuleID);

+

+	//serverÉÏÏÂÎÄ´æÔÚ£¬·¢ËÍÓ¦Óýø³ÌµÄÒì²½Ó¦´ð

+	if(ser_ctx)

+	{

+		at_write_by_ctx(ser_ctx, at_str, at_len);

+		//Õë¶Ô»Ø¸´µÄÄÚÈÝΪOK»òÕßERROR£¬ÐèÒªÇé¿öÉÏÏÂÎÄÖеÄÐÅÏ¢

+		if(strstr(at_str, "\r\nOK\r\n") != NULL || strstr(at_str, "ERROR") != NULL)

+		{

+			//Çå¿ÕÐÅÏ¢

+			ser_ctx->state ^= (RCV_REQ_NOW);

+			memset(ser_ctx->rcv_req_cmd_prefix, 0, AT_CMD_PREFIX);

+			ser_ctx->svr_dest_id = 0;

+		}

+	}

+	//serverÉÏÏÂÎIJ»´æÔÚ£¬ÊÓΪÖ÷¶¯Éϱ¨ÄÚÈÝ

+	else

+	{

+		//¹ã²¥Ó¦Óýø³ÌµÄÖ÷¶¯Éϱ¨

+		write_all_nearps_fd(at_str, at_len);

+	}			

+}

+

+//µ÷ÓÃget_modem_info½Ó¿ÚÏòsoc·¢ËÍÇëÇóÃüÁʱºó£¬ÐèÒªat_client·µ»Ø´íÎóÂ룬ÖÕÖ¹get_modem_info½Ó¿ÚÖеÄÑ­»·

+static void proc_wait_rsp_timeout()

+{

+	//¸ù¾Ýfd²éÕÒÓëÆä°ó¶¨µÄÉÏÏÂÎÄ

+	struct at_context *context = find_context_by_fd(NEAR_PS, g_fd);

+	if(context != NULL && strlen(context->send_req_cmd_prefix) != 0)

+	{

+		//ÃüÁî·¢Ëͳ¬Ê±£¬·µ»Ø´íÎóÂë

+		char *at_str = at_err_build(ATERR_WAIT_RSP_TIMEOUT);

+		at_send_msg(MODULE_ID_AT_CLIENT, context->clt_source_id, MSG_CMD_SEND_AT_MSG_RSP, strlen(at_str), at_str, 0);			

+		free(at_str);

+		//Çå¿Õ±£´æµÄÐÅÏ¢

+		memset(context->send_req_cmd_prefix, 0x00, sizeof(context->send_req_cmd_prefix));

+		context->state ^= SEND_REQ_NOW; //Çå¿Õλͼ

+		context->clt_source_id = 0;

+	}

+}

+

+/*Ö÷º¯Êý£¬³õʼ»¯³É¹¦ºó½ÓÊÕ²¢´¦ÀíÏûÏ¢*/

+int main()

+{ 

+    MSG_BUF stMsg;

+    long msgSize =  sizeof(MSG_BUF)-sizeof(long);

+    int msgHandle = 0;

+    int ret = 0;

+	char* at_str;

+	struct at_msg_data * msg_data = NULL;

+

+    /* ´´½¨ÏûÏ¢¶ÓÁÐ*/

+    msgHandle = at_create_msg_queue(MODULE_ID_AT_CLIENT);

+	at_channel_init();

+	//´´½¨½ÓÊÕmcuÓësoc¶Ô½ÓͨµÀµÄÊý¾ÝµÄỊ̈߳¬ÓÉÓÚĿǰ½öÓÐÒ»¸öͨµÀ£¬Òò´Ë¸Ã×ÓÏ߳̽ö½ÓÊÕͨµÀg_fdµÄÊý¾Ý

+	ret = at_create_thread(recv_mainloop, g_fd);

+	at_assert(ret == 0);

+	

+	while(1)

+    {

+        ret = 0;

+        memset(&stMsg, 0x00, sizeof(MSG_BUF));

+        /* »ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí*/

+        ret = at_recv_msg(msgHandle, &stMsg, msgSize, 0);

+		printf("\r\nat_demo recv_msg id=%d", stMsg.usMsgCmd);

+		

+        if (ret >= 0)

+        {

+           switch (stMsg.usMsgCmd)

+	    	{

+			case MSG_CMD_SEND_AT_TO_ZTE:/* Ö±½Ó·¢ËÍATÃüÁîÇëÇó,Óëget_modem_info½Ó¿Ú½»»¥*/			

+

+			

+				printf("recv MSG_CMD_SEND_AT_REQ g_is_poweron=%d\n",g_is_poweron);

+				if(0 == g_is_poweron)//δÊÕµ½ÖÐÐË΢µÄµÚÒ»Ìõ¿ª»úÃüÁîzmsri£¬²»ÔÊÐí·¢ËÍATÃüÁî

+				{				

+					printf("\r\g_is_poweron ==0");

+					at_send_msg(MODULE_ID_AT_CLIENT, stMsg.usSourceModuleID, MSG_CMD_SEND_AT_MSG_RSP, strlen("+CME ERROR:3"), "+CME ERROR:3", 0); 		

+					

+				}

+				else

+				{

+					rcv_app_req_proc(stMsg);

+				}

+				

+				break;

+            case MSG_CMD_SEND_RSP_TO_ZTE://ÆäËûÓ¦ÓÃÍùsocдÊý¾Ý

+				proc_send_rsp_msg(&stMsg);

+                break;

+			case MSG_CMD_RCV_TTY_STR:/* ttyͨµÀÏûÏ¢´¦Àí¡£ÄÚÈÝÊÇ´ÓttyͨµÀ¶Áµ½µÄÊý¾Ý*/

+				msg_data = (struct at_msg_data *)(stMsg.aucDataBuf);

+				if(g_is_log_state)

+				{

+					printf("\r\nat_demo ttyrcv %s", (char *)msg_data->at_str);

+				}

+				else

+				{

+					rcv_at_str_proc(msg_data->at_fd, (char *)msg_data->at_str, msg_data->at_len);

+				}

+				free(msg_data->at_str);

+				break;

+			case MSG_CMD_SEND_WAIT_RSP_TIMEOUT://·¢¸øsocÇëÇóÃüÁʱ´¦ÀíÏûÏ¢µÄ´¦Àí

+				proc_wait_rsp_timeout();

+				break;

+			default:				         	

+				printf("\r\nat_demo recv_msg default\r\n");

+				break;

+	        }

+		}

+        else

+        {

+			at_assert(0);

+        }

+		

+	}

+}

+

+

+

+

diff --git a/ap/app/at_demo/at_client/at_com.h b/ap/app/at_demo/at_client/at_com.h
new file mode 100644
index 0000000..224b5e7
--- /dev/null
+++ b/ap/app/at_demo/at_client/at_com.h
@@ -0,0 +1,91 @@
+/************************************************************************************

+demoÓ¦Óà ͨÓÃÍ·Îļþ

+***************************************************************************************/

+#include "at_api.h"

+

+

+#ifndef _AT_COM_H

+#define _AT_COM_H

+

+#define AT_CMD_PREFIX 		64			//ATǰ׺×î´ó³¤¶È

+#define AT_CMD_MAX 			2048		//µ¥ÌõATÃüÁî×î´ó³¤¶È

+

+

+#define MAXSTR(x, y)           ((strlen(x)>y)?strlen(x):y)

+

+//¶ÔÓÚÉϱ¨atÃüÁî´¦Àíº¯Êý£¬°üº¬¿Í»§¶ËÊÕµ½µÄOK/ERRÓ¦´ðºÍ²éѯÖмä½á¹ûºÍÖ÷¶¯Éϱ¨µÄatÃüÁî´¦Àí

+typedef int (*clt_act_func)(char *at_paras);

+

+typedef int (*ser_req_func)(char *at_paras, void ** res_msg);

+

+typedef void (*start_fnc)(void *arg);

+

+//ATÏìÓ¦ÀàÐÍ	

+enum AT_TYPE{

+	AT_TYPE_REQUEST,        /*ÇëÇó*/

+	AT_TYPE_RESPONSE_OK,	/* ÏìÓ¦OK*/

+	AT_TYPE_RESPONSE_ERR,	/* ÏìÓ¦ERR*/

+	AT_TYPE_INFORM, 	 	/* Ö÷¶¯Éϱ¨»òÖмä½á¹û*/

+	AT_TYPE_PDU,		 	/* ¶ÌÐÅPDU*/

+};

+

+

+//AT¿Í»§¶Ë´¥·¢µÄATÇëÇóÃüÁîµÄʼþ½á¹¹Ìå

+struct ind_ops_t

+{

+	char at_cmd_prefix[AT_CMD_PREFIX];//ATÃüÁîǰ׺×Ö·û´®£¬ÓÃÓÚ±éÀúÆ¥Å䣬һ°ãÓÃÓÚ»ñÈ¡Ö÷¶¯Éϱ¨func

+	clt_act_func inform_act;//¶Ô¸Ã½ÓÊÕµ½µÄATÖ÷¶¯Éϱ¨µÄ´¦Àíº¯Êý£¬¿É·¢ËÍÏà¹ØÍ¨ÖªÏûÏ¢

+};

+

+struct ser_ops_t

+{

+    char at_cmd_prefix[AT_CMD_PREFIX];  //ÓÃÓÚÆ¥ÅäµÄATÃüÁî¹Ø¼ü×Ö

+    int  module_id;						//·þÎñ¶ËAPP¶ÔÓ¦µÄÄ£¿éID£¬ÓÃÓÚÇëÇóÏûÏ¢µÄÉϱ¨£¬¿Í»§¶þ´Î¿ª·¢×¢²áµÄ·þÎñÆ÷£¬±ØÐëΪÍⲿģ¿éµÄID

+	ser_req_func req_rcv_act;      	//¶Ô½ÓÊÕµ½µÄÔ¶¶ËÇëÇóµÄ´¦Àí½Ó¿Ú£¬Èô¿ÉÒÔ±¾µØ´¦Àí£¬ÔòÁ¢¼´´¦Àí²¢×é×°Ó¦´ð±¨ÎÄ£¬²¢·µ»Ø¸Ã±¨ÎĵÄÄÚ´æÖ¸Õë¸øÍⲿµ÷Óú¯Êý£¬ÎÞÐë´´½¨ÉÏÏÂÎÄ£»·ñÔò£¬´´½¨ÉÏÏÂÎĺÍÕ¼ÓÃͨµÀ,½«ÃüÁîת·¢¸øÓ¦Óã¬Óɿͻ§Ó¦Óýø³ÌÒì²½·½Ê½´¦Àí£¬ÖÁÓÚÈçºÎͨÐÅ´¦Àí£¬Óɿͻ§×ÔÐÐʵÏÖ

+};

+

+

+struct at_msg_data

+{

+    char *at_str;

+    int at_len;

+	int at_fd;

+};

+

+enum at_context_state {

+	AT_END = 0, //ATÁ÷³Ì½áÊø£¬¿Í»§¶Ë¿ÉÒÔÏòÉϲãapp·¢ËÍÏìÓ¦ÏûÏ¢£¬·þÎñ¶ËÐèÒªÏòatͨµÀ·¢ËÍatÏìÓ¦ÃüÁî

+	AT_CONTINUE,//AT½»»¥Á÷³Ì¼ÌÐø

+	AT_END_AND_MSG,//ÓÃÓÚ·þÎñ¶ËÊÕµ½ATÇëÇóºó£¬Á¢¼´»Ø¸´OK½á¹ûÂ룬ͬʱ»¹Ðè·¢ËÍÏûÏ¢¸ø·þÎñ¶ËAPP

+	AT_WAIT_AUTO,//ÓÃÓÚÊÕµ½Ó¦´ðºó£¬ÉÐδ»ñÈ¡µ½ÏëÒªµÄÖ÷¶¯Éϱ¨Ê±£¬·µ»Ø¸ÃÖµ£»Ä¿Ç°½öÓÃÓÚPDP¼¤»îµÄzgipdnsÖ÷¶¯Éϱ¨³ÙÓÚOKºóÉϱ¨µÄÇé¿ö

+	AT_STATE_MAX,//ÉÏÏÞºê

+};

+

+

+

+//atÃüÁîÆ¥ÅäÅжÏ,´óСд¼æÈÝ£¬¸ù¾Ý½âÎö³öÀ´µÄǰ׺³¤¶È£¬½«atǰ׺ºÍ×¢²áµÄǰ׺½øÐÐÆ¥Å䣬±ØÐëÍêȫƥÅä²Å·µ»Ø1

+int is_match_at_cmd(const char * pstrAtCmdPrefix, void * at_cmd, int at_data_len);

+

+//¸ù¾Ý¿Í»§¶ËÇëÇóÀàatÃüÁîµÄǰ׺²éÕÒ¶ÔÓ¦²Ù×÷½Úµã

+struct ind_ops_t* find_autoinfo_by_prefix(void *at_cmd_prefix, int prefix_len);

+

+int at_strncmp(const char *dest, const char *source, int size);

+

+char* at_err_build(int param);

+int ext_req_to_app(int at_fd, char *at_str, void *at_cmd_prefix, int prefix_len, char *at_cmd_paras);

+

+

+//ͨÓÃÊÊÅä½Ó¿Ú£¬Ïê¼ûat_arch.c

+int at_open(char *name);

+int at_read(int fd,char *buf,int len);

+int at_write(int fd,char *buf,int len);

+int at_close(int handle);

+int at_create_msg_queue(int id);

+int at_recv_msg(int msqid, void *msgp, int msgsz, int timeout);

+int at_create_thread(start_fnc entry_fnc,void *arg);

+void at_sleep(unsigned int time_in_ms);

+int at_get_currtime(void);

+int add_one_cache_msg(MSG_BUF *msg);

+void cache_msg_proc(void);

+

+#endif //_AT_COM_H

+

diff --git a/ap/app/at_demo/at_client/at_context.c b/ap/app/at_demo/at_client/at_context.c
new file mode 100644
index 0000000..d9ff8a7
--- /dev/null
+++ b/ap/app/at_demo/at_client/at_context.c
@@ -0,0 +1,126 @@
+#include "at_context.h"

+extern int g_fd;

+

+struct at_context nearps_ctx[NEAR_PS_CXT_MAX] = {0};

+//struct at_context *near_ps[NEAR_PS_CXT_MAX] = {&nearps_ctx};

+

+int at_write_by_ctx(struct at_context *ctx, const void *buf, int size)

+{

+	int ret = -1;

+	//char *time_str;

+	at_assert(size != 0);

+	if (ctx) {

+		if (ctx->position == NEAR_PS) {

+            ret = at_write(ctx->fd, buf, size);

+			//time_str = at_time_record(buf, 0);

+		}

+	}

+	return ret;

+}

+

+//¼ì²âµ±Ç°ÉÏÏÂÎÄÊÇ·ñ´¦ÓÚij״̬æ

+int  is_at_ctx_busy(int position, int state)

+{

+	if (position == NEAR_PS)

+		return (nearps_ctx[0].state & state);

+	

+}

+

+//ͨµÀ³õʼ»¯£¬fdºÍcontext°ó¶¨

+void at_channel_init()

+{

+	int i = 0;

+	//int at_fd = 0;

+	for(i=0;i<NEAR_PS_CXT_MAX;i++)

+	{

+		nearps_ctx[i].fd = at_open("/dev/ttyS0");//´Ë´¦ÌØÊâ¶¨ÖÆ£¬´ò¿ªuart0

+		g_fd = nearps_ctx[i].fd; //ÓÉÓÚĿǰ½öÓÐÒ»¸öͨµÀ£¬Òò´Ë´Ë´Î½«´ò¿ªµÄfdÖ±½Ó´æµ½È«¾Ö±äÁ¿ÖÐ

+		nearps_ctx[i].position = NEAR_PS;

+		//´Ë´¦ÌØÊâ¶¨ÖÆ,killµôat_ctl£¬·ÀÖ¹at_ctlÕ¼ÓÃuartͨµÀ

+		system("killall -9 at_ctl");

+	}

+}

+

+//ͨ¹ýpositionÉêÇëÉÏÏÂÎÄ

+struct at_context *alloc_context_by_position(int position, int state)

+{

+	int i = 0;

+	if(position == NEAR_PS)

+	{

+		for(i=0;i<NEAR_PS_CXT_MAX;i++)

+		{

+			if((nearps_ctx[i].state & state) == 0)

+			{

+				nearps_ctx[i].state |= state; 

+				return &nearps_ctx[i];

+			}

+		}

+		//return NULL;

+	}

+	return NULL;

+}

+

+//ͨ¹ýfd²éÕÒÓëÆä°ó¶¨µÄcontext

+struct at_context *find_context_by_fd(int position, int at_fd)

+{

+	int i = 0;

+	if(position == NEAR_PS)

+	{

+		for(i=0;i<NEAR_PS_CXT_MAX;i++)

+		{

+			if(nearps_ctx[i].fd == at_fd)

+			{

+				return &nearps_ctx[i];

+			}

+		}

+		//return NULL;

+	}

+	return NULL;

+}

+

+char* at_err_build(int param)

+{

+    char *at_str = NULL;

+	

+    at_str = malloc(32);

+	

+    if(!at_str)

+        return NULL;

+    if(param == 0)

+        sprintf(at_str,"\r\nERROR\r\n");

+    else

+        sprintf(at_str,"\r\n+CME ERROR: %d\r\n",param);

+        

+    return at_str;    

+

+}

+

+//ͨ¹ýÄ£¿éid²éÕÒÓëÆä°ó¶¨µÄcontext£¬Í¨³£ÓÃÓÚÒì²½server´¦Àí£¬ÆäËûÓ¦Ó÷µ»Ø½á¹û¸øsoc

+struct at_context *find_context_by_moduleid(int position, int module_id)

+{

+	int i = 0;

+	if(position == NEAR_PS)

+	{

+		for(i=0;i<NEAR_PS_CXT_MAX;i++)

+		{

+			if(nearps_ctx[i].svr_dest_id == module_id)

+			{

+				return &nearps_ctx[i];

+			}

+		}

+		//return NULL;

+	}

+	return NULL;

+}

+

+//ÏòËùÓеÄnear_psͨµÀдÊý¾Ý

+void write_all_nearps_fd(char *at_str, int at_len)

+{

+	int i = 0;

+	for(i=0;i<NEAR_PS_CXT_MAX;i++)

+	{

+		at_write_by_ctx(&nearps_ctx[i], at_str, at_len);

+	}

+}

+

+

diff --git a/ap/app/at_demo/at_client/at_context.h b/ap/app/at_demo/at_client/at_context.h
new file mode 100644
index 0000000..1d6789c
--- /dev/null
+++ b/ap/app/at_demo/at_client/at_context.h
@@ -0,0 +1,27 @@
+#ifndef AT_CONTEXT_H_

+#define AT_CONTEXT_H_

+

+#include "at_com.h"

+//λͼ·½Ê½±íʾATͨµÀÕýÔÚ¹¤×÷µÄATÁ÷·½ÏòÊôÐÔ£¬SEND_REQ_NOW±íʾµ±Ç°×÷Ϊ¿Í»§¶Ë¡¢RCV_REQ_NOW±íʾµ±Ç°×÷Ϊ·þÎñ¶Ë

+#define	SEND_REQ_NOW	1

+#define	RCV_REQ_NOW		2

+#define AT_CMD_MAX 	    2048		//µ¥ÌõATÃüÁî×î´ó³¤¶È

+

+//Ö§³ÖATͨµÀ¼°ÉÏÏÂÎĵĸöÊý

+#define	NEAR_PS_CXT_MAX	1

+

+/*******************************************************************************

+ *                             Type definitions                                *

+ ******************************************************************************/

+struct at_context {

+	char send_req_cmd_prefix[AT_CMD_PREFIX];///ËùÓÐATÇëÇóÏà¹ØÇ°×º£¬°üÀ¨±¾µØ·¢ËͺÍÍⲿMCU·¢Ë͵Ä

+	char rcv_req_cmd_prefix[AT_CMD_PREFIX];

+	char store_cmd[AT_CMD_MAX];

+	int position;//λÖ㬶ÔÓ¦ºêÖµNEAR_PS¡¢FAR_PS

+	int state;//ָʾµ±Ç°ÊÇ·ñÕýÔÚ±»Ê¹Ó㬲μûºêÖµSEND_REQ_NOW

+	int fd;//ÎïÀíͨµÀ±êʶ

+	int clt_source_id; //×÷ΪclientʱԴģ¿éid£¨Ö÷ÒªÊǵ÷ÓÃget_modem_infoʱµÄÔ´Ä£¿é£©

+	int svr_dest_id; //×öserverʱºòµÄÄ¿µÄÄ£¿éid

+};

+

+#endif

diff --git a/ap/app/at_demo/at_client/at_list.h b/ap/app/at_demo/at_client/at_list.h
new file mode 100644
index 0000000..aac4e29
--- /dev/null
+++ b/ap/app/at_demo/at_client/at_list.h
@@ -0,0 +1,234 @@
+#ifndef _AT_LIST_H__
+#define _AT_LIST_H__
+
+#undef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ *
+ * @ptr:    the pointer to the member.
+ * @type:   the type of the container struct this is embedded in.
+ * @member: the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({          \
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+        (type *)( (char *)__mptr - offsetof(type,member) );})
+
+
+struct list_head {
+	struct list_head *next, *prev;
+};
+
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+	struct list_head name = LIST_HEAD_INIT(name)
+
+static inline void INIT_LIST_HEAD(struct list_head *list)
+{
+	list->next = list;
+	list->prev = list;
+}
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_add(struct list_head *new,
+                              struct list_head *prev,
+                              struct list_head *next)
+{
+	next->prev = new;
+	new->next = next;
+	new->prev = prev;
+	prev->next = new;
+}
+
+/**
+ * list_add - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it after
+ *
+ * Insert a new entry after the specified head.
+ * This is good for implementing stacks.
+ */
+static inline void list_add(struct list_head *new, struct list_head *head)
+{
+	__list_add(new, head, head->next);
+}
+
+
+/**
+ * list_add_tail - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it before
+ *
+ * Insert a new entry before the specified head.
+ * This is useful for implementing queues.
+ */
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
+{
+	__list_add(new, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_del(struct list_head * prev, struct list_head * next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+/**
+ * list_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ * Note: list_empty() on entry does not return true after this, the entry is
+ * in an undefined state.
+ */
+static inline void __list_del_entry(struct list_head *entry)
+{
+	__list_del(entry->prev, entry->next);
+}
+
+#define LIST_POISON1 0
+#define LIST_POISON2 0
+
+static inline void list_del(struct list_head *entry)
+{
+	__list_del(entry->prev, entry->next);
+	entry->next = LIST_POISON1;
+	entry->prev = LIST_POISON2;
+}
+
+/**
+ * list_replace - replace old entry by new one
+ * @old : the element to be replaced
+ * @new : the new element to insert
+ *
+ * If @old was empty, it will be overwritten.
+ */
+static inline void list_replace(struct list_head *old,
+                                struct list_head *new)
+{
+	new->next = old->next;
+	new->next->prev = new;
+	new->prev = old->prev;
+	new->prev->next = new;
+}
+
+static inline void list_replace_init(struct list_head *old,
+                                     struct list_head *new)
+{
+	list_replace(old, new);
+	INIT_LIST_HEAD(old);
+}
+
+/**
+ * list_del_init - deletes entry from list and reinitialize it.
+ * @entry: the element to delete from the list.
+ */
+static inline void list_del_init(struct list_head *entry)
+{
+	__list_del_entry(entry);
+	INIT_LIST_HEAD(entry);
+}
+
+/**
+ * list_move - delete from one list and add as another's head
+ * @list: the entry to move
+ * @head: the head that will precede our entry
+ */
+static inline void list_move(struct list_head *list, struct list_head *head)
+{
+	__list_del_entry(list);
+	list_add(list, head);
+}
+
+/**
+ * list_move_tail - delete from one list and add as another's tail
+ * @list: the entry to move
+ * @head: the head that will follow our entry
+ */
+static inline void list_move_tail(struct list_head *list,
+                                  struct list_head *head)
+{
+	__list_del_entry(list);
+	list_add_tail(list, head);
+}
+
+/**
+ * list_is_last - tests whether @list is the last entry in list @head
+ * @list: the entry to test
+ * @head: the head of the list
+ */
+static inline int list_is_last(const struct list_head *list,
+                               const struct list_head *head)
+{
+	return list->next == head;
+}
+
+/**
+ * list_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+static inline int list_empty(const struct list_head *head)
+{
+	return head->next == head;
+}
+
+/**
+ * list_is_singular - tests whether a list has just one entry.
+ * @head: the list to test.
+ */
+static inline int list_is_singular(const struct list_head *head)
+{
+	return !list_empty(head) && (head->next == head->prev);
+}
+
+/**
+ * list_entry - get the struct for this entry
+ * @ptr:	the &struct list_head pointer.
+ * @type:	the type of the struct this is embedded in.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_entry(ptr, type, member) \
+	container_of(ptr, type, member)
+
+
+/**
+ * list_for_each	-	iterate over a list
+ * @pos:	the &struct list_head to use as a loop cursor.
+ * @head:	the head for your list.
+ *
+ * This variant doesn't differ from list_for_each() any more.
+ * We don't do prefetching in either case.
+ */
+#define list_for_each(pos, head) \
+	for (pos = (head)->next; pos != (head); pos = pos->next)
+
+#define list_for_each_entry(pos, head, member)				\
+        for (pos = list_entry((head)->next, typeof(*pos), member);  \
+             &pos->member != (head);    \
+             pos = list_entry(pos->member.next, typeof(*pos), member))
+
+#define list_for_each_safe(pos, n, head) \
+        for (pos = (head)->next, n = pos->next; pos != (head); \
+            pos = n, n = pos->next)
+
+#define list_for_each_entry_safe(pos, n, head, member)			\
+            for (pos = list_entry((head)->next, typeof(*pos), member),  \
+                n = list_entry(pos->member.next, typeof(*pos), member); \
+                 &pos->member != (head);                    \
+                 pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+#endif
diff --git a/ap/app/at_demo/at_client/at_proc.c b/ap/app/at_demo/at_client/at_proc.c
new file mode 100644
index 0000000..1be5a2a
--- /dev/null
+++ b/ap/app/at_demo/at_client/at_proc.c
@@ -0,0 +1,158 @@
+/************************************************************************************

+demoÓ¦Óà AT×¢²áºÍ´¦Àí

+***************************************************************************************/

+

+#include "at_list.h"

+#include "at_com.h"

+

+

+/* µ±Ç°ÇëÇ󻺴æ¶ÓÁУ¬ÓÉÓÚ¿Í»§¶ËÇëÇóÎÞ·¨·ÖÅäµ½atͨµÀ,½«µ±Ç°ÇëÇ󻺴æÔڸöÓÁе±ÖÐ,µ±ÓÐͨµÀÊÍ·Åʱ£¬´¦Àí¸Ã»º´æ¶ÓÁÐ

+*/

+static LIST_HEAD(at_nochannel_waitqueue);

+/* ¶¨Ê±Æ÷³¬Ê±ÏûÏ¢ */

+struct req_waitmsg

+{

+    struct list_head list;

+    MSG_BUF msg_buf;

+};

+#define DIFF_VALUE ('a'-'A')

+

+

+/*¶Ô»º´æÏûÏ¢µÄ´¦Àí£¬ÓÐÒ»¸öµ÷Óõ㣬¾ÍÊÇÓÐͨµÀ±»ÊÍ·Å*/

+void cache_msg_proc(void)

+{

+    struct list_head *head = NULL;

+    struct list_head *pnext = NULL;

+    struct list_head *temp = NULL;

+	struct list_head bak_wait_queue;    

+	//int fwd_fd_temp = fwd_fd;	

+		

+    head = &at_nochannel_waitqueue;

+

+    if(list_empty(head))

+    {

+        printf("ERR: cache_msg_proc is empty\n");

+        return;

+    }

+    else

+    {

+        //½«È«¾ÖÁ´±í¸³Öµ¸øÁÙʱÁ´±íÍ·£¬²¢Çå³ýÔ­È«¾ÖÁ´±íÍ·

+        list_replace_init(&at_nochannel_waitqueue,&bak_wait_queue);

+        head = &bak_wait_queue;

+        pnext = head->next;

+        do

+        {

+            MSG_BUF *msg_buf = NULL;

+            temp = pnext;

+            pnext = pnext->next;

+            list_del(temp);

+            msg_buf = &(((struct req_waitmsg *)temp)->msg_buf);

+            rcv_app_req_proc(msg_buf);

+            free(temp);

+        }

+        while(pnext != head);

+		//»Ö¸´Ö®Ç°±»´ò¶ÏµÄת·¢È«¾Ö

+		//fwd_fd = fwd_fd_temp;

+    }

+    return;

+}

+

+

+/**

+Ìí¼ÓÏûÏ¢µ½»º´æµÈ´ý¶ÓÁУ¬ÔÚͨµÀÊÍ·Åʱºò¼ÌÐø´¦Àí»º´æ¶ÓÁÐÏûÏ¢

+ */

+int add_one_cache_msg(MSG_BUF *msg)

+{

+    struct req_waitmsg *waitmsg = malloc(sizeof(struct req_waitmsg));

+

+    memset(waitmsg, 0x00, sizeof(struct req_waitmsg));

+    memcpy(&waitmsg->msg_buf, msg, sizeof(MSG_BUF));

+    

+    list_add(&waitmsg->list, &at_nochannel_waitqueue);

+    

+    printf("timer list_add  source is %x, cmd is %x!!!\n", msg->usSourceModuleID, msg->usMsgCmd);

+     

+}

+

+/*ÔÚºöÂÔ´óСдµÄǰÌáÏÂ,±È½ÏÁ½×Ö·û´®Ç°size×Ö·ûÊÇ·ñÆ¥Å䣬Èç¹ûÆ¥Åä·µ»Ø0£¬

+Èç¹ûµÚÒ»¸öÈë²Î´óÓÚµÚ¶þ¸öÈë²Î£¬·µ»ØÕýÖµ£¬·ñÔò·µ»Ø¸ºÖµ£»

+¿ÉÓÃÓڱȽÏATÃüÁîÇëÇóǰ׺ºÍÆäÖмä½á¹ûµÄǰ׺ÊÇ·ñÆ¥Å䣬ÀýÈçcops?ºÍCOPSÔÚǰ4¸ö×Ö·ûµÄ±È½Ï*/

+int at_strncmp(const char *dest, const char *source, int size)

+{

+	//int DIFF_VALUE = 'a'-'A';

+    int ch1 = 0;

+    int ch2 = 0;

+

+	if(NULL == dest || NULL == source || size < 0)

+	{

+        return -1;

+    }

+    if(0 == size)

+	{

+        return 0;

+    }

+	//½«Á½×Ö·û´®ÖеĴóС×ÖĸÏÈת»¯³É¶ÔÓ¦µÄСд×Öĸºó±È½Ïǰsize×Ö·û

+	do

+    {

+        if((ch1 = *(unsigned char *)dest) >= 'A' && (ch1 <= 'Z'))

+        {

+            ch1 += DIFF_VALUE;

+        }

+        if((ch2 = *(unsigned char *)source) >= 'A' && (ch2 <= 'Z'))

+        {

+            ch2 += DIFF_VALUE;

+        }

+		dest++;

+		source++;

+    }while(--size && (ch1 == ch2) && ch1 && ch2);

+

+    if(ch1 == ch2)

+		return 0;

+	else

+		return *(--dest) - *(--source);

+

+}

+

+

+//atÃüÁîÆ¥ÅäÅжÏ,´óСд¼æÈÝ£¬¸ù¾Ý½âÎö³öÀ´µÄǰ׺³¤¶È£¬½«atǰ׺ºÍ×¢²áµÄǰ׺½øÐÐÆ¥Å䣬±ØÐëÍêȫƥÅä²Å·µ»Ø1

+int is_match_at_cmd(const char * pstrAtCmdPrefix, void * at_cmd, int at_data_len)

+{

+	int prefix_len;

+    //int DIFF_VALUE = 'a'-'A';

+    int ch1 = 0;

+    int ch2 = 0;

+

+    if(NULL == pstrAtCmdPrefix || NULL == at_cmd)

+    {

+        return 0;

+    }

+

+    //½âÎö³öÀ´µÄǰ׺³¤¶È£¬±ØÐëºÍ×¢²áµÄǰ׺³¤¶ÈÍêȫƥÅ䣬²»Ö§³ÖÄ£ºýÆ¥Å䷽ʽ

+    if(at_data_len != strlen(pstrAtCmdPrefix))

+    {

+        return 0;

+    }

+	prefix_len = strlen(pstrAtCmdPrefix) < at_data_len ? strlen(pstrAtCmdPrefix) : at_data_len;

+

+    do

+    {

+        if((ch1 = *(unsigned char *)pstrAtCmdPrefix++) >= 'A' && (ch1 <= 'Z'))

+        {

+            ch1 += DIFF_VALUE;

+        }

+        if((ch2 = *(unsigned char *)at_cmd++) >= 'A' && (ch2 <= 'Z'))

+        {

+            ch2 += DIFF_VALUE;

+        }

+    }

+    while(prefix_len--&& (ch1 == ch2));

+

+    if(-1 == prefix_len)

+    {

+        return 1;

+    }

+    return 0;

+}

+

+

+

diff --git a/ap/app/at_demo/at_client/at_reg.c b/ap/app/at_demo/at_client/at_reg.c
new file mode 100644
index 0000000..1c7bcb3
--- /dev/null
+++ b/ap/app/at_demo/at_client/at_reg.c
@@ -0,0 +1,157 @@
+/************************************************************************************

+demoÓ¦Óà AT×¢²áºÍ´¦Àí

+***************************************************************************************/

+

+#include "at_com.h"

+#include "at_context.h"

+//#include "at_api.h"

+

+//extern char *g_curr_at_cmd;

+extern int g_is_poweron;

+

+int zmsri_auto_act(char *at_cmd);

+int cgev_auto_act(char *at_cmd);

+int urc_zipstat_func(char *at_paras);

+int urc_ziprecv_func(char *at_paras);

+

+

+/*×¢²áatÖ÷¶¯Éϱ¨´¦Àíº¯Êý*/

+struct ind_ops_t g_autoinfo_proc_arry[]={

+	{"+ZMSRI", zmsri_auto_act},	

+	{"+CGEV",  cgev_auto_act},	

+	{"+ZIPSTAT", urc_zipstat_func},

+	{"+ZIPRECV", urc_ziprecv_func},

+};

+

+//ÓÃÓÚMCU×÷Ϊ·þÎñ¶Ë£¬½ÓÊÕZXIC·¢ËÍÀ´µÄATÇëÇóµÄ´¦Àí

+struct ser_ops_t g_ser_arry[]={

+	

+};

+

+//¸ù¾Ýǰ׺²éÕÒ¶ÔÓ¦´¦Àí½Úµã

+struct ind_ops_t* find_autoinfo_by_prefix(void *at_cmd_prefix, int prefix_len)

+{

+	int tab_idx;

+	

+	for (tab_idx = 0; tab_idx < sizeof(g_autoinfo_proc_arry)/sizeof(struct ind_ops_t); tab_idx++) 

+	{

+		if(is_match_at_cmd(g_autoinfo_proc_arry[tab_idx].at_cmd_prefix, at_cmd_prefix, prefix_len))

+		{

+			return &g_autoinfo_proc_arry[tab_idx];

+		}

+	}

+	return NULL;

+}

+

+int ext_req_to_app(int at_fd, char *at_str, void *at_cmd_prefix, int prefix_len, char *at_cmd_paras)

+{

+	

+	int ret = AT_END;

+	struct at_context *context = NULL;

+	void * res_msg = NULL;

+	int tab_idx;

+	for(tab_idx = 0; tab_idx<sizeof(g_ser_arry)/sizeof(struct ser_ops_t); tab_idx++) 

+	{    

+        //×¢²áµ½g_ser_arryÊý×éµ±ÖеÄǰ׺³¤¶È£¬ÓпÉÄܱȸø¶¨µÄatǰ׺³¤¶ÈÒª³¤

+		if(0 == at_strncmp(g_ser_arry[tab_idx].at_cmd_prefix, (char *)at_cmd_prefix,MAXSTR(g_ser_arry[tab_idx].at_cmd_prefix, prefix_len)))

+		{

+			context = find_context_by_fd(NEAR_PS, at_fd);

+			if(context != NULL && strlen(context->rcv_req_cmd_prefix) != 0)

+			{

+				//»Ø¸´ATͨµÀæ

+				char* err_str = at_err_build(ATERR_CHANNEL_BUSY);

+				at_write(at_fd, err_str,strlen(err_str));

+				free(err_str);

+				return 1;

+			}

+

+			ret = g_ser_arry[tab_idx].req_rcv_act(at_cmd_paras, &res_msg);

+			//Èç¹û¸ÃatÇëÇóÃüÁî¿ÉÒÔͬ²½Ö±½Ó´¦Àí£¬ÔòÔÚreq_rcv_actº¯ÊýÖÐÖ±½Ó´¦Àí£¬Éú³ÉÏìÓ¦atÃüÁîres_msg£¬²¢·µ»ØAT_END

+			if(ret == AT_END)

+			{                

+				if(res_msg == NULL)

+					at_write(at_fd,"\r\nOK\r\n",strlen("\r\nOK\r\n"));

+				else

+				{

+					at_write(at_fd, res_msg,strlen(res_msg));				            

+					free(res_msg);

+					res_msg = NULL;

+				}

+				return 1;

+			}

+			//¶ÔÓÚÒì²½´¦Àí£¬´´½¨·þÎñ¶ËÉÏÏÂÎÄ

+			else if(ret == AT_CONTINUE)

+			{

+				if(res_msg)

+					at_assert(0);

+                if(g_ser_arry[tab_idx].module_id)

+                {                	

+                	//¶ÔÓÚ·þÎñ¶ËÕ¼ÓõÄatͨµÀ£¬¾ßÓжÀÕ¼ÐÔ£¬½öÔÚatͨµÀÒѾ­¹Ø±Õʱ£¬ÉêÇëÉÏÏÂÎIJŻáʧ°Ü£¬Òò´ËÊÍ·ÅÄÚ´æºó£¬Ö±½Ó·µ»Ø¼´¿É£¬ÎÞÐèÔÙ·¢ËÍÏûÏ¢

+                    context->state |= (RCV_REQ_NOW);

+					int store_len = prefix_len<(AT_CMD_PREFIX)?prefix_len:(AT_CMD_PREFIX-1);

+					strncpy(context->rcv_req_cmd_prefix, (char *)at_cmd_prefix, store_len);

+					context->svr_dest_id = g_ser_arry[tab_idx].module_id;

+					return 1;

+                }

+				else

+				{

+					at_assert(0);

+				}

+		    }

+			else

+			{

+				at_assert(0);

+			}

+        }

+    }    

+    return 0;

+}

+

+

+/*Éϵ翪»úÊÕµ½zmsri˵Ã÷ÖÐÐË΢socÒѾ­ready£¬¿ÉÒÔ·¢ËÍATÃüÁî

+½¨Òé¼Ó¸ö¶¨Ê±Åжϣ¬¿ª»úÒ»¶Îʱ¼äδÊÕµ½zmsri£¬ËµÃ÷socÒì³£ÁË*/

+int zmsri_auto_act(char *at_cmd)

+{

+	printf("\r\nrecv zmsri_auto_act");

+	if(g_is_poweron == 0)

+		g_is_poweron = 1;

+	else

+		at_assert(0);	/*ÊÕµ½µÚ¶þÌõÒÔÉÏzmsri˵Ã÷socÖØÆôÁË£¬µ«mcu²»ÖªµÀ£¬ÐèÒªÕû»úÖØÆô½øÐÐ״̬ͬ²½*/

+    at_send_msg(MODULE_ID_AT_CLIENT,MODULE_ID_AT_SOCKET,MSG_CMD_AT_READY_IND, 0, NULL,0);

+    return 0;

+}

+

+//cgev´¦Àí£¬¼à¿Øµ±Ç°¸÷CIDµÄ¼¤»î״̬£¬È¥¼¤»îʱ·¢ËÍÏûÏ¢¶Ï¿ªÍø¿Ú£¬Çå³ý¼¤»î״̬

+int cgev_auto_act(char *at_paras)

+{

+    int c_id = 0;

+    char *strtemp = NULL;

+    if(strstr(at_paras, "PDN ACT ") != NULL)

+    {

+

+    }

+    else if(strstr(at_paras, "PDN DEACT ") != NULL)

+    {

+    	int idx = 0;

+		int is_normal_cid = 0;

+		strtemp = strstr(at_paras, "PDN DEACT ")+strlen("PDN DEACT ");

+		c_id = atoi(strtemp);

+		at_send_msg(MODULE_ID_AT_CLIENT,MODULE_ID_AT_SOCKET,MSG_CMD_PDP_DEACT_IND,0, NULL,0);

+    }

+

+    return 0;

+}

+

+int urc_zipstat_func(char *at_paras)

+{

+	at_send_msg(MODULE_ID_AT_CLIENT,MODULE_ID_AT_SOCKET,AT_SOCKET_ZIPSTAT,strlen(at_paras), (unsigned char *)at_paras,0);

+	return 0;

+}

+

+

+int urc_ziprecv_func(char *at_paras)

+{

+	at_send_msg(MODULE_ID_AT_CLIENT,MODULE_ID_AT_SOCKET,AT_SOCKET_ZIPRECV,strlen(at_paras), (unsigned char *)at_paras,0);

+	return 0;

+}

+

diff --git a/ap/app/at_demo/com/Makefile b/ap/app/at_demo/com/Makefile
new file mode 100644
index 0000000..c26c658
--- /dev/null
+++ b/ap/app/at_demo/com/Makefile
@@ -0,0 +1,31 @@
+#*******************************************************************************
+# include ZTE library makefile
+#*******************************************************************************
+include $(zte_lib_mak)
+
+##############USER COMIZE BEGIN################
+#include ../../net_team.mk
+
+LIB_STATIC = libcom.a
+#LIB_SHARED = libatutils.so
+
+OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
+
+CFLAGS += -g
+
+
+##############USER COMIZE END##################
+CFLAGS += -fPIC
+LDFLAGS += -shared
+
+all: $(LIB_STATIC)
+
+$(LIB_STATIC) : $(OBJS)
+	$(AR) rcs $(LIB_STATIC) $(OBJS)
+
+romfs:
+
+
+clean:
+	-$(RM) *.a *.o *.so $(LIB_STATIC) $(OBJS)
+
diff --git a/ap/app/at_demo/com/at_api.c b/ap/app/at_demo/com/at_api.c
new file mode 100644
index 0000000..1e6ad27
--- /dev/null
+++ b/ap/app/at_demo/com/at_api.c
@@ -0,0 +1,497 @@
+//#include "at_com.h"

+#include <stdio.h>

+#include <stdlib.h>

+#include <string.h>

+#include <ctype.h>

+#include <errno.h>

+#include <sys/types.h>

+#include <sys/wait.h>

+#include <sys/msg.h>

+#include "at_api.h"

+

+#define AT_PARAM_MAX_NUM 50

+#define RESEND_TIMES_MAX 3

+

+//µ÷Óøýӿڷ¢ËÍÖ÷¶¯Éϱ¨×Ö·û´®¸øÔ¶¶ËоƬ

+int send_rsp_str_to_modem(int      module_id, char *rsp_cmd,int rsp_len)

+{

+	return at_send_msg(module_id, MODULE_ID_AT_CLIENT, MSG_CMD_SEND_RSP_TO_ZTE, rsp_len, rsp_cmd, 0);

+}

+

+//»ñÈ¡ATÃüÁîǰ׺

+static void get_at_req_prefix(char *at_str, char** at_prefix)

+{

+	char *prefix = NULL;	

+    char *pszAtHead = NULL;	

+    char *ptemstr = NULL;

+	

+	if((*at_str == 'A'||*at_str == 'a')&&(*(at_str+1) == 'T'||*(at_str+1) == 't'))

+    {

+        if(isalpha(*(at_str+2)))

+        {

+            *at_prefix = NULL;

+        }

+		else

+		{

+			prefix = (char*)malloc(50);

+			if(prefix == NULL) at_assert(0);

+			memset(prefix, 0x00, 50);

+	

+			pszAtHead = at_str;

+			//ÕÒµ½Ê׸ö·Ç×Öĸ»òÕßÊý×ֵIJÎÊý£¬ÀýÈç+

+			for(; *at_str != '\0'; at_str++)

+			{

+			   if(!(isalnum(*at_str) || *at_str == '\r' || *at_str == '\n'))

+			   {

+				   pszAtHead = at_str;

+				   pszAtHead++;

+				   break;

+			   }

+			}

+

+			for(ptemstr = pszAtHead; *ptemstr != '\0'; ptemstr++)

+			{

+				if(*ptemstr == '=' || *ptemstr == '?' || *ptemstr == '\r')

+				{

+					memcpy(prefix, pszAtHead, ptemstr-pszAtHead); 

+					*at_prefix = prefix;

+					return;

+				}

+			}

+		}

+    }

+	else

+	{

+		at_assert(0);

+	}

+

+}

+

+static int is_print_str(const char *str){

+    while(isprint(*str)){

+        str++;

+    }

+    return *str == '\0';

+}

+

+static int get_fmt_param_count(const char *str){

+    int fmt_param_count = 0;

+    

+    for(; *str != '\0'; str++){

+        if(*str == ','){

+            fmt_param_count++;

+        }

+    }

+    return fmt_param_count + 1;

+}

+

+

+

+/*return 0±íʾ½âÎö²ÎÊýÕý³££¬ÄÚ²¿½øÐÐÑϸñµÄ²ÎÊý¼ì²é£¬°üÀ¨²ÎÊý¸öÊýÒ»ÖÂÐÔ¼ì²é£¬¶ÔÓÚ¿ÉÑ¡²ÎÊý£¬ÐèÒªµ÷ÓÃÕß×ÔÐп¼ÂÇ*/

+static int  parse_param_safe(char *fmt, char *buf, void **pval)

+{

+	char *p;

+    char *sepp; 

+    char *tmp;

+	char sepc;

+	char *pstr[AT_PARAM_MAX_NUM] = {0};

+	int  len, flag;

+	int  n   = 0;

+	int  nparam = 0;//buf×Ö·û´®Êµ¼ÊµÄ²ÎÊý¸öÊý

+	int  fmt_param_num = 0;//fmt¸ñʽ»¯ÖÐÒªÇóµÄ²ÎÊý×ܸöÊý£¬Óë%¸öÊýÒ»ÖÂ

+	int  ret  = AT_PARSE_OK;

+	int  mark_flag = 0;//ÓÃÓÚ±êÊ¶ÌØÊâ·ûºÅµÄÅä¶ÔÇé¿ö£¬Ä¿Ç°ÓÃÓÚË«ÒýºÅ

+	

+    while(*buf == ' ') buf++;

+	len = strlen(buf) + 1;

+	tmp = p = (char*)malloc(len);

+	if (p == NULL) {

+		return ATERR_NO_PRINT;

+	}

+	//fmt_param_num = find_char_num(fmt,"%");

+	memset(p, 0, len);

+	//ÉêÇëÐÂÄÚ´æ´æ·ÅÈë²ÎµÄATÃüÁÒÔ±ã½øÐÐÕûÐζ¨ÖÆ

+	memcpy(p, buf, strlen(buf));

+    /*È¥³ýβ²¿µÄ\r\n£¬Ä¿Ç°½öÔÚ7100ÉÏÓдËÎÊÌâ */

+    for(len--; len > 0; len--){

+        if(p[len - 1] == '\r' || p[len - 1] == '\n'){

+            p[len - 1] = '\0';

+        } else {

+            break;

+        }

+    }

+    if(!is_print_str(p)){/* ÈçATÃüÁîÖаüº¬²»¿É¼û×Ö·ûÖ±½Ó·µ»Ø´íÎó */

+        free(tmp);

+		return ATERR_NO_PRINT;

+    }

+    /*°´¶ººÅ½øÐÐÿ¸ö²ÎÊýµÄ·Ö¸îÕûÐÎ,Ë«ÒýºÅÀïµÄ¶ººÅÌø¹ý*/

+	do {

+		flag = 0;

+		mark_flag = 0;

+		if (*p == '"') {

+			int i, j;

+			for (i = j = 0, ++p; p[j] != '\0'; i++, j++) {

+				if (p[j] == '"') {

+					++j;

+					mark_flag = 1;

+					break;

+				}

+			}

+			if(mark_flag == 0){/* δƥÅ䵽˫ÒýºÅÖ±½Ó·µ»Ø´íÎó */

+				free(tmp);

+				return ATERR_DROP_MARK;

+			}

+			if (j == 1) flag = 1;

+			p[j - 1] = '\0';

+			sepp = p + j;

+		} else {

+			sepp = p + strcspn(p, ",");

+			if (p == sepp) flag = 1;

+		}

+

+		nparam++;

+		sepc = sepp[0];

+		sepp[0] = '\0';

+

+		if (flag == 1)

+			pstr[n++] = NULL;

+		else

+			pstr[n++] = p;

+		p = sepp + 1;

+	} while ((n < AT_PARAM_MAX_NUM) && (sepc == ','));

+

+    if(nparam < get_fmt_param_count(fmt)){

+		ret = ATWARN_DROP_RN;    

+	}else if(nparam > get_fmt_param_count(fmt)){

+		ret = ATWARN_LACK_PARAM;    

+	}

+    /* convert the string params to the types that fmt Appointed */

+    int param_count = 0; /*ÊäÈëµÄ×Ö·û´®ÖÐÓÐЧ²ÎÊý¸öÊý*/

+    int param_str_index = 0; /* the index of string params */

+    int param_val_index = 0; /* the index of param values  */

+	//°´ÕÕÈë²Î¸ñʽ½øÐÐÿ¸ö²ÎÊýÖµµÄ·µ»Ø¸³Öµ

+    for (; fmt !=  NULL && param_str_index < nparam; param_str_index++) {

+        char type;

+        unsigned int  size;

+        char str_param_size[10] = { 0 };

+        int  param_size_index  = 0;

+

+        while(*fmt == ' ') fmt++;

+        if(*fmt == ','){

+            fmt++;

+            continue;  /* igmore the param that is without type */

+        }

+        if(*fmt++ != '%'){

+             ret = ATERR_NO_PRINT;

+             break;

+        }

+        for (; param_size_index < sizeof(str_param_size) - 1; fmt++, param_size_index++){

+            if(!isdigit(*fmt)){

+                break;

+            }

+            str_param_size[param_size_index] = *fmt;

+        }

+        type = *(fmt++);

+        size = atoi(str_param_size);

+        while(*fmt == ' ') fmt++; /* igmore the blanks */

+        fmt = (*fmt == ',' ? fmt + 1 : NULL);

+

+        if (type == 'd') {

+            if(size == 0 || size == 4) {

+                if(pstr[param_str_index] != NULL) {

+                    *((int *)pval[param_val_index]) = (int)atoi(pstr[param_str_index]);

+                    param_count++;

+                }

+            } else if(size == 1) {

+                if(pstr[param_str_index] != NULL) {

+                    *((char *)pval[param_val_index]) = (char)atoi(pstr[param_str_index]);

+                    param_count++;

+                }

+            } else if(size == 2) {

+                if(pstr[param_str_index] != NULL) {

+                    *((short *)pval[param_val_index]) = (short)atoi(pstr[param_str_index]); 

+                    param_count++;

+                }

+            }else {

+                at_assert(0);

+                break;

+            } 

+        } else if (type == 's') {

+            if (size == 0) {

+                if(pstr[param_str_index] != NULL) {

+                    strcpy((char *)pval[param_val_index], pstr[param_str_index]);

+                    param_count++;

+                }

+            } else {

+               if(size < strlen(pstr[param_str_index])){

+				    ret = ATERR_STR_TOO_LONG;

+                    break;

+			   }

+               if(pstr[param_str_index] != NULL) {

+                    strncpy((char *)pval[param_val_index], pstr[param_str_index], size - 1);

+                    param_count++;

+                }

+            }

+        } else {

+                at_assert(0);

+                break;

+        }

+        param_val_index++;

+    }

+    free(tmp);

+    return ret;

+}

+

+

+/*%d¸ñʽʱ£¬Èë²Î±ØÐëΪintÀàÐÍ£¬·ñÔòÄÚ²¿ÓÐÔ½½çµÄ·çÏÕ*/

+/*Óû§Ê¹ÓÃʱ£¬Èô²»ÏëÓɸýӿÚÄÚ²¿½øÐвÎÊýµÄ¸ñʽ»¯½âÎö£¬¿ÉÒÔ½«fmt¸³ÖµÎª"%s"£¬pval¸³ÖµÎªchar **p˫ָÕ룬ÕâÑù²ÎÊý½«×÷ΪÕûÌå×Ö·û´®·µ»Ø¸øµ÷ÓÃÕß*/

+int parse_param(char *fmt, char *buf, void **pval)

+{

+	int ret = parse_param_safe(fmt,buf,pval);

+    if(ret==ATWARN_LACK_PARAM||ret==ATWARN_DROP_RN)

+        return  AT_PARSE_OK;

+    return ret;

+}

+

+

+//¸øat_client·¢ËÍÇëÇóÏûÏ¢£¬Ð¯´øatÃüÁî×Ö·û´®ºÍ³¬Ê±Ê±³¤

+static void send_app_req(int module_id, char *req_at, int len, int timeout,int direct)

+{

+	struct app_req appreq;

+

+	memset(&appreq, 0x00, sizeof(struct app_req));

+	memcpy(appreq.atstr, req_at, len);

+	appreq.str_len = len;

+    appreq.timeout = timeout;

+	if(direct == NEAR_PS)

+		at_send_msg(module_id, MODULE_ID_AT_CLIENT, MSG_CMD_SEND_AT_TO_ZTE,sizeof(struct app_req), &appreq, 0);

+	

+	printf("send_app_req\n");

+

+}

+

+

+//·µ»Ø1   ¿É³¢ÊÔÖØ·¢        ·µ»Ø0 ²»ÔÙÖØ·¢

+int at_client_err_proc(int err, int sent_cnt)

+{

+	if(9001 == err)//ÖÐÐË΢·µ»Ø×´Ì¬»úÒì³££¬ÐèÒªÕû»úÖØÆô

+	{

+		at_assert(0);

+	}

+	if(6003 == err || 6004 == err || 3 == err || 4 == err)

+	{

+		if(sent_cnt == 1)

+		{

+			return 1;

+		}

+		else

+		{

+			printf("please check req\n");			

+		}

+	}

+	else if(8008 == err || 6000 == err)

+	{

+		if(sent_cnt == 1)

+		{

+			return 1;

+		}

+		else

+		{//Á¬ÐøÁ½´Î³¬Ê±»òͨµÀ×èÈû£¬ÖÐÐË΢оƬÒì³££¬ÐèÒªÕû»úÖØÆô

+			at_assert(0);

+		}

+	}			

+	

+	return 0;

+}

+

+

+/**

+ * @brief Ó¦Ó÷¢ËͶ¯×÷ÀàATÇëÇ󣬲¢×èÈûµÈ´ý¶¯×÷½á¹û£»×¢Ò⣺¸Ã½Ó¿ÚÖ»ÄÜÓÃÓÚ²éѯºÍÉèÖúÍÖ´ÐÐÇëÇó£¬Í¨¹ýÈë²Î½øÐÐÖмä½á¹ûµÄÄÚ²¿½âÎö´¦Àí£¬²¢ÇÒ

+          ÓÐÖмä½á¹ûÉϱ¨Ê±£¬Ö»Ö§³ÖÒ»ÌõÖмä½á¹ûµÄÉϱ¨½âÎö£»

+ * @param req_at  ÇëÇóATÃüÁî

+ * @param info_fmt ATÏìÓ¦µÄ¸ñʽ»¯·½Ê½

+ * @param pval  ¸ñʽ»¯ºóµÄATÏìÓ¦

+ * @param safe_parm_check	ָʾÊÇ·ñ¶Ô²ÎÊý¸öÊý½øÐÐÒ»ÖÂÐÔ¼ì²é£¬0±íʾº¬¿ÉÑ¡²ÎÊý£¬²»¶Ô²ÎÊý¸öÊý½øÐмì²é;1±íʾ¶Ô²ÎÊý¸öÊý½øÐÐÑϸñ¼ì²é

+ * @return 0±íʾ·µ»Ø³É¹¦£¬ÆäËûÖµ±íʾʧ°Ü´íÎóÂë

+ * @note  1. Óû§Ê¹ÓÃʱ£¬Èô²»ÏëÓɸýӿÚÄÚ²¿½øÐвÎÊýµÄ¸ñʽ»¯½âÎö£¬¿ÉÒÔ½«info_fmt¸³ÖµÎª"%s"£¬pval¸³ÖµÎªchar **p˫ָÕ룬ÕâÑù²ÎÊý½«×÷ΪÕûÌå×Ö·û´®·µ»Ø¸øµ÷ÓÃÕß

+	      2. ¶ÔÓÚZMGL,CPBR, COPS=?µÈÒ»ÌõÇëÇó»áÓжàÌõÖмä½á¹ûÇé¿ö£¬»¹ÐèʹÓÃregister_inform_func×¢²áÖмä½á¹ûµÄ´¦Àíº¯Êý

+ * @warning 

+ */

+static int  send_req_and_wait(char *req_at,int len,char *info_fmt,void **pval, int safe_parm_check,int timeout,int direct)

+{

+	int my_handle = 0;

+    char *prefix = NULL;

+	MSG_BUF rsp_msg = {0};

+	long msgSize = sizeof(MSG_BUF)-sizeof(long);

+	int iRet = 0;

+    int module_id = MODULE_ID_APP_DYNAMIC_BASE;//ÄÚ²¿¶¯Ì¬»ñȡԴģ¿éID£¬³õʼֵΪMODULE_ID_ATDYNAMIC_BASE

+    int  err = 0;

+	int  at_send_cnt = 0;

+

+	if(len > DATA_BUFFER_MAX-12)	

+		at_assert(0);

+    at_assert(((info_fmt==NULL&&pval==NULL)||(info_fmt!=NULL&&pval!=NULL)));

+    //¶¯Ì¬´´½¨ÁÙʱµÄÏûÏ¢¶ÓÁйܵÀ

+    //msggetʹÓòÎÊýIPC_CREAT | IPC_EXCL| 0600£¬Åжϵ±Ç°module_idµÄÏûÏ¢¶ÓÁÐÊÇ·ñ

+    //´æÔÚ£¬Èç¹û²»´æÔÚ£¬Ö±½Ó´´½¨ÐµÄÏûÏ¢¶ÓÁУ»Èç¹û´æÔÚ£¬·µ»ØÖµÎ´-1£¬È»ºómodule_id

+    //Öµ¼Ó1£¬²»¶ÏÑ­»·Ö±µ½ÕÒµ½Ã»ÓÐʹÓõÄmodule_idÖµ

+    while((my_handle = msgget(module_id,IPC_CREAT | IPC_EXCL| 0600)) == -1)

+    {

+        module_id++;

+		if (module_id > MODULE_ID_APP_DYNAMIC_END) 

+			//µ±module_id´óÓÚMODULE_ID_ATDYNAMIC_ENDֵʱ£¬Ö÷¶¯¶ÏÑÔ

+			at_assert(0);

+	}

+    //¸ù¾ÝÇëÇóATÃüÁîºÍ²éѯÓï·¨£¬ÕÒµ½¶ÔÓ¦µÄ²éѯǰ׺£¬¶¯Ì¬¸³Öµ¸ø³ö²Î£¬Íⲿ½øÐÐÄÚ´æµÄÊÍ·Å

+    get_at_req_prefix(req_at,&prefix);

+RESEND:	

+    //¸øat_ctl·¢ËÍÏûÏ¢£¬·¢Ë͵ÄÏûÏ¢ÄÚÈÝÊÇatÃüÁî×Ö·û´®

+	at_send_cnt++;

+    at_assert(at_send_cnt<=RESEND_TIMES_MAX);

+    //ÓÉatctlÖ÷¿ØÄÚ²¿ÉèÖó¬Ê±µÈ´ý£¬ÖØ·¢ºó»áÓÉÖØ¹¹ÖØÉè¸Ã¶¨Ê±Æ÷

+	send_app_req(module_id,req_at,len,timeout,direct);

+	printf("prefix:%s\n",prefix);

+	while(1)

+	{

+		iRet = 0;

+		memset(&rsp_msg, 0x00, sizeof(MSG_BUF));

+		iRet = msgrcv(my_handle, &rsp_msg, msgSize, 0, 0);

+		if (iRet < 0)

+        {

+        	continue;

+		}

+		//ËÀµÈÓ¦´ðÏûÏ¢

+		if(rsp_msg.usMsgCmd == MSG_CMD_SEND_AT_MSG_RSP)//Æ¥Åäµ½ÊÇMSG_CMD_SEND_AT_MSG_RSPʱ²Å´¦Àí

+		{

+		    char *buf = rsp_msg.aucDataBuf;

+            char *at_paras = NULL;

+        	char *rsp_head = NULL;

+			char *rsp_tail = NULL;

+            rsp_head = buf;

+			printf("recv MSG_CMD_SEND_AT_MSG_RSP, buf:%s\n",buf);

+        	//¶ÔÓÚ²éѯÇëÇ󣬲¢ÌṩÁ˲ÎÊýÄÚ´æ¿Õ¼ä£¬Ôò½øÐвÎÊýµÄ½âÎö

+        	if(prefix!=NULL && info_fmt!=NULL && pval!=NULL && ((rsp_head=strcasestr(buf,prefix))!=NULL))

+        	{

+        		//Ìø¹ýÖмä½á¹ûµÄÍ·²¿£¬ÕÒµ½²ÎÊýµÄÊ×µØÖ·

+        		rsp_head = rsp_head+strlen(prefix)+2; 

+				if((rsp_tail = strchr(rsp_head,'\0')) == NULL)//µ±Éϱ¨µÄÖмä½á¹ûÖÐûÓÐ\r\nʱ£¬ËµÃ÷½á¹ûÓÐÎÊÌ⣬ֱ½Ó¶ÏÑÔ

+					at_assert(0);

+				

+				if(strcmp(info_fmt,"%s") == 0)

+					//Èç¹û²»ÏëÓÉÄÚ²¿½øÐвÎÊýµÄ¸ñʽ»¯½âÎöʱ£¬Ö±½Ó½«È«²¿²ÎÊýÄÚÈÝÈ¡³öÀ´¸³Öµµ½pval[0]ÖУ¬²»×öÈκνâÎö

+					strncpy((char *)*pval, rsp_head, (int)(rsp_tail-rsp_head));

+				else//ÐèÒª²ÎÊý½âÎöʱ£¬½«Öмä½á¹û´ÓÉϱ¨½á¹ûÖгé³öÀ´£¨Éϱ¨µÄ½á¹ûÖпÉÄÜÓÐOK´æÔÚ£©

+				{

+					char *at_paras =  malloc(strlen(rsp_head)+1);

+					if(at_paras == NULL) at_assert(0);

+                    memset(at_paras, 0, strlen(rsp_head)+1);

+					memcpy(at_paras, rsp_head, (int)(rsp_tail-rsp_head));

+

+					if(safe_parm_check)

+						err = parse_param_safe(info_fmt, at_paras, pval);//°´ÕÕ¸ñʽ½âÎö²ÎÊý

+					else

+						err = parse_param(info_fmt, at_paras, pval);//°´ÕÕ¸ñʽ½âÎö²ÎÊý

+					printf("rsp parse_param_safe return ERR=%d!!!!!!\n",err);

+					printf("at_paras=%s!!!!!!\n",at_paras);

+

+					if(at_paras != NULL)

+						free(at_paras);

+                    //²ÎÊý²»ºÏ·¨£¬¿ÉÄÜÊÇ´®¿ÚͨÐÅÒì³£Ôì³ÉµÄ

+                    else if(err != AT_PARSE_OK)

+                        goto RESEND;

+				}                

+        	}

+        	//±ê×¼3GPPµÄ´íÎ󣬲»½øÐÐÖØ´«³¢ÊÔ

+        	if((rsp_head = strstr(buf,"ERROR")) != NULL)

+			{

+				//Èç¹ûÕÒ²»µ½Ã°ºÅ£¬ËµÃ÷ERRORûÓдíÎóÂë

+				if(strchr(rsp_head,':') != NULL)

+					sscanf(rsp_head+strlen("ERROR")+2, "%d", &err); 				

+				printf("server return ERR=%d, at_send_cnt=%d!!!!!!!\n",err,at_send_cnt);

+				//ÖÐÐË΢оƬ״̬»úÒì³££¬Ò»°ãΪ˽×ÔÖØÆô£¬ÐèÒª½øÐÐÕû»úµÄÖØÆô²Ù×÷

+                if(err == ATERR_ZXIC_ERR)

+                    at_assert(!"ZXIC  err!");

+				

+				//¶ÔÓÚÏòÖÐÐË΢оƬ·¢ËÍÇëÇóʱ£¬»Ø¸´´íÎóÂëΪATERR_DROP_MARK¡¢ATERR_NO_PRINT¡¢ATERR_STR_TOO_LONG¡¢ATWARN_DROP_RN¡¢

+				//ATWARN_LACK_PARAM¡¢ATERR_WAIT_REQ_END_TIMEOUT¡¢ATERR_WAIT_RSP_TIMEOUTºÍATERR_UNKNOWNING_CMDʱ¶¼±ØÐëÖØ·¢

+                else if((err>=ATERR_DROP_MARK && err<=ATWARN_LACK_PARAM) || err == ATERR_WAIT_REQ_END_TIMEOUT || err == ATERR_WAIT_RSP_TIMEOUT

+					|| err == ATERR_UNKNOWN_CMD)

+                    goto RESEND;

+                break;

+			}			

+			//¶ÔÓÚÉèÖÃÀàÃüÁîºÍһЩִÐÐÀàÃüÁֻÓÐOKÉϱ¨Ã»ÓÐÖмä½á¹ûÉϱ¨

+			else if((rsp_head = strstr(buf,"OK")) != NULL)

+        	{

+        		//ÖÐÐË΢»Ø¸´µÄ½á¹ûÈç¹û½âÎö³öµÄ²ÎÊý²»ºÏ·¨£¬Á¢¼´ÖØÐ·¢ËÍÇëÇó

+        	    if(err>=ATERR_DROP_MARK && err<=ATWARN_LACK_PARAM)

+                    goto RESEND;

+                break;		

+        	}

+        }

+    }

+    if(prefix!=NULL)

+        free(prefix);

+    //²éѯÃüÁî½á¹û·µ»Øºó£¬Ïú»Ù֮ǰ´´½¨µÄÏûÏ¢¶ÓÁÐ

+    if(msgctl(my_handle,IPC_RMID,0) < 0)

+        printf("%d:%s",errno,strerror(errno));	

+    return err;

+}

+

+//ÄÚ²¿¶ÔÓÚÎïÀíͨµÀÒì³£Ôì³ÉµÄÊý¾Ý´íÎó½øÐÐÖØ·¢³¢ÊÔµÄÈÝ´í£¬timeoutΪºÁÃëΪµ¥Î»µÄµÈ´ý½á¹ûʱ³¤

+int  get_modem_info(char *req_at,char *info_fmt,void **pval, int timeout)

+{

+    return send_req_and_wait(req_at,strlen(req_at),info_fmt,pval,0,timeout,NEAR_PS);

+}

+

+//·¢ËÍÏûÏ¢½Ó¿Ú£¬³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø·Ç0

+int at_send_msg(int source_id, int target_id, unsigned short Msg_cmd, unsigned short us_DataLen, unsigned char *pData, int msgflag)

+{

+	MSG_BUF stMsg;

+	int lRet = 0;

+	int lTgtMsgID = 0;

+	long msgSize = sizeof(MSG_BUF) - sizeof(long);

+

+	long errNo = 0;

+

+	memset(&stMsg, 0, sizeof(MSG_BUF));

+

+	lTgtMsgID = msgget(target_id, 0);

+	if (-1 == lTgtMsgID) {

+		return -1;

+	}

+

+	if ((us_DataLen > 0) && (NULL == pData)) {

+		return -1;

+	}

+

+	stMsg.usSourceModuleID = source_id;

+	stMsg.usTargetModuleID = target_id;

+	stMsg.usMsgCmd = Msg_cmd;

+	stMsg.usDataLen = us_DataLen;

+

+	if (us_DataLen > 0) {

+		memcpy(stMsg.aucDataBuf, pData, us_DataLen);

+	}

+

+AGAIN:

+

+	lRet = msgsnd(lTgtMsgID, &stMsg, msgSize, msgflag!=0?04000:0);//IPC_NOWAIT 04000

+	if (lRet < 0) {

+		if (errno == EINTR) {

+			goto AGAIN;

+		}

+		if (msgflag == 0) {

+			assert(0);

+		}

+		return -1;

+	}

+	return 0;

+}

+

+

+

+

+

+

+

+

diff --git a/ap/app/at_demo/com/at_api.h b/ap/app/at_demo/com/at_api.h
new file mode 100644
index 0000000..78e9a0e
--- /dev/null
+++ b/ap/app/at_demo/com/at_api.h
@@ -0,0 +1,193 @@
+/************************************************************************************

+ͨÓÃÍ·Îļþ

+***************************************************************************************/

+#ifndef _AT_API_H

+#define _AT_API_H

+#include <assert.h>

+

+

+#ifndef NULL

+#define NULL                    0

+#endif

+

+#define DATA_BUFFER_MAX 	640 		//MSG_BUF×î´óÊý¾ÝÔØºÉ

+

+enum SAP_ERR {

+    AT_PARSE_OK             = 0,      /*parse_param²ÎÊý½âÎöÕýÈ·*/

+	ATERR_ZXIC_ERR          = 8000,   /*ÖÐÐË΢оƬ·¢ÉúÒì³££¬ÇÒÎÞ·¨»Ö¸´£¬ÐèÒª½øÐÐÕû»úÖØÆô*/

+    ATERR_PARAM_INVALID 	= 8001,   /*ÃüÁî²ÎÊýϸ½Ú²»¶Ô£¬Óë¾ßÌåATÃüÁî½ô¹ØÁª*/

+    ATERR_NOT_ALLOWED 		= 8002,   /*Óë¾ßÌåÒµÎñÁ÷³Ì³åÍ»£¬²Ù×÷²»ÔÊÐí*/

+    ATERR_PROC_FAILED		= 8003,   /*ÃüÁî´¦Àíʧ°Ü£¬ÊôÓÚsoftapϵͳÒì³££¬ÈçÏûÏ¢·¢ËÍʧ°ÜµÈ*/

+    ATERR_DROP_MARK 		= 8004,	  /*Ë«ÒýºÅ¶ªÊ§Ò»¸ö£¬¿ÉÄÜÊǶª¶ººÅÔì³ÉµÄÆ«ÒÆ*/

+    ATERR_NO_PRINT			= 8005,   /*×Ö·û´®ÄÚÈÝ·ÇASCIIÃ÷ÎÄ£¬¿ÉÄÜÊǶª¶ººÅÔì³ÉµÄÆ«ÒÆ*/

+    ATERR_STR_TOO_LONG		= 8006,   /*ASCII×Ö·û´®¶ÁÈ¡µÄ³¤¶È³¬¹ý½âÎöÔ¼¶¨µÄ³¤¶È£¬¿ÉÄÜÊÇÍⲿÊäÈëµÄATÃüÁî²»ºÏ·¨*/

+    ATWARN_DROP_RN 			= 8007,   /*ʵ¼Ê×Ö·û´®²ÎÊý¸öÊý´óÓÚfmt¸ñʽ»¯¸öÊý£¬¿ÉÄÜÊǵ÷ÓÃÕßÖ»¹ØÐIJ¿·Ö²ÎÊý£¬Ðè½÷É÷´¦Àí¸ÃºêÖµ*/

+    ATWARN_LACK_PARAM 		= 8008,   /*°´ÕÕÈë²Î¸ñʽfmt½âÎö£¬ÄÚÈÝȱÉÙ²ÎÊý£¬ÓÉÓÚ²ÎÊý¿ÉÑ¡£¬¿ÉÄÜÊÇÕý³£µÄ£¬Ðè½÷É÷ʹÓøúêÖµ*/

+    ATERR_MEM_LESS 		    = 8009,   /*ÖÐÐË΢оƬÄÚ²¿ÄÚ´æ²»×ãÔì³ÉÎÞ·¨½ÓÊÕµ±Ç°ATÃüÁî*/

+    ATERR_WAIT_REQ_END_TIMEOUT	= 8010, /*µÈ´ýÍⲿÊäÈëµÄREQÇëÇóÃüÁî½áÊø·û\r³¬Ê±*/

+    ATERR_WAIT_RSP_TIMEOUT	= 8011,    /*·¢ËÍÍêATÇëÇóºó£¬µÈ´ýÔ¶¶ËRSPÓ¦´ð½á¹û³¬Ê±*/

+    ATERR_CHANNEL_BUSY      = 8012,   /*µ±Ç°ATͨµÀÕýÔÚ´¦ÀíATÇëÇó£¬ÓÖÊÕµ½Ò»ÌõATÇëÇ󱨴í*/

+    ATERR_UNKNOWN_CMD    	= 8013,   /*ÍⲿÊäÈëµÄÃüÁî²»¿Éʶ±ð£¬Îª·Ç·¨µÄATÃüÁî*/

+    

+    ATERR_PPP_FILE_FAILED 	= 8100,   /*PPPÎļþ²Ù×÷ʧ°Ü*/

+    ATERR_PPP_NOT_EXISTED 	= 8101,   /*PPPD²»´æÔÚ*/

+    ATERR_PPP_WRONG_CHAN 	= 8102,   /*PPPͨµÀ´íÎó*/

+

+    //³¬¹ý9000µÄΪÓëÍⲿMCUÏà¹ØµÄ¶¨ÖÆ´íÎóÂ룬ÐèÒªÍⲿMCUÓû§°´ÕÕ´íÎóÂë½øÐÐÏà¹ØÈÝ´í¶¯×÷

+    USER_EXTAND_ERR_BASE  = 9000,   

+};

+

+struct app_req{

+	char atstr[DATA_BUFFER_MAX-12];

+    int  str_len;//¸Ã±äÁ¿ÎªÁ˽â¾ö¶þ½øÖÆÂëÁ÷µÄÖ±½Ó·¢ËÍ£¬ÎÞ·¨Ö±½ÓʹÓÃstrlen

+	int  timeout;

+};

+

+enum at_channel_site {

+	FAR_PS = 0,    //Ô¶ÀëPSЭÒéÕ»µÄATͨµÀ£¬ÀýÈçAPºËÄÚUSBö¾ÙµÄATͨµÀ

+	NEAR_PS,       //¿¿½üPSЭÒéÕ»²àµÄATͨµÀ£¬ÀýÈçAPºËÄÚ¹²ÏíDDRÐéÄâµÄATͨµÀ

+	POSITION_VOLTE, //ÓëvolteÄ£¿éͨÐŵÄptyͨµÀλÖÃ

+	POSITION_MAX,  //ÉÏÏÞºê

+};

+

+//ÏûÏ¢ÊÕ·¢µÄ¿ò¼Ü½á¹¹Ìå

+typedef struct tagMSG_BUF {

+	int usTargetModuleID;			/*Ä¿µÄÄ£¿éÏûÏ¢¶ÓÁÐID*/

+	int usSourceModuleID;			/*Ô´Ä£¿éÏûÏ¢¶ÓÁÐID*/

+	unsigned short usMsgCmd;        /*ÏûÏ¢Â룬Õâ¸öÊÇÓÃÀ´Ö¸Ê¾ÏûÏ¢µÄÄÚÈÝÊÇʲôµÄ*/

+	unsigned short usDataLen;       /*Я´øµÄÓÐЧÊý¾Ý³¤¶È*/

+	unsigned char  aucDataBuf[640]; /*Я´øµÄÓÐЧÊý¾Ýbuffer*/

+} MSG_BUF;

+

+//AT¿Í»§¶ËÏûÏ¢£¬°üÀ¨ÍⲿӦÓ÷¢À´ºÍATÄ£¿éÏìÓ¦µÄÏûÏ¢

+enum at_client_msg

+{

+	MSG_CMD_SEND_AT_TO_ZTE = 200,	//ÉϲãÓ¦Ó÷¢ËÍATÇëÇó×Ö·û´®¸øZTEоƬ£¬²¢ÉèÖó¬Ê±¶¨Ê±Æ÷µÈ´ýÓ¦´ð

+	MSG_CMD_SEND_AT_MSG_RSP,        //Ö÷Ï߳̽«ATÏìӦ͸´«¸øÓ¦ÓÃ

+	//MSG_CMD_SEND_REQAT_TO_FARPS,

+	MSG_CMD_SEND_RSP_TO_ZTE,     //ÉϲãÓ¦Ó÷¢ËÍAT×Ö·û´®¸øÔ¶¶Ë£¬²»ÐèµÈ´ýÓ¦´ð

+	MSG_CMD_RCV_TTY_STR,		//´ÓatͨµÀ¶Áµ½atÃüÁîÏìÓ¦£¬·¢ËÍÏûÏ¢¸øÖ÷Ïß³Ì	

+	MSG_CMD_SEND_WAIT_RSP_TIMEOUT, //·¢¸øsocÇëÇóÃüÁʱ´¦ÀíÏûÏ¢

+	MSG_CMD_AT_READY_IND,		//ÖÐÐË΢ģ¿éÆô¶¯Ö÷¶¯Éϱ¨£¬¿ÉÒÔ·¢Æð¿ª»ú

+	MSG_CMD_PDP_DEACT_IND,		//pdpÍøÂç²àÈ¥¼¤»îָʾ£¬¿ÉÏûϢЯ´øÈ¥¼¤»îµÄcidºÅ

+};

+

+enum  sock_msg_type {

+	AT_SOCKET_BASE = 0x0100,

+    AT_SOCKET_ZIPSTAT,

+    AT_SOCKET_ZIPRECV,

+    AT_SOCKET_RCV_TIMEOUT,

+    APP_SOCKET_SEND_REQ,

+    APP_SOCKET_CLOSE_REQ,

+};

+

+

+//ÏûÏ¢¶ÓÁÐid

+typedef enum

+{

+	MODULE_ID_APP_DYNAMIC_BASE = 0X100, 				//¿Í»§MCU²éѯatÃüÁîʱ¶¯Ì¬IDÆðʼֵ

+	MODULE_ID_APP_DYNAMIC_END  = MODULE_ID_APP_DYNAMIC_BASE+0X100,//¿Í»§MCU²éѯatÃüÁîʱ¶¯Ì¬ID½áÊøÖµ

+	MODULE_ID_AT_CLIENT,	//at¿Í»§¶Ë¿ò¼ÜÄ£¿é

+	MODULE_ID_AT_SOCKET,    //socketÀ©Õ¹AT¿Í»§¶ËÄ£¿é   

+}T_Module_ID;

+

+

+

+#define at_assert(exp) do { \

+					        if(exp == 0) {  \

+								assert(0); \ 

+							} \

+                          } while(0)

+                          

+

+/**

+* @brief ½ø³Ì¼äͨÐÅÏûÏ¢·¢Ëͽӿڣ¬Èç¹ûÏûÏ¢¶ÓÁÐδ´´½¨£¬·µ»ØÊ§°ÜֵΪ-1

+* @param source_id(IN)	:ÏûÏ¢·¢ËÍÄ£¿éID

+* @param target_id(IN)	:ÏûÏ¢½ÓÊÕÄ£¿éID

+* @param Msg_cmd(IN)	:ÏûÏ¢ÃüÁÓÃÓÚ½ÓÊÕÄ£¿é´¦ÀíÏûϢʱ£¬È·¶¨ÏûÏ¢´¦ÀíµÄ·½Ê½

+* @param us_DataLen(IN) :ÏûÏ¢ÖÐЯ´øÊý¾ÝµÄ³¤¶È

+* @param pData(IN)		:ÏûÏ¢ÖÐЯ´øµÄÊý¾ÝÄÚÈÝ

+* @param msgflag(IN)		:ÏûÏ¢µÄ·¢ËÍ·½Ê½£¬0±íʾ×èÈû·¢ËÍ£¬IPC_NOWAIT±íʾ·Ç×èÈû·¢ËÍ

+* @return ·¢Ëͳɹ¦·µ»Ø0£¬·¢ËÍʧ°Ü·µ»Ø·Ç0£¬¾ßÌå´íÎóÀàÐÍÇë²Î¿¼linux±ê×¼µÄerrnoÀàÐÍ

+* @note ·¢ËÍʧ°Ü£¬Ó¦ÓÃÅжÏerrno == ENOENT, ±íʾ¶ÓÁÐÂú£»Èô½ÓÊÕ·½Ò»¶¨»á±»Æô¶¯£¬·¢ËÍ·½¿É¼ÌÐøµ÷ÓÃipc_send_msg2½Ó¿Ú

+*/

+int at_send_msg(int source_id, int target_id, unsigned short Msg_cmd, unsigned short us_DataLen, unsigned char *pData, int msgflag);

+

+/**

+ * @brief Ó¦Ó÷¢ËͶ¯×÷Àà»ò²éѯÀàATÇëÇó¸ø3GPPЭÒéÕ»£¬²¢×èÈûµÈ´ý¶¯×÷½á¹û£»×¢Ò⣺¸Ã½Ó¿ÚÖ»ÄÜÓÃÓÚ²éѯºÍÉèÖúÍÖ´ÐÐÇëÇó£¬Í¨¹ýÈë²Î½øÐÐÖмä½á¹ûµÄÄÚ²¿½âÎö´¦Àí£¬²¢ÇÒ

+	ÓÐÖмä½á¹ûÉϱ¨Ê±£¬Ö»Ö§³ÖÒ»ÌõÖмä½á¹ûµÄÉϱ¨½âÎö£»

+ * @param req_at  ÇëÇóATÃüÁ´óСдÃô¸Ð£¬±ØÐë´óд

+ * @param info_fmt ATÏìÓ¦µÄ¸ñʽ»¯·½Ê½

+ * @param pval	¸ñʽ»¯ºóµÄATÏìÓ¦£¬¾ßÌåʹÓòο´parse_param½Ó¿Ú

+ * @param timeout	ºÁÃëΪµ¥Î»µÄµÈ´ý½á¹ûʱ³¤

+ * @return 0±íʾ·µ»Ø³É¹¦£¬ÆäËûÖµ±íʾʧ°Ü´íÎóÂë

+ * @note  

+ * 1. Óû§Ê¹ÓÃʱ£¬Èô²»ÏëÓɸýӿÚÄÚ²¿½øÐвÎÊýµÄ¸ñʽ»¯½âÎö£¬¿ÉÒÔ½«info_fmt¸³ÖµÎª"%s"£¬pval¸³ÖµÎªchar **p˫ָÕ룬ÕâÑù²ÎÊý½«×÷ΪÕûÌå×Ö·û´®·µ»Ø¸øµ÷ÓÃÕß

+ * 2. ¶ÔÓÚZMGL,CPBR, COPS=?µÈÒ»ÌõÇëÇó»áÓжàÌõÖмä½á¹ûÇé¿ö£¬¸Ãº¯Êý²»ÊÊÓÃ

+ * 3. ×Ö·û´®½âÎöʱµÄÈë²Î³¤¶È±ØÐë´óÓÚ¿ÉÄܽâ³öµÄ×Ö·û´®³¤¶È£¬·ñÔò»áÔ½½ç

+ * 4. µ±´æÔÚÖмäÉϱ¨Ê±£¬pvalºÍinfo_fmt²»Îª¿Õ£»µ±ÎªÖмäÉϱ¨Ê±£¬Á½¸ö±ØÐë½ÔΪ¿Õ

+ * 5. pvalºÍinfo_fmtÁ½ÕßҪô¶¼ÎªNULL,Ҫô¶¼²»ÎªNULL£¬²»ÄÜ´æÔÚÆäÖÐÒ»¸öΪNULL£¬ÁíÒ»¸ö²»ÎªNULLµÄÇé¿ö

+ * 6. ʾÀý

+ <pre>

+	int ret = 0;

+	ret = get_modem_info("AT+CFUN=1\r", NULL,  NULL, 1000);

+	//·µ»Ø¼´±íʾִÐгɹ¦

+

+	char *pstr = malloc(50);

+	memset(pstr,0,50);

+	ret = get_modem_info("AT+CIMI\r", "%s",  (void**)&pstr,1000);

+	//·µ»Øºópstr==111111111111111

+

+	int n1 = 0;

+	int n2 = 0;

+	int n3 = 0;

+	char *p2[] = {&n1,&n2,&n3};

+	ret = get_modem_info("AT+CCIOTOPT?\r", "%d,%d,%d",	(void**)p2,1000);

+	//+CCIOTOPT: 1,2,3½âÎöºón1==1 n2==2 n3==3

+</pre>

+ * @warning 

+ */

+

+int  get_modem_info(char *req_at,char *info_fmt,void **pval, int timeout);

+

+/**

+ * @brief ATÃüÁî½âÎö½Ó¿Ú

+ * @param fmt ATÇëÇó»òÏìÓ¦µÄ¸ñʽ»¯·½Ê½

+ * @param buf  ATÇëÇó»òÏìÓ¦µÄ×Ö·û´®Ö¸Õë²»º¬Í·²¿ºÍ¿Õ¸ñ

+ * @param pval	¸ñʽ»¯ºóµÄATÃüÁî

+ * @return 0±íʾ½âÎö²ÎÊýÕý³££¬²»½øÐвÎÊý¸öÊýµÄÓÐЧÐÔ¼ì²é£¬¾ßÌå·µ»ØÖµ²Î¿´¸ÃÍ·ÎļþSAP_ERRö¾ÙÀàÐÍÖÐAT_PARSE_OKµÈºêÖµ

+ * @note  

+ * 1. ½âÎöµÄATÃüÁî±ØÐë°´ÕÕ3GPP27007±ê׼ЭÒ飬²ÎÊýÒÔ¶ººÅ¸ô¿ª£¬×Ö·û´®Ðè´øË«ÒýºÅ£¬·ñÔò»á¶ÏÑÔ

+ * 2. ×Ö·û´®½âÎöʱµÄÈë²Î³¤¶È±ØÐë´óÓÚ¿ÉÄܽâ³öµÄ×Ö·û´®³¤¶È£¬·ñÔò»áÔ½½ç

+ * 3. ·µ»ØÖµÇë²Î¿¼Ã¶¾Ùenum SAP_ERR,²»½øÐвÎÊý¸öÊýµÄÓÐЧÐÔ¼ì²é

+ * 4. ÈôfmtÖ¸¶¨µÄ²ÎÊýÀàÐͱØÐëÓëpvalÖÐÖ¸ÕëµÄÒ»Ò»¶ÔÓ¦

+ * 5. ʾÀý

+<pre>

+	char buf[]="1,2,\"test\"";

+	int n1 = 0;

+	int n2 = 0;

+	char *n3 = malloc(strlen(buf));

+	char *p[] = {&n1,&n2,n3};

+	ret = parse_param("%d,%d,%s", buf, (void**)p);

+	//½âÎöºón1==1 n2==2 n3=="test"	 

+	ret = parse_param("%4d,%d,%3s", buf, (void**)p);

+	//½âÎöºón1==1 n2==2 n3=="te"	 

+</pre>

+ * @warning 

+ */

+

+int parse_param(char *fmt, char *buf, void **pval);

+

+/**

+  * @brief ·þÎñ¶ËÓ¦ÓóÌÐò£¬·¢ËÍÖмä½á¹ûºÍÏìÓ¦µ½ÖÐÐË΢оƬ

+  * @param module_id	  Ó¦ÓÃÄ£¿é¶ÓÁÐid

+  * @param rsp_cmd		  ´ý·¢Ë͵½ÖÐÐË΢оƬµÄÊý¾Ý

+  * @param rsp_len		  ÃüÁ¶È

+  * @return intÐͽá¹ûÂë

+  * @retval ³É¹¦ 0, ʧ°Ü -1

+  * @note 

+  */

+int send_rsp_str_to_modem(int  module_id, char *rsp_cmd,int rsp_len);

+

+#endif 

+

diff --git a/ap/app/at_demo/readme.txt b/ap/app/at_demo/readme.txt
new file mode 100644
index 0000000..aea7974
--- /dev/null
+++ b/ap/app/at_demo/readme.txt
@@ -0,0 +1,30 @@
+±¾²Î¿¼´úÂëÊÊÓÃÓÚ7100ºÍ7520V3µÈ¶à¿îÖÐÐË΢оƬ£¬ÓÃÓÚÖ¸µ¼¿Í»§ÔÚÍⲿMCUÉÏ¿ª·¢at¿Í»§¶ËÓ¦ÓÃỊ̈߳¬ÆäÖÐat_clientΪAT¿Í»§¶ËµÄ¿ò¼ÜÄ£¿é£¬¶ÔÉÏΪ¶à¸öÓ¦ÓÃÏß³ÌÌṩ֧³Å·þÎñ£»user_demoΪsocketÀ©Õ¹ATÃüÁîµÄ¿Í»§¶ËʵÏֲο¼£»²Î¿¼´úÂëÊÇ»ùÓÚlinux²Ù×÷ϵͳʵÏֵ쬻ù´¡Ö§³Å½Ó¿Ú·â×°³Élibcom.a¾²Ì¬¿â£¬¿Í»§Ê¹ÓÃʱ£¬¶Ô²Ù×÷ϵͳµÄ½Ó¿Ú½øÐÐÌæ»»¡£

+

+ATÃüÁîµÄÇëÇóÊÇÒÔAT´òÍ·\r\n½áβµÄ×Ö·û´®£¬ÏìÓ¦ÊÇÒÔ\r\n´òÍ·\r\n½áβµÄ×Ö·û£¬¾ßÌåÃèÊöÏêϸ¼û3gpp-27007ЭÒé

+Ò»ÌõATÇëÇóÏ·¢ºó£¬ÔÚûÓÐÊÕµ½ÏìÓ¦(OK»òERROR)ǰһ°ã²»ÔÊÐíÏ·¢ÏÂÒ»ÌõÇëÇó

+

+ʵÏÖÔ­ÀíΪ£ºat_client¶ÔÏÂÍê³É¶ÔATͨµÀµÄ¶Áд²Ù×÷£¬ÄÚ²¿Íê³ÉATÃüÁîµÄ½âÎöºÍ·â×°£¬¶ÔÉÏÌṩÏûÏ¢»úÖÆ£¬¹©Ó¦Óýø³Ìͨ¹ýÏûÏ¢Íê³ÉATÏà¹ØÊ¼þÁ÷³Ì¡£

+Óû§¼¶Ó¦Óýø³ÌÔÚat_clientÖ®ÉϽøÐÐATÏà¹ØÓ¦Óýø³ÌµÄ¿ª·¢£¬Í¨¹ýget_modem_info½Ó¿Úͬ²½½øÐзþÎñ¶ËµÄ²Ù×÷ºÍÐÅÏ¢»ñÈ¡£»Í¨¹ýg_autoinfo_proc_arryÊý×é×¢²á¸ÐÐËȤµÄÖ÷¶¯Éϱ¨¡£

+

+

+´úÂëÁ÷³Ì£º

+1¡¢at_demo²Î¿¼Ä£¿é£¬Ñ¡ÓÃsocketµÄÀ©Õ¹ATÃüÁî×÷Ϊģ¿é£¬Óû§¶þ´Î¿ª·¢µÄÓ¦Óýø³Ì·ÂÔì¸ÃÄ£¿é£¬¶ÔÉϽÓÊÕ¸üÉϲãµÄÊý¾Ý·þÎñ£¬¶ÔϽÓÊÕat_clientÉϱ¨µÄÖ÷¶¯Éϱ¨ÏûÏ¢£¬²¢Í¨¹ýget_modem_info½Ó¿ÚʵÏÖͬ²½µÄAT¶¯×÷ÇëÇóµÄ²Ù×÷£»

+2¡¢at_clientÄ£¿éÊÕµ½ÏûÏ¢ºó¸ù¾Ý×¢²áµÄ´¦Àíº¯Êý×é³ÉATÇëÇó·¢ËÍ(´Ó´®¿Ú\USBÐéÄâ´®¿Ú)¸øÖÐÐË΢SOC£¬Í¬Ê±¼Ç¼ÏÂͨµÀ״̬(demo´úÂë¼Ç¼ÁËATÇëÇó×Ö·û´®ºÍÏìÓ¦´¦Àíº¯Êý)

+3¡¢µ±ÊÕµ½ATÏìӦʱ´¦Àí²¢ÅжÏÊÇÏìÓ¦»¹ÊÇÖ÷¶¯Éϱ¨\Öмä½á¹ûÉϱ¨

+4¡¢Èç¹ûÊÇÖ÷¶¯Éϱ¨\Öмä½á¹û£¬¸ù¾Ý½âÎö³öÀ´µÄATǰ׺ƥÅäµ½´¦Àíº¯Êý²¢½âÎö

+5¡¢Èç¹ûÊÇÏìÓ¦£¬Ðè¸ù¾ÝÇëÇóʱ¼Ç¼µÄÏìÓ¦´¦Àíº¯Êý½âÎö´¦Àí£¬´¦ÀíÍêºóÇå³ýͨµÀ״̬

+6¡¢×îºó£¬½«½âÎöºóµÄ½á¹û×é×°³É¶ÔÓ¦µÄRSPÓ¦´ðÏûÏ¢»òINDÏûÏ¢£¬Éϱ¨¸ø¶ÔÓ¦µÄÒµÎñÄ£¿é

+

+×¢Òâµã£º

+1¡¢ÖÐÐË΢Èí¼þƽ̨£¬¿ª»úºó£¬ÊÕµ½ÍⲿMCUµÄATÇëÇó£¬Èô²»ÊÇÕý³£µÄ¿ª»úATÃüÁîÁ÷³Ì£¬»á»Ø¸´ERR¸øÍⲿMCU£¬´ËʱÍⲿMCUÊÕµ½ERRºó£¬ÐèÒª½øÐÐÖØÐ¿ª»ú³õʼ»¯»òÕßÕû»úÖØÆô²Ù×÷

+2¡¢¶ÔÓÚÖ§³ÖÈȲå°ÎµÄË«·½Í¨ÐÅ»úÖÆ£¬ÈçUSB£¬ÔòÒªÇóÍⲿMCU¼ì²âµ½ÈȲå°Îʼþºó£¬±ØÐë½øÐÐÖØÐ¿ª»ú³õʼ»¯»òÕßÕû»úÖØÆô²Ù×÷

+3¡¢ÍⲿMCUÔÚδÊÕµ½ÖÐÐË΢SOCµÄµÚÒ»ÌõÖ÷¶¯Éϱ¨ZMSRIÏûÏ¢£¬²»ÔÊÐíÏ·¢ÈκÎATÃüÁîÇëÇó£¬ÒòΪ´ËʱÖÐÐË΢SOCÉÐδ׼±¸ºÃ

+4¡¢ÍⲿMCUÊÕµ½µÄµÚÒ»ÌõÀ´×ÔÖÐÐË΢SOCµÄATÃüÁî²»ÊÇZMSRIÏûÏ¢£¬ÔòÈÏΪÖÐÐË΢SOCÓëÍⲿMCUδͬ²½£¬ÐëÖØÆôÖÐÐË΢SOC»òÕû»úÖØÆô

+5¡¢ÍⲿMCUÈôÕý³£ÔËÐÐʱÓÖÊÕµ½ÖÐÐË΢SOCÆô¶¯µÄÖ÷¶¯Éϱ¨ZMSRI£¬ÔòÈÏΪÖÐÐË΢SOC³öÏÖÒì³£ÖØÆô£¬±ØÐëÖ´ÐÐÕû»úÖØÆô

+6¡¢ÍⲿMCU·¢ËÍATÇëÇóºó£¬Èô³¬Ê±(ºêÖµ¿É¸Ä£¬Ä¿Ç°È±Ê¡Îª5·ÖÖÓ)δÊÕµ½ATÓ¦´ð£¬ÔòÖØÐ·¢Ë͸ÃATÇëÇó£¬ÈôÈÔÈ»³¬Ê±Î´ÊÕµ½Ó¦´ð£¬ÔòÈÏΪÖÐÐË΢оƬÒì³££»

+7¡¢ÍⲿMCUµÄPPP¿Í»§¶Ë·¢Ë͵ÄATÃüÁîÇëÇ󣬱£³ÖÓëÆÕͨATÒ»ÑùµÄÈÝ´í»úÖÆ£¬ÒÔ½â¾öË«·½µÄÒì²½ÖØÆôÒì³£

+8¡¢ÍⲿMCUͨ¹ýÀ©Õ¹ATÃüÁî֪ͨÖÐÐË΢SOC½øÐÐfotaÉý¼¶£¬´ËºóÍⲿMCU²»×¼×öÆäËûÓëÖÐÐË΢SOC¹ØÁªµÄÒµÎñÁ÷³Ìʼþ

+

+ÌØ±ð×¢Òâµã£º

+AT+ZWORKLOCKÓÃÓÚÉêÇëÖÐÐË΢оƬµÄʹÓÃȨ£¬Ò»µ©ÉêÇ룬²»»áÔÙ½øÈëÖÐÐË΢Éî˯£¬ËùÒÔ¶ÔÓÚ¹¦ºÄÒªÇó¸ßµÄÐͺŻú£¬Îñ±Ø×¢Òâ³ÖËøÊ±¼ä²»Äܹý³¤£¬7100оƬԭÔòÉϲ»Äܳ¬¹ý·ÖÖÓ¼¶¡£

+AT+ZSETOUTÓÃÓÚÇл»ATͨµÀΪ±ê×¼Êä³ö£¬ÕâÑùttyͨµÀ¾Í¿ÉÒÔÓÃÓÚµ÷ÊÔ£¬¼´ÊäÈëÖÐÐË΢µÄµ÷ÊÔÏà¹ØµÄÀ©Õ¹ATÃüÁÊä³öµ÷ÊÔÏàÓ¦µÄlog´òÓ¡µ½MCUµÄ¿ØÖÆÌ¨£»
\ No newline at end of file
diff --git a/ap/app/at_demo/user_demo/Makefile b/ap/app/at_demo/user_demo/Makefile
new file mode 100644
index 0000000..6ca2315
--- /dev/null
+++ b/ap/app/at_demo/user_demo/Makefile
@@ -0,0 +1,34 @@
+#*******************************************************************************

+# include ZTE application makefile

+#*******************************************************************************

+include $(zte_app_mak)
+

+##############USER COMIZE BEGIN################

+EXEC = user_demo

+OBJS = $(patsubst %.c,%.o,$(wildcard *.c))

+

+

+CFLAGS += -I$(zte_app_path)/include

+CFLAGS += -I../com

+#CFLAGS += -I$(zte_app_path)/at_demo/at_client/com

+LDLIBS += -lcom -L../com

+

+LDLIBS += -lpthread 

+
+
+##############USER COMIZE END##################
+

+#*******************************************************************************
+# targets
+#*******************************************************************************
+all: $(EXEC)
+
+$(EXEC): $(OBJS)
+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group
+	@cp $@ $@.elf
+
+romfs:
+	$(ROMFSINST) $(EXEC) /sbin/$(EXEC)
+
+clean:
+	-rm -f $(EXEC) *.elf *.gdb *.o
diff --git a/ap/app/at_demo/user_demo/user_demo.c b/ap/app/at_demo/user_demo/user_demo.c
new file mode 100644
index 0000000..27d43be
--- /dev/null
+++ b/ap/app/at_demo/user_demo/user_demo.c
@@ -0,0 +1,263 @@
+#define _LINUX_OS

+#include <stdlib.h>

+#include "user_demo.h"

+#ifdef _LINUX_OS

+#include <sys/time.h>

+#include <signal.h>

+#include <semaphore.h>

+#include <sys/msg.h>

+#include <pthread.h>

+#endif

+#include "at_api.h"

+#include <errno.h>

+

+int  zxic_is_ready = 0;

+struct zipstat_info ipstat_info = {0};

+struct ziprecv_info recv_data = {0};

+

+struct zipsocket_info mysocket_info = {0};

+//¶ÔÓÚATÎïÀíͨµÀµÄ´íÎó£¬at_client¿ò¼ÜÄ£¿é»á½øÐÐÖØ·¢³¢ÊÔ£»¶ÔÓÚÒµÎñ²ãÃæµÄERR´íÎó£¬ÐèÒªÒµÎñ¿ª·¢Ä£¿é½øÐÐÈÝ´í

+//ĿǰµÄ²Î¿¼´úÂëÊǽøÐÐÖ¸¶¨´ÎÊýµÄÖØ·¢£¬ÈôÈÔʧ°Ü£¬Ôò¶ÏÑÔ½ø¶øÕû»úÖØÆô£»timeoutµ¥Î»ÎªºÁÃë

+int get_modem_info_succ(char *req_at,char *info_fmt,void **pval, long timeout)

+{

+    int ret = 0;

+    int again_num = 0;

+    while((ret = get_modem_info(req_at,info_fmt,pval,timeout))!=0)

+    {

+        printf("%d",ret);

+		switch(ret)

+		{

+		case ATERR_NOT_ALLOWED:

+			printf("param is wrong and can not resent, please check cmd\n");

+			return ret;

+		case ATERR_MEM_LESS:

+		case ATERR_CHANNEL_BUSY:

+		case ATERR_PROC_FAILED:

+			//sleep 1sºóÔÙ´ÎÖØ·¢

+			printf("wait 1s and resent\n");

+			sleep(1);

+			break;

+		case ATERR_PARAM_INVALID:

+			//Á¢¼´ÖØ·¢

+			printf("resent again\n");

+			break;

+		default:

+			return ret;

+		}

+        if(again_num++ > RESEND_MAX)

+            at_assert(!"have  resend  fial!!!");

+    }

+}

+

+

+int at_socket_send()

+{

+	char at_str[128]= {0};

+	int sock =0;

+	int send_len = 0;

+	void *p[]={&sock,&send_len};

+	int ret = 0;

+

+    //ÉêÇëʹÓÃZXICÖÐÐË΢оƬ

+    memset(at_str, 0, sizeof(at_str));

+	strcpy(at_str,"AT+ZWORKLOCK=FFFF\r\n");

+	ret = get_modem_info_succ(at_str,NULL,NULL,500);

+	//Èç¹û¸ÃÃüÁîʧ°Ü£¬Ôò¶ÏÑÔ

+	if(ret != AT_PARSE_OK)

+	{

+		printf("AT+ZWORKLOCK=FFFF failed!!!\n");

+		at_assert(0);

+	}

+    

+	//´´½¨socket

+	memset(at_str, 0, sizeof(at_str));

+	sprintf(at_str,"AT+ZIPOPEN=%d,%d,%s,%d,%d\r\n",mysocket_info.socket_id,mysocket_info.conn_type,mysocket_info.remote_ip,mysocket_info.remote_port,mysocket_info.local_port);

+	ret = get_modem_info_succ(at_str,NULL,NULL,5000);

+	//Èç¹û¸ÃÃüÁîʧ°Ü£¬Ôò·¢ËÍAT+ZWORKLOCK=0£¬ÊͷŶÔZXICÖÐÐË΢оƬµÄʹÓÃ

+	if(ret != AT_PARSE_OK)

+	{

+		printf("ZIPOPEN failed!!!\n");

+		goto ERR_PROC2;

+	}

+	

+	//·¢ËÍÊý¾Ý

+    memset(at_str, 0, sizeof(at_str));

+	sprintf(at_str,"AT+ZIPSEND=%d,%d,%s\r\n",mysocket_info.socket_id,mysocket_info.send_len,mysocket_info.send_data);

+    ret = get_modem_info_succ(at_str,"%d,%d",p,5000);

+	//Èç¹û¸ÃÃüÁîʧ°Ü£¬Óû§¿ÉÒÔ¸ù¾Ýret´íÎóÖµ½øÐÐÈÝ´í´¦Àí£¬²Î¿¼´úÂëΪ·¢Ë͹رÕsocketµÄÃüÁî

+	if(ret != AT_PARSE_OK)

+	{

+		printf("ZIPSEND failed!!!\n");

+		goto ERR_PROC1;

+	}

+    //½ÓÊÕÊý¾Ý²ÉÓÃÖ÷¶¯Éϱ¨·½Ê½£¬²Î¼ûAT_SOCKET_ZIPRECVÏûÏ¢

+	printf("+ZIPSEND=%d,%d\n",sock,send_len);

+    return 1;

+

+ERR_PROC1:

+	//¹Ø±Õsocket

+	memset(at_str, 0, sizeof(at_str));

+	sprintf(at_str,"AT+ZIPCLOSE=%d\r\n",mysocket_info.socket_id);

+    ret = get_modem_info_succ(at_str,NULL,NULL,5000);

+	//Èç¹û¸ÃÃüÁîʧ°Ü£¬Ôò·¢ËÍAT+ZWORKLOCK=0£¬ÊͷŶÔZXICÖÐÐË΢оƬµÄʹÓÃ

+	if(ret != AT_PARSE_OK)

+	{

+		printf("ZIPCLOSE failed and goto ERR_PROC2!!!\n");

+	}

+

+ERR_PROC2:

+    //ÊÍ·ÅZXICÖÐÐË΢оƬµÄʹÓÃ

+    memset(at_str, 0, sizeof(at_str));

+	strcpy(at_str,"AT+ZWORKLOCK=0\r\n");

+	ret = get_modem_info_succ(at_str,NULL,NULL,1000);

+	//Èç¹û¸ÃÃüÁîʧ°Ü£¬Ôò¶ÏÑÔ

+	if(ret != AT_PARSE_OK)

+	{

+		printf("AT+ZWORKLOCK=0 failed!!!\n");

+		at_assert(0);

+	}

+    return  0;

+}

+int at_socket_close()

+{

+	char at_str[128]= {0};

+	int sock =0;

+	int send_len = 0;

+	void *p[]={&sock,&send_len};

+	int ret = 0;

+

+	//¹Ø±Õsocket

+	memset(at_str, 0, sizeof(at_str));

+	sprintf(at_str,"AT+ZIPCLOSE=%d\r\n",mysocket_info.socket_id);

+    ret = get_modem_info_succ(at_str,NULL,NULL,5000);

+	//Èç¹û¸ÃÃüÁîʧ°Ü£¬Ôò·¢ËÍAT+ZWORKLOCK=0£¬ÊͷŶÔZXICÖÐÐË΢оƬµÄʹÓÃ

+	if(ret != AT_PARSE_OK)

+	{

+		printf("ZIPCLOSE failed !!!\n");

+	}

+

+    //ÊÍ·ÅZXICÖÐÐË΢оƬµÄʹÓÃ

+    memset(at_str, 0, sizeof(at_str));

+	strcpy(at_str,"AT+ZWORKLOCK=0\r\n");

+	ret = get_modem_info_succ(at_str,NULL,NULL,1000);

+	//Èç¹û¸ÃÃüÁîʧ°Ü£¬Ôò¶ÏÑÔ

+	if(ret != AT_PARSE_OK)

+	{

+		printf("AT+ZWORKLOCK=0 failed!!!\n");

+		at_assert(0);

+	}

+    return  0;

+}

+//½ÓÊÕ³¬Ê±´¦Àíº¯Êý

+void rcv_timeout_handle(int signo)

+{

+	//·¢Ëͳ¬Ê±´¦ÀíÏûÏ¢¸øÖ÷Ï̴߳¦Àí

+	at_send_msg(MODULE_ID_AT_CLIENT, MODULE_ID_AT_SOCKET, AT_SOCKET_RCV_TIMEOUT, 0, NULL, 0);			

+}

+void rcv_atmsg_proc(void)

+{

+    MSG_BUF stMsg = {0};

+    int iMsgHandle = 0;

+    char *p[]={0};

+	int iRet = 0;

+	long msgSize = sizeof(MSG_BUF)-sizeof(long);

+	struct itimerval val;

+    /* ´´½¨ÏûÏ¢¶ÓÁÐ*/

+    iMsgHandle = msgget(MODULE_ID_AT_SOCKET, IPC_CREAT|0600);

+    while(1)

+    {

+        iRet = 0;

+        memset(&stMsg, 0x00, sizeof(MSG_BUF));

+

+        /* »ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí*/

+        iRet = msgrcv(iMsgHandle, &stMsg, msgSize, 0, 0);

+        if (iRet >= 0)

+        {

+            switch (stMsg.usMsgCmd)

+            {

+                //ÊÕµ½ZXICµÄµÚÒ»ÌõÖ÷¶¯Éϱ¨£¬±íÃ÷ZXIC״̬¾ÍÐ÷£¬¿ªÊ¼¿ÉÒÔ½øÐÐÊý¾Ý½»»¥

+                case MSG_CMD_AT_READY_IND:

+                    zxic_is_ready = 1;

+                    break;

+                //Ó¦Óò㷢ËÍÊý¾ÝÇëÇó£¬ÄÚ²¿½øÐÐÔ¶³ÌsocketµÄAT¿Í»§¶ËÁ÷³Ì

+                case APP_SOCKET_SEND_REQ:

+                    assert(zxic_is_ready==1);

+                    iRet = at_socket_send();

+                    //Èôsocket´´½¨»ò·¢ËÍʧ°Ü£¬ÐèÒªÓû§¸ù¾ÝÐèÇó½øÐÐÈÝ´í´¦Àí£¬²Î¿¼´úÂëÖ±½Ó¶ÏÑÔ

+                    assert(iRet==1);

+                    //ÉèÖõȴýrcvÏÂÐÐÊý¾Ý³¬Ê±

+					signal(SIGALRM, rcv_timeout_handle);

+                    //ΪÁËÈ·±£ÖÐÐË΢оƬµÄÊ¡µçЧ¹û×î´ó»¯£¬ÍⲿMCUËøÖÐÐË΢оƬµÄʱ³¤±ØÐë¿É¿Ø

+					val.it_value.tv_sec = 30;//ĿǰÉèÖÃ30s³¬Ê±

+					val.it_value.tv_usec = 0;

+					val.it_interval.tv_usec = 0;

+					val.it_interval.tv_sec = 0;//¶¨Ê±Æ÷½öÆôÒ»´Î

+					setitimer(ITIMER_REAL, &val, 0);

+					break;

+                case AT_SOCKET_ZIPSTAT:

+                    p[0] = &ipstat_info.sock_id;

+                    p[1] = &ipstat_info.state;

+                    iRet = parse_param("%d%d",stMsg.aucDataBuf,p);

+                    at_assert(iRet == AT_PARSE_OK);

+					printf("+ZIPSTAT: %d,%d\n",ipstat_info.sock_id,ipstat_info.state);

+                    break;  

+                case AT_SOCKET_ZIPRECV:

+                    p[0] = &recv_data.sock_id;

+                    p[1] = recv_data.dst_ip;

+                    p[2] = &recv_data.dst_port;

+                    p[3] = &recv_data.data_len;

+                    iRet = parse_param("%d%s%d%d",stMsg.aucDataBuf,p);

+                    at_assert(iRet == AT_PARSE_OK);

+                    recv_data.data = malloc(recv_data.data_len);

+                    iRet = parse_param(",,,,%s",stMsg.aucDataBuf,&recv_data.data);

+                    at_assert(iRet == AT_PARSE_OK);

+					printf("Response: +ZIPRECV: %d,%s,%d,&d,%s\n",recv_data.sock_id,recv_data.dst_ip,recv_data.dst_port,recv_data.data_len,recv_data.data);

+					free(recv_data.data);

+					recv_data.data = NULL;

+                    break;

+                //Ó¦ÓòãÍ£Ö¹scoketµÄÊÕ·¢

+                case APP_SOCKET_CLOSE_REQ:

+                //µÈ´ý½ÓÊÕÍø²à·þÎñÆ÷ÏÂÐÐÊý¾Ý³¬Ê±

+                case AT_SOCKET_RCV_TIMEOUT:

+                //µ±PDPÈ¥»îʱ£¬½øÐÐsocketµÄ¹Ø±Õ

+                case MSG_CMD_PDP_DEACT_IND:

+			        //Í£½ÓÊյȴý¶¨Ê±Æ÷,½«¶¨Ê±Æ÷ÄÚÈÝÇå¿Õ

+			        memset(&val,0,sizeof(struct itimerval));

+        			setitimer(ITIMER_REAL, &val, 0);

+                    at_socket_close();

+                    break;

+                default:

+                    printf("ERR: MSG UNKNOW \n");

+                	break;

+            }

+        }

+        else

+        {

+            if(errno != EINTR)

+                printf("errno = %d, errmsg = %s\n", errno,strerror(errno));

+        }

+    }

+}

+

+

+/*Ä£ÄâÍⲿӦÓõķ¢ÏûÏ¢Ïß³Ì*/

+int main(int argc, char *argv[])

+{ 

+	int ret = 0;

+

+	//»ñÈ¡socket²ÎÊýÐÅÏ¢

+	mysocket_info.socket_id = atoi(argv[1]);          //socket id

+	mysocket_info.conn_type = atoi(argv[2]);          // 0 TCP , 1 UDP

+	strcpy(mysocket_info.remote_ip, argv[3]);         //Ô¶¶ËIPµØÖ·

+	mysocket_info.remote_port= atoi(argv[4]);         //Ô¶¶Ë¶Ë¿ÚºÅ

+	mysocket_info.local_port= atoi(argv[5]);          //±¾µØ¶Ë¿ÚºÅ

+	mysocket_info.send_len= atoi(argv[6]);            //·¢ËÍÊý¾Ý³¤¶È

+	mysocket_info.send_data= malloc(mysocket_info.send_len);

+	memset(mysocket_info.send_data, 0x00, mysocket_info.send_len);

+	strcpy(mysocket_info.send_data, argv[7]);  		  //·¢ËÍÊý¾Ý	

+	rcv_atmsg_proc();

+	free(mysocket_info.send_data);

+	return 0;

+}

+

+

diff --git a/ap/app/at_demo/user_demo/user_demo.h b/ap/app/at_demo/user_demo/user_demo.h
new file mode 100644
index 0000000..a4a193c
--- /dev/null
+++ b/ap/app/at_demo/user_demo/user_demo.h
@@ -0,0 +1,52 @@
+#ifndef USER_DEMO_H_

+#define USER_DEMO_H_

+

+

+#define NULL 0

+#define  RESEND_MAX    5

+

+struct zApp_CopsReadRes

+{

+    int  mode;

+    int  format;

+    char  oper[70];

+    int  act;  

+    int  subact; 

+};

+

+

+struct zApp_PdpActInfo {

+	int  cid;   

+	char ip_type[10];

+	char ip[16];

+	char gateway[16];	

+	char pri_dns[16];

+	char sec_dns[16];	

+};

+

+struct zipsocket_info{

+	int socket_id;//Ó¦ÓÃÖÐÕæÊµ´´½¨µÄsocket¾ä±ú

+    int conn_type;//Á¬½ÓÀàÐÍ 0 tcp 1 udp

+    char remote_ip[128]; //Ô¶¶ËipµØÖ·

+    int  remote_port;//Ô¶¶Ëport    

+    int local_port;	//±¾µØport

+    int send_len;

+	char* send_data;

+};

+

+struct zipstat_info

+{

+    int sock_id;

+    int state;

+};

+struct ziprecv_info

+{

+    int sock_id;

+    char dst_ip[30];

+    int dst_port;

+    int data_len;

+    char *data;

+};

+

+extern void rcv_atmsg_proc(void);

+#endif