Commit 98493069 authored by Chengzhao Li's avatar Chengzhao Li
Browse files

- Since identifier only be used in iOS, android use device.address. We only...

- Since identifier only be used in iOS, android use device.address. We only map identifier/address on central device, peripheral devices only use unique id to identify devices
parent e0e11d9f
......@@ -433,7 +433,7 @@ static NCMCBluetoothLEManager *_sharedNCMCBluetoothLEManager = nil;
self.discoveredPeripherals[peripheral.identifier.UUIDString] = info;
peripheral.delegate = self;
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:name andIdentifier:peripheral.identifier.UUIDString];
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:name andIdentifier:peripheral.identifier.UUIDString andUniqueID:-1];
[self.centralService notifyFoundPeer:peerID];
}
}
......@@ -442,7 +442,7 @@ static NCMCBluetoothLEManager *_sharedNCMCBluetoothLEManager = nil;
{
NCMCPeripheralInfo *info = self.discoveredPeripherals[peripheral.identifier.UUIDString];
if (info) {
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:info.name andIdentifier:peripheral.identifier.UUIDString];
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:info.name andIdentifier:peripheral.identifier.UUIDString andUniqueID:-1];
[self.centralService notifyLostPeer:peerID];
[self.discoveredPeripherals removeObjectForKey:peripheral.identifier.UUIDString];
......@@ -503,7 +503,7 @@ static NCMCBluetoothLEManager *_sharedNCMCBluetoothLEManager = nil;
{
NSLog(@"discovery service failed : %@", error.localizedDescription);
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:info.name andIdentifier:peripheral.identifier.UUIDString];
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:info.name andIdentifier:peripheral.identifier.UUIDString andUniqueID:-1];
[self.centralService notifyLostPeer:peerID];
[self.discoveredPeripherals removeObjectForKey:peripheral.identifier.UUIDString];
......@@ -530,7 +530,7 @@ static NCMCBluetoothLEManager *_sharedNCMCBluetoothLEManager = nil;
if (error) {
NSLog(@"discovery Characteristics failed : %@", error.localizedDescription);
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:info.name andIdentifier:peripheral.identifier.UUIDString];
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:info.name andIdentifier:peripheral.identifier.UUIDString andUniqueID:-1];
[self.centralService notifyLostPeer:peerID];
[self.discoveredPeripherals removeObjectForKey:peripheral.identifier.UUIDString];
......@@ -566,7 +566,7 @@ static NCMCBluetoothLEManager *_sharedNCMCBluetoothLEManager = nil;
#if __CC_PLATFORM_IOS
NSLog(@"peripheral maxResponse : %lu , maxNoResponse : %lu", (unsigned long)[peripheral maximumWriteValueLengthForType: CBCharacteristicWriteWithResponse], (unsigned long)[peripheral maximumWriteValueLengthForType: CBCharacteristicWriteWithoutResponse]);
#endif
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:info.name andIdentifier:peripheral.identifier.UUIDString];
NCMCPeerID* peerID = [[NCMCPeerID alloc]initWithDisplayName:info.name andIdentifier:peripheral.identifier.UUIDString andUniqueID:-1];
if (isReadCharFound && isWriteWithResponseCharFoud && isWriteWithoutResponseCharFoud) {
// send central info to peripheral and wait for perpheral confirm the connection
if (self.session != nil) {
......
......@@ -13,7 +13,8 @@
@property (strong, nonatomic)NSString *identifier;
@property (strong, nonatomic)NSString *displayName;
@property (assign, nonatomic)char uniqueID;
- (instancetype)initWithDisplayName:(NSString *)n andIdentifier:(NSString*)i;
- (instancetype)initWithDisplayName:(NSString *)_name andIdentifier:(NSString*)_identifier andUniqueID:(char)_uniqueID;
@end
......@@ -13,12 +13,13 @@
@interface NCMCSession()
@property (strong, nonatomic)NSString* serviceID;
@property (assign, nonatomic)char myUniqueID;
@property (strong, nonatomic)NSMutableDictionary<NSString*, NCMCDeviceInfo*> *connectedDevices;
@property (strong, nonatomic)NSMutableArray<NCMCDeviceInfo*> *connectedDevices;
-(void)notifyPeerStateChanged:(NCMCPeerID *)peerID newState:(NCMCSessionState)state;
-(void)notifyDidReceiveData:(NSData *)data fromPeer:(NCMCPeerID *)peerID;
-(char)getDeviceUniqueIDByIdentifier:(NSString*)identifier;
-(void)onDataReceived:(NSData *)data from:(NSString *)identifier;
-(void)onPeripheralDisconnected:(NSString *)identifier; // used by central
-(void)onCentralDisconnected; // used by perihearal
......@@ -26,6 +27,5 @@
-(void)sendCentralConnectionRequestToPeer:(NCMCPeerID *)peerID;
-(void)setSelfAsCentral;
-(NSString*)getCentralDeviceIdentifier;
@end
......@@ -9,7 +9,7 @@
@implementation NCMCPeerID
@synthesize displayName, identifier;
@synthesize displayName, identifier, uniqueID;
-(instancetype)initWithDisplayName:(NSString *)name
{
......@@ -18,18 +18,20 @@
if (self) {
self.displayName = name;
self.identifier = [[[NSUUID alloc]init] UUIDString];
self.uniqueID = -1;
}
return self;
}
-(instancetype)initWithDisplayName:(NSString *)n andIdentifier:(NSString *)i
-(instancetype)initWithDisplayName:(NSString *)_name andIdentifier:(NSString *)_identifier andUniqueID:(char)_uniqueID
{
self = [super init];
if (self) {
self.displayName = n;
self.identifier = i;
self.displayName = _name;
self.identifier = _identifier;
self.uniqueID = _uniqueID;
}
return self;
......@@ -48,6 +50,7 @@
// Copy NSObject subclasses
[copy setIdentifier:self.identifier];
[copy setDisplayName:self.displayName];
[copy setUniqueID:self.uniqueID];
}
return copy;
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment