Skip to content

Commit

Permalink
added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-cavalcanti committed Oct 20, 2023
1 parent c7ec613 commit 68f4c29
Show file tree
Hide file tree
Showing 14 changed files with 601 additions and 473 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zmq_remote_api"
version = "0.2.0"
version = "4.6.0"
edition = "2021"


Expand Down
2 changes: 1 addition & 1 deletion examples/sim_ik_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() -> Result<(), RemoteAPIError> {
})?;

// Must call require before usint sim_ik functions
client.require(sim::Module::SimIK)?;
client.require(sim::Plugin::SimIK)?;

// When simulation is not running, ZMQ message handling could be a bit
// slow, since the idle loop runs at 8 Hz by default. So let's make
Expand Down
29 changes: 27 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
pub mod log_utils;
//! # ZMQ Remote API for CoppeliaSim, Rust implementation
//! The ZMQ Remote API requires the [ZMQ plugin](https://github.com/CoppeliaRobotics/simExtZMQ).
//!
//! the Current Plugins support is
//! - [SimIK](https://www.coppeliarobotics.com/helpFiles/en/simIK.htm)
//! - [The Remote API](https://www.coppeliarobotics.com/helpFiles/index.html)
//!
//! Make sure that you are using the same version of the Client and CoppeliaSim, see the branchs of the repository
//! [rust_zmqRemoteApi](https://github.com/samuel-cavalcanti/rust_zmqRemoteApi)
//!
//! ## Get started
//!
//! ```
//! use zmq_remote_api::{sim, sim::Sim, RemoteAPIError, RemoteApiClientParams};
//!
//! fn main() -> Result<(), RemoteAPIError> {
//! let client = zmq_remote_api::RemoteApiClient::new(RemoteApiClientParams::default())?;
//!
//! Ok(())
//! }
//!
//! ```
//! Or See an example in
//! [examples](https://github.com/samuel-cavalcanti/rust_zmqRemoteApi/tree/main/examples)
//!
mod log_utils;
mod remote_api_client;
mod remote_api_objects;
mod zmq_protocol;
Expand All @@ -9,5 +34,5 @@ pub use zmq_protocol::{ErrorResponse, FunctionResponse, ObjectResponse, ZmqRespo
pub use zmq_protocol::{RawRequest, ZmqRequest, LANG, VERSION};

pub use remote_api_objects::connection_error::RemoteAPIError;

/// You will need to use Json to communicate with the the ZMQ server
pub use serde_json;
9 changes: 8 additions & 1 deletion src/remote_api_client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ use crate::zmq_protocol::{RawRequest, ZmqRequest};
use crate::{log_utils, RemoteAPIError, RemoteApiClientParams};

const ZMQ_RECV_FLAG_NONE: i32 = 0;

/// The ZEROMQ Socket Connection
/// BY default host:"localhost"
/// BY default port:23000
/// # Example:
/// ```
/// use zmq_remote_api::{RemoteApiClient,RemoteApiClientParams};
/// let client = RemoteApiClient::new(RemoteApiClientParams::default()).unwrap();
/// ```
pub struct RemoteApiClient {
rpc_socket: zmq::Socket,
end_point: String,
Expand Down
4 changes: 4 additions & 0 deletions src/remote_api_client/remote_api_client_params.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/// The Socket connection Parameters, in most of the cases the default is Okay to use
/// If the simulation is running in another pc, make sure the ip is correct
pub struct RemoteApiClientParams {
/// the Ip address, the default is "localhost"
pub host: String,
/// The socket port, the default is 23000
pub rpc_port: usize,
}

Expand Down
9 changes: 6 additions & 3 deletions src/remote_api_client/remote_api_client_trait.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use serde_json::Value as JsonValue;

use crate::{sim::Module, RawRequest, RemoteAPIError, ZmqRequest, ZmqResponse};
use crate::{sim::Plugin, RawRequest, RemoteAPIError, ZmqRequest, ZmqResponse};

/// THe implementation of the [PROTOCOL](https://github.com/CoppeliaRobotics/zmqRemoteApi/blob/master/PROTOCOL.md)
/// This trait forces a socket connection to implement the PROTOCOL
/// The Sim, SimIK, rely on this trait
pub trait RemoteApiClientInterface {
fn send_raw_request(&self, request: Vec<u8>) -> Result<JsonValue, RemoteAPIError>;
fn get_uuid(&self) -> String;
fn get_callback(&self, function_name: &str) -> Option<&Box<dyn Fn(JsonValue) -> JsonValue>>;

fn require(&self, module: Module) -> Result<(), RemoteAPIError> {
fn require(&self, module: Plugin) -> Result<(), RemoteAPIError> {
let name = match module {
Module::SimIK => "simIK".into(),
Plugin::SimIK => "simIK".into(),
};

let require_req = ZmqRequest::require_request(name, self.get_uuid());
Expand Down
1 change: 1 addition & 0 deletions src/remote_api_objects/connection_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[derive(Debug)]
/// RemoteAPIError will be retured if the client was unable to send our receive messages
pub struct RemoteAPIError {
message: String,
}
Expand Down
4 changes: 2 additions & 2 deletions src/remote_api_objects/requests_macro.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
macro_rules! requests {

( $sim_type:literal, $(
($rust_fn:ident,$function_name:literal $(, ( $($arg_id:ident : $arg_type:ty),+ ) )? $(, opt( $($opt_arg_id:ident : $opt_arg_type:ty),+ ) )? $(->$return_type:ty)? )
($rust_doc:literal, $rust_fn:ident,$function_name:literal $(, ( $($arg_id:ident : $arg_type:ty),+ ) )? $(, opt( $($opt_arg_id:ident : $opt_arg_type:ty),+ ) )? $(->$return_type:ty)? )
),+ $(,)? ) => {
$(




#[doc=$rust_doc]
#[allow(dead_code,clippy::too_many_arguments)]
fn $rust_fn(&self, $( $($arg_id:$arg_type,)* )* $( $($opt_arg_id:Option<$opt_arg_type>,)* )* ) -> Result<$($return_type)*, crate::remote_api_objects::connection_error::RemoteAPIError> {//

Expand Down
6 changes: 5 additions & 1 deletion src/remote_api_objects/sim/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! All the Supported Plugins is insite this module
//! Current only the Remote API and SimIK is Supported
#[rustfmt::skip]
mod sim_api;
#[rustfmt::skip]
Expand All @@ -9,7 +12,8 @@ pub use sim_api::Sim;
pub use sim_const::*;
pub use sim_ik_api::SimIK;

pub enum Module {
/// The Supported extra plugins
pub enum Plugin {
SimIK,
}

Expand Down
Loading

0 comments on commit 68f4c29

Please sign in to comment.