3

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

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

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

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

我期待更快。

我是否受到以下限制: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;
            }

        }
    }
4

0 回答 0