本文整理汇总了Python中cflib.drivers.crazyradio.Crazyradio.close方法的典型用法代码示例。如果您正苦于以下问题:Python Crazyradio.close方法的具体用法?Python Crazyradio.close怎么用?Python Crazyradio.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cflib.drivers.crazyradio.Crazyradio
的用法示例。
在下文中一共展示了Crazyradio.close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_status
# 需要导入模块: from cflib.drivers.crazyradio import Crazyradio [as 别名]
# 或者: from cflib.drivers.crazyradio.Crazyradio import close [as 别名]
def get_status(self):
cradio = Crazyradio()
ver = cradio.version
cradio.close()
cradio = None
return "Crazyradio version {}".format(ver)
示例2: scan_interface
# 需要导入模块: from cflib.drivers.crazyradio import Crazyradio [as 别名]
# 或者: from cflib.drivers.crazyradio.Crazyradio import close [as 别名]
def scan_interface(self, address):
""" Scan interface for Crazyflies """
# This will cause an exception if not successful
cradio = Crazyradio()
# FIXME: implements serial number in the Crazyradio driver!
serial = "N/A"
logger.info("v%s dongle with serial %s found", cradio.version,
serial)
found = []
if address != None:
addr = "{:X}".format(address)
new_addr = struct.unpack("<BBBBB", binascii.unhexlify(addr))
cradio.set_address(new_addr)
cradio.set_arc(1)
cradio.set_data_rate(cradio.DR_250KPS)
if address == None or address == 0xE7E7E7E7E7:
found += map(lambda c: ["radio://0/{}/250K".format(c), ""],
self._scan_radio_channels(cradio))
cradio.set_data_rate(cradio.DR_1MPS)
found += map(lambda c: ["radio://0/{}/1M".format(c), ""],
self._scan_radio_channels(cradio))
cradio.set_data_rate(cradio.DR_2MPS)
found += map(lambda c: ["radio://0/{}/2M".format(c), ""],
self._scan_radio_channels(cradio))
else:
found += map(lambda c: ["radio://0/{}/250K/{:X}".format(c, address), ""],
self._scan_radio_channels(cradio))
cradio.set_data_rate(cradio.DR_1MPS)
found += map(lambda c: ["radio://0/{}/1M/{:X}".format(c, address), ""],
self._scan_radio_channels(cradio))
cradio.set_data_rate(cradio.DR_2MPS)
found += map(lambda c: ["radio://0/{}/2M/{:X}".format(c, address), ""],
self._scan_radio_channels(cradio))
cradio.close()
cradio = None
return found
示例3: scan_interface
# 需要导入模块: from cflib.drivers.crazyradio import Crazyradio [as 别名]
# 或者: from cflib.drivers.crazyradio.Crazyradio import close [as 别名]
def scan_interface(self, address):
""" Scan interface for Crazyflies """
cradio = Crazyradio()
# FIXME: implements serial number in the Crazyradio driver!
serial = "N/A"
logger.info("v%s dongle with serial %s found", cradio.version,
serial)
found = []
if address is not None:
addr = "{:X}".format(address)
new_addr = struct.unpack("<BBBBB", binascii.unhexlify(addr))
self.cradio.set_address(new_addr)
cradio.set_arc(1)
cradio.set_data_rate(self.cradio.DR_250KPS)
if address is None or address == 0xE7E7E7E7E7:
found += [["radio://0/{}/250K".format(c), ""]
for c in self._scan_radio_channels()]
cradio.set_data_rate(self.cradio.DR_1MPS)
found += [["radio://0/{}/1M".format(c), ""]
for c in self._scan_radio_channels()]
cradio.set_data_rate(self.cradio.DR_2MPS)
found += [["radio://0/{}/2M".format(c), ""]
for c in self._scan_radio_channels()]
else:
found += [["radio://0/{}/250K/{:X}".format(c, address), ""]
for c in self._scan_radio_channels()]
cradio.set_data_rate(self.cradio.DR_1MPS)
found += [["radio://0/{}/1M/{:X}".format(c, address), ""]
for c in self._scan_radio_channels()]
cradio.set_data_rate(self.cradio.DR_2MPS)
found += [["radio://0/{}/2M/{:X}".format(c, address), ""]
for c in self._scan_radio_channels()]
cradio.close()
cradio = None
return found
示例4: RadioDriver
# 需要导入模块: from cflib.drivers.crazyradio import Crazyradio [as 别名]
# 或者: from cflib.drivers.crazyradio.Crazyradio import close [as 别名]
#.........这里部分代码省略.........
else:
try:
return self.in_queue.get(True, time)
except Queue.Empty:
return None
def send_packet(self, pk):
""" Send the packet pk though the link """
# if self.out_queue.full():
# self.out_queue.get()
if (self.cradio is None):
return
try:
self.out_queue.put(pk, True, 2)
except Queue.Full:
if self.link_error_callback:
self.link_error_callback("RadioDriver: Could not send packet"
" to copter")
def pause(self):
self._thread.stop()
self._thread = None
def restart(self):
if self._thread:
return
self._thread = _RadioDriverThread(self.cradio, self.in_queue,
self.out_queue,
self.link_quality_callback,
self.link_error_callback)
self._thread.start()
def close(self):
""" Close the link. """
# Stop the comm thread
self._thread.stop()
# Close the USB dongle
try:
if self.cradio:
self.cradio.close()
except:
# If we pull out the dongle we will not make this call
pass
self.cradio = None
def _scan_radio_channels(self, start=0, stop=125):
""" Scan for Crazyflies between the supplied channels. """
return list(self.cradio.scan_channels(start, stop, (0xff,)))
def scan_interface(self):
""" Scan interface for Crazyflies """
if self.cradio is None:
try:
self.cradio = Crazyradio()
except Exception:
return []
else:
raise Exception("Cannot scann for links while the link is open!")
# FIXME: implements serial number in the Crazyradio driver!
serial = "N/A"
logger.info("v%s dongle with serial %s found", self.cradio.version,
serial)
found = []
self.cradio.set_arc(1)
self.cradio.set_data_rate(self.cradio.DR_250KPS)
found += map(lambda c: ["radio://0/{}/250K".format(c), ""],
self._scan_radio_channels())
self.cradio.set_data_rate(self.cradio.DR_1MPS)
found += map(lambda c: ["radio://0/{}/1M".format(c), ""],
self._scan_radio_channels())
self.cradio.set_data_rate(self.cradio.DR_2MPS)
found += map(lambda c: ["radio://0/{}/2M".format(c), ""],
self._scan_radio_channels())
self.cradio.close()
self.cradio = None
return found
def get_status(self):
if self.cradio is None:
try:
self.cradio = Crazyradio()
except USBError as e:
return "Cannot open Crazyradio. Permission problem?"\
" ({})".format(str(e))
except Exception as e:
return str(e)
return "Crazyradio version {}".format(self.cradio.version)
def get_name(self):
return "radio"
示例5: _RadioTransferThread
# 需要导入模块: from cflib.drivers.crazyradio import Crazyradio [as 别名]
# 或者: from cflib.drivers.crazyradio.Crazyradio import close [as 别名]
class _RadioTransferThread(threading.Thread):
""" Thread that handles transfer for a single crazyradio hardware
Can handles transfers form more than one radio profile (ie. link to a copter)
"""
def __init__(self, radio_id):
threading.Thread.__init__(self)
self.cradio = Crazyradio(devid=radio_id)
if self.cradio.version >= 0.4:
self.cradio.set_arc(10)
else:
logger.warning("Radio version <0.4 will be obsoleted soon!")
self._num_profiles = 0
self.tx_queue = Queue.Queue()
self.sp = False
def add_profile(self):
self._num_profiles += 1
rx_queue = Queue.Queue()
return rx_queue
def remove_profile(self, handle):
# we don't need to to anything, the python garbage collector will take care of it
self._num_profiles -= 1
def num_profiles(self):
return self._num_profiles
def send_packet(self, profile, data):
self.tx_queue.put([profile, data])
return profile.handle.get()
def stop(self):
self.sp = True
self.tx_queue.put([None, None])
self.join()
def run(self):
#Simply service transfers requests
while not self.sp:
tx = self.tx_queue.get()
if self.sp:
break
ack = self._send_packet(tx[0], tx[1])
tx[0].handle.put(ack)
# Close the USB dongle
try:
if self.cradio:
self.cradio.close()
print("Closed radio")
except:
# If we pull out the dongle we will not make this call
pass
self.cradio = None
def _send_packet(self, profile, data):
"""
Send packet making sure the radio is configured for the
right transfers profile
"""
assert isinstance(profile, _RadioProfile)
if self.cradio.channel != profile.channel:
self.cradio.set_channel(profile.channel)
if self.cradio.data_rate != profile.rate:
self.cradio.set_data_rate(profile.rate)
if self.cradio.address != profile.address:
self.cradio.set_address(profile.address)
return self.cradio.send_packet(data)
示例6: RadioDriver
# 需要导入模块: from cflib.drivers.crazyradio import Crazyradio [as 别名]
# 或者: from cflib.drivers.crazyradio.Crazyradio import close [as 别名]
#.........这里部分代码省略.........
return self.in_queue.get(True, time)
except queue.Empty:
return None
def send_packet(self, pk):
""" Send the packet pk though the link """
# if self.out_queue.full():
# self.out_queue.get()
if (self.cradio is None):
return
try:
self.out_queue.put(pk, True, 2)
except queue.Full:
if self.link_error_callback:
self.link_error_callback('RadioDriver: Could not send packet'
' to copter')
def pause(self):
self._thread.stop()
self._thread = None
def restart(self):
if self._thread:
return
self._thread = _RadioDriverThread(self.cradio, self.in_queue,
self.out_queue,
self.link_quality_callback,
self.link_error_callback,
self)
self._thread.start()
def close(self):
""" Close the link. """
# Stop the comm thread
self._thread.stop()
# Close the USB dongle
try:
if self.cradio:
self.cradio.close()
except:
# If we pull out the dongle we will not make this call
pass
self.cradio = None
while not self.out_queue.empty():
self.out_queue.get()
# Clear callbacks
self.link_error_callback = None
self.link_quality_callback = None
def _scan_radio_channels(self, start=0, stop=125):
""" Scan for Crazyflies between the supplied channels. """
return list(self.cradio.scan_channels(start, stop, (0xff,)))
def scan_selected(self, links):
to_scan = ()
for l in links:
one_to_scan = {}
uri_data = re.search('^radio://([0-9]+)((/([0-9]+))'
'(/(250K|1M|2M))?)?$',
l)