fix(modem_sim): Support of PPPD exit

This commit is contained in:
David Cermak
2025-07-11 11:00:56 +02:00
parent 9302994673
commit b95d8be41d
4 changed files with 46 additions and 50 deletions

6
.gitignore vendored
View File

@ -94,3 +94,9 @@ docs/html
# esp-idf managed components # esp-idf managed components
**/managed_components/** **/managed_components/**
# modem simulator uses esp-at clone
common_components/modem_sim/modem_sim_esp32/
# repository release tools
release_notes.txt

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
set -e
# Create directory "modem_sim_esp32", go inside it # Create directory "modem_sim_esp32", go inside it
# Usage: ./install.sh [platform] [module] # Usage: ./install.sh [platform] [module]
@ -7,21 +8,25 @@ SCRIPT_DIR=$(pwd)
mkdir -p modem_sim_esp32 mkdir -p modem_sim_esp32
cd modem_sim_esp32 cd modem_sim_esp32
# Shallow clone https://github.com/espressif/esp-at.git
if [ ! -d "esp-at" ]; then
git clone --depth 1 https://github.com/espressif/esp-at.git
else
echo "esp-at directory already exists, skipping clone."
fi
cd esp-at
# Add esp-idf directory which is a symlink to the $IDF_PATH
if [ -z "$IDF_PATH" ]; then if [ -z "$IDF_PATH" ]; then
echo "Error: IDF_PATH environment variable is not set" echo "Error: IDF_PATH environment variable is not set"
exit 1 exit 1
fi fi
# Default ESP_AT_VERSION uses this specific commit from master to support new chips and features
ESP_AT_VERSION="aa9d7e0e9b741744f7bf5bec3bbf887cff033d5f"
# Shallow clone of esp-at.git at $ESP_AT_VERSION
if [ ! -d "esp-at" ]; then
# cannot shallow clone from a specific commit, so we init, shallow fetch, and checkout
mkdir -p esp-at && cd esp-at && git init && git remote add origin https://github.com/espressif/esp-at.git
git fetch --depth 1 origin $ESP_AT_VERSION && git checkout $ESP_AT_VERSION
else
echo "esp-at directory already exists, skipping clone."
cd esp-at
fi
# Add esp-idf directory which is a symlink to the $IDF_PATH
if [ ! -L "esp-idf" ]; then if [ ! -L "esp-idf" ]; then
ln -sf "$IDF_PATH" esp-idf ln -sf "$IDF_PATH" esp-idf
else else

View File

@ -1,14 +1,6 @@
file(GLOB_RECURSE srcs *.c)
set(includes "include")
# Add more required components you need here, separated by spaces
set(require_components at freertos nvs_flash)
idf_component_register( idf_component_register(
SRCS ${srcs} SRCS additional_commands.c
INCLUDE_DIRS ${includes} INCLUDE_DIRS include
REQUIRES ${require_components}) REQUIRES at freertos nvs_flash)
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE TRUE) idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE TRUE)

View File

@ -19,8 +19,6 @@
#include "esp_http_server.h" #include "esp_http_server.h"
#include "esp_timer.h" #include "esp_timer.h"
extern uint8_t g_at_cmd_port;
static uint8_t at_test_cmd_test(uint8_t *cmd_name) static uint8_t at_test_cmd_test(uint8_t *cmd_name)
{ {
uint8_t buffer[64] = {0}; uint8_t buffer[64] = {0};
@ -102,18 +100,32 @@ static void on_ip_event(void *arg, esp_event_base_t base, int32_t event_id, void
static SemaphoreHandle_t at_sync_sema = NULL; static SemaphoreHandle_t at_sync_sema = NULL;
static void wait_data_callback(void) static void wait_data_callback(void)
{ {
static uint8_t buffer[1024] = {0}; static uint8_t buffer[1500] = {0};
// xSemaphoreGive(at_sync_sema);
int len = esp_at_port_read_data(buffer, sizeof(buffer) - 1); int len = esp_at_port_read_data(buffer, sizeof(buffer) - 1);
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_recv", buffer, len, ESP_LOG_VERBOSE);
// Check for the escape sequence "+++" in the received data
const uint8_t escape_seq[] = "+++";
uint8_t *escape_ptr = memmem(buffer, len, escape_seq, 3);
if (escape_ptr != NULL) {
printf("Found +++ sequence, signal to the command processing thread\n");
int data_before_escape = escape_ptr - buffer;
if (data_before_escape > 0) {
esp_netif_receive(s_netif, buffer, data_before_escape, NULL);
}
if (at_sync_sema) {
xSemaphoreGive(at_sync_sema);
}
return;
}
esp_netif_receive(s_netif, buffer, len, NULL); esp_netif_receive(s_netif, buffer, len, NULL);
} }
static esp_err_t transmit(void *h, void *buffer, size_t len) static esp_err_t transmit(void *h, void *buffer, size_t len)
{ {
// struct eppp_handle *handle = h;
printf("transmit: %d bytes\n", len); printf("transmit: %d bytes\n", len);
// ESP_LOG_BUFFER_HEXDUMP("ppp_uart_send", buffer, len, ESP_LOG_INFO);
esp_at_port_write_data(buffer, len); esp_at_port_write_data(buffer, len);
return ESP_OK; return ESP_OK;
} }
@ -123,7 +135,7 @@ static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
uint8_t buffer[64] = {0}; uint8_t buffer[64] = {0};
snprintf((char *)buffer, 64, "execute command: <AT%s> is executed\r\n", cmd_name); snprintf((char *)buffer, 64, "execute command: <AT%s> is executed\r\n", cmd_name);
esp_at_port_write_data(buffer, strlen((char *)buffer)); esp_at_port_write_data(buffer, strlen((char *)buffer));
printf("YYYEEES Command <AT%s> executed successfully\r\n", cmd_name); printf("Command <AT%s> executed successfully\r\n", cmd_name);
if (!at_sync_sema) { if (!at_sync_sema) {
at_sync_sema = xSemaphoreCreateBinary(); at_sync_sema = xSemaphoreCreateBinary();
assert(at_sync_sema != NULL); assert(at_sync_sema != NULL);
@ -162,22 +174,8 @@ static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
esp_netif_action_start(s_netif, 0, 0, 0); esp_netif_action_start(s_netif, 0, 0, 0);
esp_netif_action_connected(s_netif, 0, 0, 0); esp_netif_action_connected(s_netif, 0, 0, 0);
// receive input data while (xSemaphoreTake(at_sync_sema, pdMS_TO_TICKS(1000)) == pdFALSE) {
// while(xSemaphoreTake(at_sync_sema, portMAX_DELAY)) { printf(".");
// int len = esp_at_port_read_data(buffer, sizeof(buffer) - 1);
// if (len > 0) {
// buffer[len] = '\0'; // null-terminate the string
// printf("Received data: %s\n", buffer);
// } else {
// printf("No data received or error occurred.\n");
// continue;
// }
// }
// uart_write_bytes(g_at_cmd_port, "CONNECT\r\n", strlen("CONNECT\r\n"));
while (1) {
vTaskDelay(pdMS_TO_TICKS(1000));
printf("-");
} }
return ESP_AT_RESULT_CODE_OK; return ESP_AT_RESULT_CODE_OK;
} }
@ -191,7 +189,6 @@ static uint8_t at_test_cereg(uint8_t *cmd_name)
static uint8_t at_query_cereg(uint8_t *cmd_name) static uint8_t at_query_cereg(uint8_t *cmd_name)
{ {
printf("%s: AT command <AT%s> is executed\r\n", __func__, cmd_name); printf("%s: AT command <AT%s> is executed\r\n", __func__, cmd_name);
// static uint8_t buffer[] = "+CEREG: 0,1,2,3,4,5\r\n";
static uint8_t buffer[] = "+CEREG: 7,8\r\n"; static uint8_t buffer[] = "+CEREG: 7,8\r\n";
esp_at_port_write_data(buffer, sizeof(buffer)); esp_at_port_write_data(buffer, sizeof(buffer));
return ESP_AT_RESULT_CODE_OK; return ESP_AT_RESULT_CODE_OK;
@ -209,7 +206,6 @@ static uint8_t at_exe_cereg(uint8_t *cmd_name)
return ESP_AT_RESULT_CODE_OK; return ESP_AT_RESULT_CODE_OK;
} }
/* HTTP Server handlers */
static esp_err_t hello_get_handler(httpd_req_t *req) static esp_err_t hello_get_handler(httpd_req_t *req)
{ {
const char* resp_str = "Hello from ESP-AT HTTP Server!"; const char* resp_str = "Hello from ESP-AT HTTP Server!";
@ -405,9 +401,6 @@ static const esp_at_cmd_struct at_custom_cmd[] = {
{"+PPPD", at_test_cmd_test, at_query_cmd_test, at_setup_cmd_test, at_exe_cmd_test}, {"+PPPD", at_test_cmd_test, at_query_cmd_test, at_setup_cmd_test, at_exe_cmd_test},
{"+CEREG", at_test_cereg, at_query_cereg, at_setup_cereg, at_exe_cereg}, {"+CEREG", at_test_cereg, at_query_cereg, at_setup_cereg, at_exe_cereg},
{"+HTTPD", at_test_httpd, at_query_httpd, at_setup_httpd, at_exe_httpd}, {"+HTTPD", at_test_httpd, at_query_httpd, at_setup_httpd, at_exe_httpd},
/**
* @brief You can define your own AT commands here.
*/
}; };
bool esp_at_custom_cmd_register(void) bool esp_at_custom_cmd_register(void)