cli for uart working
This commit is contained in:
parent
668a62c90e
commit
ca1f8f80d4
@ -7,5 +7,13 @@
|
||||
"path": "rx_esp32"
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
"settings": {
|
||||
"files.associations": {
|
||||
"nvs_flash.h": "c",
|
||||
"esp_wifi.h": "c",
|
||||
"esp_event.h": "c",
|
||||
"esp_task_wdt.h": "c",
|
||||
"esp_err.h": "c"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
|
||||
#include "../lib/cli/CMDList/CMDList.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "commands.h"
|
||||
|
||||
int contrl(char* line)
|
||||
@ -8,14 +10,22 @@ int contrl(char* line)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern volatile bool running;
|
||||
int shutdown(char* line)
|
||||
{
|
||||
printf("goodby.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CMD_t Commands[] = {
|
||||
{ "ctrl", &contrl }
|
||||
{ "ctrl", &contrl },
|
||||
{ "shutdown", &shutdown }
|
||||
};
|
||||
|
||||
CMDList_t* getCMDList()
|
||||
{
|
||||
CMDList_t* list = CMDList_init();
|
||||
for (int i = sizeof(Commands) / sizeof(CMD_t); i >= 0; i--)
|
||||
for (int i = sizeof(Commands) / sizeof(CMD_t) - 1; i >= 0; i--)
|
||||
{
|
||||
CMDList_add(list, (CMD_t*)&Commands[i], Commands[i].cmd);
|
||||
}
|
||||
|
||||
@ -11,8 +11,6 @@
|
||||
|
||||
static uint8_t BoatId = 1;
|
||||
|
||||
static const char *TAG = "rcrf-rx_esp32";
|
||||
|
||||
// cli config
|
||||
#define HISTORY
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@ -14,7 +15,7 @@
|
||||
#include "commands.h"
|
||||
#include "wifi.h"
|
||||
|
||||
bool running = true;
|
||||
bool volatile running = true;
|
||||
CMDList_t* cmdList;
|
||||
|
||||
bool rxBuffer_overflow = false;
|
||||
@ -23,7 +24,7 @@ bool rxBuffer_overflow = false;
|
||||
* CLI char out function. used to print back to a CLI, but the lib
|
||||
* is only used for reciving command and not having a full cli
|
||||
*/
|
||||
int charOut(const char* c)
|
||||
int charOut_uart(const char* c)
|
||||
{
|
||||
printf(c);
|
||||
return 0;
|
||||
@ -34,11 +35,11 @@ void app_main() {
|
||||
ESP_ERROR_CHECK(esp_task_wdt_deinit());
|
||||
|
||||
// wait so I have time to open the serial monitor
|
||||
for (unsigned long i=0; i < 10000; i++)
|
||||
{
|
||||
printf(".");
|
||||
}
|
||||
printf("\n");
|
||||
// for (unsigned long i=0; i < 10000; i++)
|
||||
// {
|
||||
// printf(".");
|
||||
// }
|
||||
// printf("\n");
|
||||
|
||||
/* Initialize NVS — it is used to store PHY calibration data */
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
@ -81,15 +82,15 @@ void app_main() {
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT)
|
||||
{
|
||||
printf("INFO: connected to ap SSID '%s'\n", WIFI_SSID);
|
||||
printf("INFO: main: connected to ap SSID '%s'\n", WIFI_SSID);
|
||||
}
|
||||
else if (bits & WIFI_FAIL_BIT)
|
||||
{
|
||||
printf("ERROR: Failed to connect to SSID '%s',\n", WIFI_SSID);
|
||||
printf("ERROR: main: Failed to connect to SSID '%s',\n", WIFI_SSID);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAITAL: UNEXPECTED EVENT\n");
|
||||
printf("FAITAL: main: UNEXPECTED EVENT\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -97,38 +98,30 @@ void app_main() {
|
||||
// int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
// if (sock < 0)
|
||||
// {
|
||||
// printf("FAITAL: failed to create UDP socket\n");
|
||||
// printf("FAITAL: main: failed to create UDP socket\n");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// running = true;
|
||||
running = true;
|
||||
|
||||
// cmdList = getCMDList();
|
||||
cmdList = getCMDList();
|
||||
|
||||
// // init cli
|
||||
// CLI_init((CLI_charOutFn)&charOut, cmdList);
|
||||
// init cli
|
||||
CLI_t cli_uart = CLI_init((CLI_charOutFn)&charOut_uart, cmdList);
|
||||
|
||||
// while (running)
|
||||
// {
|
||||
// int packetSize = UDP.parsePacket();
|
||||
// while (packetSize) {
|
||||
// char c;
|
||||
// int len = UDP.read(&c, 1);
|
||||
// if (len == 1)
|
||||
// {
|
||||
// CLI_charIn(c);
|
||||
// packetSize--;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// printf("UDP read error");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
char ch_uart = 0;
|
||||
|
||||
// CLI_deinit();
|
||||
// CMDList_deinit(cmdList);
|
||||
while (running)
|
||||
{
|
||||
ch_uart = getchar();
|
||||
if (ch_uart != 255)
|
||||
{
|
||||
CLI_charIn(&cli_uart, ch_uart);
|
||||
}
|
||||
}
|
||||
|
||||
CLI_deinit(&cli_uart);
|
||||
CMDList_deinit(cmdList);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -24,27 +24,27 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
|
||||
switch (event_id)
|
||||
{
|
||||
case WIFI_EVENT_WIFI_READY:
|
||||
printf("INFO: WiFi ready\n");
|
||||
printf("INFO: wifi: WiFi ready\n");
|
||||
break;
|
||||
case WIFI_EVENT_SCAN_DONE:
|
||||
printf("INFO: Finished scanning AP\n");
|
||||
printf("INFO: wifi: Finished scanning AP\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_START:
|
||||
printf("INFO: Station start\n");
|
||||
printf("INFO: wifi: Station start\n");
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case WIFI_EVENT_STA_STOP:
|
||||
printf("INFO: Station stop\n");
|
||||
printf("INFO: wifi: Station stop\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_CONNECTED:
|
||||
printf("INFO: Station connected to AP\n");
|
||||
printf("INFO: wifi: Station connected to AP\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_DISCONNECTED:
|
||||
printf("INFO: Station disconnected from AP\n");
|
||||
printf("WARN: wifi: Station disconnected from AP\n");
|
||||
if (s_retry_num < MAX_RETRY_ATTEMPTS)
|
||||
{
|
||||
s_retry_num++;
|
||||
printf("INFO: retry num %d", s_retry_num);
|
||||
printf("INFO: wifi: retry num %d", s_retry_num);
|
||||
for (unsigned long i=0; i < 10000000; i++)
|
||||
{
|
||||
// printf(".\n");
|
||||
@ -58,119 +58,119 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
|
||||
break;
|
||||
break;
|
||||
case WIFI_EVENT_STA_AUTHMODE_CHANGE:
|
||||
printf("INFO: the auth mode of AP connected by device's station changed\n");
|
||||
printf("INFO: wifi: the auth mode of AP connected by device's station changed\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_WPS_ER_SUCCESS:
|
||||
printf("INFO: Station wps succeeds in enrollee mode\n");
|
||||
printf("INFO: wifi: Station wps succeeds in enrollee mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_WPS_ER_FAILED:
|
||||
printf("INFO: Station wps fails in enrollee mode\n");
|
||||
printf("ERROR: wifi: Station wps fails in enrollee mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_WPS_ER_TIMEOUT:
|
||||
printf("INFO: Station wps timeout in enrollee mode\n");
|
||||
printf("ERROR: wifi: Station wps timeout in enrollee mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_WPS_ER_PIN:
|
||||
printf("INFO: Station wps pin code in enrollee mode\n");
|
||||
printf("INFO: wifi: Station wps pin code in enrollee mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP:
|
||||
printf("INFO: Station wps overlap in enrollee mode\n");
|
||||
printf("INFO: wifi: Station wps overlap in enrollee mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_START:
|
||||
printf("INFO: Soft-AP start\n");
|
||||
printf("INFO: wifi: Soft-AP start\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_STOP:
|
||||
printf("INFO: Soft-AP stop\n");
|
||||
printf("INFO: wifi: Soft-AP stop\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_STACONNECTED:
|
||||
printf("INFO: a station connected to Soft-AP\n");
|
||||
printf("INFO: wifi: a station connected to Soft-AP\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_STADISCONNECTED:
|
||||
printf("INFO: a station disconnected from Soft-AP\n");
|
||||
printf("WARN: wifi: a station disconnected from Soft-AP\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_PROBEREQRECVED:
|
||||
printf("INFO: Receive probe request packet in soft-AP interface\n");
|
||||
printf("INFO: wifi: Receive probe request packet in soft-AP interface\n");
|
||||
break;
|
||||
case WIFI_EVENT_FTM_REPORT:
|
||||
printf("INFO: Receive report of FTM procedure\n");
|
||||
printf("INFO: wifi: Receive report of FTM procedure\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_BSS_RSSI_LOW:
|
||||
printf("INFO: AP's RSSI crossed configured threshold\n");
|
||||
printf("INFO: wifi: AP's RSSI crossed configured threshold\n");
|
||||
break;
|
||||
case WIFI_EVENT_ACTION_TX_STATUS:
|
||||
printf("INFO: Status indication of Action Tx operation\n");
|
||||
printf("INFO: wifi: Status indication of Action Tx operation\n");
|
||||
break;
|
||||
case WIFI_EVENT_ROC_DONE:
|
||||
printf("INFO: Remain-on-Channel operation complete\n");
|
||||
printf("INFO: wifi: Remain-on-Channel operation complete\n");
|
||||
break;
|
||||
case WIFI_EVENT_STA_BEACON_TIMEOUT:
|
||||
printf("INFO: Station beacon timeout\n");
|
||||
printf("ERROR: wifi: Station beacon timeout\n");
|
||||
break;
|
||||
case WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START:
|
||||
printf("INFO: Connectionless module wake interval start\n");
|
||||
printf("INFO: wifi: Connectionless module wake interval start\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_WPS_RG_SUCCESS:
|
||||
printf("INFO: Soft-AP wps succeeds in registrar mode\n");
|
||||
printf("INFO: wifi: Soft-AP wps succeeds in registrar mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_WPS_RG_FAILED:
|
||||
printf("INFO: Soft-AP wps fails in registrar mode\n");
|
||||
printf("ERROR: wifi: Soft-AP wps fails in registrar mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_WPS_RG_TIMEOUT:
|
||||
printf("INFO: Soft-AP wps timeout in registrar mode\n");
|
||||
printf("ERROR: wifi: Soft-AP wps timeout in registrar mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_WPS_RG_PIN:
|
||||
printf("INFO: Soft-AP wps pin code in registrar mode\n");
|
||||
printf("INFO: wifi: Soft-AP wps pin code in registrar mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_AP_WPS_RG_PBC_OVERLAP:
|
||||
printf("INFO: Soft-AP wps overlap in registrar mode\n");
|
||||
printf("INFO: wifi: Soft-AP wps overlap in registrar mode\n");
|
||||
break;
|
||||
case WIFI_EVENT_ITWT_SETUP:
|
||||
printf("INFO: iTWT setup\n");
|
||||
printf("INFO: wifi: iTWT setup\n");
|
||||
break;
|
||||
case WIFI_EVENT_ITWT_TEARDOWN:
|
||||
printf("INFO: iTWT teardown\n");
|
||||
printf("INFO: wifi: iTWT teardown\n");
|
||||
break;
|
||||
case WIFI_EVENT_ITWT_PROBE:
|
||||
printf("INFO: iTWT probe\n");
|
||||
printf("INFO: wifi: iTWT probe\n");
|
||||
break;
|
||||
case WIFI_EVENT_ITWT_SUSPEND:
|
||||
printf("INFO: iTWT suspend\n");
|
||||
printf("INFO: wifi: iTWT suspend\n");
|
||||
break;
|
||||
case WIFI_EVENT_NAN_STARTED:
|
||||
printf("INFO: NAN Discovery has started\n");
|
||||
printf("INFO: wifi: NAN Discovery has started\n");
|
||||
break;
|
||||
case WIFI_EVENT_NAN_STOPPED:
|
||||
printf("INFO: NAN Discovery has stopped\n");
|
||||
printf("INFO: wifi: NAN Discovery has stopped\n");
|
||||
break;
|
||||
case WIFI_EVENT_NAN_SVC_MATCH:
|
||||
printf("INFO: NAN Service Discovery match found\n");
|
||||
printf("INFO: wifi: NAN Service Discovery match found\n");
|
||||
break;
|
||||
case WIFI_EVENT_NAN_REPLIED:
|
||||
printf("INFO: Replied to a NAN peer with Service Discovery match\n");
|
||||
printf("INFO: wifi: Replied to a NAN peer with Service Discovery match\n");
|
||||
break;
|
||||
case WIFI_EVENT_NAN_RECEIVE:
|
||||
printf("INFO: Received a Follow-up message\n");
|
||||
printf("INFO: wifi: Received a Follow-up message\n");
|
||||
break;
|
||||
case WIFI_EVENT_NDP_INDICATION:
|
||||
printf("INFO: Received NDP Request from a NAN Peer\n");
|
||||
printf("INFO: wifi: Received NDP Request from a NAN Peer\n");
|
||||
break;
|
||||
case WIFI_EVENT_NDP_CONFIRM:
|
||||
printf("INFO: NDP Confirm Indication\n");
|
||||
printf("INFO: wifi: NDP Confirm Indication\n");
|
||||
break;
|
||||
case WIFI_EVENT_NDP_TERMINATED:
|
||||
printf("INFO: NAN Datapath terminated indication\n");
|
||||
printf("INFO: wifi: NAN Datapath terminated indication\n");
|
||||
break;
|
||||
case WIFI_EVENT_HOME_CHANNEL_CHANGE:
|
||||
printf("INFO: WiFi home channel change,doesn't occur when scanning\n");
|
||||
printf("INFO: wifi: WiFi home channel change,doesn't occur when scanning\n");
|
||||
break;
|
||||
case WIFI_EVENT_MAX:
|
||||
printf("INFO: Invalid WiFi event ID\n");
|
||||
printf("INFO: wifi: Invalid WiFi event ID\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
||||
{
|
||||
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
|
||||
printf("INFO: got ip: " IPSTR "\n", IP2STR(&event->ip_info.ip));
|
||||
printf("INFO: wifi: got ip: " IPSTR "\n", IP2STR(&event->ip_info.ip));
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
@ -198,7 +198,7 @@ void wifiInit()
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(
|
||||
IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip));
|
||||
|
||||
printf("INFO: wifi_init_sta finished.\n");
|
||||
printf("INFO: wifi: wifi_init_sta finished.\n");
|
||||
}
|
||||
|
||||
void wifi_connect()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user