Skip to content

Commit 3b9a10c

Browse files
committed
fix #87
1 parent 021a323 commit 3b9a10c

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

bindings/python/hako_asset_python.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,23 @@ static PyObject* py_hako_asset_pdu_write(PyObject*, PyObject* args) {
210210
return Py_BuildValue("O", Py_False);
211211
}
212212
}
213+
static PyObject* py_hako_asset_pdu_create(PyObject*, PyObject* args) {
214+
const char* robo_name;
215+
HakoPduChannelIdType lchannel;
216+
size_t pdu_size;
217+
218+
if (!PyArg_ParseTuple(args, "siL", &robo_name, &lchannel, &pdu_size)) {
219+
return NULL;
220+
}
221+
222+
int result = hako_asset_pdu_create(robo_name, lchannel, pdu_size);
223+
224+
if (result == 0) {
225+
Py_RETURN_TRUE;
226+
} else {
227+
Py_RETURN_FALSE;
228+
}
229+
}
213230
static PyObject* py_hako_conductor_start(PyObject*, PyObject* args) {
214231
hako_time_t delta_usec, max_delay_usec;
215232

@@ -241,6 +258,7 @@ static PyObject* py_init_for_external(PyObject*, PyObject*) {
241258
static PyMethodDef hako_asset_python_methods[] = {
242259
{"asset_register", asset_register, METH_VARARGS, "Register asset"},
243260
{"init_for_external", py_init_for_external, METH_NOARGS, "Initialize for external"},
261+
{"pdu_create", py_hako_asset_pdu_create, METH_VARARGS, "Create PDU data for the specified robot name and channel ID."},
244262
{"start", py_hako_asset_start, METH_VARARGS, "Start the asset."},
245263
{"simulation_time", py_hako_asset_simulation_time, METH_NOARGS, "Get the current simulation time."},
246264
{"usleep", py_hako_asset_usleep, METH_VARARGS, "Sleep for the specified time in microseconds."},

src/assets/src/hako_asset.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ int hako_initialize_for_external(void)
4545
std::cout << "INFO: Success for external initialization." << std::endl;
4646
return 0;
4747
}
48+
int hako_asset_pdu_create(const char *robo_name, HakoPduChannelIdType lchannel, size_t pdu_size)
49+
{
50+
return hako_asset_impl_pdu_create(robo_name, lchannel, pdu_size);
51+
}
4852
int hako_asset_start(void) {
4953
if (hako_asset_instance.is_initialized == false) {
5054
std::cerr << "Error: not initialized." << std::endl;

src/assets/src/hako_asset_impl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,19 @@ bool hako_asset_impl_initialize_for_external()
198198
hako_asset_instance.is_initialized = true;
199199
return true;
200200
}
201-
201+
int hako_asset_impl_pdu_create(const char *robo_name, HakoPduChannelIdType lchannel, size_t pdu_size)
202+
{
203+
if (!hako_asset_instance.is_initialized) {
204+
return false;
205+
}
206+
std::string robotName = robo_name;
207+
bool err = hako_asset_instance.hako_asset->create_pdu_lchannel(robotName, lchannel, pdu_size);
208+
if (err == false) {
209+
std::cerr << "ERROR: Can not create_pdu_channel()" << std::endl;
210+
return false;
211+
}
212+
return true;
213+
}
202214
bool hako_asset_impl_register_callback(const hako_asset_callbacks_t* callback)
203215
{
204216
if (hako_asset_instance.external_use) {

src/assets/src/hako_asset_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern bool hako_asset_impl_pdu_read(const char* robo_name, HakoPduChannelIdType
5353
extern bool hako_asset_impl_pdu_write(const char* robo_name, HakoPduChannelIdType lchannel, const char* buffer, size_t buffer_len);
5454

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

5758
/*
5859
* for master api for test

src/include/hako_asset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern hako_time_t hako_asset_simulation_time(void);
2929
extern int hako_asset_usleep(hako_time_t sleep_time_usec);
3030

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

3334
#ifdef __cplusplus
3435
}

0 commit comments

Comments
 (0)