# HG changeset patch # User Edouard Tisserant # Date 1367139844 -32400 # Node ID 8078c01ae464a657714917375e717fcc354c2fc6 # Parent 92a009dc58269fc2e02c9fd23aa87cc18a00543b Now Debug Buffer Unpacking is a separate function, declared in typemapping.py diff -r 92a009dc5826 -r 8078c01ae464 runtime/PLCObject.py --- a/runtime/PLCObject.py Sun Apr 28 17:26:22 2013 +0900 +++ b/runtime/PLCObject.py Sun Apr 28 18:04:04 2013 +0900 @@ -25,7 +25,7 @@ import Pyro.core as pyro from threading import Timer, Thread, Lock, Semaphore import ctypes, os, commands, types, sys -from targets.typemapping import LogLevelsDefault, LogLevelsCount, SameEndianessTypeTranslator as TypeTranslator +from targets.typemapping import LogLevelsDefault, LogLevelsCount, TypeTranslator, UnpackDebugBuffer if os.name in ("nt", "ce"): @@ -452,39 +452,20 @@ Return a list of variables, corresponding to the list of required idx """ if self.PLCStatus == "Started": - res=[] tick = ctypes.c_uint32() size = ctypes.c_uint32() - buffer = ctypes.c_void_p() - offset = 0 + buff = ctypes.c_void_p() + TraceVariables = None if self.PLClibraryLock.acquire(False): if self._GetDebugData(ctypes.byref(tick), ctypes.byref(size), - ctypes.byref(buffer)) == 0: + ctypes.byref(buff)) == 0: if size.value: - for idx, iectype, forced in self._Idxs: - cursor = ctypes.c_void_p(buffer.value + offset) - c_type,unpack_func, pack_func = \ - TypeTranslator.get(iectype, - (None,None,None)) - if c_type is not None and offset < size.value: - res.append(unpack_func( - ctypes.cast(cursor, - ctypes.POINTER(c_type)).contents)) - offset += ctypes.sizeof(c_type) if iectype != "STRING" else len(res[-1])+1 - else: - if c_type is None: - PLCprint("Debug error - " + iectype + - " not supported !") - #if offset >= size.value: - #PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size.value)) - break + TraceVariables = UnpackDebugBuffer(buff, size.value, self._Idxs) self._FreeDebugData() self.PLClibraryLock.release() - if offset and offset == size.value: - return self.PLCStatus, tick.value, res - #elif size.value: - #PLCprint("Debug error - wrong buffer unpack ! %d != %d"%(offset, size.value)) + if TraceVariables is not None: + return self.PLCStatus, tick.value, TraceVariables return self.PLCStatus, None, [] def RemoteExec(self, script, **kwargs): diff -r 92a009dc5826 -r 8078c01ae464 targets/typemapping.py --- a/targets/typemapping.py Sun Apr 28 17:26:22 2013 +0900 +++ b/targets/typemapping.py Sun Apr 28 18:04:04 2013 +0900 @@ -73,9 +73,37 @@ #TODO } +TypeTranslator=SameEndianessTypeTranslator + # Construct debugger natively supported types DebugTypesSize = dict([(key,sizeof(t)) for key,(t,p,u) in SameEndianessTypeTranslator.iteritems() if t is not None]) +def UnpackDebugBuffer(buff, size, indexes): + res = [] + offset = 0 + for idx, iectype, forced in indexes: + cursor = c_void_p(buff.value + offset) + c_type,unpack_func, pack_func = \ + TypeTranslator.get(iectype, + (None,None,None)) + if c_type is not None and offset < size: + res.append(unpack_func( + cast(cursor, + POINTER(c_type)).contents)) + offset += sizeof(c_type) if iectype != "STRING" else len(res[-1])+1 + else: + #if c_type is None: + # PLCprint("Debug error - " + iectype + + # " not supported !") + #if offset >= size: + # PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size)) + break + if offset and offset == size: + return res + return None + + + LogLevels = ["CRITICAL","WARNING","INFO","DEBUG"] LogLevelsCount = len(LogLevels) LogLevelsDict = dict(zip(LogLevels,range(LogLevelsCount)))