从Android Wearable流式传输传感器数据的最大速率

时间:2015-01-15 02:50:43

标签: android wear-os android-wear-data-api

我正在开发一款需要从可穿戴设备传输实时传感器数据的应用。我正在使用LG G手表以及加速度计和陀螺仪传感器。

传感器数据和系统当前时间打包为4个字节的数组,每个传感器的每个轴X 32个样本(因此4 X 3 X COUNT。

然后通过消息api发送此数据。

主要问题: 我已经以最快的更新速率(SENSOR_DELAY_FASTEST)注册了传感器,当我分析我用移动设备捕获的数据样本时,每个样本的时间步长大约为200ms(大约5 HZ)。

我期待更快。

我受限于: 1)蓝牙4.0带宽 2)LG G手表传感器(它是Invensense,带宽应该高得多)......或者 3)消息API

DataApi是否允许我更快地将数据流式传输到移动设备?

以下是我的代码的一部分:

static final int COUNT = 32;
static ByteBuffer AcceleratorBuffer = ByteBuffer.allocate((4 * 3 * COUNT) + (8 * 1 * COUNT));
static ByteBuffer GyroBuffer = ByteBuffer.allocate((4 * 3 * COUNT) + (8 * 1 * COUNT));

static int accelerator_cycle = 0;
static int gyro_cycle = 0;


static AcceleratorWearSensorListener mAcceleratorSensorEventListener = null;
static GyroWearSensorListener mGyroSensorEventListener = null;

static class GyroWearSensorListener implements SensorEventListener {
    GoogleApiClient mGoogleApiClient;

    public GyroWearSensorListener(GoogleApiClient mGoogleApiClient) {
        this.mGoogleApiClient = mGoogleApiClient;
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        if (On) {

            Float x = event.values[0];
            Float y = event.values[1];
            Float z = event.values[2];
            Log.i(TAG, "Gyro x: " + x + " y: " + y + " z: " + z);

            GyroBuffer.putFloat(x).putFloat(y).putFloat(z).putLong(System.currentTimeMillis()).array();
            ++gyro_cycle;
            if (gyro_cycle % COUNT == 0) {
                Wearable.NodeApi.getConnectedNodes(mGoogleApiClient)
                        .setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
                            @Override
                            public void onResult(NodeApi.GetConnectedNodesResult nodes) {
                                Log.i(TAG, "Nodes size : " + nodes.getNodes().size());
                                for (Node node : nodes.getNodes()) {
                                    if (node != null && mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
                                        Wearable.MessageApi.sendMessage(
                                                mGoogleApiClient, node.getId(), GYROSCOPE_DATA_PACKET, GyroBuffer.array())
                                                .setResultCallback(

                                                        new ResultCallback<MessageApi.SendMessageResult>() {
                                                            @Override
                                                            public void onResult(MessageApi.SendMessageResult sendMessageResult) {

                                                                if (!sendMessageResult.getStatus().isSuccess()) {
                                                                    Log.e(TAG, "Failed to send message with status code: "
                                                                            + sendMessageResult.getStatus().getStatusCode());
                                                                } else {
                                                                    Log.e(TAG, "send gyro data successfully ");
                                                                }
                                                            }
                                                        }
                                                );
                                    } else {
                                        Log.e(TAG, "node null or client null or not connected. ");
                                    }
                                }
                            }
                        });


                GyroBuffer.clear();
                gyro_cycle = 0;
            }

        }
    }

0 个答案:

没有答案