Skip to content

Commit 14f7f32

Browse files
committed
pbio/protocol: add macro for status report size
The status report may grow in the future, so add a macro to help catch places in the code that need to be updated if the size changes.
1 parent 9f44554 commit 14f7f32

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/pbio/include/pbio/protocol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ typedef enum {
341341
*/
342342
#define PBIO_PYBRICKS_STATUS_FLAG(status) (1 << status)
343343

344+
/** Size of status report event message in bytes. */
345+
#define PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE 6
346+
344347
uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_pybricks_user_program_id_t program_id);
345348

346349
/**

lib/pbio/src/protocol/pybricks.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ _Static_assert(NUM_PBIO_PYBRICKS_STATUS <= sizeof(uint32_t) * 8,
1313
"oh no, we added too many status flags");
1414

1515
/**
16-
* Writes Pybricks status report command to @p buf
16+
* Writes Pybricks status report command to @p buf.
17+
*
18+
* The buffer must be at least ::PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE bytes.
1719
*
1820
* @param [in] buf The buffer to hold the binary data.
1921
* @param [in] flags The status flags.
@@ -24,7 +26,7 @@ uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_py
2426
buf[0] = PBIO_PYBRICKS_EVENT_STATUS_REPORT;
2527
pbio_set_uint32_le(&buf[1], flags);
2628
buf[5] = program_id;
27-
return 6;
29+
return PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE;
2830
}
2931

3032
/**

0 commit comments

Comments
 (0)