dbus-sdr: Add sensor event type to sensor

The sensor event type only returned threshold sensor(0x01).
Implement the functionality of getSensorEventTypeFromPath to support
sensor event type codes: unspecified(0x00), threshold(0x01), and
sensor-specified(0x6f).

Signed-off-by: Scron Chang <Scron.Chang@quantatw.com>
Change-Id: Ic08bce55422b8d436fb032627a0a8f96fead1d61
diff --git a/dbus-sdr/sdrutils.cpp b/dbus-sdr/sdrutils.cpp
index dbb1445..5ea88d8 100644
--- a/dbus-sdr/sdrutils.cpp
+++ b/dbus-sdr/sdrutils.cpp
@@ -193,7 +193,8 @@
     auto findSensor = sensorTypes.find(type.c_str());
     if (findSensor != sensorTypes.end())
     {
-        sensorType = static_cast<uint8_t>(findSensor->second);
+        sensorType =
+            static_cast<uint8_t>(std::get<sensorTypeCodes>(findSensor->second));
     } // else default 0x0 RESERVED
 
     return sensorType;
@@ -221,8 +222,16 @@
 
 uint8_t getSensorEventTypeFromPath(const std::string& path)
 {
-    // TODO: Add support for additional reading types as needed
-    return 0x1; // reading type = threshold
+    uint8_t sensorEventType = 0;
+    std::string type = getSensorTypeStringFromPath(path);
+    auto findSensor = sensorTypes.find(type.c_str());
+    if (findSensor != sensorTypes.end())
+    {
+        sensorEventType = static_cast<uint8_t>(
+            std::get<sensorEventTypeCodes>(findSensor->second));
+    }
+
+    return sensorEventType;
 }
 
 std::string getPathFromSensorNumber(uint16_t sensorNum)
diff --git a/include/dbus-sdr/sdrutils.hpp b/include/dbus-sdr/sdrutils.hpp
index 753c0dd..6b54417 100644
--- a/include/dbus-sdr/sdrutils.hpp
+++ b/include/dbus-sdr/sdrutils.hpp
@@ -239,6 +239,9 @@
     }
 };
 
+static constexpr size_t sensorTypeCodes = 0;
+static constexpr size_t sensorEventTypeCodes = 1;
+
 enum class SensorTypeCodes : uint8_t
 {
     reserved = 0x0,
@@ -249,13 +252,28 @@
     other = 0xB,
 };
 
-const static boost::container::flat_map<const char*, SensorTypeCodes, CmpStr>
-    sensorTypes{{{"temperature", SensorTypeCodes::temperature},
-                 {"voltage", SensorTypeCodes::voltage},
-                 {"current", SensorTypeCodes::current},
-                 {"fan_tach", SensorTypeCodes::fan},
-                 {"fan_pwm", SensorTypeCodes::fan},
-                 {"power", SensorTypeCodes::other}}};
+enum class SensorEventTypeCodes : uint8_t
+{
+    unspecified = 0x00,
+    threshold = 0x01,
+    sensorSpecified = 0x6f
+};
+
+const static boost::container::flat_map<
+    const char*, std::pair<SensorTypeCodes, SensorEventTypeCodes>, CmpStr>
+    sensorTypes{
+        {{"temperature", std::make_pair(SensorTypeCodes::temperature,
+                                        SensorEventTypeCodes::threshold)},
+         {"voltage", std::make_pair(SensorTypeCodes::voltage,
+                                    SensorEventTypeCodes::threshold)},
+         {"current", std::make_pair(SensorTypeCodes::current,
+                                    SensorEventTypeCodes::threshold)},
+         {"fan_tach", std::make_pair(SensorTypeCodes::fan,
+                                     SensorEventTypeCodes::threshold)},
+         {"fan_pwm", std::make_pair(SensorTypeCodes::fan,
+                                    SensorEventTypeCodes::threshold)},
+         {"power", std::make_pair(SensorTypeCodes::other,
+                                  SensorEventTypeCodes::threshold)}}};
 
 std::string getSensorTypeStringFromPath(const std::string& path);