Serial protocol SendData only prefix with size in case of variable size content (i.e. SetTraceVariableList)
authorEdouard Tisserant
Fri, 22 Mar 2013 10:46:51 +0900
changeset 36 73360d0bacbc
parent 35 cb9da964a178
child 38 13c9ff7f3b54
Serial protocol SendData only prefix with size in case of variable size content (i.e. SetTraceVariableList)
LPCconnector/LPCAppProto.py
--- a/LPCconnector/LPCAppProto.py	Thu Mar 21 17:29:53 2013 +0100
+++ b/LPCconnector/LPCAppProto.py	Fri Mar 22 10:46:51 2013 +0900
@@ -46,17 +46,14 @@
         return None 
         
     def SendData(self, Data):
-        length = len(Data)
-        # transform length into a byte string
-        # we presuppose endianess of LPC same as PC
-        lengthstr = ctypes.string_at(ctypes.pointer(ctypes.c_int(length)),4)
-        buffer = lengthstr + Data
-        return self.pseudofile.write(buffer)
+        return self.pseudofile.write(Data)
 
     def GetData(self):
         lengthstr = self.pseudofile.read(4)
         # transform a byte string into length 
-        length = ctypes.cast(ctypes.c_char_p(lengthstr), ctypes.POINTER(ctypes.c_int)).contents.value
+        length = ctypes.cast(
+            ctypes.c_char_p(lengthstr), 
+            ctypes.POINTER(ctypes.c_uint32)).contents.value
         return self.pseudofile.read(length)
 
     def ExchangeData(self): 
@@ -82,7 +79,12 @@
 class SET_TRACE_VARIABLETransaction(LPCAppTransaction):
     def __init__(self, data):
         LPCAppTransaction.__init__(self, 0x04)
-        self.Data = data
+        length = len(data)
+        # transform length into a byte string
+        # we presuppose endianess of LPC same as PC
+        lengthstr = ctypes.string_at(ctypes.pointer(ctypes.c_uint32(length)),4)
+        self.Data = lengthstr + data
+
     def ExchangeData(self):
         self.SendData(self.Data)