init
This commit is contained in:
210
unitree_SDK/include/unitree/robot/b2/config/config_api.hpp
Normal file
210
unitree_SDK/include/unitree/robot/b2/config/config_api.hpp
Normal file
@@ -0,0 +1,210 @@
|
||||
#ifndef __UT_ROBOT_B2_CONFIG_API_HPP__
|
||||
#define __UT_ROBOT_B2_CONFIG_API_HPP__
|
||||
|
||||
#include <unitree/common/json/jsonize.hpp>
|
||||
|
||||
namespace unitree
|
||||
{
|
||||
namespace robot
|
||||
{
|
||||
namespace b2
|
||||
{
|
||||
/*
|
||||
* service name
|
||||
*/
|
||||
const std::string CONFIG_SERVICE_NAME = "config";
|
||||
|
||||
/*
|
||||
* api version
|
||||
*/
|
||||
const std::string CONFIG_API_VERSION = "1.0.0.1";
|
||||
|
||||
/*
|
||||
* api id
|
||||
*/
|
||||
const int32_t CONFIG_API_ID_SET = 1001;
|
||||
const int32_t CONFIG_API_ID_GET = 1002;
|
||||
const int32_t CONFIG_API_ID_DEL = 1003;
|
||||
const int32_t CONFIG_API_ID_META = 1004;
|
||||
|
||||
/*
|
||||
* data type
|
||||
*/
|
||||
class JsonizeConfigMeta : public common::Jsonize
|
||||
{
|
||||
public:
|
||||
JsonizeConfigMeta()
|
||||
{}
|
||||
|
||||
~JsonizeConfigMeta()
|
||||
{}
|
||||
|
||||
void fromJson(common::JsonMap& json)
|
||||
{
|
||||
common::FromJson(json["name"], name);
|
||||
common::FromJson(json["lastModified"], lastModified);
|
||||
common::FromJson(json["size"], size);
|
||||
common::FromJson(json["epoch"], epoch);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const
|
||||
{
|
||||
common::ToJson(name, json["name"]);
|
||||
common::ToJson(lastModified, json["lastModified"]);
|
||||
common::ToJson(size, json["size"]);
|
||||
common::ToJson(epoch, json["epoch"]);
|
||||
}
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
std::string lastModified;
|
||||
int32_t size;
|
||||
int32_t epoch;
|
||||
};
|
||||
|
||||
class ConfigSetParameter : public common::Jsonize
|
||||
{
|
||||
public:
|
||||
ConfigSetParameter()
|
||||
{}
|
||||
|
||||
~ConfigSetParameter()
|
||||
{}
|
||||
|
||||
void fromJson(common::JsonMap& json)
|
||||
{
|
||||
common::FromJson(json["name"], name);
|
||||
common::FromJson(json["content"], content);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const
|
||||
{
|
||||
common::ToJson(name, json["name"]);
|
||||
common::ToJson(content, json["content"]);
|
||||
}
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
std::string content;
|
||||
};
|
||||
|
||||
class ConfigGetParameter : public common::Jsonize
|
||||
{
|
||||
public:
|
||||
ConfigGetParameter()
|
||||
{}
|
||||
|
||||
~ConfigGetParameter()
|
||||
{}
|
||||
|
||||
void fromJson(common::JsonMap& json)
|
||||
{
|
||||
common::FromJson(json["name"], name);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const
|
||||
{
|
||||
common::ToJson(name, json["name"]);
|
||||
}
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class ConfigGetData : public common::Jsonize
|
||||
{
|
||||
public:
|
||||
ConfigGetData()
|
||||
{}
|
||||
|
||||
~ConfigGetData()
|
||||
{}
|
||||
|
||||
void fromJson(common::JsonMap& json)
|
||||
{
|
||||
common::FromJson(json["content"], content);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const
|
||||
{
|
||||
common::ToJson(content, json["content"]);
|
||||
}
|
||||
|
||||
public:
|
||||
std::string content;
|
||||
};
|
||||
|
||||
class ConfigDelParameter : public common::Jsonize
|
||||
{
|
||||
public:
|
||||
ConfigDelParameter()
|
||||
{}
|
||||
|
||||
~ConfigDelParameter()
|
||||
{}
|
||||
|
||||
void fromJson(common::JsonMap& json)
|
||||
{
|
||||
common::FromJson(json["name"], name);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const
|
||||
{
|
||||
common::ToJson(name, json["name"]);
|
||||
}
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class ConfigMetaParameter : public common::Jsonize
|
||||
{
|
||||
public:
|
||||
ConfigMetaParameter()
|
||||
{}
|
||||
|
||||
~ConfigMetaParameter()
|
||||
{}
|
||||
|
||||
void fromJson(common::JsonMap& json)
|
||||
{
|
||||
common::FromJson(json["name"], name);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const
|
||||
{
|
||||
common::ToJson(name, json["name"]);
|
||||
}
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class ConfigMetaData : public common::Jsonize
|
||||
{
|
||||
public:
|
||||
ConfigMetaData()
|
||||
{}
|
||||
|
||||
~ConfigMetaData()
|
||||
{}
|
||||
|
||||
void fromJson(common::JsonMap& json)
|
||||
{
|
||||
common::FromJson(json["meta"], meta);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const
|
||||
{
|
||||
common::ToJson(meta, json["meta"]);
|
||||
}
|
||||
|
||||
public:
|
||||
JsonizeConfigMeta meta;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif//__UT_ROBOT_B2_CONFIG_API_HPP__
|
@@ -0,0 +1,68 @@
|
||||
#ifndef __UT_ROBOT_B2_CONFIG_CLIENT_HPP__
|
||||
#define __UT_ROBOT_B2_CONFIG_CLIENT_HPP__
|
||||
|
||||
#include <unitree/robot/client/client.hpp>
|
||||
#include <unitree/robot/channel/channel_subscriber.hpp>
|
||||
#include <unitree/idl/go2/ConfigChangeStatus_.hpp>
|
||||
|
||||
namespace unitree
|
||||
{
|
||||
namespace robot
|
||||
{
|
||||
namespace b2
|
||||
{
|
||||
/*
|
||||
* @brief ConfigMeta
|
||||
*/
|
||||
class ConfigMeta
|
||||
{
|
||||
public:
|
||||
ConfigMeta() : size(-1), epoch(-1)
|
||||
{}
|
||||
~ConfigMeta()
|
||||
{}
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
std::string lastModified;
|
||||
int32_t size;
|
||||
int32_t epoch;
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief ConfigClient
|
||||
*/
|
||||
|
||||
using ConfigChangeStatusCallback = std::function<void(const std::string&,const std::string&)>;
|
||||
|
||||
class ConfigClient : public Client
|
||||
{
|
||||
public:
|
||||
explicit ConfigClient();
|
||||
~ConfigClient();
|
||||
|
||||
void Init();
|
||||
|
||||
int32_t Set(const std::string& name, const std::string& content);
|
||||
int32_t Get(const std::string& name, std::string& content);
|
||||
int32_t Del(const std::string& name);
|
||||
int32_t Meta(const std::string& name, ConfigMeta& meta);
|
||||
int32_t Meta(const std::string& name, std::string& meta);
|
||||
|
||||
void SubscribeChangeStatus(const std::string& name, const ConfigChangeStatusCallback& callback);
|
||||
|
||||
private:
|
||||
void ChangeStatusMessageHandler(const void* message);
|
||||
|
||||
private:
|
||||
unitree::common::Mutex mLock;
|
||||
std::map<std::string,ConfigChangeStatusCallback> mNameCallbackMap;
|
||||
ChannelSubscriberPtr<unitree_go::msg::dds_::ConfigChangeStatus_> mSubscriberPtr;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif//__UT_ROBOT_B2_CONFIG_CLIENT_HPP__
|
||||
|
29
unitree_SDK/include/unitree/robot/b2/config/config_error.hpp
Normal file
29
unitree_SDK/include/unitree/robot/b2/config/config_error.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef __UT_ROBOT_B2_CONFIG_ERROR_HPP__
|
||||
#define __UT_ROBOT_B2_CONFIG_ERROR_HPP__
|
||||
|
||||
namespace unitree
|
||||
{
|
||||
namespace robot
|
||||
{
|
||||
namespace b2
|
||||
{
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_PARAMETER, 8201, "parameter error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_NOT_FOUND, 8202, "config name is not found.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_NAME, 8203, "name is invalid.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_LIMITED, 8204, "name/content length limited.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_LOCK, 8205, "lock error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_LOAD_META, 8206, "load meta error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_SAVE_META, 8207, "save meta error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_TEMP_META, 8208, "save meta temp error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_FORMAL_META, 8209, "formalize meta error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_REMOVE_META, 8210, "remove meta error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_LOAD_DATA, 8211, "load data error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_SAVE_DATA, 8212, "save data error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_TEMP_DATA, 8213, "save data temp error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_FORMAL_DATA, 8214, "formalize data error.")
|
||||
UT_DECL_ERR(UT_CONFIG_ERR_REMOVE_DATA, 8215, "remove data error.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif//__UT_ROBOT_B2_CONFIG_ERROR_HPP__
|
Reference in New Issue
Block a user