Skip to content

Commit

Permalink
jovian-hardware-survey: Fix RA4 info
Browse files Browse the repository at this point in the history
And do less work ourselves...

The vendor script does not provide a string for RA4, so we identify on
the bootloader type, as they do.

Though we still trust what the vendor tells us for D2× controllers.
  • Loading branch information
samueldr committed Oct 27, 2024
1 parent fc4c4c1 commit f956e45
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions pkgs/jovian-hardware-survey/jovian-hardware-survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

D20BOOTLOADER ||= "/usr/share/jupiter_controller_fw_updater/d20bootloader.py"

# Identifiers from: class DeviceType(IntEnum)
DeviceType = {
:D21_D21 => 0x100,
:D2x_D21 => 0x200,
:RA4 => 0x300,
}

# Handles joining/escaping a command, and raises on status != 0
# Additionally prints the command to stderr.
def run(*args, stdout:, silent: false, stderr: false, ignore_fail: false)
Expand Down Expand Up @@ -255,7 +262,7 @@ def controller_information()
return @controller_information if @controller_information
begin
info = JSON.parse(run(D20BOOTLOADER, "getdevicesjson", silent: true, stdout: true)).first
bootloader_type = info["release_number"] >> 8 # Shift for the major release byte
bootloader_type = info["release_number"] & 0xff00 # Mask out lower byte
raw = run(D20BOOTLOADER, "getinfo", silent: true, stdout: true, stderr: true)

# Clean up the raw data
Expand All @@ -266,27 +273,31 @@ def controller_information()
.map { |line| line.split(/\s*-\s*/, 6).last } # "2023-08-09 20:35:03,265 - __main__ - INFO - ......"
.join("\n")

# Seed device_type from the bootloader type
device_type = bootloader_type

# Extract the info
if bootloader_type == 3
# RA4
device_type =
raw
.split(/\n+/)
.grep(/Found a/)
.first
.sub("DeviceType.", "")
.split(/\s+/)[2]
if bootloader_type == DeviceType[:RA4]
mcu = raw.split("**").last.strip
mcus = [mcu]
else
# D20/D21
mcus = raw.split("\n\n")
header = mcus.shift.split(/\n/)
# Let the vendor identify the device for us.
device_type = header
.find { |line| line.match(/^Found a/) }
.split(/\s+/)[2]
end

# Identify the device type from the bootloader type
if DeviceType.key(device_type.to_i)
device_type = DeviceType.key(device_type.to_i).to_s
end

# Format the raw information (bootloader_type) with the information we got.
device_type = "%s (0x%x)" % [device_type.to_s, bootloader_type]

mcus = mcus.map do |mcu|
mcu.split(/\n/)
.grep(/:/)
Expand All @@ -312,6 +323,7 @@ def controller_information()
"Hardware Info" => mcus,
"Bootloader Type" => bootloader_type,
"Hardware ID" => mcus.first["Stored hardware ID"],
"Release Number" => info["release_number"],
}
end

Expand Down

0 comments on commit f956e45

Please sign in to comment.