init
This commit is contained in:
61
unitree_SDK/include/unitree/robot/client/client.hpp
Normal file
61
unitree_SDK/include/unitree/robot/client/client.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef __UT_ROBOT_SDK_CLIENT_HPP__
|
||||
#define __UT_ROBOT_SDK_CLIENT_HPP__
|
||||
|
||||
#include <unitree/robot/client/client_base.hpp>
|
||||
#include <unitree/robot/client/lease_client.hpp>
|
||||
|
||||
#define UT_ROBOT_CLIENT_REG_API_NO_PROI(apiId) \
|
||||
UT_ROBOT_CLIENT_REG_API(apiId, 0)
|
||||
|
||||
#define UT_ROBOT_CLIENT_REG_API(apiId, priority) \
|
||||
RegistApi(apiId, priority)
|
||||
|
||||
namespace unitree
|
||||
{
|
||||
namespace robot
|
||||
{
|
||||
/*
|
||||
* @brief
|
||||
* @class: Client
|
||||
*/
|
||||
class Client: public ClientBase
|
||||
{
|
||||
public:
|
||||
explicit Client(const std::string& name, bool enableLease = false);
|
||||
virtual ~Client();
|
||||
|
||||
void WaitLeaseApplied();
|
||||
int64_t GetLeaseId();
|
||||
|
||||
const std::string& GetApiVersion() const;
|
||||
std::string GetServerApiVersion();
|
||||
|
||||
protected:
|
||||
void SetApiVersion(const std::string& apiVersion);
|
||||
|
||||
int32_t Noop();
|
||||
|
||||
int32_t Call(int32_t apiId, const std::string& parameter, std::string& data);
|
||||
int32_t Call(int32_t apiId, const std::string& parameter);
|
||||
|
||||
int32_t Call(int32_t apiId, const std::vector<uint8_t>& parameter, std::vector<uint8_t>& data);
|
||||
int32_t Call(int32_t apiId, const std::vector<uint8_t>& parameter);
|
||||
|
||||
int32_t Call(int32_t apiId, const std::string& parameter, const std::vector<uint8_t>& binary);
|
||||
|
||||
void RegistApi(int32_t apiId, int32_t priority = 0);
|
||||
int32_t CheckApi(int32_t apiId, int32_t& priority, int64_t& leaseId);
|
||||
|
||||
private:
|
||||
bool mEnableLease;
|
||||
std::string mApiVersion;
|
||||
std::unordered_map<int32_t,int32_t> mApiMap;
|
||||
LeaseClientPtr mLeaseClientPtr;
|
||||
};
|
||||
|
||||
using ClientPtr = std::shared_ptr<Client>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif//__UT_ROBOT_SDK_CLIENT_HPP__
|
54
unitree_SDK/include/unitree/robot/client/client_base.hpp
Normal file
54
unitree_SDK/include/unitree/robot/client/client_base.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef __UT_ROBOT_SDK_CLIENT_BASE_HPP__
|
||||
#define __UT_ROBOT_SDK_CLIENT_BASE_HPP__
|
||||
|
||||
#include <unitree/robot/client/client_stub.hpp>
|
||||
|
||||
namespace unitree
|
||||
{
|
||||
namespace robot
|
||||
{
|
||||
/*
|
||||
* @brief
|
||||
* @default client timeout. 1s
|
||||
*/
|
||||
const int64_t ROBOT_CLIENT_TIMEOUT = 1000000;
|
||||
|
||||
/*
|
||||
* @brief
|
||||
* @class: ClientBase
|
||||
*/
|
||||
class ClientBase
|
||||
{
|
||||
public:
|
||||
explicit ClientBase(const std::string& name);
|
||||
virtual ~ClientBase();
|
||||
|
||||
virtual void Init() = 0;
|
||||
|
||||
void SetTimeout(int64_t timeout);
|
||||
void SetTimeout(float timeout);
|
||||
|
||||
protected:
|
||||
int32_t Call(int32_t apiId, const std::string& parameter, std::string& data, int32_t priority, int64_t leaseId);
|
||||
int32_t Call(int32_t apiId, const std::string& parameter, int32_t priority, int64_t leaseId);
|
||||
|
||||
int32_t Call(int32_t apiId, const std::vector<uint8_t>& parameter, std::vector<uint8_t>& bin_data, int32_t priority, int64_t leaseId);
|
||||
int32_t Call(int32_t apiId, const std::vector<uint8_t>& parameter, int32_t priority, int64_t leaseId);
|
||||
|
||||
int32_t Call(int32_t apiId, const std::string& parameter, const std::vector<uint8_t>& binary, int32_t priority, int64_t leaseId);
|
||||
|
||||
int32_t Call(int32_t apiId, const std::string& parameter, std::string& data, int32_t priority, int64_t leaseId, int64_t timeout);
|
||||
|
||||
void SetHeader(RequestHeader& header, int32_t apiId, int64_t leaseId, int32_t priority, bool noReply);
|
||||
|
||||
private:
|
||||
int64_t mTimeout;
|
||||
ClientStubPtr mClientStubPtr;
|
||||
};
|
||||
|
||||
using ClientBasePtr = std::shared_ptr<ClientBase>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif//__UT_ROBOT_SDK_CLIENT_BASE_HPP__
|
36
unitree_SDK/include/unitree/robot/client/client_stub.hpp
Normal file
36
unitree_SDK/include/unitree/robot/client/client_stub.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef __UT_ROBOT_SDK_CLIENT_STUB_HPP__
|
||||
#define __UT_ROBOT_SDK_CLIENT_STUB_HPP__
|
||||
|
||||
#include <unitree/robot/future/request_future.hpp>
|
||||
#include <unitree/robot/channel/channel_labor.hpp>
|
||||
#include <unitree/common/block_queue.hpp>
|
||||
|
||||
namespace unitree
|
||||
{
|
||||
namespace robot
|
||||
{
|
||||
class ClientStub
|
||||
{
|
||||
public:
|
||||
explicit ClientStub();
|
||||
~ClientStub();
|
||||
|
||||
void Init(const std::string& name);
|
||||
|
||||
bool Send(const Request& req, int64_t waitTimeout);
|
||||
RequestFuturePtr SendRequest(const Request& req, int64_t waitTimeout);
|
||||
|
||||
private:
|
||||
void ResponseFunc(const void* message);
|
||||
|
||||
private:
|
||||
ChannelLaborPtr<Request,Response> mChannelLaborPtr;
|
||||
RequestFutureQueuePtr mFutureQueuePtr;
|
||||
};
|
||||
|
||||
using ClientStubPtr = std::shared_ptr<ClientStub>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif//__UT_ROBOT_SDK_CLIENT_STUB_HPP__
|
65
unitree_SDK/include/unitree/robot/client/lease_client.hpp
Normal file
65
unitree_SDK/include/unitree/robot/client/lease_client.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef __UT_ROBOT_SDK_LEASE_CLIENT_H__
|
||||
#define __UT_ROBOT_SDK_LEASE_CLIENT_H__
|
||||
|
||||
#include <unitree/robot/client/client_base.hpp>
|
||||
#include <unitree/common/thread/recurrent_thread.hpp>
|
||||
|
||||
namespace unitree
|
||||
{
|
||||
namespace robot
|
||||
{
|
||||
class LeaseContext
|
||||
{
|
||||
public:
|
||||
LeaseContext();
|
||||
~LeaseContext();
|
||||
|
||||
void Update(int64_t id, int64_t term);
|
||||
void Reset();
|
||||
|
||||
bool Valid() const;
|
||||
|
||||
int64_t GetId() const;
|
||||
int64_t GetTerm() const;
|
||||
|
||||
private:
|
||||
int64_t mId;
|
||||
int64_t mTerm;
|
||||
};
|
||||
|
||||
using LeaseContextPtr = std::shared_ptr<LeaseContext>;
|
||||
|
||||
class LeaseClient : public ClientBase
|
||||
{
|
||||
public:
|
||||
explicit LeaseClient(const std::string& name);
|
||||
~LeaseClient();
|
||||
|
||||
void Init();
|
||||
|
||||
void WaitApplied();
|
||||
int64_t GetId();
|
||||
bool Applied();
|
||||
|
||||
private:
|
||||
void Apply();
|
||||
void Renewal();
|
||||
|
||||
void ThreadFunction();
|
||||
|
||||
int64_t GetWaitMicrosec();
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mContextName;
|
||||
LeaseContext mContext;
|
||||
common::ThreadPtr mThreadPtr;
|
||||
common::Mutex mMutex;
|
||||
};
|
||||
|
||||
using LeaseClientPtr = std::shared_ptr<LeaseClient>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif//__UT_ROBOT_SDK_LEASE_CLIENT_H__
|
Reference in New Issue
Block a user