Add compact sensor data record and fix sdr count

Description
- Commit added compact sensor data record structure
- Total sdr count from get sdr list and get device sdr
info mismatch
- Fixed by added condtion to check fru data record,
type12 record and sdrcount increamented
- Also added condition for compact sensor data record count
- get device sdr info command, keep reading record in while. As
"getSensorDataRecord" handler function adds record in end, everytime
record vector keeps growing. So get device info command keep reading the
same record and end up with wrong sdr count
- Changed code to add record in begin everytime

Tested
Successfully built and tested in reference platform. SDR count from
both get sdr list and get device sdr info matches.

$ ipmitool raw 0x04 0x20 0x01
e6 81 7d 01 00 00
$ ipmitool sdr elist all | wc -l
230

$  ipmitool raw 0x04 0x20 0x00
c8 81 7d 01 00 00
$ ipmitool sensor list | wc -l
200

Change-Id: Ifd76a53485de8d92af955e2bb4d4268b3e891110
Signed-off-by: selvaganapathi <selvaganapathim@ami.com>
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index 6b3dc8c..c57a1a2 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -1968,6 +1968,7 @@
             ->getIpmiEntityRecords();
     size_t entityCount = entityRecords.size();
 
+    recordData.clear();
     size_t lastRecord = getNumberOfSensors() + fruCount +
                         ipmi::storage::type12Count + entityCount - 1;
     if (recordID == lastRecordIndex)
@@ -2020,8 +2021,9 @@
             }
             data.header.record_id_msb = recordID >> 8;
             data.header.record_id_lsb = recordID & 0xFF;
-            recordData.insert(recordData.end(), (uint8_t*)&data,
-                              ((uint8_t*)&data) + sizeof(data));
+            recordData.insert(recordData.end(),
+                              reinterpret_cast<uint8_t*>(&data),
+                              reinterpret_cast<uint8_t*>(&data) + sizeof(data));
         }
 
         return 0;
@@ -2100,8 +2102,8 @@
             return GENERAL_ERROR;
         }
 
-        recordData.insert(recordData.end(), (uint8_t*)&record,
-                          ((uint8_t*)&record) + sizeof(record));
+        recordData.insert(recordData.end(), reinterpret_cast<uint8_t*>(&record),
+                          reinterpret_cast<uint8_t*>(&record) + sizeof(record));
 
         return 0;
     }
@@ -2125,8 +2127,8 @@
             constructStaticSensorSdr(ctx, sensorNum, recordID, sensor, record);
         }
 
-        recordData.insert(recordData.end(), (uint8_t*)&record,
-                          ((uint8_t*)&record) + sizeof(record));
+        recordData.insert(recordData.end(), reinterpret_cast<uint8_t*>(&record),
+                          reinterpret_cast<uint8_t*>(&record) + sizeof(record));
 
         return 0;
     }
@@ -2149,8 +2151,8 @@
         {
             return GENERAL_ERROR;
         }
-        recordData.insert(recordData.end(), (uint8_t*)&record,
-                          ((uint8_t*)&record) + sizeof(record));
+        recordData.insert(recordData.end(), reinterpret_cast<uint8_t*>(&record),
+                          reinterpret_cast<uint8_t*>(&record) + sizeof(record));
     }
 
     return 0;
@@ -2196,7 +2198,12 @@
             get_sdr::SensorDataRecordHeader* hdr =
                 reinterpret_cast<get_sdr::SensorDataRecordHeader*>(
                     record.data());
-            if (hdr && hdr->record_type == get_sdr::SENSOR_DATA_FULL_RECORD)
+            if (!hdr)
+            {
+                continue;
+            }
+
+            if (hdr->record_type == get_sdr::SENSOR_DATA_FULL_RECORD)
             {
                 get_sdr::SensorDataFullRecord* recordData =
                     reinterpret_cast<get_sdr::SensorDataFullRecord*>(
@@ -2206,7 +2213,22 @@
                     sdrCount++;
                 }
             }
+            else if (hdr->record_type == get_sdr::SENSOR_DATA_COMPACT_RECORD)
+            {
+                get_sdr::SensorDataCompactRecord* recordData =
+                    reinterpret_cast<get_sdr::SensorDataCompactRecord*>(
+                        record.data());
+                if (ctx->lun == recordData->key.owner_lun)
+                {
+                    sdrCount++;
+                }
+            }
+            else if (hdr->record_type == get_sdr::SENSOR_DATA_FRU_RECORD)
+            {
+                sdrCount++;
+            }
         }
+        sdrCount += ipmi::storage::type12Count;
     }
     else if (count.value_or(0) == getSensorCount)
     {