{
    "name"  : "查看端口硬件供电状态",
    "precondition" : ["name", "type"],
    "problems" : {
        "no_pd" : {
            "desc"      : "【问题】检测到接口的PD端开，或者说没有接PD",
            "advice"    : "【建议】建议重新插紧网线或者更换网线，有条件的话，更换其他PD试试"
        },
        "level_err" : {
            "desc"      : "【问题】PD分级错误",
            "advice"    : "【建议】拔插PD尝试重新分级"
        },
        "dvdt_err" :{
            "desc"      : "【问题】DVDT错误，PD为非标，上电期间电流过大，无法上电",
            "advice"    : "【建议】开启端口以AT模式上电可解决，早期有版本以AF模式上电，建议确认版本"
        }
    },
    "support" : "S5750-24GT/8SFP-P S5750-48GT/4SFP-P",
    "register" : {
        "11" : "0x11AA",
        "23" : "0x11AA",
        "35" : "0x11AA",
        "47" : "0x11AA",
        "12" : "0x11AC",
        "24" : "0x11AC",
        "36" : "0x11AC",
        "48" : "0x11AC",
        "9"  : "0x11AE",
        "21" : "0x11AE",
        "33" : "0x11AE",
        "45" : "0x11AE",
        "10" : "0x11b0",
        "22" : "0x11b0",
        "34" : "0x11b0",
        "46" : "0x11b0",
        "7" : "0x11B2",
        "19" : "0x11B1",
        "31" : "0x11B2",
        "43" : "0x11B1",
        "8" : "0x11B4",
        "20" : "0x11B4",
        "32" : "0x11B4",
        "44" : "0x11B4",
        "5" : "0x11B6",
        "17" : "0x11B6",
        "29" : "0x11B6",
        "41" : "0x11B6",
        "6" : "0x11B8",
        "18" : "0x11B8",
        "30" : "0x11B8",
        "42" : "0x11B8",
        "3" : "0x11BA",
        "15" : "0x11BA",
        "27" : "0x11BA",
        "39" : "0x11BA",
        "4" : "0x11BC",
        "16" : "0x11BC",
        "28" : "0x11BC",
        "40" : "0x11BC",
        "1" : "0x11BE",
        "13" : "0x11BE",
        "25" : "0x11BE",
        "37" : "0x11BE",
        "2" : "0x11C0",
        "14" : "0x11C0",
        "26" : "0x11C0",
        "38" : "0x11C0"
    }
}
---------------------------code-------------------------------
type = precondition('type')
if type != 'copper':
    add_reason('非电口类型的端口不需要进行该项诊断')
    return 'skip'
end

model = get_device_model()
print model
if model.search(/S5750-24GT\/8SFP-P/i) == -1 && model.search(/S5750-48GT\/4SFP-P/i) == -1:
    add_reason('该诊断仅支持设备型号为S5750-24GT/8SFP-P或者S5750-48GT/4SFP-P的设备')
    return 'skip'
end

res = cli('debug ssp rem')

#获取端口号
reg = /(?:\d+\/)+(\d+)/
intf_name = precondition('name')
tmp = intf_name.match(reg)
port_num = tmp[1]

port_register = get_configure_value('register')
register_num = port_register[port_num]

port_num_int = parse_int(port_num)
chip_num = 0
if port_num_int >= 1 && port_num_int <= 12:
    chip_num = 1
end

if port_num_int >= 13 && port_num_int <= 24:
    chip_num = 0
end

if port_num_int >= 25 && port_num_int <= 36:
    chip_num = 3
end

if port_num_int >= 37 && port_num_int <= 48:
    chip_num = 2
end

cmd = format("i2c_read slot 0 type 4 dev_id %s %s 2 2", chip_num, register_num)

res = cli(cmd)

cli('exit')
reg = /[0-9a-f]+:\s*[0-9a-f]{2}\s+([0-9a-f]{2})/i
tmp = res.match(reg)
if tmp == null :
    return 'success'
end
value = tmp[1]
value = parse_int(value, 16)

if value == 4:
    add_problem('no_pd')
    return 'warn'
end

if value == 6:
    add_problem('level_err')
    return 'warn'
end

if value == 13:
    add_problem('dvdt_err')
    return 'warn'
end

return 'success'