Send a packet and receive the ack from the radio dongle
            The ack contains information about the packet transmition
            and a data payload if the ack packet contained any
548963
def send_packet(self, dataOut):
        
        ackIn = None
        data = None
        try:
            if (pyusb1 is False):
                self.handle.bulkWrite(1, dataOut, 1000)
                data = self.handle.bulkRead(0x81, 64, 1000)
            else:
                self.handle.write(endpoint=1, data=dataOut, timeout=1000)
                data = self.handle.read(0x81, 64, timeout=1000)
        except usb.USBError:
            pass

        if data is not None:
            ackIn = _radio_ack()
            if data[0] != 0:
                ackIn.ack = (data[0] & 0x01) != 0
                ackIn.powerDet = (data[0] & 0x02) != 0
                ackIn.retry = data[0] >> 4
                ackIn.data = data[1:]
            else:
                ackIn.retry = self.arc

        return ackIn
51892
def _push_packet(self, packet):
        
        self._read_queue.append((decode(packet), packet))

        if self._read_waiter is not None:
            w, self._read_waiter = self._read_waiter, None
            w.set_result(None)
218182
def handle_event(self, packet):
        """"""
        if packet.get('command'):
            task = self.send_command_ack(packet['id'], packet['command'])
            self.loop.create_task(task)
235782
def receive_data(data)
      #append data to buffer
      @data << data

      while (@data.length >=4)
        cmd_length = @data[0..3].unpack('N').first
        if(@data.length < cmd_length)
          #not complete packet ... break
          break
        end

        pkt = @data.slice!(0,cmd_length)

        begin
          # parse incoming PDU
          pdu = read_pdu(pkt)

          # let subclass process it
          process_pdu(pdu) if pdu
        rescue Exception => e
          logger.error "Error receiving data: #{e}\n#{e.backtrace.join("\n")}"
          run_callback(:data_error, e)
        end

      end
    end
1066321
def send(self, data):
        """"""
        bytes_sent = self._sock.send(extract_bytes(data))
        self.bytes_written += bytes_sent
        return bytes_sent
24908
def receive_packet
      # Poll socket - is there data waiting?
      result = IO.select([@socket], [], [], SELECT_TIMEOUT)
      unless result.nil?
        # Yes - read in the packet
        packet = MQTT::Packet.read(@socket)
        handle_packet packet
      end
      keep_alive!
    # Pass exceptions up to parent thread
    rescue Exception => exp
      unless @socket.nil?
        @socket.close
        @socket = nil
      end
      Thread.current[:parent].raise(exp)
    end
95370
function(data) {
    /* 
     * Here we handle the beginning of the transmission
     * The receiver initiates the transfer by either calling
     * checksum mode or CRC mode.
     */
    if(data[0] === CRC_MODE && blockNumber === _self.XMODEM_START_BLOCK) {
      log.info("[SEND] - received C byte for CRC transfer!");
      _self.XMODEM_OP_MODE = 'crc';
      if(packagedBuffer.length > blockNumber) {
        /**
         * Transmission Start event. A successful start of transmission.
         * @event Xmodem#start
         * @property {string} - Indicates transmission mode 'crc' or 'normal'
         */
        _self.emit('start', _self.XMODEM_OP_MODE);
        sendBlock(socket, blockNumber, packagedBuffer[blockNumber], _self.XMODEM_OP_MODE);
        _self.emit('status', { action: 'send', signal: 'SOH', block: blockNumber });
        blockNumber++;
      }
    }
    else if(data[0] === NAK && blockNumber === _self.XMODEM_START_BLOCK) {
      log.info("[SEND] - received NAK byte for standard checksum transfer!");
      _self.XMODEM_OP_MODE = 'normal';
      if(packagedBuffer.length > blockNumber) {
        _self.emit('start', _self.XMODEM_OP_MODE);
        sendBlock(socket, blockNumber, packagedBuffer[blockNumber], _self.XMODEM_OP_MODE);
        _self.emit('status', { action: 'send', signal: 'SOH', block: blockNumber });
        blockNumber++;
      }
    }
    /*
     * Here we handle the actual transmission of data and
     * retransmission in case the block was not accepted.
     */
    else if(data[0] === ACK && blockNumber > _self.XMODEM_START_BLOCK) {
      // Woohooo we are ready to send the next block! :)
      log.info('ACK RECEIVED');
      _self.emit('status', { action: 'recv', signal: 'ACK' });
      if(packagedBuffer.length > blockNumber) {
        sendBlock(socket, blockNumber, packagedBuffer[blockNumber], _self.XMODEM_OP_MODE);
        _self.emit('status', { action: 'send', signal: 'SOH', block: blockNumber });
        blockNumber++;
      }
      else if(packagedBuffer.length === blockNumber) {
        // We are EOT
        if(sent_eof === false) {
          sent_eof = true;
          log.info("WE HAVE RUN OUT OF STUFF TO SEND, EOT EOT!");
          _self.emit('status', { action: 'send', signal: 'EOT' });
          socket.write(new Buffer([EOT]));
        }
        else {
          // We are finished!
          log.info('[SEND] - Finished!');
          _self.emit('stop', 0);
          socket.removeListener('data', sendData);
        }
      }
    }
    else if(data[0] === NAK && blockNumber > _self.XMODEM_START_BLOCK) {
      if (blockNumber === packagedBuffer.length && sent_eof) {
        log.info('[SEND] - Resending EOT, because receiver responded with NAK.');
        _self.emit('status', { action: 'send', signal: 'EOT' });
        socket.write(new Buffer([EOT]));
      } else {
        log.info('[SEND] - Packet corruption detected, resending previous block.');
        _self.emit('status', { action: 'recv', signal: 'NAK' });
        blockNumber--;
        if(packagedBuffer.length > blockNumber) {
          sendBlock(socket, blockNumber, packagedBuffer[blockNumber], _self.XMODEM_OP_MODE);
          _self.emit('status', { action: 'send', signal: 'SOH', block: blockNumber });
          blockNumber++;
        }
      }
    }
    else {
      log.warn("GOT SOME UNEXPECTED DATA which was not handled properly!");
      log.warn("===>");
      log.warn(data);
      log.warn("<===");
      log.warn("blockNumber: " + blockNumber);
    }
  }
129169
def send_packet(self, packet):
        
        if self.log_packet_level:
            logger.log(self.log_packet_level, "-> %s", packet)
        serialised = packet.serialise_packet()
        self.event_handler.broadcast_event("raw_outbound", serialised)
        self.send_raw(serialised)
760577
function receive(msg, rinfo){
    var packet = lob.decloak(msg);
    if(!packet) packet = lob.decode(msg); // accept un-encrypted discovery broadcast hints
    if(!packet) return mesh.log.info('dropping invalid packet from',rinfo,msg.toString('hex'));
    tp.pipe(false, {type:'udp4',ip:rinfo.address,port:rinfo.port}, function(pipe){
      mesh.receive(packet, pipe);
    });
  }
302732
def send_packet(self, dev, packet):
        '''
        
        '''
        if packet is None:
            raise ValueError("No packet object given to send_packet")
        if not isinstance(packet, Packet):
            raise ValueError("Object given to send_packet is not a Packet (it is: {})".format(type(packet)))
 
        intf = None
        if isinstance(dev, int):
           dev = self._lookup_devname(dev)

        if isinstance(dev, Interface):
            intf = dev
            dev = dev.name
        elif dev in self._devinfo:
            intf = self.interface_by_name(dev)
        else:
            raise ValueError("Unrecognized device name for packet send: {}".format(dev))

        if intf.iftype == InterfaceType.Loopback:
            pdev = self._localsend.get(dev, None)
            pdev.send_packet(packet)
        else:
            pdev = self._pcaps.get(dev, None)
            rawpkt = packet.to_bytes()
            log_debug("Sending packet on device {}: {}".format(dev, str(packet)))
            pdev.send_packet(rawpkt)
1086462
def send_packet(self, pk):
        
        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')
199173
def send_and_receive(self, req):
        
        rx_data = self._send_and_receive(target=req.target,
                                         lun=req.lun,
                                         netfn=req.netfn,
                                         cmdid=req.cmdid,
                                         payload=encode_message(req))
        rsp = create_message(req.netfn + 1, req.cmdid, req.group_extension)
        decode_message(rsp, rx_data)
        return rsp
268139
def send_rsp_recv_cmd(self, target, data, timeout):
        
        return super(Device, self).send_rsp_recv_cmd(target, data, timeout)
945630
def receive(self, decode=True):
        
        payload = self.socket.recv()
        payload = self.verify(payload)
        if decode:
            payload = self.decode(payload)
        return payload
21134
def receive(self, ikpdb):
        
        # with self._connection_lock:
        while self._network_loop:
            _logger.n_debug("Enter socket.recv(%s) with self._received_data = %s", 
                            self.SOCKET_BUFFER_SIZE, 
                            self._received_data)
            try:
                # We may land here with a full packet already in self.received_data
                # In that case we must not enter recv() 
                if self.SOCKET_BUFFER_SIZE:
                    data = self._connection.recv(self.SOCKET_BUFFER_SIZE)
                else:
                    data = b''
                _logger.n_debug("Socket.recv(%s) => %s", self.SOCKET_BUFFER_SIZE, data)

            except socket.timeout:
                _logger.n_debug("socket.timeout witk ikpdb.status=%s", ikpdb.status)
                if ikpdb.status == 'terminated':
                    _logger.n_debug("breaking IKPdbConnectionHandler.receive() "
                                    "network loop as ikpdb state is 'terminated'.")
                    return {    
                        'command': '_InternalQuit',
                        'args':{}
                    }
                continue

            except socket.error as socket_err:
                if ikpdb.status == 'terminated':
                    return {'command': '_InternalQuit', 
                            'args':{'socket_error_number': socket_err.errno,
                                    'socket_error_str': socket_err.strerror}}
                continue
            
            except Exception as exc:
                _logger.g_error("Unexecpected Error: '%s' in IKPdbConnectionHandler"
                                ".command_loop.", exc)
                _logger.g_error(traceback.format_exc())
                print("".join(traceback.format_stack()))
                return {    
                    'command': '_InternalQuit',
                    'args':{
                        "error": exc.__class__.__name__,
                        "message": exc.message
                    }
                }
    
            # received data is utf8 encoded
            self._received_data += data.decode('utf-8')
                
            # have we received a MAGIC_CODE
            try:
                magic_code_idx = self._received_data.index(self.MAGIC_CODE)
            except ValueError:
                continue
            
            # Have we received a 'length='
            try:
                length_idx = self._received_data.index(u'length=')
            except ValueError:
                continue
            
            # extract length content from received data
            json_length = int(self._received_data[length_idx + 7:magic_code_idx])
            message_length = magic_code_idx + len(self.MAGIC_CODE) + json_length
            if message_length <= len(self._received_data):
                full_message = self._received_data[:message_length]
                self._received_data = self._received_data[message_length:]
                if len(self._received_data) > 0:
                    self.SOCKET_BUFFER_SIZE = 0
                else:
                    self.SOCKET_BUFFER_SIZE = 4096
                break
            else:
                self.SOCKET_BUFFER_SIZE = message_length - len(self._received_data)

        self.log_received(full_message)
        obj = self.decode(full_message)
        return obj
199028
def send_packet(data)
      # Raise exception if we aren't connected
      raise MQTT::NotConnectedException unless connected?

      # Only allow one thread to write to socket at a time
      @write_semaphore.synchronize do
        @socket.write(data.to_s)
      end
    end
404849
def send_raw_packet(self, packet: str):
        """"""
        data = packet + '\r\n'
        log.debug('writing data: %s', repr(data))
        self.transport.write(data.encode())