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

Method run

cflib/crtp/serialdriver.py:248–288  ·  view source on GitHub ↗

Run the sender thread

(self)

Source from the content-addressed store, hash-verified

246 self._stop = True
247
248 def run(self):
249 """ Run the sender thread """
250 out_data = bytearray(MTU + 6)
251 out_data[0:3] = bytearray(
252 [START_BYTE1, START_BYTE2, SYSLINK_RADIO_RAW])
253
254 empty_packet = CRTPPacket(header=0xFF)
255 empty_packet_data_length = 0
256 empty_packet_data = bytearray(7)
257 empty_packet_data[0:5] = bytearray(
258 [START_BYTE1, START_BYTE2, SYSLINK_RADIO_RAW, 0x01,
259 empty_packet.header])
260 empty_packet_data[5:7] = compute_cksum(empty_packet_data[2:5])
261
262 while not self._stop:
263 try:
264 pk = self.out_queue.get(True, timeout=0.0003)
265 data = pk.data
266 len_data = len(data)
267 end_of_payload = 5 + len_data
268
269 out_data[3] = len_data + 1
270 out_data[4] = pk.header
271 out_data[5:end_of_payload] = data
272 out_data[end_of_payload:end_of_payload +
273 2] = compute_cksum(out_data[2:end_of_payload])
274
275 written = self.ser.write(out_data[0:end_of_payload + 2])
276
277 except queue.Empty:
278 pk = empty_packet
279 len_data = empty_packet_data_length
280 written = self.ser.write(empty_packet_data)
281
282 if written != len_data + 7:
283 if self.link_error_callback:
284 self.link_error_callback(
285 'SerialDriver: Could only send {:d}B bytes of {:d}B '
286 'packet to Crazyflie'.format(
287 written, len_data + 7)
288 )

Callers

nothing calls this directly

Calls 3

CRTPPacketClass · 0.85
compute_cksumFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected