由于edid是一种二进制格式,并且似乎没有可用于解析它的gem,因此我建议使用
bindata
gem创建数据模型,如
EDID
维基百科页面。
对于前两个字段,它类似于:
require 'bindata'
module EDID
class Record < BinData::Record
HEADER_BYTES = [0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00]
array :header_bytes, type: :uint8, initial_length: 8, value: HEADER_BYTES, assert_value: HEADER_BYTES
bit1 :manufacturer_id_pad, value: 0
array :manufacturer_id, type: :bit5, initial_length: 3
uint16le :product_code
uint32le :serial_number
uint8 :manufacture_week
uint8 :manufacture_year
uint8 :edid_version, initial_value: 1
uint8 :edid_revision, initial_value: 3
def manufacturer
manufacturer_id.map { |int| (int+64).chr }.join
end
def manufacture_year_real
manufacture_week == 255 ? manufacture_year : (manufacture_year + 1990)
end
def to_s
<<~EOB
Manufacturer: #{manufacturer}
Product: #{product_code}
Serial: #{serial_number}
Manufacture_year: #{manufacture_year_real}
Manufacture_week: #{manufacture_week == 255 ? 'unknown' : manufacture_week}
EOB
end
end
end
并将其与您的数据一起使用:
io = File.open('/sys/devices/pci0000:00/0000:00:03.1/0000:0b:00.0/drm/card0/card0-DP-1/edid')
record = EDID::Record.read(io)
puts record
输出:
Manufacturer: ACI
Product: 10147
Serial: 3173
Manufacture_year: 2014
Manufacture_week: 6