1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ALGO_BASE_H 17 #define ALGO_BASE_H 18 19 #include <cmath> 20 #include <cstdio> 21 #include <iostream> 22 23 #include "devicestatus_common.h" 24 #include "devicestatus_data_define.h" 25 #include "devicestatus_msdp_interface.h" 26 #include "sensor_data_callback.h" 27 #include "stationary_data.h" 28 29 namespace OHOS { 30 namespace Msdp { 31 namespace DeviceStatus { 32 class AlgoBase { 33 public: AlgoBase()34 AlgoBase() {}; 35 virtual ~AlgoBase() = default; 36 37 virtual bool Init(Type type) = 0; 38 void Unsubscribe(int32_t sensorTypeId); 39 void RegisterCallback(const std::shared_ptr<IMsdp::MsdpAlgoCallback> callback); 40 41 protected: 42 enum { 43 UNKNOWN = -1, 44 STILL, 45 UNSTILL, 46 HORIZONTAL, 47 NON_HORIZONTAL, 48 VERTICAL, 49 NON_VERTICAL 50 }; 51 struct { 52 float x { 0.0 }; 53 float y { 0.0 }; 54 float z { 0.0 }; 55 double resultantAcc { 0.0 }; 56 double pitch { 0.0 }; 57 double roll { 0.0 }; 58 } algoPara_ {}; 59 int32_t state_ { UNKNOWN }; 60 int32_t counter_ { COUNTER_THRESHOLD }; 61 Data reportInfo_ { TYPE_INVALID, 62 VALUE_INVALID, 63 STATUS_INVALID, 64 ACTION_INVALID, 65 0.0 }; 66 67 virtual bool StartAlgorithm(int32_t sensorTypeId, AccelData* sensorData) = 0; 68 bool SetData(int32_t sensorTypeId, AccelData* sensorData); 69 virtual void ExecuteOperation() = 0; 70 void UpdateStateAndReport(OnChangedValue value, int32_t state, Type type); 71 72 SensorCallback algoCallback_ { nullptr }; 73 std::shared_ptr<IMsdp::MsdpAlgoCallback> callback_ { nullptr }; 74 }; 75 } // namespace DeviceStatus 76 } // namespace Msdp 77 } // namespace OHOS 78 #endif // ALGO_BASE_H 79