Skip to content

Commit 1a7663a

Browse files
committed
ble-pybricks-service: rename slot to progId
Rename the requested program ID from slot to progId and the running program ID to runningProgId. These can also have the value of built-in programs, not just slot numbers, so it doesn't make sense to call them slots.
1 parent 0aeb53d commit 1a7663a

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

src/ble-pybricks-service/actions.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2021-2024 The Pybricks Authors
2+
// Copyright (c) 2021-2025 The Pybricks Authors
33
//
44
// Actions for Bluetooth Low Energy Pybricks service
55

@@ -81,15 +81,17 @@ export const sendLegacyStartReplCommand = createAction((id: number) => ({
8181
/**
8282
* Action that requests a start user program to be sent.
8383
* @param id Unique identifier for this transaction.
84-
* @param slot The slot number of the user program to start.
84+
* @param progId The program ID number of the user program to start.
8585
*
8686
* @since Pybricks Profile v1.4.0
8787
*/
88-
export const sendStartUserProgramCommand = createAction((id: number, slot: number) => ({
89-
type: 'blePybricksServiceCommand.action.sendStartUserProgram',
90-
id,
91-
slot,
92-
}));
88+
export const sendStartUserProgramCommand = createAction(
89+
(id: number, progId: number) => ({
90+
type: 'blePybricksServiceCommand.action.sendStartUserProgram',
91+
id,
92+
progId,
93+
}),
94+
);
9395

9496
/**
9597
* Action that requests to write user program metadata.
@@ -180,13 +182,13 @@ export const didFailToSendCommand = createAction((id: number, error: Error) => (
180182
/**
181183
* Action that represents a status report event received from the hub.
182184
* @param statusFlags The status flags.
183-
* @param slot The slot number of the user program that is running.
185+
* @param progId The ID number of the user program that is running.
184186
*/
185187
export const didReceiveStatusReport = createAction(
186-
(statusFlags: number, slot: number) => ({
188+
(statusFlags: number, runningProgId: number) => ({
187189
type: 'blePybricksServiceEvent.action.didReceiveStatusReport',
188190
statusFlags,
189-
slot,
191+
runningProgId,
190192
}),
191193
);
192194

src/ble-pybricks-service/protocol.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2020-2024 The Pybricks Authors
2+
// Copyright (c) 2020-2025 The Pybricks Authors
33
//
44
// Definitions related to the Pybricks Bluetooth low energy GATT service.
55

@@ -112,17 +112,17 @@ export function createStopUserProgramCommand(): Uint8Array {
112112
* Creates a {@link CommandType.StartUserProgram} message.
113113
*
114114
* Parameters:
115-
* - slot: Program identifier (one byte). Slots 0--127 are reserved for
115+
* - progId: Program identifier (one byte). Slots 0--127 are reserved for
116116
* downloaded user programs. Slots 128--255 are for builtin user programs.
117117
*
118118
* @since Pybricks Profile v1.4.0
119119
*/
120120
export function createStartUserProgramCommand(
121-
slot: number | BuiltinProgramId,
121+
progId: number | BuiltinProgramId,
122122
): Uint8Array {
123123
const msg = new Uint8Array(2);
124124
msg[0] = CommandType.StartUserProgram;
125-
msg[1] = slot;
125+
msg[1] = progId;
126126
return msg;
127127
}
128128

@@ -303,15 +303,18 @@ export function getEventType(msg: DataView): EventType {
303303
/**
304304
* Parses the payload of a status report message.
305305
* @param msg The raw message data.
306-
* @returns The status as bit flags and the slot number of the running program.
306+
* @returns The status as bit flags and the program ID number of the running program.
307307
*
308308
* @since Pybricks Profile v1.0.0 - changed in v1.4.0
309309
*/
310-
export function parseStatusReport(msg: DataView): { flags: number; slot: number } {
310+
export function parseStatusReport(msg: DataView): {
311+
flags: number;
312+
runningProgId: number;
313+
} {
311314
assert(msg.getUint8(0) === EventType.StatusReport, 'expecting status report event');
312315
return {
313316
flags: msg.getUint32(1, true),
314-
slot: msg.byteLength > 5 ? msg.getUint8(5) : 0,
317+
runningProgId: msg.byteLength > 5 ? msg.getUint8(5) : 0,
315318
};
316319
}
317320

src/ble-pybricks-service/sagas.test.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) 2021-2024 The Pybricks Authors
2+
// Copyright (c) 2021-2025 The Pybricks Authors
33

44
import { AsyncSaga } from '../../test';
55
import {
@@ -35,11 +35,11 @@ describe('command encoder', () => {
3535
],
3636
],
3737
[
38-
'start user program with slot',
38+
'start user program with program id',
3939
sendStartUserProgramCommand(0, 0x2a),
4040
[
4141
0x01, // start user program command
42-
0x2a, // program slot
42+
0x2a, // program ID
4343
],
4444
],
4545
[
@@ -192,7 +192,7 @@ describe('event decoder', () => {
192192
0x00, // .
193193
0x00, // .
194194
0x00, // flags count MSB
195-
0x80, // slot
195+
0x80, // program ID
196196
],
197197
didReceiveStatusReport(0x00000001, BuiltinProgramId.REPL),
198198
],

src/ble-pybricks-service/sagas.ts

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

@@ -75,7 +75,7 @@ function* encodeRequest(): Generator {
7575
yield* put(writeCommand(action.id, createLegacyStartReplCommand()));
7676
} else if (sendStartUserProgramCommand.matches(action)) {
7777
yield* put(
78-
writeCommand(action.id, createStartUserProgramCommand(action.slot)),
78+
writeCommand(action.id, createStartUserProgramCommand(action.progId)),
7979
);
8080
} else if (sendWriteUserProgramMetaCommand.matches(action)) {
8181
yield* put(
@@ -127,7 +127,7 @@ function* decodeResponse(action: ReturnType<typeof didNotifyEvent>): Generator {
127127
switch (responseType) {
128128
case EventType.StatusReport: {
129129
const status = parseStatusReport(action.value);
130-
yield* put(didReceiveStatusReport(status.flags, status.slot));
130+
yield* put(didReceiveStatusReport(status.flags, status.runningProgId));
131131
break;
132132
}
133133
case EventType.WriteStdout:

0 commit comments

Comments
 (0)