RPC: Add command line option support for RPC host

The RPC host program needs to be rebuilt whenever the transportation is changed.
This patch adds support for command-line options for RPC transportation so that the host app does not have to rebuild.
Follow README.rst on how to use it.

Signed-off-by: Jason Guo <jason.guo@arm.com>
Change-Id: I0acf3570cb0d0808caa4263b16749feaf7267865
diff --git a/erpc/host_example/main.c b/erpc/host_example/main.c
index ddf2665..1545525 100644
--- a/erpc/host_example/main.c
+++ b/erpc/host_example/main.c
@@ -15,6 +15,13 @@
 #include "psa/client.h"
 #include "psa/crypto.h"
 
+#if (!defined(ERPC_TRANSPORT_UART)) && (!defined(ERPC_TRANSPORT_TCP))
+#include <stdlib.h>
+#include <getopt.h>
+#define ARGC_UART 3
+#define ARGC_TCP 4
+#endif
+
 static void test_call(void)
 {
     psa_status_t status;
@@ -37,12 +44,61 @@
 {
     erpc_transport_t transport;
 
+#if (!defined(ERPC_TRANSPORT_UART)) && (!defined(ERPC_TRANSPORT_TCP))
+    int erpc_uart_flag = 0, erpc_tcp_flag = 0;
+    char *uart_dev = NULL, *tcp_host = NULL, *tcp_port = NULL;
+    struct option erpc_transport_options[] =
+    {
+        {"UART", no_argument, &erpc_uart_flag, 1},
+        {"TCP", no_argument, &erpc_tcp_flag, 1},
+        {0, 0, 0, 0}
+    };
+#endif
+
 #ifdef ERPC_TRANSPORT_UART
     transport = erpc_transport_serial_init(PORT_NAME, 115200);
 #elif defined(ERPC_TRANSPORT_TCP)
     transport = erpc_transport_tcp_init(ERPC_HOST, ERPC_PORT, false);
 #else
-#error "No valid transportation layer selected."
+    /* Check if argc is correct */
+    if (argc != ARGC_UART && argc != ARGC_TCP) {
+        printf("Incorrect argument numbers.\r\n");
+        printf("Please input --UART PORT or --TCP HOST PORT\r\n");
+        return 1;
+    }
+
+    /* Loop check to set _flag and parse arguments */
+    while (getopt_long(argc, argv, "", erpc_transport_options, NULL) != -1);
+    if (!erpc_uart_flag && !erpc_tcp_flag) {
+        printf("No valid transportation layer selected.\r\n");
+        return 1;
+    } else if(erpc_uart_flag && erpc_tcp_flag) {
+        printf("UART and TCP cannot be set at the same time.\r\n");
+        return 1;
+    } else if (erpc_uart_flag) {
+        if (argc - optind != 1) {
+            printf("Incorrect argument numbers for --UART.\r\n");
+            return 1;
+        }
+        uart_dev = argv[optind];
+    } else if (erpc_tcp_flag) {
+        if (argc - optind != 2) {
+            printf("Incorrect argument numbers for --TCP.\r\n");
+        return 1;
+        }
+        tcp_host = argv[optind];
+        tcp_port = argv[optind + 1];
+    }
+
+    /* eRPC transport initialization */
+    if (erpc_uart_flag) {
+        printf("UART device is setting to %s\r\n",uart_dev);
+        transport = erpc_transport_serial_init(uart_dev, 115200);
+    } else if (erpc_tcp_flag) {
+        printf("TCP host is setting to %s\t",tcp_host);
+        printf("TCP port is setting to %s\r\n",tcp_port);
+        transport = erpc_transport_tcp_init(tcp_host, atoi(tcp_port), false);
+    }
 #endif
 
     if (!transport) {