结构体
esp_at_cmd_struct 该结构体用来定义AT命令 typedef struct { char *at_cmdName; /*!< at command name */ uint8_t (*at_testCmd)(uint8_t *cmd_name); /*!<测试命令函数指针 */ uint8_t (*at_queryCmd)(uint8_t *cmd_name); /*!<查询命令函数指针 */ uint8_t (*at_setupCmd)(uint8_t para_num); /*!< 设置命令函数指针 */ uint8_t (*at_exeCmd)(uint8_t *cmd_name); /*!< 执行命令函数指针 */ } esp_at_cmd_struct; /** * @brief esp_at_device_ops_struct * 设备操作AT的函数结构 */ typedef struct { int32_t (*read_data) (uint8_t *data, int32_t len); /*!< 从设备读数据 */ int32_t (*write_data)(uint8_t *data, int32_t len); /*!< 写数据到设备 */ int32_t (*get_data_length)(void); /*!< 获取接收数据的长度 */ bool (*wait_write_complete)(int32_t timeout_msec); /*!< 等待写数据结束 */ } esp_at_device_ops_struct; /* *@brief esp_at_custom_net_ops_struct *网络接收函数结构 for AT * */ typedef struct { int32_t (*recv_data)(uint8_t*data,int32_t len); void (*connect_cb)(void); void (*disconnect_cb)(void); } esp_at_custom_net_ops_struct; /** * @brief esp_at_status * some custom function interacting with AT * */ typedef enum { ESP_AT_STATUS_NORMAL = 0x0, /*!< 一般模式.mcu 可以发送AT command */ ESP_AT_STATUS_TRANSMIT, /*!<透传模式 */ } esp_at_status_type; /** * @brief esp_at_ops_struct * AT的用户函数接口 * */ typedef struct { void (*status_callback) (esp_at_status_type status); /*!< callback when AT status changes */ void (*pre_deepsleep_callback) (void); /*!< callback before enter deep sleep */ void (*pre_restart_callback) (void); } esp_at_custom_ops_struct; /** * @AT特定的回调类型 * */ typedef void (*esp_at_port_specific_callback_t) (void); // error number /** * @brief module number,Now just AT module * */ typedef enum { ESP_AT_MODULE_NUM = 0x01 } esp_at_module; /** * @brief 子类别编号 * */ typedef enum { ESP_AT_SUB_OK = 0x00, /*!< OK */ ESP_AT_SUB_COMMON_ERROR = 0x01, ESP_AT_SUB_NO_TERMINATOR = 0x02, /*!< 不以 "\r\n"结束 */ ESP_AT_SUB_NO_AT = 0x03, /*!< 没有发现 AT or at or At or aT */ ESP_AT_SUB_PARA_LENGTH_MISMATCH = 0x04, /*!< 参数长度不匹配 */ ESP_AT_SUB_PARA_TYPE_MISMATCH = 0x05, /*!< 参数长度不匹配 */ ESP_AT_SUB_PARA_NUM_MISMATCH = 0x06, /*!< 参数长度不匹配 */ ESP_AT_SUB_PARA_INVALID = 0x07, ESP_AT_SUB_PARA_PARSE_FAIL = 0x08, /*!< 解析参数失败 */ ESP_AT_SUB_UNSUPPORT_CMD = 0x09, ESP_AT_SUB_CMD_EXEC_FAIL = 0x0A, ESP_AT_SUB_CMD_PROCESSING = 0x0B, /*!< 上一个命令正在处理 */ ESP_AT_SUB_CMD_OP_ERROR = 0x0C, } esp_at_error_code; #define ESP_AT_ERROR_NO(subcategory,extension) \ ((ESP_AT_MODULE_NUM << 24) | ((subcategory) << 16) | (extension)) #define ESP_AT_CMD_ERROR_OK ESP_AT_ERROR_NO(ESP_AT_SUB_OK,0x00) #define ESP_AT_CMD_ERROR_NON_FINISH ESP_AT_ERROR_NO(ESP_AT_SUB_NO_TERMINATOR,0x00) #define ESP_AT_CMD_ERROR_NOT_FOUND_AT ESP_AT_ERROR_NO(ESP_AT_SUB_NO_AT,0x00) #define ESP_AT_CMD_ERROR_PARA_LENGTH(which_para) ESP_AT_ERROR_NO(ESP_AT_SUB_PARA_LENGTH_MISMATCH,which_para) #define ESP_AT_CMD_ERROR_PARA_TYPE(which_para) ESP_AT_ERROR_NO(ESP_AT_SUB_PARA_TYPE_MISMATCH,which_para) #define ESP_AT_CMD_ERROR_PARA_NUM(need,given) ESP_AT_ERROR_NO(ESP_AT_SUB_PARA_NUM_MISMATCH,(((need) << 8) | (given))) #define ESP_AT_CMD_ERROR_PARA_INVALID(which_para) ESP_AT_ERROR_NO(ESP_AT_SUB_PARA_INVALID,which_para) #define ESP_AT_CMD_ERROR_PARA_PARSE_FAIL(which_para) ESP_AT_ERROR_NO(ESP_AT_SUB_PARA_PARSE_FAIL,which_para) #define ESP_AT_CMD_ERROR_CMD_UNSUPPORT ESP_AT_ERROR_NO(ESP_AT_SUB_UNSUPPORT_CMD,0x00) #define ESP_AT_CMD_ERROR_CMD_EXEC_FAIL(result) ESP_AT_ERROR_NO(ESP_AT_SUB_CMD_EXEC_FAIL,result) #define ESP_AT_CMD_ERROR_CMD_PROCESSING ESP_AT_ERROR_NO(ESP_AT_SUB_CMD_PROCESSING,0x00) #define ESP_AT_CMD_ERROR_CMD_OP_ERROR ESP_AT_ERROR_NO(ESP_AT_SUB_CMD_OP_ERROR,0x00) /** * @brief AT解析的结果 * */ typedef enum { ESP_AT_PARA_PARSE_RESULT_FAIL = -1, /*!<解析失败,可能是参数类型不匹配或超出范围 */ ESP_AT_PARA_PARSE_RESULT_OK = 0, /*!< Successful */ ESP_AT_PARA_PARSE_RESULT_OMITTED, /*!< 参数是OMITTED. */ } esp_at_para_parse_result_type; /** * @简要介绍AT命令处理的结果代码 * */ typedef enum { ESP_AT_RESULT_CODE_OK = 0x00, /*!< "OK" */ ESP_AT_RESULT_CODE_ERROR = 0x01, /*!< "ERROR" */ ESP_AT_RESULT_CODE_FAIL = 0x02, /*!< "ERROR" */ ESP_AT_RESULT_CODE_SEND_OK = 0x03, /*!< "SEND OK" */ ESP_AT_RESULT_CODE_SEND_FAIL = 0x04, /*!< "SEND FAIL" */ ESP_AT_RESULT_CODE_IGNORE = 0x05, /*!< response nothing */ ESP_AT_RESULT_CODE_PROCESS_DONE = 0x06, /*!< response nothing */ ESP_AT_RESULT_CODE_MAX } esp_at_result_code_string_index;API介绍
/** * @brief This function should be called only once, before any other AT functions are called. * * @param netconn_max at模块中链接的最大数量 * @param custom_version 自定义版本信息 */ void esp_at_module_init(uint32_t netconn_max, const uint8_t *custom_version); /** * @brief 从命令字符串解析数字参数. * * @param para_index the index of parameter * @param value the value parsed * * @return * - ESP_AT_PARA_PARSE_RESULT_OK : succeed * - ESP_AT_PARA_PARSE_RESULT_FAIL : fail * - ESP_AT_PARA_PARSE_RESULT_OMITTED : this parameter is OMITTED */ esp_at_para_parse_result_type esp_at_get_para_as_digit(int32_t para_index, int32_t *value); /** * @brief 从命令字符串解析字符串参数. * * @param para_index the index of parameter * @param result the pointer that point to the result. * * @return * - ESP_AT_PARA_PARSE_RESULT_OK : succeed * - ESP_AT_PARA_PARSE_RESULT_FAIL : fail * - ESP_AT_PARA_PARSE_RESULT_OMITTED : this parameter is OMITTED */ esp_at_para_parse_result_type esp_at_get_para_as_str(int32_t para_index, uint8_t **result); /** * @brief 调用esp_at_port_recv_data_notify_from_isr通知模块端口接收到的数据。 *收到此通知后,任务将通过调用esp_at_device_ops中的get_data_length和read_data来获取数据。 *此功能必须在isr中使用。 * * @param len data length * */ void esp_at_port_recv_data_notify_from_isr(int32_t len); /** * @brief调用esp_at_port_recv_data_notify通知模块端口收到的数据。 *收到此通知后,任务将通过调用esp_at_device_ops中的get_data_length和read_data来获取数据。 *此功能不得用于isr。 * * @param len数据长度 * @param msec超时时间,单位为毫秒。 如果msec是portMAX_DELAY,它会永远等待。 * * @return * - true : succeed * - false : fail */ bool esp_at_port_recv_data_notify(int32_t len, uint32_t msec); /** * @brief 终端透明传输模式,此功能必须在isr中使用。 * */ void esp_at_transmit_terminal_from_isr(void); /** * @brief terminal transparent transmit mode,This function MUST NOT be used in isr. * */ void esp_at_transmit_terminal(void); /** * @brief注册命令集,由custom定义, * * @param custom_at_cmd_array at命令集 * @param cmd_num命令编号 * */ bool esp_at_custom_cmd_array_regist(const esp_at_cmd_struct *custom_at_cmd_array, uint32_t cmd_num); /** * @brief regist device operate functions set, * * @param ops device operate functions set * */ void esp_at_device_ops_regist(esp_at_device_ops_struct* ops); /* * @brief注册关于套接字状态的自定义回调, * * @param link_id链接ID * @param ops自定义操作功能集 * *注意:确保在esp_at_module_init之后调用此API。 */ bool esp_at_custom_net_ops_regist (int32_t link_id,esp_at_custom_net_ops_struct* ops); /** * @brief regist custom operate functions set interacting with AT, * * @param ops custom operate functions set * */ void esp_at_custom_ops_regist(esp_at_custom_ops_struct* ops); /** * @brief get at module version number, * * @return at version bit31~bit24: at main version * bit23~bit16: at sub version * bit15~bit8 : at test version * bit7~bit0 : at custom version */ uint32_t esp_at_get_version(void); /** * @brief response AT process result, * * @param result_code see esp_at_result_code_string_index * */ void esp_at_response_result(uint8_t result_code); /** * @brief write data into device, * * @param data data buffer to be written * @param len data length * * @return * - >= 0 : the real length of the data written * - others : fail. */ int32_t esp_at_port_write_data(uint8_t *data, int32_t len); /** * @brief read data from device, * * @param data data buffer * @param len data length * * @return * - >= 0 : the real length of the data read from device * - others : fail */ int32_t esp_at_port_read_data(uint8_t*data,int32_t len); /** * @brief wait for transmitting data completely to peer device, * * @param timeout_msec timeout time,The unit is millisecond. * * @return * - true : succeed,transmit data completely * - false : fail */ bool esp_at_port_wait_write_complete(int32_t timeout_msec); /** * @brief get the length of the data received, * * @return * - >= 0 : the length of the data received * - others : fail */ int32_t esp_at_port_get_data_length(void); /** * @brief regist at base command set. If not,you can not use AT base command * @param NONE * */ bool esp_at_base_cmd_regist(void); /** * @brief regist at wifi command set. If not,you can not use AT wifi command * @param NONE * */ bool esp_at_wifi_cmd_regist(void); /** * @brief regist at net command set. If not,you can not use AT net command * @param NONE * */ bool esp_at_net_cmd_regist(void); /** * @brief regist at ble command set. If not,you can not use AT ble command * @param NONE * */ bool esp_at_ble_cmd_regist(void); /** * @brief regist at bt command set. If not,you can not use AT bt command * @param NONE * */ bool esp_at_bt_cmd_regist(void); /** * @brief regist at fs command set. If not,you can not use AT fs command * @param NONE * */ bool esp_at_fs_cmd_regist(void); /** * @brief 注册WPA2 Enterprise AP命令集。 如果没有,则无法使用AT EAP命令 * @param NONE * */ bool esp_at_eap_cmd_regist(void); /** * @brief 注册以太网命令集。 如果没有,则不能使用AT ethernet命令 * @param NONE * */ bool esp_at_eth_cmd_regist(void); /** * @brief设置AT命令终止符,默认情况下,终结符为“\ r \ n” *您可以通过调用此函数来更改它,但它现在只支持一个字符。 * @param NONE * * @return * - true : succeed,transmit data completely * - false : fail */ bool esp_at_custom_cmd_line_terminator_set(uint8_t* terminator); /** * @brief 获取AT命令行终止符,默认情况下,返回字符串为“\ r \ n” * @param NONE * * @return the command line terminator */ uint8_t* esp_at_custom_cmd_line_terminator_get(void); /** * @brief找到at_customize.csv中定义的分区 * @param键入分区的类型 *子类型分区的子类型 *标签分区标签 * * @return指向esp_partition_t结构的指针,如果没有找到分区,则返回NULL。 *此指针在应用程序的生命周期内有效 */ const esp_partition_t* esp_at_custom_partition_find(esp_partition_type_t type, esp_partition_subtype_t subtype, const char* label); /** * @brief regist at ethernet command set. If not,you can not use AT ethernet command * @param NONE * */ bool esp_at_eth_cmd_regist(void); /** * @brief AT核心作为特定状态,它将在接收数据时调用回调。 * for example: * * static void wait_data_callback (void) { xSemaphoreGive(sync_sema); } void process_task(void* para) { vSemaphoreCreateBinary(sync_sema); xSemaphoreTake(sync_sema,portMAX_DELAY); esp_at_port_write_data((uint8_t *)">",strlen(">")); esp_at_port_enter_specific(wait_data_callback); while(xSemaphoreTake(sync_sema,portMAX_DELAY)) { len = esp_at_port_read_data(data, data_len); // TODO: } } * @param callback * */ void esp_at_port_enter_specific(esp_at_port_specific_callback_t callback); /** * @brief Exit AT core as specific status. * @param NONE * */ void esp_at_port_exit_specific(void); /** * @brief Get current AT command name. * @param NONE */ const uint8_t* esp_at_get_current_cmd_name(void); #endif