public abstract class SerialPortServer extends DefaultLocalServiceListener
SerialPortServer
class represents a serial port server.Constructor and Description |
---|
SerialPortServer(BluetoothService service)
Creates a serial port server, using the serial port service provided by this device.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this serial port server.
|
protected abstract void |
onDataReceived(BluetoothConnection connection,
byte[] data)
Called when data has been received from a client.
|
protected abstract void |
onDataSent(BluetoothConnection connection,
boolean success)
Called when data has been sent to a client.
|
void |
onNotificationSent(BluetoothConnection connection,
BluetoothCharacteristic characteristic,
boolean success)
Called when a characteristic notification or indication is sent.
|
void |
onReadRequest(BluetoothConnection connection,
BluetoothAttribute attribute)
Called when a read request is received.
|
void |
onWriteRequest(BluetoothConnection connection,
BluetoothAttribute attribute,
byte[] value)
Called when a write request is received.
|
void |
sendData(BluetoothConnection connection,
byte[] data)
Sends the given data to the given client.
|
onExecuteWriteRequest, onPrepareWriteRequest, onReadBlobRequest
public SerialPortServer(BluetoothService service) throws AttributeNotFoundException
service
- the serial port service provided by this device.AttributeNotFoundException
- if one of the mandatory attributes of the service is missing.public void close()
protected abstract void onDataReceived(BluetoothConnection connection, byte[] data)
connection
- the connection to the device from which the data has been received.data
- the data received from the client.protected abstract void onDataSent(BluetoothConnection connection, boolean success)
connection
- the connection to the device to which the data has been sent.success
- true if the the data was sent successfully, false otherwise.public void onNotificationSent(BluetoothConnection connection, BluetoothCharacteristic characteristic, boolean success)
LocalServiceListener
If a notification was sent, this method is called as soon as the notification is sent to the device. If an indication was sent, this method is called when the device acknowledges the indication.
onNotificationSent
in interface LocalServiceListener
onNotificationSent
in class DefaultLocalServiceListener
connection
- the connection with the device to which the notification was sent.characteristic
- the characteristic which has changed.success
- true if the notification was sent successfully, false otherwise.BluetoothConnection.sendNotification(BluetoothCharacteristic, byte[], boolean)
public void onReadRequest(BluetoothConnection connection, BluetoothAttribute attribute)
LocalServiceListener
onReadRequest
in interface LocalServiceListener
onReadRequest
in class DefaultLocalServiceListener
connection
- the connection with the device which has sent the request.attribute
- the attribute to read.public void onWriteRequest(BluetoothConnection connection, BluetoothAttribute attribute, byte[] value)
LocalServiceListener
onWriteRequest
in interface LocalServiceListener
onWriteRequest
in class DefaultLocalServiceListener
connection
- the connection with the device which has sent the request.attribute
- the attribute to write.value
- the value to write.public void sendData(BluetoothConnection connection, byte[] data)
onDataSent(BluetoothConnection, boolean)
methods is called
once the data has been sent to the client.connection
- the connection to the device to which the data should be sent.data
- the data to send.