Skip to content

Commit 964a7d5

Browse files
committed
pbsys/status: add status report size macro
The size of the status report may change in the future, so add a macro to help catch other places in the code that may need to be updated when the size changes.
1 parent 14f7f32 commit 964a7d5

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

lib/pbio/include/pbsys/status.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <pbio/protocol.h>
1616

17+
#define PBSYS_STATUS_REPORT_SIZE 6
18+
1719
void pbsys_status_set_program_id(pbio_pybricks_user_program_id_t program_id);
1820
void pbsys_status_set(pbio_pybricks_status_t status);
1921
void pbsys_status_clear(pbio_pybricks_status_t status);

lib/pbio/sys/bluetooth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ static PT_THREAD(pbsys_bluetooth_monitor_status(struct pt *pt)) {
269269
etimer_restart(&timer);
270270

271271
// send the message
272+
_Static_assert(sizeof(msg.payload) >= PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE);
272273
msg.context.size = pbsys_status_get_status_report(&msg.payload[0]);
273274
msg.context.connection = PBDRV_BLUETOOTH_CONNECTION_PYBRICKS;
274275
list_add(send_queue, &msg);

lib/pbio/sys/status.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ static void pbsys_status_update_flag(pbio_pybricks_status_t status, bool set) {
3838
}
3939

4040
/**
41-
* Gets the Pybricks status report and writes it to @p buf
41+
* Gets the Pybricks status report and writes it to @p buf.
42+
*
43+
* The buffer must be at least ::PBSYS_STATUS_REPORT_SIZE bytes.
4244
*
4345
* @param [in] buf The buffer to hold the binary data.
4446
* @return The number of bytes written to @p buf.
4547
*/
4648
uint32_t pbsys_status_get_status_report(uint8_t *buf) {
49+
_Static_assert(PBSYS_STATUS_REPORT_SIZE == PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE,
50+
"size of status report does not match size of event");
4751
return pbio_pybricks_event_status_report(buf, pbsys_status.flags, pbsys_status.program_id);
4852
}
4953

0 commit comments

Comments
 (0)