diff --git a/micropython/extmod/modtrezormsg/modtrezormsg-unix.h b/micropython/extmod/modtrezormsg/modtrezormsg-unix.h index 375bf57bd..25d0e7beb 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg-unix.h +++ b/micropython/extmod/modtrezormsg/modtrezormsg-unix.h @@ -57,6 +57,10 @@ ssize_t msg_recv(uint8_t *iface, uint8_t *buf, size_t len) } si_other = si; slen = sl; + if (r == 8 && memcmp("PINGPING", buf, 8) == 0) { + msg_send(0, (const uint8_t *)"PONGPONG", 8); + return 0; + } return r; } diff --git a/micropython/extmod/modtrezormsg/modtrezormsg.c b/micropython/extmod/modtrezormsg/modtrezormsg.c index fc686e1ee..f819d52a1 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg.c +++ b/micropython/extmod/modtrezormsg/modtrezormsg.c @@ -429,15 +429,10 @@ 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) { - if (l == 8 && memcmp("PINGPING", recvbuf, 8) == 0) { - msg_send(iface, (const uint8_t *)"PONGPONG", 8); - return mp_const_none; - } else { - mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL)); - tuple->items[0] = MP_OBJ_NEW_SMALL_INT(iface); - tuple->items[1] = mp_obj_new_str_of_type(&mp_type_bytes, recvbuf, l); - return MP_OBJ_FROM_PTR(tuple); - } + mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL)); + tuple->items[0] = MP_OBJ_NEW_SMALL_INT(iface); + tuple->items[1] = mp_obj_new_str_of_type(&mp_type_bytes, recvbuf, l); + return MP_OBJ_FROM_PTR(tuple); } if (timeout <= 0) { break;