connectors/LPC/LPCProto.py
changeset 536 9b77aabf3d36
parent 508 73ecb803d8af
child 545 627e5c636a4f
equal deleted inserted replaced
533:25437efb7ae4 536:9b77aabf3d36
    83         length = len(self.OptData)
    83         length = len(self.OptData)
    84         # transform length into a byte string
    84         # transform length into a byte string
    85         # we presuppose endianess of LPC same as PC
    85         # we presuppose endianess of LPC same as PC
    86         lengthstr = ctypes.string_at(ctypes.pointer(ctypes.c_int(length)),4)
    86         lengthstr = ctypes.string_at(ctypes.pointer(ctypes.c_int(length)),4)
    87         buffer = lengthstr + self.OptData
    87         buffer = lengthstr + self.OptData
    88         ###################################################################
    88         return self.pseudofile.write(buffer)
    89         # TO BE REMOVED AS SOON AS USB IS FIXED IN CONTROLLER
       
    90         ###################################################################
       
    91         length += 4
       
    92         cursor = 0
       
    93         while cursor < length:
       
    94             next_cursor = cursor + MAX_PACKET_SIZE
       
    95             # sent just enough bytes to not crash controller
       
    96             self.pseudofile.write(buffer[cursor:next_cursor])
       
    97             # if sent quantity was 128
       
    98             if next_cursor <= length:
       
    99                 self.GetCommandAck()
       
   100             cursor = next_cursor
       
   101 
    89 
   102     def GetData(self):
    90     def GetData(self):
   103         lengthstr = self.pseudofile.read(4)
    91         lengthstr = self.pseudofile.read(4)
   104         # transform a byte string into length 
    92         # transform a byte string into length 
   105         length = ctypes.cast(ctypes.c_char_p(lengthstr), ctypes.POINTER(ctypes.c_int)).contents.value
    93         length = ctypes.cast(ctypes.c_char_p(lengthstr), ctypes.POINTER(ctypes.c_int)).contents.value