mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 02:53:33 +08:00
Meaningful error codes instead of plain -1
This commit is contained in:
@@ -157,7 +157,7 @@ int Scheduler::spin(MonotonicTime deadline)
|
||||
if (inside_spin_) // Preventing recursive calls
|
||||
{
|
||||
assert(0);
|
||||
return -1;
|
||||
return -ErrRecursiveCall;
|
||||
}
|
||||
inside_spin_ = true;
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ void DataTypeInfoProvider::handleGetDataTypeInfoRequest(const protocol::GetDataT
|
||||
|
||||
int DataTypeInfoProvider::start()
|
||||
{
|
||||
int res = -1;
|
||||
int res = 0;
|
||||
|
||||
res = cats_srv_.start(
|
||||
ComputeAggregateTypeSignatureCallback(this, &DataTypeInfoProvider::handleComputeAggregateTypeSignatureRequest));
|
||||
|
||||
@@ -108,12 +108,12 @@ int GlobalTimeSyncMaster::init()
|
||||
GlobalDataTypeRegistry::instance().find(DataTypeKindMessage, protocol::GlobalTimeSync::getDataTypeFullName());
|
||||
if (desc == NULL)
|
||||
{
|
||||
return -1;
|
||||
return -ErrUnknownDataType;
|
||||
}
|
||||
dtid_ = desc->getID();
|
||||
|
||||
// Iface master array
|
||||
int res = -1;
|
||||
int res = -ErrLogic;
|
||||
for (uint8_t i = 0; i < MaxCanIfaces; i++)
|
||||
{
|
||||
if (!iface_masters_[i].isConstructed())
|
||||
|
||||
@@ -105,7 +105,7 @@ int NodeInitializer::checkOneNodeOneDataTypeKind(NodeID nid, DataTypeKind kind)
|
||||
}
|
||||
if (!last_cats_request_ok_)
|
||||
{
|
||||
return -1;
|
||||
return -ErrFailure;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -59,15 +59,13 @@ void NodeStatusProvider::handleGetNodeInfoRequest(const protocol::GetNodeInfo::R
|
||||
|
||||
int NodeStatusProvider::startAndPublish()
|
||||
{
|
||||
int res = -1;
|
||||
|
||||
if (!isNodeInfoInitialized())
|
||||
{
|
||||
UAVCAN_TRACE("NodeStatusProvider", "Node info was not initialized");
|
||||
return -1;
|
||||
return -ErrNotInited;
|
||||
}
|
||||
|
||||
res = publish(); // Initial broadcast
|
||||
int res = publish(); // Initial broadcast
|
||||
if (res < 0)
|
||||
{
|
||||
goto fail;
|
||||
|
||||
@@ -73,7 +73,7 @@ int ParamServer::start(IParamManager* manager)
|
||||
{
|
||||
if (manager == NULL)
|
||||
{
|
||||
return -1;
|
||||
return -ErrInvalidParam;
|
||||
}
|
||||
manager_ = manager;
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ int CanIOManager::sendToIface(int iface_index, const CanFrame& frame, MonotonicT
|
||||
if (iface == NULL)
|
||||
{
|
||||
assert(0); // Nonexistent interface
|
||||
return -1;
|
||||
return -ErrLogic;
|
||||
}
|
||||
const int res = iface->send(frame, tx_deadline, flags);
|
||||
if (res != 1)
|
||||
@@ -311,7 +311,7 @@ int CanIOManager::send(const CanFrame& frame, MonotonicTime tx_deadline, Monoton
|
||||
const int select_res = driver_.select(masks, blocking_deadline);
|
||||
if (select_res < 0)
|
||||
{
|
||||
return select_res;
|
||||
return -ErrDriver;
|
||||
}
|
||||
assert(masks.read == 0);
|
||||
}
|
||||
@@ -383,7 +383,7 @@ int CanIOManager::receive(CanRxFrame& out_frame, MonotonicTime blocking_deadline
|
||||
const int select_res = driver_.select(masks, blocking_deadline);
|
||||
if (select_res < 0)
|
||||
{
|
||||
return select_res;
|
||||
return -ErrDriver;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ int CanIOManager::receive(CanRxFrame& out_frame, MonotonicTime blocking_deadline
|
||||
{
|
||||
counters_[i].frames_rx += 1;
|
||||
}
|
||||
return res;
|
||||
return (res < 0) ? -ErrDriver : res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ int Dispatcher::send(const Frame& frame, MonotonicTime tx_deadline, MonotonicTim
|
||||
if (frame.getSrcNodeID() != getNodeID())
|
||||
{
|
||||
assert(0);
|
||||
return -1;
|
||||
return -ErrLogic;
|
||||
}
|
||||
|
||||
CanFrame can_frame;
|
||||
@@ -234,7 +234,7 @@ int Dispatcher::send(const Frame& frame, MonotonicTime tx_deadline, MonotonicTim
|
||||
{
|
||||
UAVCAN_TRACE("Dispatcher", "Unable to send: frame is malformed: %s", frame.toString().c_str());
|
||||
assert(0);
|
||||
return -1;
|
||||
return -ErrLogic;
|
||||
}
|
||||
return canio_.send(can_frame, tx_deadline, blocking_deadline, iface_mask, qos, flags);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ int Frame::getMaxPayloadLen() const
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
return -1;
|
||||
return -ErrLogic;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ int DynamicTransferBufferManagerEntry::read(unsigned int offset, uint8_t* data,
|
||||
if (!data)
|
||||
{
|
||||
assert(0);
|
||||
return -1;
|
||||
return -ErrInvalidParam;
|
||||
}
|
||||
if (offset >= max_write_pos_)
|
||||
{
|
||||
@@ -148,7 +148,7 @@ int DynamicTransferBufferManagerEntry::write(unsigned int offset, const uint8_t*
|
||||
if (!data)
|
||||
{
|
||||
assert(0);
|
||||
return -1;
|
||||
return -ErrInvalidParam;
|
||||
}
|
||||
|
||||
if (offset >= max_size_)
|
||||
@@ -190,7 +190,6 @@ int DynamicTransferBufferManagerEntry::write(unsigned int offset, const uint8_t*
|
||||
if (new_block == NULL)
|
||||
{
|
||||
break; // We're in deep shit.
|
||||
|
||||
}
|
||||
// Appending the chain with the new block
|
||||
if (last_written_block != NULL)
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace uavcan
|
||||
int IncomingTransfer::write(unsigned int, const uint8_t*, unsigned int)
|
||||
{
|
||||
assert(0); // Incoming transfer container is read-only
|
||||
return -1;
|
||||
return -ErrLogic;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -35,7 +35,7 @@ int SingleFrameIncomingTransfer::read(unsigned int offset, uint8_t* data, unsign
|
||||
if (data == NULL)
|
||||
{
|
||||
assert(0);
|
||||
return -1;
|
||||
return -ErrInvalidParam;
|
||||
}
|
||||
if (offset >= payload_len_)
|
||||
{
|
||||
@@ -69,7 +69,7 @@ int MultiFrameIncomingTransfer::read(unsigned int offset, uint8_t* data, unsigne
|
||||
if (tbb == NULL)
|
||||
{
|
||||
UAVCAN_TRACE("MultiFrameIncomingTransfer", "Read failed: no such buffer");
|
||||
return -1;
|
||||
return -ErrLogic;
|
||||
}
|
||||
return tbb->read(offset, data, len);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
|
||||
assert(0);
|
||||
UAVCAN_TRACE("TransferSender", "Frame payload write failure, %i", res);
|
||||
registerError();
|
||||
return (res < 0) ? res : -1;
|
||||
return (res < 0) ? res : -ErrLogic;
|
||||
}
|
||||
frame.makeLast();
|
||||
assert(frame.isLast() && frame.isFirst());
|
||||
@@ -97,7 +97,7 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
|
||||
}
|
||||
|
||||
assert(0);
|
||||
return -1; // Return path analysis is apparently broken. There should be no warning, this 'return' is unreachable.
|
||||
return -ErrLogic; // Return path analysis is apparently broken. There should be no warning, this 'return' is unreachable.
|
||||
}
|
||||
|
||||
int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime tx_deadline,
|
||||
@@ -113,7 +113,7 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
|
||||
{
|
||||
UAVCAN_TRACE("TransferSender", "OTR access failure, dtd=%s tt=%i",
|
||||
data_type_.toString().c_str(), int(transfer_type));
|
||||
return -1;
|
||||
return -ErrMemory;
|
||||
}
|
||||
|
||||
const TransferID this_tid = tid->get();
|
||||
|
||||
Reference in New Issue
Block a user