-
Notifications
You must be signed in to change notification settings - Fork 198
Unit tests for peripheral #442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
0e23d3d
62093e5
b972d81
3688ca4
e94fde5
20c8126
76a172e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,46 +8,46 @@ abstract class _DescriptorMetadata { | |||||
|
||||||
class Descriptor extends InternalDescriptor { | ||||||
ManagerForDescriptor _manager; | ||||||
TransactionIdGenerator _transactionIdGenerator; | ||||||
Characteristic characteristic; | ||||||
String uuid; | ||||||
|
||||||
Descriptor.fromJson( | ||||||
Map<String, dynamic> jsonObject, | ||||||
Characteristic characteristic, | ||||||
ManagerForDescriptor manager, | ||||||
) : super(jsonObject[_DescriptorMetadata.id]) { | ||||||
Descriptor.fromJson(Map<String, dynamic> jsonObject, | ||||||
Characteristic characteristic, ManagerForDescriptor manager, | ||||||
{TransactionIdGenerator transactionIdGenerator = | ||||||
TransactionIdGenerator.INSTANCE}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and run formatter |
||||||
: super(jsonObject[_DescriptorMetadata.id]) { | ||||||
_manager = manager; | ||||||
_transactionIdGenerator = transactionIdGenerator; | ||||||
this.characteristic = characteristic; | ||||||
uuid = jsonObject[_DescriptorMetadata.uuid]; | ||||||
} | ||||||
|
||||||
Future<Uint8List> read({String transactionId}) => | ||||||
_manager.readDescriptorForIdentifier( | ||||||
this, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
Future<void> write(Uint8List value, {String transactionId}) => | ||||||
_manager.writeDescriptorForIdentifier( | ||||||
this, | ||||||
value, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
@override | ||||||
bool operator ==(Object other) => | ||||||
identical(this, other) || | ||||||
other is Descriptor && | ||||||
runtimeType == other.runtimeType && | ||||||
_manager == other._manager && | ||||||
characteristic == other.characteristic && | ||||||
uuid == other.uuid; | ||||||
other is Descriptor && | ||||||
runtimeType == other.runtimeType && | ||||||
_manager == other._manager && | ||||||
characteristic == other.characteristic && | ||||||
uuid == other.uuid; | ||||||
|
||||||
@override | ||||||
int get hashCode => | ||||||
_manager.hashCode ^ | ||||||
characteristic.hashCode ^ | ||||||
uuid.hashCode; | ||||||
_manager.hashCode ^ characteristic.hashCode ^ uuid.hashCode; | ||||||
} | ||||||
|
||||||
class DescriptorWithValue extends Descriptor with WithValue { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,14 +16,18 @@ abstract class _PeripheralMetadata { | |||||
class Peripheral { | ||||||
static const int NO_MTU_NEGOTIATION = 0; | ||||||
ManagerForPeripheral _manager; | ||||||
TransactionIdGenerator _transactionIdGenerator; | ||||||
|
||||||
String name; | ||||||
String identifier; | ||||||
|
||||||
Peripheral.fromJson(Map<String, dynamic> json, ManagerForPeripheral manager) | ||||||
Peripheral.fromJson(Map<String, dynamic> json, ManagerForPeripheral manager, | ||||||
{TransactionIdGenerator transactionIdGenerator = | ||||||
TransactionIdGenerator.INSTANCE}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and run formatter |
||||||
: _manager = manager, | ||||||
name = json[_PeripheralMetadata.name], | ||||||
identifier = json[_PeripheralMetadata.identifier]; | ||||||
identifier = json[_PeripheralMetadata.identifier], | ||||||
_transactionIdGenerator = transactionIdGenerator; | ||||||
|
||||||
/// Connects to the peripheral. | ||||||
/// | ||||||
|
@@ -82,7 +86,7 @@ class Peripheral { | |||||
/// Optional [transactionId] could be used to cancel operation. | ||||||
Future<void> discoverAllServicesAndCharacteristics({String transactionId}) => | ||||||
_manager.discoverAllServicesAndCharacteristics( | ||||||
this, transactionId ?? TransactionIdGenerator.getNextId()); | ||||||
this, transactionId ?? _transactionIdGenerator.getNextId()); | ||||||
|
||||||
/// Returns a list of [Service]s of this peripheral. | ||||||
/// | ||||||
|
@@ -103,7 +107,7 @@ class Peripheral { | |||||
/// | ||||||
/// Optional [transactionId] could be used to cancel operation. | ||||||
Future<int> rssi({String transactionId}) => | ||||||
_manager.rssi(this, transactionId ?? TransactionIdGenerator.getNextId()); | ||||||
_manager.rssi(this, transactionId ?? _transactionIdGenerator.getNextId()); | ||||||
|
||||||
/// Requests new MTU value for current connection and return the negotiation | ||||||
/// result on Android, reads MTU on iOS. | ||||||
|
@@ -118,7 +122,7 @@ class Peripheral { | |||||
/// If MTU has been requested in [connect()] this method will end with [BleError]. | ||||||
Future<int> requestMtu(int mtu, {String transactionId}) => | ||||||
_manager.requestMtu( | ||||||
this, mtu, transactionId ?? TransactionIdGenerator.getNextId()); | ||||||
this, mtu, transactionId ?? _transactionIdGenerator.getNextId()); | ||||||
|
||||||
/// Reads value of [Characteristic] matching specified UUIDs. | ||||||
/// | ||||||
|
@@ -135,7 +139,7 @@ class Peripheral { | |||||
this, | ||||||
serviceUuid, | ||||||
characteristicUuid, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
/// Writes value of [Characteristic] matching specified UUIDs. | ||||||
|
@@ -157,7 +161,7 @@ class Peripheral { | |||||
characteristicUuid, | ||||||
value, | ||||||
withResponse, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
/// Returns a list of [Descriptor]s for [Characteristic] matching specified UUIDs. | ||||||
|
@@ -191,7 +195,7 @@ class Peripheral { | |||||
serviceUuid, | ||||||
characteristicUuid, | ||||||
descriptorUuid, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
/// Writes value of [Descriptor] matching specified UUIDs. | ||||||
|
@@ -214,7 +218,7 @@ class Peripheral { | |||||
characteristicUuid, | ||||||
descriptorUuid, | ||||||
value, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
/// Returns a stream of notifications/indications from [Characteristic] | ||||||
|
@@ -236,7 +240,7 @@ class Peripheral { | |||||
this, | ||||||
serviceUuid, | ||||||
characteristicUuid, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
@override | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,18 +11,20 @@ class Service extends InternalService { | |||||
Peripheral peripheral; | ||||||
|
||||||
ManagerForService _manager; | ||||||
TransactionIdGenerator _transactionIdGenerator; | ||||||
|
||||||
/// The UUID of this service. | ||||||
String uuid; | ||||||
|
||||||
Service.fromJson( | ||||||
Map<String, dynamic> jsonObject, | ||||||
Peripheral peripheral, | ||||||
ManagerForService managerForService, | ||||||
) : super(jsonObject[_ServiceMetadata.id]) { | ||||||
Service.fromJson(Map<String, dynamic> jsonObject, Peripheral peripheral, | ||||||
ManagerForService managerForService, | ||||||
{TransactionIdGenerator transactionIdGenerator = | ||||||
TransactionIdGenerator.INSTANCE}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and run formatter |
||||||
: super(jsonObject[_ServiceMetadata.id]) { | ||||||
this.peripheral = peripheral; | ||||||
uuid = jsonObject[_ServiceMetadata.uuid]; | ||||||
_manager = managerForService; | ||||||
_transactionIdGenerator = transactionIdGenerator; | ||||||
} | ||||||
|
||||||
/// Returns a list of [Characteristic]s of this service. | ||||||
|
@@ -51,7 +53,7 @@ class Service extends InternalService { | |||||
characteristicUuid, | ||||||
value, | ||||||
withResponse, | ||||||
transactionId ?? TransactionIdGenerator.getNextId()); | ||||||
transactionId ?? _transactionIdGenerator.getNextId()); | ||||||
|
||||||
/// Reads the value of a [Characteristic] identified by [characteristicUuid]. | ||||||
/// | ||||||
|
@@ -67,7 +69,7 @@ class Service extends InternalService { | |||||
peripheral, | ||||||
this, | ||||||
characteristicUuid, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
/// Returns a [Stream] of values emitted by a [Characteristic] identified by | ||||||
|
@@ -86,7 +88,7 @@ class Service extends InternalService { | |||||
peripheral, | ||||||
this, | ||||||
characteristicUuid, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
/// Returns a list of [Descriptor]s of a [Characteristic] identified by | ||||||
|
@@ -114,7 +116,7 @@ class Service extends InternalService { | |||||
this, | ||||||
characteristicUuid, | ||||||
descriptorUuid, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
/// Writes the [value] of a [Descriptor] identified by [descriptorUuid] | ||||||
|
@@ -132,7 +134,7 @@ class Service extends InternalService { | |||||
characteristicUuid, | ||||||
descriptorUuid, | ||||||
value, | ||||||
transactionId ?? TransactionIdGenerator.getNextId(), | ||||||
transactionId ?? _transactionIdGenerator.getNextId(), | ||||||
); | ||||||
|
||||||
@override | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,10 +8,12 @@ class InternalBleManager | |||||
ManagerForCharacteristic, | ||||||
ManagerForDescriptor { | ||||||
FlutterBleLib _bleLib; | ||||||
TransactionIdGenerator _transactionIdGenerator; | ||||||
|
||||||
InternalBleManager() { | ||||||
InternalBleManager({TransactionIdGenerator transactionIdGenerator = TransactionIdGenerator.INSTANCE}) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and run formatter |
||||||
_bleLib = FlutterBleLib(); | ||||||
_bleLib.registerManager(this); | ||||||
_transactionIdGenerator = transactionIdGenerator; | ||||||
} | ||||||
|
||||||
@override | ||||||
|
@@ -36,11 +38,11 @@ class InternalBleManager | |||||
|
||||||
@override | ||||||
Future<void> enableRadio({String transactionId}) => | ||||||
_bleLib.enableRadio(transactionId ?? TransactionIdGenerator.getNextId()); | ||||||
_bleLib.enableRadio(transactionId ?? _transactionIdGenerator.getNextId()); | ||||||
|
||||||
@override | ||||||
Future<void> disableRadio({String transactionId}) => | ||||||
_bleLib.disableRadio(transactionId ?? TransactionIdGenerator.getNextId()); | ||||||
_bleLib.disableRadio(transactionId ?? _transactionIdGenerator.getNextId()); | ||||||
|
||||||
@override | ||||||
Future<BluetoothState> bluetoothState() => _bleLib.state(); | ||||||
|
@@ -172,7 +174,7 @@ class InternalBleManager | |||||
} | ||||||
|
||||||
@override | ||||||
Future<void> requestMtu( | ||||||
Future<int> requestMtu( | ||||||
Peripheral peripheral, int mtu, String transactionId) { | ||||||
return _bleLib.requestMtu(peripheral, mtu, transactionId); | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
abstract class TransactionIdGenerator { | ||
class TransactionIdGenerator { | ||
static int _id = 0; | ||
static const TransactionIdGenerator INSTANCE = const TransactionIdGenerator._internal(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. run formatter |
||
|
||
static String getNextId() { | ||
String getNextId() { | ||
_id++; | ||
return _id.toString(); | ||
} | ||
|
||
const TransactionIdGenerator._internal(); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.