From 576a5dafcf0cb0a06970cbeb66fdc3f0ddf06de6 Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Fri, 22 Nov 2024 15:07:06 +0100 Subject: [PATCH] fix(connect): device connect/reset issue workarounds --- packages/connect/src/device/Device.ts | 7 ++++++- packages/connect/src/device/DeviceList.ts | 3 +++ packages/transport/src/api/usb.ts | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/connect/src/device/Device.ts b/packages/connect/src/device/Device.ts index 60bc96b2b89..c5508ccc9ea 100644 --- a/packages/connect/src/device/Device.ts +++ b/packages/connect/src/device/Device.ts @@ -555,12 +555,17 @@ export class Device extends TypedEmitter { } catch (error) { if ( !this.inconsistent && - (error.message === 'GetFeatures timeout' || error.message === 'Unknown message') + (error.message === 'GetFeatures timeout' || + error.message === 'Unknown message' || + error.message.startsWith('assertType: Response of unexpected type')) ) { // handling corner-case T1B1 + bootloader < 1.4.0 (above) // if GetFeatures fails try again // this time add empty "fn" param to force Initialize message + + // also a workaround for "Response of unexpected type" error, where a previous call was interrupted this.inconsistent = true; + console.log('Retry GetFeatures due to incorrect message'); return this._runInner(() => Promise.resolve({}), options); } diff --git a/packages/connect/src/device/DeviceList.ts b/packages/connect/src/device/DeviceList.ts index ce261e51f99..e86b440b6f5 100644 --- a/packages/connect/src/device/DeviceList.ts +++ b/packages/connect/src/device/DeviceList.ts @@ -195,6 +195,7 @@ export class DeviceList extends TypedEmitter implements IDevic } private onDeviceConnected(descriptor: Descriptor, transport: Transport) { + console.log('onDeviceConnected', descriptor); const { path } = descriptor; const id = (this.deviceCounter++).toString(16).slice(-8); const device = new Device({ @@ -206,9 +207,11 @@ export class DeviceList extends TypedEmitter implements IDevic this.devices[path] = device; const penalty = this.authPenaltyManager.get(); + console.log('before handshake'); this.handshakeLock(async () => { if (this.devices[path]) { // device wasn't removed while waiting for lock + console.log('handshake'); await device.handshake(penalty); } }); diff --git a/packages/transport/src/api/usb.ts b/packages/transport/src/api/usb.ts index 7cd17860a9e..376b4869024 100644 --- a/packages/transport/src/api/usb.ts +++ b/packages/transport/src/api/usb.ts @@ -317,7 +317,7 @@ export class UsbApi extends AbstractApi { `usb: device.selectConfiguration error ${err}. device: ${this.formatDeviceForLog(device)}`, ); } - try { + /*try { // reset fails on ChromeOS and windows this.logger?.debug('usb: device.reset'); await this.abortableMethod(() => device?.reset(), { signal }); @@ -329,7 +329,7 @@ export class UsbApi extends AbstractApi { `usb: device.reset error ${err}. device: ${this.formatDeviceForLog(device)}`, ); // empty - } + }*/ } try { const interfaceId = this.debugLink ? DEBUGLINK_INTERFACE_ID : INTERFACE_ID; @@ -367,7 +367,7 @@ export class UsbApi extends AbstractApi { this.logger?.debug(`usb: device.releaseInterface: ${interfaceId}`); if (!this.debugLink) { // NOTE: `device.reset()` interrupts transfers for all interfaces (debugLink and normal) - await device.reset(); + // await device.reset(); } await device.releaseInterface(interfaceId); this.logger?.debug(