diff --git a/build/linux/bpi/makefile b/build/linux/bpi/makefile index ae8e53d5a..23cd02398 100644 --- a/build/linux/bpi/makefile +++ b/build/linux/bpi/makefile @@ -266,6 +266,7 @@ INCLUDEDIRS = \ -I$(ONE_WIFI_HOME)/source/apps/easyconnect \ -I$(ONE_WIFI_HOME)/source/apps/em \ -I$(ONE_WIFI_HOME)/source/apps/linkquality \ + -I$(ONE_WIFI_HOME)/source/apps/wifi_sensing/inc \ -I$(ONE_WIFI_HOME)/source/utils/quality_mgr/inc/ \ -I$(ONE_WIFI_HOME)/source/utils/math_utils/inc/ \ -I$(ONE_WIFI_HOME)/source/core/services \ @@ -446,6 +447,10 @@ ifdef EM_APP endif WEBCONFIG_SOURCES += $(ONE_WIFI_HOME)/source/webconfig/wifi_webconfig_link_report.c +ifdef WIFI_SENSING_APP_SUPPORT + CSOURCES += $(wildcard $(ONE_WIFI_HOME)/source/apps/wifi_sensing/src/*.c) +endif + COBJECTS = $(CSOURCES:.c=.o) # expands to list of object files WEBCONFIG_OBJECTS = $(WEBCONFIG_SOURCES:.c=.o) # expands to list of object files diff --git a/build/linux/rpi/makefile b/build/linux/rpi/makefile index b39ed4417..6ea8374f7 100644 --- a/build/linux/rpi/makefile +++ b/build/linux/rpi/makefile @@ -237,6 +237,7 @@ INCLUDEDIRS = \ -I$(ONE_WIFI_HOME)/source/apps/easyconnect \ -I$(ONE_WIFI_HOME)/source/apps/em \ -I$(ONE_WIFI_HOME)/source/apps/linkquality \ + -I$(ONE_WIFI_HOME)/source/apps/wifi_sensing/inc \ -I$(ONE_WIFI_HOME)/source/utils/quality_mgr/inc/ \ -I$(ONE_WIFI_HOME)/source/utils/math_utils/inc/ \ -I$(ONE_WIFI_HOME)/source/core/services \ @@ -422,6 +423,10 @@ endif WEBCONFIG_SOURCES += $(ONE_WIFI_HOME)/source/webconfig/wifi_webconfig_link_report.c WEBCONFIG_SOURCES += $(ONE_WIFI_HOME)/source/webconfig/wifi_webconfig_ignite.c +ifdef WIFI_SENSING_APP_SUPPORT + CSOURCES += $(wildcard $(ONE_WIFI_HOME)/source/apps/wifi_sensing/src/*.c) +endif + COBJECTS = $(CSOURCES:.c=.o) # expands to list of object files WEBCONFIG_OBJECTS = $(WEBCONFIG_SOURCES:.c=.o) # expands to list of object files diff --git a/build/openwrt/makefile b/build/openwrt/makefile index ec7bb9c80..b7cd4ccf9 100644 --- a/build/openwrt/makefile +++ b/build/openwrt/makefile @@ -312,6 +312,7 @@ INCLUDEDIRS = \ -I$(ONE_WIFI_HOME)/source/apps/easyconnect \ -I$(ONE_WIFI_HOME)/source/apps/em \ -I$(ONE_WIFI_HOME)/source/apps/linkquality \ + -I$(ONE_WIFI_HOME)/source/apps/wifi_sensing/inc \ -I$(ONE_WIFI_HOME)/source/utils/quality_mgr/inc/ \ -I$(ONE_WIFI_HOME)/source/utils/math_utils/inc/ \ -I$(ONE_WIFI_HOME)/source/core/services \ @@ -491,6 +492,10 @@ ifdef EM_APP endif WEBCONFIG_SOURCES += $(ONE_WIFI_HOME)/source/webconfig/wifi_webconfig_link_report.c +ifdef WIFI_SENSING_APP_SUPPORT + CSOURCES += $(wildcard $(ONE_WIFI_HOME)/source/apps/wifi_sensing/src/*.c) +endif + COBJECTS = $(CSOURCES:.c=.o) # expands to list of object files WEBCONFIG_OBJECTS = $(WEBCONFIG_SOURCES:.c=.o) # expands to list of object files diff --git a/configure.ac b/configure.ac index 287728717..7e0668111 100644 --- a/configure.ac +++ b/configure.ac @@ -133,6 +133,7 @@ AM_CONDITIONAL([EASYCONNECT_SUPPORT], [test x$EASYCONNECT_SUPPORT_ENABLE = xtrue AM_CONDITIONAL([HAL_IPC], [test x$HAL_IPC = xtrue]) AM_CONDITIONAL([ONEWIFI_CAC_APP_SUPPORT], [test x$ONEWIFI_CAC_APP_SUPPORT = xtrue]) +AM_CONDITIONAL([WIFI_SENSING_APP_SUPPORT], [test x$WIFI_SENSING_APP_SUPPORT = xtrue]) AM_CONDITIONAL([ONEWIFI_STA_MGR_APP_SUPPORT], [test x$ONEWIFI_STA_MGR_APP_SUPPORT = xtrue]) AM_CONDITIONAL([ONEWIFI_DML_SUPPORT], [test x$ONEWIFI_DML_SUPPORT_MAKEFILE = xtrue]) AM_CONDITIONAL([ONEWIFI_JSON_DML_SUPPORT], [test x$ONEWIFI_JSON_DML_SUPPORT = xtrue]) diff --git a/include/wifi_base.h b/include/wifi_base.h index 1659ba63e..20896b11c 100644 --- a/include/wifi_base.h +++ b/include/wifi_base.h @@ -175,7 +175,8 @@ typedef enum { wifi_app_inst_sta_mgr = wifi_app_inst_base << 17, wifi_app_inst_memwraptool = wifi_app_inst_base << 18, wifi_app_inst_link_quality = wifi_app_inst_base << 19, - wifi_app_inst_max = wifi_app_inst_base << 20 + wifi_app_inst_wifi_sensing = wifi_app_inst_base << 20, + wifi_app_inst_max = wifi_app_inst_base << 21 } wifi_app_inst_t; typedef struct { diff --git a/source/apps/wifi_apps.c b/source/apps/wifi_apps.c index 8126295ee..1a01e1ecc 100644 --- a/source/apps/wifi_apps.c +++ b/source/apps/wifi_apps.c @@ -27,6 +27,11 @@ #include "wifi_util.h" #include "wifi_apps_mgr.h" #include "wifi_linkquality.h" + +#ifdef WIFI_SENSING_APP_SUPPORT +#include "motion_sensing.h" +#endif + #ifdef ONEWIFI_ANALYTICS_APP_SUPPORT extern int analytics_init(wifi_app_t *app, unsigned int create_flag); extern int analytics_deinit(wifi_app_t *app); @@ -419,6 +424,16 @@ wifi_app_descriptor_t app_desc[] = { NULL, NULL }, #endif // ONEWIFI_EASYCONNECT_APP_SUPPORT +#ifdef WIFI_SENSING_APP_SUPPORT + { + wifi_app_inst_wifi_sensing, 0, + wifi_event_type_hal_ind, + true, true, + "WiFiSensing", + sensing_app_init, sensing_app_event, sensing_app_deinit, + NULL, NULL + }, +#endif }; wifi_app_descriptor_t* get_app_desc(int *size){ diff --git a/source/apps/wifi_apps_mgr.h b/source/apps/wifi_apps_mgr.h index 764aa8133..39b34df17 100644 --- a/source/apps/wifi_apps_mgr.h +++ b/source/apps/wifi_apps_mgr.h @@ -53,6 +53,11 @@ extern "C" { #include "wifi_easyconnect.h" #endif // ONEWIFI_EASYCONNECT_APP_SUPPORT #include "wifi_linkquality.h" + +#ifdef WIFI_SENSING_APP_SUPPORT +#include "motion_sensing.h" +#endif + #define MAX_APP_INIT_DATA 1024 #define APP_DETACHED 0x01 @@ -98,6 +103,9 @@ typedef struct { em_data_t em_data; #endif //EM_APP linkquality_data_t linkquality; +#ifdef WIFI_SENSING_APP_SUPPORT + sensing_app_obj_t sensing_obj; +#endif } u; } wifi_app_data_t; diff --git a/source/apps/wifi_sensing/inc/motion_sensing.h b/source/apps/wifi_sensing/inc/motion_sensing.h new file mode 100644 index 000000000..a21e271b6 --- /dev/null +++ b/source/apps/wifi_sensing/inc/motion_sensing.h @@ -0,0 +1,46 @@ +/************************************************************************************ + If not stated otherwise in this file or this component's LICENSE file the + following copyright and licenses apply: + + Copyright 2018 RDK Management + + 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 MOTION_SENSING_H +#define MOTION_SENSING_H + +#include +#include "wifi_base.h" +#include "wifi_events.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct wifi_app wifi_app_t; + +typedef struct sensing_app_obj { + bool sensing_enabled; +} sensing_app_obj_t; + + +int sensing_app_init(wifi_app_t *app, unsigned int create_flag); +int sensing_app_deinit(wifi_app_t *app); +int sensing_app_event(wifi_app_t *app, wifi_event_t *event); + +#ifdef __cplusplus +} +#endif + +#endif//MOTION_SENSING_H diff --git a/source/apps/wifi_sensing/src/motion_sensing.c b/source/apps/wifi_sensing/src/motion_sensing.c new file mode 100644 index 000000000..622b7bb09 --- /dev/null +++ b/source/apps/wifi_sensing/src/motion_sensing.c @@ -0,0 +1,126 @@ +/************************************************************************************ + If not stated otherwise in this file or this component's LICENSE file the + following copyright and licenses apply: + + Copyright 2018 RDK Management + + 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 +#include +#include +#include "wifi_util.h" +#include "wifi_events.h" +#include "wifi_apps_mgr.h" +#include "wifi_ctrl.h" +#include "motion_sensing.h" + +sensing_app_obj_t *get_sensing_app_obj(void) +{ + wifi_app_t *app = NULL; + wifi_apps_mgr_t *apps_mgr; + + wifi_ctrl_t *ctrl = (wifi_ctrl_t *)get_wifictrl_obj(); + if (ctrl == NULL) { + wifi_util_error_print(WIFI_SENSING, "%s:%d NULL Pointer \n", __func__, __LINE__); + return NULL; + } + + apps_mgr = &ctrl->apps_mgr; + app = get_app_by_inst(apps_mgr, wifi_app_inst_wifi_sensing); + if (app == NULL) { + wifi_util_error_print(WIFI_SENSING,"%s:%d NULL Pointer \n", __func__, __LINE__); + return NULL; + } + + return &app->data.u.sensing_obj; +} + +void sensing_app_assoc_device_event(wifi_app_t *apps, void *data) +{ + if (data == NULL) { + wifi_util_error_print(WIFI_SENSING,"%s:%d NULL Pointer \n", __func__, __LINE__); + return; + } + + assoc_dev_data_t *assoc_data = (assoc_dev_data_t *) data; + + if (isVapPrivate(assoc_data->ap_index)) { + mac_addr_str_t str_sta_mac = { 0 }; + + to_mac_str(assoc_data->dev_stats.cli_MACAddress, str_sta_mac); + wifi_util_info_print(WIFI_SENSING,"%s:%d sta info:%s\n", __func__, __LINE__, str_sta_mac); + } +} + +void sensing_app_disassoc_device_event(wifi_app_t *apps, void *data) +{ + if (data == NULL) { + wifi_util_error_print(WIFI_SENSING,"%s:%d NULL Pointer \n", __func__, __LINE__); + return; + } + + assoc_dev_data_t *assoc_data = (assoc_dev_data_t *) data; + + if (isVapPrivate(assoc_data->ap_index)) { + mac_addr_str_t str_sta_mac = { 0 }; + + to_mac_str(assoc_data->dev_stats.cli_MACAddress, str_sta_mac); + wifi_util_info_print(WIFI_SENSING,"%s:%d sta info:%s\n", __func__, __LINE__, str_sta_mac); + } +} + +int hal_event_for_sensing_app(wifi_app_t *app, wifi_event_subtype_t sub_type, void *data) +{ + switch (sub_type) { + case wifi_event_hal_assoc_device: + sensing_app_assoc_device_event(app, data); + break; + case wifi_event_hal_disassoc_device: + sensing_app_disassoc_device_event(app, data); + break; + default: + break; + } + return RETURN_OK; +} + +int sensing_app_event(wifi_app_t *app, wifi_event_t *event) +{ + switch (event->event_type) { + case wifi_event_type_hal_ind: + hal_event_for_sensing_app(app, event->sub_type, event->u.core_data.msg); + break; + + default: + break; + } + + return RETURN_OK; +} + +int sensing_app_init(wifi_app_t *app, unsigned int create_flag) +{ + wifi_util_info_print(WIFI_SENSING,"%s:%d wifi sensing app started...\n", __func__, __LINE__); + if (app_init(app, create_flag) != 0) { + return RETURN_ERR; + } + + return 0; +} + +int sensing_app_deinit(wifi_app_t *app) +{ + return RETURN_OK; +} diff --git a/source/core/Makefile.am b/source/core/Makefile.am index 314ed9a0e..6a42cfaa1 100644 --- a/source/core/Makefile.am +++ b/source/core/Makefile.am @@ -173,6 +173,24 @@ endif OneWifi_SOURCES += $(top_srcdir)/source/apps/linkquality/wifi_linkquality.c OneWifi_CPPFLAGS += -I$(top_srcdir)/source/apps/linkquality/ +if WIFI_SENSING_APP_SUPPORT +OneWifi_CXXFLAGS = -I$(STAGING_INCDIR)/ccsp +OneWifi_SOURCES += $(top_srcdir)/source/apps/wifi_sensing/src/motion_sensing.c \ + $(top_srcdir)/source/apps/wifi_sensing/src/motion_sensing_core.cpp \ + $(top_srcdir)/source/apps/wifi_sensing/src/motion_sensing_events.cpp \ + $(top_srcdir)/source/apps/wifi_sensing/src/motion_sensing_zilker.cpp \ + $(top_srcdir)/source/apps/wifi_sensing/src/sounder.cpp \ + $(top_srcdir)/source/apps/wifi_sensing/src/csi_raw_data_save.c + +OneWifi_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/inc + +OneWifi_SOURCES += $(top_srcdir)/source/apps/wifi_sensing/tflite/src/inference.c \ + $(top_srcdir)/source/apps/wifi_sensing/tflite/src/tensor.c \ + $(top_srcdir)/source/apps/wifi_sensing/tflite/src/wifi_tools.c + +OneWifi_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/tflite/inc/ +endif + if USE_DML_SOURCES # Common WFA DML sources (used in both ONEWIFI_DML_SUPPORT and ONEWIFI_JSON_DML_SUPPORT) WFA_JSON_DML_SOURCES = $(top_srcdir)/source/platform/common/data_model/wifi_dml_json_parser.c $(top_srcdir)/source/platform/common/data_model/wifi_dml_api.c \ @@ -232,4 +250,7 @@ OneWifi_LDFLAGS += -L$(top_builddir)/source/webconfig/ endif OneWifi_LDFLAGS += -lwifi_webconfig OneWifi_LDFLAGS += -lwifi_bus +if WIFI_SENSING_APP_SUPPORT +OneWifi_LDFLAGS += -ltensorflowlite_c +endif #OneWifi_LDFLAGS += -llibnl-3.la llibnl-genl-3.la llibnl-route-3.la llibnl-nf-3.la llibnl-idiag-3 diff --git a/source/dml/dml_webconfig/Makefile.am b/source/dml/dml_webconfig/Makefile.am index 63e182885..76ce178b0 100644 --- a/source/dml/dml_webconfig/Makefile.am +++ b/source/dml/dml_webconfig/Makefile.am @@ -46,6 +46,8 @@ noinst_LTLIBRARIES = libCcspWifiAgent_dml_webconfig.la libCcspWifiAgent_dml_webconfig_la_CPPFLAGS = -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/custom -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/include -I$(top_srcdir)/../CcspCommonLibrary/source/debug_api/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include/linux -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/package/slap/include -I$(top_srcdir)/../hal/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/http/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/ansc/include -I$(top_srcdir)/source/dml/dml_webconfig -I$(top_srcdir)/source/dml/tr_181/ml -I$(top_srcdir)/source/dml/tr_181/sbapi -I$(top_srcdir)/include/tr_181/ml -I$(top_srcdir)/source/dml/wifi_ssp -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/MessageBusHelper/include -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/PoamIrepFolder -I$(top_srcdir)/include/wifi_ssp -I$(top_srcdir)/./include -I$(top_srcdir)/source/core -I$(top_srcdir)/source/stats -I$(top_srcdir)/source/db -I$(top_srcdir)/source/utils -I$(top_srcdir)/source/core/services -I$(top_srcdir)/source/apps -I$(top_srcdir)/source/apps/analytics -I$(top_srcdir)/source/apps/levl -I$(top_srcdir)/source/apps/em -I$(top_srcdir)/source/apps/cac -I$(top_srcdir)/source/apps/sta_mgr -I$(top_srcdir)/source/apps/sm -I$(top_srcdir)/lib/const -I$(top_srcdir)/source/apps/motion -I$(top_srcdir)/source/apps/csi -I$(top_srcdir)/source/apps/whix -I$(top_srcdir)/source/apps/harvester -I$(top_srcdir)/source/apps/blaster -I$(top_srcdir)/source/apps/ocs -I$(top_srcdir)/source/platform/rdkb/ -I$(top_srcdir)/source/platform/common -I$(top_srcdir)/source/ccsp -I$(top_srcdir)/source/dml/rdkb/ -I$(top_srcdir)/source/stubs -I$(top_srcdir)/source/apps/sta_mgr -I$(top_srcdir)/source/apps/linkquality -I$(top_srcdir)/source/utils/math_utils/inc/ -I$(top_srcdir)/source/utils/quality_mgr/inc/ $(CPPFLAGS) +libCcspWifiAgent_dml_webconfig_la_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/inc + libCcspWifiAgent_dml_webconfig_la_CPPFLAGS += $(EM_APP_FLAG) libCcspWifiAgent_dml_webconfig_la_SOURCES = dml_onewifi_api.c libCcspWifiAgent_dml_webconfig_la_LDFLAGS = -lccsp_common -lsecure_wrapper diff --git a/source/dml/tr_181/ml/Makefile.am b/source/dml/tr_181/ml/Makefile.am index df20de953..9f3f7e26f 100644 --- a/source/dml/tr_181/ml/Makefile.am +++ b/source/dml/tr_181/ml/Makefile.am @@ -44,6 +44,8 @@ hardware_platform = i686-linux-gnu noinst_LTLIBRARIES = libCcspWifiAgent_ml.la libCcspWifiAgent_ml_la_CPPFLAGS = -I$(top_srcdir)/source/apps/em -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/custom -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/include -I$(top_srcdir)/../CcspCommonLibrary/source/debug_api/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include/linux -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/package/slap/include -I$(top_srcdir)/../hal/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/http/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/ansc/include -I$(top_srcdir)/source/dml/dml_webconfig -I$(top_srcdir)/source/dml/tr_181/ml -I$(top_srcdir)/source/dml/tr_181/sbapi -I$(top_srcdir)/include/tr_181/ml -I$(top_srcdir)/source/dml/wifi_ssp -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/MessageBusHelper/include -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/PoamIrepFolder -I$(top_srcdir)/include/wifi_ssp -I$(top_srcdir)/./include -I$(top_srcdir)/source/core -I$(top_srcdir)/source/stats -I$(top_srcdir)/source/db -I$(top_srcdir)/source/utils -I$(top_srcdir)/lib/ovsdb -I$(top_srcdir)/lib/inc -I$(top_srcdir)/lib/json_util -I$(top_srcdir)/lib/ds -I$(top_srcdir)/lib/common -I$(top_srcdir)/lib/pjs -I$(top_srcdir)/lib/log -I$(top_srcdir)/lib/const -I$(top_srcdir)/lib/schema -I$(top_srcdir)/lib/osp -I$(top_srcdir)/lib/osa -I$(top_srcdir)/lib/psfs -I$(top_srcdir)/lib/qm -I$(top_srcdir)/source/core/services -I$(top_srcdir)/source/apps -I$(top_srcdir)/source/apps/analytics -I$(top_srcdir)/source/apps/levl -I$(top_srcdir)/source/apps/sta_mgr -I$(top_srcdir)/source/apps/csi -I$(top_srcdir)/source/apps/motion -I$(top_srcdir)/source/apps/cac -I$(top_srcdir)/source/apps/sm -I$(top_srcdir)/source/apps/whix -I$(top_srcdir)/source/apps/harvester -I$(top_srcdir)/source/apps/blaster -I$(top_srcdir)/source/apps/ocs -I$(top_srcdir)/source/platform/rdkb -I$(top_srcdir)/source/platform/common -I$(top_srcdir)/source/ccsp/ -I$(top_srcdir)/source/dml/rdkb/ -I$(top_srcdir)/source/apps/linkquality -I$(top_srcdir)/source/utils/math_utils/inc/ -I$(top_srcdir)/source/utils/quality_mgr/inc/ $(CPPFLAGS) +libCcspWifiAgent_ml_la_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/inc + libCcspWifiAgent_ml_la_CPPFLAGS += $(EM_APP_FLAG) libCcspWifiAgent_ml_la_SOURCES = plugin_main.c cosa_apis_util.c plugin_main_apis.c cosa_wifi_dml.c cosa_apis_busutil.c cosa_wifi_internal.c cosa_logging_internal.c cosa_logging_dml.c cosa_harvester_dml.c libCcspWifiAgent_ml_la_LDFLAGS = -lccsp_common -lsecure_wrapper diff --git a/source/dml/tr_181/ml/cosa_wifi_dml.c b/source/dml/tr_181/ml/cosa_wifi_dml.c index 23f33b534..83ac0114d 100755 --- a/source/dml/tr_181/ml/cosa_wifi_dml.c +++ b/source/dml/tr_181/ml/cosa_wifi_dml.c @@ -598,6 +598,7 @@ WiFi_GetParamUlongValue *puLong = numOfRadios; return TRUE; } + /* CcspTraceWarning(("Unsupported parameter '%s'\n", ParamName)); */ return FALSE; } diff --git a/source/dml/tr_181/sbapi/Makefile.am b/source/dml/tr_181/sbapi/Makefile.am index 6d327d38c..8c19e2f84 100644 --- a/source/dml/tr_181/sbapi/Makefile.am +++ b/source/dml/tr_181/sbapi/Makefile.am @@ -48,6 +48,8 @@ noinst_LTLIBRARIES = libCcspWifiAgent_sbapi.la libCcspWifiAgent_sbapi_la_CPPFLAGS = -I$(top_srcdir)/source/apps/em -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/custom -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/include -I$(top_srcdir)/../CcspCommonLibrary/source/debug_api/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include/linux -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/package/slap/include -I$(top_srcdir)/../hal/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/http/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/ansc/include -I$(top_srcdir)/source/dml/wifi_ssp -I$(top_srcdir)/source/dml/dml_webconfig -I$(top_srcdir)/source/dml/tr_181/ml -I$(top_srcdir)/include/tr_181/ml -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/MessageBusHelper/include -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/PoamIrepFolder -I$(top_srcdir)/include/wifi_ssp -I$(top_srcdir)/./include -I$(top_srcdir)/lib/ovsdb -I$(top_srcdir)/lib/inc -I$(top_srcdir)/lib/json_util -I$(top_srcdir)/lib/ds -I$(top_srcdir)/lib/common -I$(top_srcdir)/lib/pjs -I$(top_srcdir)/lib/log -I$(top_srcdir)/lib/const -I$(top_srcdir)/lib/schema -I$(top_srcdir)/lib/osp -I$(top_srcdir)/lib/osa -I$(top_srcdir)/lib/psfs -I$(top_srcdir)/lib/qm -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/rbus -I$(top_srcdir)/source/core -I$(top_srcdir)/source/stats -I$(top_srcdir)/source/utils -I$(top_srcdir)/source/db -I$(top_srcdir)/source/core/services -I$(top_srcdir)/source/apps -I$(top_srcdir)/source/apps/analytics -I$(top_srcdir)/source/apps/levl -I$(top_srcdir)/source/apps/sta_mgr -I$(top_srcdir)/source/apps/cac -I$(top_srcdir)/source/apps/sm -I$(top_srcdir)/source/apps/csi -I$(top_srcdir)/source/apps/motion -I$(top_srcdir)/source/apps/whix -I$(top_srcdir)/source/apps/harvester -I$(top_srcdir)/source/apps/blaster -I$(top_srcdir)/source/apps/ocs -I$(top_srcdir)/source/platform/common -I$(top_srcdir)/source/ccsp/ -I$(top_srcdir)/source/dml/rdkb/ -I$(top_srcdir)/source/apps/linkquality -I$(top_srcdir)/source/utils/math_utils/inc/ -I$(top_srcdir)/source/utils/quality_mgr/inc/ $(CPPFLAGS) +libCcspWifiAgent_sbapi_la_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/inc + if ONEWIFI_DBUS_SUPPORT libCcspWifiAgent_sbapi_la_CPPFLAGS += -I$(top_srcdir)/source/platform/dbus -I${PKG_CONFIG_SYSROOT_DIR}/$(includedir)/dbus-1.0 -I${PKG_CONFIG_SYSROOT_DIR}/usr/lib/dbus-1.0/include else diff --git a/source/platform/Makefile.am b/source/platform/Makefile.am index 716e49da5..52292acd9 100644 --- a/source/platform/Makefile.am +++ b/source/platform/Makefile.am @@ -42,6 +42,8 @@ libwifi_bus_la_LDFLAGS += -lwifi_webconfig libwifi_bus_la_CPPFLAGS = -I$(top_srcdir)/source/apps/em -I$(top_srcdir)/source/platform/ -I/var/tmp/pc-rdkb/include/dbus-1.0 -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/custom -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/include -I$(top_srcdir)/../CcspCommonLibrary/source/debug_api/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include/linux -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/package/slap/include -I$(top_srcdir)/../hal/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/http/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/ansc/include -I$(top_srcdir)/source/dml/wifi_ssp -I$(top_srcdir)/source/dml/dml_webconfig -I$(top_srcdir)/source/dml/tr_181/ml -I$(top_srcdir)/source/dml/tr_181/sbapi -I$(top_srcdir)/include/tr_181/ml -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/MessageBusHelper/include -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/PoamIrepFolder -I$(top_srcdir)/include/wifi_ssp -I$(top_srcdir)/./include -I$(top_srcdir)/source/core -I$(top_srcdir)/source/stats -I$(top_srcdir)/source/db -I$(top_srcdir)/lib/ovsdb -I$(top_srcdir)/lib/inc -I$(top_srcdir)/lib/json_util -I$(top_srcdir)/lib/ds -I$(top_srcdir)/lib/common -I$(top_srcdir)/lib/pjs -I$(top_srcdir)/lib/log -I$(top_srcdir)/lib/const -I$(top_srcdir)/lib/schema -I$(top_srcdir)/lib/osp -I$(top_srcdir)/lib/osa -I$(top_srcdir)/lib/psfs -I$(top_srcdir)/lib/qm -I$(top_srcdir)/source/utils -I$(top_srcdir)/source/core/services -I$(top_srcdir)/source/apps -I$(top_srcdir)/source/apps/analytics -I$(top_srcdir)/source/apps/levl -I$(top_srcdir)/source/apps/cac -I$(top_srcdir)/source/apps/sm -I$(top_srcdir)/source/apps/motion -I$(top_srcdir)/source/apps/csi -I$(top_srcdir)/source/apps/whix -I$(top_srcdir)/source/apps/harvester -I$(top_srcdir)/source/apps/blaster -I$(top_srcdir)/source/apps/ocs -I$(top_srcdir)/source/platform/common/ -I$(top_srcdir)/source/ccsp -I$(top_srcdir)/source/dml/rdkb -I$(top_srcdir)/source/apps/linkquality -I$(top_srcdir)/source/utils/math_utils/inc/ -I$(top_srcdir)/source/utils/quality_mgr/inc/ +libwifi_bus_la_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/inc + libwifi_bus_la_SOURCES = $(top_srcdir)/source/platform/common/bus_common.c libwifi_bus_la_SOURCES += $(top_srcdir)/lib/common/util.c $(top_srcdir)/source/utils/wifi_util.c $(top_srcdir)/source/utils/collection.c diff --git a/source/sampleapps/Makefile.am b/source/sampleapps/Makefile.am index 97916f1d5..2d723fb52 100644 --- a/source/sampleapps/Makefile.am +++ b/source/sampleapps/Makefile.am @@ -44,6 +44,8 @@ hardware_platform = i686-linux-gnu bin_PROGRAMS = onewifi_component_test_app onewifi_component_test_app_CPPFLAGS = $(CPPFLAGS) -I$(top_srcdir)/source/apps/em -I$(top_srcdir)/./include -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/rbus -I$(top_srcdir)/../hal/include -I$(top_srcdir)/source/dml/tr_181/sbapi -I$(top_srcdir)/source/core -I$(top_srcdir)/source/stats -I$(top_srcdir)/source/utils -I$(top_srcdir)/source/core -I$(top_srcdir)/source/db -I$(top_srcdir)/source/dml/wifi_ssp -I$(top_srcdir)/./include -I$(top_srcdir)/./lib/ovsdb -I$(top_srcdir)/./lib/ds -I$(top_srcdir)/lib/common -I$(top_srcdir)/lib/pjs -I$(top_srcdir)/lib/log -I$(top_srcdir)/lib/const -I$(top_srcdir)/lib/schema -I$(top_srcdir)/lib/osp -I$(top_srcdir)/lib/osa -I$(top_srcdir)/lib/psfs -I$(top_srcdir)/lib/qm -I$(top_srcdir)/./lib/json_util/ -I$(top_srcdir)/source/dml/dml_webconfig -I$(top_srcdir)/source/core/services -I$(top_srcdir)/source/apps -I$(top_srcdir)/source/apps/analytics -I$(top_srcdir)/source/apps/levl -I$(top_srcdir)/source/apps/sta_mgr -I$(top_srcdir)/source/apps/cac -I$(top_srcdir)/source/apps/sm -I$(top_srcdir)/source/apps/motion -I$(top_srcdir)/source/apps/csi -I$(top_srcdir)/source/apps/whix -I$(top_srcdir)/source/apps/harvester -I$(top_srcdir)/source/apps/blaster -I$(top_srcdir)/source/apps/ocs -I$(top_srcdir)/source/platform/rdkb -I$(top_srcdir)/source/platform/common -I$(top_srcdir)/source/ccsp -I$(top_srcdir)/source/dml/rdkb -I$(top_srcdir)/source/apps/linkquality -I$(top_srcdir)/source/utils/math_utils/inc/ -I$(top_srcdir)/source/utils/quality_mgr/inc/ +onewifi_component_test_app_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/inc + onewifi_component_test_app_SOURCES = wifi_webconfig_consumer.c webconfig_consumer_apis.c webconfig_consumer_cli.c onewifi_component_test_app_SOURCES += $(top_srcdir)/source/utils/collection.c $(top_srcdir)/source/utils/scheduler.c diff --git a/source/utils/Makefile.am b/source/utils/Makefile.am index 7f228da46..cc4671eb2 100644 --- a/source/utils/Makefile.am +++ b/source/utils/Makefile.am @@ -58,6 +58,8 @@ lib_LTLIBRARIES=libwifi_utils.la libwifi_utils_la_CPPFLAGS = -I$(top_srcdir)/source/apps/em -I/var/tmp/pc-rdkb/include/dbus-1.0 -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/custom -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/include -I$(top_srcdir)/../CcspCommonLibrary/source/debug_api/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include/linux -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/package/slap/include -I$(top_srcdir)/../hal/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/http/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/ansc/include -I$(top_srcdir)/source/dml/wifi_ssp -I$(top_srcdir)/source/dml/dml_webconfig -I$(top_srcdir)/source/dml/tr_181/ml -I$(top_srcdir)/source/dml/tr_181/sbapi -I$(top_srcdir)/include/tr_181/ml -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/MessageBusHelper/include -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/PoamIrepFolder -I$(top_srcdir)/include/wifi_ssp -I$(top_srcdir)/./include -I$(top_srcdir)/source/core -I$(top_srcdir)/source/stats -I$(top_srcdir)/source/db -I$(top_srcdir)/lib/ovsdb -I$(top_srcdir)/lib/inc -I$(top_srcdir)/lib/json_util -I$(top_srcdir)/lib/ds -I$(top_srcdir)/lib/common -I$(top_srcdir)/lib/pjs -I$(top_srcdir)/lib/log -I$(top_srcdir)/lib/const -I$(top_srcdir)/lib/schema -I$(top_srcdir)/lib/osp -I$(top_srcdir)/lib/osa -I$(top_srcdir)/lib/psfs -I$(top_srcdir)/lib/qm -I$(top_srcdir)/source/core/services -I$(top_srcdir)/source/apps -I$(top_srcdir)/source/apps/analytics -I$(top_srcdir)/source/apps/levl -I$(top_srcdir)/source/apps/cac -I$(top_srcdir)/source/apps/sm -I$(top_srcdir)/source/apps/motion -I$(top_srcdir)/source/apps/csi -I$(top_srcdir)/source/apps/whix -I$(top_srcdir)/source/apps/harvester -I$(top_srcdir)/source/apps/blaster -I$(top_srcdir)/source/apps/ocs -I$(top_srcdir)/source/platform/common/ -I$(top_srcdir)/source/ccsp -I$(top_srcdir)/source/dml/rdkb -I$(top_srcdir)/source/apps/sta_mgr -I$(top_srcdir)/source/apps/linkquality -I$(top_srcdir)/source/utils/math_utils/inc/ -I$(top_srcdir)/source/utils/quality_mgr/inc/ +libwifi_utils_la_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/inc + if ONEWIFI_DBUS_SUPPORT libwifi_utils_la_CPPFLAGS += -I$(top_srcdir)/source/platform/dbus -I${PKG_CONFIG_SYSROOT_DIR}/$(includedir)/dbus-1.0 -I${PKG_CONFIG_SYSROOT_DIR}/usr/lib/dbus-1.0/include/ $(CPPFLAGS) else diff --git a/source/utils/math_utils/inc/base.h b/source/utils/math_utils/inc/base.h index 39cbb84a6..ca92d09a3 100644 --- a/source/utils/math_utils/inc/base.h +++ b/source/utils/math_utils/inc/base.h @@ -25,7 +25,7 @@ extern "C" { #endif -#define MAX_LEN 128 +#define MAX_LEN 256 #define MAX_MTRX_LEN MAX_LEN / 4 #define PI 3.14159 diff --git a/source/utils/math_utils/inc/matrix.h b/source/utils/math_utils/inc/matrix.h index 84ae16957..60122cdd5 100644 --- a/source/utils/math_utils/inc/matrix.h +++ b/source/utils/math_utils/inc/matrix.h @@ -29,16 +29,54 @@ class matrix_t { unsigned int m_cols; number_t m_val[MAX_MTRX_LEN][MAX_MTRX_LEN]; + unsigned int m_row_capacity; + unsigned int m_col_capacity; + private: void row_reduced_echelon_form(matrix_t &rref, matrix_t minor); public: + void reset() + { + m_rows = 0; + m_cols = 0; + } void set_row(unsigned int row, vector_t &v); void set_col(unsigned int col, vector_t &v); + void set_row_capacity(unsigned int cap) + { + m_row_capacity = cap; + } + unsigned int get_row_capacity() + { + return m_row_capacity; + } + + void set_col_capacity(unsigned int cap) + { + m_col_capacity = cap; + } + unsigned int get_col_capacity() + { + return m_col_capacity; + } + + unsigned int get_num_rows() + { + return m_rows; + } + unsigned int get_num_cols() + { + return m_cols; + } + vector_t get_row(unsigned int row); vector_t get_col(unsigned int col); + void push(vector_t v); + void push(matrix_t m); + matrix_t operator*(matrix_t m); matrix_t operator+(matrix_t m); matrix_t operator-(matrix_t m); diff --git a/source/utils/math_utils/inc/mvnpdf.h b/source/utils/math_utils/inc/mvnpdf.h index f0cbbae62..36b43ccb1 100644 --- a/source/utils/math_utils/inc/mvnpdf.h +++ b/source/utils/math_utils/inc/mvnpdf.h @@ -20,12 +20,12 @@ #define MVNPDF_H #include "base.h" +#include "matrix.h" #include "number.h" #include "vector.h" -#include "matrix.h" -#define MAX_VARIATES 5 -#define MAX_WINDOW 5 +#define MAX_VARIATES 5 +#define MAX_WINDOW 5 class mvnpdf_t { unsigned int m_variates; @@ -34,20 +34,29 @@ class mvnpdf_t { vector_t m_mean; vector_t m_variance; vector_t m_data[MAX_WINDOW]; - + public: void print(); - vector_t get_mean() { return m_mean; } - matrix_t get_covariance() { return m_cov; } - matrix_t get_zinverse() { return m_cov.inverse(); } + vector_t get_mean() + { + return m_mean; + } + matrix_t get_covariance() + { + return m_cov; + } + matrix_t get_zinverse() + { + return m_cov.inverse(); + } double mvnpdf(vector_t v); vector_t mean(); vector_t variance(vector_t v); vector_t stddev(); - + public: mvnpdf_t(unsigned int n); - ~mvnpdf_t(); + ~mvnpdf_t(); }; #endif diff --git a/source/utils/math_utils/inc/number.h b/source/utils/math_utils/inc/number.h index a29a0220a..082fabd0e 100644 --- a/source/utils/math_utils/inc/number.h +++ b/source/utils/math_utils/inc/number.h @@ -32,38 +32,51 @@ class number_t { bool is_zero(double x, int n); public: - bool operator ==(number_t n); - number_t operator *(number_t n); - number_t operator /(number_t n); - number_t operator +(number_t n); - number_t operator -(number_t n); - - number_t operator *(unsigned int n); - number_t operator /(unsigned int n); - matrix_t operator *(matrix_t m); - + bool operator!=(const number_t &other) const; + bool operator==(const number_t &other) const; + number_t operator*(number_t n); + number_t operator/(number_t n); + number_t operator+(number_t n); + number_t operator-(number_t n); + + number_t operator*(unsigned int n); + number_t operator/(unsigned int n); + matrix_t operator*(matrix_t m); + void sqroot(number_t n[]); number_t sqrt_val(void); double mod_z(); number_t absolute(); - double abs_val() const; - number_t operator-(void); + double abs_val() const; + number_t operator-(void); number_t exponential(); number_t power(unsigned int n); bool is_zero(int n); - - void set_real(double d) {m_re = d;} - void set_imag(double d) {m_im = d;} - - double get_real() {return m_re;} - double get_imag() {return m_im;} - + + void set_real(double d) + { + m_re = d; + } + void set_imag(double d) + { + m_im = d; + } + + double get_real() + { + return m_re; + } + double get_imag() + { + return m_im; + } + void print(); - - number_t(double r, double i); + + number_t(double r, double i); number_t(char *str); number_t(); - ~number_t(); + ~number_t(); }; #endif diff --git a/source/utils/math_utils/inc/sequence.h b/source/utils/math_utils/inc/sequence.h index e8d28b002..4fe8257bf 100644 --- a/source/utils/math_utils/inc/sequence.h +++ b/source/utils/math_utils/inc/sequence.h @@ -22,29 +22,62 @@ #include "base.h" #include "number.h" +#define MAX_SAMPLING_WINDOW 30 + class sequence_t { public: - number_t m_mean; - number_t m_variance; - number_t m_last; - number_t m_max; - number_t m_min; - unsigned int m_samples; - + number_t m_mean; + number_t m_variance; + number_t m_variance_running; + number_t m_gaussian; + number_t m_kurtosis; + number_t m_mfilter; + number_t m_last[MAX_SAMPLING_WINDOW]; + number_t m_max; + number_t m_min; + unsigned int m_total_samples; + unsigned int m_sampling_window; + unsigned int m_seq_index; public: - - sequence_t operator +(number_t n); - - void set_max(number_t n) { m_max = n; } - void set_min(number_t n) { m_min = n; } - - number_t get_max() { return m_max; } - number_t get_min() { return m_min; } - number_t get_mean() { return m_mean; } - number_t get_variance() { return m_variance; } - + sequence_t operator+(number_t n); + + void set_max(number_t n) + { + m_max = n; + } + void set_min(number_t n) + { + m_min = n; + } + + number_t get_max() + { + return m_max; + } + number_t get_min() + { + return m_min; + } + number_t get_mean() + { + return m_mean; + } + number_t get_variance() + { + return m_variance; + } + number_t get_kurtosis() + { + return m_kurtosis; + } + + void reset(); + + void print(); + sequence_t(); - ~sequence_t(); + sequence_t(int sampling_window); + ~sequence_t(); }; #endif diff --git a/source/utils/math_utils/inc/vector.h b/source/utils/math_utils/inc/vector.h index 6a79b6f06..3047d88e6 100644 --- a/source/utils/math_utils/inc/vector.h +++ b/source/utils/math_utils/inc/vector.h @@ -26,13 +26,29 @@ class vector_t { public: unsigned int m_num; number_t m_val[MAX_LEN]; + unsigned int m_capacity; public: void print(); - unsigned int get_capacity() + + void set_capacity(unsigned int cap) + { + m_capacity = ((cap < MAX_LEN) ? cap : MAX_LEN); + } + unsigned int get_capacity(void) + { + return m_capacity; + } + + number_t get_value(unsigned int index) { - return MAX_LEN; + return m_val[index]; } + unsigned int get_length() + { + return m_num; + } + vector_t invert(); void sort(); number_t mean(); @@ -45,6 +61,10 @@ class vector_t { vector_t operator-(vector_t v); vector_t operator/(number_t n); vector_t(unsigned int num, number_t n[]); + + void push(number_t n); + void push(vector_t v); + vector_t(unsigned int num); vector_t(); ~vector_t(); diff --git a/source/utils/math_utils/src/matrix.cpp b/source/utils/math_utils/src/matrix.cpp index 497972efb..d6b7a24eb 100644 --- a/source/utils/math_utils/src/matrix.cpp +++ b/source/utils/math_utils/src/matrix.cpp @@ -32,9 +32,9 @@ void matrix_t::print() for (i = 0; i < m_rows; i++) { for (j = 0; j < m_cols; j++) { m_val[i][j].print(); - wifi_util_dbg_print(WIFI_LIB, const_cast("\t\t")); + wifi_util_dbg_print(WIFI_LIB, "\t\t"); } - wifi_util_dbg_print(WIFI_LIB, const_cast("\n")); + wifi_util_dbg_print(WIFI_LIB, "\n"); } } @@ -47,7 +47,8 @@ matrix_t matrix_t::inverse() unsigned int i, j; if (m_rows != m_cols) { - wifi_util_error_print(WIFI_LIB, "%s:%d: Cannot be inverted in matrix\n", __func__, __LINE__); + wifi_util_error_print(WIFI_LIB, "%s:%d: Cannot be inverted in matrix\n", __func__, + __LINE__); return out; } @@ -339,7 +340,7 @@ int matrix_t::eigen(vector_t &vals, matrix_t &vecs) if (m_rows != m_cols) { return -1; } - + polynomial_t(faddeev_leverrier()).resolve(vals); vals.sort(); vals.print(); @@ -452,7 +453,7 @@ number_t matrix_t::determinant() matrix_t matrix_t::covariance() { unsigned int i, j; - matrix_t t(0,0), c, out(0, 0); + matrix_t t(0, 0), c, out(0, 0); if (m_rows == 1) { wifi_util_error_print(WIFI_LIB, @@ -461,15 +462,15 @@ matrix_t matrix_t::covariance() __func__, __LINE__); return out; } - + c = center(); t = c.transpose(); out.m_rows = m_cols; out.m_cols = m_cols; - - out = t*c; - + + out = t * c; + for (j = 0; j < out.m_cols; j++) { for (i = 0; i < out.m_rows; i++) { out.m_val[i][j].m_re /= (m_rows - 1); @@ -650,6 +651,56 @@ vector_t matrix_t::get_col(unsigned int col) return out; } +void matrix_t::push(vector_t v) +{ + unsigned int i, j; + + if (m_cols == 0) { + m_cols = ((v.m_num < m_col_capacity) ? v.m_num : m_col_capacity); + } + + if (v.m_num != m_cols) { + return; + } + + if (m_rows < m_row_capacity) { + for (j = 0; j < m_cols; j++) { + m_val[m_rows][j] = v.m_val[j]; + } + m_rows++; + return; + } + + // remove the top one to add at the end + for (i = 0; i < m_rows - 1; i++) { + for (j = 0; j < m_cols; j++) { + m_val[i][j] = m_val[i + 1][j]; + } + } + + for (j = 0; j < m_cols; j++) { + m_val[i][j] = v.m_val[j]; + } +} + +void matrix_t::push(matrix_t m) +{ + unsigned int i; + unsigned int rows = m.get_num_rows(); + + if (m_cols == 0) { + m_cols = m.m_cols; + } + + if (m.m_cols != m_cols) { + return; + } + + for (i = 0; i < rows; i++) { + push(m.get_row(i)); + } +} + matrix_t::matrix_t(unsigned int rows, unsigned int cols, number_t n[]) { unsigned int i, j, k = 0; @@ -657,6 +708,9 @@ matrix_t::matrix_t(unsigned int rows, unsigned int cols, number_t n[]) m_rows = rows; m_cols = cols; + m_row_capacity = MAX_MTRX_LEN; + m_col_capacity = MAX_MTRX_LEN; + for (i = 0; i < m_rows; i++) { for (j = 0; j < m_cols; j++) { m_val[i][j] = n[k]; @@ -672,6 +726,9 @@ matrix_t::matrix_t(unsigned int rows, unsigned int cols) m_rows = rows; m_cols = cols; + m_row_capacity = MAX_MTRX_LEN; + m_col_capacity = MAX_MTRX_LEN; + for (i = 0; i < m_rows; i++) { for (j = 0; j < m_cols; j++) { m_val[i][j] = number_t(0, 0); @@ -686,6 +743,9 @@ matrix_t::matrix_t(const matrix_t &m) m_rows = m.m_rows; m_cols = m.m_cols; + m_row_capacity = MAX_MTRX_LEN; + m_col_capacity = MAX_MTRX_LEN; + for (i = 0; i < m_rows; i++) { for (j = 0; j < m_cols; j++) { m_val[i][j] = m.m_val[i][j]; @@ -697,6 +757,9 @@ matrix_t::matrix_t(vector_t v, bool as_row) { unsigned int i, j; + m_row_capacity = MAX_MTRX_LEN; + m_col_capacity = MAX_MTRX_LEN; + if (as_row) { m_rows = 1; m_cols = v.m_num; @@ -716,6 +779,8 @@ matrix_t::matrix_t() { m_rows = 0; m_cols = 0; + m_row_capacity = MAX_MTRX_LEN; + m_col_capacity = MAX_MTRX_LEN; } matrix_t::~matrix_t() diff --git a/source/utils/math_utils/src/mvnpdf.cpp b/source/utils/math_utils/src/mvnpdf.cpp index b069d106b..bbf4cb499 100644 --- a/source/utils/math_utils/src/mvnpdf.cpp +++ b/source/utils/math_utils/src/mvnpdf.cpp @@ -16,37 +16,32 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "mvnpdf.h" +#include +#include #include #include #include -#include -#include -#include "mvnpdf.h" - void mvnpdf_t::print() { - } vector_t mvnpdf_t::mean() { unsigned int i; vector_t v; - + v.m_num = m_variates; for (i = 0; i < m_variates; i++) { v.m_val[i] = m_data[i].mean(); } - + return v; - } vector_t mvnpdf_t::variance(vector_t v) { - vector_t new_variance = {0}; - return m_variance; } @@ -54,12 +49,12 @@ vector_t mvnpdf_t::stddev() { unsigned int i; vector_t v; - + v.m_num = m_variates; for (i = 0; i < m_variates; i++) { v.m_val[i] = m_data[i].stddev(); } - + return v; } @@ -68,55 +63,55 @@ double mvnpdf_t::mvnpdf(vector_t v) matrix_t a, b, c, e; vector_t new_mean, new_variance; number_t det; - + if (v.m_num != m_variates) { printf("%s:%d: Invalid vector\n", __func__, __LINE__); return -1; } - + if (m_num == 0) { m_mean = v; m_num++; return 0; } - - new_mean = m_mean + (v - m_mean)/number_t(m_num + 1, 0); - + + new_mean = m_mean + (v - m_mean) / number_t(m_num + 1, 0); + a.set_col(0, v); b.set_col(0, m_mean); c.set_col(0, new_mean); - - m_cov = (number_t(m_num - 1, 0)/number_t(m_num + 1, 0))*m_cov + number_t(m_num, 0)/number_t(m_num + 1, 0)*((c - b)*(c - b).transpose()) + number_t(1, 0)/number_t(m_num + 1, 0)*((a - b)*(a - b).transpose()); - + + m_cov = (number_t(m_num - 1, 0) / number_t(m_num + 1, 0)) * m_cov + + number_t(m_num, 0) / number_t(m_num + 1, 0) * ((c - b) * (c - b).transpose()) + + number_t(1, 0) / number_t(m_num + 1, 0) * ((a - b) * (a - b).transpose()); + m_num++; m_mean = new_mean; - + det = m_cov.determinant().absolute(); if (det == number_t(0, 0)) { printf("%s:%d: Determinant is 0, not proceeding\n", __func__, __LINE__); return -1; } - - e = ((a - c).transpose()*m_cov.inverse()*(a - c)); + + e = ((a - c).transpose() * m_cov.inverse() * (a - c)); assert((e.m_rows == 1) || (e.m_cols == 1)); - - return (1/(sqrt(pow(2*PI, m_variates)*det.m_re)))*exp(-0.5*e.m_val[0][0].m_re); + return (1 / (sqrt(pow(2 * PI, m_variates) * det.m_re))) * exp(-0.5 * e.m_val[0][0].m_re); } mvnpdf_t::mvnpdf_t(unsigned int n) { m_cov = matrix_t(n, n); m_variates = n; - m_mean = {n}; + m_mean = { n }; m_num = 0; } mvnpdf_t::~mvnpdf_t() { m_variates = 0; - m_mean = {0}; + m_mean = { 0 }; m_num = 0; - m_variance = {0}; + m_variance = { 0 }; } - diff --git a/source/utils/math_utils/src/number.cpp b/source/utils/math_utils/src/number.cpp index 91d77a43f..7e3ebb40e 100644 --- a/source/utils/math_utils/src/number.cpp +++ b/source/utils/math_utils/src/number.cpp @@ -65,9 +65,14 @@ bool number_t::is_zero(int n) return (is_zero(m_re, n)) && (is_zero(m_im, n)); } -bool number_t::operator==(number_t n) +bool number_t::operator==(const number_t &other) const { - return (m_re == n.m_re) && (m_im == n.m_im); + return ((m_re == other.m_re) && (m_im == other.m_im)); +} + +bool number_t::operator!=(const number_t &other) const +{ + return !(*this == other); } number_t number_t::operator*(number_t n) @@ -86,19 +91,19 @@ number_t number_t::operator+(number_t n) return number_t(m_re + n.m_re, m_im + n.m_im); } -number_t number_t::operator -(number_t n) +number_t number_t::operator-(number_t n) { - return number_t(m_re - n.m_re, m_im - n.m_im);; + return number_t(m_re - n.m_re, m_im - n.m_im); } -number_t number_t::operator *(unsigned int n) +number_t number_t::operator*(unsigned int n) { - return number_t(m_re*n, m_im*n); + return number_t(m_re * n, m_im * n); } -number_t number_t::operator /(unsigned int n) +number_t number_t::operator/(unsigned int n) { - return number_t(m_re/n, m_im/n); + return number_t(m_re / n, m_im / n); } matrix_t number_t::operator*(matrix_t m) @@ -117,10 +122,10 @@ matrix_t number_t::operator*(matrix_t m) } number_t number_t::operator-(void) { - number_t out; + number_t out; out.m_re = -m_re; out.m_im = -m_im; - return out; + return out; } number_t number_t::sqrt_val(void) { @@ -138,7 +143,6 @@ double number_t::abs_val() const return sqrt(m_re * m_re + m_im * m_im); } - number_t number_t::exponential() { return number_t(exp(m_re), 0) * number_t(cos(m_im), sin(m_im)); @@ -185,7 +189,6 @@ void number_t::sqroot(number_t n[]) } } - number_t::number_t(double r, double i) { m_re = r; diff --git a/source/utils/math_utils/src/sequence.cpp b/source/utils/math_utils/src/sequence.cpp index 306d5c9a1..871b8718b 100644 --- a/source/utils/math_utils/src/sequence.cpp +++ b/source/utils/math_utils/src/sequence.cpp @@ -16,51 +16,206 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "sequence.h" +#include "number.h" +#include #include #include #include -#include -#include "number.h" -#include "sequence.h" -sequence_t sequence_t::operator +(number_t n) +void sequence_t::print() +{ + unsigned int i; + + if (m_sampling_window == 0) { + m_last[0].print(); + wifi_util_dbg_print(WIFI_LIB, "\n"); + return; + } + + for (i = 0; i < m_total_samples; i++) { + m_last[i].print(); + wifi_util_dbg_print(WIFI_LIB, "\t"); + } + + wifi_util_dbg_print(WIFI_LIB, "\n"); +} + +sequence_t sequence_t::operator+(number_t n) { - sequence_t seq; - number_t num[2]; - m_last = n; - - m_mean = (m_mean * m_samples + m_last)/(m_samples + 1); - (((m_variance.power(2) * m_samples) + (m_last - m_mean).power(2))/(m_samples + 1)).sqroot(num); - m_variance = num[0]; - #if 0 - if (m_max.m_re <= n.m_re) { - m_max = n; + number_t temp; + int i = 0; + + if (m_sampling_window != 0) { + m_last[m_seq_index] = n; + m_seq_index = (m_seq_index + 1) % m_sampling_window; + } else { + m_last[i] = n; } - - if (m_min.m_re >= n.m_re) { - m_min = n; + + if (m_sampling_window == 0 || m_total_samples < m_sampling_window) { + m_total_samples++; } - #endif - //m_variance.print(); - //printf("\n"); - - m_samples++; - + + if (m_variance.m_re != 0.0) { + m_gaussian.m_re = expf((-0.5) * (pow(n.m_re - m_mean.m_re, 2) / (pow(m_variance.m_re, 2)))) / + (sqrt(2 * PI * m_variance.m_re)); + } + if (m_variance.m_im != 0.0) { + m_gaussian.m_im = expf((-0.5) * (pow(n.m_im - m_mean.m_im, 2) / (pow(m_variance.m_im, 2)))) / + (sqrt(2 * PI * m_variance.m_im)); + } + + if (m_sampling_window == 0) { + m_kurtosis = (n - m_mean).power(4) / m_variance.power(2); + // convert stored values to double + double l_mean = m_mean.m_re; + double l_variance_running = m_variance_running.m_re; + double l_input = n.m_re; + + // Welford update + double delta = l_input - l_mean; + l_mean += (delta / m_total_samples); + + double delta2 = l_input - l_mean; + + l_variance_running += (delta * delta2); + + double var = l_variance_running / m_total_samples; + + // store back into number_t (imag = 0 always) + m_mean = number_t(l_mean, 0.0); + m_variance_running = number_t(l_variance_running, 0.0); + m_variance = number_t(var, 0.0); + } else if (m_total_samples > 0) { + m_mean = number_t(0, 0); + for (i = 0; i < m_total_samples; i++) { + m_mean = m_mean + m_last[i]; + } + m_mean = m_mean / m_total_samples; + + m_variance = number_t(0, 0); + for (i = 0; i < m_total_samples; i++) { + m_variance = m_variance + (m_last[i] - m_mean).power(2); + } + + m_variance = m_variance / m_total_samples; + + m_kurtosis = number_t(0, 0); + for (i = 0; i < m_total_samples; i++) { + m_kurtosis = m_kurtosis + (m_last[i] - m_mean).power(4); + } + + m_kurtosis = m_kurtosis / m_total_samples; + + temp = number_t(0, 0); + for (i = 0; i < m_total_samples; i++) { + temp = temp + (m_last[i] - m_mean).power(2); + } + + temp = temp / m_total_samples; + + if (temp != number_t(0, 0)) { + m_kurtosis = m_kurtosis / temp.power(2); + m_mfilter = (m_kurtosis.m_re > 4) ? number_t(m_kurtosis.m_re - 4, 0) : number_t(0, 0); + } + + } else { + m_mean = m_last[0]; + } + + if (m_sampling_window == 0) { + + if (m_max.m_re <= n.m_re) { + m_max = n; + } + + if (m_min.m_re >= n.m_re) { + m_min = n; + } + } else { + m_max = m_last[0]; + m_min = m_last[0]; + for (i = 1; i < m_total_samples; i++) { + if (m_max.m_re <= m_last[i].m_re) { + m_max = m_last[i]; + } + + if (m_min.m_re >= m_last[i].m_re) { + m_min = m_last[i]; + } + } + } + return *this; } +void sequence_t::reset() +{ + unsigned int i; + + m_mean = { 0, 0 }; + m_variance = { 0, 0 }; + m_max = { 0, 0 }; + m_min = { 0, 0 }; + + for (i = 0; i < MAX_SAMPLING_WINDOW; i++) { + m_last[i] = number_t(0, 0); + } + m_kurtosis = { 0, 0 }; + m_mfilter = { 0, 0 }; + + m_total_samples = 0; + m_seq_index = 0; +} + +sequence_t::sequence_t(int sampling_window) +{ + unsigned int i; + + m_mean = { 0, 0 }; + m_variance = { 0, 0 }; + m_max = { 0, 0 }; + m_min = { 0, 0 }; + + for (i = 0; i < MAX_SAMPLING_WINDOW; i++) { + m_last[i] = number_t(0, 0); + } + m_kurtosis = { 0, 0 }; + m_mfilter = { 0, 0 }; + + m_total_samples = 0; + m_seq_index = 0; + + if (sampling_window < 0) { + m_sampling_window = 0; + } else if (sampling_window > MAX_SAMPLING_WINDOW) { + m_sampling_window = MAX_SAMPLING_WINDOW; + } else { + m_sampling_window = sampling_window; + } +} + sequence_t::sequence_t() { - m_mean = {0, 0}; - m_variance = {0, 0}; - m_max = {0, 0}; - m_min = {0, 0}; - m_last = {0, 0}; - m_samples = 0; + unsigned int i; + + m_mean = { 0, 0 }; + m_variance = { 0, 0 }; + m_max = { 0, 0 }; + m_min = { 0, 0 }; + + for (i = 0; i < MAX_SAMPLING_WINDOW; i++) { + m_last[i] = number_t(0, 0); + } + m_kurtosis = { 0, 0 }; + m_mfilter = { 0, 0 }; + + m_total_samples = 0; + m_seq_index = 0; + m_sampling_window = 0; } sequence_t::~sequence_t() { - } - diff --git a/source/utils/math_utils/src/statistics.cpp b/source/utils/math_utils/src/statistics.cpp index ab3db9697..7658416b1 100644 --- a/source/utils/math_utils/src/statistics.cpp +++ b/source/utils/math_utils/src/statistics.cpp @@ -39,7 +39,6 @@ number_t statistics_t::stddev() number_t statistics_t::pdf(number_t x) { number_t exponent, coeff, mean, std; - vector_t v(0); mean = m_data.mean(); std = m_data.stddev(); diff --git a/source/utils/math_utils/src/vector.cpp b/source/utils/math_utils/src/vector.cpp index f6284387a..1d60ac784 100644 --- a/source/utils/math_utils/src/vector.cpp +++ b/source/utils/math_utils/src/vector.cpp @@ -179,10 +179,44 @@ vector_t vector_t::invert() return out; } +void vector_t::push(number_t num) +{ + unsigned int i; + + if (m_capacity <= 0) { + wifi_util_error_print(WIFI_LIB, "buffer capacity:%d is small\r\n", m_capacity); + return; + } + + if (m_num < m_capacity) { + m_val[m_num] = num; + m_num++; + return; + } + + // remove the top one to add at the end + for (i = 0; i < m_num - 1; i++) { + m_val[i] = m_val[i + 1]; + } + + m_val[i] = num; +} + +void vector_t::push(vector_t v) +{ + unsigned int i; + unsigned int num = v.get_length(); + + for (i = 0; i < num; i++) { + push(v.get_value(i)); + } +} + vector_t::vector_t(unsigned int num, number_t n[]) { unsigned int i; + m_capacity = MAX_LEN; m_num = num; for (i = 0; i < num; i++) { @@ -194,9 +228,10 @@ vector_t::vector_t(unsigned int num) { unsigned int i; + m_capacity = MAX_LEN; m_num = num; - for (i = 0; i < MAX_LEN; i++) { + for (i = 0; i < m_capacity; i++) { m_val[i].m_re = 0; m_val[i].m_im = 0; } @@ -204,6 +239,7 @@ vector_t::vector_t(unsigned int num) vector_t::vector_t() { + m_capacity = MAX_LEN; m_num = 0; } diff --git a/source/utils/quality_mgr/src/linkq.cpp b/source/utils/quality_mgr/src/linkq.cpp index b1e92217f..5ede55c02 100644 --- a/source/utils/quality_mgr/src/linkq.cpp +++ b/source/utils/quality_mgr/src/linkq.cpp @@ -129,7 +129,6 @@ vector_t linkq_t::run_algorithm(linkq_data_t data, if (!enabled) continue; - m_seq[i] = m_seq[i] + number_t((float)data[i], 0); y = m_seq[i].get_max().m_re - m_seq[i].get_min().m_re; if (y > 0.0) { diff --git a/source/utils/wifi_util.c b/source/utils/wifi_util.c index 29e1bfe07..66c0be2b2 100644 --- a/source/utils/wifi_util.c +++ b/source/utils/wifi_util.c @@ -717,7 +717,7 @@ char *get_formatted_time(char *time) return time; } -void wifi_util_print(wifi_log_level_t level, wifi_dbg_type_t module, char *format, ...) +void wifi_util_print(wifi_log_level_t level, wifi_dbg_type_t module, const char *format, ...) { char buff[256] = {0}; va_list list; @@ -842,6 +842,11 @@ void wifi_util_print(wifi_log_level_t level, wifi_dbg_type_t module, char *forma snprintf(module_filename, sizeof(module_filename), "wifiEc"); break; } + case WIFI_SENSING: { + snprintf(filename_dbg_enable, sizeof(filename_dbg_enable), LOG_PATH_PREFIX "wifiSensing"); + snprintf(module_filename, sizeof(module_filename), "wifiSensing"); + break; + } default: return; } diff --git a/source/utils/wifi_util.h b/source/utils/wifi_util.h index 7c5a5f5a0..0f971da6f 100644 --- a/source/utils/wifi_util.h +++ b/source/utils/wifi_util.h @@ -116,6 +116,7 @@ typedef enum { WIFI_MEMWRAPTOOL, WIFI_TCM, WIFI_EC, + WIFI_SENSING, } wifi_dbg_type_t; typedef enum { @@ -125,7 +126,7 @@ typedef enum { WIFI_LOG_LVL_MAX } wifi_log_level_t; -void wifi_util_print(wifi_log_level_t level, wifi_dbg_type_t module, char *format, ...); +void wifi_util_print(wifi_log_level_t level, wifi_dbg_type_t module, const char *format, ...); #define wifi_util_dbg_print(module, format, ...) \ wifi_util_print(WIFI_LOG_LVL_DEBUG, module, format, ##__VA_ARGS__) diff --git a/source/webconfig/Makefile.am b/source/webconfig/Makefile.am index aa70bdbea..883ceb00c 100644 --- a/source/webconfig/Makefile.am +++ b/source/webconfig/Makefile.am @@ -59,6 +59,8 @@ lib_LTLIBRARIES=libwifi_webconfig.la libwifi_webconfig_la_CPPFLAGS = -I$(top_srcdir)/source/apps/em -I/var/tmp/pc-rdkb/include/dbus-1.0 -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/custom -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/include -I$(top_srcdir)/../CcspCommonLibrary/source/debug_api/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/include/linux -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/include -I$(top_srcdir)/../CcspCommonLibrary/source/cosa/package/slap/include -I$(top_srcdir)/../hal/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/http/include -I$(top_srcdir)/../CcspCommonLibrary/source/util_api/ansc/include -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/MessageBusHelper/include -I$(top_srcdir)/../CcspCommonLibrary/source/ccsp/components/common/PoamIrepFolder -I$(top_srcdir)/include/wifi_ssp -I$(top_srcdir)/./include -I$(top_srcdir)/source/core -I$(top_srcdir)/source/stats -I$(top_srcdir)/source/db -I$(top_srcdir)/lib/ovsdb -I$(top_srcdir)/lib/json_util -I$(top_srcdir)/lib/ds -I$(top_srcdir)/lib/common -I$(top_srcdir)/lib/pjs -I$(top_srcdir)/lib/log -I$(top_srcdir)/lib/const -I$(top_srcdir)/lib/schema -I$(top_srcdir)/lib/osp -I$(top_srcdir)/lib/osa -I$(top_srcdir)/lib/psfs -I$(top_srcdir)/lib/qm -I$(top_srcdir)/source/utils -I$(top_srcdir)/source/core/services -I$(top_srcdir)/source/apps -I$(top_srcdir)/source/apps/analytics -I$(top_srcdir)/source/apps/levl -I$(top_srcdir)/source/apps/sta_mgr -I$(top_srcdir)/source/apps/cac -I$(top_srcdir)/source/apps/sm -I$(top_srcdir)/source/apps/csi -I$(top_srcdir)/source/apps/motion -I$(top_srcdir)/source/apps/whix -I$(top_srcdir)/source/apps/harvester -I$(top_srcdir)/source/apps/blaster -I$(top_srcdir)/source/apps/memwraptool -I$(top_srcdir)/source/apps/ocs -I$(top_srcdir)/source/platform/common -I$(top_srcdir)/source/dml/rdkb -I$(top_srcdir)/source/ccsp/ -I$(top_srcdir)/source/apps/linkquality -I$(top_srcdir)/source/utils/math_utils/inc/ -I$(top_srcdir)/source/utils/quality_mgr/inc/ $(CPPFLAGS) +libwifi_webconfig_la_CPPFLAGS += -I$(top_srcdir)/source/apps/wifi_sensing/inc + if ONEWIFI_DBUS_SUPPORT libwifi_webconfig_la_CPPFLAGS += -I$(top_srcdir)/source/platform/dbus -I${PKG_CONFIG_SYSROOT_DIR}/$(includedir)/dbus-1.0 -I${PKG_CONFIG_SYSROOT_DIR}/usr/lib/dbus-1.0/include/ else