From 288d0bb88414686520224badf0f2f2c422d2d565 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Sat, 29 Jan 2022 17:12:36 -0800 Subject: [PATCH] add detection on mac --- meshtastic/supported_device.py | 24 +++++++++++++++++++++--- meshtastic/util.py | 28 +++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/meshtastic/supported_device.py b/meshtastic/supported_device.py index 689f7a5..283ef60 100755 --- a/meshtastic/supported_device.py +++ b/meshtastic/supported_device.py @@ -57,13 +57,13 @@ tlora_v2_1_1_6 = SupportedDevice(name="T-Lora", version="2.1-1.6", for_firmware= baseport_on_linux="ttyACM", baseport_on_mac="cu.usbmodem", usb_vendor_id_in_hex="1a86", usb_product_id_in_hex="55d4") heltec_v1 = SupportedDevice(name="Heltec", version="1", for_firmware="heltec-v1", - baseport_on_linux="ttyUSB", baseport_on_mac="ttyUSB", + baseport_on_linux="ttyUSB", baseport_on_mac="cu.usbserial-", usb_vendor_id_in_hex="10c4", usb_product_id_in_hex="ea60") heltec_v2_0 = SupportedDevice(name="Heltec", version="2.0", for_firmware="heltec-v2.0", - baseport_on_linux="ttyUSB", baseport_on_mac="ttyUSB", + baseport_on_linux="ttyUSB", baseport_on_mac="cu.usbserial-", usb_vendor_id_in_hex="10c4", usb_product_id_in_hex="ea60") heltec_v2_1 = SupportedDevice(name="Heltec", version="2.1", for_firmware="heltec-v2.1", - baseport_on_linux="ttyUSB", baseport_on_mac="ttyUSB", + baseport_on_linux="ttyUSB", baseport_on_mac="cu.usbserial-", usb_vendor_id_in_hex="10c4", usb_product_id_in_hex="ea60") # TODO: get info on diy meshtastic_diy_v1 = SupportedDevice(name="Meshtastic DIY", version="1", for_firmware="meshtastic-diy-v1") @@ -134,4 +134,22 @@ def active_ports_on_supported_devices(sds): port = parts[-1] #print(f'port:{port}') ports.add(port) + elif system == "Darwin": + # see if we have any devices (ignoring any stderr output) + command = f'ls -al /dev/{bp}* 2> /dev/null' + #print(f'command:{command}') + _, ls_output = subprocess.getstatusoutput(command) + #print(f'ls_output:{ls_output}') + # if we got output, there are ports + if len(ls_output) > 0: + #print('got output') + # for each line of output + lines = ls_output.split('\n') + #print(f'lines:{lines}') + for line in lines: + parts = line.split(' ') + #print(f'parts:{parts}') + port = parts[-1] + #print(f'port:{port}') + ports.add(port) return ports diff --git a/meshtastic/util.py b/meshtastic/util.py index 78ce780..c66885f 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -300,10 +300,32 @@ def detect_supported_devices(): pass elif system == "Darwin": - # if mac, run ioreg - # could also run: system_profiler SPUSBDataType + # run: system_profiler SPUSBDataType + # could also run ioreg # if mac air (eg: arm m1) do not know how to get info TODO: research - pass + + _, sp_output = subprocess.getstatusoutput('system_profiler SPUSBDataType') + vids = get_unique_vendor_ids() + for vid in vids: + #print(f'looking for {vid}...') + search = f'Vendor ID: 0x{vid}' + #print(f'search:"{search}"') + if re.search(search, sp_output, re.MULTILINE): + #print(f'Found vendor id that matches') + devices = get_devices_with_vendor_id(vid) + # check device id + for device in devices: + #print(f'device:{device} device.usb_product_id_in_hex:{device.usb_product_id_in_hex}') + if device.usb_product_id_in_hex: + search = f'Product ID: 0x{device.usb_product_id_in_hex}' + #print(f'search:"{search}"') + if re.search(search, sp_output, re.MULTILINE): + # concatenate the devices with vendor id to possibles + possible_devices.add(device) + else: + # if there is a supported device witout a product id, then it + # might be a match... so, concatenate + possible_devices.add(device) # ls -al /dev/{tty,cu}.* # crw-rw-rw- 1 root wheel 0x9000003 Jan 13 02:46 /dev/cu.Bluetooth-Incoming-Port