1### Virtual sensors 2 3Author: 4 Vijay Khemka <vijaykhemka@fb.com>; <vijay!> 5 6Primary assignee: 7 Vijay Khemka <vijaykhemka@fb.com>; <vijay!> 8 9Created: 10 2020-05-13 11 12## Problem Description 13There are some sensors in the system whose values are derived from actual 14sensor data and some other factor like fan speed for temperature 15sensors, some complex and non standard scale factors or some other algorithmic 16calculations. Some of Virtual sensor examples are: 17 181. Airflow: Function of Fan RPM reported in units of cubic-feet per second. 192. Voltage delta between two ADC inputs. When the actual diff is what which 20 should not cross a threshold. 213. Power consumption when we have Energy/time. 22 23This design will allow to generate a new virtual sensors which are defined to 24be specific manipulation/function of existing sensors. 25 26## Background and References 27None. 28 29## Requirements 30This should implement a new virtual sensor for every given sensor and update 31them as per changes in existing sensors. 32This implementation should provide 33- a daemon to create and monitor each sensor defined in config file and 34 update them based on value change in each given sensor. 35- Every virtual sensor will be waiting for event for change in dbus value of 36 each sensor parameter and will update this sensor. 37- Sensor parameter can be any sensor dbus path and it also supports 38 chaining of virtual sensors. 39- a dbus interface like other sensors to allow other services to access its 40 data 41- capability to read parameter details from config file 42- capability to read a algorithm string from config file and use the same 43 algorithm in calculating value for new virtual sensor 44 45## Proposed Design 46Create a D-bus service "xyz.openbmc_project.VirtualSensor" with object paths 47for each sensor: "/xyz/openbmc_project/sensor/temperature/sensor_name" 48 49There is a JSON configuration file for name, old path and algorithm. 50For example, 51 52```json 53 { 54 "Desc" : 55 { 56 "Name" : "Virtual_Inlet_Temp", 57 "SensorType" : "temperature" 58 }, 59 "Params": 60 { 61 "ConstParam" : 62 [ 63 { 64 "ParamName" : "P1", 65 "Value" : 1.1 66 } 67 ], 68 "DbusParam" : 69 [ 70 { 71 "ParamName" : "P2", 72 "Desc" : 73 { 74 "Name" : "MB_INLET_TEMP", 75 "SensorType" : "temperature" 76 } 77 }, 78 { 79 "ParamName" : "P3", 80 "Desc" : 81 { 82 "Name" : "MB_FAN0_TACH", 83 "SensorType" : "fan_tach" 84 } 85 } 86 ] 87 }, 88 "Expression": "P1 + P2 + 5 - P3 * 0.1", 89 "Thresholds": 90 { 91 "CriticalHigh": 90, 92 "CriticalLow": 20, 93 "WarningHigh": 70, 94 "WarningLow": 30 95 } 96 } 97 98Desc: It defines name and unit of a sensor. Main Desc object defines 99 details about new virtual sensor and inside DbusParam object, 100 it defines details about existing dbus sensors. 101Name: Name of virtual sensor 102SensorType: Unit type of sensors and supported 103Expression: An algorithm to be used to calculate sensor value 104Params: There are currently 2 types of parameter supported ConstParam 105 and DbusParam. Every pamas should have a name to be reffered 106 in expression 107ConstParam: This is a parameter which has a constant value defined here 108DbusParam: This is an existing/virtual sensor which is listed in dbus and 109 it's value can be read from dbus path 110Thresholds: It has critical and warning high/low value to monitor sensor 111 value and used as per sensor interface defined in 112 phosphor-dbus-interfaces. 113 114``` 115## Alternatives Considered 116None 117 118## Impacts 119This application is monitoring existing sensors whenever they change values 120then only it will update this sensors so impact should be very minimal. 121 122## Testing 123Testing can be done by monitoring data read from dbus interface over a period 124of time and also can see these data if it changes by comparing with given 125sensors. 126