Skip to content

Commit b95d8be

Browse files
committed
fix(modem_sim): Support of PPPD exit
1 parent 9302994 commit b95d8be

File tree

4 files changed

+45
-49
lines changed

4 files changed

+45
-49
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,9 @@ docs/html
9494

9595
# esp-idf managed components
9696
**/managed_components/**
97+
98+
# modem simulator uses esp-at clone
99+
common_components/modem_sim/modem_sim_esp32/
100+
101+
# repository release tools
102+
release_notes.txt

common_components/modem_sim/install.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23

34
# Create directory "modem_sim_esp32", go inside it
45
# Usage: ./install.sh [platform] [module]
@@ -7,21 +8,25 @@ SCRIPT_DIR=$(pwd)
78
mkdir -p modem_sim_esp32
89
cd modem_sim_esp32
910

10-
# Shallow clone https://github.com/espressif/esp-at.git
11+
if [ -z "$IDF_PATH" ]; then
12+
echo "Error: IDF_PATH environment variable is not set"
13+
exit 1
14+
fi
15+
16+
# Default ESP_AT_VERSION uses this specific commit from master to support new chips and features
17+
ESP_AT_VERSION="aa9d7e0e9b741744f7bf5bec3bbf887cff033d5f"
18+
19+
# Shallow clone of esp-at.git at $ESP_AT_VERSION
1120
if [ ! -d "esp-at" ]; then
12-
git clone --depth 1 https://github.com/espressif/esp-at.git
21+
# cannot shallow clone from a specific commit, so we init, shallow fetch, and checkout
22+
mkdir -p esp-at && cd esp-at && git init && git remote add origin https://github.com/espressif/esp-at.git
23+
git fetch --depth 1 origin $ESP_AT_VERSION && git checkout $ESP_AT_VERSION
1324
else
1425
echo "esp-at directory already exists, skipping clone."
26+
cd esp-at
1527
fi
1628

17-
cd esp-at
18-
1929
# Add esp-idf directory which is a symlink to the $IDF_PATH
20-
if [ -z "$IDF_PATH" ]; then
21-
echo "Error: IDF_PATH environment variable is not set"
22-
exit 1
23-
fi
24-
2530
if [ ! -L "esp-idf" ]; then
2631
ln -sf "$IDF_PATH" esp-idf
2732
else
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
2-
file(GLOB_RECURSE srcs *.c)
3-
4-
set(includes "include")
5-
6-
# Add more required components you need here, separated by spaces
7-
set(require_components at freertos nvs_flash)
8-
91
idf_component_register(
10-
SRCS ${srcs}
11-
INCLUDE_DIRS ${includes}
12-
REQUIRES ${require_components})
2+
SRCS additional_commands.c
3+
INCLUDE_DIRS include
4+
REQUIRES at freertos nvs_flash)
135

146
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE TRUE)

common_components/modem_sim/pppd_cmd/custom/at_custom_cmd.c renamed to common_components/modem_sim/pppd_cmd/additional_commands.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "esp_http_server.h"
2020
#include "esp_timer.h"
2121

22-
extern uint8_t g_at_cmd_port;
23-
2422
static uint8_t at_test_cmd_test(uint8_t *cmd_name)
2523
{
2624
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
102100
static SemaphoreHandle_t at_sync_sema = NULL;
103101
static void wait_data_callback(void)
104102
{
105-
static uint8_t buffer[1024] = {0};
106-
// xSemaphoreGive(at_sync_sema);
103+
static uint8_t buffer[1500] = {0};
107104
int len = esp_at_port_read_data(buffer, sizeof(buffer) - 1);
108-
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_recv", buffer, len, ESP_LOG_VERBOSE);
105+
106+
// Check for the escape sequence "+++" in the received data
107+
const uint8_t escape_seq[] = "+++";
108+
uint8_t *escape_ptr = memmem(buffer, len, escape_seq, 3);
109+
110+
if (escape_ptr != NULL) {
111+
printf("Found +++ sequence, signal to the command processing thread\n");
112+
113+
int data_before_escape = escape_ptr - buffer;
114+
if (data_before_escape > 0) {
115+
esp_netif_receive(s_netif, buffer, data_before_escape, NULL);
116+
}
117+
118+
if (at_sync_sema) {
119+
xSemaphoreGive(at_sync_sema);
120+
}
121+
return;
122+
}
109123
esp_netif_receive(s_netif, buffer, len, NULL);
110124
}
111125

112126
static esp_err_t transmit(void *h, void *buffer, size_t len)
113127
{
114-
// struct eppp_handle *handle = h;
115128
printf("transmit: %d bytes\n", len);
116-
// ESP_LOG_BUFFER_HEXDUMP("ppp_uart_send", buffer, len, ESP_LOG_INFO);
117129
esp_at_port_write_data(buffer, len);
118130
return ESP_OK;
119131
}
@@ -123,7 +135,7 @@ static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
123135
uint8_t buffer[64] = {0};
124136
snprintf((char *)buffer, 64, "execute command: <AT%s> is executed\r\n", cmd_name);
125137
esp_at_port_write_data(buffer, strlen((char *)buffer));
126-
printf("YYYEEES Command <AT%s> executed successfully\r\n", cmd_name);
138+
printf("Command <AT%s> executed successfully\r\n", cmd_name);
127139
if (!at_sync_sema) {
128140
at_sync_sema = xSemaphoreCreateBinary();
129141
assert(at_sync_sema != NULL);
@@ -162,22 +174,8 @@ static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
162174
esp_netif_action_start(s_netif, 0, 0, 0);
163175
esp_netif_action_connected(s_netif, 0, 0, 0);
164176

165-
// receive input data
166-
// while(xSemaphoreTake(at_sync_sema, portMAX_DELAY)) {
167-
// int len = esp_at_port_read_data(buffer, sizeof(buffer) - 1);
168-
// if (len > 0) {
169-
// buffer[len] = '\0'; // null-terminate the string
170-
// printf("Received data: %s\n", buffer);
171-
// } else {
172-
// printf("No data received or error occurred.\n");
173-
// continue;
174-
// }
175-
// }
176-
177-
// uart_write_bytes(g_at_cmd_port, "CONNECT\r\n", strlen("CONNECT\r\n"));
178-
while (1) {
179-
vTaskDelay(pdMS_TO_TICKS(1000));
180-
printf("-");
177+
while (xSemaphoreTake(at_sync_sema, pdMS_TO_TICKS(1000)) == pdFALSE) {
178+
printf(".");
181179
}
182180
return ESP_AT_RESULT_CODE_OK;
183181
}
@@ -191,7 +189,6 @@ static uint8_t at_test_cereg(uint8_t *cmd_name)
191189
static uint8_t at_query_cereg(uint8_t *cmd_name)
192190
{
193191
printf("%s: AT command <AT%s> is executed\r\n", __func__, cmd_name);
194-
// static uint8_t buffer[] = "+CEREG: 0,1,2,3,4,5\r\n";
195192
static uint8_t buffer[] = "+CEREG: 7,8\r\n";
196193
esp_at_port_write_data(buffer, sizeof(buffer));
197194
return ESP_AT_RESULT_CODE_OK;
@@ -209,7 +206,6 @@ static uint8_t at_exe_cereg(uint8_t *cmd_name)
209206
return ESP_AT_RESULT_CODE_OK;
210207
}
211208

212-
/* HTTP Server handlers */
213209
static esp_err_t hello_get_handler(httpd_req_t *req)
214210
{
215211
const char* resp_str = "Hello from ESP-AT HTTP Server!";
@@ -405,9 +401,6 @@ static const esp_at_cmd_struct at_custom_cmd[] = {
405401
{"+PPPD", at_test_cmd_test, at_query_cmd_test, at_setup_cmd_test, at_exe_cmd_test},
406402
{"+CEREG", at_test_cereg, at_query_cereg, at_setup_cereg, at_exe_cereg},
407403
{"+HTTPD", at_test_httpd, at_query_httpd, at_setup_httpd, at_exe_httpd},
408-
/**
409-
* @brief You can define your own AT commands here.
410-
*/
411404
};
412405

413406
bool esp_at_custom_cmd_register(void)

0 commit comments

Comments
 (0)