Class: AmdgpuFan::PCI
- Inherits:
-
Object
- Object
- AmdgpuFan::PCI
- Defined in:
- lib/amdgpu_fan/pci.rb
Overview
PCI
Retrieve device information from PCI IDs. pci-ids.ucw.cz/
Constant Summary collapse
- TMP_FILE =
'/tmp/pci.ids.txt'- URL =
'https://pci-ids.ucw.cz/v2.2/pci.ids'
Class Method Summary collapse
-
.device_name(vendor_id, device_id, subdevice_id) ⇒ Object
Return the device name if available.
- .info ⇒ Object
- .raw ⇒ Object
- .vendor_name(vendor_id) ⇒ Object
Class Method Details
.device_name(vendor_id, device_id, subdevice_id) ⇒ Object
Return the device name if available
20 21 22 23 24 |
# File 'lib/amdgpu_fan/pci.rb', line 20 def self.device_name(vendor_id, device_id, subdevice_id) device = info.dig vendor_id, :devices, device_id device.dig(subdevice_id, :name) || device[:name] end |
.info ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/amdgpu_fan/pci.rb', line 30 def self.info current_vendor_id = nil current_device_id = nil @info = raw.each_line.with_object({}) do |line, hash| next if line.empty? || line.start_with?('#') if line[0] =~ /(\d|[a-z])/ # Vendor line current_vendor_id = line.split(' ').first.to_i(16) vendor_name = line.split(' ').last.strip hash[current_vendor_id] = { name: vendor_name, devices: {} } elsif line[0..1] =~ /\t\w/ # Device line current_device_id = line.split(' ').first.to_i(16) device_name = line.split(' ').last.strip hash[current_vendor_id][:devices][current_device_id] = { name: device_name } elsif line[0..2] =~ /\t\t\w/ # Subvendor line # subvendor_id = line.split(' ').first.to_i(16) subdevice_id = line.split[1].to_i(16) subdevice_name = line.split(' ')[1].strip hash[current_vendor_id][:devices][current_device_id][subdevice_id] = { name: subdevice_name } end end end |
.raw ⇒ Object
58 59 60 61 62 |
# File 'lib/amdgpu_fan/pci.rb', line 58 def self.raw File.write(TMP_FILE, Net::HTTP.get(URI(URL))) unless File.exist?(TMP_FILE) @raw ||= File.read(TMP_FILE) end |
.vendor_name(vendor_id) ⇒ Object
26 27 28 |
# File 'lib/amdgpu_fan/pci.rb', line 26 def self.vendor_name(vendor_id) info.dig vendor_id, :name end |