1 /* 2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 **************************************************************************************** 18 * 19 * @file lega_at_api.h 20 * 21 * @brief AT API. 22 * 23 **************************************************************************************** 24 */ 25 #ifndef _AT_API_H_ 26 #define _AT_API_H_ 27 28 #include <stdio.h> 29 #include "stdio.h" 30 #include "sonata_ble_hook.h" 31 32 #define SONATA_AT_VERSION "AT-V0.9.1" 33 #define SONATA_SDK_VERSION "SDK-V1.0.10" 34 #define SONATA_APP_VERSION "APP-V1.0.10" 35 36 typedef struct _cmd_entry { 37 char *name; 38 int (*function)(int, char **); 39 char *help; 40 } cmd_entry; 41 42 typedef struct { 43 uint8_t uart_echo; /* echo uart input info log */ 44 uint8_t max_txpwr; /* max tx power for both sta and softap */ 45 uint8_t flag_sap; /* flag of user set softap ip config */ 46 uint8_t flag_sta; /* flag of user set sta ip config */ 47 uint8_t dis_dhcp; /* disable dhcp func, use static ip */ 48 uint8_t at_scan; /* scan flag which indicate call by at task */ 49 uint8_t sta_connected; /* indicate status of station is connected */ 50 uint8_t sap_opend; /* indicate status of softap is open done */ 51 // ip_addr_t at_ping; /* save ping ip addr for at cmd */ 52 char ip[16]; /* Local IP address on the target wlan interface, ASCII */ 53 char gw[16]; /* Router IP address on the target wlan interface, ASCII */ 54 char mask[16]; /* Netmask on the target wlan interface, ASCII */ 55 } at_user_info_s; 56 57 typedef enum { 58 CONFIG_OK, /* indicate at cmd set success and response OK */ 59 PARAM_RANGE, /* indicate some at cmd param is out of range */ 60 PARAM_MISS, /* indicate at cmd param is less than needed count */ 61 CONFIG_FAIL, /* indicate at cmd set failed, or execute fail */ 62 CONN_TIMEOUT, /* indicate connect timeout in station mode */ 63 CONN_EAPOL_FAIL, /* indicate 4-way handshake failed in station mode */ 64 CONN_DHCP_FAIL, /* indicate got ip by dhcp failed in station mode */ 65 RSP_NULL = 0xFF 66 } at_rsp_status_t; 67 68 typedef struct { 69 char *command; /* at cmd string */ 70 int (*function)(int argc, char **argv); /* at cmd proccess function */ 71 } at_cmd_entry; 72 int at_init(void); 73 void at_command_process_ble(void); 74 /** @brief register user at cmd. 75 * 76 * @param cmd_entry : user at cmd array pointer 77 * @param cmd_num : user at cmd number 78 */ 79 void at_cmd_register(const cmd_entry *cmd); 80 81 /** @brief at init functin, user should call it before use at cmd 82 * @return 0 : on success. 83 * @return other : error occurred 84 */ 85 int lega_at_init(const char *task_name, uint8_t task_pri, uint32_t task_stack_size); 86 87 /** @brief at deinit functin, user should call it when donot use at any more, to free resources 88 * @return 0 : on success. 89 * @return other : error occurred 90 */ 91 int at_deinit(void); 92 93 /** @brief at command callback function, used to register to uart. 94 */ 95 void at_handle_uartirq(char ch); 96 97 /** @brief uart handle for receiving at command. 98 */ 99 100 /** @brief at register init functin, register all support cmd and user register cmd 101 */ 102 void at_cmd_register_all(void); 103 104 /** @brief register user cmd 105 */ 106 void at_user_cmd_register(void); 107 void at_gapc_cmd_register(void); 108 void at_gapm_cmd_register(void); 109 void at_gattc_cmd_register(void); 110 111 /** @brief at response, OK indicate success, others indicate failed. 112 */ 113 void at_response(at_rsp_status_t status); 114 extern int at_printf(const char *format, ...); 115 116 extern char at_dbgflg; 117 118 #define at_printf printf 119 120 #define dbg_at(Fmt, ...) do {if (at_dbgflg) at_printf(Fmt "\r\n", ## __VA_ARGS__);} while (0) 121 #define dbg_atnn(Fmt, ...) do {if (at_dbgflg) at_printf(Fmt, ## __VA_ARGS__);} while (0) 122 123 #define at_rspdata(Fmt, ...) at_printf("+" Fmt "\r\n", ## __VA_ARGS__) 124 #define at_rspdatann(Fmt, ...) at_printf("+" Fmt, ## __VA_ARGS__) 125 #define at_rspinfor(Fmt, ...) at_printf(Fmt "\r\n", ## __VA_ARGS__) 126 #define at_rspinfornn(Fmt, ...) at_printf(Fmt, ## __VA_ARGS__) 127 128 #endif // _AT_API_H_ 129 130