libuavcan passive mode support

This commit is contained in:
Pavel Kirienko 2014-07-12 16:52:17 +04:00
parent 93f861ad60
commit c9c9a16e94
6 changed files with 47 additions and 4 deletions

View File

@ -26,6 +26,7 @@ const int16_t ErrInvalidTransferListener = 7;
const int16_t ErrNotInited = 8;
const int16_t ErrRecursiveCall = 9;
const int16_t ErrLogic = 10;
const int16_t ErrPassiveMode = 11;
}

View File

@ -34,6 +34,8 @@ public:
return getScheduler().getDispatcher().setNodeID(nid);
}
bool isPassiveMode() const { return getScheduler().getDispatcher().isPassiveMode(); }
int spin(MonotonicTime deadline)
{
return getScheduler().spin(deadline);

View File

@ -141,6 +141,8 @@ public:
NodeID getNodeID() const { return self_node_id_; }
bool setNodeID(NodeID nid);
bool isPassiveMode() const { return !getNodeID().isUnicast(); }
const ISystemClock& getSystemClock() const { return sysclock_; }
ISystemClock& getSystemClock() { return sysclock_; }

View File

@ -62,10 +62,15 @@ int NodeStatusProvider::startAndPublish()
return -ErrNotInited;
}
int res = publish(); // Initial broadcast
if (res < 0)
int res = -1;
if (!getNode().isPassiveMode())
{
goto fail;
res = publish(); // Initial broadcast
if (res < 0)
{
goto fail;
}
}
res = gdr_sub_.start(GlobalDiscoveryRequestCallback(this, &NodeStatusProvider::handleGlobalDiscoveryRequest));
@ -80,7 +85,10 @@ int NodeStatusProvider::startAndPublish()
goto fail;
}
TimerBase::startPeriodic(MonotonicDuration::fromMSec(protocol::NodeStatus::PUBLICATION_PERIOD_MS));
if (!getNode().isPassiveMode())
{
TimerBase::startPeriodic(MonotonicDuration::fromMSec(protocol::NodeStatus::PUBLICATION_PERIOD_MS));
}
return res;

View File

@ -19,6 +19,11 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id,
TransferID tid)
{
if (dispatcher_.isPassiveMode())
{
return -ErrPassiveMode;
}
dispatcher_.getTransferPerfCounter().addTxTransfer();
Frame frame(data_type_.getID(), transfer_type, dispatcher_.getNodeID(), dst_node_id, 0, tid);

View File

@ -218,3 +218,28 @@ TEST(TransferSender, Loopback)
EXPECT_EQ(1, dispatcher.getTransferPerfCounter().getTxTransferCount());
EXPECT_EQ(0, dispatcher.getTransferPerfCounter().getRxTransferCount());
}
TEST(TransferSender, PassiveMode)
{
uavcan::PoolManager<1> poolmgr;
SystemClockMock clockmock(100);
CanDriverMock driver(2, clockmock);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(poolmgr);
uavcan::Dispatcher dispatcher(driver, poolmgr, clockmock, out_trans_reg);
uavcan::TransferSender sender(dispatcher, makeDataType(uavcan::DataTypeKindMessage, 123),
uavcan::CanTxQueue::Volatile);
static const uint8_t Payload[] = {1, 2, 3, 4, 5};
ASSERT_EQ(-uavcan::ErrPassiveMode,
sender.send(Payload, sizeof(Payload), tsMono(1000), uavcan::MonotonicTime(),
uavcan::TransferTypeMessageBroadcast, uavcan::NodeID::Broadcast));
EXPECT_EQ(0, dispatcher.getTransferPerfCounter().getErrorCount());
EXPECT_EQ(0, dispatcher.getTransferPerfCounter().getTxTransferCount());
EXPECT_EQ(0, dispatcher.getTransferPerfCounter().getRxTransferCount());
}