-
Notifications
You must be signed in to change notification settings - Fork 26
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
Unable to use heapless Vec in macros #196
Comments
I can look at this as part of my rework of the macro, I've made some improvements there to accommodate the default value option. |
This seems to work for heapless Vec and other types. static #name_screaming: static_cell::StaticCell<[u8; size_of::<#ty>()]> = static_cell::StaticCell::new();
let store = #name_screaming.init(Default::default());
let mut val = <#ty>::default(); // constrain the type of the value here
val = #default_value; // update the temporary value with our new default
let bytes = GattValue::to_gatt(&val);
store[..bytes.len()].copy_from_slice(bytes);
let mut builder = service
.add_characteristic(#uuid, &[#(#properties),*], store); |
I think one problem with that solution is that the actual number of bytes written to the Vec is forgotten, so that when you read the Vec from code, it will have the full size of the slice, and not the actual 'used' size which is what you'd get with nrf-softdevice. Ideally, the Vec would be resized based on the attribute write. I think maybe we need some way for the attribute/attribute_server to 'convert' the raw data to the appropriate type when writing. |
I see what you mean. I wonder if the store type itself should be a heapless Vec. I'll have another look at how softdevice solves this. |
I'm trying to use a service like this:
And when trying to read values using server.get(handle), I'm getting an error of
InvalidValue
. Closer inspection reveals that macros use size_of<Vec<u8, ATT_MTU>> to calculate the storage size, which I think is wrong. It should instead store the data as the given type rather than a byte slice, and hand in the 'byte representation' to the AttributeData (at least I think that should work).The text was updated successfully, but these errors were encountered: