Skip to content

Commit c273b00

Browse files
committed
Merge branch 'nw_split_linux_wip3' into 'master'
esp-hosted-fg: Refactor build system, add Python app support, and enhance networking See merge request app-frameworks/esp_hosted!576
2 parents e614114 + f718f91 commit c273b00

31 files changed

+1972
-671
lines changed

esp_hosted_fg/common/esp_hosted_config.pb-c.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7328,20 +7328,22 @@ const ProtobufCEnumDescriptor ctrl__wifi_bw__descriptor =
73287328
ctrl__wifi_bw__value_ranges,
73297329
NULL,NULL,NULL,NULL /* reserved[1234] */
73307330
};
7331-
static const ProtobufCEnumValue ctrl__wifi_power_save__enum_values_by_number[3] =
7331+
static const ProtobufCEnumValue ctrl__wifi_power_save__enum_values_by_number[4] =
73327332
{
7333-
{ "PS_Invalid", "CTRL__WIFI_POWER_SAVE__PS_Invalid", 0 },
7333+
{ "NO_PS", "CTRL__WIFI_POWER_SAVE__NO_PS", 0 },
73347334
{ "MIN_MODEM", "CTRL__WIFI_POWER_SAVE__MIN_MODEM", 1 },
73357335
{ "MAX_MODEM", "CTRL__WIFI_POWER_SAVE__MAX_MODEM", 2 },
7336+
{ "PS_Invalid", "CTRL__WIFI_POWER_SAVE__PS_Invalid", 3 },
73367337
};
73377338
static const ProtobufCIntRange ctrl__wifi_power_save__value_ranges[] = {
7338-
{0, 0},{0, 3}
7339+
{0, 0},{0, 4}
73397340
};
7340-
static const ProtobufCEnumValueIndex ctrl__wifi_power_save__enum_values_by_name[3] =
7341+
static const ProtobufCEnumValueIndex ctrl__wifi_power_save__enum_values_by_name[4] =
73417342
{
73427343
{ "MAX_MODEM", 2 },
73437344
{ "MIN_MODEM", 1 },
7344-
{ "PS_Invalid", 0 },
7345+
{ "NO_PS", 0 },
7346+
{ "PS_Invalid", 3 },
73457347
};
73467348
const ProtobufCEnumDescriptor ctrl__wifi_power_save__descriptor =
73477349
{
@@ -7350,9 +7352,9 @@ const ProtobufCEnumDescriptor ctrl__wifi_power_save__descriptor =
73507352
"Ctrl_WifiPowerSave",
73517353
"CtrlWifiPowerSave",
73527354
"",
7353-
3,
7355+
4,
73547356
ctrl__wifi_power_save__enum_values_by_number,
7355-
3,
7357+
4,
73567358
ctrl__wifi_power_save__enum_values_by_name,
73577359
1,
73587360
ctrl__wifi_power_save__value_ranges,

esp_hosted_fg/common/include/esp_hosted_config.pb-c.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esp_hosted_fg/common/include/esp_hosted_custom_rpc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,4 @@ enum custom_rpc_event_id {
2525
/* Add more event IDs as needed */
2626
};
2727

28-
/* Maximum size for RPC data */
29-
#define RPC_USER_SPECIFIC_EVENT_DATA_SIZE 1024
30-
3128
#endif /* __ESP_HOSTED_RPC_H__ */

esp_hosted_fg/common/proto/esp_hosted_config.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ enum Ctrl_WifiBw {
3131
}
3232

3333
enum Ctrl_WifiPowerSave {
34-
PS_Invalid = 0;
34+
NO_PS = 0;
3535
MIN_MODEM = 1;
3636
MAX_MODEM = 2;
37+
PS_Invalid = 3;
3738
}
3839

3940
enum Ctrl_WifiSecProt {

esp_hosted_fg/common/utils/esp_hosted_cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,10 @@ int esp_cli_register_cmds()
455455
#ifdef CONFIG_ESP_HOSTED_COPROCESSOR
456456
#ifdef CONFIG_SLAVE_MANAGES_WIFI
457457
app_register_all_wifi_commands();
458-
#endif
459458
app_register_iperf_commands();
460459
app_register_ping_commands();
461460
app_register_iperf_hook_func(iperf_hook_show_wifi_stats);
461+
#endif
462462
#endif
463463
return 0;
464464
}

esp_hosted_fg/docs/common/c_demo.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ $ sudo ./hosted_daemon.out -f
248248
- Shows how to handle custom responses and events
249249

250250
> [!NOTE]
251+
>
251252
> 1. Provides APIs for sending packed data between host and ESP device.
252253
> 2. User is responsible for serializing data before sending and deserializing after receiving.
253254
@@ -288,10 +289,12 @@ It uses underlying control path API for reliable communication.
288289
- Host
289290
- Add your custom `requests` or `events` in [app_custom_rpc.c](../../host/linux/host_control/c_support/app_custom_rpc.c) and [app_custom_rpc.h](../../host/linux/host_control/c_support/app_custom_rpc.h).
290291
- Optionally, add your own Request and Message ID handling functions similar to the existing demo functions
291-
> [!CAUTION]
292+
293+
> [!CAUTION] Custom RPC Request - Response
292294
>
293295
> 1. The handlers in these requests should be as concise as possible.
294296
> 2. Although it is not interrupt context, try not to have blocking calls in the response handler, as this function is called as callback.
297+
295298
- Slave
296299
- In [slave_control.c](../../esp/esp_driver/network_adapter/main/slave_control.c), the default response handler for underlying RPC request handler is called with:
297300
```c
@@ -302,9 +305,13 @@ It uses underlying control path API for reliable communication.
302305
register_custom_rpc_unserialised_req_handler(handle_custom_unserialised_rpc_request);
303306
```
304307
- For your own message IDs, add cases in `handle_custom_unserialised_rpc_request()`
305-
> [!CAUTION]
308+
309+
> [!CAUTION] Custom RPC events
306310
>
307311
> 1. The handlers in these requests should be as concise as possible.
308312
> 2. Although it is not interrupt context, try not to have blocking calls in the response handler, as this function is called as callback.
313+
> 3. Refrain sending any synchronous RPC request as this would make it dead block (RPC Request `without` a response function callback registered - > `Sync RPC Req`)
314+
> 4. Sending any 'asynchronous' RPC request is supported (RPC Request `with` a response function callback registered - > `Async RPC Req`)
315+
309316
- You can also trigger events instead of immediate responses as demonstrated in `CUSTOM_RPC_REQ_ID__ECHO_BACK_AS_EVENT`
310317
- To add your own event, you can re-use `create_and_send_custom_rpc_unserialised_event()`

esp_hosted_fg/esp/esp_driver/network_adapter/main/slave_control.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,21 @@ static void send_wifi_event_data_to_host(int event, void *event_data, int event_
150150
#endif
151151
}
152152

153-
static bool wifi_is_provisioned(void)
153+
static bool wifi_is_provisioned(wifi_config_t *wifi_cfg)
154154
{
155-
wifi_config_t wifi_cfg = {0};
155+
if (!wifi_cfg) {
156+
ESP_LOGI(TAG, "NULL wifi cfg passed, ignore");
157+
return false;
158+
}
156159

157-
if (esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) {
160+
if (esp_wifi_get_config(WIFI_IF_STA, wifi_cfg) != ESP_OK) {
158161
ESP_LOGI(TAG, "Wifi get config failed");
159162
return false;
160163
}
161164

162-
ESP_LOGI(TAG, "SSID: %s", wifi_cfg.sta.ssid);
165+
ESP_LOGI(TAG, "SSID: %s", wifi_cfg->sta.ssid);
163166

164-
if (strlen((const char *) wifi_cfg.sta.ssid)) {
167+
if (strlen((const char *) wifi_cfg->sta.ssid)) {
165168
ESP_LOGI(TAG, "Wifi provisioned");
166169
return true;
167170
}
@@ -174,13 +177,14 @@ esp_err_t esp_hosted_set_sta_config(wifi_interface_t iface, wifi_config_t *cfg)
174177
{
175178

176179
wifi_config_t current_config = {0};
177-
if (!wifi_is_provisioned()) {
178-
ESP_LOGI(TAG, "Provisoning new Wi-Fi config");
180+
if (!wifi_is_provisioned(&current_config)) {
179181
if (esp_wifi_set_config(WIFI_IF_STA, cfg) != ESP_OK) {
180182
ESP_LOGW(TAG, "not provisioned and failed to set wifi config");
183+
} else {
184+
ESP_LOGI(TAG, "Provisioned new Wi-Fi config");
185+
prev_wifi_config_valid = false;
181186
}
182187
}
183-
prev_wifi_config_valid = false;
184188

185189
if (!is_wifi_config_equal(cfg, &current_config)) {
186190
new_config_recvd = 1;
@@ -1890,11 +1894,8 @@ static esp_err_t req_set_power_save_mode_handler (CtrlMsg *req,
18901894
resp->payload_case = CTRL_MSG__PAYLOAD_RESP_SET_POWER_SAVE_MODE;
18911895
resp->resp_set_power_save_mode = resp_payload;
18921896

1893-
/*
1894-
* WIFI_PS_NONE mode can not use in case of coex i.e. Wi-Fi+BT/BLE.
1895-
* By default ESP has WIFI_PS_MIN_MODEM power save mode
1896-
*/
1897-
if ((req->req_set_power_save_mode->mode == WIFI_PS_MIN_MODEM) ||
1897+
if ((req->req_set_power_save_mode->mode == WIFI_PS_NONE) ||
1898+
(req->req_set_power_save_mode->mode == WIFI_PS_MIN_MODEM) ||
18981899
(req->req_set_power_save_mode->mode == WIFI_PS_MAX_MODEM)) {
18991900
ret = esp_wifi_set_ps(req->req_set_power_save_mode->mode);
19001901
if (ret) {
@@ -2373,7 +2374,9 @@ static esp_err_t req_get_country_code_handler (CtrlMsg *req,
23732374

23742375
ret = esp_wifi_get_country_code(country_code);
23752376
if (ret == ESP_OK) {
2377+
country_code[COUNTRY_CODE_LEN-1] = '\0';
23762378
resp_payload->country.data = (uint8_t *)country_code;
2379+
ESP_LOGI(TAG,"Returning %s", country_code);
23772380
resp_payload->country.len = COUNTRY_CODE_LEN;
23782381
resp_payload->resp = SUCCESS;
23792382
} else {

esp_hosted_fg/esp/esp_driver/network_adapter/main/slave_control.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,6 @@
4444
#define MAC_LEN 6
4545
#define VENDOR_OUI_BUF 3
4646

47-
/* Define max allowed bytes for the user RPC event data */
48-
#define RPC_USER_SPECIFIC_EVENT_DATA_SIZE 1024
49-
50-
/* Structure for the user-specific RPC events */
51-
struct rpc_user_specific_event_t {
52-
int32_t resp;
53-
int32_t int_1;
54-
int32_t int_2;
55-
uint32_t uint_1;
56-
uint32_t uint_2;
57-
uint16_t data_len;
58-
uint8_t data[RPC_USER_SPECIFIC_EVENT_DATA_SIZE];
59-
};
60-
6147
typedef struct {
6248
uint8_t ssid[SSID_LENGTH];
6349
uint8_t pwd[PASSWORD_LENGTH];
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
CC = gcc
2+
3+
# Compiler and linker flags
4+
CROSS_COMPILE :=
5+
CFLAGS = -Wall -g -fPIC
6+
LDFLAGS = -lpthread -lrt
7+
8+
# Directory paths
9+
DIR_ROOT = $(CURDIR)/../..
10+
DIR_COMMON = $(DIR_ROOT)/common
11+
DIR_COMPONENTS = $(DIR_ROOT)/host/components
12+
DIR_SERIAL = $(DIR_ROOT)/host/virtual_serial_if
13+
DIR_LINUX_PORT = $(DIR_ROOT)/host/linux/port
14+
DIR_CONTROL_LIB = $(DIR_ROOT)/host/control_lib
15+
16+
# Include paths
17+
INCLUDE += -I$(DIR_COMMON)/protobuf-c
18+
INCLUDE += -I$(DIR_COMMON)/include
19+
INCLUDE += -I$(DIR_CONTROL_LIB)/include
20+
INCLUDE += -I$(DIR_CONTROL_LIB)/src/include
21+
INCLUDE += -I$(DIR_SERIAL)/include
22+
INCLUDE += -I$(DIR_COMPONENTS)/include
23+
INCLUDE += -I$(DIR_LINUX_PORT)/include
24+
25+
# Source files for the core library
26+
CORE_SRC = $(DIR_COMMON)/protobuf-c/protobuf-c/protobuf-c.c
27+
CORE_SRC += $(DIR_COMMON)/esp_hosted_config.pb-c.c
28+
CORE_SRC += $(DIR_CONTROL_LIB)/src/ctrl_core.c
29+
CORE_SRC += $(DIR_CONTROL_LIB)/src/ctrl_api.c
30+
CORE_SRC += $(DIR_SERIAL)/src/serial_if.c
31+
CORE_SRC += $(DIR_COMPONENTS)/src/esp_queue.c
32+
CORE_SRC += $(DIR_LINUX_PORT)/src/platform_wrapper.c
33+
34+
# Target library
35+
LIBCONTROL = libesp_hosted_rpc.so
36+
LIBCONTROL_STATIC = libesp_hosted_rpc.a
37+
38+
.PHONY: all clean shared static
39+
40+
all: shared static
41+
42+
shared: $(LIBCONTROL)
43+
44+
static: $(LIBCONTROL_STATIC)
45+
46+
# Build the shared library
47+
$(LIBCONTROL): $(CORE_SRC)
48+
$(CROSS_COMPILE)$(CC) $(CFLAGS) $(INCLUDE) -shared -o $@ $^ $(LDFLAGS)
49+
50+
# Build the static library
51+
$(LIBCONTROL_STATIC): $(CORE_SRC:.c=.o)
52+
ar rcs $@ $^
53+
54+
%.o: %.c
55+
$(CROSS_COMPILE)$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
56+
57+
install: all
58+
@mkdir -p $(DIR_ROOT)/lib
59+
@cp -f $(LIBCONTROL) $(LIBCONTROL_STATIC) $(DIR_ROOT)/lib/
60+
61+
clean:
62+
rm -f $(LIBCONTROL) $(LIBCONTROL_STATIC) $(CORE_SRC:.c=.o)
63+

esp_hosted_fg/host/control_lib/include/ctrl_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ typedef enum {
242242
} wifi_bandwidth_e;
243243

244244
typedef enum {
245+
WIFI_PS_NONE = CTRL__WIFI_POWER_SAVE__NO_PS,
245246
WIFI_PS_MIN_MODEM = CTRL__WIFI_POWER_SAVE__MIN_MODEM,
246247
WIFI_PS_MAX_MODEM = CTRL__WIFI_POWER_SAVE__MAX_MODEM,
247248
WIFI_PS_INVALID,

0 commit comments

Comments
 (0)