Adding RSS to accelerometer data stream
in iOS
Hello!
I'm trying to create an app in Swift that returns the rss of the streamed data. I am able to get the regular streamed data, but am unsuccessful in applying a rss filter to the onboard processing before receiving the data on the iOS.
Is there any sample code available, or example from other projects, which makes this process clear?
Comments
More specifically, I am unclear for what to set for the parameters of mbl_mw_dataprocessor_rss_create(signal, context, processor). For the signal, I am passing in a variable set to mbl_mw_acc_get_acceleration_data_signal(device.board), but do not know how to deal with the context and processor.
Some example code in Python:
All you need to do is either log or stream the output of the rss creator.
Hey Laura! Thanks a lot for the reply. I really appreciate it. While this example does help me understand what's going on a little bit more, it is not quite what I need as I am coding in Swift. Do you perhaps have any Swift examples?
To create my rms_processor_created function, I was going off of the code at the bottom of this post: https://mbientlab.com/community/discussion/comment/7959#Comment_7959. However, clearly the accounter code doesn't exactly translate to be applied to rms. With the following code, I received the error: "A C function pointer cannot be formed from a closure that captures context."
Conceptually, I still don't understand how to define the processor / where it gets defined. Any tips on that would be greatly appreciated.
In addition, will I need to use MblMwFnDataProcessor? When I attempt to, passing in (context, rms_processor_created), I receive an error that MblMwFnDataProcessor has no member 'init'.
Go ahead and download the swift example App, there should be examples there. I think you get it, you just have some syntax issues with swift.
I've gone through the whole example App and I cannot find instances of on-board data processing. There are data streams being set up and configurations being applied, but I see no evidence of anything similar to a rms processor.
Perhaps you can help point out where my understanding is flawed / what I should look into more. This is how I understand the overview of how the rms data processor gets programmed onto the data route.
Create a processor (handler) to control what happens to the data after it goes through the RMS processor
Create an acceleration signal
Apply the data processor by calling mbl_mw_dataprocessor_rms_create
Enable and start acceleration
Thanks a lot for your valuable time. I really appreciate it
Turns out I did not look through the documentation enough. Although the Swift and C++ API do not have the examples I was looking for, the developer documentation tutorials have examples for all languages: https://mbientlab.com/tutorials/CppDevelopment.html#data-processing.
Now that I've made some more progress, I have a new issue. It seems that there is no member streamingCleanup in the sample app provided (so generously by mbientlab). Could you help me understand what streamingCleanup is in the context?
I think it is a dictionary, but do not know what to set the key and value types to. Another possibility is that it's an array, but would appreciate confirmation on this before I venture into manipulating raw memory through https://developer.apple.com/documentation/swift/unsafemutablerawpointer.
Any workaround, solution code, or recommendation is greatly appreciated!
You can ignore that, in the examples we do multiple things all at the same time and this is just a helper function to clean it all up.
Hey Laura. I now see that that part is already taken care of in my acceleration_stop() method. Thanks for the clarification.
This is my current method:
When I try to run this, and click the associated button, I receive a "Thread 7: Assertion failed" (the # of the thread changes every time) error message from /MetaWear-SDK-iOS-macOS-tvOS/MetaWear/Core/MetaWearData.swift, line 88. This line is "// Generalized flow
assert(MemoryLayout.size == length)"
Not sure what that would be due to. Maybe try to run it on the main thread.
cast rms/rss values to float type, not MblMwCartesianFloat
Thanks a lot Eric! This got it working! I'm excited to start adding some more functionality to my app!