Association between Sensor data and Accounter sample count lost with bad connection

I want to use the Accounter with mbl_mw_dataprocessor_accounter_create_count to identify packet loss and react accordingly. For this I would like to have an association between the packet number and the sensor data.

I attached the accounter to the accelerometer signal:

auto acc_signal = mbl_mw_acc_get_acceleration_data_signal(metawear_board);
mbl_mw_datasignal_subscribe(acc_signal, nullptr, handle_accelerometer);

mbl_mw_dataprocessor_accounter_create_count(acc_signal, nullptr, [](void* context, MblMwDataProcessor* accounter) {
    mbl_mw_datasignal_subscribe((MblMwDataSignal *) accounter, context, handle_accounter);
});

If the connection is good, the handle_acc function is called and pretty much immediately afterwards the handle_accounter with the corresponding packet number. But when the connection deteriorates and packet loss occurs, this is not the case any more. Often the handle_acc function is called multiple times without the accounter in between, rarely handle_accounter is called multiple times without receiving sensor data.
If both functions print a line when called, the output may look like this:

Called handle_accelerometer.
Called handle_accounter with packet number 1535.
Called handle_accelerometer.
Called handle_accounter with packet number 1536.
Called handle_accelerometer.
Called handle_accelerometer.
Called handle_accelerometer.
Called handle_accounter with packet number 1556.
Called handle_accelerometer.
Called handle_accelerometer.
Called handle_accelerometer.
Called handle_accounter with packet number 1559.
Called handle_accounter with packet number 1564.
Called handle_accelerometer.
Called handle_accelerometer.
Called handle_accelerometer.
Called handle_accelerometer.
Called handle_accounter with packet number 1572.
Called handle_accelerometer.
Called handle_accelerometer.
Called handle_accounter with packet number 1575.
Called handle_accelerometer.
Called handle_accounter with packet number 1577.
Called handle_accelerometer.
Called handle_accounter with packet number 1578.

From the documentation I thought that the sample number would be appended to each BTLE packet and therefore both functions should be called exactly the same amount of time.

Is there any better way to determine an association between a sensor data packet and the sample number?

Comments

  • The counter is simply a way to determine if there are dropped packets. You should not expect to have consecutive counts if the connection is poor.

  • Thank you for your answer. So this means that the only conclusion that can be drawn from missing counter values is "probably some packets were lost in between, but we don't know how many or any at all"?

  • No...if the count no longer consecutive, then you know how many packets were lost.

  • edited November 2018

    I see. I was confused because it appeared that the accounter did not reflect the number of incoming packets. If the connection is bad the callback for the sensor stream itself is called more often than the callback for the accounter. But if I ignore the direct sensor stream it works as well as expected.

  • Don't stream both raw and processed data. You are doubling the data throughput for no reason.

This discussion has been closed.