mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 06:43:35 +08:00
fix(uavcan): Change SocketCAN return code handling
Don't forward posix return codes and parse errno instead so api knows it neeeds to do a retry instead of a discard
This commit is contained in:
committed by
Peter van der Perk
parent
61f08771a7
commit
9aefd9058d
@@ -200,7 +200,11 @@ uavcan::int16_t CanIface::send(const uavcan::CanFrame &frame, uavcan::MonotonicT
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return res;
|
if (errno == ENOBUFS || errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
|
return 0; // Transmit queue is full, retry
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +214,11 @@ uavcan::int16_t CanIface::receive(uavcan::CanFrame &out_frame, uavcan::Monotonic
|
|||||||
int32_t result = recvmsg(_fd, &_recv_msg, MSG_DONTWAIT);
|
int32_t result = recvmsg(_fd, &_recv_msg, MSG_DONTWAIT);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
return result;
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy SocketCAN frame to CanardFrame */
|
/* Copy SocketCAN frame to CanardFrame */
|
||||||
@@ -220,7 +228,7 @@ uavcan::int16_t CanIface::receive(uavcan::CanFrame &out_frame, uavcan::Monotonic
|
|||||||
out_frame.id = recv_frame->can_id;
|
out_frame.id = recv_frame->can_id;
|
||||||
|
|
||||||
if (recv_frame->len > CANFD_MAX_DLEN) {
|
if (recv_frame->len > CANFD_MAX_DLEN) {
|
||||||
return -EFAULT;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_frame.dlc = recv_frame->len;
|
out_frame.dlc = recv_frame->len;
|
||||||
@@ -231,7 +239,7 @@ uavcan::int16_t CanIface::receive(uavcan::CanFrame &out_frame, uavcan::Monotonic
|
|||||||
out_frame.id = recv_frame->can_id;
|
out_frame.id = recv_frame->can_id;
|
||||||
|
|
||||||
if (recv_frame->can_dlc > CAN_MAX_DLEN) {
|
if (recv_frame->can_dlc > CAN_MAX_DLEN) {
|
||||||
return -EFAULT;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_frame.dlc = recv_frame->can_dlc;
|
out_frame.dlc = recv_frame->can_dlc;
|
||||||
@@ -245,7 +253,7 @@ uavcan::int16_t CanIface::receive(uavcan::CanFrame &out_frame, uavcan::Monotonic
|
|||||||
out_ts_monotonic = uavcan::MonotonicTime::fromUSec(tv->tv_sec * 1000000ULL + tv->tv_usec);
|
out_ts_monotonic = uavcan::MonotonicTime::fromUSec(tv->tv_sec * 1000000ULL + tv->tv_usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user