-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add device label parameter #93
Add device label parameter #93
Conversation
38c2f2e
to
7742f0e
Compare
7742f0e
to
4cac53d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
I am thinking that we will also need to add a getter/setter for device label. RDM_PID_DEVICE_LABEL
is an NVS parameter so the setter must also write to NVS. And getters must return values by copy, not by reference. So the getter should call strncpy()
or rdm_pd_emplace()
to copy the string into a user's buffer.
I'm happy to add this feature myself in a future PR if that is helpful!
I have not yet looked into the whole nvs thing. I'll take a look and implement it :) Thinking about the NVS, why are only some parameters stored in the nvs? |
I implemented the getter but copying the string feels strange and error prone. What is the reason for getters returning by copy? |
Excellent question! A lot of PIDs are essentially constants that depend on your code. Therefore, they will survive a reboot just by the virtue of being a constant. Take, for example, The current exception is I may also remove the NVS column from the readme docs. I see now that it may be confusing for readers. It is also not currently correct because it does not have an NVS checkmark for |
I am having a hard time remembering exactly why I went with return by copy. I think it was a thread-safety issue. If you passed these variables around by their pointers, you could be in the middle of printing the device label to the terminal when the task is pre-empted by a RDM request which updates the device_label to a new value. This would result in the terminal printing part of the pre-update device_label and part of the post-update device_label. In other words, garbage data. Understanding thread-safety is difficult for me so if I am incorrect in my reasoning here, please let me know! :) |
1ae8836
to
6cfa0cf
Compare
Ahh, I haven't thought about multi-threading. I wasn't aware that the api should be thread-safe. In general I am not sure if implementing thread-safety is worth the effort to be honest. Users that are accessing data from the same task do not benefit from the locking and copying. It just makes things slower and the api harder to work with. Users that are accessing data from a different task usually know that they are doing so and can guard against corrupt data by using a mutex around the I have never seen an embedded api that deals with thread-safety internally. Usually that is left to the user. |
To be honest, I don't have much experience with what an embedded project should look like. If it is true that thread-safety should have been left to the user, then that is my mistake. :)
That is fair. I think you're correct that copy-by-pointer can offer significant advantages. I'll have to think about this. If there aren't any major issues, perhaps it could be part of the v4 API? Edit: I should add that I had a difficult time coupling the DMX code of this library to the RDM code. I think, in general, the DMX code should be thread-safe. I spent a considerable amount of time trying to make the RDM API match the DMX API, but maybe I overdid it. I may do some experiments in the |
Opps, my bad. you are right :) In general I think that I have lost track of what to do with this pr now :D What do I have to do to get them merged? :) |
Last thing is to change |
6cfa0cf
to
aee3bef
Compare
Done, sorry it took so long :-) |
This adds the device_label parameter.
This PR sits on top of #92 and thus the diff contains a lot of changes that have nothing to do with this PR. The last commit contains the actual content of this PR.