SDKJava (Android) SDK

Debug 日志

Android Java SDK:Debug 日志

当前版本 · 2.0.0

Debug 日志

在构造 SDK 前通过 SdkConfig.builder().debug(...) 选择调试模块和记录细节。先用概要信息定位连接或设备问题,需要更多数据时再提高细节。

import android.content.Context;
import com.qnbot.sdk.Sdk;
import com.qnbot.sdk.SdkConfig;
import com.qnbot.sdk.android.SerialTransport;
import com.qnbot.sdk.config.DebugConfig;
import com.qnbot.sdk.config.DebugDetail;
import com.qnbot.sdk.config.DebugModule;
import com.qnbot.sdk.config.DeviceSelector;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.config.TargetAlgorithm;
import com.qnbot.sdk.config.TargetConfig;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveConfig;
import com.qnbot.sdk.glove.GloveDevice;

/**
 * Streams retargeted output with sampled debug tracing enabled.
 *
 * <p>Pass the host {@link Context}, an authorized transport, the glove port and side, the installed
 * algorithm package, and the debug detail/rate. SDK logs are written under the SDK data root; the
 * target subscription prints each command.
 */
public final class DebugTrace {
  private DebugTrace() {}

  public static void run(Context context, SerialTransport transport, String port, Side side,
      String packageId, int sampleRate, DebugDetail detail) {
    SdkConfig config = SdkConfig.builder()
        .device(GloveConfig.builder()
                    .name("primary")
                    .side(side)
                    .connection(SerialConnection.port(port))
                    .build())
        .target(TargetConfig.builder()
                    .name("openxr_hand")
                    .side(side)
                    .source(new DeviceSelector("glove", "primary", side))
                    .algorithm(new TargetAlgorithm(packageId))
                    .build())
        .debug(DebugConfig.builder()
                   .modules(DebugModule.values())
                   .detail(detail)
                   .sampleRate(sampleRate)
                   .build())
        .build();
    try (Sdk sdk = new Sdk(config, context, transport); Glove glove = sdk.glove()) {
      GloveDevice device = glove.device();
      device.output("openxr_hand")
          .subscribe(sample
              -> System.out.println("retargeting sequence=" + sample.sequence
                  + " target=" + sample.value.target + " joints=" + sample.value.joints));
      glove.start();
      glove.runForever();
    }
  }
}

DebugTrace.run(...) 启用 DebugModule.values() 中的全部模块,用调用方给定的 DebugDetail 和采样率记录诊断,同时订阅目标输出。sampleRate 控制调试采样,不是设备或订阅频率。支持的模块包括 TRANSPORT、DEVICE、CAPTURE、CALIBRATION、RETARGETING、OUTPUT,细节为 SUMMARY 或 FULL;业务 app 可以只选择当前排查所需的模块。

同时记录 sdk.health() 或 device.health(),并保留问题时段的 app 日志。避免在每条高频回调中输出完整数据。

SDK 更新提示

启用检查的 Stable 和 RC Android 交付在首次启动 Glove 或 Exo 时,通过 OTA 检查对应组件是否有较新的稳定版本。Dev 版跳过检查;SDK 不提供 Core 独立升级提示。查看交付记录中的 update_checks_enabled。

用下面的命令查看 INFO 提示:

adb logcat -s qnbot-sdk:I

有适用更新时,update_available 行包含组件、当前版本、可用版本和 HTTPS 升级来源。SDK 不自动下载安装;按交付指南升级完整 Maven 依赖。

每次首次组件启动共用最多一秒检查预算;同一实例重复启停不会重复检查。离线、超时、坏响应或没有更新时不显示提示,原有连接和采集继续。在工作线程执行启动,并把这段有界等待计入 app 启动预算。

普通源码构建默认关闭检查;构建时可用 --enable-update-checks 启用。OTA 目录不可用或内容无效时,运行时静默跳过提示,不阻断构建。启用开关不证明已取得正式交付;app 使用实际配套交付记录中的版本和配置。