Format packet to be sent.
483850
def format_packet(command):
        """"""
        frame_header = b"\xaa"
        verify = b"\x0b"
        send_delim = b"\xbb"
        return frame_header + command.ljust(17, b"\x00") + verify + send_delim
839402
def packet(tag, blob):
    """"""
    assert len(blob) < 2**32

    if len(blob) < 2**8:
        length_type = 0
    elif len(blob) < 2**16:
        length_type = 1
    else:
        length_type = 2

    fmt = ['>B', '>H', '>L'][length_type]
    leading_byte = 0x80 | (tag << 2) | (length_type)
    return struct.pack('>B', leading_byte) + util.prefix_len(fmt, blob)
128462
async def send_data(self):
        """"""
        self.connection._ensure_alive()
        conn = self.connection

        try:
            await self._open_file()
            with self._file_object:
                chunk_size = MAX_PACKET_LEN
                while True:
                    chunk = await self._file_read(chunk_size)
                    if not chunk:
                        break
                    # TODO: consider drain data
                    conn.write_packet(chunk)
        except asyncio.CancelledError:
            self.connection._close_on_cancel()
            raise
        finally:
            # send the empty packet to signify we are done sending data
            conn.write_packet(b"")
1264416
def _write_packet(self, packet, sec=None, usec=None, caplen=None, wirelen=None):
        
        if caplen is None:
            caplen = len(packet)
        if wirelen is None:
            wirelen = caplen
        if sec is None or usec is None:
            t=time.time()
            it = int(t)
            if sec is None:
                sec = it
            if usec is None:
                usec = int(round((t-it)*1000000))
        self.f.write(struct.pack(self.endian+"IIII", sec, usec, caplen, wirelen))
        self.f.write(packet)
        if self.gz and self.sync:
            self.f.flush()
939126
def packet_queue(self, pkt):
        """"""
        
        pkt.pos = 0
        pkt.to_process = pkt.packet_length
        
        self.out_packet.append(pkt)
        return NC.ERR_SUCCESS
494205
def to_bytes(self):
        '''
        
        '''
        return struct.pack(UDP._PACKFMT, self._src, self._dst,
            self._len, self._checksum)
8787
def sendcommand(self, command, datalength=0, data=None):
        ''''''
        packet = chr(Vendapin.STX) + chr(Vendapin.ADD) + chr(command) + chr(datalength)
        if datalength > 0:
            packet += chr(data)
        packet += chr(Vendapin.ETX)
        sendpacket = packet + chr(self._checksum(packet))
        self._printpacket(sendpacket)
        self.serial.write(sendpacket)
35416
def format(self, formatstring, *args):
        """"""

        # Make a new section
        if self.incoming_section:
            self.SendMessage(['s', {'name': args}])
            self.incoming_section = False
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)
176410
def seek_to_packet(self, index):
        """"""
        pointer_position = self.packet_positions[index]
        self.blob_file.seek(pointer_position, 0)
237559
def incoming(self, packet):
        
        # This might be done prettier ;-)
        console_text = packet.data.decode('UTF-8')

        self.receivedChar.call(console_text)
931767
def makeResetPacket(ID, param):
	
	if param not in [0x01, 0x02, 0xff]:
		raise Exception('Packet.makeResetPacket invalide parameter {}'.format(param))
	# pkt = makePacket(ID, xl320.XL320_RESET, None, [param])
	pkt = makePacket(ID, xl320.XL320_RESET, None, [1])
	return pkt
309247
def _send_size(self):
        "  "
        rows, cols = _get_size(sys.stdout.fileno())
        self._send_packet({
            'cmd': 'size',
            'data': [rows, cols]
        })
238752
def _handle_raw_packet(self, raw_packet):
        """"""
        if raw_packet[1:2] == b'\x1f':
            self._reset_timeout()
            year = raw_packet[2]
            month = raw_packet[3]
            day = raw_packet[4]
            hour = raw_packet[5]
            minute = raw_packet[6]
            sec = raw_packet[7]
            week = raw_packet[8]
            self.logger.debug(
                'received date: Year: %s, Month: %s, Day: %s, Hour: %s, '
                'Minute: %s, Sec: %s, Week %s',
                year, month, day, hour, minute, sec, week)
        elif raw_packet[1:2] == b'\x0c':
            states = {}
            changes = []
            for switch in range(0, 16):
                if raw_packet[2+switch:3+switch] == b'\x01':
                    states[format(switch, 'x')] = True
                    if (self.client.states.get(format(switch, 'x'), None)
                            is not True):
                        changes.append(format(switch, 'x'))
                        self.client.states[format(switch, 'x')] = True
                elif raw_packet[2+switch:3+switch] == b'\x02':
                    states[format(switch, 'x')] = False
                    if (self.client.states.get(format(switch, 'x'), None)
                            is not False):
                        changes.append(format(switch, 'x'))
                        self.client.states[format(switch, 'x')] = False
            for switch in changes:
                for status_cb in self.client.status_callbacks.get(switch, []):
                    status_cb(states[switch])
            self.logger.debug(states)
            if self.client.in_transaction:
                self.client.in_transaction = False
                self.client.active_packet = False
                self.client.active_transaction.set_result(states)
                while self.client.status_waiters:
                    waiter = self.client.status_waiters.popleft()
                    waiter.set_result(states)
                if self.client.waiters:
                    self.send_packet()
                else:
                    self._cmd_timeout.cancel()
            elif self._cmd_timeout:
                self._cmd_timeout.cancel()
        else:
            self.logger.warning('received unknown packet: %s',
                                binascii.hexlify(raw_packet))
868185
def sam_send(sock, line_and_data):
    """"""
    if isinstance(line_and_data, tuple):
        line, data = line_and_data
    else:
        line, data = line_and_data, b''

    line = bytes(line, encoding='ascii') + b' \n'
    # print('-->', line, data)
    sock.sendall(line + data)
425346
def format_payload(enc, **kwargs):
    '''
    
    '''
    payload = {'enc': enc}
    load = {}
    for key in kwargs:
        load[key] = kwargs[key]
    payload['load'] = load
    return package(payload)
1329578
def send_one_packet(old_packet = nil)
      pf = packet_format
      raise(Errors::NotImplemented, "Unimplemented packet format: #{pf}") unless IMPLEMENTED_FORMATS.include?(pf)

      write('APISPK')

      case pf
      when :list
        read(:expect => /^.*<EOP>$/, :wait => true)
      when :bin48_net_time
        packet = read(:length => 625, :wait => true)
        Packet::Bin48NetTime.read(StringIO.new(packet), old_packet)
      when :bin48_net
        packet = read(:length => 619, :wait => true)
        Packet::Bin48Net.read(StringIO.new(packet), old_packet)
      when :bin48_abs
        packet = read(:length => 379, :wait => true)
        Packet::Bin48Abs.read(StringIO.new(packet), old_packet)
      when :bin32_net
        packet = read(:length => 429, :wait => true)
        Packet::Bin32Net.read(StringIO.new(packet), old_packet)
      when :bin32_abs
        packet = read(:length => 269, :wait => true)
        Packet::Bin32Abs.read(StringIO.new(packet), old_packet)
      end
    end