C runtime: add autoload
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Mon, 03 Jun 2024 22:29:59 +0200
changeset 3957 2510c1f935d1
parent 3956 9b4ffbb95338
child 3958 d5fb90fd2a79
C runtime: add autoload
C_runtime/PLCObject.cpp
C_runtime/PLCObject.hpp
C_runtime/posix_main.cpp
--- a/C_runtime/PLCObject.cpp	Mon Jun 03 22:29:20 2024 +0200
+++ b/C_runtime/PLCObject.cpp	Mon Jun 03 22:29:59 2024 +0200
@@ -79,6 +79,26 @@
     return 0;
 }
 
+uint32_t PLCObject::AutoLoad()
+{
+    // Load PLC object
+    uint32_t res = LoadPLC();
+    if (res != 0)
+    {
+        return res;
+    }
+
+    // Start PLC object
+    res = StartPLC();
+    if (res != 0)
+    {
+        return res;
+    }
+
+    return 0;
+}
+
+
 #define LOG_READ_BUFFER_SIZE 1 << 10 // 1KB
 
 uint32_t PLCObject::GetLogMessage(
--- a/C_runtime/PLCObject.hpp	Mon Jun 03 22:29:20 2024 +0200
+++ b/C_runtime/PLCObject.hpp	Mon Jun 03 22:29:59 2024 +0200
@@ -71,6 +71,7 @@
         uint32_t SetTraceVariablesList(const list_trace_order_1_t * orders, int32_t * debugtoken);
         uint32_t StartPLC(void);
         uint32_t StopPLC(bool * success);
+        uint32_t AutoLoad();
 
     private:
         // A map of all the blobs
--- a/C_runtime/posix_main.cpp	Mon Jun 03 22:29:20 2024 +0200
+++ b/C_runtime/posix_main.cpp	Mon Jun 03 22:29:59 2024 +0200
@@ -71,6 +71,7 @@
                                              "b:baudrate <baudrate>",
                                              "p:port <port>",
                                              "h:host <host>",
+                                             "a|autoload",
                                              NULL };
 
 /*! Help string. */
@@ -83,6 +84,7 @@
   -b/--baudrate <baudrate>     Baud rate.\n\
   -p/--port <port>             Port name or port number.\n\
   -h/--host <host>             Host definition.\n\
+  -a/--autoload                Autoload.\n\
 \n\
 Available transports (use with -t option):\n\
   tcp      Tcp transport type (host, port number).\n\
@@ -127,6 +129,7 @@
     uint32_t m_baudrate;      /*!< Baudrate rate speed. */
     const char *m_port;       /*!< Name or number of port. Based on used transport. */
     const char *m_host;       /*!< Host name */
+    bool m_autoload = false;          /*!< Autoload flag. */
 
 public:
     /*!
@@ -239,6 +242,12 @@
                     break;
                 }
 
+                case 'a':
+                {
+                    m_autoload = true;
+                    break;
+                }
+
                 default:
                 {
                     Log::error("error: unrecognized option\n\n");
@@ -363,17 +372,21 @@
             BasicCodecFactory _basicCodecFactory;
             SimpleServer _server;
 
-            BeremizPLCObjectService_service *svc;
-
             Log::info("Starting ERPC server...\n");
 
             _server.setMessageBufferFactory(&_msgFactory);
             _server.setTransport(_transport);
             _server.setCodecFactory(&_basicCodecFactory);
 
-            svc = new BeremizPLCObjectService_service(new PLCObject());
-
-            _server.addService(svc);
+            PLCObject plc_object = PLCObject();
+            BeremizPLCObjectService_service svc = BeremizPLCObjectService_service(&plc_object);
+
+            _server.addService(&svc);
+
+            if(m_autoload)
+            {
+                plc_object.AutoLoad();
+            }
 
             _server.run();