Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions ground_station/dfu_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@

class DFU_Reboot:
def __init__(self):
pass
self.backend = usb.backend.libusb1.get_backend()
if self.backend is None:
print("Warning: libusb backend not found; falling back to PyUSB default")
self.backend = None

def listDeviced(self):
def listDevices(self):
deviceList = []
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
if dev != None:
try:
deviceInfo = {"dev":dev.dev,
"vid":dev.idVendor,
"pid":dev.idProduct,
"ser":dev.dev.serial_number,
"manufacturer":dev.dev.manufacturer,
"product":dev.dev.product}
deviceList.append(deviceInfo)
except:
pass
deviceList = sorted(deviceList, key=lambda x: x['ser']) # Sort list by increasing Serial number
devices = usb.core.find(find_all=True, backend=self.backend)
for dev in devices or []:
try:
deviceInfo = {
"dev": dev,
"vid": dev.idVendor,
"pid": dev.idProduct,
"ser": getattr(dev, "serial_number", None),
"manufacturer": getattr(dev, "manufacturer", None),
"product": getattr(dev, "product", None),
}
deviceList.append(deviceInfo)
except Exception:
pass
deviceList.sort(key=lambda x: x["ser"] or "")
return deviceList

def reboot(self, devices):
Expand Down Expand Up @@ -68,6 +70,6 @@ def reboot(self, devices):

if __name__ == "__main__":
dfu = DFU_Reboot()
devices = dfu.listDeviced()
print(devices)
devices = dfu.listDevices()
print(f"devices: {devices}")
# print(dfu.reboot(devices))
4 changes: 2 additions & 2 deletions ground_station/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ extra_scripts =
upload_protocol = custom
upload_flags =
${env:ground_station.build_flags} ; Pass build flags as argument to python script
COMPARE_SERIAL_NUMBER=false ; Download only to devices with specified USB Serial Number, otherwise to all connected devices
USE_SERIAL_NUMBER_LIST=false ; Overwrite single USB Serial Number (USB_SERIAL) with list of accepted Serial Numbers
COMPARE_SERIAL_NUMBER=true ; Download only to devices with specified USB Serial Number, otherwise to all connected devices
USE_SERIAL_NUMBER_LIST=true ; Overwrite single USB Serial Number (USB_SERIAL) with list of accepted Serial Numbers
SERIAL_NUMBER_LIST=["0", "1", "2"] ; List of specific USB Serial Numbers to program and open COM-Port (if enabled)
ENABLE_AUTOMATIC_CONSOLE=false ; Enables automatic opening of serial ports
COMPARE_VID_PID_CONSOLE=true ; Open only COM-Ports with same VID/PID as specified above (USB_VID, USB_PID)
Expand Down
23 changes: 14 additions & 9 deletions ground_station/uf2_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, family ="ESP32S2", startAddr=0):
self.UF2_MAGIC_END = 0x0AB16F30 # Ditto

self.SEARCH_PATH = "esp32-firmware-update/*.bin"
self.INFO_FILE = "/INFO_UF2.TXT"
self.INFO_FILE = "INFO_UF2.TXT"
self.appstartaddr = startAddr
self.familyid = 0x0

Expand Down Expand Up @@ -185,13 +185,18 @@ def to_str(self, b):
def get_drives(self):
drives = []
if sys.platform == "win32":
r = subprocess.check_output(["wmic", "PATH", "Win32_LogicalDisk",
"get", "DeviceID,", "VolumeName,",
"FileSystem,", "DriveType"])
for line in self.to_str(r).split('\n'):
words = re.split('\s+', line)
if len(words) >= 3 and words[1] == "2" and words[2] == "FAT":
drives.append(words[0])
try:
r = subprocess.check_output(
["wmic", "logicaldisk", "get", "DeviceID,FileSystem,DriveType"],
universal_newlines=True
)
for line in r.splitlines():
if "FAT" in line and "2" in line:
match = re.match(r"^\s*([A-Z]:)", line)
if match:
drives.append(match.group(1) + "\\")
except Exception as e:
print("WMIC drive check failed:", e)
else:
rootpath = "/media"
if sys.platform == "darwin":
Expand All @@ -206,7 +211,7 @@ def get_drives(self):

def has_info(d):
try:
return os.path.isfile(d + self.INFO_FILE)
return os.path.isfile(os.path.join(d, self.INFO_FILE))
except:
return False

Expand Down
12 changes: 8 additions & 4 deletions ground_station/upload_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import ast
import time
import glob
import shutil
import subprocess
from packet_installer import installPackages
Expand Down Expand Up @@ -85,11 +84,16 @@ def getParameterString(keyword):

availableDrives = loader.get_drives()
if not availableDrives:
devices = dfu.listDeviced()
devices = dfu.listDevices()
filtered_devices = []
for d in devices:
if(d['ser'] == "0000000000000001"):
devices.remove(d)
if d['ser'] == "0000000000000001":
print("Removed fake device: ['0000000000000001']")
elif d['ser'] is None:
print("Removed 'None' device")
else:
filtered_devices.append(d)
devices = filtered_devices
if not devices:
return ['No devices found for entering bootloader, check if "libusb-win32" driver has been installed for "TinyUSB DFU_RT (Interface 1)"']
if(compare_Serial):
Expand Down