Skip to content

Commit

Permalink
Merge pull request #13 from particle-iot/feature/add-mesh-network-info
Browse files Browse the repository at this point in the history
add support for mesh network info to ParticleDevice
  • Loading branch information
RaimundasSakalauskas authored Jul 30, 2019
2 parents 75d0647 + 06693b4 commit 3b4fa88
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
13 changes: 3 additions & 10 deletions ParticleSDK/SDK/ParticleDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,15 @@ typedef NS_ENUM(NSInteger, ParticleDeviceSystemEvent) {
ParticleDeviceSystemEventSafeModeUpdater
};


typedef NS_ENUM(NSInteger, ParticleDeviceNetworkState) {
ParticleDeviceNetworkStatePending,
ParticleDeviceNetworkStateConfirmed
};

typedef NS_ENUM(NSInteger, ParticleDeviceNetworkRole) {
ParticleDeviceNetworkStateGateway,
ParticleDeviceNetworkStateNode,
ParticleDeviceNetworkRoleGateway,
ParticleDeviceNetworkRoleNode,
};

typedef NS_ENUM(NSInteger, ParticleDeviceNetworkRoleState) {
ParticleDeviceNetworkRoleStatePending,
ParticleDeviceNetworkRoleStatePendingConfirmed,
// ParticleDeviceNetworkRoleStateOwnerConfirmation
ParticleDeviceNetworkRoleStatePendingOwnerApproval
};

@class ParticleDevice;
Expand Down Expand Up @@ -115,7 +109,6 @@ typedef NS_ENUM(NSInteger, ParticleDeviceNetworkRoleState) {

// new properties for mesh networks SDK v0.9
@property (strong, nonatomic, nullable, readonly) NSString *networkId; // if device belongs to a mesh network thats the network ID
@property (nonatomic, readonly) ParticleDeviceNetworkState networkState; // pending if device is waiting to join network confirmation
@property (nonatomic, readonly) ParticleDeviceNetworkRole networkRole; // if device belongs to a mesh network true means it is a gateway device
@property (nonatomic, readonly) ParticleDeviceNetworkRoleState networkRoleState; // pending if device is waiting to role change confirmation

Expand Down
32 changes: 29 additions & 3 deletions ParticleSDK/SDK/ParticleDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,29 @@ -(nullable instancetype)initWithParams:(NSDictionary *)params
_notes = params[@"notes"];
}

if (params[@"network"] != nil) {
if ((params[@"network"][@"id"]) && ([params[@"network"][@"id"] isKindOfClass:[NSString class]])) {
_networkId = params[@"network"][@"id"];

if ((params[@"network"][@"role"]) && (params[@"network"][@"role"][@"gateway"])) {
_networkRole = ([params[@"network"][@"role"][@"gateway"] boolValue]) ? ParticleDeviceNetworkRoleGateway : ParticleDeviceNetworkRoleNode;
}

if ((params[@"network"][@"role"]) && (params[@"network"][@"role"][@"state"]) && ([params[@"network"][@"role"][@"state"] isKindOfClass:[NSString class]])) {
NSString *state = [params[@"network"][@"role"][@"state"] lowercaseString];

if ([state isEqualToString:@"confirmed"]) {
_networkRoleState = ParticleDeviceNetworkRoleStatePendingConfirmed;
} else if ([state isEqualToString:@"pending"]) {
_networkRoleState = ParticleDeviceNetworkRoleStatePending;
} else {
_networkRoleState = ParticleDeviceNetworkRoleStatePendingOwnerApproval;
}
}
}
}


if ((params[@"system_firmware_version"]) && ([params[@"system_firmware_version"] isKindOfClass:[NSString class]]))
{
_systemFirmwareVersion = params[@"system_firmware_version"];
Expand Down Expand Up @@ -578,7 +601,7 @@ -(NSString *)description

}

NSString *desc = [NSString stringWithFormat:@"<ParticleDevice 0x%lx, type: %@, id: %@, name: %@, connected: %@, flashing: %@, variables: %@, functions: %@, version: %@, requires update: %@, last app: %@, last heard: %@, notes: %@>",
NSString *desc = [NSString stringWithFormat:@"<ParticleDevice 0x%lx, type: %@, id: %@, name: %@, connected: %@, flashing: %@, variables: %@, functions: %@, version: %@, requires update: %@, last app: %@, last heard: %@, notes: %@, networkId: %@, networkRole: %d, networkRoleState: %d>",
(unsigned long)self,
self.typeString,
self.id,
Expand All @@ -591,8 +614,11 @@ -(NSString *)description
(self.requiresUpdate) ? @"true" : @"false",
self.lastApp,
self.lastHeard,
self.notes];

self.notes,
self.networkId,
self.networkRole,
self.networkRoleState];

return desc;

}
Expand Down

0 comments on commit 3b4fa88

Please sign in to comment.