Skip to content

调试工具

Android SDK 的 DebugModule 调试工具说明。

功能概览

DebugModule 提供丰富的调试和测试功能:

功能Fragment说明
命令测试DebugCmdFragment发送各种命令
消息发送DebugCmdSendMsgFragment发送通知消息
音频采集DebugAudioGatherFragment录制音频数据
PCM 流DebugPCMFragmentPCM 音频播放
显示控制DebugDisplayFragment屏幕显示测试
日志查看DebugLogFragment查看设备日志
固件升级DebugLocalUpdateActivityOTA 更新
佩戴数据DebugWearingDataActivityIMU 传感器

启动调试界面

kotlin
// 从 MainActivity 跳转
val intent = Intent(this, DebugActivity::class.java)
startActivity(intent)

命令测试

DebugCmdFragment

测试发送各种命令到设备:

kotlin
// 测试获取电池
btnGetBattery.setOnClickListener {
    DeviceManager.getInstance().sendCmd(CmdReqGetBattery())
}

// 测试设置亮度
btnSetBrightness.setOnClickListener {
    val brightness = seekBar.progress
    DeviceManager.getInstance().sendCmd(
        CmdReqSetBrightness().apply {
            this.brightness = brightness
        }
    )
}

音频采集

DebugAudioGatherFragment

从设备采集 PCM 音频数据:

kotlin
// 开始采集
btnStartGather.setOnClickListener {
    AudioGatherManager.getInstance().startGather()
}

// 停止采集
btnStopGather.setOnClickListener {
    AudioGatherManager.getInstance().stopGather()
}

// 音频数据回调
AudioGatherManager.getInstance().setCallback { pcmData ->
    // 处理 PCM 数据
    saveToFile(pcmData)
}

PCM 播放

PCMAudioPlayer

播放接收到的 PCM 音频:

java
// PCMAudioPlayer.java
public class PCMAudioPlayer {
    public void start();
    public void write(byte[] data);
    public void stop();
    public void release();
}

使用示例:

kotlin
val player = PCMAudioPlayer()
player.start()

// 接收数据时播放
onPcmDataReceived { data ->
    player.write(data)
}

// 停止播放
player.stop()
player.release()

日志查看

DebugLogFragment

查看和导出设备日志:

kotlin
// 获取日志
btnFetchLog.setOnClickListener {
    DeviceManager.getInstance().sendCmd(CmdReqGetLog())
}

// 导出日志
btnExportLog.setOnClickListener {
    val logContent = logTextView.text.toString()
    saveLogToFile(logContent)
}

固件升级

DebugLocalUpdateActivity

本地 OTA 升级:

kotlin
// 选择固件文件
btnSelectFirmware.setOnClickListener {
    openFilePicker()
}

// 开始升级
btnStartUpdate.setOnClickListener {
    val firmwarePath = selectedFile.path
    OTAManager.getInstance().startUpdate(firmwarePath) { progress ->
        progressBar.progress = progress
    }
}

传感器数据

DebugWearingDataActivity

查看 IMU 和佩戴传感器数据:

kotlin
// 开始监听
MetaGlassDeviceGlobal.addSensorDataListener { data ->
    tvAccel.text = "加速度: ${data.accelX}, ${data.accelY}, ${data.accelZ}"
    tvGyro.text = "陀螺仪: ${data.gyroX}, ${data.gyroY}, ${data.gyroZ}"
    tvWearing.text = "佩戴状态: ${if (data.isWearing) "已佩戴" else "未佩戴"}"
}

导航配置

DebugModule 使用 Navigation Component:

xml
<!-- res/navigation/debug_nav_graph.xml -->
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:startDestination="@id/debugMainFragment">

    <fragment
        android:id="@+id/debugMainFragment"
        android:name=".fragment.DebugMainFragment">
        <action
            android:id="@+id/action_to_cmd"
            app:destination="@id/debugCmdFragment" />
    </fragment>

    <fragment
        android:id="@+id/debugCmdFragment"
        android:name=".fragment.DebugCmdFragment" />

    <!-- 更多 Fragment -->
</navigation>

依赖

kotlin
// DebugModule/build.gradle.kts
dependencies {
    implementation(project(":BluetoothModule"))
    implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
    implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
    implementation("com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.11")
}

Mooting 开发者文档