data_fuser.py segmentation faults during libmetawear.mbl_mw_datasignal_subscribe().

I did a clean build/install the MetaWear-SDK-Python (0.6.1) and MetaWear-SDK-Cpp (0.17.0).

Then, to derive from data_fuser.py, first I ran data_fuser.py (unchanged, except adding the debug printfs) but the script seg faults when calling libmetawear.mbl_mw_datasignal_subscribe() on line 38 (https://github.com/mbientlab/MetaWear-SDK-Python/blob/0.6.1/examples/data_fuser.py).
Here's the data_fuser.py (with added debug prints) and the activity log leading up to the crash:

from ctypes import c_void_p, cast, POINTER
from mbientlab.metawear import MetaWear, libmetawear, parse_value, cbindings
from time import sleep
from threading import Event
from sys import argv

states = []

class State:
    def __init__(self, device):
        self.device = device
        self.callback = cbindings.FnVoid_VoidP_DataP(self.data_handler)
        self.processor = None

    def data_handler(self, ctx, data):
        values = parse_value(data, n_elem = 2)
        print("acc: (%.4f,%.4f,%.4f), gyro; (%.4f,%.4f,%.4f)" % (values[0].x, values[0].y, values[0].z, values[1].x, values[1].y, values[1].z))

    def setup(self):
        libmetawear.mbl_mw_settings_set_connection_parameters(self.device.board, 7.5, 7.5, 0, 6000)
        print("mbl_mw_settings_set_connection_parameters")
        sleep(1.5)

        e = Event()

        def processor_created(context, pointer):
            self.processor = pointer
            e.set()
        fn_wrapper = cbindings.FnVoid_VoidP_VoidP(processor_created)

        acc = libmetawear.mbl_mw_acc_get_acceleration_data_signal(self.device.board)
        print("mbl_mw_acc_get_acceleration_data_signal")
        gyro = libmetawear.mbl_mw_gyro_bmi160_get_rotation_data_signal(self.device.board)
        print("mbl_mw_gyro_bmi160_get_rotation_data_signal")

        signals = (c_void_p * 1)()
        signals[0] = gyro
        libmetawear.mbl_mw_dataprocessor_fuser_create(acc, signals, 1, None, fn_wrapper)
        e.wait()
        print("mbl_mw_dataprocessor_fuser_create")

        #libmetawear.mbl_mw_datasignal_subscribe(self.processor, None, self.callback)
        print("mbl_mw_datasignal_subscribe")

    def start(self):
        libmetawear.mbl_mw_gyro_bmi160_enable_rotation_sampling(self.device.board)
        print("mbl_mw_gyro_bmi160_enable_rotation_sampling")
        libmetawear.mbl_mw_acc_enable_acceleration_sampling(self.device.board)
        print("mbl_mw_acc_enable_acceleration_sampling")

        libmetawear.mbl_mw_gyro_bmi160_start(self.device.board)
        print("mbl_mw_gyro_bmi160_start")
        libmetawear.mbl_mw_acc_start(self.device.board)
        print("mbl_mw_acc_start")

for i in range(len(argv) - 1):
    d = MetaWear(argv[i + 1])
    d.connect()
    print("Connected to " + d.address)
    states.append(State(d))

for s in states:
    print("configuring %s" % (s.device.address))
    s.setup()

for s in states:
    s.start()

sleep(10.0)

print("resetting devices")
events = []
for s in states:
    e = Event()
    events.append(e)

    s.device.on_disconnect = lambda s: e.set()
    libmetawear.mbl_mw_debug_reset(s.device.board)

for e in events:
    e.wait()

spy35_env) pi@SS:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/examples $ python data_fuser.py F9:4E:B7:A1:F7:CE
error 1542810072.026808: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
Connected to F9:4E:B7:A1:F7:CE
configuring F9:4E:B7:A1:F7:CE
mbl_mw_settings_set_connection_parameters
mbl_mw_acc_get_acceleration_data_signal
mbl_mw_gyro_bmi160_get_rotation_data_signal
mbl_mw_dataprocessor_fuser_create
Segmentation fault
(sspy35_env) pi@SS:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/examples $

If I comment out the mbl_mw_datasignal_subscribe() then the output is:
(sspy35_env) pi@SS:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/examples $ !py
python data_fuser.py F9:4E:B7:A1:F7:CE
error 1542811687.837156: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
Connected to F9:4E:B7:A1:F7:CE
configuring F9:4E:B7:A1:F7:CE
mbl_mw_settings_set_connection_parameters
mbl_mw_acc_get_acceleration_data_signal
mbl_mw_gyro_bmi160_get_rotation_data_signal
mbl_mw_dataprocessor_fuser_create
mbl_mw_datasignal_subscribe
mbl_mw_gyro_bmi160_enable_rotation_sampling
mbl_mw_acc_enable_acceleration_sampling
mbl_mw_gyro_bmi160_start
mbl_mw_acc_start
resetting devices
(sspy35_env) pi@SS:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/examples $

Comments

  • Update the board to firmware v1.4.4.

  • Thanks Eric. Can you please provide the link to the instructions and the firmware?

  • Thanks. Never mind. I got it.

  • Eric:
    OK, after updating the firmware to 1.4.4 and latest software from the master branch, I ran the unit test suite and it results in FAILED (failures=2, errors=12, skipped=1). Is that normal?
    Am I missing something here?

    Thanks.

    (sspy35_env) pi@SS-hpd:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/MetaWear-SDK-Cpp $ make test
    python3 -m unittest discover -s test
    .......

    ....

    FAIL: test_read_after_deserialize (test_metawearboard.TestDeviceInfo)

    Traceback (most recent call last):
    File "/home/pi/SSquare/sspy35_env/MB/MetaWear-SDK-Python/MetaWear-SDK-Cpp/test/test_metawearboard.py", line 111, in test_read_after_deserialize
    self.assertEqual(actual.contents, expected)
    AssertionError: {manufacturer : b'8c\xc0\x01', model_number : b'5', serial_[76 chars]0.1'} != {manufacturer : b'deadbeef', model_number : b'5', serial_nu[72 chars]0.1'}


    Ran 452 tests in 33.420s

    FAILED (failures=2, errors=12, skipped=1)
    Makefile:109: recipe for target 'test' failed
    make: *** [test] Error 1
    (sspy35_env) pi@SS-hpd:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/MetaWear-SDK-Cpp $

  • I only asked you to update the firmware. Follow my instructions exactly; do not any more or any less.

This discussion has been closed.