82 |
84 |
83 def SendData(self): |
85 def SendData(self): |
84 length = len(self.OptData) |
86 length = len(self.OptData) |
85 # transform length into a byte string |
87 # transform length into a byte string |
86 # we presuppose endianess of LPC same as PC |
88 # we presuppose endianess of LPC same as PC |
87 lengthstr = ctypes.string_at(ctypes.pointer(ctypes.c_int(length)),4) |
89 lengthstr = ctypes.string_at(ctypes.pointer(ctypes.c_int(length)),4) |
88 self.pseudofile.write(lengthstr + self.OptData) |
90 buffer = lengthstr + self.OptData |
|
91 ################################################################### |
|
92 # TO BE REMOVED AS SOON AS USB IS FIXED IN CONTROLLER |
|
93 ################################################################### |
|
94 length += 4 |
|
95 cursor = 0 |
|
96 while cursor < length: |
|
97 next_cursor = cursor + MAX_PACKET_SIZE |
|
98 # sent just enough bytes to not crash controller |
|
99 self.pseudofile.write(buffer[cursor:next_cursor]) |
|
100 # if sent quantity was 128 |
|
101 if next_cursor <= length: |
|
102 self.GetCommandAck() |
|
103 cursor = next_cursor |
89 |
104 |
90 def GetData(self): |
105 def GetData(self): |
91 lengthstr = self.pseudofile.read(4) |
106 lengthstr = self.pseudofile.read(4) |
92 # transform a byte string into length |
107 # transform a byte string into length |
93 length = ctypes.cast(ctypes.c_char_p(lengthstr), ctypes.POINTER(ctypes.c_int)).contents.value |
108 length = ctypes.cast(ctypes.c_char_p(lengthstr), ctypes.POINTER(ctypes.c_int)).contents.value |
128 LPCTransaction.__init__(self, 0x07) |
143 LPCTransaction.__init__(self, 0x07) |
129 ExchangeData = LPCTransaction.GetData |
144 ExchangeData = LPCTransaction.GetData |
130 |
145 |
131 if __name__ == "__main__": |
146 if __name__ == "__main__": |
132 TestConnection = LPCProto(6,115200,2) |
147 TestConnection = LPCProto(6,115200,2) |
133 #TestConnection.HandleTransaction(GET_PLCIDTransaction()) |
148 # TestConnection.HandleTransaction(GET_PLCIDTransaction()) |
134 TestConnection.HandleTransaction(STARTTransaction()) |
149 TestConnection.HandleTransaction(STARTTransaction()) |
135 TestConnection.HandleTransaction(SET_TRACE_VARIABLETransaction( |
150 # TestConnection.HandleTransaction(SET_TRACE_VARIABLETransaction( |
136 "\x03\x00\x00\x00")) |
151 # "\x03\x00\x00\x00"*200)) |
137 TestConnection.HandleTransaction(STARTTransaction()) |
152 # TestConnection.HandleTransaction(STARTTransaction()) |
138 while True: |
153 while True: |
139 time.sleep(0.5) |
154 #time.sleep(0.5) |
140 TestConnection.HandleTransaction(SET_TRACE_VARIABLETransaction( |
155 TestConnection.HandleTransaction(SET_TRACE_VARIABLETransaction( |
141 "\x01\x00\x00\x00"*31)) |
156 "\x01\x00\x00\x00"*200)) |
142 #print map(hex,map(ord,TestConnection.HandleTransaction(GET_TRACE_VARIABLETransaction()))) |
157 #print map(hex,map(ord,TestConnection.HandleTransaction(GET_TRACE_VARIABLETransaction()))) |
143 #TestConnection.HandleTransaction(STOPTransaction()) |
158 #TestConnection.HandleTransaction(STOPTransaction()) |