Packed acceleration - Segmentation fault
I'm getting a Segmentation fault
when using the packed acceleration mode. Here is my implementation approach:
Set the connection parameters during connection process:
MetaWear.mbl_mw_settings_set_connection_parameters(device.board, 7.5, 7.5, 0, 6000);
Set the acceleration sensor config:
MetaWear.mbl_mw_acc_set_range(device.board, range);
MetaWear.mbl_mw_acc_set_odr(device.board, odr);
MetaWear.mbl_mw_acc_write_acceleration_config(device.board);
Recording process:
let accSignal = MetaWear.mbl_mw_acc_get_packed_acceleration_data_signal(device.board);
let onAccDataCallback = (dataPtr) => {
let data = dataPtr.deref();
// ... data is written to a csv-file ...
// stoped after X seconds
};
MetaWear.mbl_mw_datasignal_subscribe(accSignal, MetaWear.FnVoid_DataP.toPointer(onAccDataCallback));
MetaWear.mbl_mw_acc_enable_acceleration_sampling(device.board);
MetaWear.mbl_mw_acc_start(device.board);
Stop the recording process:
MetaWear.mbl_mw_acc_stop(device.board);
MetaWear.mbl_mw_acc_disable_acceleration_sampling(device.board);
MetaWear.mbl_mw_datasignal_unsubscribe(accSignal);
I think the Segmentation fault
occurs somewhere during stopping the process because I receive all data (the csv-file is complete).
The same implementation works fine for let accSignal = MetaWear.mbl_mw_acc_get_acceleration_data_signal(device.board);
.
Could someone also explain how the packed data is treated / unpacked? Do I already get the "unpacked" data sets in my onAccDataCallback
?
This discussion has been closed.
Comments
That is mostly a result of a missing null pointer check in the underlying C++ code, that was added in a later C++ SDK release. You can work around it by resetting the board instead of stopping/unsubscribing.
Yes
Thank´s Eric! Resetting solves the problem.
But for my use case the workaround is a bit unpleasant because I am recording in a loop and therefore I need to reconnect the sensors each time after resetting.
This fix was done for the C++ implementation but is not included yet in the JavaScript/Node SDK?
If you're recording in a loop, you don't really need to do anything beyond stopping the sensor.
Correct