Add support for Previous State in Sensor events

Previously, the sensor events generated by the PLDM stack only
included the current state of the sensor without any reference
to the previous state.

This commit introduces a new feature to address this limitation
by caching the previous states of all sensors.

The enhancement ensures that platform event messages(sensor events)
now contain the correct previous state information alongside the
current state.

Behavior Model:
1. Upon the initial occurrence of a sensor event, both the current
   state and the previous state are identical, adhering to the
   specification.
2. Subsequently, when the PLDM stack sends out sensor events, it
   retrieves the previous state from its cache and populates it
   accordingly.

Testing:
1. Example: Change the value of a sensor, such as dimm8 identify, to
   false using busctl.
   Tx: 81 02 0a 01 00 00 4d 00 01 00 [ 01 01 ]
- Note: Initially, both the event state and the previous state are 01.

2. Change the value of dimm8 identify to true.
   Tx: 81 02 0a 01 00 00 4d 00 01 00 [ 02 01 ]
- Result: Event state: 02, Previous state: 01.

3. Change the value of dimm8 identify back to false.
   Tx: 81 02 0a 01 00 00 4d 00 01 00 [ 01 02 ]
- Result: Event state: 01, Previous state: 02.

4. Similar results can be obtained using the getStateSensorReadings
   command for the same sensor at respective times.

Change-Id: Ic93a55e61fd5128cecc698b3555a6639876882ed
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/host-bmc/dbus_to_event_handler.cpp b/host-bmc/dbus_to_event_handler.cpp
index 55a3b9f..4b11654 100644
--- a/host-bmc/dbus_to_event_handler.cpp
+++ b/host-bmc/dbus_to_event_handler.cpp
@@ -109,10 +109,11 @@
             pldm::utils::DBusHandler::getBus(),
             propertiesChanged(dbusMapping.objectPath.c_str(),
                               dbusMapping.interface.c_str()),
-            [this, sensorEventDataVec, dbusValueMapping,
-             dbusMapping](auto& msg) mutable {
+            [this, sensorEventDataVec, dbusValueMapping, dbusMapping, sensorId,
+             offset](auto& msg) mutable {
             DbusChangedProps props{};
             std::string intf;
+            uint8_t previousState = PLDM_SENSOR_UNKNOWN;
             msg.read(intf, props);
             if (!props.contains(dbusMapping.propertyName))
             {
@@ -150,8 +151,18 @@
                         reinterpret_cast<struct pldm_sensor_event_data*>(
                             sensorEventDataVec.data());
                     eventData->event_class[1] = itr.first;
-                    eventData->event_class[2] = itr.first;
+                    if (sensorCacheMap.contains(sensorId) &&
+                        sensorCacheMap[sensorId][offset] != PLDM_SENSOR_UNKNOWN)
+                    {
+                        previousState = sensorCacheMap[sensorId][offset];
+                    }
+                    else
+                    {
+                        previousState = itr.first;
+                    }
+                    eventData->event_class[2] = previousState;
                     this->sendEventMsg(PLDM_SENSOR_EVENT, sensorEventDataVec);
+                    updateSensorCacheMaps(sensorId, offset, previousState);
                     break;
                 }
             }