38
38
//| Listen method of a canio.CAN object."""
39
39
//|
40
40
41
- //| def read (self) -> Optional[Message]:
41
+ //| def receive (self) -> Optional[Message]:
42
42
//| """Reads a message, after waiting up to self.timeout seconds
43
43
//|
44
44
//| If no message is received in time, None is returned. Otherwise,
45
45
//| a Message is returned."""
46
46
//| ...
47
47
//|
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 ) {
49
49
canio_listener_obj_t * self = MP_OBJ_TO_PTR (self_in );
50
50
common_hal_canio_listener_check_for_deinit (self );
51
51
52
52
canio_message_obj_t * message = m_new_obj (canio_message_obj_t );
53
53
message -> base .type = & canio_message_type ;
54
54
55
- if (common_hal_canio_listener_readinto (self , message )) {
55
+ if (common_hal_canio_listener_receiveinto (self , message )) {
56
56
return message ;
57
57
} else {
58
58
m_free (message ); // message did not escape into vm
59
59
}
60
60
return mp_const_none ;
61
61
}
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 );
79
63
80
64
//| def in_waiting(self) -> int:
81
65
//| """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
100
84
//| ...
101
85
//|
102
86
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 );
104
88
if (result == mp_const_none ) {
105
89
return MP_OBJ_STOP_ITERATION ;
106
90
}
@@ -170,8 +154,7 @@ STATIC const mp_rom_map_elem_t canio_listener_locals_dict_table[] = {
170
154
{ MP_ROM_QSTR (MP_QSTR___exit__ ), MP_ROM_PTR (& canio_listener_exit_obj ) },
171
155
{ MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& canio_listener_deinit_obj ) },
172
156
{ 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 ) },
175
158
{ MP_ROM_QSTR (MP_QSTR_timeout ), MP_ROM_PTR (& canio_listener_timeout_obj ) },
176
159
};
177
160
STATIC MP_DEFINE_CONST_DICT (canio_listener_locals_dict , canio_listener_locals_dict_table );
0 commit comments