File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -184,16 +184,22 @@ class BLEPacketReconstructor {
184184 " peripheral_id " : peripheralId
185185 ] )
186186
187- // Find the buffer for this peripheral (we don't know the query ID yet)
188187 let bufferKeys = continuationBuffer. keys. filter { $0. hasPrefix ( peripheralId) }
189188
190189 if bufferKeys. isEmpty {
191- // This might be the first packet of a multipart response
192190 return handleFirstPacketOfMultipart ( data: data, peripheralId: peripheralId)
193191 }
194192
195- // Track sequence counters for multiple concurrent operations
196- guard let bufferKey = bufferKeys. first else {
193+ // When multiple buffers exist, pick the most recently active one.
194+ // Continuation packets don't carry a query ID, so we use recency
195+ // as the best heuristic. The GoPro BLE protocol expects one
196+ // multipart response per characteristic at a time.
197+ let bufferKey : String
198+ if bufferKeys. count == 1 {
199+ bufferKey = bufferKeys [ 0 ]
200+ } else if let mostRecent = bufferKeys. max ( by: { ( lastPacketTime [ $0] ?? . distantPast) < ( lastPacketTime [ $1] ?? . distantPast) } ) {
201+ bufferKey = mostRecent
202+ } else {
197203 ErrorHandler . bleError ( " No buffer key found for continuation packet " , context: [ " peripheral_id " : peripheralId] )
198204 return nil
199205 }
You can’t perform that action at this time.
0 commit comments