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

samples: bluteooth: CS ranging requestor sample #18921

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sean-madigan
Copy link
Contributor

@sean-madigan sean-madigan commented Nov 15, 2024

Add Channel sounding ranging requestor sample with distance estimation algorithm.

@github-actions github-actions bot added doc-required PR must not be merged without tech writer approval. changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. labels Nov 15, 2024
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Nov 15, 2024

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 5

Inputs:

Sources:

more details

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (0)

Outputs:

Toolchain

Version:
Build docker image:

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ❌ Toolchain
  • ❌ Build twister
  • ❌ Integration tests

Note: This message is automatically posted and updated by the CI

@github-actions github-actions bot removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Nov 15, 2024
This is a utility function to help extract useful parts of
the ranging data provided by the ranging requestor service.

Signed-off-by: Sean Madigan <[email protected]>
@sean-madigan sean-madigan changed the title Sample requestor samples: bluteooth: CS ranging requestor sample Nov 15, 2024
@NordicBuilder
Copy link
Contributor

You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds.

Note: This comment is automatically posted by the Documentation Publish GitHub Action.

This sample can be used to set up a Channel Sounding Initiator with
the GATT Ranging Requestor client.
It can connect to Channel Sounding Reflector with Ranging Responder
sample to request CS Ranging Data from.
A simple distance estimation algorithm is included. This uses the
same logic as the Zephyr Channel Sounding sample.

Signed-off-by: Sean Madigan <[email protected]>
@olivier-le-sage
Copy link
Contributor

If possible I think we should use mode 3 here. There's no disadvantage to using it (as long as it's supported on both sides), so I expect it would be more useful to customers than using mode 2 + 1

* must be populated with the length of the step data inside the callback.
* @param[in] user_data User data to be passed to the callbacks.
*/
void bt_ras_rreq_rd_subevent_data_parse(
Copy link
Contributor

Choose a reason for hiding this comment

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

did you try having a single function that parses both formats and gives a single callback ? I think it would be easier for users

Copy link
Contributor

Choose a reason for hiding this comment

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

it would also remove struct ras_rd_cs_subevent_step (since the mode would be a duplicate)


struct ras_ranging_header *rd_header =
net_buf_simple_pull_mem(peer_steps, sizeof(struct ras_ranging_header));
(void)rd_header;
Copy link
Contributor

Choose a reason for hiding this comment

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

can just remove the variable?

err = bt_conn_set_security(connection, BT_SECURITY_L2);
if (err) {
printk("Failed to encrypt connection (err %d)\n", err);
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to handle these failing more gracefully - perhaps disconnect the peer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is fine as is


err = bt_gatt_exchange_mtu(connection, &mtu_exchange_params);
if (err) {
printk("MTU exchange failed (err %d)\n", err);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's worth handling the return code here, the only error code you could get is EALREADY which means the sem_mtu_exchange_done semaphore would have already been given in the MTU exchange callback.

NET_BUF_SIMPLE_DEFINE_STATIC(latest_peer_steps, BT_RAS_PROCEDURE_MEM);
static int32_t most_recent_peer_ranging_counter = PROCEDURE_COUNTER_NONE;
static int32_t most_recent_local_ranging_counter = PROCEDURE_COUNTER_NONE;
static int32_t dropped_ranging_counter = PROCEDURE_COUNTER_NONE;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was hoping implementing RAS would make it easier to manage ranging counters in the app by leveraging the notifications you get from the server, wouldn't it make more sense to have something like:

  • array of steps storing N counters
  • discard array entry X if you get the data overwritten callback
  • set a flag in entry X when you get ranging data ready
  • app logic requests counters it has stored locally then processes entries where this flag is set ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess what I wrote here doesn't exactly work but you'd think this overwritten notification would be useful somehow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure exactly how to improve this currently

static struct bt_conn *connection;
static uint8_t n_ap;
static uint8_t latest_num_steps_reported;
NET_BUF_SIMPLE_DEFINE_STATIC(latest_local_steps, BT_RAS_PROCEDURE_MEM);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think BT_RAS_PROCEDURE_MEM is the correct estimate here, since the local steps are storing a full bt_le_cs_subevent_step and no subevent headers

#define CON_STATUS_LED DK_LED1

#define CS_CONFIG_ID 0
#define NUM_MODE_0_STEPS 1
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be more stable to use 2-3 mode 0 steps. Since there's no memory limitations with RAS we don't lose anything by increasing this

printk("MTU exchange failed (err %d)\n", err);
}

err = k_sem_take(&sem_mtu_exchange_done, K_SECONDS(5));
Copy link
Contributor

Choose a reason for hiding this comment

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

K_FOREVER is probably fine

return 0;
}

k_sem_take(&sem_remote_capabilities_obtained, K_SECONDS(5));
Copy link
Contributor

@olivier-le-sage olivier-le-sage Nov 18, 2024

Choose a reason for hiding this comment

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

this can also be K_FOREVER I think ? Same for the other control procedures in the setup phase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't take 5s? Might as well have the timeout?

Comment on lines +97 to +98
.. [#phase_and_amplitude] `Bluetooth Core Specification v. 6.0: Vol. 1, Part A, 9.2 <https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-60/out/en/architecture,-change-history,-and-conventions/architecture.html#UUID-a8d03618-5fcf-3043-2198-559653272b1b>`_
.. [#rtt_packets] `Bluetooth Core Specification v. 6.0: Vol. 1, Part A, 9.3 <https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-60/out/en/architecture,-change-history,-and-conventions/architecture.html#UUID-9d4969af-baa6-b7e4-03ca-70b340877adf>`_
Copy link
Contributor

@peknis peknis Nov 18, 2024

Choose a reason for hiding this comment

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

}

dropped_ranging_counter = PROCEDURE_COUNTER_NONE;
latest_num_steps_reported = result->header.num_steps_reported;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is limited to 1 subevent per procedure, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Realised this variable was unused, but yeah I think currently only one subevent per procedure

@sean-madigan
Copy link
Contributor Author

If possible I think we should use mode 3 here. There's no disadvantage to using it (as long as it's supported on both sides), so I expect it would be more useful to customers than using mode 2 + 1

Seems like it is still WIP in the controller, I can make a task to update this sample to use mode 3 when there is proper controller support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-required PR must not be merged without tech writer approval.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants