Skip to content

Commit

Permalink
Feature : get publication settings (#222)
Browse files Browse the repository at this point in the history
* expose ConfigModelPublicationGet message

* added iOS argmuents class
  • Loading branch information
R0m4in-dooz authored Feb 9, 2022
1 parent edfdf33 commit 1b7eea3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ class DoozMeshManagerApi(context: Context, binaryMessenger: BinaryMessenger) : S
mMeshManagerApi.createMeshPdu(pNode.unicastAddress, meshMessage)
result.success(null)
}
"getPublicationSettings" -> {
val elementAddress = call.argument<Int>("elementAddress")!!
val modelIdentifier = call.argument<Int>("modelIdentifier")!!
val currentMeshNetwork = mMeshManagerApi.meshNetwork!!
val pNode: ProvisionedMeshNode = currentMeshNetwork.getNode(elementAddress)
val meshMessage = ConfigModelPublicationGet(
elementAddress,
modelIdentifier
)
mMeshManagerApi.createMeshPdu(pNode.unicastAddress, meshMessage)
result.success(null)
}
"sendV2MagicLevel" -> {
val io = call.argument<Int>("io")!!
val index = call.argument<Int>("index")!!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// GetPublicationSettingsArguments.swift
// nordic_nrf_mesh
//
// Created by OZEO DOOZ on 09/02/2022.
//

struct GetPublicationSettingsArguments: BaseFlutterArguments {
let elementAddress: Int16
let modelIdentifier: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum DoozMeshManagerApiChannel {
case setSNBeacon(_ data: ConfigBeaconSetArguments)
case sendConfigModelSubscriptionDeleteAll(_ data: SendConfigModelSubscriptionDeleteAllArguments)
case sendConfigModelPublicationSet(_ data: SendConfigModelPublicationSetArguments)
case getPublicationSettings(_ data: GetPublicationSettingsArguments)
case sendLightLightness(_ data: SendLightLightnessArguments)
case sendLightCtl(_ data: SendLightCtlArguments)
case sendLightHsl(_ data: SendLightHslArguments)
Expand Down Expand Up @@ -111,6 +112,8 @@ enum DoozMeshManagerApiChannel {
self = .sendConfigModelSubscriptionDeleteAll(try SendConfigModelSubscriptionDeleteAllArguments(arguments))
case "sendConfigModelPublicationSet":
self = .sendConfigModelPublicationSet(try SendConfigModelPublicationSetArguments(arguments))
case "getPublicationSettings":
self = .getPublicationSettings(try GetPublicationSettingsArguments(arguments))
case "sendLightLightness":
self = .sendLightLightness(try SendLightLightnessArguments(arguments))
case "sendLightCtl":
Expand Down
15 changes: 15 additions & 0 deletions ios/Classes/DoozMeshManagerApi/DoozMeshManagerApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,21 @@ private extension DoozMeshManagerApi {
}
}
break
case .getPublicationSettings(let data):
if
let node = meshNetworkManager.meshNetwork?.node(withAddress: Address(exactly: data.elementAddress)!),
let element = node.element(withAddress: Address(exactly: data.elementAddress)!),
let model = element.model(withModelId: UInt32(data.modelIdentifier)){
let message: ConfigModelPublicationGet = ConfigModelPublicationGet(for: model)!
do{
_ = try meshNetworkManager.send(message, to: node)
result(nil)
}catch{
let nsError = error as NSError
result(FlutterError(code: String(nsError.code), message: nsError.localizedDescription, details: nil))
}
}
break
case .sendLightLightness(let data):
guard let appKey = meshNetworkManager.meshNetwork?.applicationKeys[KeyIndex(data.keyIndex)] else{
let error = MeshNetworkError.keyIndexOutOfRange
Expand Down
19 changes: 19 additions & 0 deletions lib/src/mesh_manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,25 @@ class MeshManagerApi {
return status;
}

Future<ConfigModelPublicationStatus> getPublicationSettings(
int elementAddress,
int modelIdentifier,
) async {
if (Platform.isAndroid || Platform.isIOS) {
final status = _onConfigModelPublicationStatusController.stream.firstWhere(
(element) => element.elementAddress == elementAddress && element.modelIdentifier == modelIdentifier,
orElse: () => const ConfigModelPublicationStatus(-1, -1, -1, false, -1, -1, -1, -1, -1, -1, false),
);
await _methodChannel.invokeMethod(
'getPublicationSettings',
{'elementAddress': elementAddress, 'modelIdentifier': modelIdentifier},
);
return status;
} else {
throw UnimplementedError('${Platform.environment} not supported');
}
}

Future<LightLightnessStatusData> sendLightLightness(
int address,
int lightness,
Expand Down

0 comments on commit 1b7eea3

Please sign in to comment.