{ConfigDataType::DATATYPE_STRING, "cat1_imei", "pls poweron 4G first" },//CONFIGMODEL_ITEM_CAT1_IMEI,
{ConfigDataType::DATATYPE_STRING, "cat1_modemver", "pls poweron 4G first" },//CONFIGMODEL_ITEM_CAT1_MODEMVER,
{ConfigDataType::DATATYPE_STRING, "cat1_pyver", "pls poweron 4G first" },//CONFIGMODEL_ITEM_CAT1_PYVER,
- {ConfigDataType::DATATYPE_INT, "ppp_baudrate", "1000000" },//CONFIGMODEL_ITEM_PPP_BAUDRATE,
+ {ConfigDataType::DATATYPE_INT, "ppp_baudrate", "2000000" },//CONFIGMODEL_ITEM_PPP_BAUDRATE,
{ConfigDataType::DATATYPE_INT, "language_id", "0" },//CONFIGMODEL_ITEM_LANGUAGE_ID, //默认选择中文
{ConfigDataType::DATATYPE_STRING, "language_code", "zh" },//CONFIGMODEL_ITEM_LANGUAGE_CODE, //默认没有选择语言
{ConfigDataType::DATATYPE_INT, "timezone", "32" },//CONFIGMODEL_ITEM_TIMEZONE, //单位刻钟 默认+8 小时 = 4*8 = 32 刻钟
ppp_print_info("PPP SET BAUDRATE: Successfully set PPP baudrate from %d to %d in config model\n",
current_baudrate, baudrate);
ppp_print_info("PPP SET BAUDRATE: Note: This change will take effect after PPP module restart\n");
- errcode_t rett = ppp_at_set_baudrate(baudrate);
+ errcode_t rett = ppp_api_set_baudrate_in_all_mode(baudrate);
ppp_print_info("PPP SET BAUDRATE: Successfully set PPP baudrate to %d, ret: %d\n ", baudrate,rett);
return ERRCODE_SUCC;
}
return ERRCODE_SUCC;
}
+errcode_t ppp_api_set_baudrate_in_all_mode(uint32_t baudrate)
+{
+ errcode_t ret = ERRCODE_SUCC;
+ uint8_t need_resume = 0;
+ uint8_t need_deinit_at = 0;
+
+ // 1. 如果在 PPP 模式,先暂停
+ if(ppp_serial_get_mode() == PPP_SERIAL_MODE_PPP_DATA) {
+ PPP_DEBUG_INFO("In PPP mode, pausing...");
+ if (ppp_ppp_mode_pause() != ERRCODE_SUCC) {
+ PPP_DEBUG_ERROR("Failed to pause PPP mode");
+ return ERRCODE_FAIL;
+ }
+ need_resume = 1;
+
+ // 2. 暂停后需要初始化 AT handler 才能执行 AT 命令
+ PPP_DEBUG_INFO("Initializing AT handler for command execution...");
+ ppp_error_t at_ret = ppp_at_handler_init(SIO_UART_BUS, g_ppp_config.baudrate, true);
+ if (at_ret != PPP_ERR_OK) {
+ PPP_DEBUG_ERROR("Failed to initialize AT handler: %d", at_ret);
+ // 尝试恢复 PPP 模式
+ ppp_ppp_mode_resume();
+ return ERRCODE_FAIL;
+ }
+ need_deinit_at = 1;
+ } else {
+ PPP_DEBUG_INFO("Already in AT mode");
+ need_resume = 0;
+ need_deinit_at = 0;
+ }
+
+ // 3. 执行 AT 命令更新信息
+ PPP_DEBUG_CRITICAL("Starting baudrate set... %u",baudrate);
+ if(ppp_at_set_baudrate(baudrate) != ERRCODE_SUCC) {
+ PPP_DEBUG_ERROR("Failed to set baudrate");
+ ret = ERRCODE_FAIL;
+ }
+
+ // 4. 如果需要,去初始化 AT handler 并恢复 PPP 模式
+ if (need_resume) {
+ // 先去初始化 AT handler
+ if (need_deinit_at) {
+ PPP_DEBUG_INFO("Deinitializing AT handler...");
+ ppp_at_handler_deinit();
+ }
+
+ // 然后恢复 PPP 模式
+ PPP_DEBUG_INFO("Resuming PPP mode...");
+ errcode_t resume_ret = ppp_ppp_mode_resume();
+ if (resume_ret != ERRCODE_SUCC) {
+ PPP_DEBUG_ERROR("Failed to resume PPP mode: %d", resume_ret);
+ PPP_DEBUG_ERROR("Forcing PPP mode recovery...");
+
+ // 强制恢复到 PPP 模式
+ ppp_serial_switch_to_ppp_mode();
+
+ #if PPP_USE_INTERRUPT_MODE
+ ppp_error_t int_ret = ppp_interrupt_enable();
+ if (int_ret != PPP_ERR_OK) {
+ PPP_DEBUG_ERROR("Failed to enable interrupt after forced recovery: %d", int_ret);
+ } else {
+ PPP_DEBUG_INFO("PPP interrupt mode re-enabled after forced recovery");
+ }
+ #else
+ ppp_error_t thread_ret = ppp_lwip_start_receive_thread();
+ if (thread_ret != PPP_ERR_OK) {
+ PPP_DEBUG_ERROR("Failed to start receive thread after forced recovery: %d", thread_ret);
+ } else {
+ PPP_DEBUG_INFO("PPP receive thread restarted after forced recovery");
+ }
+ #endif
+
+ PPP_DEBUG_WARN("PPP mode forcefully recovered, but connection may be unstable");
+ ret = ERRCODE_FAIL;
+ }
+ }
+
+ return ret;
+}
+
errcode_t ppp_api_update_netinfo_in_all_mode(void)
{
errcode_t ret = ERRCODE_SUCC;