# HG changeset patch # User Edouard Tisserant # Date 1717593495 -7200 # Node ID 9271afc4f34a14371e111f527e03c68cd266f10f # Parent 5744391252ec5de83b2c4a885d5e46868120ebf8# Parent d5edde0c145ba1dde2e7d1623aad2fdbfcbeb0c2 merge again diff -r 5744391252ec -r 9271afc4f34a .github/workflows/run_tests_in_docker.yml --- a/.github/workflows/run_tests_in_docker.yml Wed Jun 05 15:05:54 2024 +0200 +++ b/.github/workflows/run_tests_in_docker.yml Wed Jun 05 15:18:15 2024 +0200 @@ -24,7 +24,8 @@ - uses: actions/checkout@v3 with: repository: open62541/open62541 - ref: v1.3.6 + # v1.3.7 + ref: b8ac9e77f703e6ba5c012b886a8821037503daa6 path: open62541 submodules: recursive @@ -34,6 +35,13 @@ ref: 4d7d67a8e911d744165709c20a254b5cb924ec71 path: Modbus + - uses: actions/checkout@v3 + with: + repository: EmbeddedRPC/erpc + # v1.12.0 + ref: 85d3dd8656ccce4c2d929a69484fb8d88ec6c6c3 + path: erpc + - name: Restore cached docker image id: cache-docker-restore uses: actions/cache/restore@v3 diff -r 5744391252ec -r 9271afc4f34a C_runtime/PLCObject.cpp --- a/C_runtime/PLCObject.cpp Wed Jun 05 15:05:54 2024 +0200 +++ b/C_runtime/PLCObject.cpp Wed Jun 05 15:18:15 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( @@ -89,24 +109,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 +161,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; diff -r 5744391252ec -r 9271afc4f34a C_runtime/PLCObject.hpp --- a/C_runtime/PLCObject.hpp Wed Jun 05 15:05:54 2024 +0200 +++ b/C_runtime/PLCObject.hpp Wed Jun 05 15:18:15 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 diff -r 5744391252ec -r 9271afc4f34a C_runtime/posix_main.cpp --- a/C_runtime/posix_main.cpp Wed Jun 05 15:05:54 2024 +0200 +++ b/C_runtime/posix_main.cpp Wed Jun 05 15:18:15 2024 +0200 @@ -71,6 +71,7 @@ "b:baudrate ", "p:port ", "h:host ", + "a|autoload", NULL }; /*! Help string. */ @@ -83,6 +84,7 @@ -b/--baudrate Baud rate.\n\ -p/--port Port name or port number.\n\ -h/--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(); diff -r 5744391252ec -r 9271afc4f34a runtime/PLCObject.py --- a/runtime/PLCObject.py Wed Jun 05 15:05:54 2024 +0200 +++ b/runtime/PLCObject.py Wed Jun 05 15:18:15 2024 +0200 @@ -330,7 +330,7 @@ return False - def PythonRuntimeCall(self, methodname, reverse_order=False): + def PythonRuntimeCall(self, methodname, use_evaluator=True, reverse_order=False): """ Calls init, start, stop or cleanup method provided by runtime python files, loaded when new PLC uploaded @@ -339,7 +339,10 @@ if reverse_order: methods = reversed(methods) for method in methods: - _res, exp = default_evaluator(method) + if use_evaluator: + _res, exp = self.evaluator(method) + else: + _res, exp = default_evaluator(method) if exp is not None: self.LogMessage(0, '\n'.join(traceback.format_exception(*exp))) @@ -403,7 +406,7 @@ self.LogMessage(0, traceback.format_exc()) raise - self.PythonRuntimeCall("init") + self.PythonRuntimeCall("init", use_evaluator=False) self.PythonThreadCondLock = Lock() self.PythonThreadCmdCond = Condition(self.PythonThreadCondLock) @@ -418,7 +421,7 @@ if self.python_runtime_vars is not None: self.PythonThreadCommand("Finish") self.PythonThread.join() - self.PythonRuntimeCall("cleanup", reverse_order=True) + self.PythonRuntimeCall("cleanup", use_evaluator=False, reverse_order=True) self.python_runtime_vars = None diff -r 5744391252ec -r 9271afc4f34a tests/Makefile --- a/tests/Makefile Wed Jun 05 15:05:54 2024 +0200 +++ b/tests/Makefile Wed Jun 05 15:18:15 2024 +0200 @@ -71,7 +71,7 @@ # SOURCE and BUILD # -BUILT_PROJECTS=beremiz matiec open62541 Modbus +BUILT_PROJECTS=beremiz matiec open62541 Modbus erpc tar_opts=--absolute-names --exclude=.hg --exclude=.git --exclude=.*.pyc --exclude=.*.swp @@ -109,8 +109,11 @@ cd $(build_dir)/Modbus && \ make - -built_apps: $(build_dir)/matiec/iec2c $(build_dir)/beremiz/$(beremiz_checksum).sha1 $(build_dir)/open62541/build/bin/libopen62541.a $(build_dir)/Modbus/libmb.a +$(build_dir)/beremiz/C_runtime/beremiz_runtime: | $(build_dir)/erpc/$(erpc_checksum).sha1 + cd $(build_dir)/beremiz/C_runtime && \ + make + +built_apps: $(build_dir)/matiec/iec2c $(build_dir)/beremiz/$(beremiz_checksum).sha1 $(build_dir)/open62541/build/bin/libopen62541.a $(build_dir)/Modbus/libmb.a $(build_dir)/beremiz/C_runtime/beremiz_runtime touch $@ define log_command diff -r 5744391252ec -r 9271afc4f34a tests/cli_tests/C_runtime.bash --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/cli_tests/C_runtime.bash Wed Jun 05 15:18:15 2024 +0200 @@ -0,0 +1,55 @@ +#!/bin/bash + +rm -f ./PLC_OK ./CLI_OK + +# Run C runtime +$BEREMIZPATH/C_runtime/beremiz_runtime -v -t tcp -p 61131 -h localhost > >( + echo "Start PLC stdout reader loop" + while read line; do + # Wait for server to print modified value + echo "PLC>> $line" + if [[ "$line" == "C runtime OK #3" ]]; then + echo "$line" + touch ./PLC_OK + fi + done + echo "End PLC stdout reader loop" +) & +PLC_PID=$! + +# Start PLC with C runtime test +setsid $BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \ + --project-home $BEREMIZPATH/tests/projects/c_runtime build transfer run > >( +echo "Start CLI loop" +while read line; do + # Wait for CLI to output expected PLC log message on stdout + echo "CLI>> $line" + if [[ $line =~ .*C\ runtime\ log\ OK\ #3$ ]]; then + echo "$line" + touch ./CLI_OK + fi +done +echo "End CLI loop" +) & +CLI_PID=$! + +echo all subprocess started, start polling results +res=110 # default to ETIMEDOUT +c=45 +while ((c--)); do + if [[ -a ./PLC_OK && -a ./CLI_OK ]]; then + echo got results. + res=0 # OK success + break + else + echo waiting.... $c + sleep 1 + fi +done + +# Kill PLC and subprocess +echo will kill CLI:$CLI_PID and PLC:$PLC_PID +pkill -s $CLI_PID +kill $PLC_PID + +exit $res diff -r 5744391252ec -r 9271afc4f34a tests/projects/c_runtime/beremiz.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/c_runtime/beremiz.xml Wed Jun 05 15:18:15 2024 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r 5744391252ec -r 9271afc4f34a tests/projects/c_runtime/plc.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/c_runtime/plc.xml Wed Jun 05 15:18:15 2024 +0200 @@ -0,0 +1,399 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 'C runtime log OK #' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + beat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + count + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lvl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + T#1s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +