Compare commits
5 Commits
435a7caa66
...
78e81da80f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78e81da80f | ||
| 8aee83507d | |||
|
|
56592a01f5 | ||
|
|
bdf2be1c16 | ||
|
|
da729abb0f |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,3 +3,6 @@
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
GIT_GUIDE.md
|
||||
git_upload.bat
|
||||
.trae/
|
||||
|
||||
244
GIT_GUIDE.md
Normal file
244
GIT_GUIDE.md
Normal file
@@ -0,0 +1,244 @@
|
||||
# Git 操作指南
|
||||
|
||||
## 快速上传脚本
|
||||
|
||||
双击运行 `git_upload.bat` 即可快速上传代码到 Git 仓库。
|
||||
|
||||
## 常用 Git 命令
|
||||
|
||||
### 1. 基础操作
|
||||
|
||||
```powershell
|
||||
# 查看当前状态
|
||||
& "C:\Program Files\Git\bin\git.exe" status
|
||||
|
||||
# 查看修改内容
|
||||
& "C:\Program Files\Git\bin\git.exe" diff
|
||||
|
||||
# 查看提交历史
|
||||
& "C:\Program Files\Git\bin\git.exe" log --oneline
|
||||
|
||||
# 查看最近 5 次提交
|
||||
& "C:\Program Files\Git\bin\git.exe" log -5
|
||||
```
|
||||
|
||||
### 2. 提交代码
|
||||
|
||||
```powershell
|
||||
# 添加所有文件
|
||||
& "C:\Program Files\Git\bin\git.exe" add -A
|
||||
|
||||
# 添加指定文件
|
||||
& "C:\Program Files\Git\bin\git.exe" add 文件名
|
||||
|
||||
# 提交更改
|
||||
& "C:\Program Files\Git\bin\git.exe" commit -m "提交信息"
|
||||
|
||||
# 添加并提交(一步完成)
|
||||
& "C:\Program Files\Git\bin\git.exe" commit -am "提交信息"
|
||||
```
|
||||
|
||||
### 3. 推送到远程仓库
|
||||
|
||||
```powershell
|
||||
# 推送到远程仓库
|
||||
& "C:\Program Files\Git\bin\git.exe" push
|
||||
|
||||
# 首次推送(设置上游分支)
|
||||
& "C:\Program Files\Git\bin\git.exe" push -u origin main
|
||||
|
||||
# 强制推送(谨慎使用)
|
||||
& "C:\Program Files\Git\bin\git.exe" push --force
|
||||
```
|
||||
|
||||
### 4. 拉取代码
|
||||
|
||||
```powershell
|
||||
# 拉取远程代码
|
||||
& "C:\Program Files\Git\bin\git.exe" pull
|
||||
|
||||
# 拉取并合并
|
||||
& "C:\Program Files\Git\bin\git.exe" pull origin main
|
||||
```
|
||||
|
||||
### 5. 分支操作
|
||||
|
||||
```powershell
|
||||
# 查看所有分支
|
||||
& "C:\Program Files\Git\bin\git.exe" branch -a
|
||||
|
||||
# 创建新分支
|
||||
& "C:\Program Files\Git\bin\git.exe" branch 分支名
|
||||
|
||||
# 切换分支
|
||||
& "C:\Program Files\Git\bin\git.exe" checkout 分支名
|
||||
|
||||
# 创建并切换到新分支
|
||||
& "C:\Program Files\Git\bin\git.exe" checkout -b 分支名
|
||||
|
||||
# 删除本地分支
|
||||
& "C:\Program Files\Git\bin\git.exe" branch -d 分支名
|
||||
|
||||
# 删除远程分支
|
||||
& "C:\Program Files\Git\bin\git.exe" push origin --delete 分支名
|
||||
```
|
||||
|
||||
### 6. 撤销操作
|
||||
|
||||
```powershell
|
||||
# 撤销工作区的修改
|
||||
& "C:\Program Files\Git\bin\git.exe" restore 文件名
|
||||
|
||||
# 撤销所有工作区的修改
|
||||
& "C:\Program Files\Git\bin\git.exe" restore .
|
||||
|
||||
# 撤销暂存区的修改
|
||||
& "C:\Program Files\Git\bin\git.exe" reset HEAD 文件名
|
||||
|
||||
# 撤销最后一次提交(保留修改)
|
||||
& "C:\Program Files\Git\bin\git.exe" reset --soft HEAD~1
|
||||
|
||||
# 撤销最后一次提交(丢弃修改)
|
||||
& "C:\Program Files\Git\bin\git.exe" reset --hard HEAD~1
|
||||
```
|
||||
|
||||
### 7. 远程仓库操作
|
||||
|
||||
```powershell
|
||||
# 查看远程仓库
|
||||
& "C:\Program Files\Git\bin\git.exe" remote -v
|
||||
|
||||
# 添加远程仓库
|
||||
& "C:\Program Files\Git\bin\git.exe" remote add origin 远程仓库地址
|
||||
|
||||
# 删除远程仓库
|
||||
& "C:\Program Files\Git\bin\git.exe" remote remove origin
|
||||
|
||||
# 修改远程仓库地址
|
||||
& "C:\Program Files\Git\bin\git.exe" remote set-url origin 新地址
|
||||
```
|
||||
|
||||
### 8. 查看文件
|
||||
|
||||
```powershell
|
||||
# 查看已跟踪的文件
|
||||
& "C:\Program Files\Git\bin\git.exe" ls-files
|
||||
|
||||
# 查看被忽略的文件
|
||||
& "C:\Program Files\Git\bin\git.exe" status --ignored
|
||||
|
||||
# 查看文件大小
|
||||
& "C:\Program Files\Git\bin\git.exe" ls-files -s
|
||||
```
|
||||
|
||||
## 完整上传流程
|
||||
|
||||
### 方式一:使用脚本(推荐)
|
||||
|
||||
```powershell
|
||||
# 双击运行 git_upload.bat
|
||||
# 按照提示输入提交信息即可
|
||||
```
|
||||
|
||||
### 方式二:手动执行命令
|
||||
|
||||
```powershell
|
||||
# 1. 查看当前状态
|
||||
& "C:\Program Files\Git\bin\git.exe" status
|
||||
|
||||
# 2. 添加所有修改的文件
|
||||
& "C:\Program Files\Git\bin\git.exe" add -A
|
||||
|
||||
# 3. 提交更改
|
||||
& "C:\Program Files\Git\bin\git.exe" commit -m "你的提交信息"
|
||||
|
||||
# 4. 推送到远程仓库
|
||||
& "C:\Program Files\Git\bin\git.exe" push
|
||||
```
|
||||
|
||||
## 项目配置信息
|
||||
|
||||
- **远程仓库地址**: `http://lmhrt.cn:6771/ming/Rader_Success_5.git`
|
||||
- **主分支**: `main`
|
||||
- **Git 路径**: `C:\Program Files\Git\bin\git.exe`
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 1. 推送失败,提示需要拉取
|
||||
|
||||
```powershell
|
||||
# 先拉取远程代码
|
||||
& "C:\Program Files\Git\bin\git.exe" pull
|
||||
|
||||
# 解决冲突后再推送
|
||||
& "C:\Program Files\Git\bin\git.exe" push
|
||||
```
|
||||
|
||||
### 2. 忘记添加 .gitignore
|
||||
|
||||
```powershell
|
||||
# 从暂存区移除已添加的文件
|
||||
& "C:\Program Files\Git\bin\git.exe" rm -r --cached .pio
|
||||
|
||||
# 提交更改
|
||||
& "C:\Program Files\Git\bin\git.exe" commit -m "Remove .pio from tracking"
|
||||
& "C:\Program Files\Git\bin\git.exe" push
|
||||
```
|
||||
|
||||
### 3. 修改最后一次提交信息
|
||||
|
||||
```powershell
|
||||
# 修改最后一次提交(未推送)
|
||||
& "C:\Program Files\Git\bin\git.exe" commit --amend -m "新的提交信息"
|
||||
```
|
||||
|
||||
### 4. 查看文件历史
|
||||
|
||||
```powershell
|
||||
# 查看指定文件的历史
|
||||
& "C:\Program Files\Git\bin\git.exe" log --follow 文件名
|
||||
|
||||
# 查看指定文件在某次提交的内容
|
||||
& "C:\Program Files\Git\bin\git.exe" show 提交哈希:文件名
|
||||
```
|
||||
|
||||
## 提交信息规范
|
||||
|
||||
建议使用清晰的提交信息,例如:
|
||||
|
||||
```
|
||||
- "Add new feature: radar data upload"
|
||||
- "Fix bug: WiFi connection timeout"
|
||||
- "Update documentation: README.md"
|
||||
- "Refactor: improve code structure"
|
||||
- "Optimize: reduce memory usage"
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **提交前检查**: 使用 `git status` 查看要提交的文件
|
||||
2. **合理提交**: 频繁提交,每次提交一个完整的功能或修复
|
||||
3. **提交信息**: 使用清晰、简洁的提交信息
|
||||
4. **推送前拉取**: 推送前先 `git pull` 避免冲突
|
||||
5. **敏感信息**: 不要提交密码、密钥等敏感信息
|
||||
|
||||
## 快捷别名(可选)
|
||||
|
||||
如果经常使用 Git,可以在 PowerShell 配置文件中添加别名:
|
||||
|
||||
```powershell
|
||||
# 在 PowerShell 配置文件中添加
|
||||
function gs { & "C:\Program Files\Git\bin\git.exe" status $args }
|
||||
function ga { & "C:\Program Files\Git\bin\git.exe" add $args }
|
||||
function gc { & "C:\Program Files\Git\bin\git.exe" commit -m $args }
|
||||
function gp { & "C:\Program Files\Git\bin\git.exe" push $args }
|
||||
function gl { & "C:\Program Files\Git\bin\git.exe" pull $args }
|
||||
```
|
||||
|
||||
使用示例:
|
||||
```powershell
|
||||
gs # git status
|
||||
ga -A # git add -A
|
||||
gc "update" # git commit -m "update"
|
||||
gp # git push
|
||||
```
|
||||
37
git_upload.bat
Normal file
37
git_upload.bat
Normal file
@@ -0,0 +1,37 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
echo ========================================
|
||||
echo Git 上传脚本 - Rader_Success_5
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
set GIT_PATH="C:\Program Files\Git\bin\git.exe"
|
||||
set REMOTE_URL=http://lmhrt.cn:6771/ming/Rader_Success_5.git
|
||||
|
||||
echo [1/5] 检查 Git 状态...
|
||||
%GIT_PATH% status
|
||||
echo.
|
||||
|
||||
echo [2/5] 添加所有文件到暂存区...
|
||||
%GIT_PATH% add -A
|
||||
echo.
|
||||
|
||||
echo [3/5] 提交更改...
|
||||
set /p commit_msg="请输入提交信息 (默认: Update project): "
|
||||
if "%commit_msg%"=="" set commit_msg=Update project
|
||||
%GIT_PATH% commit -m "%commit_msg%"
|
||||
echo.
|
||||
|
||||
echo [4/5] 拉取远程代码...
|
||||
%GIT_PATH% pull
|
||||
echo.
|
||||
|
||||
echo [5/5] 推送到远程仓库...
|
||||
%GIT_PATH% push
|
||||
echo.
|
||||
|
||||
echo ========================================
|
||||
echo 上传完成!
|
||||
echo ========================================
|
||||
echo.
|
||||
pause
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
// ESP32 GPIO控制演示
|
||||
#define BOOT_BUTTON_PIN 0 // Boot按钮引脚
|
||||
#define NETWORK_LED_PIN 48 // 网络状态LED指示灯开发板48引脚,雷达板5引脚
|
||||
#define NETWORK_LED_PIN 5 // 网络状态LED指示灯开发板48引脚,雷达板5引脚
|
||||
#define CONFIG_CLEAR_PIN 4 // 配置清除指示灯
|
||||
#define GPIO8 8 // 自定义GPIO8
|
||||
#define GPIO9 9 // 自定义GPIO9
|
||||
@@ -617,3 +617,4 @@ void loop() {
|
||||
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ WiFiManager::WiFiManager() {
|
||||
savedNetworkCount = 0;
|
||||
currentState = WIFI_IDLE;
|
||||
lastReconnectAttempt = 0;
|
||||
isScanning = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,12 +130,12 @@ bool WiFiManager::connectToNetwork(const char* ssid, const char* password) {
|
||||
setNetworkStatus(NET_CONNECTING);
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
unsigned long startTime = millis();
|
||||
unsigned long lastStatusPrint = 0;
|
||||
|
||||
// 等待连接成功或超时
|
||||
while (WiFi.status() != WL_CONNECTED && (millis() - startTime) < WIFI_CONNECT_TIMEOUT) {
|
||||
if (millis() - lastStatusPrint >= 500) {
|
||||
Serial.printf("[WiFi] 连接中,状态: %d\n", WiFi.status());
|
||||
@@ -168,13 +169,23 @@ bool WiFiManager::connectToNetwork(const char* ssid, const char* password) {
|
||||
* @return 是否成功连接到匹配的网络
|
||||
*/
|
||||
bool WiFiManager::scanAndMatchNetworks() {
|
||||
if (isScanning) {
|
||||
Serial.println("⚠️ [WiFi] 正在扫描中,跳过本次扫描");
|
||||
return false;
|
||||
}
|
||||
|
||||
Serial.println("🔍 [WiFi] 开始扫描WiFi网络...");
|
||||
currentState = WIFI_SCANNING;
|
||||
isScanning = true;
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.println("📶 WiFi已连接,断开后扫描");
|
||||
WiFi.disconnect(false);
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
WiFi.disconnect(true);
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
WiFi.mode(WIFI_STA);
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
|
||||
int n = WiFi.scanNetworks();
|
||||
Serial.printf("🔍 扫描到 %d 个WiFi网络\n", n);
|
||||
@@ -182,6 +193,7 @@ bool WiFiManager::scanAndMatchNetworks() {
|
||||
if (n <= 0) {
|
||||
Serial.println("❌ 未扫描到任何WiFi网络或扫描失败");
|
||||
currentState = WIFI_DISCONNECTED;
|
||||
isScanning = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -221,13 +233,19 @@ bool WiFiManager::scanAndMatchNetworks() {
|
||||
if (bestNetwork.ssid != nullptr) {
|
||||
Serial.printf("✅ 选择信号最强的网络: %s, 信号: %d dBm\n",
|
||||
bestNetwork.ssid, bestNetwork.rssi);
|
||||
|
||||
WiFi.scanDelete();
|
||||
vTaskDelay(300 / portTICK_PERIOD_MS);
|
||||
|
||||
if (connectToNetwork(bestNetwork.ssid, bestNetwork.password)) {
|
||||
isScanning = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("❌ 未找到匹配的WiFi网络或信号过弱");
|
||||
currentState = WIFI_DISCONNECTED;
|
||||
isScanning = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -260,18 +278,33 @@ bool WiFiManager::initializeWiFi() {
|
||||
* 扫描附近的WiFi网络,过滤信号弱的网络,将结果通过BLE发送给客户端
|
||||
*/
|
||||
void WiFiManager::scanAndSendResults() {
|
||||
Serial.println("📱 [BLE-WiFi] 开始WiFi扫描...");
|
||||
if (isScanning) {
|
||||
Serial.println("⚠️ [WiFi] 正在扫描中,跳过本次扫描");
|
||||
if (deviceConnected) {
|
||||
String errorMsg = String("{\"type\":\"scanWiFiResult\",\"success\":false,\"message\":\"正在扫描中,请稍后再试\",\"networks\":[],\"count\":0}");
|
||||
sendJSONDataToBLE(errorMsg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("📱 [BLE-WiFi] 开始WiFi扫描...");
|
||||
isScanning = true;
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.println("📶 WiFi已连接,断开后扫描");
|
||||
WiFi.disconnect(false);
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
WiFi.disconnect(true);
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
WiFi.mode(WIFI_STA);
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
|
||||
int n = WiFi.scanNetworks();
|
||||
Serial.printf("🔍 扫描到 %d 个WiFi网络\n", n);
|
||||
|
||||
if (n <= 0) {
|
||||
Serial.println("❌ 未扫描到任何WiFi网络或扫描失败");
|
||||
isScanning = false;
|
||||
if (deviceConnected) {
|
||||
String errorMsg = String("{\"type\":\"scanWiFiResult\",\"success\":false,\"message\":\"未扫描到任何WiFi网络或扫描失败\",\"networks\":[],\"count\":0}");
|
||||
sendJSONDataToBLE(errorMsg);
|
||||
@@ -331,6 +364,9 @@ void WiFiManager::scanAndSendResults() {
|
||||
|
||||
Serial.printf("✅ 发送WiFi扫描结果,包含 %d 个可用网络\n", first ? 0 : n);
|
||||
|
||||
WiFi.scanDelete();
|
||||
isScanning = false;
|
||||
|
||||
if (deviceConnected) {
|
||||
sendJSONDataToBLE(wifiList);
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ private:
|
||||
int savedNetworkCount; // 已保存的网络数量
|
||||
WiFiManagerState currentState; // 当前WiFi管理器状态
|
||||
unsigned long lastReconnectAttempt; // 上次尝试重连的时间
|
||||
bool isScanning; // 是否正在扫描
|
||||
|
||||
bool scanAndMatchNetworks(); // 扫描并匹配网络
|
||||
bool connectToNetwork(const char* ssid, const char* password); // 连接到指定网络
|
||||
|
||||
Reference in New Issue
Block a user