summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-09-24 14:05:16 -0500
committerJeff Epler <jepler@gmail.com>2020-09-28 17:22:00 -0500
commit48bda589b81acad03bfe088c4c754040e9eb0783 (patch)
tree6bfe24b384881632a98dacfb86a21a6369019bf8 /shared-bindings
parent79ca430ddf25a71c73d6219fb68160fb405c3777 (diff)
Listerner: read -> receive, drop readinto
This prepares for creating a separate RemoteTransmissionRequest class
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/canio/CAN.h1
-rw-r--r--shared-bindings/canio/Listener.c29
-rw-r--r--shared-bindings/canio/Listener.h12
3 files changed, 19 insertions, 23 deletions
diff --git a/shared-bindings/canio/CAN.h b/shared-bindings/canio/CAN.h
index 66c972c28..08166dfd4 100644
--- a/shared-bindings/canio/CAN.h
+++ b/shared-bindings/canio/CAN.h
@@ -28,6 +28,7 @@
#include "py/obj.h"
#include "shared-bindings/microcontroller/Pin.h"
+#include "shared-bindings/canio/__init__.h"
#include "shared-bindings/canio/Message.h"
extern const mp_obj_type_t canio_can_type;
diff --git a/shared-bindings/canio/Listener.c b/shared-bindings/canio/Listener.c
index 1f4176f0c..5159c8481 100644
--- a/shared-bindings/canio/Listener.c
+++ b/shared-bindings/canio/Listener.c
@@ -38,44 +38,28 @@
//| Listen method of a canio.CAN object."""
//|
-//| def read(self) -> Optional[Message]:
+//| def receive(self) -> Optional[Message]:
//| """Reads a message, after waiting up to self.timeout seconds
//|
//| If no message is received in time, None is returned. Otherwise,
//| a Message is returned."""
//| ...
//|
-STATIC mp_obj_t canio_listener_read(mp_obj_t self_in) {
+STATIC mp_obj_t canio_listener_receive(mp_obj_t self_in) {
canio_listener_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_canio_listener_check_for_deinit(self);
canio_message_obj_t *message = m_new_obj(canio_message_obj_t);
message->base.type = &canio_message_type;
- if (common_hal_canio_listener_readinto(self, message)) {
+ if (common_hal_canio_listener_receiveinto(self, message)) {
return message;
} else {
m_free(message); // message did not escape into vm
}
return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_read_obj, canio_listener_read);
-
-//| def readinto(self, message: Message) -> bool:
-//| """Returns True (and modifies message) if a message was received
-//| before ``timeout`` seconds elapsed, False otherwise."""
-//| ...
-//|
-STATIC mp_obj_t canio_listener_readinto(mp_obj_t self_in, mp_obj_t message) {
- canio_listener_obj_t *self = MP_OBJ_TO_PTR(self_in);
- mp_obj_type_t *type = mp_obj_get_type(message);
- if (type != &canio_message_type) {
- mp_raise_TypeError_varg(translate("expected '%q' but got '%q'"), MP_QSTR_Message, type->name);
- }
- common_hal_canio_listener_check_for_deinit(self);
- return mp_obj_new_bool(common_hal_canio_listener_readinto(self, message));
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(canio_listener_readinto_obj, canio_listener_readinto);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_receive_obj, canio_listener_receive);
//| def in_waiting(self) -> int:
//| """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
//| ...
//|
STATIC mp_obj_t canio_iternext(mp_obj_t self_in) {
- mp_obj_t result = canio_listener_read(self_in);
+ mp_obj_t result = canio_listener_receive(self_in);
if (result == mp_const_none) {
return MP_OBJ_STOP_ITERATION;
}
@@ -170,8 +154,7 @@ STATIC const mp_rom_map_elem_t canio_listener_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&canio_listener_exit_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&canio_listener_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_in_waiting), MP_ROM_PTR(&canio_listener_in_waiting_obj) },
- { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&canio_listener_read_obj) },
- { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&canio_listener_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_receive), MP_ROM_PTR(&canio_listener_receive_obj) },
{ MP_ROM_QSTR(MP_QSTR_timeout), MP_ROM_PTR(&canio_listener_timeout_obj) },
};
STATIC MP_DEFINE_CONST_DICT(canio_listener_locals_dict, canio_listener_locals_dict_table);
diff --git a/shared-bindings/canio/Listener.h b/shared-bindings/canio/Listener.h
index eaa3490df..d925fa265 100644
--- a/shared-bindings/canio/Listener.h
+++ b/shared-bindings/canio/Listener.h
@@ -27,5 +27,17 @@
#pragma once
#include "py/obj.h"
+#include "shared-bindings/canio/CAN.h"
+#include "shared-bindings/canio/Match.h"
extern const mp_obj_type_t canio_listener_type;
+
+typedef struct canio_listener_obj canio_listener_obj_t;
+
+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);
+void common_hal_canio_listener_check_for_deinit(canio_listener_obj_t *self);
+void common_hal_canio_listener_deinit(canio_listener_obj_t *self);
+bool common_hal_canio_listener_receiveinto(canio_listener_obj_t *self, canio_message_obj_t *message);
+int common_hal_canio_listener_in_waiting(canio_listener_obj_t *self);
+float common_hal_canio_listener_get_timeout(canio_listener_obj_t *self);
+void common_hal_canio_listener_set_timeout(canio_listener_obj_t *self, float timeout);