diff options
author | Sven Gothel <[email protected]> | 2020-05-31 21:32:48 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-31 21:32:48 +0200 |
commit | 9ae37c02afdcd6344f32e823e40f9ee8c4a9ae0a (patch) | |
tree | 81ea71505b897fd8c57702e9d8bd53fa69116a95 | |
parent | f76ad2569b3c57a8da3165c7ce79ad9a8a34d9b7 (diff) |
HCIErrorCode (Java): Use byte native value (uint8_t) and fast switch/case value mapping
-rw-r--r-- | java/jni/direct_bt/DBTAdapter.cxx | 4 | ||||
-rw-r--r-- | java/org/tinyb/HCIErrorCode.java | 216 |
2 files changed, 142 insertions, 78 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx index ba0862d4..8da84686 100644 --- a/java/jni/direct_bt/DBTAdapter.cxx +++ b/java/jni/direct_bt/DBTAdapter.cxx @@ -41,7 +41,7 @@ static const std::string _adapterSettingsClazzCtorArgs("(I)V"); static const std::string _eirDataTypeSetClassName("org/tinyb/EIRDataTypeSet"); static const std::string _eirDataTypeSetClazzCtorArgs("(I)V"); static const std::string _hciErrorCodeClassName("org/tinyb/HCIErrorCode"); -static const std::string _hciErrorCodeClazzGetArgs("(I)Lorg/tinyb/HCIErrorCode;"); +static const std::string _hciErrorCodeClazzGetArgs("(B)Lorg/tinyb/HCIErrorCode;"); static const std::string _deviceClazzCtorArgs("(JLdirect_bt/tinyb/DBTAdapter;Ljava/lang/String;ILjava/lang/String;J)V"); static const std::string _adapterSettingsChangedMethodArgs("(Lorg/tinyb/BluetoothAdapter;Lorg/tinyb/AdapterSettings;Lorg/tinyb/AdapterSettings;Lorg/tinyb/AdapterSettings;J)V"); @@ -334,7 +334,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener { env->SetLongField(jdevice, deviceClazzTSUpdateField, (jlong)timestamp); java_exception_check_and_throw(env, E_FILE_LINE); - jobject hciErrorCode = env->CallStaticObjectMethod(hciErrorCodeClazzRef->getClass(), hciErrorCodeClazzGet, (jint)static_cast<uint8_t>(reason)); + jobject hciErrorCode = env->CallStaticObjectMethod(hciErrorCodeClazzRef->getClass(), hciErrorCodeClazzGet, (jbyte)static_cast<uint8_t>(reason)); java_exception_check_and_throw(env, E_FILE_LINE); JNIGlobalRef::check(hciErrorCode, E_FILE_LINE); diff --git a/java/org/tinyb/HCIErrorCode.java b/java/org/tinyb/HCIErrorCode.java index 01c80921..cb242a7a 100644 --- a/java/org/tinyb/HCIErrorCode.java +++ b/java/org/tinyb/HCIErrorCode.java @@ -32,76 +32,76 @@ package org.tinyb; * @since 2.0.0 */ public enum HCIErrorCode { - SUCCESS(0x00), - UNKNOWN_HCI_COMMAND(0x01), - UNKNOWN_CONNECTION_IDENTIFIER(0x02), - HARDWARE_FAILURE(0x03), - PAGE_TIMEOUT(0x04), - AUTHENTICATION_FAILURE(0x05), - PIN_OR_KEY_MISSING(0x06), - MEMORY_CAPACITY_EXCEEDED(0x07), - CONNECTION_TIMEOUT(0x08), - CONNECTION_LIMIT_EXCEEDED(0x09), - SYNC_DEVICE_CONNECTION_LIMIT_EXCEEDED(0x0a), - CONNECTION_ALREADY_EXISTS(0x0b), - COMMAND_DISALLOWED(0x0c), - CONNECTION_REJECTED_LIMITED_RESOURCES(0x0d), - CONNECTION_REJECTED_SECURITY(0x0e), - CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR(0x0f), - CONNECTION_ACCEPT_TIMEOUT_EXCEEDED(0x10), - UNSUPPORTED_FEATURE_OR_PARAM_VALUE(0x11), - INVALID_HCI_COMMAND_PARAMETERS(0x12), - REMOTE_USER_TERMINATED_CONNECTION(0x13), - REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES(0x14), - REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF(0x15), - CONNECTION_TERMINATED_BY_LOCAL_HOST(0x16), - REPEATED_ATTEMPTS(0x17), - PAIRING_NOT_ALLOWED(0x18), - UNKNOWN_LMP_PDU(0x19), - UNSUPPORTED_REMOTE_OR_LMP_FEATURE(0x1a), - SCO_OFFSET_REJECTED(0x1b), - SCO_INTERVAL_REJECTED(0x1c), - SCO_AIR_MODE_REJECTED(0x1d), - INVALID_LMP_OR_LL_PARAMETERS(0x1e), - UNSPECIFIED_ERROR(0x1f), - UNSUPPORTED_LMP_OR_LL_PARAMETER_VALUE(0x20), - ROLE_CHANGE_NOT_ALLOWED(0x21), - LMP_OR_LL_RESPONSE_TIMEOUT(0x22), - LMP_OR_LL_COLLISION(0x23), - LMP_PDU_NOT_ALLOWED(0x24), - ENCRYPTION_MODE_NOT_ACCEPTED(0x25), - LINK_KEY_CANNOT_BE_CHANGED(0x26), - REQUESTED_QOS_NOT_SUPPORTED(0x27), - INSTANT_PASSED(0x28), - PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED(0x29), - DIFFERENT_TRANSACTION_COLLISION(0x2a), - QOS_UNACCEPTABLE_PARAMETER(0x2c), - QOS_REJECTED(0x2d), - CHANNEL_ASSESSMENT_NOT_SUPPORTED(0x2e), - INSUFFICIENT_SECURITY(0x2f), - PARAMETER_OUT_OF_RANGE(0x30), - ROLE_SWITCH_PENDING(0x32), - RESERVED_SLOT_VIOLATION(0x34), - ROLE_SWITCH_FAILED(0x35), - EIR_TOO_LARGE(0x36), - SIMPLE_PAIRING_NOT_SUPPORTED_BY_HOST(0x37), - HOST_BUSY_PAIRING(0x38), - CONNECTION_REJECTED_NO_SUITABLE_CHANNEL(0x39), - CONTROLLER_BUSY(0x3a), - UNACCEPTABLE_CONNECTION_PARAM(0x3b), - ADVERTISING_TIMEOUT(0x3c), - CONNECTION_TERMINATED_MIC_FAILURE(0x3d), - CONNECTION_EST_FAILED_OR_SYNC_TIMETOUT(0x3e), - MAX_CONNECTION_FAILED (0x3f), - COARSE_CLOCK_ADJ_REJECTED(0x40), - TYPE0_SUBMAP_NOT_DEFINED(0x41), - UNKNOWN_ADVERTISING_IDENTIFIER(0x42), - LIMIT_REACHED(0x43), - OPERATION_CANCELLED_BY_HOST(0x44), - PACKET_TOO_LONG(0x45), - INTERNAL_FAILURE(0xff); + SUCCESS((byte) 0x00), + UNKNOWN_HCI_COMMAND((byte) 0x01), + UNKNOWN_CONNECTION_IDENTIFIER((byte) 0x02), + HARDWARE_FAILURE((byte) 0x03), + PAGE_TIMEOUT((byte) 0x04), + AUTHENTICATION_FAILURE((byte) 0x05), + PIN_OR_KEY_MISSING((byte) 0x06), + MEMORY_CAPACITY_EXCEEDED((byte) 0x07), + CONNECTION_TIMEOUT((byte) 0x08), + CONNECTION_LIMIT_EXCEEDED((byte) 0x09), + SYNC_DEVICE_CONNECTION_LIMIT_EXCEEDED((byte) 0x0a), + CONNECTION_ALREADY_EXISTS((byte) 0x0b), + COMMAND_DISALLOWED((byte) 0x0c), + CONNECTION_REJECTED_LIMITED_RESOURCES((byte) 0x0d), + CONNECTION_REJECTED_SECURITY((byte) 0x0e), + CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR((byte) 0x0f), + CONNECTION_ACCEPT_TIMEOUT_EXCEEDED((byte) 0x10), + UNSUPPORTED_FEATURE_OR_PARAM_VALUE((byte) 0x11), + INVALID_HCI_COMMAND_PARAMETERS((byte) 0x12), + REMOTE_USER_TERMINATED_CONNECTION((byte) 0x13), + REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES((byte) 0x14), + REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF((byte) 0x15), + CONNECTION_TERMINATED_BY_LOCAL_HOST((byte) 0x16), + REPEATED_ATTEMPTS((byte) 0x17), + PAIRING_NOT_ALLOWED((byte) 0x18), + UNKNOWN_LMP_PDU((byte) 0x19), + UNSUPPORTED_REMOTE_OR_LMP_FEATURE((byte) 0x1a), + SCO_OFFSET_REJECTED((byte) 0x1b), + SCO_INTERVAL_REJECTED((byte) 0x1c), + SCO_AIR_MODE_REJECTED((byte) 0x1d), + INVALID_LMP_OR_LL_PARAMETERS((byte) 0x1e), + UNSPECIFIED_ERROR((byte) 0x1f), + UNSUPPORTED_LMP_OR_LL_PARAMETER_VALUE((byte) 0x20), + ROLE_CHANGE_NOT_ALLOWED((byte) 0x21), + LMP_OR_LL_RESPONSE_TIMEOUT((byte) 0x22), + LMP_OR_LL_COLLISION((byte) 0x23), + LMP_PDU_NOT_ALLOWED((byte) 0x24), + ENCRYPTION_MODE_NOT_ACCEPTED((byte) 0x25), + LINK_KEY_CANNOT_BE_CHANGED((byte) 0x26), + REQUESTED_QOS_NOT_SUPPORTED((byte) 0x27), + INSTANT_PASSED((byte) 0x28), + PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED((byte) 0x29), + DIFFERENT_TRANSACTION_COLLISION((byte) 0x2a), + QOS_UNACCEPTABLE_PARAMETER((byte) 0x2c), + QOS_REJECTED((byte) 0x2d), + CHANNEL_ASSESSMENT_NOT_SUPPORTED((byte) 0x2e), + INSUFFICIENT_SECURITY((byte) 0x2f), + PARAMETER_OUT_OF_RANGE((byte) 0x30), + ROLE_SWITCH_PENDING((byte) 0x32), + RESERVED_SLOT_VIOLATION((byte) 0x34), + ROLE_SWITCH_FAILED((byte) 0x35), + EIR_TOO_LARGE((byte) 0x36), + SIMPLE_PAIRING_NOT_SUPPORTED_BY_HOST((byte) 0x37), + HOST_BUSY_PAIRING((byte) 0x38), + CONNECTION_REJECTED_NO_SUITABLE_CHANNEL((byte) 0x39), + CONTROLLER_BUSY((byte) 0x3a), + UNACCEPTABLE_CONNECTION_PARAM((byte) 0x3b), + ADVERTISING_TIMEOUT((byte) 0x3c), + CONNECTION_TERMINATED_MIC_FAILURE((byte) 0x3d), + CONNECTION_EST_FAILED_OR_SYNC_TIMETOUT((byte) 0x3e), + MAX_CONNECTION_FAILED ((byte) 0x3f), + COARSE_CLOCK_ADJ_REJECTED((byte) 0x40), + TYPE0_SUBMAP_NOT_DEFINED((byte) 0x41), + UNKNOWN_ADVERTISING_IDENTIFIER((byte) 0x42), + LIMIT_REACHED((byte) 0x43), + OPERATION_CANCELLED_BY_HOST((byte) 0x44), + PACKET_TOO_LONG((byte) 0x45), + INTERNAL_FAILURE((byte) 0xff); - public final int value; + public final byte value; /** * Maps the specified name to a constant of HCIErrorCode. @@ -125,17 +125,81 @@ public enum HCIErrorCode { * @throws IllegalArgumentException if the specified name can't be mapped to a constant of this enum type * as described above. */ - public static HCIErrorCode get(final int value) throws IllegalArgumentException { - final HCIErrorCode[] enums = HCIErrorCode.values(); - for(int i=0; i<enums.length; i++) { - if( value == enums[i].value ) { - return enums[i]; - } + public static HCIErrorCode get(final byte value) throws IllegalArgumentException { + switch( value ) { + case (byte) 0x00: return SUCCESS; + case (byte) 0x01: return UNKNOWN_HCI_COMMAND; + case (byte) 0x02: return UNKNOWN_CONNECTION_IDENTIFIER; + case (byte) 0x03: return HARDWARE_FAILURE; + case (byte) 0x04: return PAGE_TIMEOUT; + case (byte) 0x05: return AUTHENTICATION_FAILURE; + case (byte) 0x06: return PIN_OR_KEY_MISSING; + case (byte) 0x07: return MEMORY_CAPACITY_EXCEEDED; + case (byte) 0x08: return CONNECTION_TIMEOUT; + case (byte) 0x09: return CONNECTION_LIMIT_EXCEEDED; + case (byte) 0x0a: return SYNC_DEVICE_CONNECTION_LIMIT_EXCEEDED; + case (byte) 0x0b: return CONNECTION_ALREADY_EXISTS; + case (byte) 0x0c: return COMMAND_DISALLOWED; + case (byte) 0x0d: return CONNECTION_REJECTED_LIMITED_RESOURCES; + case (byte) 0x0e: return CONNECTION_REJECTED_SECURITY; + case (byte) 0x0f: return CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR; + case (byte) 0x10: return CONNECTION_ACCEPT_TIMEOUT_EXCEEDED; + case (byte) 0x11: return UNSUPPORTED_FEATURE_OR_PARAM_VALUE; + case (byte) 0x12: return INVALID_HCI_COMMAND_PARAMETERS; + case (byte) 0x13: return REMOTE_USER_TERMINATED_CONNECTION; + case (byte) 0x14: return REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES; + case (byte) 0x15: return REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF; + case (byte) 0x16: return CONNECTION_TERMINATED_BY_LOCAL_HOST; + case (byte) 0x17: return REPEATED_ATTEMPTS; + case (byte) 0x18: return PAIRING_NOT_ALLOWED; + case (byte) 0x19: return UNKNOWN_LMP_PDU; + case (byte) 0x1a: return UNSUPPORTED_REMOTE_OR_LMP_FEATURE; + case (byte) 0x1b: return SCO_OFFSET_REJECTED; + case (byte) 0x1c: return SCO_INTERVAL_REJECTED; + case (byte) 0x1d: return SCO_AIR_MODE_REJECTED; + case (byte) 0x1e: return INVALID_LMP_OR_LL_PARAMETERS; + case (byte) 0x1f: return UNSPECIFIED_ERROR; + case (byte) 0x20: return UNSUPPORTED_LMP_OR_LL_PARAMETER_VALUE; + case (byte) 0x21: return ROLE_CHANGE_NOT_ALLOWED; + case (byte) 0x22: return LMP_OR_LL_RESPONSE_TIMEOUT; + case (byte) 0x23: return LMP_OR_LL_COLLISION; + case (byte) 0x24: return LMP_PDU_NOT_ALLOWED; + case (byte) 0x25: return ENCRYPTION_MODE_NOT_ACCEPTED; + case (byte) 0x26: return LINK_KEY_CANNOT_BE_CHANGED; + case (byte) 0x27: return REQUESTED_QOS_NOT_SUPPORTED; + case (byte) 0x28: return INSTANT_PASSED; + case (byte) 0x29: return PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED; + case (byte) 0x2a: return DIFFERENT_TRANSACTION_COLLISION; + case (byte) 0x2c: return QOS_UNACCEPTABLE_PARAMETER; + case (byte) 0x2d: return QOS_REJECTED; + case (byte) 0x2e: return CHANNEL_ASSESSMENT_NOT_SUPPORTED; + case (byte) 0x2f: return INSUFFICIENT_SECURITY; + case (byte) 0x30: return PARAMETER_OUT_OF_RANGE; + case (byte) 0x32: return ROLE_SWITCH_PENDING; + case (byte) 0x34: return RESERVED_SLOT_VIOLATION; + case (byte) 0x35: return ROLE_SWITCH_FAILED; + case (byte) 0x36: return EIR_TOO_LARGE; + case (byte) 0x37: return SIMPLE_PAIRING_NOT_SUPPORTED_BY_HOST; + case (byte) 0x38: return HOST_BUSY_PAIRING; + case (byte) 0x39: return CONNECTION_REJECTED_NO_SUITABLE_CHANNEL; + case (byte) 0x3a: return CONTROLLER_BUSY; + case (byte) 0x3b: return UNACCEPTABLE_CONNECTION_PARAM; + case (byte) 0x3c: return ADVERTISING_TIMEOUT; + case (byte) 0x3d: return CONNECTION_TERMINATED_MIC_FAILURE; + case (byte) 0x3e: return CONNECTION_EST_FAILED_OR_SYNC_TIMETOUT; + case (byte) 0x3f: return MAX_CONNECTION_FAILED; + case (byte) 0x40: return COARSE_CLOCK_ADJ_REJECTED; + case (byte) 0x41: return TYPE0_SUBMAP_NOT_DEFINED; + case (byte) 0x42: return UNKNOWN_ADVERTISING_IDENTIFIER; + case (byte) 0x43: return LIMIT_REACHED; + case (byte) 0x44: return OPERATION_CANCELLED_BY_HOST; + case (byte) 0x45: return PACKET_TOO_LONG; + case (byte) 0xff: return INTERNAL_FAILURE; } throw new IllegalArgumentException("Unsupported value "+value); } - HCIErrorCode(final int v) { + HCIErrorCode(final byte v) { value = v; } } |