CONFIGMODEL_ITEM_CAT1_IMEI, //Cat1 imei
CONFIGMODEL_ITEM_CAT1_MODEMVER, //Cat1 modem version
CONFIGMODEL_ITEM_CAT1_PYVER, //Cat1 Python app version
+ CONFIGMODEL_ITEM_PPP_BAUDRATE, //PPP 波特率
CONFIGMODEL_ITEM_LANGUAGE_ID, //语言ID int id
CONFIGMODEL_ITEM_LANGUAGE_CODE, //语言Code string "zh","en"
CONFIGMODEL_ITEM_TIMEZONE, //单位刻钟 默认+8 小时 = 8*4 = 32 刻钟
{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", "115200" },//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 刻钟
bool cm_getisFirstTimeStart(void);
+
+
+/* PPP 波特率 */
+void set_ppp_baudrate_from_config_model(uint32_t value);
+/* PPP 波特率 */
+uint32_t get_ppp_baudrate_from_config_model(void);
+
+
+
+
#ifdef __cplusplus
#if __cplusplus
}
OHOS::ConfigModel::GetInstance()->set_condigData_Bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_HFP,value);
}
- void cm_set_A2DP_switch(bool value)
+void cm_set_A2DP_switch(bool value)
{
OHOS::ConfigModel::GetInstance()->set_condigData_Bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_A2DP,value);
}
{
return OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SAVE_RUNTIMR_LOG_STATUS);
}
+
+void set_ppp_baudrate_from_config_model(uint32_t value)
+{
+ OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_PPP_BAUDRATE,value);
+}
+
+uint32_t get_ppp_baudrate_from_config_model(void)
+{
+ return OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_PPP_BAUDRATE);
+}
+
#ifdef __cplusplus
#if __cplusplus
}
#include "zhihui_tcp_test.h"
#include "ppp_example.h"
#include "uart.h"
+#include "ConfigModelC.h"
return ERRCODE_SUCC;
}
+/**
+ * @brief AT^PPPSETBAUD - 设置PPP波特率到配置模型
+ * @param para 参数: 波特率值
+ * @param paraLen 参数长度
+ */
+static errcode_t at_ppp_set_config_baudrate(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+ UNUSED(strCommonCmd);
+
+ if (!para || paraLen == 0) {
+ ppp_print_err("PPP SET BAUDRATE: Missing baudrate parameter\n");
+ return ERRCODE_FAIL;
+ }
+
+ uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
+ uint32_t argc = 0;
+
+ int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+ if (ret != CUSTOM_UTILS_SUCCESS || argc != 1) {
+ ppp_print_err("PPP SET BAUDRATE: Invalid parameter format, usage: AT^PPPSETBAUD=baudrate\n");
+ return ERRCODE_FAIL;
+ }
+
+ uint32_t baudrate = atoi((char*)argv[0]);
+
+ // 检查波特率是否为支持的值
+ if (baudrate != 9600 && baudrate != 19200 && baudrate != 38400 &&
+ baudrate != 57600 && baudrate != 115200 && baudrate != 230400 &&
+ baudrate != 460800 && baudrate != 921600 && baudrate != 1000000 && baudrate != 2000000) {
+ ppp_print_err("PPP SET BAUDRATE: Invalid baudrate %d\n", baudrate);
+ ppp_print_err("PPP SET BAUDRATE: Supported values: 9600,19200,38400,57600,115200,230400,460800,921600,1000000,2000000\n");
+ return ERRCODE_FAIL;
+ }
+
+ // 获取当前配置的波特率
+ uint32_t current_baudrate = get_ppp_baudrate_from_config_model();
+
+ if (current_baudrate == baudrate) {
+ ppp_print_info("PPP SET BAUDRATE: Baudrate already set to %d, no change needed\n", baudrate);
+ return ERRCODE_SUCC;
+ }
+
+ // 设置新的波特率到配置模型
+ set_ppp_baudrate_from_config_model(baudrate);
+
+ 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);
+ ppp_print_info("PPP SET BAUDRATE: Successfully set PPP baudrate to %d, ret: %d\n ", baudrate,rett);
+ return ERRCODE_SUCC;
+}
+
+/**
+ * @brief AT^PPPGETBAUD - 获取PPP波特率配置
+ */
+static errcode_t at_ppp_get_config_baudrate(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+ UNUSED(para);
+ UNUSED(paraLen);
+ UNUSED(strCommonCmd);
+
+ uint32_t config_baudrate = get_ppp_baudrate_from_config_model();
+ uint32_t current_baudrate = ppp_at_get_current_baudrate();
+
+ ppp_print_info("PPP GET BAUDRATE: Config model baudrate: %d\n", config_baudrate);
+ ppp_print_info("PPP GET BAUDRATE: Current runtime baudrate: %d\n", current_baudrate);
+
+ if (config_baudrate != current_baudrate) {
+ ppp_print_warning("PPP GET BAUDRATE: Warning - Config and runtime baudrates differ!\n");
+ ppp_print_warning("PPP GET BAUDRATE: Consider restarting PPP module to sync baudrates\n");
+ } else {
+ ppp_print_info("PPP GET BAUDRATE: Config and runtime baudrates are synchronized\n");
+ }
+
+ return ERRCODE_SUCC;
+}
+
static const at_cmd_table_t g_ppp_cmd[] = {
{ (char *)"AT^CAT1POWER", cat1_power, (char *)"1" },
{ (char *)"AT^CAT1GETSIGNAL", at_cat1_getsignal, (char *)"1" },
{ (char *)"AT^DEMOTEST", at_demo_serial_test, (char *)"[interval_ms],[duration_sec],[baudrate]" },
{ (char *)"AT^DEMOSTOP", at_demo_test_stop, (char *)" " },
{ (char *)"AT^DEMOSTATS", at_demo_test_stats, (char *)" " },
+ /* PPP配置模型波特率管理指令 */
+ { (char *)"AT^PPPSETBAUD", at_ppp_set_config_baudrate, (char *)"baudrate" },
+ { (char *)"AT^PPPGETBAUD", at_ppp_get_config_baudrate, (char *)" " },
};
at_cmd_table_t *get_ppp_cmd_table(uint32_t *cmd_count)
static bool g_ppp_connected = false;
static osal_task *g_monitor_task = NULL;
static bool g_ppp_env_initialized = false;
-
+static uint32_t g_ppp_baudrate = PPP_UART_BAUDRATE;
/**
* @brief PPP环境初始化
* @return 0成功,-1失败
.apn = "CMIOTZSZCGRE.GD", // 中国移动APN cmnet
.username = "", // 用户名(通常为空)
.password = "", // 密码(通常为空)
- .baudrate = PPP_UART_BAUDRATE, // 2M波特率
+ .baudrate = g_ppp_baudrate, // 2M波特率
.auto_baudrate = true, // 启用自动波特率检测
.dial_timeout = 30000, // 30秒拨号超时
.retry_count = 3 // 重试3次
}
-
+uint32_t get_ppp_baudrate(void)
+{
+ return g_ppp_baudrate;
+}
+void set_ppp_baudrate(uint32_t value)
+{
+ g_ppp_baudrate = value;
+}
int ppp_env_init_monitor_task(void)
{
/* 4. 创建网络监控任务 */
#define SIO_UART_IRQ_NUM UART_0_IRQN // UART IRQ引脚
#endif
-#define PPP_UART_BAUDRATE 2000000
+#define PPP_UART_BAUDRATE 115200
/* 支持的波特率列表(自适应模式) */
#define PPP_BAUDRATE_AUTO_LIST {9600, 57600, 115200}
*/
int ppp_env_init_monitor_task(void);
+/**
+ * @brief 获取PPP波特率
+ *
+ * @return 波特率
+ */
+uint32_t get_ppp_baudrate(void);
+
+/**
+ * @brief 设置PPP波特率
+ *
+ * @param value 波特率
+ */
+void set_ppp_baudrate(uint32_t value);
+
#ifdef __cplusplus
}
bool initialized;
uint8_t uart_bus;
uint32_t current_baudrate;
+ uint32_t target_baudrate;
bool auto_baudrate_mode;
ppp_at_response_t last_response;
osal_mutex at_mutex; // 改为结构体,不是指针
return PPP_ERR_INVALID_PARAM;
}
- PPP_DEBUG_INFO("Starting baudrate handshake (prove 1000000 not working, then try auto handshake)");
+ PPP_DEBUG_INFO("Starting baudrate handshake (prove %d not working, then try auto handshake)",g_at_ctx.current_baudrate);
- // 1. 先reset模组,证明1000000没有正常工作
- PPP_DEBUG_DEBUG("Resetting module to prove 1000000 baudrate is not working...");
- ppp_power_reset_cat1();
- osal_msleep(5000);
+ // uint8_t dummy_buffer[256]={0};
// 2. 依次尝试自动波特率列表
for (int i = 0; i < PPP_BAUDRATE_AUTO_COUNT; i++) {
PPP_DEBUG_DEBUG("UART configured for baudrate %u", baudrate);
// 清空接收缓冲区
- PPP_DEBUG_DEBUG("Clearing UART RX buffer before AT test...");
- uint8_t dummy_buffer[256];
- int clear_cnt = 0;
- while (uapi_uart_read(g_at_ctx.uart_bus, dummy_buffer, sizeof(dummy_buffer), 100) > 0) {
- clear_cnt++;
- }
- if (clear_cnt > 0) {
- PPP_DEBUG_DEBUG("Cleared %d RX buffer rounds", clear_cnt);
- }
+ // PPP_DEBUG_DEBUG("Clearing UART RX buffer before AT test...");
+ // int clear_cnt = 0;
+ // memset(dummy_buffer,0,sizeof(dummy_buffer));
+ // while (uapi_uart_read(g_at_ctx.uart_bus, dummy_buffer, sizeof(dummy_buffer), 100) > 0) {
+ // clear_cnt++;
+ // }
+ // if (clear_cnt > 0) {
+ // PPP_DEBUG_DEBUG("Cleared %d RX buffer rounds", clear_cnt);
+ // }
// 3次重试AT
ppp_error_t ret = PPP_ERR_AT_FAILED;
PPP_DEBUG_DEBUG("--- AT Test at %u baud, retry %d/3 ---", baudrate, retry + 1);
// 再次清空缓冲区,防止上次残留
- while (uapi_uart_read(g_at_ctx.uart_bus, dummy_buffer, sizeof(dummy_buffer), 100) > 0) {}
+ // memset(dummy_buffer,0,sizeof(dummy_buffer));
+ // while (uapi_uart_read(g_at_ctx.uart_bus, dummy_buffer, sizeof(dummy_buffer), 100) > 0) {}
ppp_at_response_t response;
ret = ppp_at_send_command("AT", "OK", 1000, &response);
PPP_DEBUG_INFO("AT command successful at baudrate %u", baudrate);
// 在当前波特率下,设置AT+IPR=1000000
- ppp_at_set_baudrate(PPP_UART_BAUDRATE);
- ppp_at_set_baudrate(PPP_UART_BAUDRATE);
-
+ ret = ppp_at_set_baudrate(g_at_ctx.current_baudrate);
+ if (ret != PPP_ERR_OK) {
+ ret = ppp_at_set_baudrate(g_at_ctx.current_baudrate);
+ if (ret != PPP_ERR_OK) {
+ PPP_DEBUG_ERROR("Failed to set baudrate %u", g_at_ctx.current_baudrate);
+ return ret;
+ }
+ }
// 再次reset模组,让其自动工作在1000000波特率下
- PPP_DEBUG_DEBUG("Resetting module again to switch to baudrate %d...",PPP_UART_BAUDRATE);
- ppp_power_reset_cat1();
- osal_msleep(5000);
+ PPP_DEBUG_DEBUG("Resetting module again to switch to baudrate %d...",g_at_ctx.current_baudrate);
+ // ppp_power_reset_cat1();
+ // osal_msleep(5000);
ret = ppp_at_send_command("AT", "OK", 1000, &response);
if(ret != PPP_ERR_OK) {
- PPP_DEBUG_INFO("Baudrate handshake failed, now at %d baud",PPP_UART_BAUDRATE);
+ PPP_DEBUG_INFO("Baudrate handshake failed, now at %d baud",g_at_ctx.current_baudrate);
}else{
- PPP_DEBUG_INFO("Baudrate handshake successful, now at %d baud",PPP_UART_BAUDRATE);
+ PPP_DEBUG_INFO("Baudrate handshake successful, now at %d baud",g_at_ctx.current_baudrate);
}
return PPP_ERR_OK;
} else {
uint32_t current_time = tcp_test_get_time_ms();
// 检查是否可以发送
- bool can_send = (send_interval_ms == 0) ||
- (current_time - last_send_time >= send_interval_ms);
+ bool can_send = true;// (send_interval_ms == 0) || (current_time - last_send_time >= send_interval_ms);
if (can_send) {
// 生成固定模式数据
conn->last_activity_time = tcp_test_get_time_ms();
// 短暂延迟避免CPU占用过高
- TCP_SLEEP_MS(send_interval_ms > 0 ? 1 : 0);
+ // TCP_SLEEP_MS(send_interval_ms > 0 ? 1 : 0);
+ TCP_SLEEP_MS(send_interval_ms );
}
free(send_buffer);
conn->last_activity_time = tcp_test_get_time_ms();
// 短暂延迟
- TCP_SLEEP_MS(1);
+ TCP_SLEEP_MS(20);
}
// 处理剩余不完整数据
#ifdef SUPPORT_PPP_SERVICE
+ uint32_t baudrate = get_ppp_baudrate_from_config_model();
+ if(baudrate != 0)
+ set_ppp_baudrate(baudrate);
ppp_env_init();
#endif