blob: cdaa28ba4b89519549149ea488660880c22f24b0 [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>
James Feist38fb5982020-05-28 10:09:54 -070018
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070019#include <iostream>
20
21static constexpr double maxReading = 127;
22static constexpr double minReading = 0;
23
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070024NVMeSensor::NVMeSensor(sdbusplus::asio::object_server& objectServer,
James Feist7d7579f2020-09-02 14:13:08 -070025 boost::asio::io_service&,
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070026 std::shared_ptr<sdbusplus::asio::connection>& conn,
27 const std::string& sensorName,
Jeff Lin7b7a9de2021-02-22 11:16:27 +080028 std::vector<thresholds::Threshold>&& thresholdsIn,
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070029 const std::string& sensorConfiguration,
30 const int busNumber) :
Zhikui Renda98f092021-11-01 09:41:08 -070031 Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration,
Andrew Jeffery0c23fc32021-12-08 16:48:30 +103032 NVMeSensor::CONFIG_TYPE, false, false, maxReading, minReading, conn,
33 PowerState::on),
Andrew Jeffery18fffd32021-06-09 16:56:53 +093034 bus(busNumber), objServer(objectServer)
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070035{
36 sensorInterface = objectServer.add_interface(
37 "/xyz/openbmc_project/sensors/temperature/" + name,
38 "xyz.openbmc_project.Sensor.Value");
39
40 if (thresholds::hasWarningInterface(thresholds))
41 {
42 thresholdInterfaceWarning = objectServer.add_interface(
43 "/xyz/openbmc_project/sensors/temperature/" + name,
44 "xyz.openbmc_project.Sensor.Threshold.Warning");
45 }
46 if (thresholds::hasCriticalInterface(thresholds))
47 {
48 thresholdInterfaceCritical = objectServer.add_interface(
49 "/xyz/openbmc_project/sensors/temperature/" + name,
50 "xyz.openbmc_project.Sensor.Threshold.Critical");
51 }
52 association = objectServer.add_interface(
53 "/xyz/openbmc_project/sensors/temperature/" + name,
54 association::interface);
55
Zev Weiss6b6891c2021-04-22 02:46:21 -050056 setInitialProperties(conn, sensor_paths::unitDegreesC);
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070057}
58
59NVMeSensor::~NVMeSensor()
60{
61 // close the input dev to cancel async operations
62 objServer.remove_interface(thresholdInterfaceWarning);
63 objServer.remove_interface(thresholdInterfaceCritical);
64 objServer.remove_interface(sensorInterface);
65 objServer.remove_interface(association);
66}
67
68void NVMeSensor::checkThresholds(void)
69{
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070070 thresholds::checkThresholds(this);
71}