Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call remote functions from a C++ client #22

Open
grassjelly opened this issue May 2, 2023 · 0 comments
Open

How to call remote functions from a C++ client #22

grassjelly opened this issue May 2, 2023 · 0 comments

Comments

@grassjelly
Copy link

grassjelly commented May 2, 2023

I am trying to write an Odrive C++ client by using the test_node.cpp in the test directory as a reference to instantiate the required helper objects using the latest API found in libfibre.h. I managed to compile my application with no errors but was wondering how does one access/run the functions similar to what is demonstrated in the JS demo?

The odrive interfaces has also been created by passing the latest odrive-interface.yaml from the Odrive repository to the generator tool.

here's my on_found_cb function:

void on_found_cb(void* fibre_obj_ptr, LibFibreObject* obj, LibFibreInterface* intf, const char* path, size_t path_length) {
  fibre_obj_ptr = obj;
 
  // I tried this with no luck
  //obj->get_vbus_voltage();

  //obj->vel_input(2);  
  //from odrive interfce:
  //In `CONTROL_MODE_VELOCITY_CONTROL`, sets the desired velocity of the axis.
}

I also managed to port the old example to use the new API but am not so sure how to access the returned value after the function call and pass arguments to the remote functions.

Another version of on_found_cb function:

void on_found_cb(void* fibre_obj_ptr, LibFibreObject* obj, LibFibreInterface* intf, const char* path, size_t path_length) {
  fibre_obj_ptr = obj;

  LibFibreInterfaceInfo* info = libfibre_get_interface_info(intf);
  for (size_t i = 0; i < sizeof(info->functions); ++i) {
  if (std::strcmp(info->name, "get_vbus_voltage") == 0)
    {
      LibFibreObject** child_obj_ptr;
      libfibre_get_attribute(intf, obj, i, child_obj_ptr);

      fibre::Function* func = reinterpret_cast<fibre::Function*>(info->functions[i]);
      CoroAsFunc* call = new CoroAsFunc{func};
      uint8_t tx_buf[sizeof(LibFibreObject*)];
      *(LibFibreObject**)tx_buf = obj;
      cbufptr_t args[] = {tx_buf};
      call->call(&args[0], 1, &on_finished_call);
    }
  }
  libfibre_free_interface_info(info);
}

Thank you!

@grassjelly grassjelly changed the title running function from C++ client How to call remote functions from a C++ client May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant