Closed mniestroj closed 1 year ago
Visit the preview URL for this PR (updated for commit 9dade39):
https://golioth-zephyr-sdk-doxygen-dev--pr313-dfu-rework-57p76rrd.web.app
(expires Wed, 26 Oct 2022 16:29:48 GMT)
🔥 via Firebase Hosting GitHub Action 🌎
Sign: a389eefadf4b4b68a539327b3459dd66c142cf49
So far there were 3 threads involved:
This is overly complicated and makes callbacks implementation hard to read due to FW state reporting logic taking most of callback body.
Change implementation to utilize only 2 threads instead, with following changes:
There is little data shared among those threads and most important thing is to notify about state of FW download. For that reason use semaphores, which make main() execution continue step by step, making overall logic easy to follow.
This change solves one of the issues with pytest scripts expecting a specific sequence of FW states. So far this sequence was not followed from time to time, due to UDP packets reordering. This issue is now partly solved by reporting FW states from Zephyr main thread and remaining fix will be a conversion from asynchronous to synchronous golioth_fw_report_state() API.
As a consequence of above, change
golioth_fw_report_state()
API to be synchronous. This API does not take any callback, which means that it is not possible to handle any communication errors or error responses from server. The main reason why its implementation used golioth_coap_req_cb() (in [1]) was to reduce breaking changes by allowing users to call this API from system_client thread (which is not possible for synchronous APIs).As right now samples/dfu/ has been updated to report FW state (i.e. call golioth_fw_report_state() API) from main application thread, there is little reason to keep golioth_fw_report_state() asynchronous.
If asynchronous API will be required in future, then such API would need to take callback argument similar to other services (like LightDB and LightDB Stream). Such API is not introduced now, as that would either require second DFU sample with a slightly different flow or alternatively unit tests for this new callback-based API.