在 Android 智能手表上记录数据时出现随机间隙

Random gaps while recording data on Android smartwatch

我正在使用 Fossil Gen 5 智能手表 运行 WearOS 记录来自加速度计、陀螺仪 (32 Hz) 和 PPG 传感器 (64 Hz) 的传感器数据。我正在为每个传感器使用一个唯一的 bufferedWriter 对象,以便在创建每个传感器事件时将数据写入 .txt 文件(如下所示):

void registerSensor(){

    Log.i(TAG,"Sensor Registered");

    try {
        accWriter = new BufferedWriter(new FileWriter(accFile, true));
        gyrWriter = new BufferedWriter(new FileWriter(gyrFile, true));
        ppgWriter = new BufferedWriter(new FileWriter(ppgFile, true));
    } catch (IOException e) {
        e.printStackTrace();
    }

    //just in case
    if (sensorManager == null)
        sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);

    listener = new SensorEventListener() {
        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {}
        @Override
        public void onSensorChanged(SensorEvent event) {

            switch (event.sensor.getType()) {
                case 65572:
                    String msg1 = "Recording PPG";
                    mData1.setText(msg1);
                    ppgTime = System.currentTimeMillis() + (event.timestamp - SystemClock.elapsedRealtimeNanos()) / 1000000L;
                    try {
                        ppgWriter.write(ppgTime + ", " + event.values[0] + ", " + ambient + "\n");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    break;

                case Sensor.TYPE_ACCELEROMETER:
                    String msg2 = "Recording ACC";
                    mData2.setText(msg2);
                    accTime = System.currentTimeMillis() + (event.timestamp - SystemClock.elapsedRealtimeNanos()) / 1000000L;
                    try {
                        accWriter.write(accTime + ", " + df.format(event.values[0]) + ", " + df.format(event.values[1]) + ", " + df.format(event.values[2]) + ", " + ambient + "\n");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    break;

                case Sensor.TYPE_GYROSCOPE:
                    String msg3 = "Recording GYR";
                    mData3.setText(msg3);
                    gyrTime = System.currentTimeMillis() + (event.timestamp - SystemClock.elapsedRealtimeNanos()) / 1000000L;
                    try {
                        gyrWriter.write(gyrTime + ", " + df.format(event.values[0]) + ", " + df.format(event.values[1]) + ", " + df.format(event.values[2]) + ", " + ambient + "\n");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    break;
            }
        }
    };
    sensorManager.registerListener(listener, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),31250); // SensorManager.SENSOR_DELAY_FASTEST);
    sensorManager.registerListener(listener, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), 31250);
    sensorManager.registerListener(listener, sensorManager.getDefaultSensor(65572), 15625);

}

我希望采样频率在预期值附近徘徊。但是我在所有 3 个传感器流中随机丢失了大约 60 秒的数据块。

Please see this image that visually describes the issue (I'm not able to embed images yet)

我测试了很多次,结果都是一样的。我以为可能会掉一些事件,所以我尝试将所有数据写入一个String,然后在超过一定大小后将String写入文件。这并没有解决问题。

非常感谢任何帮助或建议!请原谅我的礼节,因为我是 Whosebug 的新手。

如果样本在屏幕关闭时掉落,您需要使用唤醒传感器。 您可以通过将 true 传递给 sensorManager.registerListener 来做到这一点。 根据文档,采样频率只是对 os.

的提示