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

✨ (ble): Add ReceiveFile Service #614

Merged
merged 3 commits into from
Apr 13, 2022

Conversation

YannLocatelli
Copy link
Member

No description provided.

@YannLocatelli YannLocatelli self-assigned this Mar 18, 2022
@codecov
Copy link

codecov bot commented Mar 18, 2022

Codecov Report

Merging #614 (9f35dd6) into develop (2aefb4e) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop     #614      +/-   ##
===========================================
+ Coverage    98.18%   98.20%   +0.01%     
===========================================
  Files           94       95       +1     
  Lines         1986     2004      +18     
===========================================
+ Hits          1950     1968      +18     
  Misses          36       36              
Impacted Files Coverage Δ
libs/BLEKit/include/BLEServiceFileReception.h 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@github-actions
Copy link

github-actions bot commented Mar 18, 2022

File comparision analysis report

🔖 Info

Target Flash Used (%) Flash Available (%) Static RAM (%)
bootloader 145244 (55%) 116900 (44%) 30048 (5%)
os 294244 (18%) 1270428 (81%) 32320 (6%)
Click to show memory sections
| -          |      Hex |     Bytes |  KiB |
|------------|---------:|----------:|-----:|
| Flash      | 0x200000 | 2 097 152 | 2048 |
| SRAM       |  0x80000 |   524 288 |  512 |
| Bootloader |  0x40000 |   262 144 |  256 |
| Header     |   0x1000 |     4 096 |    4 |
| OS         | 0x17E000 | 1 564 672 | 1528 |
| Tail       |   0x1000 |     4 096 |    4 |
| Scratch    |  0x40000 |   262 144 |  256 |

📝 Summary

Click to show summary
  • ✔️ - existing target
  • ✨ - new target
  • ⚰️ - deleted target
  • ✅ - files are the same
  • ❌ - files are different
Target Status .bin .map Total Flash (base/head) Total Flash Δ Static RAM (base/head) Static RAM Δ
LekaOS ✔️ 294244 (14%) ø 32320 (6%) ø
bootloader ✔️ 145244 (6%) ø 30048 (5%) ø
certs_emc_ble_bt_lcd_led_motors ✔️ 250688 (11%) ø 29240 (5%) ø
certs_emc_ble_led_motors ✔️ 174568 (8%) ø 24952 (4%) ø
certs_emc_bt_lcd_qspi_rfid_touch_wifi ✔️ 148840 (7%) ø 22528 (4%) ø
certs_emc_lcd_led_motors ✔️ 91928 (4%) ø 16168 (3%) ø
hardware_motors_test_reduction_and_wheels ✔️ 177960 (8%) ø 24360 (4%) ø
spike_lk_behavior_kit ✔️ 142592 (6%) ø 15704 (2%) ø
spike_lk_ble ✔️ 174892 (8%)
215120 (10%)
📈
40228 (23%)
24672 (4%)
27496 (5%)
📈
2824 (11%)
spike_lk_bluetooth ✔️ 73256 (3%) ø 11448 (2%) ø
spike_lk_cg_animations ✔️ 141016 (6%) ø 24416 (4%) ø
spike_lk_color_kit ✔️ 65712 (3%) ø 13744 (2%) ø
spike_lk_command_kit ✔️ 144856 (6%) ø 16360 (3%) ø
spike_lk_config_kit ✔️ 124204 (5%) ø 14312 (2%) ø
spike_lk_coreled ✔️ 76164 (3%) ø 13688 (2%) ø
spike_lk_event_queue ✔️ 74736 (3%) ø 12072 (2%) ø
spike_lk_file_manager_kit ✔️ 103604 (4%) ø 14048 (2%) ø
spike_lk_file_reception ✔️ 326984 (15%) ø 27576 (5%) ø
spike_lk_flash_memory ✔️ 63880 (3%) ø 11448 (2%) ø
spike_lk_lcd ✔️ 142664 (6%) ø 23992 (4%) ø
spike_lk_led ✔️ 65744 (3%) ø 13392 (2%) ø
spike_lk_led_kit ✔️ 103220 (4%) ø 14664 (2%) ø
spike_lk_log_kit ✔️ 68528 (3%) ø 11912 (2%) ø
spike_lk_motors ✔️ 62528 (2%) ø 11488 (2%) ø
spike_lk_reinforcer ✔️ 101996 (4%) ø 14664 (2%) ø
spike_lk_rfid ✔️ 73072 (3%) ø 11448 (2%) ø
spike_lk_sensors_battery ✔️ 78196 (3%) ø 12568 (2%) ø
spike_lk_sensors_light ✔️ 60056 (2%) ø 11440 (2%) ø
spike_lk_sensors_microphone ✔️ 72496 (3%) ø 11504 (2%) ø
spike_lk_sensors_temperature_humidity ✔️ 66968 (3%) ø 11424 (2%) ø
spike_lk_sensors_touch ✔️ 68600 (3%) ø 11432 (2%) ø
spike_lk_serial_number ✔️ 58904 (2%) ø 11464 (2%) ø
spike_lk_ticker_timeout ✔️ 69052 (3%) ø 11632 (2%) ø
spike_lk_update_process_app_base ✔️ 122788 (5%) ø 15288 (2%) ø
spike_lk_update_process_app_update ✔️ 77632 (3%) ø 12352 (2%) ø
spike_lk_wifi ✔️ 116392 (5%) ø 14808 (2%) ø
spike_mbed_blinky ✔️ 57968 (2%) ø 11400 (2%) ø
spike_mbed_watchdog_ticker_vs_thread ✔️ 63208 (3%) ø 12448 (2%) ø
spike_stl_cxxsupport ✔️ 58456 (2%) ø 11400 (2%) ø

🗺️ Map files diff output

Click to show diff list
spike_lk_ble (click to expand)
--- build_artifacts/base_ref-build-enable_log_debug-OFF/spike_lk_ble-map.txt	2022-04-13 14:23:03.973714086 +0000
+++ build_artifacts/head_ref-build-enable_log_debug-OFF/spike_lk_ble-map.txt	2022-04-13 14:23:04.317714251 +0000
@@ -1,16 +1,18 @@
-| Module                 |           .text |       .data |          .bss |
-|------------------------|-----------------|-------------|---------------|
-| [fill]                 |       354(+354) |     17(+17) |       68(+68) |
-| [lib]/BLEKit.a         |     1216(+1216) |       0(+0) |         0(+0) |
-| [lib]/CoreEventQueue.a |       204(+204) |       0(+0) |         0(+0) |
-| [lib]/c.a              |   26128(+26128) | 2472(+2472) |       58(+58) |
-| [lib]/gcc.a            |     7084(+7084) |       0(+0) |         0(+0) |
-| [lib]/mbed-os-static.a | 118704(+118704) |   689(+689) | 19084(+19084) |
-| [lib]/misc             |       188(+188) |       4(+4) |       28(+28) |
-| [lib]/nosys.a          |         32(+32) |       0(+0) |         0(+0) |
-| [lib]/stdc++.a         |     4116(+4116) |       8(+8) |       28(+28) |
-| main.cpp.obj           |     2362(+2362) |     74(+74) |   1854(+1854) |
-| Subtotals              | 160388(+160388) | 3264(+3264) | 21120(+21120) |
-Total Static RAM memory (data + bss): 24384(+24384) bytes
-Total Flash memory (text + data): 163652(+163652) bytes
+| Module                  |           .text |       .data |          .bss |
+|-------------------------|-----------------|-------------|---------------|
+| [fill]                  |       386(+386) |       9(+9) |       86(+86) |
+| [lib]/BLEKit.a          |     1216(+1216) |       0(+0) |         0(+0) |
+| [lib]/CoreEventQueue.a  |       154(+154) |       0(+0) |         0(+0) |
+| [lib]/CriticalSection.a |           8(+8) |       0(+0) |         0(+0) |
+| [lib]/FileManagerKit.a  |       768(+768) |       0(+0) |         0(+0) |
+| [lib]/c.a               |   40940(+40940) | 2572(+2572) |       97(+97) |
+| [lib]/gcc.a             |     7084(+7084) |       0(+0) |         0(+0) |
+| [lib]/mbed-os-static.a  | 139242(+139242) |   705(+705) | 19323(+19323) |
+| [lib]/misc              |       188(+188) |       4(+4) |       28(+28) |
+| [lib]/nosys.a           |         32(+32) |       0(+0) |         0(+0) |
+| [lib]/stdc++.a          |     4116(+4116) |       8(+8) |       28(+28) |
+| main.cpp.obj            |     3710(+3710) |     78(+78) |   4270(+4270) |
+| Subtotals               | 197844(+197844) | 3376(+3376) | 23832(+23832) |
+Total Static RAM memory (data + bss): 27208(+27208) bytes
+Total Flash memory (text + data): 201220(+201220) bytes
 
Flash used: 215120&nbsp;(10%) / total: 2097152
SRAM used: 27496&nbsp;(5%) / total: 524288

@github-actions
Copy link

github-actions bot commented Mar 18, 2022

File comparision analysis report

🔖 Info

Target Flash Used (%) Flash Available (%) Static RAM (%)
bootloader 145244 (55%) 116900 (44%) 30048 (5%)
os 313168 (20%) 1251504 (79%) 38512 (7%)
Click to show memory sections
| -          |      Hex |     Bytes |  KiB |
|------------|---------:|----------:|-----:|
| Flash      | 0x200000 | 2 097 152 | 2048 |
| SRAM       |  0x80000 |   524 288 |  512 |
| Bootloader |  0x40000 |   262 144 |  256 |
| Header     |   0x1000 |     4 096 |    4 |
| OS         | 0x17E000 | 1 564 672 | 1528 |
| Tail       |   0x1000 |     4 096 |    4 |
| Scratch    |  0x40000 |   262 144 |  256 |

📝 Summary

Click to show summary
  • ✔️ - existing target
  • ✨ - new target
  • ⚰️ - deleted target
  • ✅ - files are the same
  • ❌ - files are different
Target Status .bin .map Total Flash (base/head) Total Flash Δ Static RAM (base/head) Static RAM Δ
LekaOS ✔️ 313168 (14%) ø 38512 (7%) ø
bootloader ✔️ 145244 (6%) ø 30048 (5%) ø
certs_emc_ble_bt_lcd_led_motors ✔️ 258248 (12%) ø 35272 (6%) ø
certs_emc_ble_led_motors ✔️ 191600 (9%) ø 30976 (5%) ø
certs_emc_bt_lcd_qspi_rfid_touch_wifi ✔️ 165248 (7%) ø 28680 (5%) ø
certs_emc_lcd_led_motors ✔️ 91928 (4%) ø 16168 (3%) ø
hardware_motors_test_reduction_and_wheels ✔️ 194032 (9%) ø 30384 (5%) ø
spike_lk_behavior_kit ✔️ 151960 (7%) ø 21648 (4%) ø
spike_lk_ble ✔️ 184576 (8%)
224788 (10%)
📈
40212 (21%)
30752 (5%)
33568 (6%)
📈
2816 (9%)
spike_lk_bluetooth ✔️ 91192 (4%) ø 17472 (3%) ø
spike_lk_cg_animations ✔️ 149224 (7%) ø 30416 (5%) ø
spike_lk_color_kit ✔️ 88992 (4%) ø 19744 (3%) ø
spike_lk_command_kit ✔️ 156688 (7%) ø 22560 (4%) ø
spike_lk_config_kit ✔️ 136740 (6%) ø 20368 (3%) ø
spike_lk_coreled ✔️ 88556 (4%) ø 19632 (3%) ø
spike_lk_event_queue ✔️ 84664 (4%) ø 18136 (3%) ø
spike_lk_file_manager_kit ✔️ 127820 (6%) ø 20216 (3%) ø
spike_lk_file_reception ✔️ 331692 (15%) ø 33536 (6%) ø
spike_lk_flash_memory ✔️ 87352 (4%) ø 17512 (3%) ø
spike_lk_lcd ✔️ 155608 (7%) ø 30064 (5%) ø
spike_lk_led ✔️ 88808 (4%) ø 19400 (3%) ø
spike_lk_led_kit ✔️ 115724 (5%) ø 20608 (3%) ø
spike_lk_log_kit ✔️ 92000 (4%) ø 18168 (3%) ø
spike_lk_motors ✔️ 86576 (4%) ø 17552 (3%) ø
spike_lk_reinforcer ✔️ 111852 (5%) ø 20608 (3%) ø
spike_lk_rfid ✔️ 91008 (4%) ø 17472 (3%) ø
spike_lk_sensors_battery ✔️ 87600 (4%) ø 18584 (3%) ø
spike_lk_sensors_light ✔️ 84584 (4%) ø 17512 (3%) ø
spike_lk_sensors_microphone ✔️ 85336 (4%) ø 17512 (3%) ø
spike_lk_sensors_temperature_humidity ✔️ 90896 (4%) ø 17496 (3%) ø
spike_lk_sensors_touch ✔️ 92248 (4%) ø 17632 (3%) ø
spike_lk_serial_number ✔️ 82752 (3%) ø 17648 (3%) ø
spike_lk_ticker_timeout ✔️ 83224 (3%) ø 17592 (3%) ø
spike_lk_update_process_app_base ✔️ 145268 (6%) ø 21352 (4%) ø
spike_lk_update_process_app_update ✔️ 100968 (4%) ø 18472 (3%) ø
spike_lk_wifi ✔️ 131280 (6%) ø 20832 (3%) ø
spike_mbed_blinky ✔️ 57968 (2%) ø 11400 (2%) ø
spike_mbed_watchdog_ticker_vs_thread ✔️ 84688 (4%) ø 18448 (3%) ø
spike_stl_cxxsupport ✔️ 84000 (4%) ø 17536 (3%) ø

🗺️ Map files diff output

Click to show diff list
spike_lk_ble (click to expand)
--- build_artifacts/base_ref-build-enable_log_debug-ON/spike_lk_ble-map.txt	2022-04-13 14:24:41.285988018 +0000
+++ build_artifacts/head_ref-build-enable_log_debug-ON/spike_lk_ble-map.txt	2022-04-13 14:24:41.561989865 +0000
@@ -1,18 +1,19 @@
 | Module                  |           .text |       .data |          .bss |
 |-------------------------|-----------------|-------------|---------------|
-| [fill]                  |       368(+368) |     17(+17) |       72(+72) |
+| [fill]                  |       376(+376) |       9(+9) |       82(+82) |
 | [lib]/BLEKit.a          |     1216(+1216) |       0(+0) |         0(+0) |
-| [lib]/CoreEventQueue.a  |       172(+172) |       0(+0) |         0(+0) |
+| [lib]/CoreEventQueue.a  |       122(+122) |       0(+0) |         0(+0) |
 | [lib]/CriticalSection.a |           8(+8) |       0(+0) |         0(+0) |
-| [lib]/c.a               |   26152(+26152) | 2472(+2472) |       58(+58) |
+| [lib]/FileManagerKit.a  |       768(+768) |       0(+0) |         0(+0) |
+| [lib]/c.a               |   40964(+40964) | 2572(+2572) |       97(+97) |
 | [lib]/gcc.a             |     7148(+7148) |       0(+0) |         0(+0) |
 | [lib]/m.a               |       360(+360) |       0(+0) |         0(+0) |
-| [lib]/mbed-os-static.a  | 122244(+122244) |   689(+689) | 19120(+19120) |
+| [lib]/mbed-os-static.a  | 142782(+142782) |   705(+705) | 19359(+19359) |
 | [lib]/misc              |       188(+188) |       4(+4) |       28(+28) |
 | [lib]/nosys.a           |         32(+32) |       0(+0) |         0(+0) |
 | [lib]/stdc++.a          |     5424(+5424) |       8(+8) |       44(+44) |
-| main.cpp.obj            |     4836(+4836) |     74(+74) |   7878(+7878) |
-| Subtotals               | 168148(+168148) | 3264(+3264) | 27200(+27200) |
-Total Static RAM memory (data + bss): 30464(+30464) bytes
-Total Flash memory (text + data): 171412(+171412) bytes
+| main.cpp.obj            |     6216(+6216) |     78(+78) | 10294(+10294) |
+| Subtotals               | 205604(+205604) | 3376(+3376) | 29904(+29904) |
+Total Static RAM memory (data + bss): 33280(+33280) bytes
+Total Flash memory (text + data): 208980(+208980) bytes
 
Flash used: 224788&nbsp;(10%) / total: 2097152
SRAM used: 33568&nbsp;(6%) / total: 524288

@YannLocatelli YannLocatelli force-pushed the yann/feature/ble/receive-file-service branch 3 times, most recently from da4f555 to 7cff6fc Compare March 25, 2022 19:09
@YannLocatelli YannLocatelli marked this pull request as ready for review March 25, 2022 19:09
@YannLocatelli YannLocatelli added this to the v1.0.0 milestone Apr 5, 2022
Copy link
Member

@ladislas ladislas left a comment

Choose a reason for hiding this comment

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

LGTM 👍

few things/suggestions to change

also wondering about using a circular buffer for storing incoming data before consuming theme. can be added later.

libs/BLEKit/include/BLEServiceReceiveFile.h Outdated Show resolved Hide resolved
libs/BLEKit/include/BLEServiceReceiveFile.h Outdated Show resolved Hide resolved
libs/BLEKit/include/BLEServiceReceiveFile.h Outdated Show resolved Hide resolved
libs/BLEKit/include/BLEServiceReceiveFile.h Outdated Show resolved Hide resolved
libs/BLEKit/include/internal/ServicesCharacteristics.h Outdated Show resolved Hide resolved
libs/BLEKit/include/BLEServiceReceiveFile.h Outdated Show resolved Hide resolved
Comment on lines 33 to 36
std::copy(params.data, params.data + params.len, file_reception_stream.begin() + params.offset);
if (_on_stream_callback) {
_on_stream_callback(std::span {file_reception_stream.data(), params.len});
}
Copy link
Member

Choose a reason for hiding this comment

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

I haven't seen it work in real life, but seeing this makes me wonder about what happens if the consuming callback is slower than the data receive rate, let's say you want to write to a file in a low priority thread and it takes time.

I would use a circular buffer in this case so you can push data on one side and pop/consume it on the other side without impacting either one of the processes.

it could be argued that the circular buffer could be an implementation detail of the callback, but as the callback doesn't have any control over the receiving speed and process, I think it's best to play it safe and add the circular buffer here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, it works in real life

Changing the type of buffer will not change the shortcoming of data receive rate that depends only from the source. If the source set the data rate to 1MB/s, either the classical array and the circular buffer will struggle the same way.

A efficient way to handle this is to send back a signal to the source to inform that the received data has been processed.

I applied KISS for a first attempt since there was no evidence that will work and since there isn't feature in iPad to proceed it (for now).

I will change as you suggested with a circular buffer, but it will take time as it has to be tested to check that it works in real life.

Copy link
Member

Choose a reason for hiding this comment

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

I will change as you suggested with a circular buffer, but it will take time as it has to be tested to check that it works in real life.

I did not say you must change it, just keep in mind that the issue can appear.

also, it's not about the iPad, it's about writing data to a buffer then taking the buffer to do something else.
like write data to buffer --> read buffer to write to file

if the read buffer to write to file is slow and slower than the write data, data will be corrupted and overridden each time the callback is called.

using a circular buffer prevents this because you don't write where you read, so you have time to write while you read. Sure the buffer must be big enough and if the speed difference is too big, you'll still get the issue, but at least you can check/wait if the buffer is full before writing

@YannLocatelli YannLocatelli force-pushed the yann/feature/ble/receive-file-service branch 2 times, most recently from 0eb0027 to e4ffb13 Compare April 11, 2022 13:47
Comment on lines +75 to +84
auto path = service_file_reception.getFilePath();

if (reception_file.open(path.data(), "a")) {
write_buffer.fill('\0');
auto data_read = file_reception_circular_queue.pop(write_buffer.data(), std::size(write_buffer));
reception_file.write(write_buffer.data(), data_read);
reception_file.close();
}
Copy link
Member

Choose a reason for hiding this comment

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

c'est cette partie là qui doit être exécutée dans un event queue afin que la partie "slow" de l'écriture ne perturbe pas la réception, que les deux soient faits dans des contexts différents.

Copy link
Member Author

Choose a reason for hiding this comment

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

Je me demandais si justement ils n'était pas déjà gérés par l'eventQueue du BLE

Après ça coûte rien d'en faire un autre en effet

@YannLocatelli YannLocatelli force-pushed the yann/feature/ble/receive-file-service branch from b0ec0ef to fedd204 Compare April 12, 2022 20:06
Copy link
Member

@ladislas ladislas left a comment

Choose a reason for hiding this comment

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

pour moi c'est bon! 👍

@ladislas ladislas self-requested a review April 13, 2022 13:47
@YannLocatelli YannLocatelli force-pushed the yann/feature/ble/receive-file-service branch from fedd204 to e884aa7 Compare April 13, 2022 14:08
@YannLocatelli YannLocatelli force-pushed the yann/feature/ble/receive-file-service branch from e884aa7 to 9f35dd6 Compare April 13, 2022 14:09
@sonarcloud
Copy link

sonarcloud bot commented Apr 13, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@ladislas ladislas merged commit 9e8bcb2 into develop Apr 13, 2022
@ladislas ladislas deleted the yann/feature/ble/receive-file-service branch April 13, 2022 14:30
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.

2 participants