_canio: Message: setting data clears rtr, and vice versa
This commit is contained in:
parent
a76119afcb
commit
c39ec1581e
|
@ -117,7 +117,7 @@ STATIC const mp_obj_property_t canio_message_id_obj = {
|
|||
//| data: bytes
|
||||
//| """The content of the message, or dummy content in the case of an rtr.
|
||||
//|
|
||||
//| Assigning to data also sets the length."""
|
||||
//| Assigning to data also sets the length and clears the rtr flag."""
|
||||
//|
|
||||
STATIC mp_obj_t canio_message_data_get(const mp_obj_t self_in) {
|
||||
canio_message_obj_t *self = self_in;
|
||||
|
@ -202,7 +202,7 @@ STATIC const mp_obj_property_t canio_message_extended_obj = {
|
|||
|
||||
|
||||
//| rtr: bool
|
||||
//| """True if the message represents a remote transmission request (RTR)"""
|
||||
//| """True if the message represents a remote transmission request (RTR). Setting rtr to true zeros out data"""
|
||||
//|
|
||||
STATIC mp_obj_t canio_message_rtr_get(const mp_obj_t self_in) {
|
||||
canio_message_obj_t *self = self_in;
|
||||
|
|
|
@ -59,6 +59,7 @@ const void *common_hal_canio_message_get_data(const canio_message_obj_t *self)
|
|||
|
||||
const void common_hal_canio_message_set_data(canio_message_obj_t *self, const void *data, size_t size)
|
||||
{
|
||||
self->rtr = false;
|
||||
self->size = size;
|
||||
memcpy(self->data, data, size);
|
||||
}
|
||||
|
@ -84,6 +85,9 @@ bool common_hal_canio_message_get_rtr(const canio_message_obj_t *self)
|
|||
void common_hal_canio_message_set_rtr(canio_message_obj_t *self, bool rtr)
|
||||
{
|
||||
self->rtr = rtr;
|
||||
if (rtr) {
|
||||
memset(self->data, 0, self->size);
|
||||
}
|
||||
}
|
||||
|
||||
bool common_hal_canio_message_get_extended(const canio_message_obj_t *self)
|
||||
|
|
Loading…
Reference in New Issue