From f9ba6bf41d8c2afa987c9cf476678a129cf6a0e0 Mon Sep 17 00:00:00 2001 From: Raj Nakarja Date: Tue, 27 Aug 2024 18:12:13 +0200 Subject: [PATCH] Improved bluetooth throughput from 50kBps to 60Bps Updated camera FPS script to show FPS value --- source/application/bluetooth.c | 2 +- source/application/bluetooth.h | 2 +- source/memory_layout.ld | 2 +- tests/test_camera_fps.py | 13 ++++++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/source/application/bluetooth.c b/source/application/bluetooth.c index 482bf0b7..702a27ec 100644 --- a/source/application/bluetooth.c +++ b/source/application/bluetooth.c @@ -368,7 +368,7 @@ void bluetooth_setup(bool factory_reset) ble_cfg_t cfg; cfg.conn_cfg.conn_cfg_tag = 1; cfg.conn_cfg.params.gap_conn_cfg.conn_count = 1; - cfg.conn_cfg.params.gap_conn_cfg.event_length = 300; + cfg.conn_cfg.params.gap_conn_cfg.event_length = (15 * 1000) / 1250; check_error(sd_ble_cfg_set(BLE_CONN_CFG_GAP, &cfg, ram_start)); // Set BLE role to peripheral only diff --git a/source/application/bluetooth.h b/source/application/bluetooth.h index b8a919dd..93d4b4d6 100644 --- a/source/application/bluetooth.h +++ b/source/application/bluetooth.h @@ -28,7 +28,7 @@ #include #include -#define BLE_PREFERRED_MAX_MTU 256 +#define BLE_PREFERRED_MAX_MTU 185 extern uint16_t ble_negotiated_mtu; void bluetooth_setup(bool factory_reset); diff --git a/source/memory_layout.ld b/source/memory_layout.ld index 749b5919..4267ddd5 100644 --- a/source/memory_layout.ld +++ b/source/memory_layout.ld @@ -51,7 +51,7 @@ ENTRY(Reset_Handler) MEMORY { APPLICATION_FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0xCE000 - APPLICATION_RAM (rwx) : ORIGIN = 0x20002A08, LENGTH = 256K - 0x2A08 + APPLICATION_RAM (rwx) : ORIGIN = 0x200026F8, LENGTH = 256K - 0x26F8 BOOTLOADER_FLASH (rx) : ORIGIN = 0xF5000, LENGTH = 0x9000 BOOTLOADER_RAM (rwx) : ORIGIN = 0x20002AE8, LENGTH = 256K - 0x2AE8 diff --git a/tests/test_camera_fps.py b/tests/test_camera_fps.py index 5b6fb446..c967efb9 100644 --- a/tests/test_camera_fps.py +++ b/tests/test_camera_fps.py @@ -1,6 +1,7 @@ from aioconsole import ainput from frameutils import Bluetooth import asyncio +import time header = bytearray( [ @@ -631,20 +632,26 @@ ) image_buffer = b"" +last_fps_time = time.time() +fps = 0 def receive_data(data): global image_buffer + global last_fps_time + global fps if len(data) == 1: with open("temp_focus_image.jpg", "wb") as f: f.write(header + image_buffer) image_buffer = b"" + fps = 1 / (time.time() - last_fps_time) + last_fps_time = time.time() return image_buffer += data[1:] print( - f"Received {str(len(image_buffer)-1)} bytes. Press enter to finish ", + f"Received {str(len(image_buffer)-1)} bytes. FPS = {fps}. Press enter to finish ", end="\r", ) @@ -658,11 +665,11 @@ async def main(): while true do if state == 'CAPTURE' then - frame.camera.capture { quality_factor = 25 } + frame.camera.capture { quality_factor = 50 } state_time = frame.time.utc() state = 'WAIT' elseif state == 'WAIT' then - if frame.time.utc() > state_time + 0.2 then + if frame.time.utc() > state_time + 0.1 then state = 'SEND' end elseif state == 'SEND' then