修改蓝牙
This commit is contained in:
parent
dca184ea3d
commit
a1666d018f
|
|
@ -21,6 +21,7 @@ static CmdExecutor_t init_executor;
|
|||
static CmdExecutor_t first_connect_executor;
|
||||
static CmdExecutor_t connect_executor;
|
||||
static CmdExecutor_t set_executor;
|
||||
static uint8_t recovery_level = 0; // 放在文件开头
|
||||
|
||||
|
||||
const char* ble_state_names[] = {
|
||||
|
|
@ -175,8 +176,13 @@ void BLE_StateMachine_Handler(void)
|
|||
|
||||
case BLE_ERROR :
|
||||
{
|
||||
static uint8_t recovery_level = 0;
|
||||
const uint8_t MAX_RECOVERY_LEVEL = 3;
|
||||
recovery_level++;
|
||||
if (recovery_level > MAX_RECOVERY_LEVEL) {
|
||||
DEBUG("恢复尝试已达上限(%d次),进入等待", MAX_RECOVERY_LEVEL);
|
||||
curr_state = BLE_WAITTING;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(g_ble_error.type)
|
||||
{
|
||||
|
|
@ -194,31 +200,20 @@ void BLE_StateMachine_Handler(void)
|
|||
break;
|
||||
|
||||
case ERR_TYPE_TIMEOUT_EXCEEDED:
|
||||
{
|
||||
|
||||
g_ble_error.recovery_target = RECOVERY_TARGET_RESTART_SEQ;
|
||||
|
||||
|
||||
|
||||
//curr_state = BLE_SET;
|
||||
//重新配置串口信息
|
||||
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case ERR_TYPE_PARSE_FAILED:
|
||||
{
|
||||
|
||||
// DEBUG("error message ,main state:%s, sub state:%s, cmd_index:%d, timestamp:%d",
|
||||
// ble_state_names[g_ble_error.main_state], ble_sub_state_names[g_ble_error.sub_state], g_ble_error.cmd_index, g_ble_error.timestamp);
|
||||
g_ble_error.recovery_target = RECOVERY_TARGET_RESTART_SEQ;
|
||||
|
||||
//重新配置串口信息
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case ERR_TYPE_MODULE_ERROR:
|
||||
|
|
@ -233,18 +228,21 @@ void BLE_StateMachine_Handler(void)
|
|||
DEBUG("error message ,main state:%s, sub state:%s, cmd_index:%d, timestamp:%d",
|
||||
ble_state_names[g_ble_error.main_state], ble_sub_state_names[g_ble_error.sub_state], g_ble_error.cmd_index, g_ble_error.timestamp);
|
||||
//curr_state = BLE_SET;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i == table_size)
|
||||
{
|
||||
g_ble_error.recovery_target = RECOVERY_TARGET_RESTART_SEQ;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
g_ble_error.recovery_target = RECOVERY_TARGET_PANIC;
|
||||
|
||||
|
|
@ -253,19 +251,6 @@ void BLE_StateMachine_Handler(void)
|
|||
|
||||
}
|
||||
|
||||
if(g_ble_error.recovery_target >= RECOVERY_TARGET_SW_RESET_MODULE)
|
||||
{
|
||||
recovery_level++;
|
||||
if(recovery_level > MAX_RECOVERY_LEVEL)
|
||||
{
|
||||
// 超过最大恢复级别,无法恢复,进入等待
|
||||
DEBUG("恢复级别 %d 超过阈值,进入等待", recovery_level);
|
||||
curr_state = BLE_WAITTING;
|
||||
break; // 跳出 BLE_ERROR
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 3. 执行恢复动作
|
||||
switch(g_ble_error.recovery_target)
|
||||
{
|
||||
|
|
@ -286,6 +271,7 @@ void BLE_StateMachine_Handler(void)
|
|||
break;
|
||||
}
|
||||
// 返回原状态,重新开始执行序列
|
||||
recovery_level = 0;
|
||||
curr_state = g_ble_error.origin_state;
|
||||
break;
|
||||
|
||||
|
|
@ -307,10 +293,11 @@ void BLE_StateMachine_Handler(void)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
recovery_level = 0;
|
||||
curr_state = g_ble_error.origin_state;
|
||||
break;
|
||||
|
||||
// case RECOVERY_TARGET_SW_RESET_MODULE:
|
||||
case RECOVERY_TARGET_SW_RESET_MODULE:
|
||||
case RECOVERY_TARGET_FACTORY_RESET:
|
||||
// 需要通过 AT 命令执行,进入 BLE_SET 状态
|
||||
// 注意:origin_state 保持不变,BLE_SET 执行完后会返回它
|
||||
|
|
@ -338,6 +325,7 @@ void BLE_StateMachine_Handler(void)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
recovery_level = 0;
|
||||
curr_state = g_ble_error.origin_state;
|
||||
break;
|
||||
|
||||
|
|
@ -354,10 +342,10 @@ void BLE_StateMachine_Handler(void)
|
|||
curr_state = BLE_WAITTING;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case BLE_SET :
|
||||
|
|
@ -378,7 +366,7 @@ void BLE_StateMachine_Handler(void)
|
|||
}
|
||||
break;
|
||||
case RECOVERY_TARGET_FACTORY_RESET:
|
||||
//回复出厂设置
|
||||
{ //回复出厂设置
|
||||
{
|
||||
static const BleAtCmd_t factory_reset_seq[] = {
|
||||
{"AT+DEFAULT\r\n", "OK", 100, 3, NULL, NULL},
|
||||
|
|
@ -388,6 +376,7 @@ void BLE_StateMachine_Handler(void)
|
|||
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//没有匹配目标则返回原状态
|
||||
curr_state = g_ble_error.origin_state;
|
||||
|
|
@ -419,7 +408,7 @@ void BLE_StateMachine_Handler(void)
|
|||
// 请根据实际情况调整。下面假设有一个全局变量 uint8_t g_recovery_level; 并在 BLE_ERROR 中改为使用它。
|
||||
// 如果没有,你可以将 recovery_level 定义在文件作用域(static),然后在 BLE_SET 中包含一个 extern 声明。
|
||||
// 这里我们暂时注释掉,你需要根据你的设计实现。
|
||||
// g_recovery_level = 0; // 如果使用全局变量
|
||||
recovery_level = 0;
|
||||
|
||||
memset(&set_executor, 0, sizeof(set_executor));
|
||||
curr_state = g_ble_error.origin_state;
|
||||
|
|
@ -438,12 +427,9 @@ void BLE_StateMachine_Handler(void)
|
|||
}
|
||||
// 若返回 BUSY,则继续等待,不做状态切换
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case BLE_WAITTING:
|
||||
|
|
@ -474,7 +460,7 @@ void BLE_StateMachine_Handler(void)
|
|||
}
|
||||
|
||||
|
||||
ExecutorResult_t CmdExecutor_Process(CmdExecutor_t* ex)
|
||||
ExecutorResult_t CmdExecutor_Process(CmdExecutor_t* ex) //发送流程执行器
|
||||
{
|
||||
switch(ex->state)
|
||||
{
|
||||
|
|
@ -512,8 +498,6 @@ ExecutorResult_t CmdExecutor_Process(CmdExecutor_t* ex)
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue