pldmtool : Add retry option `-n` or `--retry-count`

Add `-n` or `--retry-count` option to support resendinng the PLDM
message when the sendRecvMsg method of pldm transport handler is
failed.

Tested:
1. When the option `-n` or `--retry-count` is included in pldmtool
command and the pldm message keeps be failed. pldmtool will retry to
send PLDM message `-n` times after first failure.

Signed-off-by: ThuBaNguyen <thu@os.amperecomputing.com>
Change-Id: I2c3d5e1514ead5a1f2eea6eb43178d45439788f8
diff --git a/pldmtool/pldm_cmd_helper.cpp b/pldmtool/pldm_cmd_helper.cpp
index 9c7f94a..afd49dd 100644
--- a/pldmtool/pldm_cmd_helper.cpp
+++ b/pldmtool/pldm_cmd_helper.cpp
@@ -63,31 +63,45 @@
         printBuffer(Tx, requestMsg);
     }
 
-    void* responseMessage = nullptr;
-    size_t responseMessageSize{};
     auto tid = mctp_eid;
     PldmTransport pldmTransport{};
+    uint8_t retry = 0;
+    int rc = PLDM_ERROR;
 
-    int rc = pldmTransport.sendRecvMsg(tid, requestMsg.data(),
+    while (PLDM_REQUESTER_SUCCESS != rc && retry <= numRetries)
+    {
+        void* responseMessage = nullptr;
+        size_t responseMessageSize{};
+
+        rc = pldmTransport.sendRecvMsg(tid, requestMsg.data(),
                                        requestMsg.size(), responseMessage,
                                        responseMessageSize);
+        if (rc)
+        {
+            std::cerr << "[" << unsigned(retry) << "] pldm_send_recv error rc "
+                      << rc << std::endl;
+            retry++;
+            continue;
+        }
+
+        responseMsg.resize(responseMessageSize);
+        memcpy(responseMsg.data(), responseMessage, responseMsg.size());
+
+        free(responseMessage);
+
+        if (pldmVerbose)
+        {
+            std::cout << "pldmtool: ";
+            printBuffer(Rx, responseMsg);
+        }
+    }
+
     if (rc)
     {
-        std::cerr << "failed to pldm send recv\n";
-        return rc;
+        std::cerr << "failed to pldm send recv error rc " << rc << std::endl;
     }
 
-    responseMsg.resize(responseMessageSize);
-    memcpy(responseMsg.data(), responseMessage, responseMsg.size());
-
-    free(responseMessage);
-
-    if (pldmVerbose)
-    {
-        std::cout << "pldmtool: ";
-        printBuffer(Rx, responseMsg);
-    }
-    return PLDM_SUCCESS;
+    return rc;
 }
 } // namespace helper
 } // namespace pldmtool