forked from espressif/esp-at
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdbool.h> | ||
#include "esp_at.h" | ||
|
||
static uint8_t at_test_cmd_test(uint8_t *cmd_name) | ||
{ | ||
uint8_t buffer[64] = {0}; | ||
snprintf((char *)buffer, 64, "test command: <AT%s=?> is executed\r\n", cmd_name); | ||
esp_at_port_write_data(buffer, strlen((char *)buffer)); | ||
|
||
return ESP_AT_RESULT_CODE_OK; | ||
} | ||
|
||
static uint8_t at_query_cmd_test(uint8_t *cmd_name) | ||
{ | ||
uint8_t buffer[64] = {0}; | ||
snprintf((char *)buffer, 64, "query command: <AT%s?> is executed\r\n", cmd_name); | ||
esp_at_port_write_data(buffer, strlen((char *)buffer)); | ||
|
||
return ESP_AT_RESULT_CODE_OK; | ||
} | ||
|
||
static uint8_t at_setup_cmd_test(uint8_t para_num) | ||
{ | ||
uint8_t index = 0; | ||
|
||
// get first parameter, and parse it into a digit | ||
int32_t digit = 0; | ||
if (esp_at_get_para_as_digit(index++, &digit) != ESP_AT_PARA_PARSE_RESULT_OK) { | ||
return ESP_AT_RESULT_CODE_ERROR; | ||
} | ||
|
||
// get second parameter, and parse it into a string | ||
uint8_t *str = NULL; | ||
if (esp_at_get_para_as_str(index++, &str) != ESP_AT_PARA_PARSE_RESULT_OK) { | ||
return ESP_AT_RESULT_CODE_ERROR; | ||
} | ||
|
||
// allocate a buffer and construct the data, then send the data to mcu via interface (uart/spi/sdio/socket) | ||
uint8_t *buffer = (uint8_t *)malloc(512); | ||
if (!buffer) { | ||
return ESP_AT_RESULT_CODE_ERROR; | ||
} | ||
int len = snprintf((char *)buffer, 512, "setup command: <AT%s=%d,\"%s\"> is executed\r\n", | ||
esp_at_get_current_cmd_name(), digit, str); | ||
esp_at_port_write_data(buffer, len); | ||
|
||
// remember to free the buffer | ||
free(buffer); | ||
|
||
return ESP_AT_RESULT_CODE_OK; | ||
} | ||
|
||
static uint8_t at_exe_cmd_test(uint8_t *cmd_name) | ||
{ | ||
uint8_t buffer[64] = {0}; | ||
snprintf((char *)buffer, 64, "execute command: <AT%s> is executed\r\n", cmd_name); | ||
esp_at_port_write_data(buffer, strlen((char *)buffer)); | ||
|
||
return ESP_AT_RESULT_CODE_OK; | ||
} | ||
|
||
static const esp_at_cmd_struct at_custom_cmd[] = { | ||
{"+TEST2", at_test_cmd_test, at_query_cmd_test, at_setup_cmd_test, at_exe_cmd_test}, | ||
/** | ||
* @brief You can define your own AT commands here. | ||
*/ | ||
}; | ||
|
||
bool esp_at_custom_cmd_register2(void) | ||
{ | ||
return esp_at_custom_cmd_array_regist(at_custom_cmd, sizeof(at_custom_cmd) / sizeof(esp_at_cmd_struct)); | ||
} | ||
|
||
ESP_AT_CMD_SET_INIT_FN(esp_at_custom_cmd_register2, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
#include "esp_at_core.h" | ||
#include "esp_at.h" | ||
|
||
/** | ||
* @brief You can include more header files here for your own AT commands. | ||
*/ |