public void onCharacteristicRead()

in amazonfreertossdk/src/main/java/software/amazon/freertos/amazonfreertossdk/AmazonFreeRTOSDevice.java [557:663]


                public void onCharacteristicRead(BluetoothGatt gatt,
                                                 BluetoothGattCharacteristic characteristic,
                                                 int status) {
                    mRWinProgress = false;
                    Log.d(TAG, "->->-> onCharacteristicRead status: " + (status == 0 ? "Success. " : status));

                    if (status == BluetoothGatt.GATT_SUCCESS) {
                        // On the first successful read we enable the services
                        if (mBleConnectionState == BleConnectionState.BLE_CONNECTED) {
                            Log.d(TAG, "GATT services initializing...");
                            mBleConnectionState = AmazonFreeRTOSConstants.BleConnectionState.BLE_INITIALIZING;
                            mBleConnectionStatusCallback.onBleConnectionStatusChanged(mBleConnectionState);
                            initialize();
                        }
                        byte[] responseBytes = characteristic.getValue();
                        Log.d(TAG, "->->-> onCharacteristicRead: " + bytesToHexString(responseBytes));
                        switch (characteristic.getUuid().toString()) {
                            case UUID_MQTT_PROXY_TXLARGE:
                                try {
                                    mTxLargeObject.write(responseBytes);
                                    if (responseBytes.length < mMaxPayloadLen) {
                                        byte[] largeMessage = mTxLargeObject.toByteArray();
                                        Log.d(TAG, "MQTT Large object received from device successfully: "
                                                + bytesToHexString(largeMessage));
                                        handleMqttTxMessage(largeMessage);
                                        mTxLargeObject.reset();
                                    } else {
                                        sendBleCommand(new BleCommand(READ_CHARACTERISTIC,
                                                UUID_MQTT_PROXY_TXLARGE, UUID_MQTT_PROXY_SERVICE));
                                    }
                                } catch (IOException e) {
                                    Log.e(TAG, "Failed to concatenate byte array.", e);
                                }
                                break;
                            case UUID_NETWORK_TXLARGE:
                                try {
                                    mTxLargeNw.write(responseBytes);
                                    if (responseBytes.length < mMaxPayloadLen) {
                                        byte[] largeMessage = mTxLargeNw.toByteArray();
                                        Log.d(TAG, "NW Large object received from device successfully: "
                                                + bytesToHexString(largeMessage));
                                        handleNwTxMessage(largeMessage);
                                        mTxLargeNw.reset();
                                    } else {
                                        sendBleCommand(new BleCommand(READ_CHARACTERISTIC,
                                                UUID_NETWORK_TXLARGE, UUID_NETWORK_SERVICE));
                                    }
                                } catch (IOException e) {
                                    Log.e(TAG, "Failed to concatenate byte array.", e);
                                }
                                break;
                            case UUID_DEVICE_MTU:
                                Mtu currentMtu = new Mtu();
                                currentMtu.mtu = new String(responseBytes);
                                Log.i(TAG, "Default MTU is set to: " + currentMtu.mtu);
                                try {
                                    mMtu = Integer.parseInt(currentMtu.mtu);
                                    mMaxPayloadLen = Math.max(mMtu - 3, 0);
                                    if (mDeviceInfoCallback != null) {
                                        mDeviceInfoCallback.onObtainMtu(mMtu);
                                    }
                                    setMtu(mMtu);
                                } catch (NumberFormatException e) {
                                    Log.e(TAG, "Cannot parse default MTU value.");
                                }
                                break;
                            case UUID_IOT_ENDPOINT:
                                BrokerEndpoint currentEndpoint = new BrokerEndpoint();
                                currentEndpoint.brokerEndpoint = new String(responseBytes);
                                Log.i(TAG, "Current broker endpoint is set to: "
                                        + currentEndpoint.brokerEndpoint);
                                if (mDeviceInfoCallback != null) {
                                    mDeviceInfoCallback.onObtainBrokerEndpoint(currentEndpoint.brokerEndpoint);
                                }
                                break;
                            case UUID_DEVICE_VERSION:
                                Version currentVersion = new Version();
                                currentVersion.version = new String(responseBytes);
                                if (!currentVersion.version.isEmpty()) {
                                    mAmazonFreeRTOSLibVersion = currentVersion.version;
                                }
                                Log.i(TAG, "Ble software version on device is: " + currentVersion.version);
                                if (mDeviceInfoCallback != null) {
                                    mDeviceInfoCallback.onObtainDeviceSoftwareVersion(currentVersion.version);
                                }
                                break;
                            case UUID_DEVICE_PLATFORM:
                                String platform = new String(responseBytes);
                                if (!platform.isEmpty()) {
                                    mAmazonFreeRTOSDeviceType = platform;
                                }
                                Log.i(TAG, "Device type is: " + mAmazonFreeRTOSDeviceType);
                                break;
                            case UUID_DEVICE_ID:
                                String devId = new String(responseBytes);
                                if (!devId.isEmpty()) {
                                    mAmazonFreeRTOSDeviceId = devId;
                                }
                                Log.i(TAG, "Device id is: " + mAmazonFreeRTOSDeviceId);
                                break;
                            default:
                                Log.w(TAG, "Unknown characteristic read. ");
                        }
                    }
                    processIncomingQueue();
                    processNextBleCommand();
                }