135 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			135 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #include <stdbool.h>
 | |
| #include <stdint.h>
 | |
| 
 | |
| #include "nvs_flash.h"
 | |
| #include "esp_wifi.h"
 | |
| #include "esp_event.h"
 | |
| #include "esp_task_wdt.h"
 | |
| 
 | |
| #include "../lib/cli/CLI/CLI.h"
 | |
| #include "../lib/cli/CMDList/CMDList.h"
 | |
| 
 | |
| #include "config.h"
 | |
| #include "utils.h"
 | |
| #include "commands.h"
 | |
| #include "wifi.h"
 | |
| 
 | |
| bool running = true;
 | |
| CMDList_t* cmdList;
 | |
| 
 | |
| 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)
 | |
| {
 | |
| 	printf(c);
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| void app_main() {
 | |
| 	// disable watchdog
 | |
| 	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");
 | |
| 
 | |
| 	/* Initialize NVS — it is used to store PHY calibration data */
 | |
| 	esp_err_t ret = nvs_flash_init();
 | |
| 	if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
 | |
| 	{
 | |
| 		ESP_ERROR_CHECK(nvs_flash_erase());
 | |
| 		ret = nvs_flash_init();
 | |
| 	}
 | |
| 	ESP_ERROR_CHECK(ret);
 | |
| 
 | |
| 	printChipInfo();
 | |
| 
 | |
| 	wifiInit();
 | |
| 
 | |
| 	// while (true)
 | |
| 	// {
 | |
| 	// 	wifi_scan();
 | |
| 	// 	// wait so I have time to open the serial monitor
 | |
| 	// 	for (unsigned long i=1; i < 1000000; i++)
 | |
| 	// 	{
 | |
| 	// 		if (i % 100 == 0)
 | |
| 	// 		{
 | |
| 	// 			printf(",");
 | |
| 	// 		}
 | |
| 	// 	}
 | |
| 	// 	printf("\n");
 | |
| 	// }
 | |
| 
 | |
| 	wifi_connect();
 | |
| 
 | |
| 	/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
 | |
| 	* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
 | |
| 	EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
 | |
| 			WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
 | |
| 			pdFALSE,
 | |
| 			pdFALSE,
 | |
| 			portMAX_DELAY);
 | |
| 
 | |
| 	/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
 | |
| 	* happened. */
 | |
| 	if (bits & WIFI_CONNECTED_BIT)
 | |
| 	{
 | |
| 		printf("INFO: 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);
 | |
| 	}
 | |
| 	else
 | |
| 	{
 | |
| 		printf("FAITAL: UNEXPECTED EVENT\n");
 | |
| 		return;
 | |
| 	}
 | |
| 
 | |
| 	// // setup UDP server
 | |
| 	// int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 | |
| 	// if (sock < 0)
 | |
| 	// {
 | |
| 	// 	printf("FAITAL: failed to create UDP socket\n");
 | |
|    //    return;
 | |
| 	// }
 | |
| 
 | |
| 	// running = true;
 | |
| 
 | |
| 	// cmdList = getCMDList();
 | |
| 
 | |
| 	// // init cli
 | |
| 	// CLI_init((CLI_charOutFn)&charOut, 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;
 | |
| 	// 		}
 | |
| 	// 	}
 | |
| 	// }
 | |
| 
 | |
| 	// CLI_deinit();
 | |
| 	// CMDList_deinit(cmdList);
 | |
| 
 | |
| 	return;
 | |
| }
 |