當前位置: 首頁>>代碼示例>>Python>>正文


Python Crazyradio.send_packet方法代碼示例

本文整理匯總了Python中cflib.drivers.crazyradio.Crazyradio.send_packet方法的典型用法代碼示例。如果您正苦於以下問題:Python Crazyradio.send_packet方法的具體用法?Python Crazyradio.send_packet怎麽用?Python Crazyradio.send_packet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cflib.drivers.crazyradio.Crazyradio的用法示例。


在下文中一共展示了Crazyradio.send_packet方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _RadioTransferThread

# 需要導入模塊: from cflib.drivers.crazyradio import Crazyradio [as 別名]
# 或者: from cflib.drivers.crazyradio.Crazyradio import send_packet [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)
開發者ID:Venris,項目名稱:crazyflie-multilink,代碼行數:73,代碼來源:radiodriver.py


注:本文中的cflib.drivers.crazyradio.Crazyradio.send_packet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。