mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 08:23:35 +08:00
spinOnce(), fixes #31
This commit is contained in:
@@ -159,7 +159,8 @@ int Scheduler::spin(MonotonicTime deadline)
|
||||
UAVCAN_ASSERT(0);
|
||||
return -ErrRecursiveCall;
|
||||
}
|
||||
inside_spin_ = true;
|
||||
InsideSpinSetter iss(*this);
|
||||
UAVCAN_ASSERT(inside_spin_);
|
||||
|
||||
int retval = 0;
|
||||
while (true)
|
||||
@@ -179,7 +180,28 @@ int Scheduler::spin(MonotonicTime deadline)
|
||||
}
|
||||
}
|
||||
|
||||
inside_spin_ = false;
|
||||
return retval;
|
||||
}
|
||||
|
||||
int Scheduler::spinOnce()
|
||||
{
|
||||
if (inside_spin_) // Preventing recursive calls
|
||||
{
|
||||
UAVCAN_ASSERT(0);
|
||||
return -ErrRecursiveCall;
|
||||
}
|
||||
InsideSpinSetter iss(*this);
|
||||
UAVCAN_ASSERT(inside_spin_);
|
||||
|
||||
const int retval = dispatcher_.spinOnce();
|
||||
if (retval < 0)
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
|
||||
const MonotonicTime ts = deadline_scheduler_.pollAndGetMonotonicTime(getSystemClock());
|
||||
pollCleanup(ts, unsigned(retval));
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@@ -229,6 +229,40 @@ int Dispatcher::spin(MonotonicTime deadline)
|
||||
return num_frames_processed;
|
||||
}
|
||||
|
||||
int Dispatcher::spinOnce()
|
||||
{
|
||||
int num_frames_processed = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
CanIOFlags flags = 0;
|
||||
CanRxFrame frame;
|
||||
const int res = canio_.receive(frame, MonotonicTime(), flags);
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
else if (res > 0)
|
||||
{
|
||||
if (flags & CanIOFlagLoopback)
|
||||
{
|
||||
handleLoopbackFrame(frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
num_frames_processed++;
|
||||
handleFrame(frame);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break; // No frames left
|
||||
}
|
||||
}
|
||||
|
||||
return num_frames_processed;
|
||||
}
|
||||
|
||||
int Dispatcher::send(const Frame& frame, MonotonicTime tx_deadline, MonotonicTime blocking_deadline,
|
||||
CanTxQueue::Qos qos, CanIOFlags flags, uint8_t iface_mask)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user