xref: /btstack/platform/daemon/binding/java/src/com/bluekitchen/btstack/Packet.java (revision 8257e5f9e1a9f15ac2fe1e69adc5d2eeeadf3fff)
1 package com.bluekitchen.btstack;
2 
3 public class Packet {
4 
5 	public static final int HCI_COMMAND_PACKET = 1;
6 	public static final int HCI_EVENT_PACKET   = 4;
7 	public static final int L2CAP_DATA_PACKET  = 6;
8 	public static final int RFCOMM_DATA_PACKET = 7;
9 
10 	protected byte[] data;
11 	protected int payloadLen;
12 	protected int packetType;
13 	protected int channel;
14 
getPacketType()15 	public final int getPacketType() {
16 		return packetType;
17 	}
18 
getBuffer()19 	public final byte[] getBuffer() {
20 		return data;
21 	}
22 
getPayloadLen()23 	public final int getPayloadLen(){
24 		return payloadLen;
25 	}
26 
getChannel()27 	public final int getChannel() {
28 		return channel;
29 	}
30 
Packet(int packetType, int channel, byte[] buffer, int payloadLen)31 	public Packet(int packetType, int channel, byte[] buffer, int payloadLen){
32 		this.packetType = packetType;
33 		this.channel = channel;
34 		this.data = new byte[payloadLen];
35 		System.arraycopy(buffer, 0, this.data, 0, payloadLen);
36 		this.payloadLen = payloadLen;
37 	}
38 
toString()39 	public String toString(){
40 		StringBuffer t = new StringBuffer();
41 		t.append(String.format("Packet %d, channel %d, len %d: ", packetType, channel, payloadLen));
42 		t.append(Util.asHexdump(data, payloadLen));
43 		return t.toString();
44 	}
45 
dump()46 	public void dump(){
47 		System.out.println(this.toString());
48 	}
49 }
50