From 58a4825055fa13f8a8a39606000747ebc82c503a Mon Sep 17 00:00:00 2001 From: Cosmoslip <37982167+Cosmoflips@users.noreply.github.com> Date: Wed, 11 Jan 2023 16:02:16 +0800 Subject: [PATCH] Configurable DI/DO RPC Implement for ARM (#22) * Update build.yml * feat:Dio features for arm * fix:bugfix --- CMakeLists.txt | 3 +- Doxyfile | 2 +- sdk/include/lebai/robot.hh | 28 +++ sdk/src/protos/io.cc | 364 +++++++++++++++++++++++++++++++++++++ sdk/src/protos/io.hh | 155 +++++++++++++++- sdk/src/robot.cc | 32 ++++ sdk/src/robot_impl.cc | 32 ++++ sdk/src/robot_impl.hh | 4 + 8 files changed, 616 insertions(+), 4 deletions(-) mode change 100644 => 100755 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index 4abb28e..e3f11e6 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile command" TRUE) - -project(lebai VERSION 1.0.12 LANGUAGES CXX) +project(lebai VERSION 1.0.13 LANGUAGES CXX) set(PROJECT_NAMESPACE lebai) message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}") # message(STATUS "major: ${PROJECT_VERSION_MAJOR}") diff --git a/Doxyfile b/Doxyfile index fe551de..d8b0cb6 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "lebai sdk" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.0.12 +PROJECT_NUMBER = 1.0.13 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/sdk/include/lebai/robot.hh b/sdk/include/lebai/robot.hh index 907608c..45d8b93 100644 --- a/sdk/include/lebai/robot.hh +++ b/sdk/include/lebai/robot.hh @@ -546,6 +546,34 @@ namespace lebai * @return 返回多个模拟输入数值 */ std::vector get_ais(std::string device, unsigned int pin, unsigned int num); + /** + * @brief 设置数字端口输出值 + * @param pin: 端口号,从 0 开始 + * @param value: 待设置的模拟输出值 + * @return 若设置成功为true,若当前此端口为输入模式则为false + */ + bool set_dio(unsigned int pin, bool value); + /** + * @brief 设置数字端口模式 + * @param pin: 端口号,从 0 开始 + * @param value 设置的值,false为输入模式,true为输出模式 + * @return 返回是否成功 + */ + bool set_dio_mode(unsigned int pin, bool value); + /** + * @brief 获取数字端口输出值 + * @param pin: 端口号,从 0 开始 + * @param count: 查询的连续端口数 + * @return 从pin开始的连续count个端口的当前值 + */ + std::vector get_dios(unsigned int pin, unsigned int count); + /** + * @brief 获取数字端口模式 + * @param pin: 端口号,从 0 开始 + * @param count:查询的连续端口数 + * @return 从pin开始的连续count个端口的当前模式 + */ + std::vector get_dios_mode(unsigned int pin, unsigned int count); /** @}*/ diff --git a/sdk/src/protos/io.cc b/sdk/src/protos/io.cc index 3bc45b9..0c2bb5e 100644 --- a/sdk/src/protos/io.cc +++ b/sdk/src/protos/io.cc @@ -826,5 +826,369 @@ namespace lebai { return false; } + + void SetDioModeRequest::set_pin(unsigned int pin) + { + pin_ = pin; + } + unsigned int SetDioModeRequest::pin() const + { + return pin_; + } + unsigned int *SetDioModeRequest::mutable_pin() + { + return &pin_; + } + + void SetDioModeRequest::set_value(bool value) + { + value_ = value; + } + bool SetDioModeRequest::value() const + { + return value_; + } + bool *SetDioModeRequest::mutable_value() + { + return &value_; + } + + bool SetDioModeRequest::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("pin")) + { + pin_ = obj["pin"].GetUint(); + } + if(obj.HasMember("value")) + { + value_ = obj["value"].GetBool(); + } + return true; + } + bool SetDioModeRequest::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("pin"); + writer->Uint(pin_); + writer->Key("value"); + writer->Bool(value_); + writer->EndObject(); + return true; + } + bool SetDioModeRequest::IsNullJSONData() const + { + return false; + } + + void SetDioModeResponse::set_success(bool success) + { + success_ = success; + } + bool SetDioModeResponse::success() const + { + return success_; + } + bool *SetDioModeResponse::mutable_success() + { + return &success_; + } + bool SetDioModeResponse::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("success")) + { + success_ = obj["success"].GetBool(); + } + return true; + } + bool SetDioModeResponse::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("success"); + writer->Bool(success_); + writer->EndObject(); + return true; + } + bool SetDioModeResponse::IsNullJSONData() const + { + return false; + } + + void SetDioRequest::set_pin(unsigned int pin) + { + pin_ = pin; + } + unsigned int SetDioRequest::pin() const + { + return pin_; + } + unsigned int *SetDioRequest::mutable_pin() + { + return &pin_; + } + + void SetDioRequest::set_value(bool value) + { + value_ = value; + } + bool SetDioRequest::value() const + { + return value_; + } + bool *SetDioRequest::mutable_value() + { + return &value_; + } + + bool SetDioRequest::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("pin")) + { + pin_ = obj["pin"].GetUint(); + } + if(obj.HasMember("value")) + { + value_ = obj["value"].GetBool(); + } + return true; + } + bool SetDioRequest::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("pin"); + writer->Uint(pin_); + writer->Key("value"); + writer->Bool(value_); + writer->EndObject(); + return true; + } + bool SetDioRequest::IsNullJSONData() const + { + return false; + } + + void SetDioResponse::set_success(bool success) + { + success_ = success; + } + bool SetDioResponse::success() const + { + return success_; + } + bool *SetDioResponse::mutable_success() + { + return &success_; + } + bool SetDioResponse::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("success")) + { + success_ = obj["success"].GetBool(); + } + return true; + } + bool SetDioResponse::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("success"); + writer->Bool(success_); + writer->EndObject(); + return true; + } + bool SetDioResponse::IsNullJSONData() const + { + return false; + } + + void GetDiosRequest::set_pin(unsigned int pin) + { + pin_ = pin; + } + unsigned int GetDiosRequest::pin() const + { + return pin_; + } + unsigned int *GetDiosRequest::mutable_pin() + { + return &pin_; + } + + void GetDiosRequest::set_count(unsigned int count) + { + count_ = count; + } + unsigned int GetDiosRequest::count() const + { + return count_; + } + unsigned int *GetDiosRequest::mutable_count() + { + return &count_; + } + + bool GetDiosRequest::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("pin")) + { + pin_ = obj["pin"].GetUint(); + } + if(obj.HasMember("count")) + { + count_ = obj["count"].GetUint(); + } + return true; + } + bool GetDiosRequest::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("pin"); + writer->Uint(pin_); + writer->Key("count"); + writer->Uint(count_); + writer->EndObject(); + return true; + } + bool GetDiosRequest::IsNullJSONData() const + { + return false; + } + + void GetDiosResponse::set_values(std::vector values) + { + values_ = values; + } + std::vector GetDiosResponse::values() const + { + return values_; + } + std::vector *GetDiosResponse::mutable_values() + { + return &values_; + } + bool GetDiosResponse::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("values")) + { + std::vector values; + for(auto i = obj["values"].GetArray().Begin();i != obj["values"].GetArray().End();i++) + { + values.push_back(i->GetBool()); + } + values_ = values; + } + return true; + } + bool GetDiosResponse::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("values"); + writer->StartArray(); + for(auto i:values_) + { + writer->Bool(i); + } + writer->EndArray(); + writer->EndObject(); + return true; + } + bool GetDiosResponse::IsNullJSONData() const + { + return false; + } + + void GetDiosModeRequest::set_pin(unsigned int pin) + { + pin_ = pin; + } + unsigned int GetDiosModeRequest::pin() const + { + return pin_; + } + unsigned int *GetDiosModeRequest::mutable_pin() + { + return &pin_; + } + + void GetDiosModeRequest::set_count(unsigned int count) + { + count_ = count; + } + unsigned int GetDiosModeRequest::count() const + { + return count_; + } + unsigned int *GetDiosModeRequest::mutable_count() + { + return &count_; + } + + bool GetDiosModeRequest::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("pin")) + { + pin_ = obj["pin"].GetUint(); + } + if(obj.HasMember("count")) + { + count_ = obj["count"].GetUint(); + } + return true; + } + bool GetDiosModeRequest::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("pin"); + writer->Uint(pin_); + writer->Key("count"); + writer->Uint(count_); + writer->EndObject(); + return true; + } + bool GetDiosModeRequest::IsNullJSONData() const + { + return false; + } + + void GetDiosModeResponse::set_values(std::vector values) + { + values_ = values; + } + std::vector GetDiosModeResponse::values() const + { + return values_; + } + std::vector *GetDiosModeResponse::mutable_values() + { + return &values_; + } + bool GetDiosModeResponse::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("values")) + { + std::vector values; + for(auto i = obj["values"].GetArray().Begin();i != obj["values"].GetArray().End();i++) + { + values.push_back(i->GetBool()); + } + values_ = values; + } + return true; + } + bool GetDiosModeResponse::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("values"); + writer->StartArray(); + for(auto i:values_) + { + writer->Bool(i); + } + writer->EndArray(); + writer->EndObject(); + return true; + } + bool GetDiosModeResponse::IsNullJSONData() const + { + return false; + } } } \ No newline at end of file diff --git a/sdk/src/protos/io.hh b/sdk/src/protos/io.hh index 129f411..6c9d8e1 100644 --- a/sdk/src/protos/io.hh +++ b/sdk/src/protos/io.hh @@ -282,7 +282,7 @@ namespace lebai unsigned int pin() const; unsigned int *mutable_pin(); - void set_values(std::vector pin); + void set_values(std::vector values); std::vector values() const; std::vector *mutable_values(); @@ -297,5 +297,158 @@ namespace lebai virtual bool Serialize(rapidjson::Writer *writer) const; virtual bool IsNullJSONData() const; }; + + class SetDioModeRequest : public JSONBase + { + public: + void set_pin(unsigned int pin); + unsigned int pin() const; + unsigned int *mutable_pin(); + + void set_value(bool value); + bool value() const; + bool *mutable_value(); + + protected: + unsigned int pin_; + bool value_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + + class SetDioModeResponse : public JSONBase + { + public: + void set_success(bool success); + bool success() const; + bool *mutable_success(); + + protected: + bool success_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + + class SetDioRequest : public JSONBase + { + public: + void set_pin(unsigned int pin); + unsigned int pin() const; + unsigned int *mutable_pin(); + + void set_value(bool value); + bool value() const; + bool *mutable_value(); + + protected: + unsigned int pin_; + bool value_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + + class SetDioResponse : public JSONBase + { + public: + void set_success(bool success); + bool success() const; + bool *mutable_success(); + + protected: + bool success_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + + class GetDiosRequest : public JSONBase + { + public: + void set_pin(unsigned int pin); + unsigned int pin() const; + unsigned int *mutable_pin(); + + void set_count(unsigned int count); + unsigned int count() const; + unsigned int *mutable_count(); + protected: + unsigned int pin_; + unsigned int count_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + class GetDiosResponse : public JSONBase + { + public: + void set_values(std::vector pin); + std::vector values() const; + std::vector *mutable_values(); + + protected: + std::vector values_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + + class GetDiosModeRequest : public JSONBase + { + public: + void set_pin(unsigned int pin); + unsigned int pin() const; + unsigned int *mutable_pin(); + + void set_count(unsigned int count); + unsigned int count() const; + unsigned int *mutable_count(); + protected: + unsigned int pin_; + unsigned int count_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + class GetDiosModeResponse : public JSONBase + { + public: + void set_values(std::vector pin); + std::vector values() const; + std::vector *mutable_values(); + + protected: + std::vector values_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + } } \ No newline at end of file diff --git a/sdk/src/robot.cc b/sdk/src/robot.cc index f620a5a..f9c37de 100644 --- a/sdk/src/robot.cc +++ b/sdk/src/robot.cc @@ -730,6 +730,38 @@ std::vector Robot::get_ais(std::string device, unsigned int pin, unsigne io::GetAioPinsResponse resp = impl_->getAIS(req); return resp.values(); } +bool Robot::set_dio(unsigned int pin, bool value) +{ + io::SetDioRequest req; + req.set_pin(pin); + req.set_value(value); + io::SetDioResponse resp = impl_->setDio(req); + return resp.success(); +} +bool Robot::set_dio_mode(unsigned int pin, bool value) +{ + io::SetDioModeRequest req; + req.set_pin(pin); + req.set_value(value); + io::SetDioModeResponse resp = impl_->setDioMode(req); + return resp.success(); +} +std::vector Robot::get_dios(unsigned int pin, unsigned int count) +{ + io::GetDiosRequest req; + req.set_pin(pin); + req.set_count(count); + io::GetDiosResponse resp = impl_->getDios(req); + return resp.values(); +} +std::vector Robot::get_dios_mode(unsigned int pin, unsigned int count) +{ + io::GetDiosModeRequest req; + req.set_pin(pin); + req.set_count(count); + io::GetDiosModeResponse resp = impl_->getDiosMode(req); + return resp.values(); +} // bool Robot::get_robot_di(unsigned int pin) // { diff --git a/sdk/src/robot_impl.cc b/sdk/src/robot_impl.cc index 17748ce..4781371 100644 --- a/sdk/src/robot_impl.cc +++ b/sdk/src/robot_impl.cc @@ -271,6 +271,38 @@ namespace lebai get_aio_resp.FromJSONString(resp); return get_aio_resp; } + io::SetDioResponse Robot::RobotImpl::setDio(const io::SetDioRequest &req) + { + std::string resp; + json_rpc_connector_->CallRpc("set_dio", req.ToJSONString(), &resp); + io::SetDioResponse resp_; + resp_.FromJSONString(resp); + return resp_; + } + io::SetDioModeResponse Robot::RobotImpl::setDioMode(const io::SetDioModeRequest &req) + { + std::string resp; + json_rpc_connector_->CallRpc("set_dio_mode", req.ToJSONString(), &resp); + io::SetDioModeResponse resp_; + resp_.FromJSONString(resp); + return resp_; + } + io::GetDiosResponse Robot::RobotImpl::getDios(const io::GetDiosRequest &req) + { + std::string resp; + json_rpc_connector_->CallRpc("get_dios", req.ToJSONString(), &resp); + io::GetDiosResponse resp_; + resp_.FromJSONString(resp); + return resp_; + } + io::GetDiosModeResponse Robot::RobotImpl::getDiosMode(const io::GetDiosModeRequest &req) + { + std::string resp; + json_rpc_connector_->CallRpc("get_dios_mode", req.ToJSONString(), &resp); + io::GetDiosModeResponse resp_; + resp_.FromJSONString(resp); + return resp_; + } void Robot::RobotImpl::setAO(const io::SetAoPinRequest & req) { diff --git a/sdk/src/robot_impl.hh b/sdk/src/robot_impl.hh index 1351f57..7c8b81e 100644 --- a/sdk/src/robot_impl.hh +++ b/sdk/src/robot_impl.hh @@ -75,6 +75,10 @@ namespace lebai io::GetAioPinsResponse getAIS(const io::GetAioPinsRequest & req); io::GetAioPinResponse getAO(const io::GetAioPinRequest & req); io::GetAioPinsResponse getAOS(const io::GetAioPinsRequest & req); + io::SetDioResponse setDio(const io::SetDioRequest & req); + io::SetDioModeResponse setDioMode(const io::SetDioModeRequest & req); + io::GetDiosResponse getDios(const io::GetDiosRequest & req); + io::GetDiosModeResponse getDiosMode(const io::GetDiosModeRequest & req); void setAO(const io::SetAoPinRequest & req); void setClaw(const claw::SetClawRequest & req); void setLed(const led::LedData & req);