1032 lines
33 KiB
C
1032 lines
33 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include "command/command.h"
|
|
#include "wm_include.h"
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "lwip/netif.h"
|
|
#include "app_common.h"
|
|
#include "app_utils.h"
|
|
#include "nano_shell_interface.h"
|
|
#include "wm_gpio_afsel.h"
|
|
#include "wm_cpu.h"
|
|
|
|
#include "wm_bt.h"
|
|
#include "ble_modem.h"
|
|
#include "ble_service.h"
|
|
#include "gadget_bridge.h"
|
|
|
|
extern int wm_printf(const char *fmt,...);
|
|
extern u32 tls_mem_get_avail_heapsize(void);
|
|
extern bool disconnect_client(void);
|
|
|
|
extern int demo_bt_enable();
|
|
extern int demo_bt_destroy();
|
|
extern int demo_ble_server_on();
|
|
extern int demo_ble_server_off();
|
|
|
|
static 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"NEW_LINE, event, mac_addr);
|
|
}
|
|
|
|
static void wifi_scan_result_cb(void)
|
|
{
|
|
u16 buffer_size = sizeof(struct tls_scan_bss_t) + sizeof(struct tls_bss_info_t) * 20;
|
|
u8 *buf = tls_mem_alloc(buffer_size);
|
|
if(buf == NULL)
|
|
{
|
|
shell_printf("Failed to allocate result buffer"NEW_LINE);
|
|
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)"NEW_LINE,
|
|
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 :"NEW_LINE"SSID : %s"NEW_LINE"BSSID : %02X:%02X:%02X:%02X:%02X:%02X"NEW_LINE"RSSI : %d dB"NEW_LINE"Channel : %u"NEW_LINE"Max DR : %u Mbps"NEW_LINE"Mode %u"NEW_LINE"Auth :%u"NEW_LINE"WPS supported : %u"NEW_LINE NEW_LINE,
|
|
i,
|
|
(char *)station_list[i].ssid,
|
|
station_list[i].bssid[0], station_list[i].bssid[1], station_list[i].bssid[2], station_list[i].bssid[3], station_list[i].bssid[4], station_list[i].bssid[5],
|
|
(s8)station_list[i].rssi,
|
|
station_list[i].channel,
|
|
station_list[i].max_data_rate,
|
|
station_list[i].mode,
|
|
station_list[i].privacy,
|
|
station_list[i].wps_support);
|
|
}
|
|
|
|
tls_mem_free(buf);
|
|
|
|
tls_wifi_scan_result_cb_register(NULL);
|
|
}
|
|
|
|
static void tls_wifi_data_ext_recv_cb(u8* data, u32 data_len, struct tls_wifi_ext_t *ext)
|
|
{
|
|
shell_printf("recv packet :"NEW_LINE"rssi : %d\nrate : %u"NEW_LINE, (s8)ext->rssi, ext->rx_rate);
|
|
for(u32 i = 0; i < data_len; i++)
|
|
{
|
|
shell_printf("%02X", data[i]);
|
|
if(i % 30 == 0)
|
|
shell_printf(NEW_LINE);
|
|
}
|
|
shell_printf(NEW_LINE);
|
|
}
|
|
|
|
static void tls_rtc_irq_cb(void *arg)
|
|
{
|
|
struct tm rtc_time;
|
|
tls_get_rtc(&rtc_time);
|
|
|
|
shell_printf("rtc isr called"NEW_LINE"time is :"NEW_LINE"%d:%d:%d %d/%d/%d"NEW_LINE,
|
|
rtc_time.tm_hour,
|
|
rtc_time.tm_min,
|
|
rtc_time.tm_sec,
|
|
rtc_time.tm_mday,
|
|
rtc_time.tm_mon,
|
|
rtc_time.tm_year);
|
|
|
|
tls_rtc_timer_stop();
|
|
}
|
|
|
|
static void parser_event_cb(const gadget_bridge_event_data_t *gadget_bridge_event_data)
|
|
{
|
|
shell_printf("----------->Event of type : %s\n", gadget_bridge_event_type_2_str(gadget_bridge_event_data->event_type));
|
|
|
|
switch(gadget_bridge_event_data->event_type)
|
|
{
|
|
case GADGET_BRIDGE_EVENT_TYPE_SET_TIME:
|
|
shell_printf("%d:%d:%d %d/%d/%d\n%d\n",
|
|
gadget_bridge_event_data->time.local_time.tm_hour,
|
|
gadget_bridge_event_data->time.local_time.tm_min,
|
|
gadget_bridge_event_data->time.local_time.tm_sec,
|
|
gadget_bridge_event_data->time.local_time.tm_mday,
|
|
gadget_bridge_event_data->time.local_time.tm_mon,
|
|
gadget_bridge_event_data->time.local_time.tm_year + 1900,
|
|
gadget_bridge_event_data->time.time_zone);
|
|
break;
|
|
case GADGET_BRIDGE_EVENT_TYPE_NOTIFY:
|
|
shell_printf("%u\n%s\n%s\n%s\n",
|
|
gadget_bridge_event_data->notification.handle,
|
|
gadget_bridge_notification_type_2_str(gadget_bridge_event_data->notification.notification_type),
|
|
gadget_bridge_event_data->notification.title,
|
|
gadget_bridge_event_data->notification.body);
|
|
break;
|
|
break;
|
|
case GADGET_BRIDGE_EVENT_TYPE_CALL:
|
|
shell_printf("%u\n%s\n%s\n",
|
|
gadget_bridge_event_data->call.call_action,
|
|
gadget_bridge_event_data->call.contact,
|
|
gadget_bridge_event_data->call.phone_number);
|
|
break;
|
|
case GADGET_BRIDGE_EVENT_TYPE_WEATHER:
|
|
shell_printf("%.2f\n%u\n%s\n%.2f\n%u\n%s\n",
|
|
gadget_bridge_event_data->weather.temperature_celsius,
|
|
gadget_bridge_event_data->weather.humidity,
|
|
gadget_bridge_event_data->weather.weather_desc,
|
|
gadget_bridge_event_data->weather.wind_speed_kmh,
|
|
gadget_bridge_event_data->weather.wind_dir,
|
|
gadget_bridge_event_data->weather.location);
|
|
break;
|
|
case GADGET_BRIDGE_EVENT_TYPE_FIND:
|
|
shell_printf("%d\n",gadget_bridge_event_data->find.find);
|
|
break;
|
|
case GADGET_BRIDGE_EVENT_TYPE_ACT:
|
|
shell_printf("%d\n%d\n%u\n",
|
|
gadget_bridge_event_data->act.heart_rate_monitor,
|
|
gadget_bridge_event_data->act.steps,
|
|
gadget_bridge_event_data->act.heart_rate_interval);
|
|
break;
|
|
case GADGET_BRIDGE_EVENT_TYPE_MUSIC_STATE:
|
|
shell_printf("%s\n%u\n%u\n%u\n",
|
|
gadget_bridge_music_state_2_str(gadget_bridge_event_data->music_state.music_state),
|
|
gadget_bridge_event_data->music_state.position_in_seconds,
|
|
gadget_bridge_event_data->music_state.shuffle,
|
|
gadget_bridge_event_data->music_state.repeat);
|
|
break;
|
|
case GADGET_BRIDGE_EVENT_TYPE_MUSIC_INFO:
|
|
shell_printf("%s\n%s\n%u\n",
|
|
gadget_bridge_event_data->music_info.artist,
|
|
gadget_bridge_event_data->music_info.track,
|
|
gadget_bridge_event_data->music_info.duration_in_seconds);
|
|
break;
|
|
default:
|
|
shell_printf("Unhandled\n");
|
|
}
|
|
}
|
|
|
|
static void nus_data_rx_cb(const uint8_t *data, uint16_t length)
|
|
{
|
|
//shell_printf("%s, received data : "NEW_LINE"#", __FUNCTION__);
|
|
//shell_putc('"');
|
|
for (uint16_t i = 0; i < length; i++)
|
|
{
|
|
if (data[i] < 32)
|
|
shell_printf("[%u]", data[i]);
|
|
else
|
|
shell_putc(data[i]);
|
|
}
|
|
//shell_printf("\","NEW_LINE);
|
|
shell_printf("# ");
|
|
gadget_bridge_parser_feed((const char *)data, length);
|
|
gadget_bridge_parser_code_e code;
|
|
while((code = gadget_bridge_parser_run()) == GADGET_BRIDGE_PARSER_CODE_PARSING);
|
|
shell_printf("Gadget bridge parser code : %s"NEW_LINE, gadget_bridge_parser_code_2_str(code));
|
|
//shell_puts("#"NEW_LINE);
|
|
}
|
|
|
|
int _system(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "list_task") == 0)
|
|
{
|
|
char *buf = NULL;
|
|
|
|
buf = tls_mem_alloc(1024);
|
|
if(NULL == buf)
|
|
return 0;
|
|
#if configUSE_TRACE_FACILITY
|
|
vTaskList(buf);
|
|
#endif
|
|
shell_printf(NEW_LINE"%s"NEW_LINE"buf_len : %d"NEW_LINE, buf, strlen(buf));
|
|
tls_mem_free(buf);
|
|
buf = NULL;
|
|
}
|
|
else if(strcmp(argv[1], "ram_usage") == 0)
|
|
{
|
|
uint32_t total_mem_size = (unsigned int)&__heap_end - (unsigned int)&__heap_start;
|
|
shell_printf("Free OS heap : %u/%u byte(s)"NEW_LINE"tls heap size : %u/%u byte(s)"NEW_LINE, xPortGetFreeHeapSize(), configTOTAL_HEAP_SIZE, tls_mem_get_avail_heapsize(), total_mem_size);
|
|
}
|
|
else if(strcmp(argv[1], "cpu_clock") == 0)
|
|
{
|
|
if(argc == 3)
|
|
{
|
|
uint8_t clock = strtoul(argv[2], NULL, 10);
|
|
if(clock < 2 || clock > 240)
|
|
{
|
|
shell_printf("Bad clock !"NEW_LINE
|
|
"Available options are :"NEW_LINE
|
|
"\t- 2, 40, 80, 160, 240"NEW_LINE);
|
|
}
|
|
else
|
|
{
|
|
uint8_t div = 480/clock;
|
|
tls_sys_clk_set(div);
|
|
tls_sys_clk sys_clk;
|
|
tls_sys_clk_get(&sys_clk);
|
|
|
|
shell_printf("Clock set to %u : cpu(%u), wlan(%u) and APB(%u)"NEW_LINE, clock, sys_clk.cpuclk, sys_clk.wlanclk, sys_clk.apbclk);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
tls_sys_clk sys_clk;
|
|
tls_sys_clk_get(&sys_clk);
|
|
|
|
shell_printf("Clocks : cpu(%u), wlan(%u) and APB(%u)"NEW_LINE, sys_clk.cpuclk, sys_clk.wlanclk, sys_clk.apbclk);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of system actions :"NEW_LINE
|
|
"list_task"NEW_LINE
|
|
"ram_usage"NEW_LINE
|
|
"cpu_clock 2|40|80|160|240"NEW_LINE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _reset(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
tls_sys_reset();
|
|
return 0;
|
|
}
|
|
|
|
int _bus(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
char spi_recv_buff[32] = "";
|
|
u32 fclk = SPI_DEFAULT_SPEED;
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "spi_init") == 0)
|
|
{
|
|
if(argc == 3)
|
|
{
|
|
fclk = strtoul(argv[2], NULL, 10);
|
|
if(!fclk) fclk = SPI_DEFAULT_SPEED;
|
|
}
|
|
shell_printf("SPI init : %d, clk -> %u Hz"NEW_LINE, tls_spi_setup(SPI_DEFAULT_MODE, SPI_CS_ACTIVE_MODE, fclk), fclk);
|
|
}
|
|
else if(strcmp(argv[1], "spi_w") == 0)
|
|
{
|
|
shell_printf("Writing [%s](len : %d) to SPI"NEW_LINE, argv[2], strlen(argv[2]));
|
|
if(tls_spi_write((u8*)argv[2], strlen(argv[2])) != TLS_SPI_STATUS_OK)
|
|
{
|
|
shell_printf("Failed to write to SPI"NEW_LINE);
|
|
return 0;
|
|
}
|
|
}
|
|
else if(strcmp(argv[1], "spi_r") == 0)
|
|
{
|
|
if(tls_spi_read((u8*)spi_recv_buff, sizeof(spi_recv_buff) - 1) != TLS_SPI_STATUS_OK)
|
|
{
|
|
shell_printf("Failed to read from SPI"NEW_LINE);
|
|
return 0;
|
|
}
|
|
shell_printf("Received [%s](len : %d) from SPI"NEW_LINE, spi_recv_buff, strlen(spi_recv_buff));
|
|
}
|
|
else if(strcmp(argv[1], "spi_wr") == 0)
|
|
{
|
|
if(tls_spi_read_with_cmd((u8 *) argv[2], strlen(argv[2]), (u8 *) spi_recv_buff, sizeof(spi_recv_buff) - 1) != TLS_SPI_STATUS_OK)
|
|
{
|
|
shell_printf("Failed to write & read combo using SPI"NEW_LINE);
|
|
return 0;
|
|
}
|
|
shell_printf("Writing [%s](len : %d) to SPI"NEW_LINE, argv[2], strlen(argv[2]));
|
|
shell_printf("Received [%s](len : %d) from SPI"NEW_LINE, spi_recv_buff, strlen(spi_recv_buff));
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of %s actions :"NEW_LINE"spi_init"NEW_LINE"spi_w"NEW_LINE"spi_r"NEW_LINE"spi_wr"NEW_LINE, argv[0]);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "state") == 0)
|
|
{
|
|
shell_printf("SOFT AP state : %u"NEW_LINE, tls_wifi_softap_get_state());
|
|
}
|
|
else if(strcmp(argv[1], "create") == 0)
|
|
{
|
|
struct tls_softap_info_t ap_info;
|
|
struct tls_ip_info_t ip_info;
|
|
|
|
tls_wifi_set_oneshot_flag(0);
|
|
tls_wifi_softap_destroy();
|
|
|
|
shell_printf("Registering client event callback"NEW_LINE);
|
|
tls_wifi_softap_client_event_register(&(tls_wifi_client_event_cb));
|
|
|
|
strncpy((char *)ap_info.ssid, argv[2], 32);
|
|
ap_info.ssid[32] = '\0';
|
|
ap_info.encrypt = IEEE80211_ENCRYT_TKIP_WPA2;
|
|
ap_info.channel = 5;
|
|
|
|
ap_info.keyinfo.format = 1;
|
|
ap_info.keyinfo.index = 1;
|
|
ap_info.keyinfo.key_len = strlen(argv[3]);
|
|
strncpy((char *)ap_info.keyinfo.key, argv[3], 63);
|
|
|
|
ip_info.ip_addr[0] = 192;
|
|
ip_info.ip_addr[1] = 168;
|
|
ip_info.ip_addr[2] = 1;
|
|
ip_info.ip_addr[3] = 1;
|
|
ip_info.netmask[0] = 255;
|
|
ip_info.netmask[1] = 255;
|
|
ip_info.netmask[2] = 255;
|
|
ip_info.netmask[3] = 0;
|
|
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"NEW_LINE, ap_info.ssid, ap_info.keyinfo.key_len, ap_info.keyinfo.key, result);
|
|
}
|
|
else if(strcmp(argv[1], "destroy") == 0)
|
|
{
|
|
tls_wifi_softap_client_event_register(NULL);
|
|
tls_wifi_set_oneshot_flag(0);
|
|
tls_wifi_softap_destroy();
|
|
shell_printf("Stopping SOFT AP"NEW_LINE);
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of soft_ap actions :"NEW_LINE"state"NEW_LINE"create <SSID> <PWD>"NEW_LINE"destroy"NEW_LINE);
|
|
}
|
|
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..."NEW_LINE);
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Failed to start wifi scan"NEW_LINE);
|
|
}
|
|
}
|
|
else if(strcmp(argv[1], "state") == 0)
|
|
{
|
|
shell_printf("Station state : %u"NEW_LINE, tls_wifi_get_state());
|
|
}
|
|
else if(strcmp(argv[1], "connect") == 0)
|
|
{
|
|
shell_printf("Connecting to %s with pwd : %s"NEW_LINE, argv[2], argv[3]);
|
|
if(tls_wifi_connect((u8 *)argv[2], strlen(argv[2]), (u8 *)argv[3], strlen(argv[3])) == WM_SUCCESS)
|
|
{
|
|
shell_printf("Connecting..."NEW_LINE);
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Failed to connect !"NEW_LINE);
|
|
}
|
|
}
|
|
else if(strcmp(argv[1], "disconnect") == 0)
|
|
{
|
|
shell_printf("Disconnecting from current station"NEW_LINE);
|
|
tls_wifi_set_oneshot_flag(0);
|
|
tls_wifi_disconnect();
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of station actions :"NEW_LINE"scan"NEW_LINE"state"NEW_LINE"connect <SSID> <PWD>"NEW_LINE"disconnect"NEW_LINE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _cpu_temp(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
int temperature = adc_temp();
|
|
|
|
shell_printf("CPU temp is %d.%03d"NEW_LINE, temperature/1000, temperature%1000);
|
|
return 0;
|
|
}
|
|
|
|
int _wifi(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "off") == 0)
|
|
{
|
|
tls_wifi_softap_destroy();
|
|
tls_wifi_disconnect();
|
|
shell_printf("set one shot flg : %d"NEW_LINE,tls_wifi_set_oneshot_flag(0));
|
|
shell_printf("Stopping WIFI interface"NEW_LINE);
|
|
}
|
|
else if(strcmp(argv[1], "error") == 0)
|
|
{
|
|
shell_printf("Error : %s"NEW_LINE, tls_wifi_get_errinfo(tls_wifi_get_errno()));
|
|
}
|
|
else if(strcmp(argv[1], "promiscuous_on") == 0)
|
|
{
|
|
shell_printf("WiFi promiscuous on"NEW_LINE);
|
|
tls_wifi_data_ext_recv_cb_register(&(tls_wifi_data_ext_recv_cb));
|
|
}
|
|
else if(strcmp(argv[1], "promiscuous_off") == 0)
|
|
{
|
|
shell_printf("WiFi promiscuous off"NEW_LINE);
|
|
tls_wifi_data_ext_recv_cb_register(NULL);
|
|
}
|
|
else if(strcmp(argv[1], "mode") == 0)
|
|
{
|
|
shell_printf("Mode is : %d"NEW_LINE, tls_wifi_get_oneshot_flag());
|
|
}
|
|
else if(strcmp(argv[1], "get_ip") == 0)
|
|
{
|
|
struct netif *netif = tls_get_netif();
|
|
|
|
if(netif)
|
|
{
|
|
shell_printf("netif 1"NEW_LINE"ip addr : %v"NEW_LINE"netmask : %v"NEW_LINE"gateway : %v"NEW_LINE, netif->ip_addr.addr,
|
|
netif->netmask.addr,
|
|
netif->gw.addr);
|
|
|
|
if(netif->next)
|
|
{
|
|
shell_printf("netif 2"NEW_LINE"ip addr : %v"NEW_LINE"netmask : %v"NEW_LINE"gateway : %v"NEW_LINE, netif->next->ip_addr.addr,
|
|
netif->next->netmask.addr,
|
|
netif->next->gw.addr);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("No netif yet, connect to sta or create soft_ap !"NEW_LINE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of wifi actions :"NEW_LINE"off"NEW_LINE"error"NEW_LINE"promiscuous_on"NEW_LINE"promiscuous_off"NEW_LINE"mode"NEW_LINE"get_ip"NEW_LINE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _wifi_sleep(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "query") == 0)
|
|
{
|
|
shell_printf("power saving : 0x%X, psm chip sleep : 0x%X"NEW_LINE,
|
|
tls_wifi_get_psflag(),
|
|
tls_wifi_get_psm_chipsleep_flag());
|
|
}
|
|
else if(strcmp(argv[1], "set") == 0)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of wifi_sleep actions :"NEW_LINE"query"NEW_LINE"set"NEW_LINE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _pmu(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "sleep") == 0)
|
|
{
|
|
u32 duration = strtoul(argv[2], NULL, 10);
|
|
shell_printf("Going to sleep mode for %u s"NEW_LINE, duration);
|
|
tls_pmu_timer0_start(duration);
|
|
tls_pmu_sleep_start();
|
|
shell_printf("Waking up out of sleep mode"NEW_LINE);
|
|
tls_pmu_timer0_stop();
|
|
}
|
|
else if(strcmp(argv[1], "standby") == 0)
|
|
{
|
|
u32 duration = strtoul(argv[2], NULL, 10);
|
|
shell_printf("Going to standby mode for %u s"NEW_LINE, duration);
|
|
tls_pmu_timer0_start(duration);
|
|
tls_pmu_standby_start();
|
|
shell_printf("Waking up out of standby mode"NEW_LINE);
|
|
tls_pmu_timer0_stop();
|
|
}
|
|
else if(strcmp(argv[1], "periph_clock_en") == 0 && argc == 3)
|
|
{
|
|
if(strcmp(argv[2], "0"))
|
|
{
|
|
tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_LCD);
|
|
tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_I2S);
|
|
tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM);
|
|
tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_TOUCH_SENSOR);
|
|
//tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_BT);
|
|
shell_printf("Open peripheral clocks"NEW_LINE);
|
|
}
|
|
else
|
|
{
|
|
tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_LCD);
|
|
tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_I2S);
|
|
tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM);
|
|
tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_TOUCH_SENSOR);
|
|
//tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_BT);
|
|
shell_printf("Closed peripheral clocks"NEW_LINE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of pmu actions :"NEW_LINE"sleep <duration(s)>"NEW_LINE"standby <duration(s)>"NEW_LINE
|
|
"periph_clock_en 0|1"NEW_LINE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "get") == 0)
|
|
{
|
|
struct tm rtc_time;
|
|
tls_get_rtc(&rtc_time);
|
|
|
|
shell_printf("rtc time is :"NEW_LINE"%d:%d:%d %d/%d/%d"NEW_LINE,
|
|
rtc_time.tm_hour,
|
|
rtc_time.tm_min,
|
|
rtc_time.tm_sec,
|
|
rtc_time.tm_mday,
|
|
rtc_time.tm_mon,
|
|
rtc_time.tm_year);
|
|
}
|
|
else if(strcmp(argv[1], "set") == 0)
|
|
{
|
|
struct tm rtc_time;
|
|
|
|
rtc_time.tm_hour = strtoul(argv[2], NULL, 10);
|
|
rtc_time.tm_min = strtoul(argv[3], NULL, 10);
|
|
rtc_time.tm_sec = strtoul(argv[4], NULL, 10);
|
|
rtc_time.tm_mday = strtoul(argv[5], NULL, 10);
|
|
rtc_time.tm_mon = strtoul(argv[6], NULL, 10);
|
|
rtc_time.tm_year = strtoul(argv[7], NULL, 10);
|
|
|
|
shell_printf("Setting rtc to :"NEW_LINE"%d:%d:%d %d/%d/%d"NEW_LINE"isr callback registered !"NEW_LINE,
|
|
rtc_time.tm_hour,
|
|
rtc_time.tm_min,
|
|
rtc_time.tm_sec,
|
|
rtc_time.tm_mday,
|
|
rtc_time.tm_mon,
|
|
rtc_time.tm_year);
|
|
|
|
tls_set_rtc(&rtc_time);
|
|
tls_rtc_isr_register(&(tls_rtc_irq_cb), NULL);
|
|
}
|
|
else if(strcmp(argv[1], "alarm") == 0)
|
|
{
|
|
struct tm rtc_time;
|
|
|
|
rtc_time.tm_hour = strtoul(argv[2], NULL, 10);
|
|
rtc_time.tm_min = strtoul(argv[3], NULL, 10);
|
|
rtc_time.tm_sec = strtoul(argv[4], NULL, 10);
|
|
rtc_time.tm_mday = strtoul(argv[5], NULL, 10);
|
|
rtc_time.tm_mon = strtoul(argv[6], NULL, 10);
|
|
rtc_time.tm_year = strtoul(argv[7], NULL, 10);
|
|
|
|
shell_printf("Setting rtc alarm to :"NEW_LINE"%d:%d:%d %d/%d/%d"NEW_LINE,
|
|
rtc_time.tm_hour,
|
|
rtc_time.tm_min,
|
|
rtc_time.tm_sec,
|
|
rtc_time.tm_mday,
|
|
rtc_time.tm_mon,
|
|
rtc_time.tm_year);
|
|
|
|
tls_rtc_timer_start(&(rtc_time));
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of rtc actions :"NEW_LINE"get"NEW_LINE"set <h> <m> <s> <d> <m> <y>"NEW_LINE"alarm <h> <m> <s> <d> <m> <y>"NEW_LINE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void demo_timer_irq(void *arg)
|
|
{
|
|
bool *sleeping = arg;
|
|
if(*sleeping)
|
|
ble_modem_sleep();
|
|
else
|
|
ble_modem_wake();
|
|
}
|
|
|
|
int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "enable") == 0 && argc == 4)
|
|
{
|
|
bool btOnly = atoi(argv[2]) == 1;
|
|
bool service = atoi(argv[3]) == 1;
|
|
|
|
bool result = ble_modem_on(btOnly, service);
|
|
shell_printf("Enabling bluetooth : %d with bt only : %d and service : %d"NEW_LINE, result, btOnly, service);
|
|
|
|
if(result)
|
|
{
|
|
gadget_bridge_parser_register_event_callback(&(parser_event_cb));
|
|
ble_service_register_nus_data_rx_cb(&(nus_data_rx_cb));
|
|
ble_service_set_pairing_passkey(123456);
|
|
|
|
if(!ble_modem_is_sleeping())ble_modem_sleep();
|
|
}
|
|
}
|
|
else if(strcmp(argv[1], "disable") == 0)
|
|
{
|
|
shell_printf("Disabling bluetooth : %d"NEW_LINE, ble_modem_off());
|
|
}
|
|
else if(strcmp(argv[1], "start_demo") == 0)
|
|
{
|
|
bool result = ble_service_start();
|
|
shell_printf("Starting demo : %d"NEW_LINE"Use a BLE app to find the device"NEW_LINE, result /*demo_ble_server_on()*/);
|
|
if(result)
|
|
{
|
|
ble_service_register_nus_data_rx_cb(&(nus_data_rx_cb));
|
|
}
|
|
}
|
|
else if(strcmp(argv[1], "stop_demo") == 0)
|
|
{
|
|
shell_printf("Stopping demo : %d"NEW_LINE, ble_service_stop() /*demo_ble_server_off()*/);
|
|
ble_service_register_nus_data_rx_cb(NULL);
|
|
}
|
|
else if(strcmp(argv[1], "mtu_exch") == 0)
|
|
{
|
|
shell_printf("MTU exchange request : %d"NEW_LINE, ble_service_request_mtu_exchange());
|
|
}
|
|
else if(strcmp(argv[1], "mac_addr") == 0)
|
|
{
|
|
const uint8_t *mac = ble_service_get_device_mac_address();
|
|
shell_printf("The device MAC address is : %02X:%02X:%02X:%02X:%02X:%02X"NEW_LINE,
|
|
mac[5],
|
|
mac[4],
|
|
mac[3],
|
|
mac[2],
|
|
mac[1],
|
|
mac[0]);
|
|
}
|
|
else if(strcmp(argv[1], "send_ble_notif") == 0 && argc > 2)
|
|
{
|
|
char cmd[200] = "";
|
|
bool found = false;
|
|
bool to_return = false;
|
|
if(strcmp(argv[2], "toast") == 0 && argc == 5)
|
|
{
|
|
gadget_bridge_toast_type_e toast_type = GADGET_BRIDGE_TOAST_TYPE_INFO;
|
|
|
|
if(strcmp(argv[3], "warn") == 0)
|
|
{
|
|
toast_type = GADGET_BRIDGE_TOAST_TYPE_WARN;
|
|
}
|
|
else if(strcmp(argv[3], "error") == 0)
|
|
{
|
|
toast_type = GADGET_BRIDGE_TOAST_TYPE_ERROR;
|
|
}
|
|
|
|
to_return = gadget_bridge_send_toast(toast_type, argv[4]);
|
|
}
|
|
else if(strcmp(argv[2], "ver") == 0 && argc == 5)
|
|
{
|
|
to_return = gadget_bridge_send_firmware_version(argv[3], argv[4]);
|
|
}
|
|
else if(strcmp(argv[2], "bat") == 0 && argc == 6)
|
|
{
|
|
sprintf(cmd, "{\"t\":\"status\",\"bat\":%s,\"chg\":%s,\"volt\":%s} \n", argv[3], argv[4], argv[5]);
|
|
uint8_t percent = atoi(argv[3]);
|
|
bool charging = atoi(argv[4]);
|
|
float volt = strtof(argv[5], NULL);
|
|
to_return = gadget_bridge_send_battery_status(percent, volt, charging);
|
|
}
|
|
else if(strcmp(argv[2], "find_phone") == 0 && argc == 4)
|
|
{
|
|
to_return = gadget_bridge_send_find_phone(strcmp(argv[3], "true") == 0);
|
|
}
|
|
else if(strcmp(argv[2], "music") == 0 && argc == 4)
|
|
{
|
|
gadget_bridge_music_control_e music_control = GADGET_BRIDGE_MUSIC_CONTROL_PAUSE;
|
|
|
|
if(strcmp(argv[3], "pause") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_PAUSE;
|
|
else if(strcmp(argv[3], "play") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_PLAY;
|
|
else if(strcmp(argv[3], "playpause") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_PLAYPAUSE;
|
|
else if(strcmp(argv[3], "next") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_NEXT;
|
|
else if(strcmp(argv[3], "previous") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_PREVIOUS;
|
|
else if(strcmp(argv[3], "volumeup") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_VOLUMEUP;
|
|
else if(strcmp(argv[3], "volumedown") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_VOLUMEDOWN;
|
|
else if(strcmp(argv[3], "forward") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_FORWARD;
|
|
else if(strcmp(argv[3], "rewind") == 0)
|
|
music_control = GADGET_BRIDGE_MUSIC_CONTROL_REWIND;
|
|
|
|
to_return = gadget_bridge_send_music_control(music_control);
|
|
}
|
|
else if(strcmp(argv[2], "notify") == 0)
|
|
{
|
|
sprintf(cmd, "{\"t\":\"notify\",\"n\":\"%s\",\"id\":%s,\"tel\":\"%s\",\"msg\":\"%s\"} \n", argv[3], argv[4], argv[5], argv[6]);
|
|
found = true;
|
|
}
|
|
else if(strcmp(argv[2], "act") == 0 && argc == 5)
|
|
{
|
|
to_return = gadget_bridge_send_activity_data(atoi(argv[3]), atoi(argv[4]));
|
|
}
|
|
/*else if(strcmp(argv[2], "calendar") == 0 && argc == 3)
|
|
{
|
|
to_return = gadget_bridge_send_force_calendar_sync();
|
|
}*/
|
|
else if(strcmp(argv[2], "http") == 0 && argc == 6)
|
|
{
|
|
to_return = gadget_bridge_send_http_request(atoi(argv[3]), argv[4], GADGET_BRIDGE_HTTP_REQUEST_GET, NULL, NULL);
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action, list of send_ble_notif actions :"NEW_LINE"toast info|warn|error \"msg\""NEW_LINE"bat \"XX%%\" 1|0 X.X"NEW_LINE"find_phone true|false"NEW_LINE"music play|pause|playpause|previous|next|volumeup|volumedown|forward|rewind"NEW_LINE"notify reply|dismiss_all id \"tel\" \"msg\""NEW_LINE
|
|
"act hrm steps"NEW_LINE
|
|
"ver \"version 1\" \"version 2\""NEW_LINE
|
|
, argv[2]);
|
|
}
|
|
|
|
shell_printf("Sending ble ntf : %d"NEW_LINE, to_return);
|
|
|
|
if(found)
|
|
{
|
|
shell_printf("Sending ble ntf with content : #%s# -> %s"NEW_LINE, cmd, ble_service_send_nus_data((const uint8_t *)cmd, strlen(cmd)) ? "success" : "failure");
|
|
}
|
|
/*else
|
|
{
|
|
shell_printf("Unknown %s action, list of send_ble_notif actions :"NEW_LINE"toast \"msg\""NEW_LINE"bat \"XX%%\" 1|0 X.X"NEW_LINE"find_phone true|false"NEW_LINE"music play|pause|previous|next"NEW_LINE"notify reply|dismiss_all id \"tel\" \"msg\""NEW_LINE
|
|
"act hrm steps"NEW_LINE, argv[2]);
|
|
}*/
|
|
}
|
|
else if(strcmp(argv[1], "up_conn_param") == 0)
|
|
{
|
|
if(argc != 8)
|
|
{
|
|
shell_printf("6 arguments expected"NEW_LINE);
|
|
return 0;
|
|
}
|
|
//First we need to retrieve every parameters from the shell
|
|
uint16_t itvl_min = strtoul(argv[2], NULL, 10);
|
|
uint16_t itvl_max = strtoul(argv[3], NULL, 10);
|
|
uint16_t latency = strtoul(argv[4], NULL, 10);
|
|
uint16_t supervision_timeout = strtoul(argv[5], NULL, 10);
|
|
uint16_t min_ce_len = strtoul(argv[6], NULL, 10);
|
|
uint16_t max_ce_len = strtoul(argv[7], NULL, 10);
|
|
|
|
shell_printf("BLE connection update request : %d"NEW_LINE, ble_service_update_connection_parameters(itvl_min, itvl_max, latency, supervision_timeout, min_ce_len, max_ce_len));
|
|
}
|
|
else if(strcmp(argv[1], "ble_tx_power") == 0)
|
|
{
|
|
if(argc == 3)
|
|
{
|
|
int8_t tx_power = strtoul(argv[2], NULL, 10);
|
|
shell_printf("Setting BLE TX power to : %d -> %u"NEW_LINE, tx_power, tls_ble_set_tx_power(TLS_BLE_PWR_TYPE_DEFAULT, tx_power));
|
|
}
|
|
else // We simply return the current tx_power
|
|
{
|
|
shell_printf("Current BLE TX power is : %d"NEW_LINE, tls_ble_get_tx_power(TLS_BLE_PWR_TYPE_DEFAULT));
|
|
}
|
|
}
|
|
else if(strcmp(argv[1], "bt_tx_power") == 0)
|
|
{
|
|
if(argc == 3)
|
|
{
|
|
int8_t tx_power = strtoul(argv[2], NULL, 10);
|
|
shell_printf("Setting BT TX power to : %d -> %u"NEW_LINE, tx_power, tls_bredr_set_tx_power(tx_power, tx_power));
|
|
}
|
|
else // We simply return the current tx_power
|
|
{
|
|
int8_t min_pow = 0, max_pow = 0;
|
|
tls_bredr_get_tx_power(&min_pow, &max_pow);
|
|
shell_printf("Current BT TX power is : min(%d) max(%d)"NEW_LINE, min_pow, max_pow);
|
|
}
|
|
}
|
|
else if(strcmp(argv[1], "ble_modem_sleep") == 0)
|
|
{
|
|
if(argc == 3)
|
|
{
|
|
static bool sleeping;
|
|
sleeping = strtoul(argv[2], NULL, 10);
|
|
|
|
static uint8_t timer_id = WM_TIMER_ID_INVALID;
|
|
if(timer_id == WM_TIMER_ID_INVALID)
|
|
{
|
|
struct tls_timer_cfg timer_cfg;
|
|
|
|
timer_cfg.unit = TLS_TIMER_UNIT_MS;
|
|
timer_cfg.timeout = 2000;
|
|
timer_cfg.is_repeat = 0;
|
|
timer_cfg.callback = (tls_timer_irq_callback)demo_timer_irq;
|
|
timer_cfg.arg = &sleeping;
|
|
timer_id = tls_timer_create(&timer_cfg);
|
|
}
|
|
|
|
tls_timer_start(timer_id);
|
|
}
|
|
}
|
|
else if(strcmp(argv[1], "ble_modem_wake") == 0)
|
|
{
|
|
shell_printf("BLE modem waking up : %d"NEW_LINE, tls_bt_ctrl_wakeup());
|
|
}
|
|
else if(strcmp(argv[1], "ble_modem_mode") == 0)
|
|
{
|
|
if(strcmp(argv[2], "bt") == 0)
|
|
{
|
|
tls_rf_bt_mode(1);
|
|
shell_printf("BLE modem set to bt only mode"NEW_LINE);
|
|
}
|
|
else
|
|
{
|
|
tls_rf_bt_mode(0);
|
|
shell_printf("BLE modem set to bt/wifi"NEW_LINE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[1]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of bluetooth actions :"NEW_LINE
|
|
"enable 0|1 0|1"NEW_LINE
|
|
"disable"NEW_LINE
|
|
"start_demo"NEW_LINE
|
|
"stop_demo"NEW_LINE
|
|
"send_ble_notif toast \"msg\"|bat \"%%\"|findPhone|music|notify"NEW_LINE
|
|
"mtu_exch"NEW_LINE
|
|
"up_conn_param itvl_min itvl_max latency supervision_timeout min_ce_len max_ce_len"NEW_LINE
|
|
"ble_tx_power 1|2|3|4|5"NEW_LINE
|
|
"bt_tx_power 1|2|3|4|5"NEW_LINE
|
|
"ble_modem_sleep 1|0"NEW_LINE
|
|
"ble_modem_wake"NEW_LINE
|
|
"ble_modem_mode bt|bt_wifi"NEW_LINE
|
|
"mac_addr"NEW_LINE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _telnet(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "dont_echo") == 0)
|
|
{
|
|
shell_printf("Disabling client echo"NEW_LINE"%c%c%c"NEW_LINE, 0xFF, 0xFB, 0x01);
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of %s actions :"NEW_LINE"dont_echo"NEW_LINE, argv[0]);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
int _exit_remote_access(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(disconnect_client())
|
|
{
|
|
shell_printf("Disconnected !"NEW_LINE);
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Not using remote access !"NEW_LINE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _utils(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "random") == 0)
|
|
{
|
|
uint32_t random = random_gen_6_digit();
|
|
shell_printf("Random 6 digit number is : %u"NEW_LINE, random);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of %s actions :"NEW_LINE
|
|
"random"NEW_LINE, argv[0]);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
NANO_SHELL_ADD_CMD(bus,
|
|
_bus,
|
|
"Command to interact with the SPI bus",
|
|
" Use this command to send/receive data from the SPI bus"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(system,
|
|
_system,
|
|
"Query system information",
|
|
" Use this command to get system information"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(reset,
|
|
_reset,
|
|
"Reset the system",
|
|
" Use this command reset the system"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(soft_ap,
|
|
_soft_ap,
|
|
"Command to control SOFT AP",
|
|
" Use this command to control the SOFT AP subsystem"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(station,
|
|
_station,
|
|
"Command to control STATION mode",
|
|
" Use this command to connect to a WiFi access point"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(wifi,
|
|
_wifi,
|
|
"Command to control WIFI interface",
|
|
" Use this command to control the WIFI interface"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(cpu_temp,
|
|
_cpu_temp,
|
|
"Command to read the CPU temperature",
|
|
" Use this command to read the CPU temperature"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(wifi_sleep,
|
|
_wifi_sleep,
|
|
"Command to control WiFi sleep",
|
|
" Use this command to control WiFi sleep feature"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(pmu,
|
|
_pmu,
|
|
"Command to control the power management unit",
|
|
" Use this command to control power management unit feature"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(rtc,
|
|
_rtc,
|
|
"Command to query and set up the rtc",
|
|
" Use this command to interact with the rtc module"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(bluetooth,
|
|
_bluetooth,
|
|
"Command to control bluetooth functionality",
|
|
" Use this command to interact use bluetooth"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(telnet,
|
|
_telnet,
|
|
"Command to set the telnet session up",
|
|
" Use this command to set telnet session parameters"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(exit,
|
|
_exit_remote_access,
|
|
"Disconnect from Nano-Shell remote access",
|
|
" Use this command to disconnect from Nano-Shell remote access"NEW_LINE);
|
|
NANO_SHELL_ADD_CMD(utils,
|
|
_utils,
|
|
"Command used to test various utils functions",
|
|
" Use this command to try various utility functions out lilke random and more"NEW_LINE);
|