Skip to content

Commit

Permalink
fix #87
Browse files Browse the repository at this point in the history
  • Loading branch information
tmori committed Jan 11, 2025
1 parent 021a323 commit 3b9a10c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
18 changes: 18 additions & 0 deletions bindings/python/hako_asset_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ static PyObject* py_hako_asset_pdu_write(PyObject*, PyObject* args) {
return Py_BuildValue("O", Py_False);
}
}
static PyObject* py_hako_asset_pdu_create(PyObject*, PyObject* args) {
const char* robo_name;
HakoPduChannelIdType lchannel;
size_t pdu_size;

if (!PyArg_ParseTuple(args, "siL", &robo_name, &lchannel, &pdu_size)) {
return NULL;
}

int result = hako_asset_pdu_create(robo_name, lchannel, pdu_size);

if (result == 0) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
static PyObject* py_hako_conductor_start(PyObject*, PyObject* args) {
hako_time_t delta_usec, max_delay_usec;

Expand Down Expand Up @@ -241,6 +258,7 @@ static PyObject* py_init_for_external(PyObject*, PyObject*) {
static PyMethodDef hako_asset_python_methods[] = {
{"asset_register", asset_register, METH_VARARGS, "Register asset"},
{"init_for_external", py_init_for_external, METH_NOARGS, "Initialize for external"},
{"pdu_create", py_hako_asset_pdu_create, METH_VARARGS, "Create PDU data for the specified robot name and channel ID."},
{"start", py_hako_asset_start, METH_VARARGS, "Start the asset."},
{"simulation_time", py_hako_asset_simulation_time, METH_NOARGS, "Get the current simulation time."},
{"usleep", py_hako_asset_usleep, METH_VARARGS, "Sleep for the specified time in microseconds."},
Expand Down
4 changes: 4 additions & 0 deletions src/assets/src/hako_asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ int hako_initialize_for_external(void)
std::cout << "INFO: Success for external initialization." << std::endl;
return 0;
}
int hako_asset_pdu_create(const char *robo_name, HakoPduChannelIdType lchannel, size_t pdu_size)
{
return hako_asset_impl_pdu_create(robo_name, lchannel, pdu_size);
}
int hako_asset_start(void) {
if (hako_asset_instance.is_initialized == false) {
std::cerr << "Error: not initialized." << std::endl;
Expand Down
14 changes: 13 additions & 1 deletion src/assets/src/hako_asset_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,19 @@ bool hako_asset_impl_initialize_for_external()
hako_asset_instance.is_initialized = true;
return true;
}

int hako_asset_impl_pdu_create(const char *robo_name, HakoPduChannelIdType lchannel, size_t pdu_size)
{
if (!hako_asset_instance.is_initialized) {
return false;
}
std::string robotName = robo_name;
bool err = hako_asset_instance.hako_asset->create_pdu_lchannel(robotName, lchannel, pdu_size);
if (err == false) {
std::cerr << "ERROR: Can not create_pdu_channel()" << std::endl;
return false;
}
return true;
}
bool hako_asset_impl_register_callback(const hako_asset_callbacks_t* callback)
{
if (hako_asset_instance.external_use) {
Expand Down
1 change: 1 addition & 0 deletions src/assets/src/hako_asset_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern bool hako_asset_impl_pdu_read(const char* robo_name, HakoPduChannelIdType
extern bool hako_asset_impl_pdu_write(const char* robo_name, HakoPduChannelIdType lchannel, const char* buffer, size_t buffer_len);

extern bool hako_asset_impl_initialize_for_external();
extern int hako_asset_impl_pdu_create(const char *robo_name, HakoPduChannelIdType lchannel, size_t pdu_size);

/*
* for master api for test
Expand Down
1 change: 1 addition & 0 deletions src/include/hako_asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern hako_time_t hako_asset_simulation_time(void);
extern int hako_asset_usleep(hako_time_t sleep_time_usec);

extern int hako_initialize_for_external(void);
extern int hako_asset_pdu_create(const char *robo_name, HakoPduChannelIdType lchannel, size_t pdu_size);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 3b9a10c

Please sign in to comment.