blob: 78e9a0eabb886920e83d769fff3a1dc2ca6cc401 [file] [log] [blame]
/************************************************************************************
ͨÓÃÍ·Îļþ
***************************************************************************************/
#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