mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 22:23:33 +08:00
pull request corrections
This commit is contained in:
@@ -148,8 +148,7 @@ class SocketCanIface : public uavcan::ICanIface
|
||||
std::queue<RxItem> rx_queue_; // TODO: Use pool allocator
|
||||
std::unordered_multiset<std::uint32_t> pending_loopback_ids_; // TODO: Use pool allocator
|
||||
|
||||
std::vector<uavcan::CanFilterConfig> hw_filters_container_;
|
||||
bool filters_configured_ = false;
|
||||
std::vector<::can_filter> hw_filters_container_;
|
||||
|
||||
void registerError(SocketCanError e) { errors_[e]++; }
|
||||
|
||||
@@ -228,6 +227,16 @@ class SocketCanIface : public uavcan::ICanIface
|
||||
{
|
||||
return (res < 0 && errno == EWOULDBLOCK) ? 0 : res;
|
||||
}
|
||||
/*
|
||||
* Flags
|
||||
*/
|
||||
loopback = (msg.msg_flags & static_cast<int>(MSG_CONFIRM)) != 0;
|
||||
|
||||
if (!checkHWFilters(sockcan_frame) && !loopback)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
frame = makeUavcanFrame(sockcan_frame);
|
||||
/*
|
||||
* Timestamp
|
||||
@@ -246,10 +255,6 @@ class SocketCanIface : public uavcan::ICanIface
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* Flags
|
||||
*/
|
||||
loopback = (msg.msg_flags & static_cast<int>(MSG_CONFIRM)) != 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -304,17 +309,8 @@ class SocketCanIface : public uavcan::ICanIface
|
||||
if (accept)
|
||||
{
|
||||
rx.ts_utc += clock_.getPrivateAdjustment();
|
||||
if (filters_configured_)
|
||||
{
|
||||
if (checkHWFilters(rx.frame))
|
||||
{
|
||||
rx_queue_.push(rx);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rx_queue_.push(rx);
|
||||
}
|
||||
rx_queue_.push(rx);
|
||||
|
||||
}
|
||||
}
|
||||
else if (res == 0)
|
||||
@@ -331,17 +327,24 @@ class SocketCanIface : public uavcan::ICanIface
|
||||
/**
|
||||
* Returns true if a frame accepted by HW filters
|
||||
*/
|
||||
bool checkHWFilters(const uavcan::CanFrame frame)
|
||||
bool checkHWFilters (const ::can_frame frame) const
|
||||
{
|
||||
uint16_t container_size = hw_filters_container_.size();
|
||||
for (uint16_t i = 0; i < container_size; i++)
|
||||
if (! hw_filters_container_.empty())
|
||||
{
|
||||
if (((frame.id & hw_filters_container_[i].mask) ^ hw_filters_container_[i].id) == 0)
|
||||
uint16_t container_size = hw_filters_container_.size();
|
||||
for (uint16_t i = 0; i < container_size; i++)
|
||||
{
|
||||
return 1;
|
||||
if (((frame.can_id & hw_filters_container_[i].can_mask) ^ hw_filters_container_[i].can_id) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -439,40 +442,36 @@ public:
|
||||
for (unsigned i = 0; i < num_configs; i++)
|
||||
{
|
||||
const uavcan::CanFilterConfig& fc = filter_configs[i];
|
||||
hw_filters_container_[i].id = fc.id & uavcan::CanFrame::MaskExtID;
|
||||
hw_filters_container_[i].mask = fc.mask & uavcan::CanFrame::MaskExtID;
|
||||
hw_filters_container_[i].can_id = fc.id & uavcan::CanFrame::MaskExtID;
|
||||
hw_filters_container_[i].can_mask = fc.mask & uavcan::CanFrame::MaskExtID;
|
||||
if (fc.id & uavcan::CanFrame::FlagEFF)
|
||||
{
|
||||
hw_filters_container_[i].id |= CAN_EFF_FLAG;
|
||||
hw_filters_container_[i].can_id |= CAN_EFF_FLAG;
|
||||
}
|
||||
if (fc.id & uavcan::CanFrame::FlagRTR)
|
||||
{
|
||||
hw_filters_container_[i].id |= CAN_RTR_FLAG;
|
||||
hw_filters_container_[i].can_id |= CAN_RTR_FLAG;
|
||||
}
|
||||
if (fc.mask & uavcan::CanFrame::FlagEFF)
|
||||
{
|
||||
hw_filters_container_[i].mask |= CAN_EFF_FLAG;
|
||||
hw_filters_container_[i].can_mask |= CAN_EFF_FLAG;
|
||||
}
|
||||
if (fc.mask & uavcan::CanFrame::FlagRTR)
|
||||
{
|
||||
hw_filters_container_[i].mask |= CAN_RTR_FLAG;
|
||||
hw_filters_container_[i].can_mask |= CAN_RTR_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
if (! hw_filters_container_.empty())
|
||||
{
|
||||
filters_configured_ = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* SocketCAN emulates the CAN filters in software, so the number of filters is virtually unlimited.
|
||||
* This method returns a constant value.
|
||||
*/
|
||||
std::uint16_t getNumFilters() const override { return 8; }
|
||||
static constexpr unsigned NumFilters = 8;
|
||||
std::uint16_t getNumFilters() const override { return NumFilters; }
|
||||
|
||||
|
||||
/**
|
||||
* Returns total number of errors of each kind detected since the object was created.
|
||||
|
||||
Reference in New Issue
Block a user