Fix variable tracing in new eRPC interface.
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Fri, 19 Jan 2024 19:58:44 +0100
changeset 3885 22a009561502
parent 3884 34da877021d5
child 3886 2adfa4c60bff
Fix variable tracing in new eRPC interface.
connectors/ERPC/__init__.py
controls/DebugVariablePanel/DebugVariableItem.py
erpc_interface/__init__.py
erpc_interface/erpc_PLCObject.erpc
erpc_interface/erpc_PLCObject/__init__.py
erpc_interface/erpc_PLCObject/client.py
erpc_interface/erpc_PLCObject/common.py
erpc_interface/erpc_PLCObject/interface.py
erpc_interface/erpc_PLCObject/server.py
runtime/eRPCServer.py
--- a/connectors/ERPC/__init__.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/connectors/ERPC/__init__.py	Fri Jan 19 19:58:44 2024 +0100
@@ -17,7 +17,7 @@
 # eRPC service code
 from erpc_interface.erpc_PLCObject.interface import IBeremizPLCObjectService
 from erpc_interface.erpc_PLCObject.client import BeremizPLCObjectServiceClient
-from erpc_interface.erpc_PLCObject.common import trace_order, extra_file, PLCstatus_enum
+from erpc_interface.erpc_PLCObject.common import trace_order, extra_file, PLCstatus_enum, IECtype_enum
 
 import PSKManagement as PSK
 from connectors.ERPC.PSK_Adapter import SSLPSKClientTransport
@@ -55,10 +55,12 @@
         lambda res:(enum_to_PLCstatus[res.PLCstatus], res.logcounts)),
     "GetTraceVariables":TranslatedReturnAsLastOutput(
         lambda res:(enum_to_PLCstatus[res.PLCstatus],
-                    [(sample.tick, sample.TraceBuffer) for sample in res.traces])),
+                    [(sample.tick, bytes(sample.TraceBuffer)) for sample in res.traces])),
     "MatchMD5":ReturnAsLastOutput,
     "NewPLC":ReturnAsLastOutput,
     "SeedBlob":ReturnAsLastOutput,
+    "SetTraceVariablesList": ReturnAsLastOutput,
+    "StopPLC":ReturnAsLastOutput,
 }
 
 ArgsWrappers = {
@@ -66,7 +68,9 @@
         lambda md5sum, plcObjectBlobID, extrafiles: (
             md5sum, plcObjectBlobID, [extra_file(*f) for f in extrafiles]),
     "SetTraceVariablesList": 
-        lambda orders : ([trace_order(*order) for order in orders],)
+        lambda orders : ([
+            trace_order(idx, getattr(IECtype_enum, iectype), b"" if force is None else force) 
+            for idx, iectype, force in orders],)
 }
 
 def ERPC_connector_factory(uri, confnodesroot):
--- a/controls/DebugVariablePanel/DebugVariableItem.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/controls/DebugVariablePanel/DebugVariableItem.py	Fri Jan 19 19:58:44 2024 +0100
@@ -255,7 +255,7 @@
 
                 if self.VariableType in ["STRING", "WSTRING"]:
                     # String data value is CRC
-                    num_value = (binascii.crc32(value.encode()) & STRING_CRC_MASK)
+                    num_value = (binascii.crc32(value) & STRING_CRC_MASK)
                 elif self.VariableType in ["TIME", "TOD", "DT", "DATE"]:
                     # Numeric value of time type variables
                     # is represented in seconds
--- a/erpc_interface/__init__.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/erpc_interface/__init__.py	Fri Jan 19 19:58:44 2024 +0100
@@ -1,5 +1,5 @@
 #
-# Generated by erpcgen 1.11.0 on Wed Jan 17 21:59:20 2024.
+# Generated by erpcgen 1.11.0 on Fri Jan 19 08:26:41 2024.
 #
 # AUTOGENERATED - DO NOT EDIT
 #
--- a/erpc_interface/erpc_PLCObject.erpc	Wed Jan 17 22:09:32 2024 +0100
+++ b/erpc_interface/erpc_PLCObject.erpc	Fri Jan 19 19:58:44 2024 +0100
@@ -19,6 +19,32 @@
     Disconnected
 }
 
+enum IECtype_enum {
+    BOOL,
+    STEP,
+    TRANSITION,
+    ACTION,
+    SINT,
+    USINT,
+    BYTE,
+    STRING,
+    INT,
+    UINT,
+    WORD,
+    DINT,
+    UDINT,
+    DWORD,
+    LINT,
+    ULINT,
+    LWORD,
+    REAL,
+    LREAL,
+    TIME,
+    TOD,
+    DATE,
+    DT,
+}
+
 struct PLCstatus {
     PLCstatus_enum PLCstatus;
     uint32[4] logcounts;
@@ -41,7 +67,7 @@
 
 struct trace_order {
     uint32 idx;
-    uint8 iectype;
+    IECtype_enum iectype;
     binary force;
 };
 
@@ -66,7 +92,7 @@
     RepairPLC() -> uint32
     ResetLogCount() -> uint32
     SeedBlob(in binary seed, out binary blobID) -> uint32
-    SetTraceVariablesList(in list<trace_order> orders) -> uint32
+    SetTraceVariablesList(in list<trace_order> orders, out uint32 debugtoken) -> uint32
     StartPLC() -> uint32
-    StopPLC() -> uint32
+    StopPLC(out bool success) -> uint32
 }
--- a/erpc_interface/erpc_PLCObject/__init__.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/erpc_interface/erpc_PLCObject/__init__.py	Fri Jan 19 19:58:44 2024 +0100
@@ -1,5 +1,5 @@
 #
-# Generated by erpcgen 1.11.0 on Wed Jan 17 21:59:20 2024.
+# Generated by erpcgen 1.11.0 on Fri Jan 19 08:26:41 2024.
 #
 # AUTOGENERATED - DO NOT EDIT
 #
--- a/erpc_interface/erpc_PLCObject/client.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/erpc_interface/erpc_PLCObject/client.py	Fri Jan 19 19:58:44 2024 +0100
@@ -1,5 +1,5 @@
 #
-# Generated by erpcgen 1.11.0 on Wed Jan 17 21:59:20 2024.
+# Generated by erpcgen 1.11.0 on Fri Jan 19 08:26:41 2024.
 #
 # AUTOGENERATED - DO NOT EDIT
 #
@@ -235,7 +235,9 @@
         _result = codec.read_uint32()
         return _result
 
-    def SetTraceVariablesList(self, orders):
+    def SetTraceVariablesList(self, orders, debugtoken):
+        assert type(debugtoken) is erpc.Reference, "out parameter must be a Reference object"
+
         # Build remote function invocation message.
         request = self._clientManager.create_request()
         codec = request.codec
@@ -253,6 +255,7 @@
 
         # Send request and process reply.
         self._clientManager.perform_request(request)
+        debugtoken.value = codec.read_uint32()
         _result = codec.read_uint32()
         return _result
 
@@ -271,7 +274,9 @@
         _result = codec.read_uint32()
         return _result
 
-    def StopPLC(self):
+    def StopPLC(self, success):
+        assert type(success) is erpc.Reference, "out parameter must be a Reference object"
+
         # Build remote function invocation message.
         request = self._clientManager.create_request()
         codec = request.codec
@@ -283,7 +288,8 @@
 
         # Send request and process reply.
         self._clientManager.perform_request(request)
-        _result = codec.read_uint32()
-        return _result
-
-
+        success.value = codec.read_bool()
+        _result = codec.read_uint32()
+        return _result
+
+
--- a/erpc_interface/erpc_PLCObject/common.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/erpc_interface/erpc_PLCObject/common.py	Fri Jan 19 19:58:44 2024 +0100
@@ -1,5 +1,5 @@
 #
-# Generated by erpcgen 1.11.0 on Wed Jan 17 21:59:20 2024.
+# Generated by erpcgen 1.11.0 on Fri Jan 19 08:26:41 2024.
 #
 # AUTOGENERATED - DO NOT EDIT
 #
@@ -13,6 +13,31 @@
     Broken = 3
     Disconnected = 4
 
+class IECtype_enum:
+    BOOL = 0
+    STEP = 1
+    TRANSITION = 2
+    ACTION = 3
+    SINT = 4
+    USINT = 5
+    BYTE = 6
+    STRING = 7
+    INT = 8
+    UINT = 9
+    WORD = 10
+    DINT = 11
+    UDINT = 12
+    DWORD = 13
+    LINT = 14
+    ULINT = 15
+    LWORD = 16
+    REAL = 17
+    LREAL = 18
+    TIME = 19
+    TOD = 20
+    DATE = 21
+    DT = 22
+
 
 # Structures data types declarations
 class log_message(object):
@@ -187,12 +212,12 @@
 class trace_order(object):
     def __init__(self, idx=None, iectype=None, force=None):
         self.idx = idx # uint32
-        self.iectype = iectype # uint8
+        self.iectype = iectype # IECtype_enum
         self.force = force # binary
 
     def _read(self, codec):
         self.idx = codec.read_uint32()
-        self.iectype = codec.read_uint8()
+        self.iectype = codec.read_int32()
         self.force = codec.read_binary()
         return self
 
@@ -202,7 +227,7 @@
         codec.write_uint32(self.idx)
         if self.iectype is None:
             raise ValueError("iectype is None")
-        codec.write_uint8(self.iectype)
+        codec.write_int32(self.iectype)
         if self.force is None:
             raise ValueError("force is None")
         codec.write_binary(self.force)
--- a/erpc_interface/erpc_PLCObject/interface.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/erpc_interface/erpc_PLCObject/interface.py	Fri Jan 19 19:58:44 2024 +0100
@@ -1,5 +1,5 @@
 #
-# Generated by erpcgen 1.11.0 on Wed Jan 17 21:59:20 2024.
+# Generated by erpcgen 1.11.0 on Fri Jan 19 08:26:41 2024.
 #
 # AUTOGENERATED - DO NOT EDIT
 #
@@ -55,13 +55,13 @@
     def SeedBlob(self, seed, blobID):
         raise NotImplementedError()
 
-    def SetTraceVariablesList(self, orders):
+    def SetTraceVariablesList(self, orders, debugtoken):
         raise NotImplementedError()
 
     def StartPLC(self):
         raise NotImplementedError()
 
-    def StopPLC(self):
+    def StopPLC(self, success):
         raise NotImplementedError()
 
 
--- a/erpc_interface/erpc_PLCObject/server.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/erpc_interface/erpc_PLCObject/server.py	Fri Jan 19 19:58:44 2024 +0100
@@ -1,5 +1,5 @@
 #
-# Generated by erpcgen 1.11.0 on Wed Jan 17 21:59:20 2024.
+# Generated by erpcgen 1.11.0 on Fri Jan 19 08:26:41 2024.
 #
 # AUTOGENERATED - DO NOT EDIT
 #
@@ -280,6 +280,9 @@
         codec.write_uint32(_result)
 
     def _handle_SetTraceVariablesList(self, sequence, codec):
+        # Create reference objects to pass into handler for out/inout parameters.
+        debugtoken = erpc.Reference()
+
         # Read incoming parameters.
         _n0 = codec.start_read_list()
         orders = []
@@ -289,7 +292,7 @@
 
 
         # Invoke user implementation of remote function.
-        _result = self._handler.SetTraceVariablesList(orders)
+        _result = self._handler.SetTraceVariablesList(orders, debugtoken)
 
         # Prepare codec for reply message.
         codec.reset()
@@ -300,6 +303,9 @@
             service=interface.IBeremizPLCObjectService.SERVICE_ID,
             request=interface.IBeremizPLCObjectService.SETTRACEVARIABLESLIST_ID,
             sequence=sequence))
+        if debugtoken.value is None:
+            raise ValueError("debugtoken.value is None")
+        codec.write_uint32(debugtoken.value)
         codec.write_uint32(_result)
 
     def _handle_StartPLC(self, sequence, codec):
@@ -320,10 +326,13 @@
         codec.write_uint32(_result)
 
     def _handle_StopPLC(self, sequence, codec):
-        # Read incoming parameters.
-
-        # Invoke user implementation of remote function.
-        _result = self._handler.StopPLC()
+        # Create reference objects to pass into handler for out/inout parameters.
+        success = erpc.Reference()
+
+        # Read incoming parameters.
+
+        # Invoke user implementation of remote function.
+        _result = self._handler.StopPLC(success)
 
         # Prepare codec for reply message.
         codec.reset()
@@ -334,6 +343,9 @@
             service=interface.IBeremizPLCObjectService.SERVICE_ID,
             request=interface.IBeremizPLCObjectService.STOPPLC_ID,
             sequence=sequence))
-        codec.write_uint32(_result)
-
-
+        if success.value is None:
+            raise ValueError("success.value is None")
+        codec.write_bool(success.value)
+        codec.write_uint32(_result)
+
+
--- a/runtime/eRPCServer.py	Wed Jan 17 22:09:32 2024 +0100
+++ b/runtime/eRPCServer.py	Fri Jan 19 19:58:44 2024 +0100
@@ -12,7 +12,7 @@
 import erpc
 
 # eRPC service code
-from erpc_interface.erpc_PLCObject.common import PSKID, PLCstatus, TraceVariables, trace_sample, PLCstatus_enum, log_message
+from erpc_interface.erpc_PLCObject.common import PSKID, PLCstatus, TraceVariables, trace_sample, PLCstatus_enum, log_message, IECtype_enum
 from erpc_interface.erpc_PLCObject.interface import IBeremizPLCObjectService
 from erpc_interface.erpc_PLCObject.server import BeremizPLCObjectServiceService
 
@@ -23,6 +23,8 @@
 
 CRITICAL_LOG_LEVEL = LogLevelsDict["CRITICAL"]
 
+enum_to_IECtype = dict(map(lambda t:(t[1],t[0]),getmembers(IECtype_enum, lambda x:type(x)==int)))
+
 def ReturnAsLastOutput(method, args_wrapper, *args):
     args[-1].value = method(*args_wrapper(*args[:-1]))
     return 0
@@ -43,10 +45,12 @@
     "GetPLCstatus":TranslatedReturnAsLastOutput(
         lambda res:PLCstatus(getattr(PLCstatus_enum, res[0]),res[1])),
     "GetTraceVariables":TranslatedReturnAsLastOutput(
-        lambda res:TraceVariables(res[0],[trace_sample(*sample) for sample in res[1]])),
+        lambda res:TraceVariables(getattr(PLCstatus_enum, res[0]),[trace_sample(*sample) for sample in res[1]])),
     "MatchMD5":ReturnAsLastOutput,
     "NewPLC":ReturnAsLastOutput,
     "SeedBlob":ReturnAsLastOutput,
+    "SetTraceVariablesList": ReturnAsLastOutput,
+    "StopPLC":ReturnAsLastOutput,
 }
 
 ArgsWrappers = {
@@ -56,7 +60,7 @@
         lambda md5sum, plcObjectBlobID, extrafiles: (
             md5sum, bytes(plcObjectBlobID), [(f.fname, bytes(f.blobID)) for f in extrafiles]),
     "SetTraceVariablesList": 
-        lambda orders : ([(order.idx, order.iectype, order.force) for order in orders],)
+        lambda orders : ([(order.idx, enum_to_IECtype[order.iectype], None if len(order.force)==0 else order.force) for order in orders],)
 }
 
 def rpc_wrapper(method_name):