Skip to content

fix(ble): send exact payload size for SplitMessage - #1011

Merged
HaoboGu merged 1 commit into
rmk-rs:mainfrom
tompre:fix/ble-msg-encode
Jul 31, 2026
Merged

fix(ble): send exact payload size for SplitMessage#1011
HaoboGu merged 1 commit into
rmk-rs:mainfrom
tompre:fix/ble-msg-encode

Conversation

@tompre

@tompre tompre commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

As mentioned in #1008, split messages are not sent efficiently at the moment. Instead the whole buffer is sent even if only part of it was used for the encoding.

This pull request changes the Characteristics type to variable length and enables efficient bandwidth usage.

It introduces GattSplitMessage, a wrapper around a [u8; SplitMessage::POSTCARD_MAX_SIZE] buffer.
It uses SplitMessage::POSTCARD_MAX_SIZE as the length, as SPLIT_MESSAGE_MAX_SIZE includes bytes needed for the COBS encoding for the serial link, which is not necessary for BLE.

@github-actions

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 397.5 KiB 397.5 KiB +0.00% 0 0 0
use_config/nrf52840_ble 438.1 KiB 438.1 KiB +0.00% ⬇️ -4 0 0
use_config/nrf52840_ble_split (central) 500.9 KiB 500.8 KiB -0.01% ⬇️ -24 0 -32
use_config/nrf52840_ble_split (peripheral) 320.6 KiB 320.6 KiB +0.00% ⬆️ +64 0 -48
use_config/pi_pico_w_ble 671.1 KiB 671.1 KiB +0.00% ⬆️ +4 0 0
use_config/rp2040 145.8 KiB 145.8 KiB +0.00% 0 0 0
use_config/rp2040_split (central) 159.4 KiB 159.4 KiB +0.00% ⬆️ +8 0 0
use_config/rp2040_split (peripheral) 27.9 KiB 27.9 KiB +0.00% 0 0 0
use_config/stm32f1 62.6 KiB 62.5 KiB +0.00% ⬇️ -4 0 0
use_config/stm32h7 100.8 KiB 100.8 KiB +0.00% 0 0 0
use_rust/nrf52832_ble 385.5 KiB 385.5 KiB +0.00% 0 0 0
use_rust/nrf52840_ble 435.6 KiB 435.6 KiB +0.00% ⬇️ -4 0 0
use_rust/nrf52840_ble_split (central) 504.9 KiB 504.9 KiB +0.00% ⬇️ +24 0 -32
use_rust/nrf52840_ble_split (peripheral) 318.4 KiB 318.4 KiB +0.00% ⬇️ +24 0 -48
use_rust/pi_pico_w_ble 671.1 KiB 671.1 KiB +0.00% ⬆️ +8 0 0
use_rust/rp2040 144.9 KiB 144.9 KiB +0.00% ⬆️ +4 0 0
use_rust/rp2040_split (central) 157.9 KiB 158.0 KiB +0.00% ⬆️ +8 0 0
use_rust/rp2040_split (peripheral) 28.2 KiB 28.2 KiB +0.00% 0 0 0
use_rust/stm32f1 61.8 KiB 61.8 KiB +0.00% ⬇️ -4 0 0
use_rust/stm32h7 118.4 KiB 118.4 KiB +0.00% ⬆️ +8 0 0
use_config/nrf52832_ble — 397.5 KiB → 397.5 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 365036	   8620	  33344	 407000	  635d8	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 365036	   8620	  33344	 407000	  635d8	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +3.7%      +2  [ = ]       0    [Unmapped]
  -0.0%    -216  [ = ]       0    .debug_info
  -0.1%    -240  [ = ]       0    .debug_line
  -0.1%    -424  [ = ]       0    .strtab
  -0.1% -3.71Ki  [ = ]       0    .debug_str
  -0.1% -4.57Ki  [ = ]       0    TOTAL
use_config/nrf52840_ble — 438.1 KiB → 438.1 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 396596	   8628	  43368	 448592	  6d850	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 396600	   8628	  43368	 448596	  6d854	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +122  [ = ]       0    .debug_str
  +0.5%     +39  [ = ]       0    .debug_abbrev
  +0.0%     +33  [ = ]       0    .strtab
  +0.0%     +10  [ = ]       0    .debug_loc
  -0.0%      -4  -0.0%      -4    .text
 -41.8%     -28  [ = ]       0    [Unmapped]
  -0.0%     -79  [ = ]       0    .debug_info
  -0.0%    -157  [ = ]       0    .debug_line
  -0.0%     -64  -0.0%      -4    TOTAL
use_config/nrf52840_ble_split (central) — 500.9 KiB → 500.8 KiB (-0.01% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 455592	   8684	  48544	 512820	  7d334	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 455616	   8684	  48576	 512876	  7d36c	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.5% +4.27Ki  [ = ]       0    .debug_loc
  +0.2% +3.77Ki  [ = ]       0    .debug_info
  +0.1% +3.44Ki  [ = ]       0    .debug_str
  +0.1%    +384  [ = ]       0    .debug_ranges
  +0.1%    +128  [ = ]       0    .symtab
  +0.0%     +73  [ = ]       0    .strtab
  +0.0%     +16  [ = ]       0    .debug_aranges
  +0.0%      +8  [ = ]       0    .debug_frame
  +0.9%      +8  [ = ]       0    .defmt
  -6.1%      -4  [ = ]       0    [Unmapped]
  -0.0%      -8  -0.0%      -8    .rodata
  -0.0%     -16  -0.0%     -16    .text
  [ = ]       0  -0.1%     -32    .bss
  -0.5%     -39  [ = ]       0    .debug_abbrev
  -0.1%    -255  [ = ]       0    .debug_line
  +0.1% +11.8Ki  -0.0%     -56    TOTAL
use_config/nrf52840_ble_split (peripheral) — 320.6 KiB → 320.6 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 292408	   8500	  27424	 328332	  5028c	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 292344	   8500	  27472	 328316	  5027c	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +3.06Ki  [ = ]       0    .debug_info
  +0.1% +2.63Ki  [ = ]       0    .debug_str
  +0.3% +1.87Ki  [ = ]       0    .debug_loc
  +0.1%    +240  [ = ]       0    .debug_ranges
  +0.2%     +64  +0.2%     +64    .rodata
  -5.7%      -4  [ = ]       0    [Unmapped]
  -0.0%      -8  [ = ]       0    .debug_aranges
  [ = ]       0  -0.2%     -48    .bss
  -0.2%     -60  [ = ]       0    .debug_frame
  -0.1%     -96  [ = ]       0    .symtab
  -0.1%    -144  [ = ]       0    .debug_line
  -0.2%    -582  [ = ]       0    .strtab
  +0.1% +6.98Ki  +0.0%     +16    TOTAL
use_config/pi_pico_w_ble — 671.1 KiB → 671.1 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 634352	      0	  52904	 687256	  a7c98	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 634348	      0	  52904	 687252	  a7c94	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +10  [ = ]       0    .debug_loc
  +0.0%      +4  +0.0%      +4    .text
 -12.5%      -9  [ = ]       0    [Unmapped]
  -0.0%     -29  [ = ]       0    .debug_info
  -0.4%     -39  [ = ]       0    .debug_abbrev
  -0.0%     -73  [ = ]       0    .debug_line
  -0.1%    -350  [ = ]       0    .strtab
  -0.1% -2.51Ki  [ = ]       0    .debug_str
  -0.0% -2.98Ki  +0.0%      +4    TOTAL
use_config/rp2040 — 145.8 KiB → 145.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135384	      0	  13892	 149276	  2471c	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135384	      0	  13892	 149276	  2471c	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +30  [ = ]       0    .debug_line
  +0.0%     +10  [ = ]       0    .debug_loc
  +0.0%     +40  [ = ]       0    TOTAL
use_config/rp2040_split (central) — 159.4 KiB → 159.4 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 148396	      0	  14844	 163240	  27da8	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 148388	      0	  14844	 163232	  27da0	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -2  [ = ]       0    .strtab
 -17.8%      -8  [ = ]       0    [Unmapped]
  -0.0%     -49  [ = ]       0    .debug_info
  -0.0%     -70  [ = ]       0    .debug_str
  -0.1%    -143  [ = ]       0    .debug_line
  -0.0%    -264  +0.0%      +8    TOTAL
use_config/rp2040_split (peripheral) — 27.9 KiB → 27.9 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25696	     60	   2804	  28560	   6f90	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25696	     60	   2804	  28560	   6f90	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +1.9%      +1  [ = ]       0    [Unmapped]
  -0.2%     -39  [ = ]       0    .strtab
  -0.1%    -714  [ = ]       0    .debug_str
  -0.1%    -752  [ = ]       0    TOTAL
use_config/stm32f1 — 62.6 KiB → 62.5 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57684	     28	   6336	  64048	   fa30	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57688	     28	   6336	  64052	   fa34	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +62  [ = ]       0    .debug_str
  +0.0%      +9  [ = ]       0    .strtab
  +0.0%      +6  [ = ]       0    .debug_line
  +5.0%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0%     +76  -0.0%      -4    TOTAL
use_config/stm32h7 — 100.8 KiB → 100.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  94840	    264	   8112	 103216	  19330	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  94840	    264	   8112	 103216	  19330	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL
use_rust/nrf52832_ble — 385.5 KiB → 385.5 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 352776	   8620	  33320	 394716	  605dc	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 352776	   8620	  33320	 394716	  605dc	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  -4.8%      -3  [ = ]       0    [Unmapped]
  -0.0%     -30  [ = ]       0    .strtab
  -0.0%    -110  [ = ]       0    .debug_str
  -0.0%    -138  [ = ]       0    .debug_line
  -0.0%    -251  [ = ]       0    .debug_info
  -0.0%    -532  [ = ]       0    TOTAL
use_rust/nrf52840_ble — 435.6 KiB → 435.6 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 396796	   8628	  40616	 446040	  6ce58	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 396800	   8628	  40616	 446044	  6ce5c	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +70  [ = ]       0    .debug_line
   +11%      +6  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0%     +72  -0.0%      -4    TOTAL
use_rust/nrf52840_ble_split (central) — 504.9 KiB → 504.9 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 457808	   8684	  50512	 517004	  7e38c	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 457784	   8684	  50544	 517012	  7e394	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.5% +4.47Ki  [ = ]       0    .debug_loc
  +0.2% +4.47Ki  [ = ]       0    .debug_info
  +0.1% +3.50Ki  [ = ]       0    .debug_str
  +0.1%    +384  [ = ]       0    .debug_ranges
  +0.1%    +160  [ = ]       0    .symtab
  +0.0%     +85  [ = ]       0    .debug_line
  +0.0%     +70  [ = ]       0    .strtab
  +0.0%     +32  +0.0%     +32    .text
  +0.0%     +24  [ = ]       0    .debug_aranges
  +0.0%     +24  [ = ]       0    .debug_frame
   +16%      +7  [ = ]       0    [Unmapped]
  -0.0%      -8  -0.0%      -8    .rodata
  [ = ]       0  -0.1%     -32    .bss
  +0.1% +13.2Ki  -0.0%      -8    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 318.4 KiB → 318.4 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 290360	   8500	  27192	 326052	  4f9a4	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 290336	   8500	  27240	 326076	  4f9bc	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +2.77Ki  [ = ]       0    .debug_info
  +0.1% +2.51Ki  [ = ]       0    .debug_str
  +0.3% +1.69Ki  [ = ]       0    .debug_loc
  +0.1%    +168  [ = ]       0    .debug_ranges
  +0.2%     +72  +0.2%     +72    .rodata
   +21%     +12  [ = ]       0    [Unmapped]
  -0.0%     -16  [ = ]       0    .debug_aranges
  [ = ]       0  -0.2%     -48    .bss
  -0.0%     -48  -0.0%     -48    .text
  -0.2%     -60  [ = ]       0    .debug_frame
  -0.1%     -96  [ = ]       0    .symtab
  -0.1%    -279  [ = ]       0    .debug_line
  -0.2%    -570  [ = ]       0    .strtab
  +0.1% +6.18Ki  -0.0%     -24    TOTAL
use_rust/pi_pico_w_ble — 671.1 KiB → 671.1 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 634228	      0	  53008	 687236	  a7c84	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 634220	      0	  53008	 687228	  a7c7c	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +894  [ = ]       0    .debug_str
  +0.0%    +109  [ = ]       0    .debug_info
  +0.0%     +52  [ = ]       0    .strtab
  +0.0%      +8  +0.0%      +8    .text
 -10.3%      -7  [ = ]       0    [Unmapped]
  -0.4%     -39  [ = ]       0    .debug_abbrev
  -0.0%     -73  [ = ]       0    .debug_line
  +0.0%    +944  +0.0%      +8    TOTAL
use_rust/rp2040 — 144.9 KiB → 144.9 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 134676	      0	  13732	 148408	  243b8	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 134672	      0	  13732	 148404	  243b4	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +173  [ = ]       0    .debug_str
  +0.0%     +83  [ = ]       0    .debug_line
  +0.0%     +28  [ = ]       0    .debug_info
  +0.0%      +9  [ = ]       0    .strtab
  +0.0%      +4  +0.0%      +4    .text
  -7.7%      -5  [ = ]       0    [Unmapped]
  +0.0%    +292  +0.0%      +4    TOTAL
use_rust/rp2040_split (central) — 157.9 KiB → 158.0 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 147160	      0	  14588	 161748	  277d4	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 147152	      0	  14588	 161740	  277cc	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -2  [ = ]       0    .strtab
  -4.9%      -3  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  -0.0%     -49  [ = ]       0    .debug_info
  -0.0%     -70  [ = ]       0    .debug_str
  -0.1%    -142  [ = ]       0    .debug_line
  -0.0%    -268  +0.0%      +8    TOTAL
use_rust/rp2040_split (peripheral) — 28.2 KiB → 28.2 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25796	     60	   3068	  28924	   70fc	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25796	     60	   3068	  28924	   70fc	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
 -10.0%      -5  [ = ]       0    [Unmapped]
  -0.2%     -38  [ = ]       0    .strtab
  -0.1%    -737  [ = ]       0    .debug_str
  -0.1%    -780  [ = ]       0    TOTAL
use_rust/stm32f1 — 61.8 KiB → 61.8 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57012	     28	   6272	  63312	   f750	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57016	     28	   6272	  63316	   f754	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +62  [ = ]       0    .debug_str
  +0.0%      +9  [ = ]       0    .strtab
  +0.0%      +6  [ = ]       0    .debug_line
  +5.0%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0%     +76  -0.0%      -4    TOTAL
use_rust/stm32h7 — 118.4 KiB → 118.4 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 106908	    320	  14012	 121240	  1d998	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 106900	    320	  14012	 121232	  1d990	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +856  [ = ]       0    .debug_str
  +0.1%     +56  [ = ]       0    .strtab
  +0.0%     +28  [ = ]       0    .debug_info
  +0.0%      +8  +0.0%      +8    .text
  -0.0%     -10  [ = ]       0    .debug_loc
 -18.0%     -11  [ = ]       0    [Unmapped]
  -0.0%     -35  [ = ]       0    .debug_line
  +0.0%    +892  +0.0%      +8    TOTAL

@HaoboGu HaoboGu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, thanks very much!

@HaoboGu
HaoboGu merged commit 2a2986c into rmk-rs:main Jul 31, 2026
59 checks passed
@tompre
tompre deleted the fix/ble-msg-encode branch August 3, 2026 08:06
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