LPCconnector/LPCAppObject.py
changeset 41 b02a30880829
parent 35 cb9da964a178
child 42 30eae94f35f7
equal deleted inserted replaced
40:000de4f24ab2 41:b02a30880829
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 import ctypes
    25 import ctypes
    26 from LPCAppProto import *
    26 from LPCAppProto import *
    27 from LPCObject import *
    27 from LPCObject import *
    28 from targets.typemapping import  LogLevelsCount, SameEndianessTypeTranslator as TypeTranslator
    28 from targets.typemapping import  LogLevelsCount, TypeTranslator, UnpackDebugBuffer
    29 
    29 
    30 class LPCAppObject(LPCObject):
    30 class LPCAppObject(LPCObject):
    31     def connect(self,comport):
    31     def connect(self,comport):
    32         self.SerialConnection = LPCAppProto(comport,#number
    32         self.SerialConnection = LPCAppProto(comport,#number
    33                                          115200, #speed
    33                                          115200, #speed
    92 
    92 
    93     def GetTraceVariables(self):
    93     def GetTraceVariables(self):
    94         """
    94         """
    95         Return a list of variables, corresponding to the list of required idx
    95         Return a list of variables, corresponding to the list of required idx
    96         """
    96         """
    97         offset = 0
       
    98         strbuf = self.HandleSerialTransaction(
    97         strbuf = self.HandleSerialTransaction(
    99                                      GET_TRACE_VARIABLETransaction())
    98                                      GET_TRACE_VARIABLETransaction())
   100         if strbuf is not None and len(strbuf) > 4 and self.PLCStatus == "Started":
    99         if strbuf is not None and len(strbuf) > 4 and self.PLCStatus == "Started":
   101             res=[]
   100             res=[]
   102             size = len(strbuf) - 4
   101             size = len(strbuf) - 4
   103             ctick = ctypes.create_string_buffer(strbuf[:4])
   102             ctick = ctypes.create_string_buffer(strbuf[:4])
   104             tick = ctypes.cast(ctick, ctypes.POINTER(ctypes.c_int)).contents
   103             tick = ctypes.cast(ctick, ctypes.POINTER(ctypes.c_int)).contents
   105             cbuff = ctypes.create_string_buffer(strbuf[4:])
   104             cbuff = ctypes.create_string_buffer(strbuf[4:])
   106             buff = ctypes.cast(cbuff, ctypes.c_void_p)
   105             buff = ctypes.cast(cbuff, ctypes.c_void_p)
   107             for idx, iectype, forced in self._Idxs:
   106             TraceVariables = UnpackDebugBuffer(buff, size,  self._Idxs)
   108                 cursor = ctypes.c_void_p(buff.value + offset)
   107             if TraceVariables is not None:
   109                 c_type,unpack_func, pack_func = TypeTranslator.get(iectype, (None,None,None))
       
   110                 if c_type is not None and offset < size:
       
   111                     res.append(unpack_func(ctypes.cast(cursor,
       
   112                                                        ctypes.POINTER(c_type)).contents))
       
   113                     offset += ctypes.sizeof(c_type)
       
   114                 else:
       
   115                     #if c_type is None:
       
   116                         #PLCprint("Debug error - " + iectype + " not supported !")
       
   117                     #if offset >= size:
       
   118                         #PLCprint("Debug error - buffer too small !")
       
   119                     break
       
   120             if offset and offset == size:
       
   121                 return self.PLCStatus, tick.value, res
   108                 return self.PLCStatus, tick.value, res
   122             #PLCprint("Debug error - wrong buffer unpack !")
       
   123         return self.PLCStatus, None, [] 
   109         return self.PLCStatus, None, [] 
   124 
   110 
   125     def GetLogMessage(self, level, msgid):
   111     def GetLogMessage(self, level, msgid):
   126         strbuf = self.HandleSerialTransaction(GET_LOGMSGTransaction(level, msgid))
   112         strbuf = self.HandleSerialTransaction(GET_LOGMSGTransaction(level, msgid))
   127         if strbuf is not None and len(strbuf) > 12:
   113         if strbuf is not None and len(strbuf) > 12: