diff --git a/2.Firmware/GeekTrack/.vscode/settings.json b/2.Firmware/GeekTrack/.vscode/settings.json index 5bb84e1..631ef79 100644 --- a/2.Firmware/GeekTrack/.vscode/settings.json +++ b/2.Firmware/GeekTrack/.vscode/settings.json @@ -45,7 +45,8 @@ "*.inc": "cpp", "*.ipp": "cpp", "istream": "cpp", - "typeinfo": "cpp" + "typeinfo": "cpp", + "esp_wifi.h": "c" }, "idf.portWin": "COM8", "idf.openOcdConfigs": [ diff --git a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL.cpp b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL.cpp index a1741a7..ea35f34 100644 --- a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL.cpp +++ b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL.cpp @@ -37,13 +37,9 @@ static void HAL_Sensor_Init() void HAL_Init() { - printf("Config_Init\n"); Config_Init(); - printf("SD_Init\n"); SD_Init(); - printf("Power_Init\n"); Power_Init(); - printf("Button_Init\n"); Button_Init(); #if CONFIG_SENSOR_ENABLE @@ -53,7 +49,6 @@ void HAL_Init() #ifndef _WIN32 ShellSupport_Init(); #endif - taskManager.Register(Power_Update, 1000); taskManager.Register(Button_Update, 10); taskManager.Register(IMU_Update, 10); diff --git a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Config.cpp b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Config.cpp index 1f82b6f..28b0f49 100644 --- a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Config.cpp +++ b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Config.cpp @@ -29,28 +29,27 @@ void Config_Init() } Config_InitFlag = true; - size_t length = 64; /* If load wifi name fail. config the default name. and password */ - if(Config_GetString("WIFI_NAME", StringBuff, &length) == 0){ + if(Config_GetString("WIFI_NAME", StringBuff, 64) == 0){ Config_SetString("WIFI_NAME", "WIFI_DAFAULT_NAME"); } - if(Config_GetString("WIFI_PWD", StringBuff, &length) == 0){ + if(Config_GetString("WIFI_PWD", StringBuff, 64) == 0){ Config_SetString("WIFI_PWD", "WIFI_DAFAULT_PWD"); } - if(Config_GetString("DEV_IDX", StringBuff, &length) == 0){ + if(Config_GetString("DEV_IDX", StringBuff, 64) == 0){ Config_SetString("DEV_IDX", "0"); } } -uint8_t Config_GetString(const char* key, char* str, size_t* length) +uint8_t Config_GetString(const char* key, char* str, size_t len) { if(!Config_InitFlag){ return 0; } - esp_err_t err = nvs_get_str(nvs_hal, key, str, length); - + size_t length = len; + esp_err_t err = nvs_get_str(nvs_hal, key, str, &length); if(err != ESP_OK) { printf("Cofig_GetStrig:: nvs_get_str error\n"); diff --git a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Network.cpp b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Network.cpp index aaf4573..baa9a36 100644 --- a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Network.cpp +++ b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Network.cpp @@ -17,11 +17,16 @@ struct sockaddr_in saddr = { 0 }; int sock = -1; char buff[UDP_BUFF_LEN] = " "; char ConfigString[64] = {0}; +char ssid[32] = {0}; +char password[64] = {0}; void Network_Init() { + Config_GetString("WIFI_NAME", ssid, 32); + Config_GetString("WIFI_PWD", password, 64); + /* Connect WIFI first. */ - WIFI_Connect(); + WIFI_Connect(ssid, password); /* Init socket to send data. */ sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (sock < 0) { @@ -36,8 +41,7 @@ void Network_Init() void Network_UdpSendData() { int err = 0; - size_t length = 64; - Config_GetString("DEV_IDX", ConfigString, &length); + Config_GetString("DEV_IDX", ConfigString, 64); while (1) { float yaw = 0.0f, roll = 0.0f, pitch = 0.0f; diff --git a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Shell.c b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Shell.c index ebcd691..c5de617 100644 --- a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Shell.c +++ b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Shell.c @@ -32,11 +32,11 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)| int PrintWifiConfig(){ char StringBuff[64] = {0}; size_t length = 64; - uint8_t ret = Config_GetString("WIFI_NAME", StringBuff, &length); + uint8_t ret = Config_GetString("WIFI_NAME", StringBuff, 64); if(ret){ printf("Config WIFI Name = %s\n", StringBuff); } - ret = Config_GetString("WIFI_PWD", StringBuff, &length); + ret = Config_GetString("WIFI_PWD", StringBuff, 64); if(ret){ printf("Config WIFI Password = %s\n", StringBuff); } @@ -66,8 +66,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)| int PrintDevIndex(){ char StringBuff[64] = {0}; - size_t length = 64; - uint8_t ret = Config_GetString("DEV_IDX", StringBuff, &length); + uint8_t ret = Config_GetString("DEV_IDX", StringBuff, 64); if(ret){ printf("Config device idx = %s \n", StringBuff); }else{ diff --git a/2.Firmware/GeekTrack/components/GeekOS/System/HAL/HAL.h b/2.Firmware/GeekTrack/components/GeekOS/System/HAL/HAL.h index 29e56e2..6431b58 100644 --- a/2.Firmware/GeekTrack/components/GeekOS/System/HAL/HAL.h +++ b/2.Firmware/GeekTrack/components/GeekOS/System/HAL/HAL.h @@ -134,7 +134,7 @@ void Memory_DumpInfo(); /* Config */ void Config_Init(); -uint8_t Config_GetString(const char* key, char* str, size_t* length); +uint8_t Config_GetString(const char* key, char* str, size_t len); void Config_SetInt(); void Config_GetInt(); uint8_t Config_SetString(const char* key, const char* str); diff --git a/2.Firmware/GeekTrack/components/Libraries/include/WIFINetwork.h b/2.Firmware/GeekTrack/components/Libraries/include/WIFINetwork.h index 332e3fe..20ee426 100644 --- a/2.Firmware/GeekTrack/components/Libraries/include/WIFINetwork.h +++ b/2.Firmware/GeekTrack/components/Libraries/include/WIFINetwork.h @@ -8,9 +8,7 @@ extern "C" { #endif -uint8_t Library_WIFI_Init(char* ssid, char* password); - -uint8_t WIFI_Connect(void); +uint8_t WIFI_Connect(char* ssid, char* password); #ifdef __cplusplus } /* extern "C" */ diff --git a/2.Firmware/GeekTrack/components/Libraries/src/WIFINetwork.c b/2.Firmware/GeekTrack/components/Libraries/src/WIFINetwork.c index 56eb1a5..3a6b82f 100644 --- a/2.Firmware/GeekTrack/components/Libraries/src/WIFINetwork.c +++ b/2.Firmware/GeekTrack/components/Libraries/src/WIFINetwork.c @@ -1,5 +1,6 @@ #include #include +#include #include "esp_wifi.h" #include "WIFINetwork.h" /* ESP32 Library support. */ @@ -9,14 +10,11 @@ #include "freertos/event_groups.h" - /* The event group allows multiple bits for each event, but we only care about two events: * - we are connected to the AP with an IP * - we failed to connect after the maximum amount of retries */ #define CFG_MAXIMUM_RETRY 1000 /* 配置最大重新连接次数 */ -#define CFG_WIFI_SSID "logzhan" // 配置默认连接的WIFI的SSID -#define CFG_WIFI_PASS "19931203" // 配置默认连接的WIFI的密码 #define WIFI_CONNECTED_BIT BIT0 #define WIFI_FAIL_BIT BIT1 @@ -26,8 +24,6 @@ static int s_retry_num = 0; wifi_config_t wifi_config = { .sta = { - .ssid = CFG_WIFI_SSID, - .password = CFG_WIFI_PASS, .threshold.authmode = WIFI_AUTH_WPA2_PSK, .pmf_cfg = { .capable = true, @@ -45,11 +41,11 @@ static void event_handler(void* arg, esp_event_base_t event_base, if (s_retry_num < CFG_MAXIMUM_RETRY) { esp_wifi_connect(); s_retry_num++; - printf("retry to connect to the AP\r\n"); + //printf("retry to connect to the AP\r\n"); } else { xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); } - printf("connect to the AP fail\r\n"); + //printf("connect to the AP fail\r\n"); } 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; ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); @@ -58,21 +54,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, } } -/** - * @brief Initializing the esp32 wifi network by gaving wifi ssid and - * password. - * @param ssid : Wifi name which you want to connect. - * @param password : The wifi's password which you want to connect. - * @return - * @date 2022-09-04 - * @author zhanli - */ -uint8_t Library_WIFI_Init(char* ssid, char* password){ - return 0; -} - - -uint8_t WIFI_Connect(){ +uint8_t WIFI_Connect(char* ssid, char* password){ ESP_LOGI(TAG, "LIB_WIFIConnect"); @@ -105,6 +87,10 @@ uint8_t WIFI_Connect(){ ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); /* Config esp32 ssid password and authmode. */ ESP_LOGI(TAG, "esp_wifi_set_config"); + + strcpy((char*)(wifi_config.sta.ssid), ssid); + strcpy((char*)(wifi_config.sta.password), password); + ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); /* Start run the esp32 wifi. */ ESP_LOGI(TAG, "esp_wifi_start"); @@ -125,12 +111,10 @@ uint8_t WIFI_Connect(){ */ if (bits & WIFI_CONNECTED_BIT) { ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", - CFG_WIFI_SSID, CFG_WIFI_PASS); - // xTaskCreate(create_multicast_ipv4_socket, "udp_client", 4096, NULL, 5, NULL); - // xTaskCreate(udp_send_data, "udp_send", 4096, NULL, 5, NULL); + ssid, password); } else if (bits & WIFI_FAIL_BIT) { ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", - CFG_WIFI_SSID, CFG_WIFI_PASS); + ssid, password); } else { ESP_LOGE(TAG, "UNEXPECTED EVENT"); } diff --git a/6.Image/GeekTrack_UDP Receive.png b/6.Image/GeekTrack_UDP Receive.png new file mode 100644 index 0000000..a3b0977 Binary files /dev/null and b/6.Image/GeekTrack_UDP Receive.png differ diff --git a/README.md b/README.md index 0006f74..20f74ea 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,11 @@ -# GeekTrack +# **GeekTrack** -**功能描述:一个无线姿态追踪模块,可以追踪姿态。可以用于全身动作捕捉也可以用于人体步态追踪, GeekTrack实际是GeekMotion阉割屏幕减少尺寸的版本,目的是为了方便固定在身体上,用于姿态追踪** +## 一、功能描述: -**GeekMotion:** https://github.com/Logzhan/GeekMoton - -状态:PCB已经打样测试完成,设备WIFI正常,信号对比PCB天线弱一些。IMU、气压计读取数据正常、SD卡识别正常。 +一个无线姿态追踪模块,可以追踪姿态。可以用于全身动作捕捉也可以用于人体步态追踪, GeekTrack实际是GeekMotion阉割屏幕减少尺寸的版本,目的是为了方便固定在身体上,用于姿态追踪 - WIFI通信功能 -- IMU、MAG传感器。 +- IMU、MAG传感器、气压传感器、温度传感器 - LettleShell命令行模块,可以采用命令行和ESP32交互。 - 计步器 - 运动识别(待实现) @@ -28,11 +26,53 @@ - 历史命令行记忆 - ... -**更新日志:** +注意:命令行被log覆盖的时候按下回车即可。 -**2022-09-03 :** 1)上传第一版原理图和PCB图 +## 二、使用方法 +WIFI的配置(通过命令行): +```shell +# 命令行设置WIFI账号和密码 +set_wifi_cfg "your wifi ssid" "your wifi password" +# 设置完成后重启生效 +reboot +``` + +配置设备索引:可以用数字表示设备的索引,数字可以为0~65536 + +```shell +set_dev_idx "device_type_num" +``` + +设备传感器信息的发送,默认UDP端口9000: + +```shell +# dev_Index yaw roll pitch +0 -75.127640 5.829678 -67.846695 +0 -75.029457 5.810158 -67.830681 +0 -74.926865 5.784514 -67.806129 +``` + +## 三、更新日志 + +**2022-09-03 :** 上传第一版原理图和PCB图 + +**2022-09-19 :** 第一版固件调试通过 + +**2022-09-24 :** + +1. 优化app_main, 精简总行数 < 40 +2. 调整结构,迁移网络部分到HAL_Network.cpp +3. 删除GeekTrack无用的关于lvgl部分 +4. 删除无用的lvgl仿真器 +5. 增加NVS存储获取设备索引信息(Idx,可以描述设备0~n) +6. UDP发送增加Idx识别信息 +7. 增加NVS设置Idx + +**2022-09-25:** 增加NVS设置WIFI ssid和WIFI 密码功能 + +## 四、编译说明 **lettleShell移植支持说明:** 需要适配esp32的ld文件。