我正在尝试解析屏幕EDID信息。不幸的是,它不是通常的编码数据。 您是否碰巧知道如何将'IODisplayEDID'中的数据转换为可读的内容?也许'词典'?
这是我的代码:
var object : io_object_t
var serialPortIterator = io_iterator_t()
let matching = IOServiceMatching("IODisplayConnect")
let kernResult = IOServiceGetMatchingServices(kIOMasterPortDefault,
matching,
&serialPortIterator)
if KERN_SUCCESS == kernResult && serialPortIterator != 0 {
repeat {
object = IOIteratorNext(serialPortIterator)
let info = IODisplayCreateInfoDictionary(object, UInt32(kIODisplayOnlyPreferredName)).takeRetainedValue() as NSDictionary as! [String:AnyObject]
if let displayEDID = info["IODisplayEDID"] as? Data {
print(displayEDID) // <-- How do I parse this data correctly?
}
} while object != 0
}
IOObjectRelease(serialPortIterator)
答案 0 :(得分:2)
好的,基本上我使用了评论中提供的维基参考Eric Aya。我按指定的顺序读取8-9个字节,以提取字母的树编号。在我的Mac上,结果显示为“APP”,我猜这意味着制造商是Apple。
if let displayEDID = info["IODisplayEDID"] as? Data {
let array = Array(displayEDID)
var bits : UInt16 = UInt16(array[8])
bits = bits << 8 + UInt16(array[9])
let thirdLetterIndex = Int(bits & 31)
let secondLetterIndex = Int(bits >> 5 & 31)
let firsLetterIndex = Int(bits >> 10 & 31)
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".characters.flatMap { $0.description }
let manufactorer = chars[firsLetterIndex - 1] + chars[secondLetterIndex - 1] + chars[thirdLetterIndex - 1]
print(manufactorer) // Result for my mac is "APP"
}