From 787c5e7e0fc2dc253bec617b38c45b7bad3c06a4 Mon Sep 17 00:00:00 2001 From: Bob Long Date: Thu, 13 Jun 2024 16:27:43 +1000 Subject: [PATCH] Tools: add devid encode/decode This helps us better understand/maintain items in the parameter files. SW-159 --- Tools/Carbonix_scripts/devid-decode.py | 27 ++++++++++++++++++++++++++ Tools/Carbonix_scripts/devid-encode.py | 21 ++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 Tools/Carbonix_scripts/devid-decode.py create mode 100644 Tools/Carbonix_scripts/devid-encode.py diff --git a/Tools/Carbonix_scripts/devid-decode.py b/Tools/Carbonix_scripts/devid-decode.py new file mode 100644 index 0000000000..01d60aeae6 --- /dev/null +++ b/Tools/Carbonix_scripts/devid-decode.py @@ -0,0 +1,27 @@ +# Decode an ArduPilot device id + +import argparse + +parser = argparse.ArgumentParser(description='Decode a device id') +parser.add_argument('device_id', type=int, help='Device ID to decode') +args = parser.parse_args() + +bus_types = { + 0: 'UNKNOWN', + 1: 'I2C', + 2: 'SPI', + 3: 'UAVCAN', + 4: 'SITL', + 5: 'MSP', + 6: 'SERIAL', + 7: 'QSPI', +} + +device_id = args.device_id +bus_type = device_id & 0x7 +bus = (device_id >> 3) & 0x1f +address = (device_id >> 8) & 0xff +devtype = (device_id >> 16) & 0xff + +print(f"Device ID: {device_id}") +print(f"{bus_types[bus_type]}{bus}, address {address}, devtype {devtype}") diff --git a/Tools/Carbonix_scripts/devid-encode.py b/Tools/Carbonix_scripts/devid-encode.py new file mode 100644 index 0000000000..9fce879439 --- /dev/null +++ b/Tools/Carbonix_scripts/devid-encode.py @@ -0,0 +1,21 @@ +# Encode an ArduPilot device ID + +# prompt the user for the bus type +print("Bus types:") +print("0: UNKNOWN") +print("1: I2C") +print("2: SPI") +print("3: UAVCAN") +print("4: SITL") +print("5: MSP") +print("6: SERIAL") +print("7: QSPI") +bus_type = int(input("Enter the bus type (0-7): ")) + +# prompt the user for the bus number +bus = int(input("Enter the bus number (0-31): ")) +address = int(input("Enter the address (0-255): ")) +devtype = int(input("Enter the device type (0-255): ")) +device_id = bus_type | (bus << 3) | (address << 8) | (devtype << 16) + +print(f"Device ID: {device_id}")