PacketBuffer – Packet-oriented characteristic usage.¶
Accumulates a Characteristic’s incoming packets in a FIFO buffer and facilitates packet aware
outgoing writes. A packet’s size is either the characteristic length or the maximum transmission
unit (MTU), whichever is smaller. The MTU can change so check
packet_size before creating a
buffer to store data.
When we’re the server, we ignore all connections besides the first to subscribe to notifications.
PacketBuffer(characteristic, *, buffer_size)¶
Monitor the given Characteristic. Each time a new value is written to the Characteristic add the newly-written bytes to a FIFO buffer.
- characteristic (Characteristic) – The Characteristic to monitor. It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic in a remote Service that a Central has connected to.
- buffer_size (int) – Size of ring buffer (in packets of the Characteristic’s maximum length) that stores incoming packets coming from the peer.
Reads a single BLE packet into the
buf. Raises an exception if the next packet is longer than the given buffer. Use
packet_sizeto read the maximum length of a single packet.
Returns: number of bytes read and stored into
Return type: int
write(data, *, header=None)¶
Writes all bytes from data into the same outgoing packet. The bytes from header are included before data when the pending packet is currently empty.
This does not block until the data is sent. It only blocks until the data is pending.
Maximum size of each packet in bytes. This is the minimum of the Characteristic length and the negotiated Maximum Transfer Unit (MTU).