diff --git a/bundle.json b/bundle.json index c07c2ce8f7d3e422683c701ff0aefea5bb329457..2e1a9ed1d2fe93204d0878b1a748ff0bcb182d50 100755 --- a/bundle.json +++ b/bundle.json @@ -32,7 +32,9 @@ "samgr", "eventhandler" ], - "third_party": [] + "third_party": [ + "jsoncpp" + ] }, "build": { "group_type": { diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 06fa4b15f0d025671a7df1efe1b0eda94fa80c7e..44224e0a4b98e171fd5e34919c57281c5ac078b1 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -22,12 +22,16 @@ ohos_shared_library("libsensor") { "$SUBSYSTEM_DIR/utils/common/include", "//third_party/libuv/include", "//third_party/node/src", + "$SUBSYSTEM_DIR/vibration_convert/core/native/include", + "$SUBSYSTEM_DIR/vibration_convert/interfaces/js/include", ] defines = [ "APP_LOG_TAG = \"sensorJs\"", "LOG_DOMAIN = 0xD002700", ] sources = [ + "$SUBSYSTEM_DIR/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp", + "$SUBSYSTEM_DIR/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp", "src/sensor_js.cpp", "src/sensor_napi_error.cpp", "src/sensor_napi_utils.cpp", @@ -39,7 +43,11 @@ ohos_shared_library("libsensor") { cfi_cross_dso = true debug = false } - deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ] + deps = [ + "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", + "${SUBSYSTEM_DIR}/utils/common:libsensor_utils", + "${SUBSYSTEM_DIR}/vibration_convert/core:vibrationconvert_native", + ] external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/frameworks/js/napi/src/sensor_js.cpp b/frameworks/js/napi/src/sensor_js.cpp index 5b55d98e9b2e4dd4eb7acaa6f81eea01d157a395..b6de7e71842366ed5871e70439729f64e554b836 100644 --- a/frameworks/js/napi/src/sensor_js.cpp +++ b/frameworks/js/napi/src/sensor_js.cpp @@ -29,6 +29,7 @@ #include "sensor_napi_error.h" #include "sensor_napi_utils.h" #include "sensor_system_js.h" +#include "vibrator_convert_js.h" namespace OHOS { namespace Sensors { @@ -1265,8 +1266,24 @@ static napi_value CreateEnumSensorAccuracy(napi_env env, napi_value exports) return exports; } +static napi_value CreateVibratorConvertClass(napi_env env, napi_value exports) +{ + napi_property_descriptor clzDes[] = { + DECLARE_NAPI_FUNCTION("getAudioAttribute", VibratorConvert::GetAudioAttribute), + DECLARE_NAPI_FUNCTION("audioToHaptic", VibratorConvert::ConvertAudioToHaptic), + DECLARE_NAPI_FUNCTION("getAudioData", VibratorConvert::GetAudioData), + }; + napi_value cons { nullptr }; + CHKCP((napi_define_class(env, "VibratorConvert", NAPI_AUTO_LENGTH, VibratorConvert::ConvertAudioToHapticConstructor, + nullptr, sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons) == napi_ok), "napi_define_class fail"); + CHKCP((napi_set_named_property(env, exports, "VibratorConvert", cons) == napi_ok), "napi_set_named_property fail"); + return exports; +} + static napi_value Init(napi_env env, napi_value exports) { + napi_value instance = VibratorConvert::CreateInstance(env); + CHKPP(instance); napi_property_descriptor desc[] = { DECLARE_NAPI_FUNCTION("on", On), DECLARE_NAPI_FUNCTION("once", Once), @@ -1319,6 +1336,7 @@ static napi_value Init(napi_env env, napi_value exports) }; CHKNRP(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc), "napi_define_properties"); + CHKCP(CreateVibratorConvertClass(env, exports), "Create vibrator convert class fail"); CHKCP(CreateEnumSensorType(env, exports), "Create enum sensor type fail"); CHKCP(CreateEnumSensorId(env, exports), "Create enum sensor id fail"); CHKCP(CreateEnumSensorAccuracy(env, exports), "Create enum sensor accuracy fail"); diff --git a/utils/common/BUILD.gn b/utils/common/BUILD.gn index 2e67dc0a84a319ddffc2fe37fa31895255c83c67..4bef6b3db74a0646073e3f330770cf77ff5cfbd1 100644 --- a/utils/common/BUILD.gn +++ b/utils/common/BUILD.gn @@ -14,6 +14,10 @@ import("//build/ohos.gni") import("./../../sensor.gni") +config("libsensor_utils_public_config") { + include_dirs = [ "include" ] +} + ohos_shared_library("libsensor_utils") { sources = [ "src/active_info.cpp", @@ -38,6 +42,8 @@ ohos_shared_library("libsensor_utils") { "$SUBSYSTEM_DIR/utils/common/include", ] + public_configs = [ ":libsensor_utils_public_config" ] + external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libprivacy_sdk", diff --git a/vibration_convert/core/BUILD.gn b/vibration_convert/core/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..27578faeeb8fc3725115fab88f2db910d77c8e7e --- /dev/null +++ b/vibration_convert/core/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2023 Huawei Device 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. + +import("//base/sensors/sensor/sensor.gni") +import("//build/ohos.gni") + +############################################## +ohos_shared_library("vibrationconvert_native") { + sources = [ + "algorithm/conversion/src/conversion_fft.cpp", + "algorithm/conversion/src/conversion_filter.cpp", + "algorithm/conversion/src/conversion_mfcc.cpp", + "algorithm/conversion/src/fft.cpp", + "algorithm/frequency_estimation/src/frequency_estimation.cpp", + "algorithm/intensity_processor/src/intensity_processor.cpp", + "algorithm/onset/src/onset.cpp", + "algorithm/peak_finder/src/peak_finder.cpp", + "native/src/audio_parsing.cpp", + "native/src/generate_vibration_json_file.cpp", + "native/src/vibration_convert_core.cpp", + "utils/src/audio_utils.cpp", + "utils/src/utils.cpp", + ] + + include_dirs = [ + "native/include", + "algorithm/conversion/include", + "algorithm/frequency_estimation/include", + "algorithm/intensity_processor/include", + "algorithm/onset/include", + "algorithm/peak_finder/include", + "utils/include", + "//third_party/jsoncpp/include", + "$SUBSYSTEM_DIR/vibration_convert/interfaces/native/include", + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/utils/include", + ] + deps = [ + "$SUBSYSTEM_DIR/utils/common:libsensor_utils", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + part_name = "sensor" + subsystem_name = "sensors" +} diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp index 92939717da033cac9d159894c19f7b016554390c..c931227b414fd90013db70fea2b750c468e20c43 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp @@ -15,8 +15,8 @@ #include "conversion_fft.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" namespace OHOS { diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp index 72691f40bcaa8245b5480bf4225b5bfc92b27e78..a4ed864f85eb233b29eebcdbc3b51b9890e431aa 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp @@ -16,8 +16,8 @@ #include "conversion_mfcc.h" #include "audio_utils.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" namespace OHOS { diff --git a/vibration_convert/core/algorithm/conversion/src/fft.cpp b/vibration_convert/core/algorithm/conversion/src/fft.cpp index f57c66098595c1a1333e5ff7598ecadd184536db..7b5fed0c3f5fa63ae841fa984a7f386c4c275809 100644 --- a/vibration_convert/core/algorithm/conversion/src/fft.cpp +++ b/vibration_convert/core/algorithm/conversion/src/fft.cpp @@ -21,8 +21,8 @@ #include #include +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp b/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp index e2020d0033b3865cf38a8191f8834df45e8dff1b..82830a859771b8c855c4abaa219e0cf6b726ebae 100644 --- a/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp +++ b/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp @@ -19,8 +19,8 @@ #include #include +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp b/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp index 406f825db1c0d46d45a3f28d2997f9375de97b38..982cf90cf794b6b8ecce8375938fe2585e550635 100644 --- a/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp +++ b/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp @@ -16,8 +16,8 @@ #include "intensity_processor.h" #include "audio_utils.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/algorithm/onset/src/onset.cpp b/vibration_convert/core/algorithm/onset/src/onset.cpp index 5f0d9a3a26b0f5324aefbbe6448fc41cb1f38665..16ab2403d3a943062f2c4bff730158341df976cc 100644 --- a/vibration_convert/core/algorithm/onset/src/onset.cpp +++ b/vibration_convert/core/algorithm/onset/src/onset.cpp @@ -21,8 +21,8 @@ #include "conversion_fft.h" #include "conversion_mfcc.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" namespace OHOS { diff --git a/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp b/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp index b9e0023a26b9cc42308bc0dc389692c2c6cae2b4..72869210dc9af92e33822701d9387f0dab5db4f9 100644 --- a/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp +++ b/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp @@ -19,8 +19,8 @@ #include #include +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" namespace OHOS { diff --git a/vibration_convert/core/native/src/audio_parsing.cpp b/vibration_convert/core/native/src/audio_parsing.cpp index 1dc57ff03a1e98a269ba39e587594a98239e8015..3717ffaa810ce11aec6e22e51ca570646c807708 100644 --- a/vibration_convert/core/native/src/audio_parsing.cpp +++ b/vibration_convert/core/native/src/audio_parsing.cpp @@ -25,15 +25,15 @@ #include #include "generate_vibration_json_file.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "vibration_convert_core.h" #include "vibration_convert_type.h" namespace OHOS { namespace Sensors { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, Sensors::SENSOR_LOG_DOMAIN, "AudioParsing"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, Sensors::SENSOR_LOG_DOMAIN, "AudioParsing" }; constexpr int32_t MIN_SAMPLE_COUNT = 4096; constexpr uint32_t AUDIO_DATA_CONVERSION_FACTOR = INT32_MAX; constexpr int32_t AUDIO_DATA_MAX_NUMBER = 100000; diff --git a/vibration_convert/core/native/src/generate_vibration_json_file.cpp b/vibration_convert/core/native/src/generate_vibration_json_file.cpp index 6135a0086f522aba1e3b0618281a0defc9d95e54..40f82ca283c1cc17613ec953bec4ad35d58c47d1 100644 --- a/vibration_convert/core/native/src/generate_vibration_json_file.cpp +++ b/vibration_convert/core/native/src/generate_vibration_json_file.cpp @@ -21,8 +21,8 @@ #include "json/json.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/native/src/vibration_convert_core.cpp b/vibration_convert/core/native/src/vibration_convert_core.cpp index dc08e3cfaf120a838cc2247efe529a7b856e90e6..a229bdf03ecb9ddea0735e66d2a41ef295480374 100644 --- a/vibration_convert/core/native/src/vibration_convert_core.cpp +++ b/vibration_convert/core/native/src/vibration_convert_core.cpp @@ -17,8 +17,8 @@ #include #include "generate_vibration_json_file.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "vibration_convert_core.h" namespace OHOS { diff --git a/vibration_convert/core/native/test/BUILD.gn b/vibration_convert/core/native/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..eb5770ade890b0cda60fa6e9381bba1920477b23 --- /dev/null +++ b/vibration_convert/core/native/test/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2023 Huawei Device 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. + +import("//base/sensors/sensor/sensor.gni") +import("//build/test.gni") + +module_output_path = "sensors/sensor/vibration_convert/interfaces" + +###########################GenerateJsonFileTest########################### +ohos_unittest("GenerateJsonFileTest") { + module_out_path = module_output_path + + sources = [ "unittest/generate_json_test.cpp" ] + + include_dirs = [ + "$SUBSYSTEM_DIR/utils/include", + "$SUBSYSTEM_DIR/vibration_convert/interfaces/native/include", + "$SUBSYSTEM_DIR/vibration_convert/core/native/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/conversion/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/frequency_estimation/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/intensity_processor/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/onset/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/peak_finder/include", + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/vibration_convert/core/utils/include", + ] + + deps = [ + "$SUBSYSTEM_DIR/utils:sensor_utils_target", + "$SUBSYSTEM_DIR/utils/common:libsensor_utils", + "$SUBSYSTEM_DIR/vibration_convert/core:vibrationconvert_native", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +###########################end########################### +group("unittest") { + testonly = true + deps = [ ":GenerateJsonFileTest" ] +} diff --git a/vibration_convert/core/native/test/unittest/generate_json_test.cpp b/vibration_convert/core/native/test/unittest/generate_json_test.cpp index 88735acb2ef940486d05c8e58996562146f8b923..cc74eec92793720b590a9f9076acbdfa5b184af3 100644 --- a/vibration_convert/core/native/test/unittest/generate_json_test.cpp +++ b/vibration_convert/core/native/test/unittest/generate_json_test.cpp @@ -20,8 +20,8 @@ #include "audio_utils.h" #include "data.h" #include "generate_vibration_json_file.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" #include "vibration_convert_core.h" #include "vibration_convert_type.h" diff --git a/vibration_convert/core/utils/include/audio_utils.h b/vibration_convert/core/utils/include/audio_utils.h index 57e3f681c4ad8e15530cf86bf7d387f3edc39e25..9f54425c39ee50725291f9b1c38e85ceddb6f6f7 100644 --- a/vibration_convert/core/utils/include/audio_utils.h +++ b/vibration_convert/core/utils/include/audio_utils.h @@ -104,4 +104,4 @@ public: }; } // namespace Sensors } // namespace OHOS -#endif \ No newline at end of file +#endif // AUDIO_UTILS_H \ No newline at end of file diff --git a/vibration_convert/core/utils/src/audio_utils.cpp b/vibration_convert/core/utils/src/audio_utils.cpp index 428c816af6fb3b5af866cd736b3d74eecb92cbb0..dc071b40359c6ab95639caf226e3109b8b3e1cc3 100644 --- a/vibration_convert/core/utils/src/audio_utils.cpp +++ b/vibration_convert/core/utils/src/audio_utils.cpp @@ -14,7 +14,7 @@ */ #include "audio_utils.h" -#include "sensors_errors.h" +#include "sensor_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/utils/src/utils.cpp b/vibration_convert/core/utils/src/utils.cpp index 275218cc54804fd5c69a7706049b523c685fff72..36d3f39e09a59eb1131394e7ede30f151238a978 100644 --- a/vibration_convert/core/utils/src/utils.cpp +++ b/vibration_convert/core/utils/src/utils.cpp @@ -25,8 +25,8 @@ #include +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h b/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h index 81129bc81b068cbef4dadc960c35f605323304f1..d5eb94c3d1bef52ff5666be48f778ff111ac022a 100644 --- a/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h +++ b/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h @@ -26,7 +26,7 @@ #include "napi/native_node_api.h" #include "refbase.h" -#include "sensors_errors.h" +#include "sensor_errors.h" #include "vibration_convert_type.h" namespace OHOS {