diff options
author | Jihoon Jung <jh8801.jung@samsung.com> | 2021-01-28 15:43:56 +0900 |
---|---|---|
committer | Jihoon Jung <jh8801.jung@samsung.com> | 2021-01-28 15:52:23 +0900 |
commit | 7e0d84fab0150d38a596fdca252e5c46b374b879 (patch) | |
tree | c18aaf704a4432c80b83cbec8883586e60234a79 | |
parent | e3f68cd84afdd7f7c3dcd40d0311cd2a91ae1733 (diff) | |
download | uwb-manager-7e0d84fab0150d38a596fdca252e5c46b374b879.tar.gz uwb-manager-7e0d84fab0150d38a596fdca252e5c46b374b879.tar.bz2 uwb-manager-7e0d84fab0150d38a596fdca252e5c46b374b879.zip |
UWB hal : Replace HAL interface with hal-api-uwbsubmit/tizen/20210208.061437accepted/tizen/unified/20210208.073159
Change-Id: Ifb294eb7f96a1398c89e11923d4b7fb3d5a39d74
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
32 files changed, 281 insertions, 2300 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 00a26b1..e8e9071 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,28 +24,11 @@ PROJECT(uwb-manager) INCLUDE(FindPkgConfig) -SET(COMMON_DEPS "glib-2.0 gio-2.0 gio-unix-2.0 dlog libtzplatform-config json-glib-1.0") -SET(GTEST_DEPS "gmock") +SET(COMMON_DEPS "glib-2.0 gio-2.0 gio-unix-2.0 dlog libtzplatform-config json-glib-1.0 hal-api-common hal-api-uwb") SET(TARGET_UWB_MANAGER "uwb-manager") -SET(TARGET_DWM1001_PLUGIN "uwb-plugin-dwm1001") -SET(TARGET_DUMMY_PLUGIN "uwb-plugin-dummy") -SET(TARGET_UWB_MANAGER_GTEST "uwb-manager-gtest") - -IF(BUILD_PLUGIN_DUMMY) -ADD_DEFINITIONS("-DDUMMY_PLUGIN") -ENDIF(BUILD_PLUGIN_DUMMY) ADD_DEFINITIONS("-DUSE_DLOG") ADD_SUBDIRECTORY(interface) ADD_SUBDIRECTORY(src) -ADD_SUBDIRECTORY(tests) - -IF(BUILD_PLUGIN) -ADD_SUBDIRECTORY(plugin/dwm1001) -ENDIF(BUILD_PLUGIN) - -IF(BUILD_PLUGIN_DUMMY) -ADD_SUBDIRECTORY(plugin/dummy) -ENDIF(BUILD_PLUGIN_DUMMY) diff --git a/hpi/uwb-hpi.c b/hpi/uwb-hpi.c deleted file mode 100755 index 69183bf..0000000 --- a/hpi/uwb-hpi.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * UWB Service Plug-in Interface for Range - * - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file implements UWB Hardware Plug-in Interface(HPI) dwm1001 functions. - * - * @file uwb-hpi.c - * @author Jiung Yu (jiung.yu@samsung.com) - */ - -#include <uwb-log-def.h> - -#include "uwb-hpi.h" - -int uwb_hpi_init(uwb_hpi_ops_s *ops, uwb_hpi_event_cbs_s *event_cbs) -{ - if (!ops->init) - return -1; - - return ops->init(event_cbs); -} - -int uwb_hpi_deinit(uwb_hpi_ops_s *ops) -{ - if (!ops->deinit) - return -1; - - return ops->deinit(); -} - -int uwb_hpi_test(uwb_hpi_ops_s *ops) -{ - if (!ops->test) - return -1; - - return ops->test(); -} - -int uwb_hpi_reset(uwb_hpi_ops_s *ops) -{ - if (!ops->reset) - return -1; - - return ops->reset(); -} - -int uwb_hpi_factory_reset(uwb_hpi_ops_s *ops) -{ - if (!ops->factory_reset) - return -1; - - return ops->factory_reset(); -} - -int uwb_hpi_enable_network(uwb_hpi_ops_s *ops) -{ - if (!ops->enable_network) - return -1; - - return ops->enable_network(); -} - -int uwb_hpi_disable_network(uwb_hpi_ops_s *ops) -{ - if (!ops->disable_network) - return -1; - - return ops->disable_network(); -} - -int uwb_hpi_get_own_node(uwb_hpi_ops_s *ops, uwb_hpi_node_s **own_node) -{ - if (!ops->get_own_node) - return -1; - - return ops->get_own_node(own_node); -} - -int uwb_hpi_get_network_info(uwb_hpi_ops_s *ops, uwb_hpi_network_s **network_info) -{ - if (!ops->reset) - return -1; - - return ops->get_network_info(network_info); - -} - -int uwb_hpi_set_configurations(uwb_hpi_ops_s *ops, uint16_t node_id, const GVariant *configurations) -{ - if (!ops->set_configurations) - return -1; - - return ops->set_configurations(node_id, configurations); -} - -int uwb_hpi_get_configurations(uwb_hpi_ops_s *ops, uint16_t node_id, GVariant **configurations) -{ - if (!ops->get_configurations) - return -1; - - return ops->get_configurations(node_id, configurations); - -} - -int uwb_hpi_set_position(uwb_hpi_ops_s *ops, uint64_t node_id, int x, int y, int z) -{ - if (!ops->set_position) - return -1; - - return ops->set_position(node_id, x, y, z); -} - -int uwb_hpi_send_message(uwb_hpi_ops_s *ops, - const unsigned char *message, int message_length) -{ - if (!ops->send_message) - return -1; - - return ops->send_message(message, message_length); -} - -int uwb_hpi_send_message_to(uwb_hpi_ops_s *ops, uint16_t node_id, - const unsigned char *message, int message_length) -{ - if (!ops->send_message_to) - return -1; - - return ops->send_message_to(node_id, message, message_length); -} diff --git a/hpi/uwb-hpi.h b/hpi/uwb-hpi.h deleted file mode 100755 index f5e571a..0000000 --- a/hpi/uwb-hpi.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * UWB Service Plug-in Interface for Range - * - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares UWB Hardware Plug-in Interface(HPI) dwm1001 functions and structures. - * - * @file uwb-hpi-dwm1001.h - * @author Jiung Yu (jiung.yu@samsung.com) - */ - -#ifndef __UWB_HPI_H__ -#define __UWB_HPI_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* TODO: replace below headers*/ -#include <stdint.h> -#include <stdbool.h> - -#include <dlfcn.h> - -#include <glib.h> - -typedef struct { - uint64_t node_id; - uint16_t pan_id; - bool is_remote; - uint64_t distance; - int x; - int y; - int z; -} uwb_hpi_node_s; - -typedef struct { - uint16_t pan_id; - GSList *remote_node_list; - int remote_node_count; -} uwb_hpi_network_s; - -typedef struct { - void (*message_received_cb) (uint16_t node_id, unsigned char *message, int message_length); - void (*position_changed_cb) (uint16_t node_id, int x, int y, int z); -} uwb_hpi_event_cbs_s; - -typedef struct { - int (*init) (uwb_hpi_event_cbs_s *event_cbs); - int (*deinit) (void); - int (*test) (void); - int (*reset) (void); - int (*factory_reset) (void); - int (*enable_network) (void); - int (*disable_network) (void); - int (*get_network_info) (uwb_hpi_network_s **network_info); - int (*set_configurations) (uint16_t node_id, const GVariant *configurations); - int (*get_configurations) (uint16_t node_id, GVariant **configurations); - int (*set_position) (uint64_t node_id, int x, int y, int z); - int (*get_own_node) (uwb_hpi_node_s **own_node); - int (*send_message) (const unsigned char *message, int message_length); - int (*send_message_to) (uint16_t node_id, const unsigned char *message, int message_length); -} uwb_hpi_ops_s; - -int uwb_hpi_init(uwb_hpi_ops_s *ops, uwb_hpi_event_cbs_s *event_cbs); -int uwb_hpi_deinit(uwb_hpi_ops_s *ops); -int uwb_hpi_test(uwb_hpi_ops_s *ops); -int uwb_hpi_reset(uwb_hpi_ops_s *ops); -int uwb_hpi_factory_reset(uwb_hpi_ops_s *ops); -int uwb_hpi_enable_network(uwb_hpi_ops_s *ops); -int uwb_hpi_disable_network(uwb_hpi_ops_s *ops); -int uwb_hpi_get_network_info(uwb_hpi_ops_s *ops, uwb_hpi_network_s **network_info); -int uwb_hpi_set_configurations(uwb_hpi_ops_s *ops, uint16_t node_id, const GVariant *configurations); -int uwb_hpi_get_configurations(uwb_hpi_ops_s *ops, uint16_t node_id, GVariant **configurations); -int uwb_hpi_set_position(uwb_hpi_ops_s *ops, uint64_t node_id, int x, int y, int z); -int uwb_hpi_get_own_node(uwb_hpi_ops_s *ops, uwb_hpi_node_s **own_node); -int uwb_hpi_send_message(uwb_hpi_ops_s *ops, const unsigned char *message, int message_length); -int uwb_hpi_send_message_to(uwb_hpi_ops_s *ops, uint16_t node_id, const unsigned char *message, int message_length); - -#ifdef __cplusplus -} -#endif - -#endif /* __UWB_HPI_H__ */ diff --git a/include/Node.h b/include/Node.h index 000c92f..bfaf9b3 100644..100755 --- a/include/Node.h +++ b/include/Node.h @@ -19,8 +19,7 @@ #include <chrono> -//#include <uwb-log-def.h> -#include <uwb-hpi.h> +#include <uwb-def.h> #define TECH_UNKNOWN 0x00 #define TECH_UWB 0x01 @@ -39,7 +38,7 @@ public: _is_remote(false), _is_calculated(false), _tech(TECH_UNKNOWN), _last_update(std::chrono::steady_clock::now()) {}; - Node(uwb_hpi_node_s *node) : + Node(uwb_node_s *node) : _distance(node->distance), _pan_id(node->pan_id), _node_id(node->node_id), _x(node->x), _y(node->y), _z(node->z), _is_remote(node->is_remote), _is_calculated(false), _tech(TECH_UWB), diff --git a/include/UwbConfig.h b/include/UwbConfig.h index 4adb235..0b5a774 100644..100755 --- a/include/UwbConfig.h +++ b/include/UwbConfig.h @@ -19,16 +19,16 @@ #include <memory> #include <glib.h> -#include <UwbRangePlugin.h> +#include <UwbHal.h> namespace UwbManagerNamespace { class UwbConfig { public: UwbConfig() : - _configurations(nullptr), _range_plugin(nullptr) {}; - UwbConfig(std::shared_ptr<UwbRangePlugin> range_plugin) : - _configurations(nullptr), _range_plugin(range_plugin) {}; + _configurations(nullptr), _uwb_hal(nullptr) {}; + UwbConfig(std::shared_ptr<UwbHal> uwb_hal) : + _configurations(nullptr), _uwb_hal(uwb_hal) {}; ~UwbConfig(); UwbConfig(const UwbConfig& config); @@ -41,7 +41,7 @@ public: GVariant *getConfigurations(void); private: GVariant *_configurations; - std::shared_ptr<UwbRangePlugin> _range_plugin; + std::shared_ptr<UwbHal> _uwb_hal; void getConfigurationFromPlugin(void); }; diff --git a/include/UwbRangePlugin.h b/include/UwbHal.h index bf471a8..e0256e4 100644..100755 --- a/include/UwbRangePlugin.h +++ b/include/UwbHal.h @@ -14,22 +14,23 @@ * limitations under the License. */ -#ifndef __UWB_RANGE_PLUGIN_H__ -#define __UWB_RANGE_PLUGIN_H__ +#ifndef __UWB_HAL_H__ +#define __UWB_HAL_H__ #include <glib.h> -#include <uwb-hpi.h> -#include <UwbPlugin.h> +#include <hal-uwb.h> +#include <uwb-def.h> namespace UwbManagerNamespace { -class UwbRangePlugin : public UwbPlugin { +class UwbHal { public: - int init(void *uwb_plugin_load) override; - int deinit() override; - std::string getPluginPath(void) override; + int init(void); + int deinit(void); + int start(void); + int stop(void); int test(void); int reset(void); int factoryReset(void); @@ -39,8 +40,8 @@ public: int enableNetwork(void); int disableNetwork(void); - int getOwnNode(uwb_hpi_node_s **own_node); - int getNetworkInfo(uwb_hpi_network_s **network_info); + int getOwnNode(uwb_node_s **own_node); + int getNetworkInfo(uwb_network_s **network_info); int setPosition(uint64_t node_id, int x, int y, int z); int sendMessage(const unsigned char *message, int message_length); @@ -49,17 +50,9 @@ public: static void messageReceivedCb(uint16_t node_id, unsigned char *message, int message_length); static void positionChangedCb(uint16_t node_id, int x, int y, int z); private: - uwb_hpi_event_cbs_s event_cbs; - uwb_hpi_ops_s ops; -#ifdef DUMMY_PLUGIN - const std::string _plugin_path = - std::string("uwb-plugin-dummy.so"); -#else - const std::string _plugin_path = - std::string("uwb-plugin-dwm1001.so"); -#endif + uwb_event_cbs_s event_cbs; }; } -#endif /* __UWB_RANGE_PLUGIN_H__ */ +#endif /* __UWB_HAL_H__ */ diff --git a/include/UwbNetwork.h b/include/UwbNetwork.h index e213f63..ea8c058 100644..100755 --- a/include/UwbNetwork.h +++ b/include/UwbNetwork.h @@ -19,16 +19,16 @@ #include <memory> -#include <UwbRangePlugin.h> +#include <UwbHal.h> namespace UwbManagerNamespace { class UwbNetwork { public: UwbNetwork() : - _is_enable(false), _pan_id(0), _range_plugin(nullptr){}; - UwbNetwork(std::shared_ptr<UwbRangePlugin> range_plugin) : - _is_enable(false), _pan_id(0), _range_plugin(range_plugin){}; + _is_enable(false), _pan_id(0), _uwb_hal(nullptr){}; + UwbNetwork(std::shared_ptr<UwbHal> uwb_hal) : + _is_enable(false), _pan_id(0), _uwb_hal(uwb_hal){}; void setPanId(int pan_id) {_pan_id = pan_id;}; int getPanId(void) {return _pan_id;}; @@ -41,7 +41,7 @@ private: bool _is_enable; int _pan_id; - std::shared_ptr<UwbRangePlugin> _range_plugin; + std::shared_ptr<UwbHal> _uwb_hal; }; } diff --git a/include/UwbPlugin.h b/include/UwbPlugin.h deleted file mode 100644 index 74a9c21..0000000 --- a/include/UwbPlugin.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __UWB_PLUGIN_H__ -#define __UWB_PLUGIN_H__ - -#include <string> - -namespace UwbManagerNamespace { - -class UwbPlugin { - -public: - virtual ~UwbPlugin() {}; - virtual int init(void *uwb_plugin_load) = 0; - virtual int deinit(void) = 0; - virtual std::string getPluginPath(void) = 0; -}; - -} - -#endif /* __UWB_PLUGIN_H__ */ diff --git a/include/UwbPluginManager.h b/include/UwbPluginManager.h deleted file mode 100644 index 5784cfd..0000000 --- a/include/UwbPluginManager.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __UWB_PLUGIN_MANAGER_H__ -#define __UWB_PLUGIN_MANAGER_H__ - -#include <string> -#include <map> -#include <memory> - -#include <dlfcn.h> - -#include <UwbPlugin.h> - -namespace UwbManagerNamespace { - -class UwbPluginManager { -public: - UwbPluginManager() {}; - ~UwbPluginManager(); - UwbPluginManager(const UwbPluginManager &) = default; - UwbPluginManager& operator=(const UwbPluginManager&) = default; - UwbPluginManager(UwbPluginManager&&) = default; - UwbPluginManager& operator=(UwbPluginManager&&) = default; - - int load(std::shared_ptr<UwbPlugin> plugin); - int unload(std::shared_ptr<UwbPlugin> plugin); -private: - std::map <std::shared_ptr<UwbPlugin>, void *>_plugins; - const std::string _func_tbl_symbol{"uwb_plugin_load"}; -}; - -} - -#endif /* __UWB_PLUGIN_MANAGER_H__ */ diff --git a/include/UwbPosition.h b/include/UwbPosition.h index 4666d73..e49169c 100644..100755 --- a/include/UwbPosition.h +++ b/include/UwbPosition.h @@ -21,14 +21,14 @@ #include <memory> #include <Node.h> -#include <UwbRangePlugin.h> +#include <UwbHal.h> namespace UwbManagerNamespace { class UwbPosition { public: - UwbPosition(std::shared_ptr<UwbRangePlugin> range_plugin) : - _range_plugin(range_plugin){}; + UwbPosition(std::shared_ptr<UwbHal> uwb_hal) : + _uwb_hal(uwb_hal){}; int update(void); @@ -55,7 +55,7 @@ private: static constexpr double EPS = 1e-10; Node _own_node; std::list<std::unique_ptr<Node>> _node_list; - std::shared_ptr<UwbRangePlugin> _range_plugin; + std::shared_ptr<UwbHal> _uwb_hal; }; } diff --git a/include/uwb-def.h b/include/uwb-def.h new file mode 100755 index 0000000..3467076 --- /dev/null +++ b/include/uwb-def.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UWB_DEF_H__ +#define __UWB_DEF_H__ + +#include <stdint.h> +#include <stdbool.h> + +#include <dlfcn.h> + +#include <glib.h> + +typedef struct { + uint64_t node_id; + uint16_t pan_id; + bool is_remote; + uint64_t distance; + int x; + int y; + int z; +} uwb_node_s; + +typedef struct { + uint16_t pan_id; + GSList *remote_node_list; + int remote_node_count; +} uwb_network_s; + +typedef struct { + void (*message_received_cb) (uint16_t node_id, unsigned char *message, int message_length); + void (*position_changed_cb) (uint16_t node_id, int x, int y, int z); +} uwb_event_cbs_s; + +#endif /* __UWB_DEF_H__ */ diff --git a/packaging/uwb-manager.spec b/packaging/uwb-manager.spec index bb4f777..3ffee5e 100644 --- a/packaging/uwb-manager.spec +++ b/packaging/uwb-manager.spec @@ -13,9 +13,9 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(json-glib-1.0) BuildRequires: pkgconfig(paho-mqtt-c) -%if 0%{?build_plugin:1} -BuildRequires: pkgconfig(dwm1001-host-api) -%endif +BuildRequires: pkgconfig(hal-api-common) +BuildRequires: pkgconfig(hal-api-uwb) + Source1: dbus-uwb-manager.conf Source2: org.tizen.uwb.service Source3: uwb-manager.service @@ -27,34 +27,6 @@ Requires(postun): /sbin/ldconfig %description Manager for handling UWB functionalities -%package -n uwb-manager-tests -Summary: UWB manager tests -Group: Network & Connectivity/Wireless -BuildRequires: pkgconfig(gmock) - -%description -n uwb-manager-tests -UWB manager test program - -%if 0%{?build_plugin:1} -%package -n uwb-plugin-dwm1001 -Summary: UWB plugin for decawave dwm1001 -Group: Network & Connectivity/Wireless -Requires: %{name} = %{version}-%{release} - -%description -n uwb-plugin-dwm1001 -UWB manager plugin for decawave dwm1001 board -%endif - -%if 0%{?build_plugin_dummy:1} -%package -n uwb-plugin-dummy -Summary: UWB plugin for dummy operations -Group: Network & Connectivity/Wireless -Requires: %{name} = %{version}-%{release} - -%description -n uwb-plugin-dummy -UWB manager plugin for dummy operations -%endif - %prep %setup -q @@ -84,8 +56,6 @@ export LDFLAGS+=" -lgcov" -DLIB_DIR=%{_libdir} \ -DBIN_DIR=%{_bindir} \ -DTZ_SYS_RO_ETC=%{TZ_SYS_RO_ETC} \ - -DBUILD_PLUGIN=%{?build_plugin:1}%{!?build_plugin:0} \ - -DBUILD_PLUGIN_DUMMY=%{?build_plugin_dummy:1}%{!?build_plugin_dummy:0} make %{?_smp_mflags} @@ -118,24 +88,3 @@ cp uwb-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/uwb-manager.conf #DBus DAC %attr(644,root,root) %{_sysconfdir}/dbus-1/system.d/uwb-manager.conf - -%files -n uwb-manager-tests -%defattr(-,root,root,-) -%{_libdir}/mock_plugin.so -%attr(500,root,root) %{_bindir}/%{name}-gtest - -%if 0%{?build_plugin:1} -%files -n uwb-plugin-dwm1001 -%manifest uwb-plugin-dwm1001.manifest -%license LICENSE -%defattr(-,network_fw,network_fw,-) -%{_libdir}/uwb-plugin-dwm1001.so -%endif - -%if 0%{?build_plugin_dummy:1} -%files -n uwb-plugin-dummy -%manifest uwb-plugin-dummy.manifest -%license LICENSE -%defattr(-,network_fw,network_fw,-) -%{_libdir}/uwb-plugin-dummy.so -%endif diff --git a/plugin/dummy/CMakeLists.txt b/plugin/dummy/CMakeLists.txt deleted file mode 100755 index a58fc45..0000000 --- a/plugin/dummy/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# @file CMakeLists.txt -# -########################## search for packages ################################ - -PKG_CHECK_MODULES(TARGET_DUMMY_PLUGIN_REQ_PKGS REQUIRED glib-2.0 dlog json-glib-1.0) - -############################# compiler flags ################################## - -SET(EXTRA_FLAGS "-Wall -Werror") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS} ${CFLAGS}") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") - -######################## directory configuration ############################ - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/hpi) -INCLUDE_DIRECTORIES(include) -INCLUDE_DIRECTORIES(${TARGET_DUMMY_PLUGIN_REQ_PKGS_INCLUDE_DIRS}) -LINK_DIRECTORIES(${TARGET_DUMMY_PLUGIN_REQ_PKGS_LIBRARY_DIRS}) - -SET(DUMMY_PLUGIN_SRCS - uwb-plugin-dummy.c - ) - -# library build -ADD_LIBRARY(${TARGET_DUMMY_PLUGIN} SHARED ${DUMMY_PLUGIN_SRCS}) -TARGET_LINK_LIBRARIES(${TARGET_DUMMY_PLUGIN} ${TARGET_DUMMY_PLUGIN_REQ_PKGS_LIBRARIES}) -SET_TARGET_PROPERTIES(${TARGET_DUMMY_PLUGIN} PROPERTIES PREFIX "" OUTPUT_NAME ${TARGET_DUMMY_PLUGIN}) - -# install -INSTALL(TARGETS ${TARGET_DUMMY_PLUGIN} LIBRARY DESTINATION ${LIB_DIR}) diff --git a/plugin/dummy/include/uwb-plugin-dummy-private.h b/plugin/dummy/include/uwb-plugin-dummy-private.h deleted file mode 100755 index faf2844..0000000 --- a/plugin/dummy/include/uwb-plugin-dummy-private.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * UWB Plug-in Logger - * - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares UWB dummy plugin logger functions and structures. - * - * @file uwb-plugin-dummy-private.h - * @author Jiung Yu (jiung.yu@samsung.com) - */ - -#ifndef __UWB_PLUGIN_DUMMY_PRIVATE_H_ -#define __UWB_PLUGIN_DUMMY_PRIVATE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <dlog.h> -#include <glib.h> -#include <unistd.h> - -#undef LOG_TAG -#define LOG_TAG "UWB_PLUGIN_DUMMY" - -#define UWB_PLUGIN_LOGV(format, args...) LOGV(format, ##args) -#define UWB_PLUGIN_LOGD(format, args...) LOGD(format, ##args) -#define UWB_PLUGIN_LOGI(format, args...) LOGI(format, ##args) -#define UWB_PLUGIN_LOGW(format, args...) LOGW(format, ##args) -#define UWB_PLUGIN_LOGE(format, args...) LOGE(format, ##args) -#define UWB_PLUGIN_LOGF(format, args...) LOGF(format, ##args) - -#define __UWB_PLUGIN_LOG_FUNC_ENTER__ LOGD("Enter") -#define __UWB_PLUGIN_LOG_FUNC_EXIT__ LOGD("Quit") - -#define UWB_PLUGIN_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) -#define UWB_PLUGIN_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) - -#define ret_if(expr) do { \ - if (expr) { \ - UWB_PLUGIN_LOGE("(%s)", #expr); \ - return; \ - } \ - } while (0) - -#define retv_if(expr, val) do { \ - if (expr) { \ - UWB_PLUGIN_LOGE("(%s)", #expr); \ - return (val); \ - } \ - } while (0) - -typedef enum { - UWB_DUMMY_DATA_TYPE_INVALID = 0, - UWB_DUMMY_DATA_TYPE_SEND_MESSAGE, - UWB_DUMMY_DATA_TYPE_SET_POSITION, - UWB_DUMMY_DATA_TYPE_GET_NODE, - UWB_DUMMY_DATA_TYPE_MAX, -} uwb_dwm1001_data_type_e; - -typedef enum { - UWB_DUMMY_DIRECTION_TYPE_INVALID = 0, - UWB_DUMMY_DIRECTION_TYPE_REQUEST, - UWB_DUMMY_DIRECTION_TYPE_RESPONSE, - UWB_DUMMY_DIRECTION_TYPE_MAX, -} uwb_dwm1001_direction_type_e; - -#ifdef __cplusplus -} -#endif - -#endif /* __UWB_PLUGIN_DUMMY_PRIVATE_H_ */ diff --git a/plugin/dummy/include/uwb-plugin-dummy.h b/plugin/dummy/include/uwb-plugin-dummy.h deleted file mode 100755 index 37da93e..0000000 --- a/plugin/dummy/include/uwb-plugin-dummy.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * UWB Range Plug-in - * - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares UWB DUMMY board plugin functions and structures. - * - * @file uwb-plugin-dummy.h - * @author Jiung Yu (jiung.yu@samsung.com) - */ - -#ifndef __UWB_PLUGIN_DUMMY_H__ -#define __UWB_PLUGIN_DUMMY_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdbool.h> -#include <glib.h> -#include <stdlib.h> - -typedef struct { - uint64_t node_id; - uint16_t pan_id; - bool is_remote; - uint64_t distance; - int x; - int y; - int z; -} uwb_node_s; - -typedef struct { - uint16_t pan_id; - GSList *remote_node_list; - int remote_node_count; -} uwb_network_s; - -typedef struct { - void (*message_received_cb) (uint16_t node_id, unsigned char *message, int message_length); - void (*position_changed_cb) (uint16_t node_id, int x, int y, int z); -} uwb_hpi_event_cbs_s; - -typedef struct { - int (*init) (uwb_hpi_event_cbs_s *event_cbs); - int (*deinit) (void); - int (*test) (void); - int (*reset) (void); - int (*factory_reset) (void); - int (*enable_network) (void); - int (*disable_network) (void); - int (*get_network_info) (uwb_network_s **network_info); - int (*set_configurations) (uint16_t node_id, const GVariant *configurations); - int (*get_configurations) (uint16_t node_id, GVariant **configurations); - int (*set_position) (uint64_t node_id, int x, int y, int z); - int (*get_own_node) (uwb_node_s **own_node); - int (*send_message) (unsigned char *message, int message_length); - int (*send_message_to) (uint16_t node_id, unsigned char *message, int message_length); -} uwb_hpi_ops_s; - -int uwb_plugin_load(uwb_hpi_ops_s *ops); - -#ifdef __cplusplus -} -#endif - -#endif /* __UWB_PLUGIN_DUMMY_H__ */ diff --git a/plugin/dummy/include/uwb-plugin-log.h b/plugin/dummy/include/uwb-plugin-log.h deleted file mode 100755 index 79162c4..0000000 --- a/plugin/dummy/include/uwb-plugin-log.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * UWB Plug-in Logger - * - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares UWB dummy plugin logger functions and structures. - * - * @file uwb-plugin-log.h - * @author Jiung Yu (jiung.yu@samsung.com) - */ - -#ifndef __UWB_PLUGIN_LOG_H_ -#define __UWB_PLUGIN_LOG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - - -#include <dlog.h> - -#undef LOG_TAG -#define LOG_TAG "UWB_PLUGIN" - -#define UWB_PLUGIN_LOGV(format, args...) LOGV(format, ##args) -#define UWB_PLUGIN_LOGD(format, args...) LOGD(format, ##args) -#define UWB_PLUGIN_LOGI(format, args...) LOGI(format, ##args) -#define UWB_PLUGIN_LOGW(format, args...) LOGW(format, ##args) -#define UWB_PLUGIN_LOGE(format, args...) LOGE(format, ##args) -#define UWB_PLUGIN_LOGF(format, args...) LOGF(format, ##args) - -#define __UWB_PLUGIN_LOG_FUNC_ENTER__ UWB_PLUGIN_LOGI("Enter") -#define __UWB_PLUGIN_LOG_FUNC_EXIT__ UWB_PLUGIN_LOGI("Quit") - -#define UWB_PLUGIN_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) -#define UWB_PLUGIN_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) - -#ifdef __cplusplus -} -#endif - -#endif /* __UWB_PLUGIN_LOG_H_ */ diff --git a/plugin/dummy/uwb-plugin-dummy.c b/plugin/dummy/uwb-plugin-dummy.c deleted file mode 100755 index fe5b9fb..0000000 --- a/plugin/dummy/uwb-plugin-dummy.c +++ /dev/null @@ -1,443 +0,0 @@ -/* - * UWB Dummy Plug-in for ranging - * - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file implements UWB ranging plugin functions. - * - * @file uwb-plugin-dummy.c - * @author Jiung Yu (jiung.yu@samsung.com) - */ -#include <inttypes.h> - -#include "uwb-plugin-dummy.h" -#include "uwb-plugin-dummy-private.h" - -/* dwm_api.h includes below */ -#ifndef _DWM_API_H_ -/** - * @brief Device modes - */ -typedef enum { - DWM_MODE_TAG = 0, //!< DWM_MODE_TAG - DWM_MODE_ANCHOR = 1//!< DWM_MODE_ANCHOR -} dwm_mode_t; -#endif //_DWM_API_H_ -/* dwm_api.h includes above */ - - -#define DBUS_DEBUG_VARIANT(var) \ - do {\ - gchar *var_debug_str = NULL;\ - if (var)\ - var_debug_str = g_variant_print((var), TRUE);\ - UWB_PLUGIN_LOGI("value [%s]", var_debug_str ? var_debug_str : "NULL");\ - g_free(var_debug_str);\ - } while (0) - -#define MOCK_PLUGIN_DUMMY_PANID 0x1D1D -#define MOCK_PLUGIN_DUMMY_NODEID 0x1D1D -#define MOCK_PLUGIN_DUMMY_POS_X 0x1D1D -#define MOCK_PLUGIN_DUMMY_POS_Y 0x1D1D -#define MOCK_PLUGIN_DUMMY_POS_Z 0x1D1D -#define MOCK_PLUGIN_DUMMY_DISTANCE 0x1D1D -#define MOCK_PLUGIN_DUMMY_NETWORK_TIMEOUT 1500 -#define MOCK_PLUGIN_DUMMY_HARDWARE_WAIT_TIME 2000 -#define MOCK_PLUGIN_DUMMY_NODE_NUM 10 - -static struct _dummy_ctx { - bool is_enable; - uint16_t pan_id; - uint64_t node_id; - uint16_t update_rate; - uint16_t stationary_update_rate; - int network_timeout; - int hardware_wait_time; - dwm_mode_t mode; - uwb_hpi_event_cbs_s *event_cbs; -} dummy_ctx; - -static void __destroy_node(gpointer data) -{ - if (data != NULL) { - uwb_node_s *node = (uwb_node_s *)data; - free(node); - } -} - -static void __clean_dummy_ctx() -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - dummy_ctx.event_cbs = NULL; - dummy_ctx.is_enable = false; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; -} - -static void __set_default_dummy_ctx() -{ - dummy_ctx.pan_id = MOCK_PLUGIN_DUMMY_PANID; - dummy_ctx.mode = DWM_MODE_ANCHOR; - dummy_ctx.update_rate = 1; - dummy_ctx.stationary_update_rate = 1; - dummy_ctx.network_timeout = MOCK_PLUGIN_DUMMY_NETWORK_TIMEOUT; - dummy_ctx.hardware_wait_time = MOCK_PLUGIN_DUMMY_HARDWARE_WAIT_TIME; -} - -static int uwb_dummy_init(uwb_hpi_event_cbs_s *event_cbs) -{ - int ret = 0; - - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - dummy_ctx.is_enable = false; - __set_default_dummy_ctx(); - dummy_ctx.event_cbs = event_cbs; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return ret; -} - -static int uwb_dummy_deinit(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - __clean_dummy_ctx(); - dummy_ctx.is_enable = false; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -static int uwb_dummy_test(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -static int uwb_dummy_reset(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(!dummy_ctx.is_enable, -1); - - g_usleep(dummy_ctx.hardware_wait_time * 1000); - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - - -int uwb_dummy_factory_reset(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(!dummy_ctx.is_enable, -1); - - g_usleep(dummy_ctx.hardware_wait_time * 1000); - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -int uwb_dummy_enable_network(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(dummy_ctx.is_enable, -1); - - dummy_ctx.node_id = MOCK_PLUGIN_DUMMY_NODEID; - dummy_ctx.is_enable = true; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -int uwb_dummy_disable_network(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(!dummy_ctx.is_enable, -1); - - __clean_dummy_ctx(); - dummy_ctx.is_enable = false; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -int uwb_dummy_get_own_node(uwb_node_s **own_node) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(own_node == NULL, -1); - retv_if(!dummy_ctx.is_enable, -1); - - *own_node = (uwb_node_s *)malloc(sizeof(uwb_node_s)); - if (*own_node == NULL) { - UWB_PLUGIN_LOGE("own_node is NULL"); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return -1; - } - - (*own_node)->distance = 0; - (*own_node)->is_remote = false; - (*own_node)->node_id = dummy_ctx.node_id; - (*own_node)->pan_id = dummy_ctx.pan_id; - if (dummy_ctx.mode == DWM_MODE_ANCHOR) { - (*own_node)->x = MOCK_PLUGIN_DUMMY_POS_X; - (*own_node)->y = MOCK_PLUGIN_DUMMY_POS_Y; - (*own_node)->z = MOCK_PLUGIN_DUMMY_POS_Z; - } else { - (*own_node)->x = 0; - (*own_node)->y = 0; - (*own_node)->z = 0; - } - - UWB_PLUGIN_LOGI("obtained node_id : %" PRIu64, dummy_ctx.node_id); - UWB_PLUGIN_LOGI("X: %d Y: %d Z: %d", (*own_node)->x, (*own_node)->y, (*own_node)->z); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - - return 0; -} - -static GSList *__get_anchor_list_anchor() -{ - GSList *node_list = NULL; - - /* Insert Nodes to node list */ - for (int i = 1; i <= MOCK_PLUGIN_DUMMY_NODE_NUM; ++i) { - uwb_node_s *node; - - node = (uwb_node_s *)malloc(sizeof(uwb_node_s)); - if (node == NULL) { - UWB_PLUGIN_LOGE("Alloc failed"); - continue; - } - node->is_remote = true; - node->node_id = (uint64_t)(MOCK_PLUGIN_DUMMY_NODEID + i); - node->pan_id = dummy_ctx.pan_id; - node->x = MOCK_PLUGIN_DUMMY_POS_X + 1; - node->y = MOCK_PLUGIN_DUMMY_POS_Y + 1; - node->z = MOCK_PLUGIN_DUMMY_POS_Z + 1; - node->distance = 0; - node_list = g_slist_append(node_list, node); - } - - return node_list; -} - -static int test_node_x[] = {0, 0, 10, 0}; -static int test_node_y[] = {0, 10, 0, -10}; - -static GSList *__get_anchor_list_tag() -{ - GSList *node_list = NULL; - - for (int i = 1; i <= 3; ++i) { - uwb_node_s *node; - node = (uwb_node_s *)malloc(sizeof(uwb_node_s)); - if (node == NULL) { - UWB_PLUGIN_LOGE("Alloc failed"); - continue; - } - - /*TODO: Should update valid position and distance */ - node->distance = 10; - node->is_remote = true; - node->node_id = (uint64_t)(MOCK_PLUGIN_DUMMY_NODEID + i); - node->pan_id = dummy_ctx.pan_id; - node->x = test_node_x[i]; - node->y = test_node_y[i]; - node->z = 0; - node_list = g_slist_append(node_list, node); - } - - return node_list; -} - -int uwb_dummy_get_network_info(uwb_network_s **network_info) -{ - GSList *node_list = NULL; - - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(network_info == NULL, -1); - retv_if(!dummy_ctx.is_enable, -1); - - /* Get Anchor list */ - (dummy_ctx.mode == DWM_MODE_ANCHOR) ? - (node_list = __get_anchor_list_anchor()) : - (node_list = __get_anchor_list_tag()); - - *network_info = (uwb_network_s *)malloc(sizeof(uwb_network_s)); - if (*network_info == NULL) { - UWB_PLUGIN_LOGE("network info is NULL"); - g_slist_free_full(node_list, __destroy_node); - return -1; - } - - (*network_info)->pan_id = dummy_ctx.pan_id; - (*network_info)->remote_node_list = node_list; - (*network_info)->remote_node_count = g_slist_length(node_list); - - if ((*network_info)->remote_node_count == 0) { - UWB_PLUGIN_LOGE("No anchor in network"); - } - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -static void __set_dummy_ctx(GVariantIter *iter) -{ - const gchar *key = NULL; - GVariant *value = NULL; - - if (!iter) - return; - - while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { - UWB_PLUGIN_LOGI("key : %s", key); - DBUS_DEBUG_VARIANT(value); - if (g_strcmp0(key, "MODE") == 0) { - const char *mode = NULL; - mode = g_variant_get_string(value, NULL); - if (strncmp(mode, "ANCHOR", strlen(mode)) == 0) - dummy_ctx.mode = DWM_MODE_ANCHOR; - else if (strncmp(mode, "TAG", strlen(mode)) == 0) - dummy_ctx.mode = DWM_MODE_TAG; - - } - - else if (g_strcmp0(key, "UPDATE_RATE") == 0) - dummy_ctx.update_rate = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "NETWORK_TIMEOUT") == 0) - dummy_ctx.network_timeout = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "HARDWARE_WAIT_TIME") == 0) - dummy_ctx.hardware_wait_time = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "PANID") == 0) - dummy_ctx.pan_id = (uint16_t)g_variant_get_int64(value); - } - UWB_PLUGIN_LOGE("pan_id : %d", (int)dummy_ctx.pan_id); - UWB_PLUGIN_LOGE("hardware_wait_time : %d", dummy_ctx.hardware_wait_time); - UWB_PLUGIN_LOGE("network_timeout : %d", dummy_ctx.network_timeout); -} - -int uwb_dummy_set_configurations(uint16_t node_id, const GVariant *configurations) -{ - GVariantIter *iter = NULL; - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(dummy_ctx.is_enable, -1); - - g_variant_get((GVariant *)configurations, "a{sv}", &iter); - - __set_dummy_ctx(iter); - - g_variant_iter_free(iter); - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -static void __build_configuration(GVariantBuilder *builder) -{ - if (!builder) - return; - - if (dummy_ctx.mode == DWM_MODE_ANCHOR) - g_variant_builder_add(builder, "{sv}", "MODE", g_variant_new("s", "ANCHOR")); - else - g_variant_builder_add(builder, "{sv}", "MODE", g_variant_new("s", "TAG")); - UWB_PLUGIN_LOGE("network_timeout : %d", dummy_ctx.network_timeout); - g_variant_builder_add(builder, "{sv}", "NETWORK_TIMEOUT", g_variant_new("x", (int64_t)dummy_ctx.network_timeout)); - g_variant_builder_add(builder, "{sv}", "HARDWARE_WAIT_TIME", g_variant_new("x", (int64_t)dummy_ctx.hardware_wait_time)); - g_variant_builder_add(builder, "{sv}", "PANID", g_variant_new("x", (int64_t)dummy_ctx.pan_id)); -} - -int uwb_dummy_get_configurations(uint16_t node_id, GVariant **configurations) -{ - GVariantBuilder *builder; - - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - __build_configuration(builder); - *configurations = g_variant_new("a{sv}", builder); - - g_variant_builder_unref(builder); - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -int uwb_dummy_set_position(uint64_t node_id, int x, int y, int z) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(node_id == 0, -1); - retv_if(!dummy_ctx.is_enable, -1); - - if (node_id != dummy_ctx.node_id) { - UWB_PLUGIN_LOGE("Invalid node ID"); - return -1; - - } - - if (dummy_ctx.mode == DWM_MODE_TAG) { - UWB_PLUGIN_LOGE("Tag mode is not support set position"); - return -1; - } - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -int uwb_plugin_load(uwb_hpi_ops_s *ops) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - if (!ops) { - UWB_PLUGIN_LOGE("Invalid parameter"); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return -1; - } - - ops->init = uwb_dummy_init; - ops->deinit = uwb_dummy_deinit; - ops->test = uwb_dummy_test; - ops->reset = uwb_dummy_reset; - ops->factory_reset = uwb_dummy_factory_reset; - ops->enable_network = uwb_dummy_enable_network; - ops->disable_network = uwb_dummy_disable_network; - ops->get_own_node = uwb_dummy_get_own_node; - ops->get_network_info = uwb_dummy_get_network_info; - ops->set_configurations = uwb_dummy_set_configurations; - ops->get_configurations = uwb_dummy_get_configurations; - ops->set_position = uwb_dummy_set_position; - ops->send_message = NULL; - ops->send_message_to = NULL; - dummy_ctx.is_enable = false; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} diff --git a/plugin/dwm1001/CMakeLists.txt b/plugin/dwm1001/CMakeLists.txt deleted file mode 100755 index 3eac0b2..0000000 --- a/plugin/dwm1001/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# @file CMakeLists.txt -# -########################## search for packages ################################ - -PKG_CHECK_MODULES(TARGET_DWM1001_PLUGIN_REQ_PKGS REQUIRED glib-2.0 dlog dwm1001-host-api json-glib-1.0) - -############################# compiler flags ################################## - -SET(EXTRA_FLAGS "-Wall -Werror") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS} ${CFLAGS}") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") - -######################## directory configuration ############################ - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/hpi) -INCLUDE_DIRECTORIES(include) -INCLUDE_DIRECTORIES(${TARGET_DWM1001_PLUGIN_REQ_PKGS_INCLUDE_DIRS}) -LINK_DIRECTORIES(${TARGET_DWM1001_PLUGIN_REQ_PKGS_LIBRARY_DIRS}) - -SET(DWM1001_PLUGIN_SRCS - uwb-plugin-dwm1001.c - ) - -# library build -ADD_LIBRARY(${TARGET_DWM1001_PLUGIN} SHARED ${DWM1001_PLUGIN_SRCS}) -TARGET_LINK_LIBRARIES(${TARGET_DWM1001_PLUGIN} ${TARGET_DWM1001_PLUGIN_REQ_PKGS_LIBRARIES}) -SET_TARGET_PROPERTIES(${TARGET_DWM1001_PLUGIN} PROPERTIES PREFIX "" OUTPUT_NAME ${TARGET_DWM1001_PLUGIN}) - -# install -INSTALL(TARGETS ${TARGET_DWM1001_PLUGIN} LIBRARY DESTINATION ${LIB_DIR}) diff --git a/plugin/dwm1001/include/uwb-plugin-dwm1001-private.h b/plugin/dwm1001/include/uwb-plugin-dwm1001-private.h deleted file mode 100755 index 1174a48..0000000 --- a/plugin/dwm1001/include/uwb-plugin-dwm1001-private.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * UWB Plug-in Logger - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares UWB dwm1001 plugin logger functions and structures. - * - * @file uwb-plugin-dwm1001-private.h - * @author Jiung Yu (jiung.yu@samsung.com) - */ - -#ifndef __UWB_PLUGIN_DWM1001_PRIVATE_H_ -#define __UWB_PLUGIN_DWM1001_PRIVATE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <dlog.h> -#include <glib.h> -#include <unistd.h> - -#undef LOG_TAG -#define LOG_TAG "UWB_PLUGIN_DWM1001" - -#define UWB_PLUGIN_LOGV(format, args...) LOGV(format, ##args) -#define UWB_PLUGIN_LOGD(format, args...) LOGD(format, ##args) -#define UWB_PLUGIN_LOGI(format, args...) LOGI(format, ##args) -#define UWB_PLUGIN_LOGW(format, args...) LOGW(format, ##args) -#define UWB_PLUGIN_LOGE(format, args...) LOGE(format, ##args) -#define UWB_PLUGIN_LOGF(format, args...) LOGF(format, ##args) - -#define __UWB_PLUGIN_LOG_FUNC_ENTER__ LOGD("Enter") -#define __UWB_PLUGIN_LOG_FUNC_EXIT__ LOGD("Quit") - -#define UWB_PLUGIN_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) -#define UWB_PLUGIN_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) - -#define ret_if(expr) do { \ - if (expr) { \ - UWB_PLUGIN_LOGE("(%s)", #expr); \ - return; \ - } \ - } while (0) - -#define retv_if(expr, val) do { \ - if (expr) { \ - UWB_PLUGIN_LOGE("(%s)", #expr); \ - return (val); \ - } \ - } while (0) - -typedef enum { - UWB_DWM1001_DATA_TYPE_INVALID = 0, - UWB_DWM1001_DATA_TYPE_SEND_MESSAGE, - UWB_DWM1001_DATA_TYPE_SET_POSITION, - UWB_DWM1001_DATA_TYPE_GET_NODE, - UWB_DWM1001_DATA_TYPE_MAX, -} uwb_dwm1001_data_type_e; - -typedef enum { - UWB_DWM1001_DIRECTION_TYPE_INVALID = 0, - UWB_DWM1001_DIRECTION_TYPE_REQUEST, - UWB_DWM1001_DIRECTION_TYPE_RESPONSE, - UWB_DWM1001_DIRECTION_TYPE_MAX, -} uwb_dwm1001_direction_type_e; - -#ifdef __cplusplus -} -#endif - -#endif /* __UWB_PLUGIN_DWM1001_PRIVATE_H_ */ diff --git a/plugin/dwm1001/include/uwb-plugin-dwm1001.h b/plugin/dwm1001/include/uwb-plugin-dwm1001.h deleted file mode 100755 index 95226b6..0000000 --- a/plugin/dwm1001/include/uwb-plugin-dwm1001.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * UWB Range Plug-in - * - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares UWB DWM1001 board plugin functions and structures. - * - * @file uwb-plugin-dwm1001.h - * @author Jiung Yu (jiung.yu@samsung.com) - */ - -#ifndef __UWB_PLUGIN_DWM1001_H__ -#define __UWB_PLUGIN_DWM1001_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <dwm_api.h> -#include <glib.h> -#include <stdlib.h> - -typedef struct { - uint64_t node_id; - uint16_t pan_id; - bool is_remote; - uint64_t distance; - int x; - int y; - int z; -} uwb_node_s; - -typedef struct { - uint16_t pan_id; - GSList *remote_node_list; - int remote_node_count; -} uwb_network_s; - -typedef struct { - void (*message_received_cb) (uint16_t node_id, unsigned char *message, int message_length); - void (*position_changed_cb) (uint16_t node_id, int x, int y, int z); -} uwb_hpi_event_cbs_s; - -typedef struct { - int (*init) (uwb_hpi_event_cbs_s *event_cbs); - int (*deinit) (void); - int (*test) (void); - int (*reset) (void); - int (*factory_reset) (void); - int (*enable_network) (void); - int (*disable_network) (void); - int (*get_network_info) (uwb_network_s **network_info); - int (*set_configurations) (uint16_t node_id, const GVariant *configurations); - int (*get_configurations) (uint16_t node_id, GVariant **configurations); - int (*set_position) (uint64_t node_id, int x, int y, int z); - int (*get_own_node) (uwb_node_s **own_node); - int (*send_message) (unsigned char *message, int message_length); - int (*send_message_to) (uint16_t node_id, unsigned char *message, int message_length); -} uwb_hpi_ops_s; - -int uwb_plugin_load(uwb_hpi_ops_s *ops); - -#ifdef __cplusplus -} -#endif - -#endif /* __UWB_PLUGIN_DWM1001_H__ */ diff --git a/plugin/dwm1001/include/uwb-plugin-log.h b/plugin/dwm1001/include/uwb-plugin-log.h deleted file mode 100755 index 9cb0c70..0000000 --- a/plugin/dwm1001/include/uwb-plugin-log.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * UWB Plug-in Logger - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares UWB dwm1001 plugin logger functions and structures. - * - * @file uwb-plugin-log.h - * @author Jiung Yu (jiung.yu@samsung.com) - */ - -#ifndef __UWB_PLUGIN_LOG_H_ -#define __UWB_PLUGIN_LOG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - - -#include <dlog.h> - -#undef LOG_TAG -#define LOG_TAG "UWB_PLUGIN" - -#define UWB_PLUGIN_LOGV(format, args...) LOGV(format, ##args) -#define UWB_PLUGIN_LOGD(format, args...) LOGD(format, ##args) -#define UWB_PLUGIN_LOGI(format, args...) LOGI(format, ##args) -#define UWB_PLUGIN_LOGW(format, args...) LOGW(format, ##args) -#define UWB_PLUGIN_LOGE(format, args...) LOGE(format, ##args) -#define UWB_PLUGIN_LOGF(format, args...) LOGF(format, ##args) - -#define __UWB_PLUGIN_LOG_FUNC_ENTER__ UWB_PLUGIN_LOGI("Enter") -#define __UWB_PLUGIN_LOG_FUNC_EXIT__ UWB_PLUGIN_LOGI("Quit") - -#define UWB_PLUGIN_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) -#define UWB_PLUGIN_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) - -#ifdef __cplusplus -} -#endif - -#endif /* __UWB_PLUGIN_LOG_H_ */ diff --git a/plugin/dwm1001/uwb-plugin-dwm1001.c b/plugin/dwm1001/uwb-plugin-dwm1001.c deleted file mode 100755 index f7ae2d0..0000000 --- a/plugin/dwm1001/uwb-plugin-dwm1001.c +++ /dev/null @@ -1,610 +0,0 @@ -/* - * UWB Plug-in for ranging - * - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file implements UWB ranging plugin functions. - * - * @file uwb-plugin-dwm1001.c - * @author Jiung Yu (jiung.yu@samsung.com) - */ -#include <inttypes.h> - -#include "uwb-plugin-dwm1001.h" -#include "uwb-plugin-dwm1001-private.h" - -#define DBUS_DEBUG_VARIANT(var) \ - do {\ - gchar *var_debug_str = NULL;\ - if (var)\ - var_debug_str = g_variant_print((var), TRUE);\ - UWB_PLUGIN_LOGI("value [%s]", var_debug_str ? var_debug_str : "NULL");\ - g_free(var_debug_str);\ - } while (0) - -#define DEFAULT_PANID 0x44a2 -#define DEFAULT_MODE DWM_MODE_ANCHOR -#define DEFAULT_NETWORK_TIMEOUT 1500 -#define DEFAULT_HARDWARE_WAIT_TIME 2000 - -static struct _dwm1001_ctx { - bool is_enable; - uint16_t pan_id; - uint64_t node_id; - dwm_cfg_anchor_t cfg_anchor; - dwm_cfg_tag_t cfg_tag; - uint16_t update_rate; - uint16_t stationary_update_rate; - int network_timeout; - int hardware_wait_time; - dwm_mode_t mode; - uwb_hpi_event_cbs_s *event_cbs; -} dwm1001_ctx; - -static void __destroy_node(gpointer data) -{ - if (data != NULL) { - uwb_node_s *node = (uwb_node_s *)data; - free(node); - } -} - -static void __clean_dwm1001_ctx() -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - dwm1001_ctx.event_cbs = NULL; - dwm1001_ctx.is_enable = false; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; -} - -static void __set_config_anchor() -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - dwm_cfg_anchor_set(&(dwm1001_ctx.cfg_anchor)); - dwm1001_ctx.mode = DWM_MODE_ANCHOR; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; -} - -static void __set_config_tag() -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - dwm_cfg_tag_set(&(dwm1001_ctx.cfg_tag)); - dwm1001_ctx.mode = DWM_MODE_TAG; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; -} - -static void __set_default_dwm1001_ctx() -{ - dwm1001_ctx.pan_id = DEFAULT_PANID; - dwm1001_ctx.cfg_anchor.bridge = false; - dwm1001_ctx.cfg_anchor.initiator = true; - dwm1001_ctx.cfg_anchor.uwb_bh_routing = true; - dwm1001_ctx.cfg_anchor.common.enc_en = false; - dwm1001_ctx.cfg_anchor.common.led_en = true; - dwm1001_ctx.cfg_anchor.common.ble_en = true; - dwm1001_ctx.cfg_anchor.common.uwb_mode = DWM_UWB_MODE_ACTIVE; - dwm1001_ctx.cfg_anchor.common.fw_update_en = false; - - dwm1001_ctx.cfg_tag.stnry_en = true; - dwm1001_ctx.cfg_tag.low_power_en = false; - dwm1001_ctx.cfg_tag.meas_mode = DWM_MEAS_MODE_TWR; - dwm1001_ctx.cfg_tag.loc_engine_en = true; - dwm1001_ctx.cfg_tag.common.enc_en = false; - dwm1001_ctx.cfg_tag.common.led_en = true; - dwm1001_ctx.cfg_tag.common.ble_en = true; - dwm1001_ctx.cfg_tag.common.uwb_mode = DWM_UWB_MODE_ACTIVE; - dwm1001_ctx.cfg_tag.common.fw_update_en = false; - dwm1001_ctx.mode = DWM_MODE_ANCHOR; - dwm1001_ctx.update_rate = 1; - dwm1001_ctx.stationary_update_rate = 1; - dwm1001_ctx.network_timeout = DEFAULT_NETWORK_TIMEOUT; - dwm1001_ctx.hardware_wait_time = DEFAULT_HARDWARE_WAIT_TIME; - -} - -static int uwb_dwm1001_init(uwb_hpi_event_cbs_s *event_cbs) -{ - int ret = 0; - - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - dwm1001_ctx.is_enable = false; - __set_default_dwm1001_ctx(); - dwm1001_ctx.event_cbs = event_cbs; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return ret; -} - -static int uwb_dwm1001_deinit(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - dwm_deinit(); - __clean_dwm1001_ctx(); - dwm1001_ctx.is_enable = false; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -static int uwb_dwm1001_test(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -static int uwb_dwm1001_reset(void) -{ - int ret = 0; - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(!dwm1001_ctx.is_enable, -1); - - dwm_reset(); - - usleep(dwm1001_ctx.hardware_wait_time * 1000); - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return ret; -} - - -int uwb_dwm1001_factory_reset(void) -{ - int ret = 0; - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(!dwm1001_ctx.is_enable, -1); - - ret = dwm_factory_reset(); - if (ret != RV_OK) { - UWB_PLUGIN_LOGE("dwm factory reset FAIL : %d", ret); - ret = -1; - } - - usleep(dwm1001_ctx.hardware_wait_time * 1000); - - (DEFAULT_MODE == DWM_MODE_ANCHOR) ? - __set_config_anchor() : __set_config_tag(); - - dwm_upd_rate_set(dwm1001_ctx.update_rate, dwm1001_ctx.stationary_update_rate); - dwm_panid_set(dwm1001_ctx.pan_id); - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return ret; -} - -int uwb_dwm1001_enable_network(void) -{ - int ret = 0; - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(dwm1001_ctx.is_enable, -1); - - dwm_init(); - - (dwm1001_ctx.mode == DWM_MODE_ANCHOR) ? - __set_config_anchor() : __set_config_tag(); - dwm_upd_rate_set(dwm1001_ctx.update_rate, dwm1001_ctx.stationary_update_rate); - dwm_panid_set((uint16_t)dwm1001_ctx.pan_id); - - ret = dwm_node_id_get(&dwm1001_ctx.node_id); - if (ret != RV_OK) { - UWB_PLUGIN_LOGE("dwm_node_id_get FAIL : %d", ret); - dwm_reset(); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return -1; - } - - ret = dwm_panid_get(&dwm1001_ctx.pan_id); - if (ret != RV_OK) { - UWB_PLUGIN_LOGE("dwm_panid_get FAIL : %d", ret); - dwm_reset(); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return -1; - } - - UWB_PLUGIN_LOGI("MODE : %d, pan_id : %" PRIu16 " node_id : %" PRIu64, - dwm1001_ctx.mode, dwm1001_ctx.pan_id, dwm1001_ctx.node_id); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - dwm1001_ctx.is_enable = true; - - return 0; -} - -int uwb_dwm1001_disable_network(void) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(!dwm1001_ctx.is_enable, -1); - - dwm_deinit(); - __clean_dwm1001_ctx(); - dwm1001_ctx.is_enable = false; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -int uwb_dwm1001_get_own_node(uwb_node_s **own_node) -{ - int ret = 0; - dwm_pos_t pos; - - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(own_node == NULL, -1); - retv_if(!dwm1001_ctx.is_enable, -1); - - ret = dwm_pos_get(&pos); - if (ret != RV_OK) { - UWB_PLUGIN_LOGE("dwm_pos_get FAIL : %d", ret); - dwm_reset(); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return -1; - } - - *own_node = (uwb_node_s *)malloc(sizeof(uwb_node_s)); - if (*own_node == NULL) { - UWB_PLUGIN_LOGE("own_node is NULL"); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return -1; - } - - (*own_node)->distance = 0; - (*own_node)->is_remote = false; - (*own_node)->node_id = dwm1001_ctx.node_id; - (*own_node)->pan_id = dwm1001_ctx.pan_id; - - if (dwm1001_ctx.mode == DWM_MODE_ANCHOR) { - (*own_node)->x = pos.x; - (*own_node)->y = pos.y; - (*own_node)->z = pos.z; - } else { - (*own_node)->x = 0; - (*own_node)->y = 0; - (*own_node)->z = 0; - } - - UWB_PLUGIN_LOGI("obtained node_id : %" PRIu64, dwm1001_ctx.node_id); - UWB_PLUGIN_LOGI("X: %d Y: %d Z: %d", pos.x, pos.y, pos.z); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - - return ret; -} - -static GSList *__get_anchor_list_anchor() -{ - dwm_anchor_list_t list; - GSList *node_list = NULL; - int ret; - - /* Get anchor nodes */ - ret = dwm_anchor_list_get(&list); - if (ret != RV_OK) { - UWB_PLUGIN_LOGE("dwm_anchor_list_get FAIL : %d", ret); - dwm_reset(); - return NULL; - } - - /* Insert Nodes to node list */ - for (int i = 0; i < list.cnt; ++i) { - uwb_node_s *node; - - /* Calculator distance between anchor node */ - node = (uwb_node_s *)malloc(sizeof(uwb_node_s)); - if (node == NULL) { - UWB_PLUGIN_LOGE("Alloc failed"); - continue; - } - node->is_remote = true; - node->node_id = list.v[i].node_id; - node->pan_id = dwm1001_ctx.pan_id; - node->x = list.v[i].x; - node->y = list.v[i].y; - node->z = list.v[i].z; - node_list = g_slist_append(node_list, node); - } - - return node_list; -} - -static GSList *__get_anchor_list_tag() -{ - dwm_loc_data_t loc; - dwm_pos_t pos; - GSList *node_list = NULL; - int ret; - - loc.p_pos = &pos; - ret = dwm_loc_get(&loc); - if (ret != RV_OK) { - UWB_PLUGIN_LOGE("dwm_loc_get FAIL : %d", ret); - dwm_reset(); - return NULL; - } - - for (int i = 0; i < loc.anchors.dist.cnt; ++i) { - uwb_node_s *node; - node = (uwb_node_s *)malloc(sizeof(uwb_node_s)); - if (node == NULL) { - UWB_PLUGIN_LOGE("Alloc failed"); - continue; - } - - node->distance = loc.anchors.dist.dist[i]; - node->is_remote = true; - node->node_id = loc.anchors.dist.addr[i]; - node->pan_id = dwm1001_ctx.pan_id; - node->x = loc.anchors.an_pos.pos[i].x; - node->y = loc.anchors.an_pos.pos[i].y; - node->z = loc.anchors.an_pos.pos[i].z; - node_list = g_slist_append(node_list, node); - } - - return node_list; -} - -int uwb_dwm1001_get_network_info(uwb_network_s **network_info) -{ - GSList *node_list = NULL; - - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(network_info == NULL, -1); - retv_if(!dwm1001_ctx.is_enable, -1); - - /* Get Anchor list */ - (dwm1001_ctx.mode == DWM_MODE_ANCHOR) ? - (node_list = __get_anchor_list_anchor()) : - (node_list = __get_anchor_list_tag()); - - *network_info = (uwb_network_s *)malloc(sizeof(uwb_network_s)); - if (*network_info == NULL) { - UWB_PLUGIN_LOGE("network info is NULL"); - g_slist_free_full(node_list, __destroy_node); - return -1; - } - - (*network_info)->pan_id = dwm1001_ctx.pan_id; - (*network_info)->remote_node_list = node_list; - (*network_info)->remote_node_count = g_slist_length(node_list); - - if ((*network_info)->remote_node_count == 0) { - UWB_PLUGIN_LOGE("No anchor in network"); - } - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -static void __set_dwm1001_ctx(GVariantIter *iter) -{ - const gchar *key = NULL; - GVariant *value = NULL; - - if (!iter) - return; - - while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { - UWB_PLUGIN_LOGI("key : %s", key); - DBUS_DEBUG_VARIANT(value); - if (g_strcmp0(key, "MODE") == 0) { - const char *mode = NULL; - mode = g_variant_get_string(value, NULL); - if (strncmp(mode, "ANCHOR", strlen(mode)) == 0) - dwm1001_ctx.mode = DWM_MODE_ANCHOR; - else if (strncmp(mode, "TAG", strlen(mode)) == 0) - dwm1001_ctx.mode = DWM_MODE_TAG; - - } else if (g_strcmp0(key, "ANCHOR_BRIDGE") == 0) - dwm1001_ctx.cfg_anchor.bridge = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "ANCHOR_INITIATOR") == 0) - dwm1001_ctx.cfg_anchor.initiator = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "ANCHOR_UWB_BH_ROUTING") == 0) - dwm1001_ctx.cfg_anchor.uwb_bh_routing = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "ANCHOR_ENC_EN") == 0) - dwm1001_ctx.cfg_anchor.common.enc_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "ANCHOR_LED_EN") == 0) - dwm1001_ctx.cfg_anchor.common.led_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "ANCHOR_BLE_EN") == 0) - dwm1001_ctx.cfg_anchor.common.ble_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "ANCHOR_UWB_MODE") == 0) - dwm1001_ctx.cfg_anchor.common.uwb_mode = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "ANCHOR_FW_UPDATE_EN") == 0) - dwm1001_ctx.cfg_anchor.common.fw_update_en = (bool)g_variant_get_boolean(value); - - else if (g_strcmp0(key, "TAG_STNRY_EN") == 0) - dwm1001_ctx.cfg_tag.stnry_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "TAG_LOW_POWER_EN") == 0) - dwm1001_ctx.cfg_tag.low_power_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "TAG_MEAS_MODE") == 0) - dwm1001_ctx.cfg_tag.meas_mode = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "TAG_LOC_ENGINE_EN") == 0) - dwm1001_ctx.cfg_tag.loc_engine_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "TAG_ENC_EN") == 0) - dwm1001_ctx.cfg_tag.common.enc_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "TAG_LED_EN") == 0) - dwm1001_ctx.cfg_tag.common.led_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "TAG_BLE_EN") == 0) - dwm1001_ctx.cfg_tag.common.ble_en = (bool)g_variant_get_boolean(value); - else if (g_strcmp0(key, "TAG_UWB_MODE") == 0) - dwm1001_ctx.cfg_tag.common.uwb_mode = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "TAG_FW_UPDATE_EN") == 0) - dwm1001_ctx.cfg_tag.common.fw_update_en = (bool)g_variant_get_boolean(value); - - else if (g_strcmp0(key, "UPDATE_RATE") == 0) - dwm1001_ctx.update_rate = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "NETWORK_TIMEOUT") == 0) - dwm1001_ctx.network_timeout = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "HARDWARE_WAIT_TIME") == 0) - dwm1001_ctx.hardware_wait_time = (int)g_variant_get_int64(value); - else if (g_strcmp0(key, "PANID") == 0) - dwm1001_ctx.pan_id = (uint16_t)g_variant_get_int64(value); - } - UWB_PLUGIN_LOGE("pan_id : %d", (int)dwm1001_ctx.pan_id); - UWB_PLUGIN_LOGE("hardware_wait_time : %d", dwm1001_ctx.hardware_wait_time); - UWB_PLUGIN_LOGE("network_timeout : %d", dwm1001_ctx.network_timeout); -} - -int uwb_dwm1001_set_configurations(uint16_t node_id, const GVariant *configurations) -{ - GVariantIter *iter = NULL; - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(dwm1001_ctx.is_enable, -1); - - g_variant_get((GVariant *)configurations, "a{sv}", &iter); - - __set_dwm1001_ctx(iter); - - g_variant_iter_free(iter); - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} - -static void __build_configuration(GVariantBuilder *builder) -{ - if (!builder) - return; - - if (dwm1001_ctx.mode == DWM_MODE_ANCHOR) - g_variant_builder_add(builder, "{sv}", "MODE", g_variant_new("s", "ANCHOR")); - else - g_variant_builder_add(builder, "{sv}", "MODE", g_variant_new("s", "TAG")); - UWB_PLUGIN_LOGE("network_timeout : %d", dwm1001_ctx.network_timeout); - g_variant_builder_add(builder, "{sv}", "NETWORK_TIMEOUT", g_variant_new("x", (int64_t)dwm1001_ctx.network_timeout)); - g_variant_builder_add(builder, "{sv}", "HARDWARE_WAIT_TIME", g_variant_new("x", (int64_t)dwm1001_ctx.hardware_wait_time)); - g_variant_builder_add(builder, "{sv}", "PANID", g_variant_new("x", (int64_t)dwm1001_ctx.pan_id)); - - g_variant_builder_add(builder, "{sv}", "ANCHOR_BRIDGE", g_variant_new("b", dwm1001_ctx.cfg_anchor.bridge)); - g_variant_builder_add(builder, "{sv}", "ANCHOR_INITIATOR", g_variant_new("b", dwm1001_ctx.cfg_anchor.initiator)); - g_variant_builder_add(builder, "{sv}", "ANCHOR_UWB_BH_ROUTING", g_variant_new("x", (int64_t)dwm1001_ctx.cfg_anchor.uwb_bh_routing)); - g_variant_builder_add(builder, "{sv}", "ANCHOR_ENC_EN", g_variant_new("b", dwm1001_ctx.cfg_anchor.common.enc_en)); - g_variant_builder_add(builder, "{sv}", "ANCHOR_LED_EN", g_variant_new("b", dwm1001_ctx.cfg_anchor.common.led_en)); - g_variant_builder_add(builder, "{sv}", "ANCHOR_BLE_EN", g_variant_new("b", dwm1001_ctx.cfg_anchor.common.ble_en)); - g_variant_builder_add(builder, "{sv}", "ANCHOR_UWB_MODE", g_variant_new("x", (int64_t)dwm1001_ctx.cfg_anchor.common.uwb_mode)); - g_variant_builder_add(builder, "{sv}", "ANCHOR_FW_UPDATE_EN", g_variant_new("b", dwm1001_ctx.cfg_anchor.common.fw_update_en)); - - g_variant_builder_add(builder, "{sv}", "TAG_STNRY_EN", g_variant_new("b", dwm1001_ctx.cfg_tag.stnry_en)); - g_variant_builder_add(builder, "{sv}", "TAG_LOW_POWER_EN", g_variant_new("b", dwm1001_ctx.cfg_tag.low_power_en)); - g_variant_builder_add(builder, "{sv}", "TAG_MEAS_MODE", g_variant_new("x", (int64_t)dwm1001_ctx.cfg_tag.meas_mode)); - g_variant_builder_add(builder, "{sv}", "TAG_LOC_ENGINE_EN", g_variant_new("b", dwm1001_ctx.cfg_tag.loc_engine_en)); - g_variant_builder_add(builder, "{sv}", "TAG_ENC_EN", g_variant_new("b", dwm1001_ctx.cfg_tag.common.enc_en)); - g_variant_builder_add(builder, "{sv}", "TAG_LED_EN", g_variant_new("b", dwm1001_ctx.cfg_tag.common.led_en)); - g_variant_builder_add(builder, "{sv}", "TAG_BLE_EN", g_variant_new("b", dwm1001_ctx.cfg_tag.common.ble_en)); - g_variant_builder_add(builder, "{sv}", "TAG_UWB_MODE", g_variant_new("x", (int64_t)dwm1001_ctx.cfg_tag.common.uwb_mode)); - g_variant_builder_add(builder, "{sv}", "TAG_FW_UPDATE_EN", g_variant_new("b", dwm1001_ctx.cfg_tag.common.fw_update_en)); - -} - -int uwb_dwm1001_get_configurations(uint16_t node_id, GVariant **configurations) -{ - GVariantBuilder *builder; - int ret = 0; - - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - __build_configuration(builder); - *configurations = g_variant_new("a{sv}", builder); - - g_variant_builder_unref(builder); - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return ret; -} - -int uwb_dwm1001_set_position(uint64_t node_id, int x, int y, int z) -{ - int ret = 0; - dwm_pos_t position; - - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - retv_if(node_id == 0, -1); - retv_if(!dwm1001_ctx.is_enable, -1); - - if (node_id != dwm1001_ctx.node_id) { - UWB_PLUGIN_LOGE("Invalid node ID"); - return -1; - - } - - if (dwm1001_ctx.mode == DWM_MODE_TAG) { - UWB_PLUGIN_LOGE("Tag mode is not support set position"); - return -1; - } - - position.qf = 100; - position.x = x; - position.y = y; - position.z = z; - - UWB_PLUGIN_LOGI("Position set to (%d, %d, %d)", - position.x, position.y, position.z); - ret = dwm_pos_set(&position); - if (ret != RV_OK) { - UWB_PLUGIN_LOGE("dwm_pos_set FAIL : %d", ret); - dwm_reset(); - return -1; - } - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return ret; -} - -int uwb_plugin_load(uwb_hpi_ops_s *ops) -{ - __UWB_PLUGIN_LOG_FUNC_ENTER__; - - if (!ops) { - UWB_PLUGIN_LOGE("Invalid parameter"); - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return -1; - } - - ops->init = uwb_dwm1001_init; - ops->deinit = uwb_dwm1001_deinit; - ops->test = uwb_dwm1001_test; - ops->reset = uwb_dwm1001_reset; - ops->factory_reset = uwb_dwm1001_factory_reset; - ops->enable_network = uwb_dwm1001_enable_network; - ops->disable_network = uwb_dwm1001_disable_network; - ops->get_own_node = uwb_dwm1001_get_own_node; - ops->get_network_info = uwb_dwm1001_get_network_info; - ops->set_configurations = uwb_dwm1001_set_configurations; - ops->get_configurations = uwb_dwm1001_get_configurations; - ops->set_position = uwb_dwm1001_set_position; - ops->send_message = NULL; - ops->send_message_to = NULL; - dwm1001_ctx.is_enable = false; - - __UWB_PLUGIN_LOG_FUNC_EXIT__; - return 0; -} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3010a6..377bb7a 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,12 +32,10 @@ LINK_DIRECTORIES(${TARGET_UWB_MANAGER_REQ_PKGS_LIBRARY_DIRS}) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/hpi ${CMAKE_SOURCE_DIR}/interface ) FILE(GLOB SRCS *.cpp) -SET(SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/hpi/uwb-hpi.c) SET(SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/interface/generated-code.c) SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/interface/generated-code.c PROPERTIES GENERATED TRUE) diff --git a/src/UwbConfig.cpp b/src/UwbConfig.cpp index ecb03bd..b1afb6d 100755 --- a/src/UwbConfig.cpp +++ b/src/UwbConfig.cpp @@ -38,13 +38,13 @@ UwbConfig::~UwbConfig() UwbConfig::UwbConfig(const UwbConfig& config) { - this->_range_plugin = config._range_plugin; + this->_uwb_hal = config._uwb_hal; this->_configurations = g_variant_ref(config._configurations); } UwbConfig& UwbConfig::operator=(const UwbConfig& config) { - this->_range_plugin = config._range_plugin; + this->_uwb_hal = config._uwb_hal; this->_configurations = g_variant_ref(config._configurations); return *this; @@ -88,8 +88,8 @@ int UwbConfig::loadConfiguration(void) g_variant_unref(this->_configurations); this->_configurations = configuration; - if (this->_range_plugin) - this->_range_plugin->setConfigurations(0, configuration); + if (this->_uwb_hal) + this->_uwb_hal->setConfigurations(0, configuration); g_object_unref(parser); __UWB_LOG_FUNC_EXIT__; @@ -106,14 +106,14 @@ int UwbConfig::setConfigurations(GVariant *configurations) return -1; } - if (this->_range_plugin == nullptr) { + if (this->_uwb_hal == nullptr) { UWB_LOGI("Range plugin is not loaded"); UWB_LOGI("Configuration is not set"); __UWB_LOG_FUNC_EXIT__; return 0; } - this->_range_plugin->setConfigurations(0, configurations); + this->_uwb_hal->setConfigurations(0, configurations); this->getConfigurationFromPlugin(); __UWB_LOG_FUNC_EXIT__; @@ -135,13 +135,13 @@ void UwbConfig::getConfigurationFromPlugin(void) { __UWB_LOG_FUNC_ENTER__; - if (this->_range_plugin == nullptr) { + if (this->_uwb_hal == nullptr) { __UWB_LOG_FUNC_EXIT__; return; } GVariant *configuration = NULL; - if (this->_range_plugin->getConfigurations(0, &configuration) != 0) { + if (this->_uwb_hal->getConfigurations(0, &configuration) != 0) { __UWB_LOG_FUNC_EXIT__; return; } diff --git a/src/UwbHal.cpp b/src/UwbHal.cpp new file mode 100755 index 0000000..d8a6062 --- /dev/null +++ b/src/UwbHal.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <uwb-log-def.h> + +#include <UwbHal.h> + +using namespace UwbManagerNamespace; + +void UwbHal::messageReceivedCb(uint16_t node_id, unsigned char *message, int message_length) +{ + UWB_LOGI("Call signal emit method in dbus class"); // LCOV_EXCL_LINE + //UwbDbusManager::emitMessageReceivedSignal(node_id, message, message_length); +} + +void UwbHal::positionChangedCb(uint16_t node_id, int x, int y, int z) +{ + UWB_LOGI("Call signal emit method in dbus class"); // LCOV_EXCL_LINE + //UwbDbusManager::emitPositionChangedSignal(node_id, x, y, z); +} + +int UwbHal::init() +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_get_backend(); +} + +int UwbHal::deinit(void) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_put_backend(); +} + +int UwbHal::start(void) +{ + __UWB_LOG_FUNC_ENTER__; + + event_cbs.message_received_cb = messageReceivedCb; + event_cbs.position_changed_cb = positionChangedCb; + + return hal_uwb_start((uwb_hal_event_cbs_s *)&event_cbs); +} + +int UwbHal::stop(void) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_stop(); +} + +int UwbHal::test(void) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_test(); +} + +int UwbHal::reset(void) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_reset(); +} + +int UwbHal::factoryReset(void) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_factory_reset(); +} + +int UwbHal::enableNetwork(void) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_enable_network(); +} + +int UwbHal::disableNetwork(void) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_disable_network(); +} + +int UwbHal::getOwnNode(uwb_node_s **own_node) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_get_own_node((uwb_hal_node_s **)own_node); +} + +int UwbHal::getNetworkInfo(uwb_network_s **network_info) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_get_network_info((uwb_hal_network_s **)network_info); +} + +int UwbHal::setConfigurations(uint16_t node_id, const GVariant *configurations) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_set_configurations(node_id, configurations); +} + +int UwbHal::getConfigurations(uint16_t node_id, GVariant **configurations) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_get_configurations(node_id, configurations); +} + +int UwbHal::setPosition(uint64_t node_id, int x, int y, int z) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_set_position(node_id, x, y, z); +} + +int UwbHal::sendMessage(const unsigned char *message, int message_length) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_send_message(message, message_length); +} + +int UwbHal::sendMessageTo(uint16_t node_id, const unsigned char *message, int message_length) +{ + __UWB_LOG_FUNC_ENTER__; + + return hal_uwb_send_message_to(node_id, message, message_length); +} + diff --git a/src/UwbNetwork.cpp b/src/UwbNetwork.cpp index 53379e1..954cdc9 100644..100755 --- a/src/UwbNetwork.cpp +++ b/src/UwbNetwork.cpp @@ -23,7 +23,7 @@ using namespace UwbManagerNamespace; static void __destroy_node(gpointer data) { if (data != NULL) { - uwb_hpi_node_s *node = (uwb_hpi_node_s *)data; + uwb_node_s *node = (uwb_node_s *)data; free(node); } } @@ -34,12 +34,12 @@ int UwbNetwork::enable(void) this->_is_enable = true; - if (this->_range_plugin == nullptr) { + if (this->_uwb_hal == nullptr) { __UWB_LOG_FUNC_EXIT__; return 0; } - int ret = this->_range_plugin->enableNetwork(); + int ret = this->_uwb_hal->enableNetwork(); if (ret != 0) { __UWB_LOG_FUNC_EXIT__; @@ -47,8 +47,8 @@ int UwbNetwork::enable(void) return -1; } - uwb_hpi_network_s *network_info = nullptr; - int res = this->_range_plugin->getNetworkInfo(&network_info); + uwb_network_s *network_info = nullptr; + int res = this->_uwb_hal->getNetworkInfo(&network_info); if (res != 0 || !network_info) { __UWB_LOG_FUNC_EXIT__; return -1; @@ -70,12 +70,12 @@ int UwbNetwork::disable(void) this->_is_enable = false; - if (this->_range_plugin == nullptr) { + if (this->_uwb_hal == nullptr) { __UWB_LOG_FUNC_EXIT__; return -1; } - this->_range_plugin->disableNetwork(); + this->_uwb_hal->disableNetwork(); __UWB_LOG_FUNC_EXIT__; return 0; diff --git a/src/UwbPluginManager.cpp b/src/UwbPluginManager.cpp deleted file mode 100644 index 4fe836c..0000000 --- a/src/UwbPluginManager.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <uwb-log-def.h> - -#include <UwbPluginManager.h> - -using namespace UwbManagerNamespace; - -UwbPluginManager::~UwbPluginManager() -{ - __UWB_LOG_FUNC_ENTER__; - - this->_plugins.clear(); - - __UWB_LOG_FUNC_EXIT__; -} - -int UwbPluginManager::load(std::shared_ptr<UwbPlugin> plugin) -{ - __UWB_LOG_FUNC_ENTER__; - - if (plugin == nullptr){ - __UWB_LOG_FUNC_EXIT__; - return -1; - } - - void *dl_handle = nullptr; - dl_handle = dlopen(plugin->getPluginPath().c_str(), RTLD_LAZY); - if (dl_handle == nullptr) { - UWB_LOGE("dlopen failed, [%d] : %s", errno, dlerror()); // LCOV_EXCL_LINE - __UWB_LOG_FUNC_EXIT__; - return -1; - } - - void *symbol_table = nullptr; - symbol_table = dlsym(dl_handle, this->_func_tbl_symbol.c_str()); - if (symbol_table == nullptr) { - UWB_LOGE("dlsym failed, [%d] : %s", errno, dlerror()); // LCOV_EXCL_LINE - dlclose(dl_handle); - __UWB_LOG_FUNC_EXIT__; - return -1; - } - - plugin->init(symbol_table); - this->_plugins[plugin] = dl_handle; - - __UWB_LOG_FUNC_EXIT__; - return 0; -} - -int UwbPluginManager::unload(std::shared_ptr<UwbPlugin> plugin) -{ - __UWB_LOG_FUNC_ENTER__; - - if (plugin == nullptr){ - __UWB_LOG_FUNC_EXIT__; - return -1; - } - - plugin->deinit(); - - auto itr = this->_plugins.find(plugin); - if (itr == this->_plugins.end()) { - __UWB_LOG_FUNC_EXIT__; - return -1; - } - - void *dl_handle = itr->second; - if (dl_handle) - dlclose(dl_handle); - - this->_plugins.erase(plugin); - - __UWB_LOG_FUNC_EXIT__; - return 0; -} diff --git a/src/UwbPosition.cpp b/src/UwbPosition.cpp index e2b97b6..8656ac0 100644..100755 --- a/src/UwbPosition.cpp +++ b/src/UwbPosition.cpp @@ -25,11 +25,11 @@ using namespace UwbManagerNamespace; int UwbPosition::updateUwbOwnNode() { - if (this->_range_plugin == nullptr) + if (this->_uwb_hal == nullptr) return 0; - uwb_hpi_node_s *own_node; - int res = this->_range_plugin->getOwnNode(&own_node); + uwb_node_s *own_node; + int res = this->_uwb_hal->getOwnNode(&own_node); if (res != 0 || !own_node) return -1; @@ -41,7 +41,7 @@ int UwbPosition::updateUwbOwnNode() static void __foreach_node(gpointer data, gpointer user_data) { - uwb_hpi_node_s *node = (uwb_hpi_node_s *)data; + uwb_node_s *node = (uwb_node_s *)data; UwbPosition *position = (UwbPosition *)user_data; if (!node || !position) @@ -56,18 +56,18 @@ static void __foreach_node(gpointer data, gpointer user_data) static void __destroy_node(gpointer data) { if (data != NULL) { - uwb_hpi_node_s *node = (uwb_hpi_node_s *)data; + uwb_node_s *node = (uwb_node_s *)data; free(node); } } int UwbPosition::updateUwbNodes(void) { - if (this->_range_plugin == nullptr) + if (this->_uwb_hal == nullptr) return 0; - uwb_hpi_network_s *network_info = nullptr; - int res = this->_range_plugin->getNetworkInfo(&network_info); + uwb_network_s *network_info = nullptr; + int res = this->_uwb_hal->getNetworkInfo(&network_info); if (res != 0 || !network_info) return -1; @@ -212,7 +212,7 @@ void UwbPosition::setPosition(int x, int y, int z) return; } - this->_range_plugin->setPosition(this->_own_node.getNodeId(), x, y, z); + this->_uwb_hal->setPosition(this->_own_node.getNodeId(), x, y, z); __UWB_LOG_FUNC_EXIT__; return; diff --git a/src/UwbRangePlugin.cpp b/src/UwbRangePlugin.cpp deleted file mode 100644 index 8553114..0000000 --- a/src/UwbRangePlugin.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <uwb-log-def.h> - -#include <UwbRangePlugin.h> -//#include <UwbDbusManager.h> - -using namespace UwbManagerNamespace; - -void UwbRangePlugin::messageReceivedCb(uint16_t node_id, unsigned char *message, int message_length) -{ - UWB_LOGI("Call signal emit method in dbus class"); // LCOV_EXCL_LINE - //UwbDbusManager::emitMessageReceivedSignal(node_id, message, message_length); -} - -void UwbRangePlugin::positionChangedCb(uint16_t node_id, int x, int y, int z) -{ - UWB_LOGI("Call signal emit method in dbus class"); // LCOV_EXCL_LINE - //UwbDbusManager::emitPositionChangedSignal(node_id, x, y, z); -} - -int UwbRangePlugin::init(void *uwb_plugin_load) -{ - int (*load_plugin)(uwb_hpi_ops_s *interfaces) = (int (*)(uwb_hpi_ops_s *))uwb_plugin_load; - - if (load_plugin == NULL) - return -1; - - if (load_plugin(&ops) < 0) { - UWB_LOGE("onload failed"); // LCOV_EXCL_LINE - return -1; - } - - event_cbs.message_received_cb = messageReceivedCb; - event_cbs.position_changed_cb = positionChangedCb; - - return uwb_hpi_init(&ops, &event_cbs); -} - -int UwbRangePlugin::deinit(void) -{ - return uwb_hpi_deinit(&ops); -} - -std::string UwbRangePlugin::getPluginPath(void) -{ - return this->_plugin_path; -} - -int UwbRangePlugin::test(void) -{ - return uwb_hpi_test(&ops); -} - -int UwbRangePlugin::reset(void) -{ - return uwb_hpi_reset(&ops); -} - -int UwbRangePlugin::factoryReset(void) -{ - return uwb_hpi_factory_reset(&ops); -} - -int UwbRangePlugin::enableNetwork(void) -{ - return uwb_hpi_enable_network(&ops); -} - -int UwbRangePlugin::disableNetwork(void) -{ - return uwb_hpi_disable_network(&ops); -} - -int UwbRangePlugin::getOwnNode(uwb_hpi_node_s **own_node) -{ - return uwb_hpi_get_own_node(&ops, own_node); -} - -int UwbRangePlugin::getNetworkInfo(uwb_hpi_network_s **network_info) -{ - return uwb_hpi_get_network_info(&ops, network_info); -} - -int UwbRangePlugin::setConfigurations(uint16_t node_id, const GVariant *configurations) -{ - return uwb_hpi_set_configurations(&ops, node_id, configurations); -} - -int UwbRangePlugin::getConfigurations(uint16_t node_id, GVariant **configurations) -{ - return uwb_hpi_get_configurations(&ops, node_id, configurations); -} - -int UwbRangePlugin::setPosition(uint64_t node_id, int x, int y, int z) -{ - return uwb_hpi_set_position(&ops, node_id, x, y, z); -} - -int UwbRangePlugin::sendMessage(const unsigned char *message, int message_length) -{ - return uwb_hpi_send_message(&ops, message, message_length); -} - -int UwbRangePlugin::sendMessageTo(uint16_t node_id, const unsigned char *message, int message_length) -{ - return uwb_hpi_send_message_to(&ops, node_id, message, message_length); -} - diff --git a/src/main.cpp b/src/main.cpp index 9bc80a4..6386e54 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,7 @@ #include <uwb-log-def.h> -#include <UwbRangePlugin.h> -#include <UwbPluginManager.h> +#include <UwbHal.h> #include <UwbConfig.h> #include <UwbNetwork.h> #include <UwbPosition.h> @@ -51,28 +50,28 @@ static void __set_signal_handler() sigaction(SIGTERM, &sa, NULL); } -static void __set_device_control_handler(UwbRangePlugin *range_plugin, +static void __set_device_control_handler(UwbHal *uwb_hal, UwbDbusIfaceAdapter &dbus_adapter) { - auto test_handler = std::bind(&UwbRangePlugin::test, - range_plugin); + auto test_handler = std::bind(&UwbHal::test, + uwb_hal); dbus_adapter.setTest(test_handler); - auto reset_handler = std::bind(&UwbRangePlugin::reset, - range_plugin); + auto reset_handler = std::bind(&UwbHal::reset, + uwb_hal); dbus_adapter.setReset(reset_handler); - auto factory_reset_handler = std::bind(&UwbRangePlugin::factoryReset, - range_plugin); + auto factory_reset_handler = std::bind(&UwbHal::factoryReset, + uwb_hal); dbus_adapter.setFactoryReset(factory_reset_handler); using namespace std::placeholders; - auto send_message_handler = std::bind(&UwbRangePlugin::sendMessage, - range_plugin, _1, _2); + auto send_message_handler = std::bind(&UwbHal::sendMessage, + uwb_hal, _1, _2); dbus_adapter.setSendMessage(send_message_handler); - auto send_message_to_handler = std::bind(&UwbRangePlugin::sendMessageTo, - range_plugin, _1, _2, _3); + auto send_message_to_handler = std::bind(&UwbHal::sendMessageTo, + uwb_hal, _1, _2, _3); dbus_adapter.setSendMessageTo(send_message_to_handler); } @@ -156,20 +155,25 @@ int main(int argc, char *argv[]) { __UWB_LOG_FUNC_ENTER__; - std::shared_ptr<UwbManagerNamespace::UwbRangePlugin> range_plugin = - std::make_shared<UwbManagerNamespace::UwbRangePlugin>(); + std::shared_ptr<UwbManagerNamespace::UwbHal> uwb_hal = + std::make_shared<UwbManagerNamespace::UwbHal>(); - UwbManagerNamespace::UwbPluginManager plugin_manager; - int ret = plugin_manager.load(range_plugin); + int ret = uwb_hal->init(); if (ret != 0) { __UWB_LOG_FUNC_EXIT__; return -1; } - UwbManagerNamespace::UwbConfig uwb_config(range_plugin); - UwbManagerNamespace::UwbNetwork uwb_network(range_plugin); + ret = uwb_hal->start(); + if (ret != 0) { + __UWB_LOG_FUNC_EXIT__; + return -1; + } + + UwbManagerNamespace::UwbConfig uwb_config(uwb_hal); + UwbManagerNamespace::UwbNetwork uwb_network(uwb_hal); std::shared_ptr<UwbManagerNamespace::UwbPosition> uwb_position = - std::make_shared<UwbManagerNamespace::UwbPosition>(range_plugin); + std::make_shared<UwbManagerNamespace::UwbPosition>(uwb_hal); UwbManagerNamespace::LocationManager location_manager(uwb_position); ret = uwb_config.loadConfiguration(); @@ -182,7 +186,7 @@ int main(int argc, char *argv[]) UwbManagerNamespace::UwbDbusIfaceAdapter dbus_adapter; dbus_manager.init(); - __set_device_control_handler(range_plugin.get(), dbus_adapter); + __set_device_control_handler(uwb_hal.get(), dbus_adapter); __set_configuration_handler(&uwb_config, dbus_adapter); __set_network_handler(&uwb_network, dbus_adapter); __set_position_handler(uwb_position.get(), dbus_adapter); @@ -201,7 +205,8 @@ int main(int argc, char *argv[]) dbus_manager.deinit(); uwb_network.disable(); - plugin_manager.unload(range_plugin); + uwb_hal->stop(); + uwb_hal->deinit(); return 0; } diff --git a/uwb-plugin-dummy.manifest b/uwb-plugin-dummy.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/uwb-plugin-dummy.manifest +++ /dev/null @@ -1,5 +0,0 @@ -<manifest> - <request> - <domain name="_"/> - </request> -</manifest> diff --git a/uwb-plugin-dwm1001.manifest b/uwb-plugin-dwm1001.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/uwb-plugin-dwm1001.manifest +++ /dev/null @@ -1,5 +0,0 @@ -<manifest> - <request> - <domain name="_"/> - </request> -</manifest> |