mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 07:43:34 +08:00
Using global RX object buffer
This commit is contained in:
@@ -178,8 +178,7 @@ TEST(ServiceClient, Basic)
|
||||
ASSERT_EQ(0, nodes.b.getDispatcher().getNumServiceResponseListeners()); // Third has timed out :(
|
||||
|
||||
// Validating
|
||||
// We use expected response instead of empty response because the last valid will be reused on fauilure
|
||||
ASSERT_TRUE(handler.match(ResultType::ErrorTimeout, 99, expected_response));
|
||||
ASSERT_TRUE(handler.match(ResultType::ErrorTimeout, 99, root_ns_a::StringService::Response()));
|
||||
|
||||
// Stray request
|
||||
ASSERT_LT(0, client3.call(99, request)); // Will timeout!
|
||||
@@ -341,7 +340,7 @@ TEST(ServiceClient, ConcurrentCalls)
|
||||
ASSERT_EQ(1, client.getNumPendingCalls()); // One dropped
|
||||
ASSERT_EQ(1, nodes.b.getDispatcher().getNumServiceResponseListeners()); // Still listening
|
||||
|
||||
ASSERT_TRUE(handler.match(ResultType::ErrorTimeout, 88, last_response));
|
||||
ASSERT_TRUE(handler.match(ResultType::ErrorTimeout, 88, root_ns_a::StringService::Response()));
|
||||
|
||||
/*
|
||||
* Validating the 500 ms timeout
|
||||
@@ -352,7 +351,7 @@ TEST(ServiceClient, ConcurrentCalls)
|
||||
ASSERT_EQ(0, client.getNumPendingCalls()); // All finished
|
||||
ASSERT_EQ(0, nodes.b.getDispatcher().getNumServiceResponseListeners()); // Not listening
|
||||
|
||||
ASSERT_TRUE(handler.match(ResultType::ErrorTimeout, 99, last_response));
|
||||
ASSERT_TRUE(handler.match(ResultType::ErrorTimeout, 99, root_ns_a::StringService::Response()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ using uavcan::DefaultDataTypeRegistrator;
|
||||
using uavcan::MonotonicDuration;
|
||||
|
||||
template <typename DataType>
|
||||
static bool validateDataTypeInfoResponse(const std::auto_ptr<ServiceCallResult<GetDataTypeInfo> >& resp, unsigned mask)
|
||||
static bool validateDataTypeInfoResponse(const std::auto_ptr<ServiceCallResultCollector<GetDataTypeInfo>::Result>& resp,
|
||||
unsigned mask)
|
||||
{
|
||||
if (!resp.get())
|
||||
{
|
||||
|
||||
@@ -51,18 +51,47 @@ struct SubscriberWithCollector
|
||||
template <typename DataType>
|
||||
class ServiceCallResultCollector : uavcan::Noncopyable
|
||||
{
|
||||
typedef uavcan::ServiceCallResult<DataType> ResultType;
|
||||
typedef uavcan::ServiceCallResult<DataType> ServiceCallResult;
|
||||
|
||||
void handler(const ResultType& result)
|
||||
public:
|
||||
class Result
|
||||
{
|
||||
this->result.reset(new ResultType(result));
|
||||
const typename ServiceCallResult::Status status_;
|
||||
uavcan::ServiceCallID call_id_;
|
||||
typename DataType::Response response_;
|
||||
|
||||
public:
|
||||
Result(typename ServiceCallResult::Status arg_status,
|
||||
uavcan::ServiceCallID arg_call_id,
|
||||
const typename DataType::Response& arg_response)
|
||||
: status_(arg_status)
|
||||
, call_id_(arg_call_id)
|
||||
, response_(arg_response)
|
||||
{ }
|
||||
|
||||
bool isSuccessful() const { return status_ == ServiceCallResult::Success; }
|
||||
|
||||
typename ServiceCallResult::Status getStatus() const { return status_; }
|
||||
|
||||
uavcan::ServiceCallID getCallID() const { return call_id_; }
|
||||
|
||||
const typename DataType::Response& getResponse() const { return response_; }
|
||||
typename DataType::Response& getResponse() { return response_; }
|
||||
};
|
||||
|
||||
private:
|
||||
void handler(const uavcan::ServiceCallResult<DataType>& tmp_result)
|
||||
{
|
||||
std::cout << tmp_result << std::endl;
|
||||
result.reset(new Result(tmp_result.getStatus(), tmp_result.getCallID(), tmp_result.getResponse()));
|
||||
}
|
||||
|
||||
public:
|
||||
std::auto_ptr<ResultType> result;
|
||||
std::auto_ptr<Result> result;
|
||||
|
||||
typedef uavcan::MethodBinder<ServiceCallResultCollector*,
|
||||
void (ServiceCallResultCollector::*)(const ResultType&)> Binder;
|
||||
void (ServiceCallResultCollector::*)(const uavcan::ServiceCallResult<DataType>&)>
|
||||
Binder;
|
||||
|
||||
Binder bind() { return Binder(this, &ServiceCallResultCollector::handler); }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user