support variable size string as last field in events in java

This commit is contained in:
matthias.ringwald@gmail.com 2014-12-05 22:37:20 +00:00
parent b708eb2d59
commit 5d36487038
4 changed files with 23 additions and 3 deletions

View File

@ -402,9 +402,10 @@ extern "C" {
// data: event(8), len(8), rfcomm channel(8), name(var) // data: event(8), len(8), rfcomm channel(8), name(var)
/** /**
* TODO: format for variable data * @format 1T
* @param rfcomm_channel * @param rfcomm_channel
* @param name * @param name
* @brief SDP_QUERY_RFCOMM_SERVICE 0x92
*/ */
#define SDP_QUERY_RFCOMM_SERVICE 0x92 #define SDP_QUERY_RFCOMM_SERVICE 0x92

View File

@ -10,6 +10,11 @@ public class Event extends Packet {
super(HCI_EVENT_PACKET, 0, packet.getBuffer(), packet.getPayloadLen()); super(HCI_EVENT_PACKET, 0, packet.getBuffer(), packet.getPayloadLen());
} }
/**
* @param
* @return eventType as int
* @brief
*/
public final int getEventType(){ public final int getEventType(){
return Util.readByte(data, 0); return Util.readByte(data, 0);
} }

View File

@ -147,4 +147,13 @@ public class Util {
public static byte[] serviceSearchPatternForUUID16(int uuid){ public static byte[] serviceSearchPatternForUUID16(int uuid){
return new byte[] {(byte)0x35, (byte)0x03, (byte)0x19, (byte) (uuid >> 8), (byte) (uuid & 0xff)}; return new byte[] {(byte)0x35, (byte)0x03, (byte)0x19, (byte) (uuid >> 8), (byte) (uuid & 0xff)};
} }
public static byte[] getBytes(byte[] buffer, int offset, int length){
return Arrays.copyOfRange(buffer, offset, offset + length);
}
public static String getText(byte[] buffer, int offset, int length){
byte [] byteData = getBytes(buffer, offset, length);
return new String(byteData, "UTF-8");
}
} }

View File

@ -96,6 +96,9 @@ public class {1} extends Event {{
java_event_getter = \ java_event_getter = \
''' '''
/**
* @return {1} as {0}
{rest}
public {0} get{1}(){{ public {0} get{1}(){{
{2} {2}
}} }}
@ -172,12 +175,13 @@ def java_type_for_btstack_type(type):
'D' : 'byte []', 'E' : 'byte [] ', 'N' : 'String' , 'P' : 'byte []', 'A' : 'byte []', 'D' : 'byte []', 'E' : 'byte [] ', 'N' : 'String' , 'P' : 'byte []', 'A' : 'byte []',
'R' : 'byte []', 'S' : 'byte []', 'R' : 'byte []', 'S' : 'byte []',
'J' : 'int', 'L' : 'int', 'V' : 'byte []', 'U' : 'BT_UUID', 'J' : 'int', 'L' : 'int', 'V' : 'byte []', 'U' : 'BT_UUID',
'X' : 'GATTService', 'Y' : 'GATTCharacteristic', 'Z' : 'GATTCharacteristicDescriptor' } 'X' : 'GATTService', 'Y' : 'GATTCharacteristic', 'Z' : 'GATTCharacteristicDescriptor',
'T' : 'String'}
return param_types[type] return param_types[type]
def size_for_type(type): def size_for_type(type):
param_sizes = { '1' : 1, '2' : 2, '3' : 3, '4' : 4, 'H' : 2, 'B' : 6, 'D' : 8, 'E' : 240, 'N' : 248, 'P' : 16, param_sizes = { '1' : 1, '2' : 2, '3' : 3, '4' : 4, 'H' : 2, 'B' : 6, 'D' : 8, 'E' : 240, 'N' : 248, 'P' : 16,
'A' : 31, 'S' : -1, 'V': -1, 'J' : 1, 'L' : 2, 'U' : 16, 'X' : 20, 'Y' : 24, 'Z' : 18} 'A' : 31, 'S' : -1, 'V': -1, 'J' : 1, 'L' : 2, 'U' : 16, 'X' : 20, 'Y' : 24, 'Z' : 18, 'T':-1}
return param_sizes[type] return param_sizes[type]
def create_command_java(fout, name, ogf, ocf, format, params): def create_command_java(fout, name, ogf, ocf, format, params):
@ -331,6 +335,7 @@ def create_event(event_name, format, args):
'X' : 'return Util.readGattService(data, %u);', 'X' : 'return Util.readGattService(data, %u);',
'Y' : 'return Util.readGattCharacteristic(data, %u);', 'Y' : 'return Util.readGattCharacteristic(data, %u);',
'Z' : 'return Util.readGattCharacteristicDescriptor(data, %u);', 'Z' : 'return Util.readGattCharacteristicDescriptor(data, %u);',
'T' : 'int offset = %u; \n return Util.getText(data, offset, getPayloadLen()-offset);',
# 'D' : 'Util.storeBytes(data, %u, 8);', # 'D' : 'Util.storeBytes(data, %u, 8);',
# 'E' : 'Util.storeBytes(data, %u, 240);', # 'E' : 'Util.storeBytes(data, %u, 240);',
# 'N' : 'Util.storeString(data, %u, 248);', # 'N' : 'Util.storeString(data, %u, 248);',