You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Amlogic MBOX通过HDMI CEC命令无法关闭三星TV

问题:Android应用通过HDMI CEC协议控制三星TV关机失败(基于Amlogic MBOX)

当前状态

  • 三星TV已开启HDMI CEC功能
  • Amlogic MBOX已开启HDMI CEC功能
  • 设备已获取Root权限,尝试过常见CEC相关解决方案但无效

相关代码实现

执行Root命令的工具函数

fun sudoForResult(vararg strings: String): String? {
    Log.e("TAG", "sudoForResult: executing ")
    var res: String? = ""
    var outputStream: DataOutputStream? = null
    var response: InputStream? = null
    try {
        val su = Runtime.getRuntime().exec("su")
        outputStream = DataOutputStream(su.outputStream)
        response = su.inputStream
        for (s in strings) {
            outputStream.writeBytes("$s\n")
            outputStream.flush()
        }
        outputStream.writeBytes("exit\n")
        outputStream.flush()
        try {
            su.waitFor()
        } catch (e: InterruptedException) {
            e.printStackTrace()
        }
        res = readFully(response)
    } catch (e: IOException) {
        e.printStackTrace()
    } finally {
        outputStream?.close()
        response?.close()
    }
    Log.e("TAG", "sudoForResult: op = \n$res")
    return res
}

已生效的CEC开启命令

sudoForResult(
    "settings put global hdmi_control_enabled 1",
    "settings put global hdmi_control_auto_wakeup_enabled 1",
    "settings put global hdmi_control_auto_device_off_enabled 1"
)

无效的TV关机命令

sudoForResult("echo 0x40 0x36 > /sys/class/cec/cmd")
sudoForResult("echo 0xF0 0x36 > /sys/class/cec/cmd")

排查命令及日志输出

命令1:查询CEC设备基础信息

sudoForResult(
    "ls -l /dev/cec",
    "ls -l /sys/class/cec/",
    "cat /sys/class/cec/physical_addr",
    "cat /sys/class/cec/device_type",
    "cat /sys/class/cec/vendor_id"
)

日志输出:

crw-rw-rw- 1 root root 217   0 2023-07-07 09:05 /dev/cec 
total 0
-r--r--r-- 1 root root 4096 2023-07-07 09:14 arc_port
lrwxrwxrwx 1 root root    0 2023-07-07 09:14 cec -> ../../devices/aocec/cec
-r--r--r-- 1 root root 4096 2023-07-07 09:14 cec_version
--w------- 1 root root 4096 2023-07-07 09:19 cmd
-rw-rw-r-- 1 root root 4096 2023-07-07 09:14 dbg_en
-rw-rw-r-- 1 root root 4096 2023-07-07 09:14 device_type
-r--r--r-- 1 root root 4096 2023-07-07 09:14 dump_reg
-rw-rw-r-- 1 root root 4096 2023-07-07 09:14 fun_cfg
-rw-rw-r-- 1 root root 4096 2023-07-07 09:14 menu_language
-r--r--r-- 1 root root 4096 2023-07-07 09:14 osd_name
-rw-rw-r-- 1 root root 4096 2023-07-07 09:14 physical_addr
-r--r--r-- 1 root root 4096 2023-07-07 09:14 pin_status
-r--r--r-- 1 root root 4096 2023-07-07 09:14 port_num
-rw-rw-r-- 1 root root 4096 2023-07-07 09:14 port_seq
-r--r--r-- 1 root root 4096 2023-07-07 09:14 port_status
-rw-rw-r-- 1 root root 4096 2023-07-07 09:14 vendor_id
-r--r--r-- 1 root root 4096 2023-07-07 09:14 wake_up
1000
4
0

命令2:发送关机指令并查看寄存器状态

sudoForResult("echo 0xF0 0x36 > /sys/class/cec/cmd && sleep 0.1 && cat /sys/class/cec/dump_reg")

日志输出:

TX buffer:
0: 0
1: 0
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 0
9: 0
10: 0
11: 0
12: 0
13: 0
14: 0
15: 0
CEC_TX_MSG_LENGTH: 0
CEC_TX_MSG_CMD: 0
CEC_TX_WRITE_BUF: 0
CEC_TX_CLEAR_BUF: 0
CEC_RX_MSG_CMD: 0
CEC_RX_CLEAR_BUF: 0
CEC_LOGICAL_ADDR0:14
CEC_LOGICAL_ADDR1: 0
CEC_LOGICAL_ADDR2: 0
CEC_LOGICAL_ADDR3: 0
CEC_LOGICAL_ADDR4: 0
CEC_CLOCK_DIV_H: 0
CEC_CLOCK_DIV_L: 0
RX buffer:
0: 0
1: 0
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 0
9: 0
10: 0
11: 0
12: 0
13: 0
14: 0
15: 0
CEC_RX_MSG_LENGTH: 0
CEC_RX_MSG_STATUS: 0
CEC_RX_NUM_MSG: 0
CEC_TX_MSG_STATUS: 0
CEC_TX_NUM_MSG: 0

问题排查与解决方案建议

  1. 修正CEC指令格式
    从寄存器日志看,设备逻辑地址为14(对应CEC规范的Playback Device 2,十六进制为0xE),TV的逻辑地址通常为0x0。正确的关机指令格式应为[源地址4位][目标地址4位] + 关机命令码,所以替换指令为:

    echo 0xE0 0x36 > /sys/class/cec/cmd
    
  2. 验证TV端CEC细节设置
    三星TV的CEC功能名为Anynet+,需进入设置-通用-外部设备管理器-Anynet+,确保:

    • Anynet+功能已开启
    • 允许外部设备控制电视电源
  3. 检查HDMI物理连接
    日志显示设备物理地址为1000,对应HDMI端口1。确认设备确实连接在TV的对应端口,且该端口的CEC功能未被单独禁用;可尝试重新插拔HDMI线或切换端口测试。

  4. 排查驱动写入异常
    从寄存器日志看,TX缓冲区全为0,说明指令未被正确写入。尝试先开启调试模式再发送指令:

    echo 1 > /sys/class/cec/dbg_en
    echo 0xE0 0x36 > /sys/class/cec/cmd
    cat /sys/class/cec/dump_reg
    

    查看是否有更详细的错误日志输出。

  5. 规避系统CEC服务干扰
    Android系统自带的HDMI CEC服务可能拦截手动指令,尝试先停止服务再测试:

    stop hdmi_control
    echo 0xE0 0x36 > /sys/class/cec/cmd
    

内容的提问来源于stack exchange,提问作者Vishal Bhimporwala

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 17:33:06