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