incyclist-devices 2.3.0-beta.1 → 2.3.0-beta.2
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/lib/ble/base/adapter.js
CHANGED
|
@@ -49,7 +49,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
49
49
|
}
|
|
50
50
|
waitForPeripheral() {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
this.logEvent({ message: 'waiting for sensor ...' });
|
|
52
|
+
this.logEvent({ message: 'waiting for sensor ...', device: this.getName(), interface: this.getInterface() });
|
|
53
53
|
const iface = interface_factory_1.BleMultiTransportInterfaceFactory.createInstance(this.getInterface());
|
|
54
54
|
const peripheral = yield iface.waitForPeripheral(this.settings);
|
|
55
55
|
this.updateSensor(peripheral);
|
|
@@ -121,7 +121,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
121
121
|
if (this.isStopped() || this.isPaused())
|
|
122
122
|
return;
|
|
123
123
|
try {
|
|
124
|
-
this.logEvent({ message: 'refreshDeviceData', data: this.deviceData, isControllable: this.isControllable() });
|
|
124
|
+
this.logEvent({ message: 'refreshDeviceData', device: this.getName(), interface: this.getInterface(), data: this.deviceData, isControllable: this.isControllable() });
|
|
125
125
|
if (this.isControllable()) {
|
|
126
126
|
const mappedData = this.mapData(this.deviceData);
|
|
127
127
|
const incyclistData = this.getCyclingMode().updateData(mappedData);
|
|
@@ -133,7 +133,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
133
133
|
this.emitData(this.data);
|
|
134
134
|
}
|
|
135
135
|
catch (err) {
|
|
136
|
-
this.logEvent({ message: 'error', fn: 'refreshDeviceData', error: err.message, stack: err.stack });
|
|
136
|
+
this.logEvent({ message: 'error', fn: 'refreshDeviceData', device: this.getName(), interface: this.getInterface(), error: err.message, stack: err.stack });
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
onDeviceData(deviceData) {
|
|
@@ -143,7 +143,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
143
143
|
this.deviceData = Object.assign({}, deviceData);
|
|
144
144
|
if (!this.canEmitData())
|
|
145
145
|
return;
|
|
146
|
-
this.logEvent({ message: 'onDeviceData', data: deviceData, isControllable: this.isControllable() });
|
|
146
|
+
this.logEvent({ message: 'onDeviceData', device: this.getName(), interface: this.getInterface(), data: deviceData, isControllable: this.isControllable() });
|
|
147
147
|
if (this.isControllable()) {
|
|
148
148
|
const mappedData = this.mapData(deviceData);
|
|
149
149
|
const incyclistData = this.getCyclingMode().updateData(mappedData);
|
|
@@ -155,7 +155,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
155
155
|
this.emitData(this.data);
|
|
156
156
|
}
|
|
157
157
|
catch (err) {
|
|
158
|
-
this.logEvent({ message: 'Error', fn: 'onDeviceData', error: err.message, stack: err.stack });
|
|
158
|
+
this.logEvent({ message: 'Error', fn: 'onDeviceData', device: this.getName(), interface: this.getInterface(), error: err.message, stack: err.stack });
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
mapData(deviceData) {
|
|
@@ -240,11 +240,11 @@ class BleAdapter extends adpater_1.default {
|
|
|
240
240
|
errorOnTimeout: false,
|
|
241
241
|
timeout: startupTimeout
|
|
242
242
|
});
|
|
243
|
-
this.logEvent({ message: 'wait for sensor data', device: this.getName() });
|
|
243
|
+
this.logEvent({ message: 'wait for sensor data', device: this.getName(), interface: this.getInterface() });
|
|
244
244
|
const hasData = yield waitTask.run();
|
|
245
245
|
clearInterval(iv);
|
|
246
246
|
if (hasData)
|
|
247
|
-
this.logEvent({ message: 'sensor data received', device: this.getName() });
|
|
247
|
+
this.logEvent({ message: 'sensor data received', device: this.getName(), interface: this.getInterface() });
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
250
|
checkCapabilities() {
|
|
@@ -264,22 +264,22 @@ class BleAdapter extends adpater_1.default {
|
|
|
264
264
|
return this.started;
|
|
265
265
|
}
|
|
266
266
|
if (preCheckResult === 'connection-failed') {
|
|
267
|
-
this.logEvent({ message: 'start result: error', error: 'could not start device, reason:could not connect', protocol: this.getProtocolName() });
|
|
267
|
+
this.logEvent({ message: 'start result: error', error: 'could not start device, reason:could not connect', device: this.getName(), interface: this.getInterface(), protocol: this.getProtocolName() });
|
|
268
268
|
yield (0, utils_1.resolveNextTick)();
|
|
269
269
|
return false;
|
|
270
270
|
}
|
|
271
|
-
this.logEvent({ message: 'starting device', device: this.getName(), props, isStarted: this.started });
|
|
271
|
+
this.logEvent({ message: 'starting device', device: this.getName(), interface: this.getInterface(), props, isStarted: this.started });
|
|
272
272
|
try {
|
|
273
273
|
const connected = yield this.startSensor();
|
|
274
274
|
if (connected) {
|
|
275
|
-
this.logEvent({ message: 'peripheral connected', device: this.getName(), props });
|
|
275
|
+
this.logEvent({ message: 'peripheral connected', device: this.getName(), interface: this.getInterface(), props });
|
|
276
276
|
}
|
|
277
277
|
else {
|
|
278
|
-
this.logEvent({ message: 'peripheral connection failed', device: this.getName(), reason: 'unknown', props });
|
|
278
|
+
this.logEvent({ message: 'peripheral connection failed', device: this.getName(), interface: this.getInterface(), reason: 'unknown', props });
|
|
279
279
|
return false;
|
|
280
280
|
}
|
|
281
281
|
yield this.waitForInitialData(timeout);
|
|
282
|
-
|
|
282
|
+
this.checkCapabilities();
|
|
283
283
|
if (this.hasCapability(types_1.IncyclistCapability.Control))
|
|
284
284
|
yield this.initControl(startProps);
|
|
285
285
|
this.resetData();
|
|
@@ -290,7 +290,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
290
290
|
return true;
|
|
291
291
|
}
|
|
292
292
|
catch (err) {
|
|
293
|
-
this.logEvent({ message: 'start result: error', error: err.message, protocol: this.getProtocolName() });
|
|
293
|
+
this.logEvent({ message: 'start result: error', error: err.message, device: this.getName(), interface: this.getInterface(), protocol: this.getProtocolName() });
|
|
294
294
|
return false;
|
|
295
295
|
}
|
|
296
296
|
});
|
|
@@ -315,14 +315,14 @@ class BleAdapter extends adpater_1.default {
|
|
|
315
315
|
}
|
|
316
316
|
stop() {
|
|
317
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
318
|
-
this.logEvent({ message: 'stopping device', device: this.getName() });
|
|
318
|
+
this.logEvent({ message: 'stopping device', device: this.getName(), interface: this.getInterface() });
|
|
319
319
|
if (this.isStarting()) {
|
|
320
320
|
yield this.startTask.stop();
|
|
321
321
|
}
|
|
322
322
|
let reason = 'unknown';
|
|
323
323
|
let stopped = false;
|
|
324
324
|
if (!this.getComms()) {
|
|
325
|
-
this.logEvent({ message: 'device stopped - not started yet', device: this.getName() });
|
|
325
|
+
this.logEvent({ message: 'device stopped - not started yet', device: this.getName(), interface: this.getInterface() });
|
|
326
326
|
return true;
|
|
327
327
|
}
|
|
328
328
|
this.getComms().reset();
|
|
@@ -333,10 +333,10 @@ class BleAdapter extends adpater_1.default {
|
|
|
333
333
|
reason = err.message;
|
|
334
334
|
}
|
|
335
335
|
if (stopped) {
|
|
336
|
-
this.logEvent({ message: 'device stopped', device: this.getName() });
|
|
336
|
+
this.logEvent({ message: 'device stopped', device: this.getName(), interface: this.getInterface() });
|
|
337
337
|
}
|
|
338
338
|
else {
|
|
339
|
-
this.logEvent({ message: 'stopping device failed', device: this.getName(), reason });
|
|
339
|
+
this.logEvent({ message: 'stopping device failed', device: this.getName(), interface: this.getInterface(), reason });
|
|
340
340
|
}
|
|
341
341
|
this.started = false;
|
|
342
342
|
this.stopped = true;
|
package/lib/ble/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.uuid = uuid;
|
|
|
6
6
|
exports.matches = matches;
|
|
7
7
|
exports.getPeripheralInfo = getPeripheralInfo;
|
|
8
8
|
exports.getCharachteristicsInfo = getCharachteristicsInfo;
|
|
9
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
9
10
|
function mapLegacyProfile(profile) {
|
|
10
11
|
switch (profile) {
|
|
11
12
|
case 'Smart Trainer': return { profile: 'Smart Trainer', protocol: 'fm' };
|
|
@@ -74,7 +75,15 @@ const parseUUID = (str) => {
|
|
|
74
75
|
};
|
|
75
76
|
exports.parseUUID = parseUUID;
|
|
76
77
|
const beautifyUUID = (str, withX = false) => {
|
|
77
|
-
|
|
78
|
+
let uuid;
|
|
79
|
+
try {
|
|
80
|
+
uuid = (0, exports.parseUUID)(str);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
const logger = new gd_eventlog_1.EventLogger('Incyclist');
|
|
84
|
+
logger.logEvent({ message: 'beautifyUUID error', uuid: str, error: err.message });
|
|
85
|
+
return str;
|
|
86
|
+
}
|
|
78
87
|
const parts = [
|
|
79
88
|
uuid.substring(0, 8),
|
|
80
89
|
uuid.substring(8, 12),
|
|
@@ -57,7 +57,7 @@ export default class DirectConnectInterface extends EventEmitter implements IBle
|
|
|
57
57
|
interface: string;
|
|
58
58
|
name: string;
|
|
59
59
|
}[];
|
|
60
|
-
protected addService(service: MulticastDnsAnnouncement): void;
|
|
60
|
+
protected addService(service: MulticastDnsAnnouncement, source?: string): void;
|
|
61
61
|
protected find(service: MulticastDnsAnnouncement): Announcement;
|
|
62
62
|
protected getAll(): Announcement[];
|
|
63
63
|
setDebug(enabled: boolean): void;
|
|
@@ -108,10 +108,10 @@ class DirectConnectInterface extends events_1.default {
|
|
|
108
108
|
if (!reconnect)
|
|
109
109
|
this.logEvent({ message: 'starting multicast DNS scan ..' });
|
|
110
110
|
this.getBinding().mdns.find(null, (service) => {
|
|
111
|
-
this.addService(service);
|
|
111
|
+
this.addService(service, 'unfiltered');
|
|
112
112
|
});
|
|
113
113
|
this.getBinding().mdns.find({ type: DC_TYPE }, (service) => {
|
|
114
|
-
this.addService(service);
|
|
114
|
+
this.addService(service, DC_TYPE);
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
catch (err) {
|
|
@@ -228,7 +228,7 @@ class DirectConnectInterface extends events_1.default {
|
|
|
228
228
|
buildDeviceSettings(matching = []) {
|
|
229
229
|
return matching.map((name) => ({ interface: DirectConnectInterface.INTERFACE_NAME, name }));
|
|
230
230
|
}
|
|
231
|
-
addService(service) {
|
|
231
|
+
addService(service, source) {
|
|
232
232
|
var _a, _b;
|
|
233
233
|
try {
|
|
234
234
|
service.transport = this.getName();
|
|
@@ -238,7 +238,7 @@ class DirectConnectInterface extends events_1.default {
|
|
|
238
238
|
this.services[idx] = { ts: Date.now(), service };
|
|
239
239
|
}
|
|
240
240
|
else {
|
|
241
|
-
this.logEvent({ message: 'device announced', device: service.name, announcement: service });
|
|
241
|
+
this.logEvent({ message: 'device announced', device: service.name, announcement: service, source });
|
|
242
242
|
this.services.push({ ts: Date.now(), service });
|
|
243
243
|
if (service.type !== DC_TYPE && ((_a = service.serviceUUIDs) === null || _a === void 0 ? void 0 : _a.length) === 0)
|
|
244
244
|
return;
|
|
@@ -82,12 +82,19 @@ class DirectConnectPeripheral {
|
|
|
82
82
|
const seqNo = this.getNextSeqNo();
|
|
83
83
|
const message = new messages_1.DiscoverServiceMessage();
|
|
84
84
|
const request = message.createRequest(seqNo, {});
|
|
85
|
+
let response;
|
|
85
86
|
this.logEvent({ message: 'DiscoverServices request', path: this.getPath(), raw: request.toString('hex') });
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
try {
|
|
88
|
+
response = yield this.send(seqNo, request);
|
|
89
|
+
const res = message.parseResponse(response);
|
|
90
|
+
const uuids = res.body.serviceDefinitions.map(s => (0, utils_1.beautifyUUID)(s.serviceUUID));
|
|
91
|
+
this.logEvent({ message: 'DiscoverServices response', path: this.getPath(), uuids, raw: request.toString('hex') });
|
|
92
|
+
return res.body.serviceDefinitions.map(s => s.serviceUUID);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
this.logEvent({ message: 'DiscoverServices failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: err.message });
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
91
98
|
});
|
|
92
99
|
}
|
|
93
100
|
discoverCharacteristics(serviceUUID) {
|
|
@@ -95,13 +102,20 @@ class DirectConnectPeripheral {
|
|
|
95
102
|
const seqNo = this.getNextSeqNo();
|
|
96
103
|
const message = new messages_1.DiscoverCharacteristicsMessage();
|
|
97
104
|
const request = message.createRequest(seqNo, { serviceUUID: (0, utils_1.parseUUID)(serviceUUID) });
|
|
105
|
+
let response;
|
|
98
106
|
this.logEvent({ message: 'DiscoverCharacteritics request', path: this.getPath(), service: (0, utils_1.beautifyUUID)(serviceUUID), raw: request.toString('hex') });
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
try {
|
|
108
|
+
response = yield this.send(seqNo, request);
|
|
109
|
+
const res = message.parseResponse(response);
|
|
110
|
+
const service = (0, utils_1.beautifyUUID)(res.body.serviceUUID);
|
|
111
|
+
const characteristics = res.body.characteristicDefinitions.map(cd => `${(0, utils_1.beautifyUUID)(cd.characteristicUUID)}:${cd.properties.join('/')}`);
|
|
112
|
+
this.logEvent({ message: 'DiscoverCharacteritics response', path: this.getPath(), service, characteristics, raw: request.toString('hex') });
|
|
113
|
+
return res.body.characteristicDefinitions.map(c => ({ uuid: c.characteristicUUID, properties: c.properties }));
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
this.logEvent({ message: 'DiscoverCharacteritics failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: err.message });
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
105
119
|
});
|
|
106
120
|
}
|
|
107
121
|
subscribe(characteristicUUID, callback) {
|
|
@@ -109,19 +123,26 @@ class DirectConnectPeripheral {
|
|
|
109
123
|
const seqNo = this.getNextSeqNo();
|
|
110
124
|
const message = new messages_1.EnableCharacteristicNotificationsMessage();
|
|
111
125
|
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), enable: true });
|
|
126
|
+
let response;
|
|
112
127
|
this.logEvent({ message: 'EnableCharacteristicNotifications request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID), enabled: true, raw: request.toString('hex') });
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
try {
|
|
129
|
+
response = yield this.send(seqNo, request);
|
|
130
|
+
const res = message.parseResponse(response);
|
|
131
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: request.toString('hex') });
|
|
132
|
+
const confirmed = res.body.characteristicUUID;
|
|
133
|
+
if ((0, utils_1.parseUUID)(confirmed) === (0, utils_1.parseUUID)(characteristicUUID)) {
|
|
134
|
+
this.subscribed.push(characteristicUUID);
|
|
135
|
+
this.eventEmitter.on((0, utils_1.parseUUID)(characteristicUUID), (data) => {
|
|
136
|
+
callback(characteristicUUID, data);
|
|
137
|
+
});
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: err.message });
|
|
144
|
+
return false;
|
|
123
145
|
}
|
|
124
|
-
return false;
|
|
125
146
|
});
|
|
126
147
|
}
|
|
127
148
|
unsubscribe(characteristicUUID) {
|
|
@@ -130,17 +151,24 @@ class DirectConnectPeripheral {
|
|
|
130
151
|
const seqNo = this.getNextSeqNo();
|
|
131
152
|
const message = new messages_1.EnableCharacteristicNotificationsMessage();
|
|
132
153
|
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), enable: false });
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
let response;
|
|
155
|
+
try {
|
|
156
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID), enabled: false, raw: request.toString('hex') });
|
|
157
|
+
response = yield this.send(seqNo, request);
|
|
158
|
+
const res = message.parseResponse(response);
|
|
159
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: request.toString('hex') });
|
|
160
|
+
const confirmed = res.body.characteristicUUID;
|
|
161
|
+
if ((0, utils_1.parseUUID)(confirmed) === (0, utils_1.parseUUID)(characteristicUUID)) {
|
|
162
|
+
this.subscribed.splice(this.subscribed.indexOf(characteristicUUID), 1);
|
|
163
|
+
this.eventEmitter.removeAllListeners((0, utils_1.parseUUID)(characteristicUUID));
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: err.message });
|
|
170
|
+
return false;
|
|
142
171
|
}
|
|
143
|
-
return false;
|
|
144
172
|
}
|
|
145
173
|
catch (err) {
|
|
146
174
|
this.logEvent({ messsage: 'EnableCharacteristicNotifications failed', reason: err.message });
|
|
@@ -158,9 +186,8 @@ class DirectConnectPeripheral {
|
|
|
158
186
|
catch (err) {
|
|
159
187
|
this.logEvent({ message: 'could not discover services', reason: err.message });
|
|
160
188
|
}
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
const service = services[i];
|
|
189
|
+
for (const element of services) {
|
|
190
|
+
const service = element;
|
|
164
191
|
let characteristics = [];
|
|
165
192
|
try {
|
|
166
193
|
characteristics = yield this.discoverCharacteristics(service);
|
|
@@ -171,8 +198,8 @@ class DirectConnectPeripheral {
|
|
|
171
198
|
}
|
|
172
199
|
if (!(characteristics === null || characteristics === void 0 ? void 0 : characteristics.length))
|
|
173
200
|
continue;
|
|
174
|
-
for (
|
|
175
|
-
const characteristic =
|
|
201
|
+
for (const element of characteristics) {
|
|
202
|
+
const characteristic = element;
|
|
176
203
|
if (characteristic.properties.includes('notify'))
|
|
177
204
|
yield this.subscribe(characteristic.uuid, callback);
|
|
178
205
|
}
|
|
@@ -188,14 +215,14 @@ class DirectConnectPeripheral {
|
|
|
188
215
|
subscribeSelected(characteristics, callback) {
|
|
189
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
217
|
const retry = [];
|
|
191
|
-
for (
|
|
192
|
-
const uuid =
|
|
218
|
+
for (const element of characteristics) {
|
|
219
|
+
const uuid = element;
|
|
193
220
|
const success = yield this.subscribe(uuid, callback);
|
|
194
221
|
if (!success)
|
|
195
222
|
retry.push(uuid);
|
|
196
223
|
}
|
|
197
|
-
for (
|
|
198
|
-
const c =
|
|
224
|
+
for (const element of retry) {
|
|
225
|
+
const c = element;
|
|
199
226
|
yield this.subscribe(c.uuid, callback);
|
|
200
227
|
}
|
|
201
228
|
return true;
|
|
@@ -216,13 +243,20 @@ class DirectConnectPeripheral {
|
|
|
216
243
|
const seqNo = this.getNextSeqNo();
|
|
217
244
|
const message = new messages_1.ReadCharacteristicMessage();
|
|
218
245
|
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID) });
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
246
|
+
let response;
|
|
247
|
+
try {
|
|
248
|
+
this.logEvent({ message: 'ReadCharacteristic request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID), raw: request.toString('hex') });
|
|
249
|
+
response = yield this.send(seqNo, request);
|
|
250
|
+
const res = message.parseResponse(response);
|
|
251
|
+
this.logEvent({ message: 'ReadCharacteristic response', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID),
|
|
252
|
+
data: Buffer.from(res.body.characteristicData).toString('hex'),
|
|
253
|
+
raw: request.toString('hex') });
|
|
254
|
+
return Buffer.from(res.body.characteristicData);
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
this.logEvent({ message: 'ReadCharacteristic failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: err.message });
|
|
258
|
+
return Buffer.from([]);
|
|
259
|
+
}
|
|
226
260
|
});
|
|
227
261
|
}
|
|
228
262
|
write(characteristicUUID, data, options) {
|
|
@@ -237,19 +271,23 @@ class DirectConnectPeripheral {
|
|
|
237
271
|
const seqNo = this.getNextSeqNo();
|
|
238
272
|
const message = new messages_1.WriteCharacteristicMessage();
|
|
239
273
|
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), characteristicData: data });
|
|
274
|
+
let response;
|
|
275
|
+
let characteristic = characteristicUUID;
|
|
240
276
|
this.logEvent({ message: 'WriteCharacteristic request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID),
|
|
241
277
|
data: data.toString('hex'),
|
|
242
278
|
raw: request.toString('hex') });
|
|
243
|
-
this.send(seqNo, request).then((
|
|
279
|
+
this.send(seqNo, request).then((data) => {
|
|
280
|
+
response = data;
|
|
244
281
|
const res = message.parseResponse(response);
|
|
245
|
-
|
|
282
|
+
characteristic = (0, utils_1.beautifyUUID)(res.body.characteristicUUID);
|
|
283
|
+
this.logEvent({ message: 'WriteCharacteristic response', path: this.getPath(), characteristic,
|
|
246
284
|
raw: request.toString('hex') });
|
|
247
285
|
if (options === null || options === void 0 ? void 0 : options.withoutResponse) {
|
|
248
286
|
resolve(Buffer.from([]));
|
|
249
287
|
}
|
|
250
288
|
})
|
|
251
289
|
.catch(err => {
|
|
252
|
-
this.logEvent({ message: 'WriteCharacteristic
|
|
290
|
+
this.logEvent({ message: 'WriteCharacteristic failed', path: this.getPath(), characteristic, raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: err.message });
|
|
253
291
|
});
|
|
254
292
|
});
|
|
255
293
|
});
|