added l2cap, rfcomm data packet & send

This commit is contained in:
mila@ringwald.ch 2014-12-04 16:20:57 +00:00
parent a8c5ee2406
commit 5600833267
4 changed files with 35 additions and 1 deletions

View File

@ -95,6 +95,14 @@ public class BTstackClient {
if (socketConnection == null) return false;
return socketConnection.sendPacket(packet);
}
public boolean L2CAPSendData(int l2capChannelID, byte[] data){
return sendPacket(new L2CAPDataPacket(l2capChannelID, data));
}
public boolean RFCOMMSendData(int rfcommChannelID, byte[] data){
return sendPacket(new RFCOMMDataPacket(rfcommChannelID, data));
}
public void disconnect(){
if (socketConnection == null) return;

View File

@ -0,0 +1,12 @@
package com.bluekitchen.btstack;
public class L2CAPDataPacket extends Packet {
public L2CAPDataPacket(int channel, byte data[]){
super(L2CAP_DATA_PACKET, channel, data, data.length);
}
public L2CAPDataPacket(Packet packet){
super(L2CAP_DATA_PACKET, packet.getChannel(), packet.getBuffer(), packet.getPayloadLen());
}
}

View File

@ -4,6 +4,8 @@ public class Packet {
public static final int HCI_COMMAND_PACKET = 1;
public static final int HCI_EVENT_PACKET = 4;
public static final int L2CAP_DATA_PACKET = 6;
public static final int RFCOMM_DATA_PACKET = 7;
protected byte[] data;
protected int payloadLen;
@ -31,7 +33,6 @@ public class Packet {
this.channel = channel;
this.data = new byte[payloadLen];
System.arraycopy(buffer, 0, this.data, 0, payloadLen);
this.data = buffer;
this.payloadLen = payloadLen;
}

View File

@ -0,0 +1,13 @@
package com.bluekitchen.btstack;
public class RFCOMMDataPacket extends Packet {
public RFCOMMDataPacket(int channel, byte data[]){
super(RFCOMM_DATA_PACKET, channel, data, data.length);
}
public RFCOMMDataPacket(Packet packet){
super(RFCOMM_DATA_PACKET, packet.getChannel(), packet.getBuffer(), packet.getPayloadLen());
}
}