Skip to content

Commit 7e9266e

Browse files
committed
Merge branch 'nw_split_linux_wip7' into 'master'
Small Bugfixes and enhancements See merge request app-frameworks/esp_hosted!579
2 parents 608f05b + 7cce538 commit 7e9266e

File tree

10 files changed

+200
-54
lines changed

10 files changed

+200
-54
lines changed

esp_hosted_fg/host/control_lib/src/ctrl_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,10 @@ int deinit_hosted_control_lib_internal(void)
17661766
{
17671767
int ret = SUCCESS;
17681768

1769+
if (is_ctrl_lib_state(CTRL_LIB_STATE_INACTIVE)) {
1770+
return SUCCESS;
1771+
}
1772+
17691773
set_ctrl_lib_state(CTRL_LIB_STATE_INACTIVE);
17701774

17711775
if (ctrl_msg_Q) {

esp_hosted_fg/host/linux/host_control/c_support/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ CROSS_COMPILE :=
1111
CFLAGS = -Wall -g
1212
LINKER = -lpthread -lrt
1313

14-
# If your Linux is very constraint environment, comment below line.
15-
CFLAGS_SANITIZE = -fsanitize=undefined -fsanitize-address-use-after-scope -fsanitize-undefined-trap-on-error -fstack-protector-all -fstack-check -fsanitize=address -fsanitize=pointer-compare -fno-omit-frame-pointer -static-libasan
14+
# Enable only when memory check (like valgrind) need to perform. This slows down the application and cleanup
15+
#CFLAGS_SANITIZE = -fsanitize=undefined -fsanitize-address-use-after-scope -fsanitize-undefined-trap-on-error -fstack-protector-all -fstack-check -fsanitize=address -fsanitize=pointer-compare -fno-omit-frame-pointer -static-libasan
1616

1717
# Root directory
1818
DIR_ROOT = $(CURDIR)/../../../../
@@ -96,3 +96,4 @@ hosted_shell.out: hosted_shell.o $(COMMON_OBJS)
9696

9797
clean:
9898
rm -f *.out *.o
99+
$(MAKE) -C $(DIR_CTRL_LIB) clean

esp_hosted_fg/host/linux/host_control/c_support/hosted_shell.c

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
#include "nw_helper_func.h"
2323
#include "esp_hosted_custom_rpc.h"
2424
#include "app_custom_rpc.h"
25+
#include <stdint.h>
2526

2627

2728
#define MAC_ADDR_LENGTH 18
28-
#define NETWORK_CHECK_INTERVAL_MS 1000
29+
#define NETWORK_CHECK_INTERVAL_MS 100
2930
#define RPC_RETRY_INTERVAL_MS 1000
3031

3132
#define POLL_FOR_IP_RESTORE (0)
@@ -334,6 +335,10 @@ static const cmd_arg_t custom_rpc_request_args[] = {
334335
{"--demo", "Demo number (1, 2, or 3)", ARG_TYPE_INT, true, NULL}
335336
};
336337

338+
static const cmd_arg_t set_country_code_args[] = {
339+
{"--code", "Country code (e.g. US, IN, CN)", ARG_TYPE_STRING, true, NULL}
340+
};
341+
337342
/* Forward declarations for command handlers */
338343
static int handle_exit(int argc, char **argv);
339344
static int handle_help(int argc, char **argv);
@@ -365,6 +370,10 @@ static int handle_subscribe_event(int argc, char **argv);
365370
static int handle_unsubscribe_event(int argc, char **argv);
366371
static int handle_set_host_port_range(int argc, char **argv);
367372
static int handle_custom_demo_rpc_request(int argc, char **argv);
373+
static int handle_set_country_code(int argc, char **argv);
374+
static int handle_set_country_code_with_ieee80211d_on(int argc, char **argv);
375+
static int handle_get_country_code(int argc, char **argv);
376+
368377

369378

370379
/* Command table */
@@ -401,6 +410,9 @@ static const shell_command_t commands[] = {
401410
{"exit", "Exit the shell", handle_exit, NULL, 0},
402411
{"quit", "Exit the shell", handle_exit, NULL, 0},
403412
{"q", "Exit the shell", handle_exit, NULL, 0},
413+
{"set_country_code", "Set Wi-Fi country code", handle_set_country_code, set_country_code_args, sizeof(set_country_code_args)/sizeof(cmd_arg_t)},
414+
{"set_country_code_with_ieee80211d_on", "Set Wi-Fi country code with ieee80211d enabled", handle_set_country_code_with_ieee80211d_on, NULL, 0},
415+
{"get_country_code", "Get Wi-Fi country code", handle_get_country_code, NULL, 0},
404416
{NULL, NULL, NULL, NULL, 0}
405417
};
406418

@@ -1203,11 +1215,10 @@ static void stop_rpc_auto_ip_restore(void) {
12031215
exit_thread_auto_ip_restore = 1;
12041216
rpc_state = RPC_STATE_INACTIVE;
12051217

1206-
printf("Cleaning up RPC resources...\n");
1218+
//printf("Cleaning up RPC resources...\n");
12071219

12081220
// Give app thread a chance to notice exit flag
1209-
printf("Waiting for background threads to terminate...\n");
1210-
sleep(1); // Brief pause
1221+
//sleep(1); // Brief pause (removed for faster exit)
12111222

12121223
// Join the app thread if it exists
12131224
if (auto_ip_restore_thread) {
@@ -1228,7 +1239,7 @@ static void stop_rpc_auto_ip_restore(void) {
12281239
}
12291240

12301241
cleanup_in_progress = 0;
1231-
printf("RPC cleanup complete\n");
1242+
//printf("Cleanup complete\n");
12321243
}
12331244

12341245
/* Shell main loop */
@@ -1380,7 +1391,7 @@ int main(int argc, char *argv[]) {
13801391
ret = shell_run(&ctx);
13811392

13821393
/* The shell has exited - initiate cleanup */
1383-
printf("Shell exited, initiating cleanup\n");
1394+
//printf("Shell exited, initiating cleanup\n");
13841395
exit_thread_auto_ip_restore = 1;
13851396

13861397
/* Clean up resources */
@@ -1690,3 +1701,28 @@ static int handle_custom_demo_rpc_request(int argc, char **argv) {
16901701
return FAILURE;
16911702
}
16921703
}
1704+
1705+
static int handle_set_country_code(int argc, char **argv) {
1706+
CHECK_RPC_ACTIVE();
1707+
if (!parse_arguments(argc, argv, set_country_code_args, sizeof(set_country_code_args)/sizeof(cmd_arg_t))) {
1708+
return FAILURE;
1709+
}
1710+
const char *code = get_arg_value(argc, argv, set_country_code_args,
1711+
sizeof(set_country_code_args)/sizeof(cmd_arg_t),
1712+
"--code");
1713+
if (!code || strlen(code) < 2) {
1714+
printf("Invalid or missing country code\n");
1715+
return FAILURE;
1716+
}
1717+
return test_set_country_code_with_params(code);
1718+
}
1719+
1720+
static int handle_set_country_code_with_ieee80211d_on(int argc, char **argv) {
1721+
CHECK_RPC_ACTIVE();
1722+
return test_set_country_code_with_ieee80211d_on();
1723+
}
1724+
1725+
static int handle_get_country_code(int argc, char **argv) {
1726+
CHECK_RPC_ACTIVE();
1727+
return test_get_country_code();
1728+
}

esp_hosted_fg/host/linux/host_control/c_support/stress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int main(int argc, char *argv[])
169169
test_set_country_code();
170170
} else if (0 == strncasecmp(SET_COUNTRY_CODE_ENABLED, argv[i],
171171
sizeof(SET_COUNTRY_CODE_ENABLED))) {
172-
test_set_country_code_enabled();
172+
test_set_country_code_with_ieee80211d_on();
173173
} else if (0 == strncasecmp(GET_COUNTRY_CODE, argv[i],
174174
sizeof(GET_COUNTRY_CODE))) {
175175
test_get_country_code();

esp_hosted_fg/host/linux/host_control/c_support/test.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
#include "app_custom_rpc.h"
2929

3030
#define DEMO_SLEEP_DURATION_SEC 50
31+
32+
/* Heartbeat demo needs to wait for events
33+
* For simplicity, we disable heartbeat demo
34+
* Anyway fullfledged cli demo is already available in hosted_shell.c
35+
*/
36+
#define ENABLE_HEARTBEAT 0
37+
3138
#define EXEC_IF_CMD_EQUALS(cmd,func) \
3239
if (0 == strncasecmp(cmd, in_cmd, sizeof(cmd))) { \
3340
func; \
@@ -88,7 +95,7 @@ static int parse_cli_cmd(char *in_cmd, char *args[])
8895
EXEC_IF_CMD_EQUALS(GET_FW_VERSION, test_print_fw_version());
8996
EXEC_IF_CMD_EQUALS(OTA, test_ota(args[0]));
9097
EXEC_IF_CMD_EQUALS(SET_COUNTRY_CODE, test_set_country_code());
91-
EXEC_IF_CMD_EQUALS(SET_COUNTRY_CODE_ENABLED, test_set_country_code_enabled());
98+
EXEC_IF_CMD_EQUALS(SET_COUNTRY_CODE_ENABLED, test_set_country_code_with_ieee80211d_on());
9299
EXEC_IF_CMD_EQUALS(GET_COUNTRY_CODE, test_get_country_code());
93100
EXEC_IF_CMD_EQUALS(CUSTOM_RPC_DEMO1, demo1_custom_rpc_unserialised_request_only_ack());
94101
EXEC_IF_CMD_EQUALS(CUSTOM_RPC_DEMO2, demo2_custom_rpc_unserialised_request_and_slave_echo_back_as_response());
@@ -113,17 +120,20 @@ static int init_app(void)
113120

114121
register_event_callbacks();
115122

123+
#if ENABLE_HEARTBEAT
116124
test_config_heartbeat();
125+
#endif
117126

118127
return 0;
119128
}
120129

121130
static void cleanup_app(void)
122131
{
123-
// TODO properly disable heartbeat
132+
#if ENABLE_HEARTBEAT
124133
test_disable_heartbeat_async();
125-
// wait for async to complete
134+
/* wait for async to complete */
126135
sleep(1);
136+
#endif
127137
unregister_event_callbacks();
128138

129139
control_path_platform_deinit();
@@ -175,10 +185,13 @@ int main(int argc, char *argv[])
175185

176186
cli_cmd = argv[1];
177187
if (SUCCESS == parse_cli_cmd(cli_cmd, &argv[2])) {
188+
189+
#if ENABLE_HEARTBEAT
178190
sleep(2);
179191
printf("\n\n\nRequested operation complete\n");
180192
printf("Sleeping for some time just to showcase heartbeat\n");
181193
sleep(DEMO_SLEEP_DURATION_SEC);
194+
#endif
182195
}
183196

184197
cleanup_app();

esp_hosted_fg/host/linux/host_control/c_support/test.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636

3737
int test_get_wifi_mode(void);
38+
int test_async_get_wifi_mode(void);
3839
int test_set_wifi_mode(int mode);
3940
int test_set_wifi_mode_station(void);
4041
int test_set_wifi_mode_softap(void);
@@ -47,6 +48,7 @@ int test_station_mode_set_mac_addr_of_esp(char *mac_str);
4748
int test_softap_mode_set_mac_addr_of_esp(char *mac_str);
4849
int test_softap_mode_get_mac_addr(char *mac_str);
4950
int test_station_mode_connect(void);
51+
int test_async_station_mode_connect(void);
5052
int test_station_mode_get_info(void);
5153
int test_get_available_wifi(void);
5254
int test_station_mode_disconnect(void);
@@ -78,8 +80,9 @@ int test_enable_wifi(void);
7880
int test_is_network_split_on(void);
7981
char * test_get_fw_version(char *, uint16_t);
8082
int test_print_fw_version(void);
81-
int test_set_country_code_enabled();
83+
int test_set_country_code_with_ieee80211d_on();
8284
int test_set_country_code();
85+
int test_set_country_code_with_params(const char *code);
8386
int test_get_country_code();
8487
int test_fetch_ip_addr_from_slave(void);
8588
int test_set_dhcp_dns_status(char *sta_ip, char *sta_nm, char *sta_gw, char *sta_dns);

0 commit comments

Comments
 (0)