File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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//|
122122STATIC 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//|
207207STATIC mp_obj_t canio_message_rtr_get (const mp_obj_t self_in ) {
208208 canio_message_obj_t * self = self_in ;
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ const void *common_hal_canio_message_get_data(const canio_message_obj_t *self)
5959
6060const 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)
8485void 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
8993bool common_hal_canio_message_get_extended (const canio_message_obj_t * self )
You can’t perform that action at this time.
0 commit comments