|
1 | 1 | import semver from 'semver'; |
2 | 2 | import { |
3 | | - createNeedUpgradeFirmwareHardwareError, |
4 | 3 | ERRORS, |
5 | 4 | HardwareErrorCode, |
| 5 | + createNeedUpgradeFirmwareHardwareError, |
6 | 6 | } from '@onekeyfe/hd-shared'; |
| 7 | + |
7 | 8 | import { supportInputPinOnSoftware, supportModifyHomescreen } from '../utils/deviceFeaturesUtils'; |
8 | 9 | import { createDeviceMessage } from '../events/device'; |
9 | 10 | import { UI_REQUEST } from '../constants/ui-request'; |
10 | | -import { Device } from '../device/Device'; |
11 | | -import DeviceConnector from '../device/DeviceConnector'; |
12 | | -import { DeviceFirmwareRange, KnownDevice } from '../types'; |
13 | | -import { CoreMessage, createFirmwareMessage, createUiMessage, DEVICE, FIRMWARE } from '../events'; |
| 11 | +import { DEVICE, FIRMWARE, createFirmwareMessage, createUiMessage } from '../events'; |
14 | 12 | import { getBleFirmwareReleaseInfo, getFirmwareReleaseInfo } from './firmware/releaseHelper'; |
15 | | -import { getDeviceFirmwareVersion, getLogger, getMethodVersionRange, LoggerNames } from '../utils'; |
| 13 | +import { |
| 14 | + LoggerNames, |
| 15 | + getDeviceFirmwareVersion, |
| 16 | + getFirmwareType, |
| 17 | + getLogger, |
| 18 | + getMethodVersionRange, |
| 19 | +} from '../utils'; |
| 20 | + |
| 21 | +import type { Device } from '../device/Device'; |
| 22 | +import type DeviceConnector from '../device/DeviceConnector'; |
| 23 | +import type { DeviceFirmwareRange, KnownDevice } from '../types'; |
| 24 | +import type { CoreMessage } from '../events'; |
| 25 | +import { generateInstanceId, RequestContext } from '../utils/tracing'; |
16 | 26 | import type { CoreContext } from '../core'; |
17 | 27 |
|
18 | 28 | const Log = getLogger(LoggerNames.Method); |
@@ -45,6 +55,12 @@ export abstract class BaseMethod<Params = undefined> { |
45 | 55 | */ |
46 | 56 | name: string; |
47 | 57 |
|
| 58 | + instanceId!: string; |
| 59 | + |
| 60 | + sdkInstanceId?: string; |
| 61 | + |
| 62 | + requestContext?: RequestContext; |
| 63 | + |
48 | 64 | /** |
49 | 65 | * 请求携带参数 |
50 | 66 | */ |
@@ -121,14 +137,45 @@ export abstract class BaseMethod<Params = undefined> { |
121 | 137 | return {}; |
122 | 138 | } |
123 | 139 |
|
| 140 | + setContext(context: CoreContext) { |
| 141 | + this.sdkInstanceId = context.sdkInstanceId; |
| 142 | + this.instanceId = generateInstanceId('Method', this.sdkInstanceId); |
| 143 | + Log.debug( |
| 144 | + `[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}` |
| 145 | + ); |
| 146 | + } |
| 147 | + |
124 | 148 | setDevice(device: Device) { |
125 | 149 | this.device = device; |
126 | | - // this.connectId = device.originalDescriptor.path; |
| 150 | + |
| 151 | + if (!device.sdkInstanceId && this.sdkInstanceId) { |
| 152 | + device.sdkInstanceId = this.sdkInstanceId; |
| 153 | + device.instanceId = generateInstanceId('Device', this.sdkInstanceId); |
| 154 | + } |
| 155 | + |
| 156 | + if (this.requestContext) { |
| 157 | + this.requestContext.deviceInstanceId = device.instanceId; |
| 158 | + this.requestContext.commandsInstanceId = device.commands?.instanceId; |
| 159 | + this.requestContext.sdkInstanceId = this.sdkInstanceId; |
| 160 | + } |
| 161 | + |
| 162 | + if (device.commands && this.sdkInstanceId) { |
| 163 | + device.commands.instanceId = generateInstanceId('DeviceCommands', this.sdkInstanceId); |
| 164 | + } |
| 165 | + |
| 166 | + if (device.commands) { |
| 167 | + device.commands.currentResponseID = this.responseID; |
| 168 | + } |
| 169 | + |
| 170 | + Log.debug( |
| 171 | + `[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${device.commands?.instanceId}` |
| 172 | + ); |
127 | 173 | } |
128 | 174 |
|
129 | 175 | checkFirmwareRelease() { |
130 | 176 | if (!this.device || !this.device.features) return; |
131 | | - const releaseInfo = getFirmwareReleaseInfo(this.device.features); |
| 177 | + const firmwareType = getFirmwareType(this.device.features); |
| 178 | + const releaseInfo = getFirmwareReleaseInfo(this.device.features, firmwareType); |
132 | 179 | this.postMessage( |
133 | 180 | createFirmwareMessage(FIRMWARE.RELEASE_INFO, { |
134 | 181 | ...releaseInfo, |
|
0 commit comments