From 4fb515a63d2b0705d915576533e2cb20afff30c7 Mon Sep 17 00:00:00 2001 From: stli Date: Sat, 11 Apr 2026 10:42:13 +0800 Subject: [PATCH] Align GATT transport interface --- KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.cpp | 30 ++++++++++++++++++------- KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.h | 22 +++++++++++++----- docs/host_dri_rebuild.md | 11 +++++++++ 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.cpp b/KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.cpp index a0847ea..64ef797 100644 --- a/KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.cpp +++ b/KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.cpp @@ -5,7 +5,7 @@ QVector Dri_Gatt_Enum() return {}; } -void Dri_Gatt_Deinit(Dri_Gatt_Struct_Port* p_Port) +void Dri_Gatt_Close(Dri_Gatt_Struct_Port* p_Port) { if (p_Port == nullptr) { @@ -15,22 +15,33 @@ void Dri_Gatt_Deinit(Dri_Gatt_Struct_Port* p_Port) *p_Port = Dri_Gatt_Struct_Port(); } -bool Dri_Gatt_Init(Dri_Gatt_Struct_Port* p_Port) +bool Dri_Gatt_Open( + Dri_Gatt_Struct_Port* p_Port, + const QString& DeviceAddress, + const Dri_Gatt_Struct_OpenConfig&) { - if (p_Port == nullptr) + if ((p_Port == nullptr) || DeviceAddress.trimmed().isEmpty()) { return false; } - Dri_Gatt_Deinit(p_Port); + Dri_Gatt_Close(p_Port); + p_Port->IsOpened = true; + p_Port->DeviceAddress = DeviceAddress.trimmed(); return false; } -bool Dri_Gatt_Read(Dri_Gatt_Struct_Port* p_Port, QByteArray& ByteArray) +bool Dri_Gatt_ReadBytes( + Dri_Gatt_Struct_Port* p_Port, + QByteArray* p_ByteArray, + int) { - ByteArray.clear(); + if (p_ByteArray != nullptr) + { + p_ByteArray->clear(); + } - if ((p_Port == nullptr) || !p_Port->IsOpened) + if ((p_Port == nullptr) || (p_ByteArray == nullptr) || !p_Port->IsOpened) { return false; } @@ -38,7 +49,10 @@ bool Dri_Gatt_Read(Dri_Gatt_Struct_Port* p_Port, QByteArray& ByteArray) return false; } -bool Dri_Gatt_Write(Dri_Gatt_Struct_Port* p_Port, const QByteArray& ByteArray) +bool Dri_Gatt_WriteBytes( + Dri_Gatt_Struct_Port* p_Port, + const QByteArray& ByteArray, + int) { if ((p_Port == nullptr) || !p_Port->IsOpened) { diff --git a/KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.h b/KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.h index 18e9cdb..c33033f 100644 --- a/KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.h +++ b/KeyBorad/KeyBorad/DRI/GATT/Dri_Gatt.h @@ -10,15 +10,27 @@ struct Dri_Gatt_Struct_PortInfo QString DeviceAddress; }; +struct Dri_Gatt_Struct_OpenConfig +{ +}; + struct Dri_Gatt_Struct_Port { bool IsOpened = false; QString DeviceAddress; - QByteArray ReadBuffer; }; QVector Dri_Gatt_Enum(); -void Dri_Gatt_Deinit(Dri_Gatt_Struct_Port* p_Port); -bool Dri_Gatt_Init(Dri_Gatt_Struct_Port* p_Port); -bool Dri_Gatt_Read(Dri_Gatt_Struct_Port* p_Port, QByteArray& ByteArray); -bool Dri_Gatt_Write(Dri_Gatt_Struct_Port* p_Port, const QByteArray& ByteArray); +void Dri_Gatt_Close(Dri_Gatt_Struct_Port* p_Port); +bool Dri_Gatt_Open( + Dri_Gatt_Struct_Port* p_Port, + const QString& DeviceAddress, + const Dri_Gatt_Struct_OpenConfig& Config); +bool Dri_Gatt_ReadBytes( + Dri_Gatt_Struct_Port* p_Port, + QByteArray* p_ByteArray, + int TimeoutMs); +bool Dri_Gatt_WriteBytes( + Dri_Gatt_Struct_Port* p_Port, + const QByteArray& ByteArray, + int TimeoutMs); diff --git a/docs/host_dri_rebuild.md b/docs/host_dri_rebuild.md index b32130c..40e1c6b 100644 --- a/docs/host_dri_rebuild.md +++ b/docs/host_dri_rebuild.md @@ -32,6 +32,17 @@ Design notes: - keeps the implementation small for now - avoids mixing GATT transport with logic concerns +Implemented behavior: + +- keep the same surface shape as CDC: + - `Enum` + - `Open` + - `Close` + - `ReadBytes` + - `WriteBytes` +- stay transport-only +- keep real BLE implementation for a later node + ### Node 2: CDC transport cleanup Files updated in this step: