@rhizomatics/signalk-einklabel-plugin 1.3.0-beta4 → 1.3.0-beta5

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.
@@ -34,6 +34,14 @@ export declare function nodeBleBackend(): BleBackend;
34
34
  * plugin quietly rediscovering it the way the direct-BlueZ backend already does.
35
35
  */
36
36
  export declare function ensureDeviceVisible(bleApi: BLEApi, pluginId: string, address: string, timeoutMs: number): Promise<void>;
37
+ /**
38
+ * Runs `fn` only once every earlier caller has finished, so paints to different devices never hold
39
+ * BLE Manager GATT slots at the same time. The server's local provider defaults to just a couple of
40
+ * slots shared with every other BLE plugin (e.g. Bluetti), so two concurrent connects can leave the
41
+ * second with none free - which the server reports as the misleading "No provider with GATT support
42
+ * can see <mac>".
43
+ */
44
+ export declare function exclusiveBleManagerAccess<T>(fn: () => Promise<T>): Promise<T>;
37
45
  /**
38
46
  * `bleApi.connectGATT()` has no timeout of its own, same story as node-ble's `Device#connect()` (see
39
47
  * `connectWithTimeout` in `bleDiscovery.ts`) - races it against `timeoutMs`.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withSessionWatchdog = withSessionWatchdog;
4
4
  exports.nodeBleBackend = nodeBleBackend;
5
5
  exports.ensureDeviceVisible = ensureDeviceVisible;
6
+ exports.exclusiveBleManagerAccess = exclusiveBleManagerAccess;
6
7
  exports.bleApiBackend = bleApiBackend;
7
8
  const pluginVersion_1 = require("../pluginVersion");
8
9
  const bleDiscovery_1 = require("./bleDiscovery");
@@ -167,6 +168,19 @@ async function ensureDeviceVisible(bleApi, pluginId, address, timeoutMs) {
167
168
  throw new Error(`device ${address} isn't visible to the SignalK BLE Manager yet (out of range, asleep, or never seen) after waiting ${timeoutMs}ms`);
168
169
  }
169
170
  }
171
+ let bleManagerQueue = Promise.resolve();
172
+ /**
173
+ * Runs `fn` only once every earlier caller has finished, so paints to different devices never hold
174
+ * BLE Manager GATT slots at the same time. The server's local provider defaults to just a couple of
175
+ * slots shared with every other BLE plugin (e.g. Bluetti), so two concurrent connects can leave the
176
+ * second with none free - which the server reports as the misleading "No provider with GATT support
177
+ * can see <mac>".
178
+ */
179
+ function exclusiveBleManagerAccess(fn) {
180
+ const run = bleManagerQueue.then(fn, fn);
181
+ bleManagerQueue = run.catch(() => { });
182
+ return run;
183
+ }
170
184
  /**
171
185
  * `bleApi.connectGATT()` has no timeout of its own, same story as node-ble's `Device#connect()` (see
172
186
  * `connectWithTimeout` in `bleDiscovery.ts`) - races it against `timeoutMs`.
@@ -345,15 +345,16 @@ async function considerRepaint(app, config, device, target, state, getApiUrl) {
345
345
  bitmap = await renderer.render(fallbackPath, { meta: { repainted: new Date().toISOString(), plugin_version: pluginVersion_1.PLUGIN_VERSION, description: device.description ?? "" } }, width, height, templatesDir, config_1.BUNDLED_TEMPLATES_DIR);
346
346
  }
347
347
  const connectTimeoutMs = config.paintConnectTimeoutSeconds * 1000;
348
- await (0, bleDiscovery_1.withRetries)(config.paintRetries, async (attempt) => {
348
+ const gattBackend = config.useBleApi && app.bleApi ? (0, bleBackend_1.bleApiBackend)(app.bleApi, pluginVersion_1.PLUGIN_NAME) : undefined;
349
+ const paintWithRetries = () => (0, bleDiscovery_1.withRetries)(config.paintRetries, async (attempt) => {
349
350
  if (attempt > 1) {
350
351
  app.debug(`${label}: attempting paint ${attempt}/${config.paintRetries}`);
351
352
  }
352
353
  const startedAt = Date.now();
353
- const gattBackend = config.useBleApi && app.bleApi ? (0, bleBackend_1.bleApiBackend)(app.bleApi, pluginVersion_1.PLUGIN_NAME) : undefined;
354
354
  await driver.paint(bitmap, { address, aesKey: device.aesKey, connectTimeoutMs, reframe: device.reframe, gattBackend });
355
355
  paintDurationMs = Date.now() - startedAt;
356
356
  });
357
+ await (gattBackend ? (0, bleBackend_1.exclusiveBleManagerAccess)(paintWithRetries) : paintWithRetries());
357
358
  (0, discoveredDevicesStore_1.touchDiscoveredDevice)(app, { address, vendor: target.vendor, pid: target.pid, hwVersion: target.hwVersion, metadata });
358
359
  // Only a successful render counts as "repainted" for dedup/catch-up purposes - a failure must not be
359
360
  // recorded here (see this function's doc comment on why).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizomatics/signalk-einklabel-plugin",
3
- "version": "1.3.0-beta4",
3
+ "version": "1.3.0-beta5",
4
4
  "description": "Display SignalK data on eInk Electronic Shelf Labels, includes working examples for tide clock and watch schedule.",
5
5
  "keywords": [
6
6
  "ble",