blob: 7fa966d1fc2eb38c577e6f769af7141066d5c4e7 [file] [log] [blame]
Nikhil Potadeb669b6b2019-03-13 10:52:21 -07001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
Ed Tanous8a57ec02020-10-09 12:46:52 -070017#include <NVMeSensor.hpp>
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070018#include <boost/algorithm/string/replace.hpp>
James Feist38fb5982020-05-28 10:09:54 -070019
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070020#include <iostream>
21
22static constexpr double maxReading = 127;
23static constexpr double minReading = 0;
24
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070025NVMeSensor::NVMeSensor(sdbusplus::asio::object_server& objectServer,
James Feist7d7579f2020-09-02 14:13:08 -070026 boost::asio::io_service&,
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070027 std::shared_ptr<sdbusplus::asio::connection>& conn,
28 const std::string& sensorName,
Jeff Lin7b7a9de2021-02-22 11:16:27 +080029 std::vector<thresholds::Threshold>&& thresholdsIn,
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070030 const std::string& sensorConfiguration,
31 const int busNumber) :
Jeff Lin7b7a9de2021-02-22 11:16:27 +080032 Sensor(boost::replace_all_copy(sensorName, " ", "_"),
33 std::move(thresholdsIn), sensorConfiguration,
Bruce Lee1263c3d2021-06-04 15:16:33 +080034 "xyz.openbmc_project.Configuration.NVMe", false, maxReading,
35 minReading, conn, PowerState::on),
Andrew Jeffery18fffd32021-06-09 16:56:53 +093036 bus(busNumber), objServer(objectServer)
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070037{
38 sensorInterface = objectServer.add_interface(
39 "/xyz/openbmc_project/sensors/temperature/" + name,
40 "xyz.openbmc_project.Sensor.Value");
41
42 if (thresholds::hasWarningInterface(thresholds))
43 {
44 thresholdInterfaceWarning = objectServer.add_interface(
45 "/xyz/openbmc_project/sensors/temperature/" + name,
46 "xyz.openbmc_project.Sensor.Threshold.Warning");
47 }
48 if (thresholds::hasCriticalInterface(thresholds))
49 {
50 thresholdInterfaceCritical = objectServer.add_interface(
51 "/xyz/openbmc_project/sensors/temperature/" + name,
52 "xyz.openbmc_project.Sensor.Threshold.Critical");
53 }
54 association = objectServer.add_interface(
55 "/xyz/openbmc_project/sensors/temperature/" + name,
56 association::interface);
57
Zev Weiss6b6891c2021-04-22 02:46:21 -050058 setInitialProperties(conn, sensor_paths::unitDegreesC);
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070059}
60
61NVMeSensor::~NVMeSensor()
62{
63 // close the input dev to cancel async operations
64 objServer.remove_interface(thresholdInterfaceWarning);
65 objServer.remove_interface(thresholdInterfaceCritical);
66 objServer.remove_interface(sensorInterface);
67 objServer.remove_interface(association);
68}
69
70void NVMeSensor::checkThresholds(void)
71{
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070072 thresholds::checkThresholds(this);
73}