1 /* 2 * Copyright (c) 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 FAN_FAULT_DETECT_H 17 #define FAN_FAULT_DETECT_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS { 24 namespace PowerMgr { 25 26 enum { 27 FAN_FAULT_OK = 0, 28 FAN_FAULT_TOO_SLOW, 29 FAN_FAULT_TOO_FAST, 30 }; 31 32 using FanSensorInfo = std::map<std::string, int32_t>; 33 using FanFaultInfoMap = std::map<int32_t, FanSensorInfo>; 34 35 class FanFaultDetect { 36 public: 37 FanFaultDetect() = default; 38 ~FanFaultDetect() = default; 39 40 void OnFanSensorInfoChanged(const FanSensorInfo& report); 41 void SetFaultInfoMap(FanFaultInfoMap& map); 42 bool HasFanConfig(); 43 44 private: 45 void CheckFanFault(const FanSensorInfo& report); 46 void CheckFanTooSlow(const FanSensorInfo& report, const FanSensorInfo& config); 47 void CheckFanTooFast(const FanSensorInfo& report, const FanSensorInfo& config); 48 bool CheckFanSensorInfo(const FanSensorInfo& report, const FanSensorInfo& config); 49 int32_t GetSensorValue(const FanSensorInfo& map, const std::string& name); 50 std::string FormatReportInfo(const FanSensorInfo& report, const FanSensorInfo& config); 51 52 FanFaultInfoMap fanFaultInfoMap_; 53 }; 54 } // namespace PowerMgr 55 } // namespace OHOS 56 #endif // FAN_FAULT_DETECT_H 57