mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-18 11:21:11 +00:00
Adding UDP ping (#3)
This commit is contained in:
parent
4d167f4961
commit
69add20cc8
@ -116,6 +116,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_s
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
|
||||
mp_obj_Msg_t *o = MP_OBJ_TO_PTR(self);
|
||||
uint8_t ping_array[64] = { [0 ... 63] = 255 };
|
||||
int timeout = mp_obj_get_int(timeout_us);
|
||||
if (timeout < 0) {
|
||||
timeout = 0;
|
||||
@ -136,11 +137,16 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
|
||||
uint8_t recvbuf[64];
|
||||
ssize_t l = msg_recv(&iface, recvbuf, 64);
|
||||
if (l > 0 && iface < o->interface_count) {
|
||||
uint16_t iface_usage_page = o->usage_pages[iface];
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
|
||||
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(iface_usage_page);
|
||||
tuple->items[1] = mp_obj_new_str_of_type(&mp_type_bytes, recvbuf, l);
|
||||
return MP_OBJ_FROM_PTR(tuple);
|
||||
if (memcmp(ping_array, recvbuf, 64) == 0) {
|
||||
msg_send(iface, ping_array, 64);
|
||||
return mp_const_none;
|
||||
} else {
|
||||
uint16_t iface_usage_page = o->usage_pages[iface];
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
|
||||
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(iface_usage_page);
|
||||
tuple->items[1] = mp_obj_new_str_of_type(&mp_type_bytes, recvbuf, l);
|
||||
return MP_OBJ_FROM_PTR(tuple);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (timeout <= 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user