Skip to content

Commit 48bda58

Browse files
committed
Listerner: read -> receive, drop readinto
This prepares for creating a separate RemoteTransmissionRequest class
1 parent 79ca430 commit 48bda58

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

ports/atmel-samd/common-hal/canio/Listener.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ int common_hal_canio_listener_in_waiting(canio_listener_obj_t *self) {
348348
return self->hw->RXFS.bit.F0FL;
349349
}
350350

351-
bool common_hal_canio_listener_readinto(canio_listener_obj_t *self, canio_message_obj_t *message) {
351+
bool common_hal_canio_listener_receiveinto(canio_listener_obj_t *self, canio_message_obj_t *message) {
352352
if (!common_hal_canio_listener_in_waiting(self)) {
353353
uint64_t deadline = supervisor_ticks_ms64() + self->timeout_ms;
354354
do {

ports/atmel-samd/common-hal/canio/Listener.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ typedef struct {
3535
__IO CAN_RXF0A_Type RXFA; /**< \brief (R/W 32) Rx FIFO n Acknowledge */
3636
} canio_rxfifo_reg_t;
3737

38-
typedef struct {
38+
typedef struct canio_listener_obj {
3939
mp_obj_base_t base;
4040
canio_can_obj_t *can;
4141
canio_can_rx_fifo_t *fifo;
@@ -47,7 +47,7 @@ typedef struct {
4747
void common_hal_canio_listener_construct(canio_listener_obj_t *self, canio_can_obj_t *can, size_t nmatch, canio_match_obj_t **matches, float timeout);
4848
void common_hal_canio_listener_check_for_deinit(canio_listener_obj_t *self);
4949
void common_hal_canio_listener_deinit(canio_listener_obj_t *self);
50-
bool common_hal_canio_listener_readinto(canio_listener_obj_t *self, canio_message_obj_t *message);
50+
bool common_hal_canio_listener_receiveinto(canio_listener_obj_t *self, canio_message_obj_t *message);
5151
int common_hal_canio_listener_in_waiting(canio_listener_obj_t *self);
5252
float common_hal_canio_listener_get_timeout(canio_listener_obj_t *self);
5353
void common_hal_canio_listener_set_timeout(canio_listener_obj_t *self, float timeout);

shared-bindings/canio/CAN.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "py/obj.h"
3030
#include "shared-bindings/microcontroller/Pin.h"
31+
#include "shared-bindings/canio/__init__.h"
3132
#include "shared-bindings/canio/Message.h"
3233

3334
extern const mp_obj_type_t canio_can_type;

shared-bindings/canio/Listener.c

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,28 @@
3838
//| Listen method of a canio.CAN object."""
3939
//|
4040

41-
//| def read(self) -> Optional[Message]:
41+
//| def receive(self) -> Optional[Message]:
4242
//| """Reads a message, after waiting up to self.timeout seconds
4343
//|
4444
//| If no message is received in time, None is returned. Otherwise,
4545
//| a Message is returned."""
4646
//| ...
4747
//|
48-
STATIC mp_obj_t canio_listener_read(mp_obj_t self_in) {
48+
STATIC mp_obj_t canio_listener_receive(mp_obj_t self_in) {
4949
canio_listener_obj_t *self = MP_OBJ_TO_PTR(self_in);
5050
common_hal_canio_listener_check_for_deinit(self);
5151

5252
canio_message_obj_t *message = m_new_obj(canio_message_obj_t);
5353
message->base.type = &canio_message_type;
5454

55-
if (common_hal_canio_listener_readinto(self, message)) {
55+
if (common_hal_canio_listener_receiveinto(self, message)) {
5656
return message;
5757
} else {
5858
m_free(message); // message did not escape into vm
5959
}
6060
return mp_const_none;
6161
}
62-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_read_obj, canio_listener_read);
63-
64-
//| def readinto(self, message: Message) -> bool:
65-
//| """Returns True (and modifies message) if a message was received
66-
//| before ``timeout`` seconds elapsed, False otherwise."""
67-
//| ...
68-
//|
69-
STATIC mp_obj_t canio_listener_readinto(mp_obj_t self_in, mp_obj_t message) {
70-
canio_listener_obj_t *self = MP_OBJ_TO_PTR(self_in);
71-
mp_obj_type_t *type = mp_obj_get_type(message);
72-
if (type != &canio_message_type) {
73-
mp_raise_TypeError_varg(translate("expected '%q' but got '%q'"), MP_QSTR_Message, type->name);
74-
}
75-
common_hal_canio_listener_check_for_deinit(self);
76-
return mp_obj_new_bool(common_hal_canio_listener_readinto(self, message));
77-
}
78-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(canio_listener_readinto_obj, canio_listener_readinto);
62+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_receive_obj, canio_listener_receive);
7963

8064
//| def in_waiting(self) -> int:
8165
//| """Returns the number of messages waiting"""
@@ -100,7 +84,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_in_waiting_obj, canio_listener_i
10084
//| ...
10185
//|
10286
STATIC mp_obj_t canio_iternext(mp_obj_t self_in) {
103-
mp_obj_t result = canio_listener_read(self_in);
87+
mp_obj_t result = canio_listener_receive(self_in);
10488
if (result == mp_const_none) {
10589
return MP_OBJ_STOP_ITERATION;
10690
}
@@ -170,8 +154,7 @@ STATIC const mp_rom_map_elem_t canio_listener_locals_dict_table[] = {
170154
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&canio_listener_exit_obj) },
171155
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&canio_listener_deinit_obj) },
172156
{ MP_ROM_QSTR(MP_QSTR_in_waiting), MP_ROM_PTR(&canio_listener_in_waiting_obj) },
173-
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&canio_listener_read_obj) },
174-
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&canio_listener_readinto_obj) },
157+
{ MP_ROM_QSTR(MP_QSTR_receive), MP_ROM_PTR(&canio_listener_receive_obj) },
175158
{ MP_ROM_QSTR(MP_QSTR_timeout), MP_ROM_PTR(&canio_listener_timeout_obj) },
176159
};
177160
STATIC MP_DEFINE_CONST_DICT(canio_listener_locals_dict, canio_listener_locals_dict_table);

shared-bindings/canio/Listener.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,17 @@
2727
#pragma once
2828

2929
#include "py/obj.h"
30+
#include "shared-bindings/canio/CAN.h"
31+
#include "shared-bindings/canio/Match.h"
3032

3133
extern const mp_obj_type_t canio_listener_type;
34+
35+
typedef struct canio_listener_obj canio_listener_obj_t;
36+
37+
void common_hal_canio_listener_construct(canio_listener_obj_t *self, canio_can_obj_t *can, size_t nmatch, canio_match_obj_t **matches, float timeout);
38+
void common_hal_canio_listener_check_for_deinit(canio_listener_obj_t *self);
39+
void common_hal_canio_listener_deinit(canio_listener_obj_t *self);
40+
bool common_hal_canio_listener_receiveinto(canio_listener_obj_t *self, canio_message_obj_t *message);
41+
int common_hal_canio_listener_in_waiting(canio_listener_obj_t *self);
42+
float common_hal_canio_listener_get_timeout(canio_listener_obj_t *self);
43+
void common_hal_canio_listener_set_timeout(canio_listener_obj_t *self, float timeout);

0 commit comments

Comments
 (0)