@microbit/microbit-connection 0.1.0 → 0.9.0-apps.alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/build/cjs/accelerometer-service.d.ts +5 -5
- package/build/cjs/accelerometer-service.js +41 -42
- package/build/cjs/accelerometer-service.js.map +1 -1
- package/build/cjs/async-util.d.ts +9 -0
- package/build/cjs/async-util.js +27 -7
- package/build/cjs/async-util.js.map +1 -1
- package/build/cjs/bluetooth-device-wrapper.d.ts +61 -27
- package/build/cjs/bluetooth-device-wrapper.js +285 -266
- package/build/cjs/bluetooth-device-wrapper.js.map +1 -1
- package/build/cjs/bluetooth-profile.d.ts +43 -35
- package/build/cjs/bluetooth-profile.js +35 -29
- package/build/cjs/bluetooth-profile.js.map +1 -1
- package/build/cjs/bluetooth.d.ts +10 -6
- package/build/cjs/bluetooth.js +286 -100
- package/build/cjs/bluetooth.js.map +1 -1
- package/build/cjs/button-service.d.ts +5 -5
- package/build/cjs/button-service.js +31 -45
- package/build/cjs/button-service.js.map +1 -1
- package/build/cjs/device-information-service.d.ts +6 -0
- package/build/cjs/device-information-service.js +34 -0
- package/build/cjs/device-information-service.js.map +1 -0
- package/build/cjs/device.d.ts +65 -8
- package/build/cjs/device.js +16 -2
- package/build/cjs/device.js.map +1 -1
- package/build/cjs/dfu-service.d.ts +9 -0
- package/build/cjs/dfu-service.js +26 -0
- package/build/cjs/dfu-service.js.map +1 -0
- package/build/cjs/flashing/flashing-full.d.ts +14 -0
- package/build/cjs/flashing/flashing-full.js +87 -0
- package/build/cjs/flashing/flashing-full.js.map +1 -0
- package/build/cjs/flashing/flashing-makecode.d.ts +6 -0
- package/build/cjs/flashing/flashing-makecode.js +48 -0
- package/build/cjs/flashing/flashing-makecode.js.map +1 -0
- package/build/cjs/flashing/flashing-partial.d.ts +9 -0
- package/build/cjs/flashing/flashing-partial.js +98 -0
- package/build/cjs/flashing/flashing-partial.js.map +1 -0
- package/build/cjs/flashing/flashing-v1.d.ts +11 -0
- package/build/cjs/flashing/flashing-v1.js +24 -0
- package/build/cjs/flashing/flashing-v1.js.map +1 -0
- package/build/cjs/flashing/nordic-dfu.d.ts +3 -0
- package/build/cjs/flashing/nordic-dfu.js +214 -0
- package/build/cjs/flashing/nordic-dfu.js.map +1 -0
- package/build/cjs/flashing/zip.d.ts +12 -0
- package/build/cjs/flashing/zip.js +177 -0
- package/build/cjs/flashing/zip.js.map +1 -0
- package/build/cjs/index.d.ts +3 -3
- package/build/cjs/index.js +2 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/led-service.d.ts +5 -7
- package/build/cjs/led-service.js +13 -44
- package/build/cjs/led-service.js.map +1 -1
- package/build/cjs/logging.d.ts +1 -1
- package/build/cjs/logging.js +3 -3
- package/build/cjs/logging.js.map +1 -1
- package/build/cjs/magnetometer-service.d.ts +5 -9
- package/build/cjs/magnetometer-service.js +30 -65
- package/build/cjs/magnetometer-service.js.map +1 -1
- package/build/cjs/partial-flashing-service.d.ts +45 -0
- package/build/cjs/partial-flashing-service.js +110 -0
- package/build/cjs/partial-flashing-service.js.map +1 -0
- package/build/cjs/uart-service.d.ts +4 -5
- package/build/cjs/uart-service.js +19 -40
- package/build/cjs/uart-service.js.map +1 -1
- package/build/cjs/usb-device-wrapper.js +33 -8
- package/build/cjs/usb-device-wrapper.js.map +1 -1
- package/build/cjs/usb-partial-flashing.d.ts +1 -3
- package/build/cjs/usb-partial-flashing.js +4 -3
- package/build/cjs/usb-partial-flashing.js.map +1 -1
- package/build/cjs/usb-radio-bridge.js +1 -2
- package/build/cjs/usb-radio-bridge.js.map +1 -1
- package/build/cjs/usb.d.ts +4 -2
- package/build/cjs/usb.js +31 -16
- package/build/cjs/usb.js.map +1 -1
- package/build/esm/accelerometer-service.d.ts +5 -5
- package/build/esm/accelerometer-service.js +42 -43
- package/build/esm/accelerometer-service.js.map +1 -1
- package/build/esm/async-util.d.ts +9 -0
- package/build/esm/async-util.js +22 -6
- package/build/esm/async-util.js.map +1 -1
- package/build/esm/bluetooth-device-wrapper.d.ts +61 -27
- package/build/esm/bluetooth-device-wrapper.js +284 -265
- package/build/esm/bluetooth-device-wrapper.js.map +1 -1
- package/build/esm/bluetooth-profile.d.ts +43 -35
- package/build/esm/bluetooth-profile.js +35 -29
- package/build/esm/bluetooth-profile.js.map +1 -1
- package/build/esm/bluetooth.d.ts +10 -6
- package/build/esm/bluetooth.js +263 -103
- package/build/esm/bluetooth.js.map +1 -1
- package/build/esm/button-service.d.ts +5 -5
- package/build/esm/button-service.js +32 -46
- package/build/esm/button-service.js.map +1 -1
- package/build/esm/device-information-service.d.ts +6 -0
- package/build/esm/device-information-service.js +30 -0
- package/build/esm/device-information-service.js.map +1 -0
- package/build/esm/device.d.ts +65 -8
- package/build/esm/device.js +15 -1
- package/build/esm/device.js.map +1 -1
- package/build/esm/dfu-service.d.ts +9 -0
- package/build/esm/dfu-service.js +22 -0
- package/build/esm/dfu-service.js.map +1 -0
- package/build/esm/flashing/flashing-full.d.ts +14 -0
- package/build/esm/flashing/flashing-full.js +84 -0
- package/build/esm/flashing/flashing-full.js.map +1 -0
- package/build/esm/flashing/flashing-makecode.d.ts +6 -0
- package/build/esm/flashing/flashing-makecode.js +44 -0
- package/build/esm/flashing/flashing-makecode.js.map +1 -0
- package/build/esm/flashing/flashing-partial.d.ts +9 -0
- package/build/esm/flashing/flashing-partial.js +95 -0
- package/build/esm/flashing/flashing-partial.js.map +1 -0
- package/build/esm/flashing/flashing-v1.d.ts +11 -0
- package/build/esm/flashing/flashing-v1.js +20 -0
- package/build/esm/flashing/flashing-v1.js.map +1 -0
- package/build/esm/flashing/nordic-dfu.d.ts +3 -0
- package/build/esm/flashing/nordic-dfu.js +211 -0
- package/build/esm/flashing/nordic-dfu.js.map +1 -0
- package/build/esm/flashing/zip.d.ts +12 -0
- package/build/esm/flashing/zip.js +174 -0
- package/build/esm/flashing/zip.js.map +1 -0
- package/build/esm/index.d.ts +3 -3
- package/build/esm/index.js +2 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/led-service.d.ts +5 -7
- package/build/esm/led-service.js +13 -44
- package/build/esm/led-service.js.map +1 -1
- package/build/esm/logging.d.ts +1 -1
- package/build/esm/logging.js +1 -1
- package/build/esm/logging.js.map +1 -1
- package/build/esm/magnetometer-service.d.ts +5 -9
- package/build/esm/magnetometer-service.js +31 -66
- package/build/esm/magnetometer-service.js.map +1 -1
- package/build/esm/partial-flashing-service.d.ts +45 -0
- package/build/esm/partial-flashing-service.js +106 -0
- package/build/esm/partial-flashing-service.js.map +1 -0
- package/build/esm/uart-service.d.ts +4 -5
- package/build/esm/uart-service.js +19 -40
- package/build/esm/uart-service.js.map +1 -1
- package/build/esm/usb-device-wrapper.js +33 -8
- package/build/esm/usb-device-wrapper.js.map +1 -1
- package/build/esm/usb-partial-flashing.d.ts +1 -3
- package/build/esm/usb-partial-flashing.js +4 -3
- package/build/esm/usb-partial-flashing.js.map +1 -1
- package/build/esm/usb-radio-bridge.js +2 -3
- package/build/esm/usb-radio-bridge.js.map +1 -1
- package/build/esm/usb.d.ts +4 -2
- package/build/esm/usb.js +33 -18
- package/build/esm/usb.js.map +1 -1
- package/package.json +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button-service.js","sourceRoot":"","sources":["../../lib/button-service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"button-service.js","sourceRoot":"","sources":["../../lib/button-service.ts"],"names":[],"mappings":";;;AAAA,oEAA8D;AAE9D,iEAAiD;AACjD,6CAAwD;AAKxD,2CAAmD;AAEnD,MAAa,aAAa;IAGxB,YACU,QAAgB,EAChB,kBAA+C;QADvD;;;;mBAAQ,QAAQ;WAAQ;QACxB;;;;mBAAQ,kBAAkB;WAA6B;QAJzD;;;;mBAAO,8BAAO,CAAC,MAAM,CAAC,EAAE;WAAC;IAKtB,CAAC;IAEJ,iBAAiB;QACf,OAAO,CAAC,gBAAgB,EAAE,gBAAg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,IAAI,KAAK,gBAAgB;YAC9B,CAAC,CAAC,8BAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;YAClC,CAAC,CAAC,8BAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;IACvC,CAAC;CACF;AA5DD,sCA4DC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeviceInformationService = void 0;
|
|
4
|
+
const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
|
|
5
|
+
const bluetooth_profile_1 = require("./bluetooth-profile");
|
|
6
|
+
class DeviceInformationService {
|
|
7
|
+
constructor(deviceId) {
|
|
8
|
+
Object.defineProperty(this, "deviceId", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: deviceId
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async getBoardVersion() {
|
|
16
|
+
const serviceMeta = bluetooth_profile_1.profile.deviceInformation;
|
|
17
|
+
try {
|
|
18
|
+
const modelNumberBytes = await bluetooth_le_1.BleClient.read(this.deviceId, serviceMeta.id, serviceMeta.characteristics.modelNumber.id);
|
|
19
|
+
const modelNumber = new TextDecoder().decode(modelNumberBytes);
|
|
20
|
+
if (modelNumber.toLowerCase() === "BBC micro:bit".toLowerCase()) {
|
|
21
|
+
return "V1";
|
|
22
|
+
}
|
|
23
|
+
if (modelNumber.toLowerCase().includes("BBC micro:bit v2".toLowerCase())) {
|
|
24
|
+
return "V2";
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`Unexpected model number ${modelNumber}`);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw new Error(`Could not read model number: ${e instanceof Error ? e.message : e}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.DeviceInformationService = DeviceInformationService;
|
|
34
|
+
//# sourceMappingURL=device-information-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-information-service.js","sourceRoot":"","sources":["../../lib/device-information-service.ts"],"names":[],"mappings":";;;AAAA,oEAA8D;AAE9D,2DAA8C;AAE9C,MAAa,wBAAwB;IACnC,YAAoB,QAAgB;QAAxB;;;;mBAAQ,QAAQ;WAAQ;IAAG,CAAC;IAExC,KAAK,CAAC,eAAe;QACnB,MAAM,WAAW,GAAG,2BAAO,CAAC,iBAAiB,CAAC;QAC9C,IAAI,CAAC;YACH,MAAM,gBAAgB,GAAG,MAAM,wBAAS,CAAC,IAAI,CAC3C,IAAI,CAAC,QAAQ,EACb,WAAW,CAAC,EAAE,EACd,WAAW,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,CAC3C,CAAC;YACF,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;YAC/D,IAAI,WAAW,CAAC,WAAW,EAAE,KAAK,eAAe,CAAC,WAAW,EAAE,EAAE,CAAC;gBAChE,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IACE,WAAW,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,WAAW,EAAE,CAAC,EACpE,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,WAAW,EAAE,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CACb,gCAAgC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CACrE,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA3BD,4DA2BC"}
|
package/build/cjs/device.d.ts
CHANGED
|
@@ -41,7 +41,56 @@ export type DeviceErrorCode =
|
|
|
41
41
|
/**
|
|
42
42
|
* Bluetooth service is missing on device.
|
|
43
43
|
*/
|
|
44
|
-
| "service-missing"
|
|
44
|
+
| "service-missing"
|
|
45
|
+
/**
|
|
46
|
+
* Failed to establish Bluetooth connection.
|
|
47
|
+
*/
|
|
48
|
+
| "bluetooth-connection-failed"
|
|
49
|
+
/**
|
|
50
|
+
* Bluetooth is disabled on the device.
|
|
51
|
+
*/
|
|
52
|
+
| "bluetooth-disabled"
|
|
53
|
+
/**
|
|
54
|
+
* Missing required Bluetooth permissions.
|
|
55
|
+
*/
|
|
56
|
+
| "bluetooth-missing-permissions"
|
|
57
|
+
/**
|
|
58
|
+
* Partial flash operation failed.
|
|
59
|
+
*/
|
|
60
|
+
| "flash-partial-failed"
|
|
61
|
+
/**
|
|
62
|
+
* Full flash operation failed.
|
|
63
|
+
*/
|
|
64
|
+
| "flash-full-failed"
|
|
65
|
+
/**
|
|
66
|
+
* Flash operation was cancelled.
|
|
67
|
+
*/
|
|
68
|
+
| "flash-cancelled";
|
|
69
|
+
export declare enum ProgressStage {
|
|
70
|
+
Initializing = "Initializing",
|
|
71
|
+
FindingDevice = "FindingDevice",
|
|
72
|
+
Connecting = "Connecting",
|
|
73
|
+
PartialFlashing = "PartialFlashing",
|
|
74
|
+
FullFlashing = "FullFlashing"
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Progress callback for tracking operation stages (connection and flashing).
|
|
78
|
+
*
|
|
79
|
+
* @param stage - The current stage of the operation
|
|
80
|
+
* @param progress - Optional progress value (0-1) for PartialFlashing and FullFlashing stages.
|
|
81
|
+
* Initializing, FindingDevice, and Connecting stages are called once
|
|
82
|
+
* without progress values to indicate stage entry.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const progressCallback = (stage, progress) => {
|
|
86
|
+
* if (progress !== undefined) {
|
|
87
|
+
* console.log(`${stage}: ${Math.round(progress * 100)}%`);
|
|
88
|
+
* } else {
|
|
89
|
+
* console.log(`Stage: ${stage}`);
|
|
90
|
+
* }
|
|
91
|
+
* };
|
|
92
|
+
*/
|
|
93
|
+
export type ProgressCallback = (stage: ProgressStage, progress?: number) => void;
|
|
45
94
|
/**
|
|
46
95
|
* Error type used for all interactions with this module.
|
|
47
96
|
*
|
|
@@ -96,19 +145,26 @@ export declare enum ConnectionStatus {
|
|
|
96
145
|
*/
|
|
97
146
|
RECONNECTING = "RECONNECTING"
|
|
98
147
|
}
|
|
148
|
+
export interface ConnectOptions {
|
|
149
|
+
/**
|
|
150
|
+
* Optional progress callback for tracking connection stages.
|
|
151
|
+
*/
|
|
152
|
+
progress?: ProgressCallback;
|
|
153
|
+
}
|
|
99
154
|
export interface FlashOptions {
|
|
100
155
|
/**
|
|
101
156
|
* True to use a partial flash where possible, false to force a full flash.
|
|
157
|
+
* Default: true.
|
|
102
158
|
*/
|
|
103
|
-
partial
|
|
159
|
+
partial?: boolean;
|
|
104
160
|
/**
|
|
105
|
-
*
|
|
161
|
+
* Optional progress callback for tracking connection and flash stages.
|
|
106
162
|
*
|
|
107
163
|
* Requesting a partial flash doesn't guarantee one is performed. Partial flashes are avoided
|
|
108
164
|
* if too many blocks have changed and failed partial flashes are retried as full flashes.
|
|
109
165
|
* The partial parameter reports the flash type currently in progress.
|
|
110
166
|
*/
|
|
111
|
-
progress
|
|
167
|
+
progress?: ProgressCallback;
|
|
112
168
|
/**
|
|
113
169
|
* Smallest possible progress increment to limit callback rate.
|
|
114
170
|
*/
|
|
@@ -130,7 +186,8 @@ export declare class AfterRequestDevice extends Event {
|
|
|
130
186
|
}
|
|
131
187
|
export declare class BackgroundErrorEvent extends Event {
|
|
132
188
|
readonly errorMessage: string;
|
|
133
|
-
|
|
189
|
+
readonly error?: unknown | undefined;
|
|
190
|
+
constructor(errorMessage: string, error?: unknown | undefined);
|
|
134
191
|
}
|
|
135
192
|
export declare class DeviceConnectionEventMap {
|
|
136
193
|
"status": ConnectionStatusEvent;
|
|
@@ -150,11 +207,11 @@ export interface DeviceConnection<M extends ValueIsEvent<M>> extends TypedEventT
|
|
|
150
207
|
dispose(): void;
|
|
151
208
|
/**
|
|
152
209
|
* Connects to a currently paired device or requests pairing.
|
|
153
|
-
* Throws on error.
|
|
154
210
|
*
|
|
155
|
-
* @
|
|
211
|
+
* @param options Optional connection options including progress callback.
|
|
212
|
+
* @throws {DeviceError} On connection failure. The error.code property indicates the failure type.
|
|
156
213
|
*/
|
|
157
|
-
connect(): Promise<
|
|
214
|
+
connect(options?: ConnectOptions): Promise<void>;
|
|
158
215
|
/**
|
|
159
216
|
* Get the board version.
|
|
160
217
|
*
|
package/build/cjs/device.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DeviceConnectionEventMap = exports.BackgroundErrorEvent = exports.AfterRequestDevice = exports.BeforeRequestDevice = exports.ConnectionStatusEvent = exports.FlashDataError = exports.ConnectionStatus = exports.DeviceError = void 0;
|
|
3
|
+
exports.DeviceConnectionEventMap = exports.BackgroundErrorEvent = exports.AfterRequestDevice = exports.BeforeRequestDevice = exports.ConnectionStatusEvent = exports.FlashDataError = exports.ConnectionStatus = exports.DeviceError = exports.ProgressStage = void 0;
|
|
4
|
+
var ProgressStage;
|
|
5
|
+
(function (ProgressStage) {
|
|
6
|
+
ProgressStage["Initializing"] = "Initializing";
|
|
7
|
+
ProgressStage["FindingDevice"] = "FindingDevice";
|
|
8
|
+
ProgressStage["Connecting"] = "Connecting";
|
|
9
|
+
ProgressStage["PartialFlashing"] = "PartialFlashing";
|
|
10
|
+
ProgressStage["FullFlashing"] = "FullFlashing";
|
|
11
|
+
})(ProgressStage || (exports.ProgressStage = ProgressStage = {}));
|
|
4
12
|
/**
|
|
5
13
|
* Error type used for all interactions with this module.
|
|
6
14
|
*
|
|
@@ -90,7 +98,7 @@ class AfterRequestDevice extends Event {
|
|
|
90
98
|
}
|
|
91
99
|
exports.AfterRequestDevice = AfterRequestDevice;
|
|
92
100
|
class BackgroundErrorEvent extends Event {
|
|
93
|
-
constructor(errorMessage) {
|
|
101
|
+
constructor(errorMessage, error) {
|
|
94
102
|
super("backgrounderror");
|
|
95
103
|
Object.defineProperty(this, "errorMessage", {
|
|
96
104
|
enumerable: true,
|
|
@@ -98,6 +106,12 @@ class BackgroundErrorEvent extends Event {
|
|
|
98
106
|
writable: true,
|
|
99
107
|
value: errorMessage
|
|
100
108
|
});
|
|
109
|
+
Object.defineProperty(this, "error", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
configurable: true,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: error
|
|
114
|
+
});
|
|
101
115
|
}
|
|
102
116
|
}
|
|
103
117
|
exports.BackgroundErrorEvent = BackgroundErrorEvent;
|
package/build/cjs/device.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../lib/device.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../lib/device.ts"],"names":[],"mappings":";;;AAsEA,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,8CAA6B,CAAA;IAC7B,gDAA+B,CAAA;IAC/B,0CAAyB,CAAA;IACzB,oDAAmC,CAAA;IACnC,8CAA6B,CAAA;AAC/B,CAAC,EANW,aAAa,6BAAb,aAAa,QAMxB;AAwBD;;;;;;;;GAQG;AACH,MAAa,WAAY,SAAQ,KAAK;IAEpC,YAAY,EAAE,IAAI,EAAE,OAAO,EAA+C;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QAFjB;;;;;WAAsB;QAGpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAND,kCAMC;AAED;;GAEG;AACH,IAAY,gBAkCX;AAlCD,WAAY,gBAAgB;IAC1B;;;OAGG;IACH,2DAAuC,CAAA;IACvC;;OAEG;IACH,mDAA+B,CAAA;IAC/B;;;;;OAKG;IACH,iEAA6C,CAAA;IAC7C;;OAEG;IACH,iDAA6B,CAAA;IAC7B;;OAEG;IACH,2CAAuB,CAAA;IACvB;;OAEG;IACH,6CAAyB,CAAA;IACzB;;;OAGG;IACH,iDAA6B,CAAA;AAC/B,CAAC,EAlCW,gBAAgB,gCAAhB,gBAAgB,QAkC3B;AA6BD,MAAa,cAAe,SAAQ,KAAK;CAAG;AAA5C,wCAA4C;AAQ5C,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAA4B,MAAwB;QAClD,KAAK,CAAC,QAAQ,CAAC,CAAC;QADN;;;;mBAAgB,MAAM;WAAkB;IAEpD,CAAC;CACF;AAJD,sDAIC;AAED,MAAa,mBAAoB,SAAQ,KAAK;IAC5C;QACE,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC/B,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,kBAAmB,SAAQ,KAAK;IAC3C;QACE,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC9B,CAAC;CACF;AAJD,gDAIC;AAED,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YACkB,YAAoB,EACpB,KAAe;QAE/B,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAHzB;;;;mBAAgB,YAAY;WAAQ;QACpC;;;;mBAAgB,KAAK;WAAU;IAGjC,CAAC;CACF;AAPD,oDAOC;AAED,MAAa,wBAAwB;IAArC;QACE,4BAAA,QAAQ;;;;;WAAwB;QAChC,4BAAA,iBAAiB;;;;;WAAuB;QACxC,4BAAA,qBAAqB;;;;;WAAQ;QAC7B,4BAAA,oBAAoB;;;;;WAAQ;IAC9B,CAAC;CAAA;AALD,4DAKC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DfuService = exports.NORDIC_DFU_SERVICE = void 0;
|
|
4
|
+
const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
|
|
5
|
+
const bluetooth_profile_1 = require("./bluetooth-profile");
|
|
6
|
+
// This is the service that should be available on V1 after the reboot.
|
|
7
|
+
// We don't use it directly (the Nordic DFU library does) but we check it's there.
|
|
8
|
+
exports.NORDIC_DFU_SERVICE = "00001530-1212-EFDE-1523-785FEABCD123";
|
|
9
|
+
class DfuService {
|
|
10
|
+
constructor(deviceId) {
|
|
11
|
+
Object.defineProperty(this, "deviceId", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: deviceId
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* We do this for V1 only.
|
|
20
|
+
*/
|
|
21
|
+
async requestRebootToBootloader() {
|
|
22
|
+
await bluetooth_le_1.BleClient.write(this.deviceId, bluetooth_profile_1.profile.dfuControl.id, bluetooth_profile_1.profile.dfuControl.characteristics.control.id, (0, bluetooth_le_1.numbersToDataView)([0x01]));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.DfuService = DfuService;
|
|
26
|
+
//# sourceMappingURL=dfu-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dfu-service.js","sourceRoot":"","sources":["../../lib/dfu-service.ts"],"names":[],"mappings":";;;AAAA,oEAG2C;AAC3C,2DAA8C;AAE9C,uEAAuE;AACvE,kFAAkF;AACrE,QAAA,kBAAkB,GAAG,sCAAsC,CAAC;AAEzE,MAAa,UAAU;IACrB,YAAoB,QAAgB;QAAxB;;;;mBAAQ,QAAQ;WAAQ;IAAG,CAAC;IAExC;;OAEG;IACH,KAAK,CAAC,yBAAyB;QAC7B,MAAM,wBAAS,CAAC,KAAK,CACnB,IAAI,CAAC,QAAQ,EACb,2BAAO,CAAC,UAAU,CAAC,EAAE,EACrB,2BAAO,CAAC,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,EAC7C,IAAA,gCAAiB,EAAC,CAAC,IAAI,CAAC,CAAC,CAC1B,CAAC;IACJ,CAAC;CACF;AAdD,gCAcC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import MemoryMap from "nrf-intel-hex";
|
|
2
|
+
import { BoardVersion, ProgressCallback } from "../device";
|
|
3
|
+
import { BluetoothDeviceWrapper } from "../bluetooth-device-wrapper";
|
|
4
|
+
/**
|
|
5
|
+
* Perform a full flash via Nordic's DFU service.
|
|
6
|
+
*
|
|
7
|
+
* The connection is closed before handing off to Nordic's service which will
|
|
8
|
+
* connect again.
|
|
9
|
+
*
|
|
10
|
+
* The device is assumed to be bonded.
|
|
11
|
+
*
|
|
12
|
+
* @throws {DeviceError} On flash failure.
|
|
13
|
+
*/
|
|
14
|
+
export declare function fullFlash(connection: BluetoothDeviceWrapper, boardVersion: BoardVersion, memoryMap: MemoryMap, progress: ProgressCallback): Promise<void>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fullFlash = fullFlash;
|
|
4
|
+
const device_1 = require("../device");
|
|
5
|
+
const dfu_service_1 = require("../dfu-service");
|
|
6
|
+
const flashing_v1_1 = require("./flashing-v1");
|
|
7
|
+
const nordic_dfu_1 = require("./nordic-dfu");
|
|
8
|
+
const async_util_1 = require("../async-util");
|
|
9
|
+
/**
|
|
10
|
+
* Perform a full flash via Nordic's DFU service.
|
|
11
|
+
*
|
|
12
|
+
* The connection is closed before handing off to Nordic's service which will
|
|
13
|
+
* connect again.
|
|
14
|
+
*
|
|
15
|
+
* The device is assumed to be bonded.
|
|
16
|
+
*
|
|
17
|
+
* @throws {DeviceError} On flash failure.
|
|
18
|
+
*/
|
|
19
|
+
async function fullFlash(connection, boardVersion, memoryMap, progress) {
|
|
20
|
+
connection.log("Full flash");
|
|
21
|
+
progress(device_1.ProgressStage.FullFlashing);
|
|
22
|
+
const { deviceId } = connection.device;
|
|
23
|
+
try {
|
|
24
|
+
if (boardVersion === "V1") {
|
|
25
|
+
connection.log("Rebooting V1 to bootloader");
|
|
26
|
+
const dfuService = new dfu_service_1.DfuService(deviceId);
|
|
27
|
+
try {
|
|
28
|
+
await dfuService.requestRebootToBootloader();
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
connection.error("Failed to request reboot to bootloader", e);
|
|
32
|
+
throw new device_1.DeviceError({
|
|
33
|
+
code: "flash-full-failed",
|
|
34
|
+
message: e instanceof Error ? e.message : "Failed to reboot to bootloader",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// Wait for device to automatically disconnect as it reboots into bootloader
|
|
38
|
+
connection.log("Waiting for device to reboot and disconnect");
|
|
39
|
+
try {
|
|
40
|
+
await connection.waitForDisconnect(3000);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
connection.log("Device did not disconnect automatically, disconnecting manually");
|
|
44
|
+
await connection.disconnect();
|
|
45
|
+
}
|
|
46
|
+
// Give device time to disconnect and reboot into bootloader mode
|
|
47
|
+
await (0, async_util_1.delay)(2500);
|
|
48
|
+
// Reconnect to device now in bootloader mode
|
|
49
|
+
progress(device_1.ProgressStage.Connecting);
|
|
50
|
+
await connection.connect();
|
|
51
|
+
await (0, flashing_v1_1.refreshServicesForV1IfDesiredServiceMissing)(deviceId, dfu_service_1.NORDIC_DFU_SERVICE);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
// The Nordic code opens its own connection.
|
|
56
|
+
await connection.disconnect();
|
|
57
|
+
// If we've previously been connected, maybe this helps???
|
|
58
|
+
await (0, async_util_1.delay)(3000);
|
|
59
|
+
}
|
|
60
|
+
const appBin = createAppBin(memoryMap, boardVersion);
|
|
61
|
+
if (appBin === null) {
|
|
62
|
+
connection.log("Invalid hex (app bin case)");
|
|
63
|
+
throw new device_1.FlashDataError("Invalid hex data: could not extract app binary");
|
|
64
|
+
}
|
|
65
|
+
connection.log(`Extracted app bin: ${appBin.length} bytes`);
|
|
66
|
+
await (0, nordic_dfu_1.flashDfu)(connection, boardVersion, appBin, progress);
|
|
67
|
+
}
|
|
68
|
+
const createAppBin = (memoryMap, boardVersion) => {
|
|
69
|
+
const appRegionBoundaries = {
|
|
70
|
+
V1: { start: 0x18000, end: 0x3c000 },
|
|
71
|
+
V2: { start: 0x1c000, end: 0x77000 },
|
|
72
|
+
}[boardVersion];
|
|
73
|
+
// Calculate data size within the app region
|
|
74
|
+
let maxAddress = appRegionBoundaries.start;
|
|
75
|
+
for (const [blockAddr, block] of memoryMap) {
|
|
76
|
+
const blockEnd = blockAddr + block.length;
|
|
77
|
+
if (blockEnd > appRegionBoundaries.start &&
|
|
78
|
+
blockAddr < appRegionBoundaries.end) {
|
|
79
|
+
maxAddress = Math.max(maxAddress, Math.min(blockEnd, appRegionBoundaries.end));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let size = maxAddress - appRegionBoundaries.start;
|
|
83
|
+
// 4-byte alignment required by DFU
|
|
84
|
+
size = Math.ceil(size / 4) * 4;
|
|
85
|
+
return memoryMap.slicePad(appRegionBoundaries.start, size);
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=flashing-full.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flashing-full.js","sourceRoot":"","sources":["../../../lib/flashing/flashing-full.ts"],"names":[],"mappings":";;AAwBA,8BA+DC;AAtFD,sCAMmB;AACnB,gDAAgE;AAChE,+CAA4E;AAC5E,6CAAwC;AAExC,8CAAsC;AAEtC;;;;;;;;;GASG;AACI,KAAK,UAAU,SAAS,CAC7B,UAAkC,EAClC,YAA0B,EAC1B,SAAoB,EACpB,QAA0B;IAE1B,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,sBAAa,CAAC,YAAY,CAAC,CAAC;IACrC,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC;IAEvC,IAAI,CAAC;QACH,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC1B,UAAU,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAE7C,MAAM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C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import MemoryMap from "nrf-intel-hex";
|
|
2
|
+
import { RegionInfo } from "../partial-flashing-service";
|
|
3
|
+
/**
|
|
4
|
+
* Find the MakeCode code region in a MemoryMap (typically from a hex file).
|
|
5
|
+
*/
|
|
6
|
+
export declare const findMakeCodeRegionInMemoryMap: (memoryMap: MemoryMap, deviceCodeRegion: RegionInfo) => RegionInfo | null;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findMakeCodeRegionInMemoryMap = void 0;
|
|
4
|
+
const PXT_MAGIC_HEX = "708E3B92C615A841C49866C975EE5197";
|
|
5
|
+
/**
|
|
6
|
+
* Find the MakeCode code region in a MemoryMap (typically from a hex file).
|
|
7
|
+
*/
|
|
8
|
+
const findMakeCodeRegionInMemoryMap = (memoryMap, deviceCodeRegion) => {
|
|
9
|
+
for (const [blockAddr, block] of memoryMap) {
|
|
10
|
+
const offset = findByteSequence(block, PXT_MAGIC_HEX);
|
|
11
|
+
if (offset >= 0) {
|
|
12
|
+
const start = blockAddr + offset;
|
|
13
|
+
const hashOffset = start + PXT_MAGIC_HEX.length / 2;
|
|
14
|
+
const hashBytes = memoryMap.slicePad(hashOffset, 8);
|
|
15
|
+
const hash = bytesToHex(hashBytes);
|
|
16
|
+
// Find the highest address with data in the memory map within the code region
|
|
17
|
+
let end = start;
|
|
18
|
+
for (const [blockAddr, block] of memoryMap) {
|
|
19
|
+
const blockEnd = blockAddr + block.length;
|
|
20
|
+
if (blockEnd > start && blockAddr < deviceCodeRegion.end) {
|
|
21
|
+
end = Math.max(end, Math.min(blockEnd, deviceCodeRegion.end));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Round up to next 64-byte boundary
|
|
25
|
+
end = Math.ceil(end / 64) * 64;
|
|
26
|
+
return { start, end, hash };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
exports.findMakeCodeRegionInMemoryMap = findMakeCodeRegionInMemoryMap;
|
|
32
|
+
const bytesToHex = (bytes) => {
|
|
33
|
+
return Array.from(bytes)
|
|
34
|
+
.map((byte) => byte.toString(16).padStart(2, "0").toUpperCase())
|
|
35
|
+
.join("");
|
|
36
|
+
};
|
|
37
|
+
function findByteSequence(data, hexTarget) {
|
|
38
|
+
const target = new Uint8Array(hexTarget.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
39
|
+
outer: for (let i = 0; i <= data.length - target.length; i++) {
|
|
40
|
+
for (let j = 0; j < target.length; j++) {
|
|
41
|
+
if (data[i + j] !== target[j])
|
|
42
|
+
continue outer;
|
|
43
|
+
}
|
|
44
|
+
return i;
|
|
45
|
+
}
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=flashing-makecode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flashing-makecode.js","sourceRoot":"","sources":["../../../lib/flashing/flashing-makecode.ts"],"names":[],"mappings":";;;AAGA,MAAM,aAAa,GAAG,kCAAkC,CAAC;AAEzD;;GAEG;AACI,MAAM,6BAA6B,GAAG,CAC3C,SAAoB,EACpB,gBAA4B,EACT,EAAE;IACrB,KAAK,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,SAAS,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QACtD,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;YAChB,MAAM,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;YACjC,MAAM,UAAU,GAAG,KAAK,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;YACpD,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;YACpD,MAAM,IAAI,GAAG,UAA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,CAC9D,CAAC;IAEF,KAAK,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC;gBAAE,SAAS,KAAK,CAAC;QAChD,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import MemoryMap from "nrf-intel-hex";
|
|
2
|
+
import { BluetoothDeviceWrapper } from "../bluetooth-device-wrapper";
|
|
3
|
+
import { ProgressCallback } from "../device";
|
|
4
|
+
export declare enum PartialFlashResult {
|
|
5
|
+
Success = "Success",
|
|
6
|
+
AttemptFullFlash = "AttemptFullFlash"
|
|
7
|
+
}
|
|
8
|
+
declare const partialFlash: (connection: BluetoothDeviceWrapper, memoryMap: MemoryMap, progress: ProgressCallback) => Promise<PartialFlashResult>;
|
|
9
|
+
export default partialFlash;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartialFlashResult = void 0;
|
|
4
|
+
const partial_flashing_service_1 = require("../partial-flashing-service");
|
|
5
|
+
const flashing_makecode_1 = require("./flashing-makecode");
|
|
6
|
+
const async_util_1 = require("../async-util");
|
|
7
|
+
const device_1 = require("../device");
|
|
8
|
+
var PartialFlashResult;
|
|
9
|
+
(function (PartialFlashResult) {
|
|
10
|
+
PartialFlashResult["Success"] = "Success";
|
|
11
|
+
PartialFlashResult["AttemptFullFlash"] = "AttemptFullFlash";
|
|
12
|
+
})(PartialFlashResult || (exports.PartialFlashResult = PartialFlashResult = {}));
|
|
13
|
+
const partialFlash = async (connection, memoryMap, progress) => {
|
|
14
|
+
const pf = new partial_flashing_service_1.PartialFlashingService(connection);
|
|
15
|
+
await pf.startNotifications();
|
|
16
|
+
const result = await connection.raceDisconnectAndTimeout(partialFlashInternal(connection, pf, memoryMap, progress), { timeout: 30_000, actionName: "partial flash" });
|
|
17
|
+
try {
|
|
18
|
+
await pf.stopNotifications();
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
// V1 disconnects quickly after a partial flash.
|
|
22
|
+
if (!(e instanceof async_util_1.DisconnectError)) {
|
|
23
|
+
connection.error("Error stopping notifications", e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
const partialFlashInternal = async (connection, pf, memoryMap, progress) => {
|
|
29
|
+
connection.log("Partial flash");
|
|
30
|
+
progress(device_1.ProgressStage.PartialFlashing);
|
|
31
|
+
try {
|
|
32
|
+
const deviceCodeRegion = await pf.getRegionInfo(partial_flashing_service_1.RegionId.MakeCode);
|
|
33
|
+
if (deviceCodeRegion === null) {
|
|
34
|
+
connection.log("Could not read code region");
|
|
35
|
+
return PartialFlashResult.AttemptFullFlash;
|
|
36
|
+
}
|
|
37
|
+
const deviceDalRegion = await pf.getRegionInfo(partial_flashing_service_1.RegionId.Dal);
|
|
38
|
+
if (deviceDalRegion === null) {
|
|
39
|
+
connection.log("Could not read DAL region");
|
|
40
|
+
return PartialFlashResult.AttemptFullFlash;
|
|
41
|
+
}
|
|
42
|
+
progress(device_1.ProgressStage.PartialFlashing);
|
|
43
|
+
const fileCodeRegion = (0, flashing_makecode_1.findMakeCodeRegionInMemoryMap)(memoryMap, deviceCodeRegion);
|
|
44
|
+
if (fileCodeRegion === null) {
|
|
45
|
+
connection.log("No partial flash data");
|
|
46
|
+
return PartialFlashResult.AttemptFullFlash;
|
|
47
|
+
}
|
|
48
|
+
if (fileCodeRegion.hash !== deviceDalRegion.hash) {
|
|
49
|
+
connection.log(`DAL hash comparison failed. Hex: ${fileCodeRegion.hash} vs device: ${deviceDalRegion.hash}`);
|
|
50
|
+
return PartialFlashResult.AttemptFullFlash;
|
|
51
|
+
}
|
|
52
|
+
if (deviceCodeRegion.start !== fileCodeRegion.start) {
|
|
53
|
+
connection.log("Code start address doesn't match");
|
|
54
|
+
return PartialFlashResult.AttemptFullFlash;
|
|
55
|
+
}
|
|
56
|
+
let nextPacketNumber = 0;
|
|
57
|
+
outer: for (let offset = fileCodeRegion.start; offset < fileCodeRegion.end;) {
|
|
58
|
+
const batchStartAddress = offset;
|
|
59
|
+
for (let packetInBatch = 0; packetInBatch < 4; ++packetInBatch) {
|
|
60
|
+
const packetNumber = nextPacketNumber++;
|
|
61
|
+
const packetDataOffset = offset + packetInBatch * 16;
|
|
62
|
+
if (packetInBatch < 3) {
|
|
63
|
+
await pf.writeFlash(memoryMap, batchStartAddress, packetDataOffset, packetNumber, packetInBatch);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const result = await pf.writeFlashForNotification(memoryMap, batchStartAddress, packetDataOffset, packetNumber, packetInBatch);
|
|
67
|
+
if (result === partial_flashing_service_1.PacketState.Retransmit) {
|
|
68
|
+
// Retry the whole 64 bytes.
|
|
69
|
+
connection.log(`Retransmit requested at offset ${offset}`);
|
|
70
|
+
continue outer;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
progress(device_1.ProgressStage.PartialFlashing, (offset - fileCodeRegion.start) /
|
|
74
|
+
(fileCodeRegion.end - fileCodeRegion.start));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
offset += 64;
|
|
79
|
+
}
|
|
80
|
+
await (0, async_util_1.delay)(100); // allow time for write to complete
|
|
81
|
+
await pf.writeEndOfFlashPacket();
|
|
82
|
+
await (0, async_util_1.delay)(100); // allow time for write to complete
|
|
83
|
+
progress(device_1.ProgressStage.PartialFlashing, 1);
|
|
84
|
+
return PartialFlashResult.Success;
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
connection.error("Partial flash failed", e);
|
|
88
|
+
if (e instanceof device_1.DeviceError) {
|
|
89
|
+
throw e;
|
|
90
|
+
}
|
|
91
|
+
throw new device_1.DeviceError({
|
|
92
|
+
code: "flash-partial-failed",
|
|
93
|
+
message: e instanceof Error ? e.message : String(e),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.default = partialFlash;
|
|
98
|
+
//# sourceMappingURL=flashing-partial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flashing-partial.js","sourceRoot":"","sources":["../../../lib/flashing/flashing-partial.ts"],"names":[],"mappings":";;;AAEA,0EAIqC;AACrC,2DAAoE;AACpE,8CAAuD;AACvD,sCAAyE;AAEzE,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,2DAAqC,CAAA;AACvC,CAAC,EAHW,kBAAkB,kCAAlB,kBAAkB,QAG7B;AAED,MAAM,YAAY,GAAG,KAAK,EACxB,UAAkC,EAClC,SAAoB,EACpB,QAA0B,EACG,EAAE;IAC/B,MAAM,EAAE,GAAG,IAAI,iDAAsB,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,EAAE,CAAC,kBAAkB,EAAE,CAAC;IAE9B,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,wBAAwB,CACtD,oBAAoB,CAAC,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,EACzD,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,CACjD,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,iBAAiB,EAAE,CAAC;IAC/B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,gDAAgD;QAChD,IAAI,CAAC,CAAC,CAAC,YAAY,4BAAe,CAAC,EAAE,CAAC;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AAC,GAAG,GAAG,cAAc,CAAC,KAAK,CAAC,CAC9C,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;YACD,MAAM,IAAI,EAAE,CAAC;QACf,CAAC;QAED,MAAM,IAAA,kBAAK,EAAC,GAAG,CAAC,CAAC,CAAC,mCAAmC;QACrD,MAAM,EAAE,CAAC,qBAAqB,EAAE,CAAC;QACjC,MAAM,IAAA,kBAAK,EAAC,GAAG,CAAC,CAAC,CAAC,mCAAmC;QACrD,QAAQ,CAAC,sBAAa,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;QAE3C,OAAO,kBAAkB,CAAC,OAAO,CAAC;IACpC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,UAAU,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,oBAAW,EAAE,CAAC;YAC7B,MAAM,CAAC,CAAC;QACV,CAAC;QACD,MAAM,IAAI,oBAAW,CAAC;YACpB,IAAI,EAAE,sBAAsB;YAC5B,OAAO,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V1 changes the service it offers in application/bootloader mode.
|
|
3
|
+
*
|
|
4
|
+
* We don't trust Android to have an up-to-date copy of services so will fall back
|
|
5
|
+
* to calling internal API via reflection if the desired/expected service is not
|
|
6
|
+
* listed.
|
|
7
|
+
*
|
|
8
|
+
* It might be that this is only needed for older versions of Android where we
|
|
9
|
+
* can't get service changed indications.
|
|
10
|
+
*/
|
|
11
|
+
export declare const refreshServicesForV1IfDesiredServiceMissing: (deviceId: string, desiredServiceUuid: string) => Promise<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.refreshServicesForV1IfDesiredServiceMissing = void 0;
|
|
4
|
+
const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
|
|
5
|
+
/**
|
|
6
|
+
* V1 changes the service it offers in application/bootloader mode.
|
|
7
|
+
*
|
|
8
|
+
* We don't trust Android to have an up-to-date copy of services so will fall back
|
|
9
|
+
* to calling internal API via reflection if the desired/expected service is not
|
|
10
|
+
* listed.
|
|
11
|
+
*
|
|
12
|
+
* It might be that this is only needed for older versions of Android where we
|
|
13
|
+
* can't get service changed indications.
|
|
14
|
+
*/
|
|
15
|
+
const refreshServicesForV1IfDesiredServiceMissing = async (deviceId, desiredServiceUuid) => {
|
|
16
|
+
const services = await bluetooth_le_1.BleClient.getServices(deviceId);
|
|
17
|
+
const deviceHasService = services.some((s) => s.uuid === desiredServiceUuid);
|
|
18
|
+
if (!deviceHasService) {
|
|
19
|
+
// On Android this does use the refresh reflection hack.
|
|
20
|
+
await bluetooth_le_1.BleClient.discoverServices(deviceId);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.refreshServicesForV1IfDesiredServiceMissing = refreshServicesForV1IfDesiredServiceMissing;
|
|
24
|
+
//# sourceMappingURL=flashing-v1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flashing-v1.js","sourceRoot":"","sources":["../../../lib/flashing/flashing-v1.ts"],"names":[],"mappings":";;;AAAA,oEAA8D;AAE9D;;;;;;;;;GASG;AACI,MAAM,2CAA2C,GAAG,KAAK,EAC9D,QAAgB,EAChB,kBAA0B,EAC1B,EAAE;IACF,MAAM,QAAQ,GAAG,MAAM,wBAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACvD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC;IAC7E,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,wDAAwD;QACxD,MAAM,wBAAS,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,2CAA2C,+CAUtD"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BluetoothDeviceWrapper } from "../bluetooth-device-wrapper";
|
|
2
|
+
import { BoardVersion, ProgressCallback } from "../device";
|
|
3
|
+
export declare function flashDfu(connection: BluetoothDeviceWrapper, boardVersion: BoardVersion, appBin: Uint8Array, progress: ProgressCallback): Promise<void>;
|