Skip to content

Commit c39ec15

Browse files
committed
_canio: Message: setting data clears rtr, and vice versa
1 parent a76119a commit c39ec15

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

shared-bindings/_canio/Message.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ STATIC const mp_obj_property_t canio_message_id_obj = {
117117
//| data: bytes
118118
//| """The content of the message, or dummy content in the case of an rtr.
119119
//|
120-
//| Assigning to data also sets the length."""
120+
//| Assigning to data also sets the length and clears the rtr flag."""
121121
//|
122122
STATIC mp_obj_t canio_message_data_get(const mp_obj_t self_in) {
123123
canio_message_obj_t *self = self_in;
@@ -202,7 +202,7 @@ STATIC const mp_obj_property_t canio_message_extended_obj = {
202202

203203

204204
//| rtr: bool
205-
//| """True if the message represents a remote transmission request (RTR)"""
205+
//| """True if the message represents a remote transmission request (RTR). Setting rtr to true zeros out data"""
206206
//|
207207
STATIC mp_obj_t canio_message_rtr_get(const mp_obj_t self_in) {
208208
canio_message_obj_t *self = self_in;

shared-module/_canio/Message.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const void *common_hal_canio_message_get_data(const canio_message_obj_t *self)
5959

6060
const void common_hal_canio_message_set_data(canio_message_obj_t *self, const void *data, size_t size)
6161
{
62+
self->rtr = false;
6263
self->size = size;
6364
memcpy(self->data, data, size);
6465
}
@@ -84,6 +85,9 @@ bool common_hal_canio_message_get_rtr(const canio_message_obj_t *self)
8485
void common_hal_canio_message_set_rtr(canio_message_obj_t *self, bool rtr)
8586
{
8687
self->rtr = rtr;
88+
if (rtr) {
89+
memset(self->data, 0, self->size);
90+
}
8791
}
8892

8993
bool common_hal_canio_message_get_extended(const canio_message_obj_t *self)

0 commit comments

Comments
 (0)