Skip to content

Commit 236ad56

Browse files
committed
firmware/sagas: reduce BLE firmware burst size
Mac users have recently been reporting failed firmware updates due to the hub disconnecting during the update process. This is likely due to the Mac sending packets faster than the hub can handle. This changes the arbitrary BLE firmware burst size from 10 to 8 to reduce the chance of the hub getting overwhelmed. Fixes: pybricks/support#1787
1 parent 6605c72 commit 236ad56

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
## [Unreleased]
66

7+
### Fixed
8+
- Fixed Bluetooth firmware updates sometimes failing on macOS. ([support#1787])
9+
10+
[[support#1787]]: https://github.com/pybricks/support/issues/1787
11+
712
## [2.3.0-beta.1] - 2023-11-24
813

914
### Changed

src/firmware/sagas.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2021-2022 The Pybricks Authors
2+
// Copyright (c) 2021-2024 The Pybricks Authors
33

44
import {
55
FirmwareMetadata,
@@ -200,12 +200,12 @@ describe('flashFirmware', () => {
200200
break;
201201
}
202202

203-
if (count % 10 === 0) {
203+
if (count % 8 === 0) {
204204
action = await saga.take();
205205
expect(action).toEqual(checksumRequest(++id));
206206

207207
saga.put(didRequest(id));
208-
saga.put(checksumResponse(0));
208+
saga.put(checksumResponse(0xee));
209209
}
210210
}
211211

@@ -366,7 +366,7 @@ describe('flashFirmware', () => {
366366
break;
367367
}
368368

369-
if (count % 10 === 0) {
369+
if (count % 8 === 0) {
370370
action = await saga.take();
371371
expect(action).toEqual(checksumRequest(++id));
372372

@@ -1331,12 +1331,12 @@ describe('flashFirmware', () => {
13311331
break;
13321332
}
13331333

1334-
if (count % 10 === 0) {
1334+
if (count % 8 === 0) {
13351335
action = await saga.take();
13361336
expect(action).toEqual(checksumRequest(++id));
13371337

13381338
saga.put(didRequest(id));
1339-
saga.put(checksumResponse(0));
1339+
saga.put(checksumResponse(0xeb));
13401340
}
13411341
}
13421342

@@ -1507,12 +1507,12 @@ describe('flashFirmware', () => {
15071507
break;
15081508
}
15091509

1510-
if (count % 10 === 0) {
1510+
if (count % 8 === 0) {
15111511
action = await saga.take();
15121512
expect(action).toEqual(checksumRequest(++id));
15131513

15141514
saga.put(didRequest(id));
1515-
saga.put(checksumResponse(0));
1515+
saga.put(checksumResponse(0xeb));
15161516
}
15171517
}
15181518

@@ -1689,7 +1689,7 @@ describe('flashFirmware', () => {
16891689
break;
16901690
}
16911691

1692-
if (count % 10 === 0) {
1692+
if (count % 8 === 0) {
16931693
action = await saga.take();
16941694
expect(action).toEqual(checksumRequest(++id));
16951695

@@ -2254,12 +2254,12 @@ describe('flashFirmware', () => {
22542254
break;
22552255
}
22562256

2257-
if (count % 10 === 0) {
2257+
if (count % 8 === 0) {
22582258
action = await saga.take();
22592259
expect(action).toEqual(checksumRequest(++id));
22602260

22612261
saga.put(didRequest(id));
2262-
saga.put(checksumResponse(0));
2262+
saga.put(checksumResponse(0xeb));
22632263
}
22642264
}
22652265

src/firmware/sagas.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2020-2022 The Pybricks Authors
2+
// Copyright (c) 2020-2024 The Pybricks Authors
33

44
import {
55
FirmwareReader,
@@ -529,11 +529,11 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
529529
break;
530530
}
531531

532-
// Request checksum every 10 packets to prevent buffer overrun on
532+
// Request checksum every 8 packets to prevent buffer overrun on
533533
// the hub because of sending too much data at once. The actual
534534
// number of packets that can be queued in the Bluetooth chip on
535535
// the hub is not known and could vary by device.
536-
if (count % 10 === 0) {
536+
if (count % 8 === 0) {
537537
const checksumAction = yield* put(checksumRequest(nextMessageId()));
538538

539539
const { response } = yield* all({
@@ -543,7 +543,7 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
543543

544544
if (response.checksum !== runningChecksum) {
545545
// istanbul ignore next
546-
if (process.env.NODE_ENV !== 'test') {
546+
if (process.env.NODE_ENV === 'test') {
547547
console.error(
548548
`checksum: got ${hex(response.checksum, 2)} expected ${hex(
549549
runningChecksum,

0 commit comments

Comments
 (0)