MCPcopy Create free account
hub / github.com/bitcraze/crazyflie-lib-python / run

Method run

cflib/crtp/serialdriver.py:187–230  ·  view source on GitHub ↗

Run the receiver thread

(self)

Source from the content-addressed store, hash-verified

185 self._stop = True
186
187 def run(self):
188 """ Run the receiver thread """
189 READ_END = bytes([START_BYTE1, START_BYTE2])
190 received = bytearray(MTU + 4)
191 received_header = memoryview(received)[0:2]
192 while not self._stop:
193 try:
194 r = self.ser.read_until(READ_END)[-2:]
195 if len(r) != 2:
196 continue
197
198 if r[0] != START_BYTE1 or r[1] != START_BYTE2:
199 continue
200
201 r = self.ser.readinto(received_header)
202 if r != 2:
203 continue
204
205 if not (0 < received_header[1] <= MTU):
206 continue
207
208 expected = received_header[1] + 2
209
210 received_data_chk = memoryview(received)[2:2+expected]
211 r = self.ser.readinto(received_data_chk)
212 if r != expected:
213 continue
214
215 # NOTE: end is (expected - 2) as the length of the data +2 for
216 # the header bytes
217 cksum = compute_cksum(memoryview(received)[:expected])
218 if cksum[0] != received_data_chk[-2] or \
219 cksum[1] != received_data_chk[-1]:
220 continue
221
222 pk = CRTPPacket(received[2], received[3:expected])
223 self.in_queue.put(pk)
224
225 except Exception as e:
226 import traceback
227 if self.link_error_callback:
228 self.link_error_callback(
229 'Error communicating with the Crazyflie!\n'
230 'Exception:%s\n\n%s' % (e, traceback.format_exc()))
231
232
233class _SerialSendThread(threading.Thread):

Callers

nothing calls this directly

Calls 2

compute_cksumFunction · 0.85
CRTPPacketClass · 0.85

Tested by

no test coverage detected