1 /* 2 * Copyright (c) 2021 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 THERMAL_CONFIG_SENSOR_CLUSTER_H 17 #define THERMAL_CONFIG_SENSOR_CLUSTER_H 18 19 #include <string> 20 #include <map> 21 #include <vector> 22 #include <memory> 23 24 namespace OHOS { 25 namespace PowerMgr { 26 struct LevelItem { 27 int32_t threshold; 28 int32_t thresholdClr; 29 double tempRiseRate; 30 uint32_t level; 31 }; 32 33 struct AuxLevelItem { 34 int32_t lowerTemp; 35 int32_t upperTemp; 36 int32_t level; 37 }; 38 39 using TypeTempMap = std::map<std::string, int32_t>; 40 using SensorInfoMap = std::map<std::string, std::vector<LevelItem>>; 41 using AuxSensorInfoMap = std::map<std::string, std::vector<AuxLevelItem>>; 42 43 class ThermalConfigSensorCluster { 44 public: 45 bool CheckStandard(); 46 void UpdateThermalLevel(const TypeTempMap& typeTempInfo); 47 48 uint32_t GetCurrentLevel(); 49 void SetSensorLevelInfo(SensorInfoMap& sensorInfolist); 50 void SetAuxSensorLevelInfo(AuxSensorInfoMap& auxSensorInfolist); 51 void SetDescFlag(bool descflag); 52 void SetAuxFlag(bool auxflag); 53 void SetRateFlag(bool rateFlag); AddState(std::string & state,std::string & val)54 void AddState(std::string& state, std::string& val) 55 { 56 stateMap_.emplace(state, val); 57 } 58 59 private: 60 bool CheckState(); 61 void CalculateSensorLevel(const TypeTempMap& typeTempInfo, std::vector<uint32_t>& levelList); 62 void AscendLevelToThreshold(std::vector<LevelItem>& levItems, uint32_t& level, uint32_t end, int32_t curTemp); 63 void DescendLevelToThresholdClr(std::vector<LevelItem>& levItems, uint32_t& level, int32_t curTemp); 64 void DescendLevelToThreshold(std::vector<LevelItem>& levItems, uint32_t& level, int32_t curTemp); 65 void AscendLevelToThresholdClr(std::vector<LevelItem>& levItems, uint32_t& level, uint32_t end, int32_t curTemp); 66 void LevelUpwardsSearch(std::vector<LevelItem>& levItems, uint32_t& level, uint32_t end, int32_t curTemp); 67 void LevelDownwardsSearch(std::vector<LevelItem>& levItems, uint32_t& level, int32_t curTemp); 68 void LevelDownwardsSearchWithThreshold(std::vector<LevelItem>& levItems, uint32_t& level, int32_t curTemp); 69 void LevelUpwardsSearchWithThreshold(std::vector<LevelItem>& levItems, uint32_t& level, 70 uint32_t end, int32_t curTemp); 71 void AscJudgment(std::vector<LevelItem>& levItems, int32_t curTemp, uint32_t& level); 72 void DescJudgment(std::vector<LevelItem>& levItems, int32_t curTemp, uint32_t& level); 73 void CheckExtraCondition(const TypeTempMap& typeTempInfo, uint32_t& level); 74 bool IsTempRateTrigger(uint32_t& level); 75 bool IsAuxSensorTrigger(const TypeTempMap& typeTempInfo, uint32_t& level); 76 77 bool descFlag_ {false}; 78 bool auxFlag_ {false}; 79 bool rateFlag_ {false}; 80 uint32_t latestLevel_ {0}; 81 SensorInfoMap sensorInfolist_; 82 AuxSensorInfoMap auxSensorInfolist_; 83 std::map<std::string, std::string> stateMap_; 84 }; 85 86 using SensorClusterPtr = std::shared_ptr<ThermalConfigSensorCluster>; 87 using SensorClusterMap = std::map<std::string, SensorClusterPtr>; 88 } // namespace PowerMgr 89 } // namesapce OHOS 90 #endif // THERMAL_CONFIG_SENSOR_CLUSTER_H 91