How to use the cflib.crtp.crtpstack.CRTPPacket function in cflib

To help you get started, we’ve selected a few cflib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitcraze / crazyflie-clients-python / src / cflib / cflib / bootloader / cloader.py View on Github external
def _update_info(self, target_id):
        """ Call the command getInfo and fill up the information received in
        the fields of the object
        """

        # Call getInfo ...
        pk = CRTPPacket()
        pk.set_header(0xFF, 0xFF)
        pk.data = (target_id, 0x10)
        self.link.send_packet(pk)

        # Wait for the answer
        pk = self.link.receive_packet(2)

        if (pk and pk.header == 0xFF and struct.unpack(" 22:
                self.targets[target_id].protocol_version = pk.datat[22]
github bitcraze / crazyflie-clients-python / src / cflib / cflib / bootloader / cloader.py View on Github external
pk.set_header(0xFF, 0xFF)
        pk.data = (target_id, 0xFF)
        self.link.send_packet(pk)

        pk = self.link.receive_packet(1)

        while ((not pk or pk.header != 0xFF or
                struct.unpack("= 0):
            pk = self.link.receive_packet(1)
            retry_counter -= 1

        if pk:
            new_address = (0xb1,) + struct.unpack("
github bitcraze / crazyflie-clients-python / src / cflib / cflib / crazyflie / log.py View on Github external
"""Callback for newly arrived packets with TOC information"""
        chan = packet.channel
        cmd = packet.data[0]
        payload = packet.data[1:]

        if (chan == CHAN_SETTINGS):
            id = payload[0]
            error_status = payload[1]
            block = self._find_block(id)
            if (cmd == CMD_CREATE_BLOCK):
                if (block is not None):
                    if error_status == 0 or error_status == errno.EEXIST:
                        if not block.added:
                            logger.debug("Have successfully added id=%d", id)

                            pk = CRTPPacket()
                            pk.set_header(5, CHAN_SETTINGS)
                            pk.data = (CMD_START_LOGGING, id, block.period)
                            self.cf.send_packet(pk, expected_reply=(
                                CMD_START_LOGGING, id))
                            block.added = True
                    else:
                        msg = self._err_codes[error_status]
                        logger.warning("Error %d when adding id=%d (%s)",
                                       error_status, id, msg)
                        block.err_no = error_status
                        block.added_cb.call(False)
                        block.error_cb.call(block, msg)

                else:
                    logger.warning("No LogEntry to assign block to !!!")
            if (cmd == CMD_START_LOGGING):
github bitcraze / crazyflie-clients-python / src / cflib / cflib / crazyflie / param.py View on Github external
def request_param_update(self, var_id):
        """Place a param update request on the queue"""
        pk = CRTPPacket()
        pk.set_header(CRTPPort.PARAM, READ_CHANNEL)
        pk.data = struct.pack('
github bitcraze / crazyflie-clients-python / src / cflib / cflib / crazyflie / log.py View on Github external
def create(self):
        """Save the log configuration in the Crazyflie"""
        pk = CRTPPacket()
        pk.set_header(5, CHAN_SETTINGS)
        pk.data = (CMD_CREATE_BLOCK, self.id)
        for var in self.variables:
            if (var.is_toc_variable() is False):  # Memory location
                logger.debug("Logging to raw memory %d, 0x%04X",
                             var.get_storage_and_fetch_byte(), var.address)
                pk.data.append(struct.pack('
github bitcraze / crazyflie-clients-python / src / cflib / cflib / bootloader / cloader.py View on Github external
def upload_buffer(self, target_id, page, address, buff):
        """Upload data into a buffer on the Crazyflie"""
        # print len(buff)
        count = 0
        pk = CRTPPacket()
        pk.set_header(0xFF, 0xFF)
        pk.data = struct.pack("=BBHH", target_id, 0x14, page, address)

        for i in range(0, len(buff)):
            pk.data.append(buff[i])

            count += 1

            if count > 24:
                self.link.send_packet(pk)
                count = 0
                pk = CRTPPacket()
                pk.set_header(0xFF, 0xFF)
                pk.data = struct.pack("=BBHH", target_id, 0x14, page,
                                      i + address + 1)
github bitcraze / crazyflie-clients-python / src / cflib / cflib / crazyflie / platformservice.py View on Github external
def set_continous_wave(self, enabled):
        """
        Enable/disable the client side X-mode. When enabled this recalculates
        the setpoints before sending them to the Crazyflie.
        """
        pk = CRTPPacket()
        pk.set_header(CRTPPort.PLATFORM, 0)
        pk.data = (0, enabled)
        self._cf.send_packet(pk)
github bitcraze / crazyflie-clients-python / src / cflib / cflib / bootloader / cloader.py View on Github external
def reset_to_bootloader1(self, cpu_id):
        """ Reset to the bootloader
        The parameter cpuid shall correspond to the device to reset.

        Return true if the reset has been done and the contact with the
        bootloader is established.
        """
        # Send an echo request and wait for the answer
        # Mainly aim to bypass a bug of the crazyflie firmware that prevents
        # reset before normal CRTP communication
        pk = CRTPPacket()
        pk.port = CRTPPort.LINKCTRL
        pk.data = (1, 2, 3) + cpu_id
        self.link.send_packet(pk)

        pk = None
        while True:
            pk = self.link.receive_packet(2)
            if not pk:
                return False

            if pk.port == CRTPPort.LINKCTRL:
                break

        # Send the reset to bootloader request
        pk = CRTPPacket()
        pk.set_header(0xFF, 0xFF)
github bitcraze / crazyflie-clients-python / src / cflib / cflib / crazyflie / mem.py View on Github external
self._refresh_callback = refresh_done_callback
        self._fetch_id = 0
        for m in self.mems:
            try:
                self.mem_read_cb.remove_callback(m.new_data)
                m.disconnect()
            except Exception as e:
                logger.info(
                    "Error when removing memory after update: {}".format(e))
        self.mems = []

        self.nbr_of_mems = 0
        self._getting_count = False

        logger.info("Requesting number of memories")
        pk = CRTPPacket()
        pk.set_header(CRTPPort.MEM, CHAN_INFO)
        pk.data = (CMD_INFO_NBR,)
        self.cf.send_packet(pk, expected_reply=(CMD_INFO_NBR,))
github bitcraze / crazyflie-clients-python / src / cflib / cflib / bootloader / cloader.py View on Github external
def reset_to_firmware(self, target_id):
        """ Reset to firmware
        The parameter cpuid shall correspond to the device to reset.

        Return true if the reset has been done
        """
        # The fake CPU ID is legacy from the Crazyflie 1.0
        # In order to reset the CPU id had to be sent, but this
        # was removed before launching it. But the length check is
        # still in the bootloader. So to work around this bug so
        # some extra data needs to be sent.
        fake_cpu_id = (1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12)
        # Send the reset to bootloader request
        pk = CRTPPacket()
        pk.set_header(0xFF, 0xFF)
        pk.data = (target_id, 0xFF) + fake_cpu_id
        self.link.send_packet(pk)

        # Wait to ack the reset ...
        pk = None
        while True:
            pk = self.link.receive_packet(2)
            if not pk:
                return False

            if (pk.header == 0xFF and struct.unpack(
                    "B" * len(pk.data), pk.data)[:2] == (target_id, 0xFF)):
                # Difference in CF1 and CF2 (CPU ID)
                if target_id == 0xFE:
                    pk.data = (target_id, 0xF0, 0x01)