Added new station commands

This commit is contained in:
Th3maz1ng 2022-06-12 21:48:51 +02:00
parent 8a2eee57ef
commit 3a53b6a1c8
5 changed files with 126 additions and 16 deletions

View File

@ -12,20 +12,32 @@
* Date : 2014-6-14
*****************************************************************************/
#include "wm_include.h"
#include "wm_gpio_afsel.h"
#include "nano_shell.h"
extern s16 uart0_rx_callback(u16 len, void *user_data);
extern s16 uart1_rx_callback(u16 len, void *user_data);
#define NANO_SHELL_TASK_STK_SIZE 1024
#define STATUS_LED WM_IO_PB_18
void user_main(void)
void user_main(void *param)
{
//We initialize input/output used by the app
tls_gpio_cfg(STATUS_LED, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
wm_uart1_tx_config(WM_IO_PB_06);
wm_uart1_rx_config(WM_IO_PB_07);
//We init the uart 1
tls_uart_port_init(TLS_UART_1, NULL, 0);
//We create a task for the nano_shell process
u8 *nano_shell_task_stack = NULL;
tls_os_task_t nano_shell_task_handle = NULL;
tls_uart_rx_callback_register(TLS_UART_0, &(uart0_rx_callback), NULL);
tls_uart_rx_callback_register(TLS_UART_1, &(uart1_rx_callback), NULL);
nano_shell_task_stack = tls_mem_alloc(sizeof(u32) * NANO_SHELL_TASK_STK_SIZE);
if(nano_shell_task_stack != NULL)
@ -42,8 +54,6 @@ void user_main(void)
);
}
tls_gpio_cfg(STATUS_LED, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
for(;;)
{
tls_gpio_write(STATUS_LED, !tls_gpio_read(STATUS_LED));

View File

@ -2,12 +2,57 @@
#include <string.h>
#include "command/command.h"
#include "wm_include.h"
#include "FreeRTOS.h"
#include "task.h"
extern int shell_printf(const char *format, ...);
extern int wm_printf(const char *fmt,...);
void tls_wifi_client_event_cb(u8 *mac, enum tls_wifi_client_event_type event)
{
struct tls_sta_info_t *mac_addr = (struct tls_sta_info_t *)mac;
shell_printf("Client event(%d), MAC : %M\n", event, mac_addr);
}
void wifi_scan_result_cb(void)
{
u16 buffer_size = sizeof(struct tls_scan_bss_t) + sizeof(struct tls_bss_info_t) * 10;
u8 *buf = tls_mem_alloc(buffer_size);
if(buf == NULL)
{
shell_printf("Failed to allocate result buffer\n");
return;
}
struct tls_scan_bss_t *scan_result = (struct tls_scan_bss_t *)buf;
struct tls_bss_info_t *station_list = scan_result->bss;
tls_wifi_get_scan_rslt(buf, buffer_size);
shell_printf("Found %u nearby station(s) - info size(%u/%u)\n",
scan_result->count,
scan_result->length,
buffer_size);
for(u8 i = 0; i < scan_result->count; i++)
{
station_list[i].ssid[station_list[i].ssid_len] = '\0';
shell_printf("station %u :\nSSID : %s\n", i, (char *)station_list[i].ssid);
}
}
int _task_list(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
tls_os_disp_task_stat_info();
char *buf = NULL;
buf = tls_mem_alloc(1024);
if(NULL == buf)
return 0;
#if configUSE_TRACE_FACILITY
vTaskList((signed char *)buf);
#endif
shell_printf("\n%s\nbuf_len : %d\n", buf, strlen(buf));
tls_mem_free(buf);
buf = NULL;
return 0;
}
@ -53,17 +98,58 @@ int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[])
ip_info.dnsname[0] = '\0';
int result = tls_wifi_softap_create(&ap_info, &ip_info);
shell_printf("Create AP with SSID : %s, key(%d) : %s -> %d\n", ap_info.ssid, ap_info.keyinfo.key_len, ap_info.keyinfo.key, result);
shell_printf("Registering client event callback\n");
tls_wifi_softap_client_event_register(&(tls_wifi_client_event_cb));
}
else if(strcmp(argv[1], "destroy") == 0)
{
tls_wifi_softap_destroy();
shell_printf("Stopping SOFT AP\n");
}
else
{
shell_printf("Unknown soft_ap action\n");
}
}
else
{
shell_printf("Unknown SOFT AP command\n");
shell_printf("List of soft_ap actions :\nstate\ncreate <SSID> <PWD>\ndestroy\n");
}
return 0;
}
int _station(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
if(argc > 1)
{
if(strcmp(argv[1], "scan") == 0)
{
tls_wifi_scan_result_cb_register(&(wifi_scan_result_cb));
if(tls_wifi_scan() == WM_SUCCESS)
{
shell_printf("Scanning nearby stations...\n");
}
else
{
shell_printf("Failed to start wifi scan\n");
}
}
else
{
shell_printf("Unknown station action\n");
}
}
else
{
shell_printf("List of station actions :\nscan\n");
}
return 0;
}
NANO_SHELL_ADD_CMD(task_list,
_task_list,
"List all tasks",
@ -76,3 +162,7 @@ NANO_SHELL_ADD_CMD(soft_ap,
_soft_ap,
"Command to control SOFT AP",
" Use this command to control the SOFT AP subsystem\r\n");
NANO_SHELL_ADD_CMD(station,
_station,
"Command to control STATION mode",
" Use this command to connect to a WiFi access point\r\n");

View File

@ -1,7 +1,7 @@
#include "wm_include.h"
#include "shell_io/static_fifo.h"
static_fifo_declare(uart0_char_fifo, 256, unsigned char, char);
static_fifo_declare(uart_char_fifo, 256, unsigned char, char);
extern int sendchar(int ch);
s16 uart0_rx_callback(u16 len, void *user_data)
@ -9,7 +9,16 @@ s16 uart0_rx_callback(u16 len, void *user_data)
u8 buff[256] = "";
int data_len = tls_uart_read(TLS_UART_0, (u8 *) buff, 256);
for(int i = 0; i < data_len; i++)
fifo_push(uart0_char_fifo, buff[i]);
fifo_push(uart_char_fifo, buff[i]);
return 0;
}
s16 uart1_rx_callback(u16 len, void *user_data)
{
u8 buff[256] = "";
int data_len = tls_uart_read(TLS_UART_1, (u8 *) buff, 256);
for(int i = 0; i < data_len; i++)
fifo_push(uart_char_fifo, buff[i]);
return 0;
}
@ -17,10 +26,10 @@ int shell_getc(char *ch)
{
//Do not forget to sleep a bit to let the idle task run ...
tls_os_time_delay(5);
if(is_fifo_empty(uart0_char_fifo))
if(is_fifo_empty(uart_char_fifo))
return 0;
*ch = fifo_pop_unsafe(uart0_char_fifo);
*ch = fifo_pop_unsafe(uart_char_fifo);
return 1;
//return tls_uart_read(TLS_UART_0, (u8 *) ch, 1);
}
@ -28,4 +37,5 @@ int shell_getc(char *ch)
void low_level_write_char(char ch)
{
(void)sendchar((int)ch);
(void)tls_uart_write(TLS_UART_1, &ch, 1);
}

View File

@ -55,7 +55,7 @@
/******************************* shell io configuration ****************************/
/* config the buffer size (shell_printf()) */
#define CONFIG_SHELL_PRINTF_BUFFER_SIZE 128U
#define CONFIG_SHELL_PRINTF_BUFFER_SIZE 1024U
/******************************* shell configuration ****************************/

View File

@ -25,16 +25,16 @@
/* 0x0000000F - 0x00000001 */
/** Define the debugging level: info */
#define TLS_DBG_LEVEL_INFO TLS_DBG_OFF
#define TLS_DBG_LEVEL_INFO TLS_DBG_ON
/** Define the debugging level: warning */
#define TLS_DBG_LEVEL_WARNING TLS_DBG_OFF
#define TLS_DBG_LEVEL_WARNING TLS_DBG_ON
/** Define the debugging level: error */
#define TLS_DBG_LEVEL_ERR TLS_DBG_OFF
#define TLS_DBG_LEVEL_ERR TLS_DBG_ON
/** Define the debugging level: dump */
#define TLS_DBG_LEVEL_DUMP TLS_DBG_OFF
#define TLS_DBG_LEVEL_DUMP TLS_DBG_ON
/** general debug info switch, default: off */
#define TLS_GENERAL_DBG TLS_DBG_OFF
#define TLS_GENERAL_DBG TLS_DBG_ON
#if TLS_DBG_SIMPLE
#define __TLS_DBGPRT_INFO(fmt, ...) printf(fmt, ##__VA_ARGS__)