meta-bletchley: phosphor-virtual-sensor: add virtual sensors

- Virtual_CFM_Sensor
Airflow which calculated from inlet fan tach

- Virtual_Inlet_Temp
Apply calibration equation to adjust inlet temperature

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: Ia4021871a64bec34a3f309b3305bf1c9e6886753
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/images/fb-bletchley-phosphor-image.inc b/meta-facebook/meta-bletchley/recipes-phosphor/images/fb-bletchley-phosphor-image.inc
index 6636f50..396e557 100644
--- a/meta-facebook/meta-bletchley/recipes-phosphor/images/fb-bletchley-phosphor-image.inc
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/images/fb-bletchley-phosphor-image.inc
@@ -2,4 +2,5 @@
     phosphor-nvme \
     plat-svc \
     motor-ctrl \
+    phosphor-virtual-sensor \
 "
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-virtual-sensor/virtual_sensor_config.json b/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-virtual-sensor/virtual_sensor_config.json
new file mode 100644
index 0000000..c1b5e16
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-virtual-sensor/virtual_sensor_config.json
@@ -0,0 +1,106 @@
+[
+    {
+        "Desc":
+        {
+            "Name": "Virtual_CFM_Sensor",
+            "SensorType": "airflow"
+        },
+        "Params":
+        {
+            "DbusParam":
+            [
+                {
+                    "ParamName": "fan0",
+                    "Desc":
+                    {
+                        "Name": "FAN0_TACH_IL",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fan1",
+                    "Desc":
+                    {
+                        "Name": "FAN1_TACH_IL",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fan2",
+                    "Desc":
+                    {
+                        "Name": "FAN2_TACH_IL",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fan3",
+                    "Desc":
+                    {
+                        "Name": "FAN3_TACH_IL",
+                        "SensorType": "fan_tach"
+                    }
+                }
+            ]
+        },
+        "Expression": "max(0, (avg(fan0, fan1, fan2, fan3) * 0.0478) - 11.467)"
+    },
+    {
+        "Desc":
+        {
+            "Name": "Virtual_Inlet_Temp",
+            "SensorType": "temperature"
+        },
+        "Threshold":{
+            "CriticalHigh": 40,
+            "CriticalLow": 0
+        },
+        "Params":
+        {
+            "DbusParam":
+            [
+                {
+                    "ParamName": "inlet_temp",
+                    "Desc":
+                    {
+                        "Name": "FRONT_PANEL_TEMP",
+                        "SensorType": "temperature"
+                    }
+                },
+                {
+                    "ParamName": "fan0",
+                    "Desc":
+                    {
+                        "Name": "FAN0_TACH_IL",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fan1",
+                    "Desc":
+                    {
+                        "Name": "FAN1_TACH_IL",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fan2",
+                    "Desc":
+                    {
+                        "Name": "FAN2_TACH_IL",
+                        "SensorType": "fan_tach"
+                    }
+                },
+                {
+                    "ParamName": "fan3",
+                    "Desc":
+                    {
+                        "Name": "FAN3_TACH_IL",
+                        "SensorType": "fan_tach"
+                    }
+                }
+            ]
+        },
+        "Expression": "if(avg(fan0, fan1, fan2, fan3) > 0, inlet_temp - (((avg(fan0, fan1, fan2, fan3)^2) * (5e-8)) - (avg(fan0, fan1, fan2, fan3) * (6e-4)) + 1.5841), inlet_temp)"
+    }
+]
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-virtual-sensor_%.bbappend b/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-virtual-sensor_%.bbappend
new file mode 100644
index 0000000..9c85366
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-virtual-sensor_%.bbappend
@@ -0,0 +1,8 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+SRC_URI += " \
+    file://virtual_sensor_config.json \
+"
+
+do_install:append() {
+    install -m 0644 -D ${WORKDIR}/virtual_sensor_config.json ${D}${datadir}/phosphor-virtual-sensor/
+}