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 SameEndianessTypeTranslator as TypeTranslator |
28 from targets.typemapping import LogLevelsCount, SameEndianessTypeTranslator as TypeTranslator |
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 |
44 self.HandleSerialTransaction(RESETTransaction()) |
44 self.HandleSerialTransaction(RESETTransaction()) |
45 return self.PLCStatus |
45 return self.PLCStatus |
46 |
46 |
47 def GetPLCstatus(self): |
47 def GetPLCstatus(self): |
48 strcounts = self.HandleSerialTransaction(GET_LOGCOUNTSTransaction()) |
48 strcounts = self.HandleSerialTransaction(GET_LOGCOUNTSTransaction()) |
49 ccounts = ctypes.cast( |
49 if len(strcounts) == LogLevelsCount * 4: |
50 ctypes.c_char_p(strcounts), |
50 cstrcounts = ctypes.create_string_buffer(strcounts) |
51 ctypes.POINTER(ctypes.c_uint32)) |
51 ccounts = ctypes.cast(cstrcounts, ctypes.POINTER(ctypes.c_uint32)) |
52 return self.PLCStatus, tuple(int(ccounts[idx]) for idx in range(4)) |
52 counts = [int(ccounts[idx]) for idx in xrange(LogLevelsCount)] |
|
53 else : |
|
54 counts = [0]*LogLevelsCount |
|
55 return self.PLCStatus, counts |
53 |
56 |
54 def MatchMD5(self, MD5): |
57 def MatchMD5(self, MD5): |
55 data = self.HandleSerialTransaction(GET_PLCIDTransaction()) |
58 data = self.HandleSerialTransaction(GET_PLCIDTransaction()) |
56 if data is not None: |
59 if data is not None: |
57 return data[:32] == MD5[:32] |
60 return data[:32] == MD5[:32] |
95 strbuf = self.HandleSerialTransaction( |
98 strbuf = self.HandleSerialTransaction( |
96 GET_TRACE_VARIABLETransaction()) |
99 GET_TRACE_VARIABLETransaction()) |
97 if strbuf is not None and len(strbuf) > 4 and self.PLCStatus == "Started": |
100 if strbuf is not None and len(strbuf) > 4 and self.PLCStatus == "Started": |
98 res=[] |
101 res=[] |
99 size = len(strbuf) - 4 |
102 size = len(strbuf) - 4 |
100 tick = ctypes.cast( |
103 ctick = ctypes.create_string_buffer(strbuf[:4]) |
101 ctypes.c_char_p(strbuf[:4]), |
104 tick = ctypes.cast(ctick, ctypes.POINTER(ctypes.c_int)).contents |
102 ctypes.POINTER(ctypes.c_int)).contents |
105 cbuff = ctypes.create_string_buffer(strbuf[4:]) |
103 buff = ctypes.cast( |
106 buff = ctypes.cast(cbuff, ctypes.c_void_p) |
104 ctypes.c_char_p(strbuf[4:]), |
|
105 ctypes.c_void_p) |
|
106 for idx, iectype, forced in self._Idxs: |
107 for idx, iectype, forced in self._Idxs: |
107 cursor = ctypes.c_void_p(buff.value + offset) |
108 cursor = ctypes.c_void_p(buff.value + offset) |
108 c_type,unpack_func, pack_func = TypeTranslator.get(iectype, (None,None,None)) |
109 c_type,unpack_func, pack_func = TypeTranslator.get(iectype, (None,None,None)) |
109 if c_type is not None and offset < size: |
110 if c_type is not None and offset < size: |
110 res.append(unpack_func(ctypes.cast(cursor, |
111 res.append(unpack_func(ctypes.cast(cursor, |