Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python tx and rx with metadata and get_timestamp #932

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Algafix
Copy link

@Algafix Algafix commented Jul 18, 2023

Hello!

I wanted to use the transmission and reception with metadata using the Python bindings and, while it was possible, it required to manually interact with the cffi and remember all the fields and flags. Also, the bladerf_get_timestamp function was missing.

Hence, I created an IntEnum to organize the Metadata Flags and a class for the Metadata object that follows the style of similar classes declared on the bindings.

For the sync_tx and sync_rx, it makes sense to be able to directly send a Metadata object instead of having to call object.struct on the method call. However, to make it backwards compatible, I have to check for the type. Also, the sync_rx has to return the Metadata object. If this approach is not correct and you prefer to maintain the previous approach or ditch the legacy version, let me know and I'll update the PR.

I've tested the functionality by implementing the C examples for TX with metadata and RX with metadata listed in the API documentation. The functionality is not exactly the same because the calls are blocking, so for example to test the TX metadata flags I had to launch multiple threads; but that is expected.

Thanks!

@vatsal-cyronics
Copy link

Hey there!

I am trying to get the metadata out using python example bu unable to fetch the meta. the execution stops at _check_error. bladerf._bladerf.InvalError: Invalid operation or parameter.
Have set _bladerf.Format.SC16_Q11_META as the format in sync_config.

rx_test.zip

Any leads on this will be highly appreciable.
Thanks in Advance.

@Algafix
Copy link
Author

Algafix commented Jul 27, 2023

Hello!

According to the API definition, one must send a meta object when requesting a rx with meta. That is in your line 144:

meta = device.sync_rx(buf, num)

Can you try:

meta_send = _bladerf.Metadata(
            0,
            _bladerf.MetadataFlags.BLADERF_META_FLAG_RX_NOW,
            0,
            0
        )

meta = device.sync_rx(buf, num, meta_send)

I don't have a bladeRF available right now, let me know if it fixes the issue.

@vatsal-cyronics
Copy link

vatsal-cyronics commented Jul 27, 2023

Hi!

Thanks for the response! Yes, the above solution worked well.

meta_send = _bladerf.Metadata(
            0,
            _bladerf.MetadataFlags.BLADERF_META_FLAG_RX_NOW,
            0,
            0
        )

meta = device.sync_rx(buf, num, 0, meta_send)

Got this as response :

Metadata(timestamp=3, flags=2147483648, status=196608, actual_count=1024)
Metadata(timestamp=1027, flags=2147483648, status=196608, actual_count=1024)
Metadata(timestamp=2051, flags=2147483648, status=196608, actual_count=1024)
...
Metadata(timestamp=1014413, flags=2147483648, status=196608, actual_count=1024)
Metadata(timestamp=1015437, flags=2147483648, status=196608, actual_count=576)

Could you please help me with how to interpret the timestamps in order to verify no-loss?

I am trying to achieve time-stamping for each chunk of samples. Was expecting actual timestamps.

Thanks! :)

@Algafix
Copy link
Author

Algafix commented Jul 27, 2023

The timestamp is a counter that increases at sample rate, and it's linked to the first sample of the buffer (note that enabling a channel resets the timestamp).

If there's is no overrun flag in the status field that means that the chunk was send without drops, and if the timestamp is continuous (adding the number of samples) that means there was no gap between chunks. You can probably verify this using the loopback mode or another receiver.

I encourage you to read the documentation since this questions are answered much clearer than I can.

https://nuand.com/libbladeRF-doc/v2.5.0/sync_rx_meta.html

@vatsal-cyronics
Copy link

Got it!

I very much appreciate your help :)

Copy link

@lgoix lgoix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forked the project from commit 41ef634
Applied the changes from 2db3b84 and this pull-request

I confirm we can TX/RX with metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants