C runtime: fix logging, makes test pass
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Mon, 03 Jun 2024 22:29:20 +0200
changeset 3956 9b4ffbb95338
parent 3955 792ae5ff01ca
child 3957 2510c1f935d1
C runtime: fix logging, makes test pass
C_runtime/PLCObject.cpp
--- a/C_runtime/PLCObject.cpp	Mon Jun 03 22:24:55 2024 +0200
+++ b/C_runtime/PLCObject.cpp	Mon Jun 03 22:29:20 2024 +0200
@@ -89,24 +89,24 @@
     uint32_t tv_sec;
     uint32_t tv_nsec;
 
-    uint32_t resultLen = m_PLCSyms.GetLogMessage(
-        level, msgID, buf, LOG_READ_BUFFER_SIZE - 1,
-        &tick, &tv_sec, &tv_nsec);
-
-    if (resultLen == 0)
-    {
-        return ENOENT;
+    uint32_t resultLen;
+    if(m_status.PLCstatus == Empty){
+        resultLen = 0;
+    } else {
+        resultLen = m_PLCSyms.GetLogMessage(
+            level, msgID, buf, LOG_READ_BUFFER_SIZE - 1,
+            &tick, &tv_sec, &tv_nsec);
     }
 
     // Get log message with given msgID
-    message->msg = (char *)malloc(resultLen);
+    message->msg = (char *)malloc(resultLen + 1);
     if (message->msg == NULL)
     {
         return ENOMEM;
     }
     // Copy the log message into eRPC message
     memcpy(message->msg, buf, resultLen);
-    message->msg[resultLen + 1] = '\0';
+    message->msg[resultLen] = '\0';
 
     message->tick = tick;
     message->sec = tv_sec;
@@ -141,6 +141,16 @@
 
 uint32_t PLCObject::GetPLCstatus(PLCstatus *status)
 {
+    if(m_status.PLCstatus == Empty){        
+        for(int lvl = 0; lvl < 4; lvl++){
+            m_status.logcounts[lvl] = 0;
+        }
+    } else {
+        // Get log counts
+        for(int lvl = 0; lvl < 4; lvl++){
+            m_status.logcounts[lvl] = m_PLCSyms.GetLogCount(lvl);
+        }
+    }
     // Get PLC status
     *status = m_status;
     return 0;