From db8d38a6b7cdd7a066e3d5f1e8dcdbd247a96832 Mon Sep 17 00:00:00 2001 From: Yu Date: Fri, 28 Aug 2020 13:59:23 +0900 Subject: [PATCH] Add CAPIs to control UWB network and location engine Change-Id: I47c81cc954fc64fe5063286a7fa5e62c59533e96 Signed-off-by: Yu jiung --- include/uwb.h | 17 ++ packaging/capi-network-uwb.spec | 2 +- src/uwb-gdbuslib.xml | 37 +++++ src/uwb.c | 273 +++++++++++++++++++++++++++++++- tests/capi-network-uwb-test.c | 101 ++++++++++++ 5 files changed, 428 insertions(+), 2 deletions(-) diff --git a/include/uwb.h b/include/uwb.h index 3717eb8..a6ad849 100755 --- a/include/uwb.h +++ b/include/uwb.h @@ -48,6 +48,11 @@ typedef void (*uwb_message_received_cb)(uint64_t node_id, const unsigned char *m int message_length, void *user_data); typedef void (*uwb_position_changed_cb)(uint64_t node_id, int x, int y, int z, void *user_data); +typedef void (*uwb_position_updated_cb)(uint64_t node_id, int x, int y, int z, + void *user_data); +typedef void (*uwb_node_added_cb)(uwb_node_h remote_node, void *user_data); +typedef void (*uwb_node_updated_cb)(uwb_node_h remote_node, void *user_data); +typedef void (*uwb_node_removed_cb)(uwb_node_h remote_node, void *user_data); typedef void (*uwb_get_network_finished_cb)(int result, uwb_network_h network, void *user_data); typedef bool (*uwb_network_foreach_remote_node_cb)(uwb_node_h remote_node, void *user_data); @@ -57,8 +62,20 @@ int uwb_reset(void); int uwb_factory_reset(void); int uwb_set_message_received_cb(uwb_message_received_cb message_received_cb, void *user_data); int uwb_set_position_changed_cb(uwb_position_changed_cb position_changed_cb, void *user_data); +int uwb_set_position_updated_cb(uwb_position_updated_cb position_updated_cb, void *user_data); +int uwb_set_node_added_cb(uwb_node_added_cb node_added_cb, void *user_data); +int uwb_set_node_updated_cb(uwb_node_updated_cb node_updated_cb, void *user_data); +int uwb_set_node_removed_cb(uwb_node_removed_cb uode_removed_cb, void *user_data); int uwb_unset_message_received_cb(void); int uwb_unset_position_changed_cb(void); +int uwb_unset_position_updated_cb(void); +int uwb_unset_node_added_cb(void); +int uwb_unset_node_updated_cb(void); +int uwb_unset_node_removed_cb(void); +int uwb_network_enable(void); +int uwb_network_disable(void); +int uwb_location_engine_start(const char *server, int port); +int uwb_location_engine_stop(void); int uwb_node_set_position(uwb_node_h node, int x, int y, int z); int uwb_node_send_message(const unsigned char *message, int len); int uwb_node_send_message_to(uwb_node_h node, const unsigned char *message, int len); diff --git a/packaging/capi-network-uwb.spec b/packaging/capi-network-uwb.spec index 25a9794..2f96ee5 100644 --- a/packaging/capi-network-uwb.spec +++ b/packaging/capi-network-uwb.spec @@ -1,6 +1,6 @@ Name: capi-network-uwb Summary: UWB CAPI -Version: 0.1.1 +Version: 0.1.2 Release: 0 Group: Network & Connectivity/API License: Apache-2.0 diff --git a/src/uwb-gdbuslib.xml b/src/uwb-gdbuslib.xml index 4cba98f..9e43337 100755 --- a/src/uwb-gdbuslib.xml +++ b/src/uwb-gdbuslib.xml @@ -10,6 +10,16 @@ + + + + + + + + + + @@ -51,5 +61,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/uwb.c b/src/uwb.c index 50851e9..a4c91ac 100755 --- a/src/uwb.c +++ b/src/uwb.c @@ -30,13 +30,22 @@ #define UWB_DBUS_SERVICE "org.tizen.uwb" /**< For uwb dbus */ #define UWB_DBUS_MANAGER_PATH "/org/tizen/uwb/manager" /**< For manager dbus */ - static struct _uwb_ctx { Manager *manager_proxy; uwb_message_received_cb message_received_cb; void *message_received_user_data; uwb_position_changed_cb position_changed_cb; void *position_changed_user_data; + + uwb_position_updated_cb position_updated_cb; + void *position_updated_user_data; + uwb_node_added_cb node_added_cb; + void *node_added_user_data; + uwb_node_updated_cb node_updated_cb; + void *node_updated_user_data; + uwb_node_removed_cb node_removed_cb; + void *node_removed_user_data; + uwb_get_network_finished_cb get_network_finished_cb; uwb_network_foreach_remote_node_cb foreach_remote_node_cb; } uwb_ctx = {NULL,}; @@ -107,6 +116,45 @@ static void __position_changed(GObject *source_object, uwb_ctx.position_changed_cb(node_id, x, y, z, uwb_ctx.position_changed_user_data); } + +static void __position_updated(GObject *source_object, + guint16 node_id, gint x, gint y, gint z) +{ + _BEGIN(); + if (uwb_ctx.position_updated_cb != NULL) + uwb_ctx.position_updated_cb(node_id, x, y, z, uwb_ctx.position_updated_user_data); +} + + +static void __node_added(GObject *source_object, + gint pan_id, guint16 node_id, gint x, gint y, gint z) +{ + _BEGIN(); + uwb_node_s remote_node = {node_id, pan_id, true, 0, x, y, z}; + if (uwb_ctx.node_added_cb != NULL) + uwb_ctx.node_added_cb(&remote_node, uwb_ctx.node_added_user_data); +} + + +static void __node_updated(GObject *source_object, + gint pan_id, guint16 node_id, gint x, gint y, gint z) +{ + _BEGIN(); + uwb_node_s remote_node = {node_id, pan_id, true, 0, x, y, z}; + if (uwb_ctx.node_updated_cb != NULL) + uwb_ctx.node_updated_cb(&remote_node, uwb_ctx.node_updated_user_data); +} + + +static void __node_removed(GObject *source_object, + gint pan_id, guint16 node_id, gint x, gint y, gint z) +{ + _BEGIN(); + uwb_node_s remote_node = {node_id, pan_id, true, 0, x, y, z}; + if (uwb_ctx.node_removed_cb != NULL) + uwb_ctx.node_removed_cb(&remote_node, uwb_ctx.node_removed_user_data); +} + static int manager_proxy_init(void) { GError *error = NULL; @@ -134,6 +182,18 @@ static int manager_proxy_init(void) g_signal_connect(uwb_ctx.manager_proxy, "position-changed", G_CALLBACK(__position_changed), NULL); + g_signal_connect(uwb_ctx.manager_proxy, "position-updated", + G_CALLBACK(__position_updated), NULL); + + g_signal_connect(uwb_ctx.manager_proxy, "node-added", + G_CALLBACK(__node_added), NULL); + + g_signal_connect(uwb_ctx.manager_proxy, "node-updated", + G_CALLBACK(__node_updated), NULL); + + g_signal_connect(uwb_ctx.manager_proxy, "node-removed", + G_CALLBACK(__node_removed), NULL); + return UWB_ERROR_NONE; } @@ -247,6 +307,70 @@ EXPORT_API int uwb_set_position_changed_cb(uwb_position_changed_cb position_chan return ret; } +EXPORT_API int uwb_set_position_updated_cb(uwb_position_updated_cb position_updated_cb, void *user_data) +{ + int ret = UWB_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + + _BEGIN(); + + uwb_ctx.position_updated_cb = position_updated_cb; + uwb_ctx.position_updated_user_data = user_data; + + _END(); + + return ret; +} + +EXPORT_API int uwb_set_node_added_cb(uwb_node_added_cb node_added_cb, void *user_data) +{ + int ret = UWB_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + + _BEGIN(); + + uwb_ctx.node_added_cb = node_added_cb; + uwb_ctx.node_added_user_data = user_data; + + _END(); + + return ret; +} + +EXPORT_API int uwb_set_node_updated_cb(uwb_node_updated_cb node_updated_cb, void *user_data) +{ + int ret = UWB_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + + _BEGIN(); + + uwb_ctx.node_updated_cb = node_updated_cb; + uwb_ctx.node_updated_user_data = user_data; + + _END(); + + return ret; +} + +EXPORT_API int uwb_set_node_removed_cb(uwb_node_removed_cb node_removed_cb, void *user_data) +{ + int ret = UWB_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + + _BEGIN(); + + uwb_ctx.node_removed_cb = node_removed_cb; + uwb_ctx.node_removed_user_data = user_data; + + _END(); + + return ret; +} + EXPORT_API int uwb_unset_message_received_cb(void) { int ret = UWB_ERROR_NONE; @@ -279,6 +403,153 @@ EXPORT_API int uwb_unset_position_changed_cb(void) return ret; } +EXPORT_API int uwb_unset_position_updated_cb(void) +{ + int ret = UWB_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + + _BEGIN(); + + uwb_ctx.position_updated_cb = NULL; + uwb_ctx.position_updated_user_data = NULL; + + _END(); + + return ret; +} + +EXPORT_API int uwb_unset_node_added_cb(void) +{ + int ret = UWB_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + + _BEGIN(); + + uwb_ctx.node_added_cb = NULL; + uwb_ctx.node_added_user_data = NULL; + + _END(); + + return ret; +} + +EXPORT_API int uwb_unset_node_updated_cb(void) +{ + int ret = UWB_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + + _BEGIN(); + + uwb_ctx.node_updated_cb = NULL; + uwb_ctx.node_updated_user_data = NULL; + + _END(); + + return ret; +} + +EXPORT_API int uwb_unset_node_removed_cb(void) +{ + int ret = UWB_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + + _BEGIN(); + + uwb_ctx.node_removed_cb = NULL; + uwb_ctx.node_removed_user_data = NULL; + + _END(); + + return ret; +} + +EXPORT_API int uwb_network_enable(void) +{ + int ret = UWB_ERROR_NONE; + GError *error = NULL; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + CHECK_NOT_INITIALIZED(); + + _BEGIN(); + + if (manager_call_enable_network_sync(uwb_ctx.manager_proxy, NULL, &error) == FALSE) { + _ERR("manager_call_enable_network_sync failed : %s", error->message); + __handle_error(error, &ret); + } + + _END(); + + return ret; +} + +EXPORT_API int uwb_network_disable(void) +{ + int ret = UWB_ERROR_NONE; + GError *error = NULL; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + CHECK_NOT_INITIALIZED(); + + _BEGIN(); + + if (manager_call_disable_network_sync(uwb_ctx.manager_proxy, NULL, &error) == FALSE) { + _ERR("manager_call_disable_network_sync failed : %s", error->message); + __handle_error(error, &ret); + } + + _END(); + + return ret; +} + +EXPORT_API int uwb_location_engine_start(const char *server, int port) +{ + int ret = UWB_ERROR_NONE; + GError *error = NULL; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + CHECK_NOT_INITIALIZED(); + + _BEGIN(); + + uwb_check_null_ret_error("server", server, UWB_ERROR_INVALID_PARAMETER); + + if (manager_call_start_location_engine_sync(uwb_ctx.manager_proxy, + server, port, NULL, &error) == FALSE) { + _ERR("manager_call_start_location_engine_sync failed : %s", error->message); + __handle_error(error, &ret); + } + + _END(); + + return ret; +} + +EXPORT_API int uwb_location_engine_stop(void) +{ + int ret = UWB_ERROR_NONE; + GError *error = NULL; + + CHECK_FEATURE_SUPPORTED(UWB_FEATURE); + CHECK_NOT_INITIALIZED(); + + _BEGIN(); + + if (manager_call_stop_location_engine_sync(uwb_ctx.manager_proxy, NULL, &error) == FALSE) { + _ERR("manager_call_stop_location_engine_sync failed : %s", error->message); + __handle_error(error, &ret); + } + + _END(); + + return ret; +} + EXPORT_API int uwb_get_own_node(uwb_node_h *own_node) { int ret = UWB_ERROR_NONE; diff --git a/tests/capi-network-uwb-test.c b/tests/capi-network-uwb-test.c index 7fbd64d..5077582 100644 --- a/tests/capi-network-uwb-test.c +++ b/tests/capi-network-uwb-test.c @@ -34,7 +34,11 @@ enum { CMD_DEINITIALIZE, CMD_RESET, CMD_FACTORY_RESET, + CMD_NETWORK_ENABLE, + CMD_NETWORK_DISABLE, CMD_GET_OWN_NODE, + CMD_LOCATION_ENGINE_START, + CMD_LOCATION_ENGINE_STOP, CMD_GET_NETWORK, CMD_SET_POSITION, CMD_SEND_MESSAGE, @@ -58,8 +62,16 @@ char *g_menu_str[] = { = "RESET", [CMD_FACTORY_RESET] = "FACTORY_RESET", + [CMD_NETWORK_ENABLE] + = "NETWORK_ENABLE", + [CMD_NETWORK_DISABLE] + = "NETWORK_DISABLE", [CMD_GET_OWN_NODE] = "GET_OWN_NODE", + [CMD_LOCATION_ENGINE_START] + = "LOCATION_ENGINE_START", + [CMD_LOCATION_ENGINE_STOP] + = "LOCATION_ENGINE_STOP", [CMD_GET_NETWORK] = "GET_NETWORK", @@ -198,6 +210,28 @@ void test_quit(void) return; } + +void __position_updated_cb(uint64_t node_id, int x, int y, int z, + void *user_data) +{ + +} + +void __node_added_cb(uwb_node_h remote_node, void *user_data) +{ + +} + +void __node_updated_cb(uwb_node_h remote_node, void *user_data) +{ + +} + +void __node_removed_cb(uwb_node_h remote_node, void *user_data) +{ + +} + void test_init(void) { int ret = 0; @@ -207,6 +241,11 @@ void test_init(void) ret = uwb_initialize(); __print_result(ret, "uwb_initialize"); + uwb_set_position_updated_cb(__position_updated_cb, NULL); + uwb_set_node_added_cb(__node_added_cb, NULL); + uwb_set_node_updated_cb(__node_updated_cb, NULL); + uwb_set_node_removed_cb(__node_removed_cb, NULL); + return; } @@ -216,6 +255,12 @@ void test_deinit(void) RET_IF_LOOP_IS_NULL(); + + uwb_unset_position_updated_cb(); + uwb_unset_node_added_cb(); + uwb_unset_node_updated_cb(); + uwb_unset_node_removed_cb(); + ret = uwb_deinitialize(); __print_result(ret, "uwb_deinitialize"); @@ -246,6 +291,30 @@ void test_factory_reset(void) return; } +void test_network_enable(void) +{ + int ret = 0; + + RET_IF_LOOP_IS_NULL(); + + ret = uwb_network_enable(); + __print_result(ret, "uwb_network_enable"); + + return; +} + +void test_network_disable(void) +{ + int ret = 0; + + RET_IF_LOOP_IS_NULL(); + + ret = uwb_network_disable(); + __print_result(ret, "uwb_network_disable"); + + return; +} + bool __print_node_info(uwb_node_h node, void *user_data) { uint64_t distance = 0; @@ -304,6 +373,30 @@ void test_get_own_node(void) return; } +void test_location_engine_start(void) +{ + int ret = 0; + + RET_IF_LOOP_IS_NULL(); + + ret = uwb_location_engine_start("localhost", 1883); + __print_result(ret, "uwb_location_engine_start"); + + return; +} + +void test_location_engine_stop(void) +{ + int ret = 0; + + RET_IF_LOOP_IS_NULL(); + + ret = uwb_location_engine_stop(); + __print_result(ret, "uwb_location_engine_stop"); + + return; +} + void __print_network_info(uwb_network_h uwb_network) { uint64_t pan_id = 0; @@ -518,8 +611,16 @@ test_func g_menu_func[] = { [CMD_FACTORY_RESET] = test_factory_reset, + [CMD_NETWORK_ENABLE] + = test_network_enable, + [CMD_NETWORK_DISABLE] + = test_network_disable, [CMD_GET_OWN_NODE] = test_get_own_node, + [CMD_LOCATION_ENGINE_START] + = test_location_engine_start, + [CMD_LOCATION_ENGINE_STOP] + = test_location_engine_stop, [CMD_GET_NETWORK] = test_get_network, -- 2.34.1