From: Caisking Date: Sat, 27 Sep 2025 09:40:13 +0000 (+0800) Subject: 增加ping外网的at指令 X-Git-Tag: V1.0.9_20251128_194606_LN~294^2~10^2~2 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=d5e82e53a5abc804dbf7ff8c212746364f8fcd9c;p=mirrors%2FFD230.git 增加ping外网的at指令 --- diff --git a/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c b/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c index bcc7c7139..079c0c9b3 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c @@ -57,6 +57,10 @@ static uint32_t ln_switch_expression_at(uint8_t *para, uint32_t paraLen, char *s static uint32_t ln_set_fps_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd); static uint32_t ln_get_fps_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd); +//网络检测相关AT命令函数声明 +static uint32_t ln_check_internet_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd); +static uint32_t ln_check_dns_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd); + /* 内存查看辅助函数 - 使用MemoryManager接口 */ /* 将 PCM 文件按 10ms(160点) 分帧喂给 VAD 并打印结果 */ @@ -1692,6 +1696,73 @@ static uint32_t ln_switch_expression_at(uint8_t *para, uint32_t paraLen, char *s } } +/* AT^LN_CHECK_INTERNET - 检测是否有外网连接 */ +static uint32_t ln_check_internet_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + VAD_UNUSED(para); + VAD_UNUSED(paraLen); + VAD_UNUSED(strCommonCmd); + + printf("[LN][CHECK_INTERNET] Checking internet connection...\n"); + + // 调用C接口检测网络连接 + int result = check_internet_connection(); + + if (result == 1) { + printf("[LN][CHECK_INTERNET] Internet connection: AVAILABLE\n"); + printf("+LN_CHECK_INTERNET: OK\n"); + } else if (result == 0) { + printf("[LN][CHECK_INTERNET] Internet connection: NOT AVAILABLE\n"); + printf("+LN_CHECK_INTERNET: NO_CONNECTION\n"); + } else { + printf("[LN][CHECK_INTERNET] Internet connection: CHECK_FAILED\n"); + printf("+LN_CHECK_INTERNET: ERROR\n"); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +/* AT^LN_CHECK_DNS - 检测DNS解析 */ +static uint32_t ln_check_dns_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + VAD_UNUSED(strCommonCmd); + + const char *hostname = "www.baidu.com"; // 默认测试主机 + + // 解析参数 + if (para != NULL && paraLen > 0) { + char hostname_str[256] = {0}; + if (paraLen >= sizeof(hostname_str)) { + printf("[LN][CHECK_DNS] Error: Hostname too long (max 255 characters)\n"); + return ERRCODE_FAIL; + } + + memcpy(hostname_str, para, paraLen); + hostname_str[paraLen] = '\0'; + hostname = hostname_str; + } + + printf("[LN][CHECK_DNS] Checking DNS resolution for: %s\n", hostname); + + // 调用C接口检测DNS解析 + int result = check_dns_resolution(hostname); + + if (result == 1) { + printf("[LN][CHECK_DNS] DNS resolution: SUCCESS\n"); + printf("+LN_CHECK_DNS: OK\n"); + } else if (result == 0) { + printf("[LN][CHECK_DNS] DNS resolution: FAILED\n"); + printf("+LN_CHECK_DNS: FAIL\n"); + } else { + printf("[LN][CHECK_DNS] DNS resolution: ERROR\n"); + printf("+LN_CHECK_DNS: ERROR\n"); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + static const at_cmd_table_t g_ln_api_cmd[] = { /* ----------------------------------- VAD ---------------------------------- */ {(char *)"AT^VAD_INIT", vad_init, (char *)"初始化 VAD"}, @@ -1769,6 +1840,10 @@ static const at_cmd_table_t g_ln_api_cmd[] = { //帧率控制 {(char *)"AT^LN_SET_FPS", ln_set_fps_at, (char *)"设置帧率: AT^LN_SET_FPS="}, {(char *)"AT^LN_GET_FPS", ln_get_fps_at, (char *)"获取当前帧率: AT^LN_GET_FPS"}, + + //网络检测 + {(char *)"AT^LN_CHECK_INTERNET", ln_check_internet_at, (char *)"检测外网连接: AT^LN_CHECK_INTERNET"}, + {(char *)"AT^LN_CHECK_DNS", ln_check_dns_at, (char *)"检测DNS解析: AT^LN_CHECK_DNS[=hostname]"}, }; diff --git a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp index d5c1b45f4..3e2ed8065 100644 --- a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp +++ b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp @@ -7,6 +7,12 @@ #include #include +// 前向声明网络检测函数,避免循环依赖 +extern "C" { + int uapi_ln_check_internet_connection(void); + int uapi_ln_check_dns_resolution(const char *hostname); +} + #ifdef __cplusplus extern "C" { @@ -199,6 +205,19 @@ bool switch_expression_video(const char *video_path) return result; } + +// 检测是否有外网连接 +int check_internet_connection(void) +{ + return uapi_ln_check_internet_connection(); +} + +// 检测DNS解析是否正常 +int check_dns_resolution(const char *hostname) +{ + return uapi_ln_check_dns_resolution(hostname); +} + #ifdef __cplusplus }; #endif \ No newline at end of file diff --git a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h index 667f446d3..c2a10fd70 100644 --- a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h +++ b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h @@ -80,6 +80,10 @@ void push_chat_stamina_notification(int chatLeft, // 切换表情视频 bool switch_expression_video(const char *video_path); +// 网络连接检测 +int check_internet_connection(void); +int check_dns_resolution(const char *hostname); + #ifdef __cplusplus } #endif