lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /************************************************************************************
|
| 2 | ͨÓÃÍ·Îļþ
|
| 3 | ***************************************************************************************/
|
| 4 | #ifndef _AT_API_H
|
| 5 | #define _AT_API_H
|
| 6 | #include <assert.h>
|
| 7 |
|
| 8 |
|
| 9 | #ifndef NULL
|
| 10 | #define NULL 0
|
| 11 | #endif
|
| 12 |
|
| 13 | #define DATA_BUFFER_MAX 640 //MSG_BUF×î´óÊý¾ÝÔØºÉ
|
| 14 |
|
| 15 | enum SAP_ERR {
|
| 16 | AT_PARSE_OK = 0, /*parse_param²ÎÊý½âÎöÕýÈ·*/
|
| 17 | ATERR_ZXIC_ERR = 8000, /*ÖÐÐË΢оƬ·¢ÉúÒì³££¬ÇÒÎÞ·¨»Ö¸´£¬ÐèÒª½øÐÐÕû»úÖØÆô*/
|
| 18 | ATERR_PARAM_INVALID = 8001, /*ÃüÁî²ÎÊýϸ½Ú²»¶Ô£¬Óë¾ßÌåATÃüÁî½ô¹ØÁª*/
|
| 19 | ATERR_NOT_ALLOWED = 8002, /*Óë¾ßÌåÒµÎñÁ÷³Ì³åÍ»£¬²Ù×÷²»ÔÊÐí*/
|
| 20 | ATERR_PROC_FAILED = 8003, /*ÃüÁî´¦Àíʧ°Ü£¬ÊôÓÚsoftapϵͳÒì³££¬ÈçÏûÏ¢·¢ËÍʧ°ÜµÈ*/
|
| 21 | ATERR_DROP_MARK = 8004, /*Ë«ÒýºÅ¶ªÊ§Ò»¸ö£¬¿ÉÄÜÊǶª¶ººÅÔì³ÉµÄÆ«ÒÆ*/
|
| 22 | ATERR_NO_PRINT = 8005, /*×Ö·û´®ÄÚÈÝ·ÇASCIIÃ÷ÎÄ£¬¿ÉÄÜÊǶª¶ººÅÔì³ÉµÄÆ«ÒÆ*/
|
| 23 | ATERR_STR_TOO_LONG = 8006, /*ASCII×Ö·û´®¶ÁÈ¡µÄ³¤¶È³¬¹ý½âÎöÔ¼¶¨µÄ³¤¶È£¬¿ÉÄÜÊÇÍⲿÊäÈëµÄATÃüÁî²»ºÏ·¨*/
|
| 24 | ATWARN_DROP_RN = 8007, /*ʵ¼Ê×Ö·û´®²ÎÊý¸öÊý´óÓÚfmt¸ñʽ»¯¸öÊý£¬¿ÉÄÜÊǵ÷ÓÃÕßÖ»¹ØÐIJ¿·Ö²ÎÊý£¬Ðè½÷É÷´¦Àí¸ÃºêÖµ*/
|
| 25 | ATWARN_LACK_PARAM = 8008, /*°´ÕÕÈë²Î¸ñʽfmt½âÎö£¬ÄÚÈÝȱÉÙ²ÎÊý£¬ÓÉÓÚ²ÎÊý¿ÉÑ¡£¬¿ÉÄÜÊÇÕý³£µÄ£¬Ðè½÷É÷ʹÓøúêÖµ*/
|
| 26 | ATERR_MEM_LESS = 8009, /*ÖÐÐË΢оƬÄÚ²¿ÄÚ´æ²»×ãÔì³ÉÎÞ·¨½ÓÊÕµ±Ç°ATÃüÁî*/
|
| 27 | ATERR_WAIT_REQ_END_TIMEOUT = 8010, /*µÈ´ýÍⲿÊäÈëµÄREQÇëÇóÃüÁî½áÊø·û\r³¬Ê±*/
|
| 28 | ATERR_WAIT_RSP_TIMEOUT = 8011, /*·¢ËÍÍêATÇëÇóºó£¬µÈ´ýÔ¶¶ËRSPÓ¦´ð½á¹û³¬Ê±*/
|
| 29 | ATERR_CHANNEL_BUSY = 8012, /*µ±Ç°ATͨµÀÕýÔÚ´¦ÀíATÇëÇó£¬ÓÖÊÕµ½Ò»ÌõATÇëÇ󱨴í*/
|
| 30 | ATERR_UNKNOWN_CMD = 8013, /*ÍⲿÊäÈëµÄÃüÁî²»¿Éʶ±ð£¬Îª·Ç·¨µÄATÃüÁî*/
|
| 31 |
|
| 32 | ATERR_PPP_FILE_FAILED = 8100, /*PPPÎļþ²Ù×÷ʧ°Ü*/
|
| 33 | ATERR_PPP_NOT_EXISTED = 8101, /*PPPD²»´æÔÚ*/
|
| 34 | ATERR_PPP_WRONG_CHAN = 8102, /*PPPͨµÀ´íÎó*/
|
| 35 |
|
| 36 | //³¬¹ý9000µÄΪÓëÍⲿMCUÏà¹ØµÄ¶¨ÖÆ´íÎóÂ룬ÐèÒªÍⲿMCUÓû§°´ÕÕ´íÎóÂë½øÐÐÏà¹ØÈÝ´í¶¯×÷
|
| 37 | USER_EXTAND_ERR_BASE = 9000,
|
| 38 | };
|
| 39 |
|
| 40 | struct app_req{
|
| 41 | char atstr[DATA_BUFFER_MAX-12];
|
| 42 | int str_len;//¸Ã±äÁ¿ÎªÁ˽â¾ö¶þ½øÖÆÂëÁ÷µÄÖ±½Ó·¢ËÍ£¬ÎÞ·¨Ö±½ÓʹÓÃstrlen
|
| 43 | int timeout;
|
| 44 | };
|
| 45 |
|
| 46 | enum at_channel_site {
|
| 47 | FAR_PS = 0, //Ô¶ÀëPSÐÒéÕ»µÄATͨµÀ£¬ÀýÈçAPºËÄÚUSBö¾ÙµÄATͨµÀ
|
| 48 | NEAR_PS, //¿¿½üPSÐÒéÕ»²àµÄATͨµÀ£¬ÀýÈçAPºËÄÚ¹²ÏíDDRÐéÄâµÄATͨµÀ
|
| 49 | POSITION_VOLTE, //ÓëvolteÄ£¿éͨÐŵÄptyͨµÀλÖÃ
|
| 50 | POSITION_MAX, //ÉÏÏÞºê
|
| 51 | };
|
| 52 |
|
| 53 | //ÏûÏ¢ÊÕ·¢µÄ¿ò¼Ü½á¹¹Ìå
|
| 54 | typedef struct tagMSG_BUF {
|
| 55 | int usTargetModuleID; /*Ä¿µÄÄ£¿éÏûÏ¢¶ÓÁÐID*/
|
| 56 | int usSourceModuleID; /*Ô´Ä£¿éÏûÏ¢¶ÓÁÐID*/
|
| 57 | unsigned short usMsgCmd; /*ÏûÏ¢Â룬Õâ¸öÊÇÓÃÀ´Ö¸Ê¾ÏûÏ¢µÄÄÚÈÝÊÇʲôµÄ*/
|
| 58 | unsigned short usDataLen; /*Я´øµÄÓÐЧÊý¾Ý³¤¶È*/
|
| 59 | unsigned char aucDataBuf[640]; /*Я´øµÄÓÐЧÊý¾Ýbuffer*/
|
| 60 | } MSG_BUF;
|
| 61 |
|
| 62 | //AT¿Í»§¶ËÏûÏ¢£¬°üÀ¨ÍⲿӦÓ÷¢À´ºÍATÄ£¿éÏìÓ¦µÄÏûÏ¢
|
| 63 | enum at_client_msg
|
| 64 | {
|
| 65 | MSG_CMD_SEND_AT_TO_ZTE = 200, //ÉϲãÓ¦Ó÷¢ËÍATÇëÇó×Ö·û´®¸øZTEоƬ£¬²¢ÉèÖó¬Ê±¶¨Ê±Æ÷µÈ´ýÓ¦´ð
|
| 66 | MSG_CMD_SEND_AT_MSG_RSP, //Ö÷Ï߳̽«ATÏìӦ͸´«¸øÓ¦ÓÃ
|
| 67 | //MSG_CMD_SEND_REQAT_TO_FARPS,
|
| 68 | MSG_CMD_SEND_RSP_TO_ZTE, //ÉϲãÓ¦Ó÷¢ËÍAT×Ö·û´®¸øÔ¶¶Ë£¬²»ÐèµÈ´ýÓ¦´ð
|
| 69 | MSG_CMD_RCV_TTY_STR, //´ÓatͨµÀ¶Áµ½atÃüÁîÏìÓ¦£¬·¢ËÍÏûÏ¢¸øÖ÷Ïß³Ì
|
| 70 | MSG_CMD_SEND_WAIT_RSP_TIMEOUT, //·¢¸øsocÇëÇóÃüÁʱ´¦ÀíÏûÏ¢
|
| 71 | MSG_CMD_AT_READY_IND, //ÖÐÐË΢ģ¿éÆô¶¯Ö÷¶¯Éϱ¨£¬¿ÉÒÔ·¢Æð¿ª»ú
|
| 72 | MSG_CMD_PDP_DEACT_IND, //pdpÍøÂç²àÈ¥¼¤»îָʾ£¬¿ÉÏûϢЯ´øÈ¥¼¤»îµÄcidºÅ
|
| 73 | };
|
| 74 |
|
| 75 | enum sock_msg_type {
|
| 76 | AT_SOCKET_BASE = 0x0100,
|
| 77 | AT_SOCKET_ZIPSTAT,
|
| 78 | AT_SOCKET_ZIPRECV,
|
| 79 | AT_SOCKET_RCV_TIMEOUT,
|
| 80 | APP_SOCKET_SEND_REQ,
|
| 81 | APP_SOCKET_CLOSE_REQ,
|
| 82 | };
|
| 83 |
|
| 84 |
|
| 85 | //ÏûÏ¢¶ÓÁÐid
|
| 86 | typedef enum
|
| 87 | {
|
| 88 | MODULE_ID_APP_DYNAMIC_BASE = 0X100, //¿Í»§MCU²éѯatÃüÁîʱ¶¯Ì¬IDÆðʼֵ
|
| 89 | MODULE_ID_APP_DYNAMIC_END = MODULE_ID_APP_DYNAMIC_BASE+0X100,//¿Í»§MCU²éѯatÃüÁîʱ¶¯Ì¬ID½áÊøÖµ
|
| 90 | MODULE_ID_AT_CLIENT, //at¿Í»§¶Ë¿ò¼ÜÄ£¿é
|
| 91 | MODULE_ID_AT_SOCKET, //socketÀ©Õ¹AT¿Í»§¶ËÄ£¿é
|
| 92 | }T_Module_ID;
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 | #define at_assert(exp) do { \
|
| 97 | if(exp == 0) { \
|
| 98 | assert(0); \
|
| 99 | } \
|
| 100 | } while(0)
|
| 101 |
|
| 102 |
|
| 103 | /**
|
| 104 | * @brief ½ø³Ì¼äͨÐÅÏûÏ¢·¢Ëͽӿڣ¬Èç¹ûÏûÏ¢¶ÓÁÐδ´´½¨£¬·µ»ØÊ§°ÜֵΪ-1
|
| 105 | * @param source_id(IN) :ÏûÏ¢·¢ËÍÄ£¿éID
|
| 106 | * @param target_id(IN) :ÏûÏ¢½ÓÊÕÄ£¿éID
|
| 107 | * @param Msg_cmd(IN) :ÏûÏ¢ÃüÁÓÃÓÚ½ÓÊÕÄ£¿é´¦ÀíÏûϢʱ£¬È·¶¨ÏûÏ¢´¦ÀíµÄ·½Ê½
|
| 108 | * @param us_DataLen(IN) :ÏûÏ¢ÖÐЯ´øÊý¾ÝµÄ³¤¶È
|
| 109 | * @param pData(IN) :ÏûÏ¢ÖÐЯ´øµÄÊý¾ÝÄÚÈÝ
|
| 110 | * @param msgflag(IN) :ÏûÏ¢µÄ·¢ËÍ·½Ê½£¬0±íʾ×èÈû·¢ËÍ£¬IPC_NOWAIT±íʾ·Ç×èÈû·¢ËÍ
|
| 111 | * @return ·¢Ëͳɹ¦·µ»Ø0£¬·¢ËÍʧ°Ü·µ»Ø·Ç0£¬¾ßÌå´íÎóÀàÐÍÇë²Î¿¼linux±ê×¼µÄerrnoÀàÐÍ
|
| 112 | * @note ·¢ËÍʧ°Ü£¬Ó¦ÓÃÅжÏerrno == ENOENT, ±íʾ¶ÓÁÐÂú£»Èô½ÓÊÕ·½Ò»¶¨»á±»Æô¶¯£¬·¢ËÍ·½¿É¼ÌÐøµ÷ÓÃipc_send_msg2½Ó¿Ú
|
| 113 | */
|
| 114 | int at_send_msg(int source_id, int target_id, unsigned short Msg_cmd, unsigned short us_DataLen, unsigned char *pData, int msgflag);
|
| 115 |
|
| 116 | /**
|
| 117 | * @brief Ó¦Ó÷¢ËͶ¯×÷Àà»ò²éѯÀàATÇëÇó¸ø3GPPÐÒéÕ»£¬²¢×èÈûµÈ´ý¶¯×÷½á¹û£»×¢Ò⣺¸Ã½Ó¿ÚÖ»ÄÜÓÃÓÚ²éѯºÍÉèÖúÍÖ´ÐÐÇëÇó£¬Í¨¹ýÈë²Î½øÐÐÖмä½á¹ûµÄÄÚ²¿½âÎö´¦Àí£¬²¢ÇÒ
|
| 118 | ÓÐÖмä½á¹ûÉϱ¨Ê±£¬Ö»Ö§³ÖÒ»ÌõÖмä½á¹ûµÄÉϱ¨½âÎö£»
|
| 119 | * @param req_at ÇëÇóATÃüÁ´óСдÃô¸Ð£¬±ØÐë´óд
|
| 120 | * @param info_fmt ATÏìÓ¦µÄ¸ñʽ»¯·½Ê½
|
| 121 | * @param pval ¸ñʽ»¯ºóµÄATÏìÓ¦£¬¾ßÌåʹÓòο´parse_param½Ó¿Ú
|
| 122 | * @param timeout ºÁÃëΪµ¥Î»µÄµÈ´ý½á¹ûʱ³¤
|
| 123 | * @return 0±íʾ·µ»Ø³É¹¦£¬ÆäËûÖµ±íʾʧ°Ü´íÎóÂë
|
| 124 | * @note
|
| 125 | * 1. Óû§Ê¹ÓÃʱ£¬Èô²»ÏëÓɸýӿÚÄÚ²¿½øÐвÎÊýµÄ¸ñʽ»¯½âÎö£¬¿ÉÒÔ½«info_fmt¸³ÖµÎª"%s"£¬pval¸³ÖµÎªchar **p˫ָÕ룬ÕâÑù²ÎÊý½«×÷ΪÕûÌå×Ö·û´®·µ»Ø¸øµ÷ÓÃÕß
|
| 126 | * 2. ¶ÔÓÚZMGL,CPBR, COPS=?µÈÒ»ÌõÇëÇó»áÓжàÌõÖмä½á¹ûÇé¿ö£¬¸Ãº¯Êý²»ÊÊÓÃ
|
| 127 | * 3. ×Ö·û´®½âÎöʱµÄÈë²Î³¤¶È±ØÐë´óÓÚ¿ÉÄܽâ³öµÄ×Ö·û´®³¤¶È£¬·ñÔò»áÔ½½ç
|
| 128 | * 4. µ±´æÔÚÖмäÉϱ¨Ê±£¬pvalºÍinfo_fmt²»Îª¿Õ£»µ±ÎªÖмäÉϱ¨Ê±£¬Á½¸ö±ØÐë½ÔΪ¿Õ
|
| 129 | * 5. pvalºÍinfo_fmtÁ½ÕßҪô¶¼ÎªNULL,Ҫô¶¼²»ÎªNULL£¬²»ÄÜ´æÔÚÆäÖÐÒ»¸öΪNULL£¬ÁíÒ»¸ö²»ÎªNULLµÄÇé¿ö
|
| 130 | * 6. ʾÀý
|
| 131 | <pre>
|
| 132 | int ret = 0;
|
| 133 | ret = get_modem_info("AT+CFUN=1\r", NULL, NULL, 1000);
|
| 134 | //·µ»Ø¼´±íʾִÐгɹ¦
|
| 135 |
|
| 136 | char *pstr = malloc(50);
|
| 137 | memset(pstr,0,50);
|
| 138 | ret = get_modem_info("AT+CIMI\r", "%s", (void**)&pstr,1000);
|
| 139 | //·µ»Øºópstr==111111111111111
|
| 140 |
|
| 141 | int n1 = 0;
|
| 142 | int n2 = 0;
|
| 143 | int n3 = 0;
|
| 144 | char *p2[] = {&n1,&n2,&n3};
|
| 145 | ret = get_modem_info("AT+CCIOTOPT?\r", "%d,%d,%d", (void**)p2,1000);
|
| 146 | //+CCIOTOPT: 1,2,3½âÎöºón1==1 n2==2 n3==3
|
| 147 | </pre>
|
| 148 | * @warning
|
| 149 | */
|
| 150 |
|
| 151 | int get_modem_info(char *req_at,char *info_fmt,void **pval, int timeout);
|
| 152 |
|
| 153 | /**
|
| 154 | * @brief ATÃüÁî½âÎö½Ó¿Ú
|
| 155 | * @param fmt ATÇëÇó»òÏìÓ¦µÄ¸ñʽ»¯·½Ê½
|
| 156 | * @param buf ATÇëÇó»òÏìÓ¦µÄ×Ö·û´®Ö¸Õë²»º¬Í·²¿ºÍ¿Õ¸ñ
|
| 157 | * @param pval ¸ñʽ»¯ºóµÄATÃüÁî
|
| 158 | * @return 0±íʾ½âÎö²ÎÊýÕý³££¬²»½øÐвÎÊý¸öÊýµÄÓÐЧÐÔ¼ì²é£¬¾ßÌå·µ»ØÖµ²Î¿´¸ÃÍ·ÎļþSAP_ERRö¾ÙÀàÐÍÖÐAT_PARSE_OKµÈºêÖµ
|
| 159 | * @note
|
| 160 | * 1. ½âÎöµÄATÃüÁî±ØÐë°´ÕÕ3GPP27007±ê×¼ÐÒ飬²ÎÊýÒÔ¶ººÅ¸ô¿ª£¬×Ö·û´®Ðè´øË«ÒýºÅ£¬·ñÔò»á¶ÏÑÔ
|
| 161 | * 2. ×Ö·û´®½âÎöʱµÄÈë²Î³¤¶È±ØÐë´óÓÚ¿ÉÄܽâ³öµÄ×Ö·û´®³¤¶È£¬·ñÔò»áÔ½½ç
|
| 162 | * 3. ·µ»ØÖµÇë²Î¿¼Ã¶¾Ùenum SAP_ERR,²»½øÐвÎÊý¸öÊýµÄÓÐЧÐÔ¼ì²é
|
| 163 | * 4. ÈôfmtÖ¸¶¨µÄ²ÎÊýÀàÐͱØÐëÓëpvalÖÐÖ¸ÕëµÄÒ»Ò»¶ÔÓ¦
|
| 164 | * 5. ʾÀý
|
| 165 | <pre>
|
| 166 | char buf[]="1,2,\"test\"";
|
| 167 | int n1 = 0;
|
| 168 | int n2 = 0;
|
| 169 | char *n3 = malloc(strlen(buf));
|
| 170 | char *p[] = {&n1,&n2,n3};
|
| 171 | ret = parse_param("%d,%d,%s", buf, (void**)p);
|
| 172 | //½âÎöºón1==1 n2==2 n3=="test"
|
| 173 | ret = parse_param("%4d,%d,%3s", buf, (void**)p);
|
| 174 | //½âÎöºón1==1 n2==2 n3=="te"
|
| 175 | </pre>
|
| 176 | * @warning
|
| 177 | */
|
| 178 |
|
| 179 | int parse_param(char *fmt, char *buf, void **pval);
|
| 180 |
|
| 181 | /**
|
| 182 | * @brief ·þÎñ¶ËÓ¦ÓóÌÐò£¬·¢ËÍÖмä½á¹ûºÍÏìÓ¦µ½ÖÐÐË΢оƬ
|
| 183 | * @param module_id Ó¦ÓÃÄ£¿é¶ÓÁÐid
|
| 184 | * @param rsp_cmd ´ý·¢Ë͵½ÖÐÐË΢оƬµÄÊý¾Ý
|
| 185 | * @param rsp_len ÃüÁ¶È
|
| 186 | * @return intÐͽá¹ûÂë
|
| 187 | * @retval ³É¹¦ 0, ʧ°Ü -1
|
| 188 | * @note
|
| 189 | */
|
| 190 | int send_rsp_str_to_modem(int module_id, char *rsp_cmd,int rsp_len);
|
| 191 |
|
| 192 | #endif
|
| 193 |
|