mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	qt-ble: allow reading of partial packet data
The existing BLE dive computers treat BLE as the packetized protocol it is, and read whole packets at a time. However, the Mares BlueLink backend treats it as just a basic "serial over BLE" transport, and for historical reasons reads the reply packets in smaller chunks. This allows that kind of IO behavior, where if the divecomputer backend reads just a part of a packet, we'll split the packet, return the part the user asked for, and push back the leftover packet onto the received packet queue. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									8426024b76
								
							
						
					
					
						commit
						890d4c3d64
					
				
					 1 changed files with 9 additions and 2 deletions
				
			
		|  | @ -191,8 +191,15 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual) | |||
| 
 | ||||
| 	QByteArray packet = receivedPackets.takeFirst(); | ||||
| 
 | ||||
| 	if ((size_t)packet.size() > size) | ||||
| 		return DC_STATUS_NOMEMORY; | ||||
| 	// Did we get more than asked for?
 | ||||
| 	//
 | ||||
| 	// Put back the left-over at the beginning of the
 | ||||
| 	// received packet list, and truncate the packet
 | ||||
| 	// we got to just the part asked for.
 | ||||
| 	if ((size_t)packet.size() > size) { | ||||
| 		receivedPackets.prepend(packet.mid(size)); | ||||
| 		packet.truncate(size); | ||||
| 	} | ||||
| 
 | ||||
| 	memcpy((char *)data, packet.data(), packet.size()); | ||||
| 	if (actual) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue