Skip to content
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

Feature : epoch protocol v2 and Nordic SDK upgrade #221

Merged
18 commits merged into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[submodule "Android-nRF-Mesh-Library-1"]
path = Android-nRF-Mesh-Library-1
url = https://github.com/OZEO-DOOZ/Android-nRF-Mesh-Library-1.git
branch = master
[submodule "IOS-nRF-Mesh-Library"]
path = IOS-nRF-Mesh-Library
url = https://github.com/OZEO-DOOZ/IOS-nRF-Mesh-Library.git
2 changes: 1 addition & 1 deletion Android-nRF-Mesh-Library-1
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.8.0

- Add DooZ scenario protocol V2 messages. `DoozEpochSet` and `DoozEpochStatus` are tested on both platforms, whereas `DoozScenarioSet` and `DoozScenarioStatus` are added in Android version but not used for now (prepare for next release)
- Expose `ConfigModelPublicationGet` msg
- Use of Nordic's Android SDK v3.1.7
- Use of Nordic's iOS SDK v3.1.5

## 0.7.0

- added getter for `BleStatus`
Expand Down
2 changes: 1 addition & 1 deletion IOS-nRF-Mesh-Library
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,60 @@ class DoozMeshManagerApi(context: Context, binaryMessenger: BinaryMessenger) : S
mMeshManagerApi.createMeshPdu(pNode.unicastAddress, meshMessage)
result.success(null)
}
"doozScenarioSet" -> {
val scenarioId = call.argument<Int>("scenarioId")!!
val command = call.argument<Int>("command")!!
val io = call.argument<Int>("io")!!
val isActive = call.argument<Boolean>("isActive")!!
val unused = call.argument<Int>("unused")!!
val value = call.argument<Int>("value")!!
val transition = call.argument<Int>("transition")!!
val startAt = call.argument<Int>("startAt")!!
val duration = call.argument<Int>("duration")!!
val daysInWeek = call.argument<Int>("daysInWeek")!!
val correlation = call.argument<Int>("correlation")!!
val extra = call.argument<Int?>("extra")
val address = call.argument<Int>("address")!!
val keyIndex = call.argument<Int>("keyIndex")!!
val sequenceNumber = getSequenceNumber(mMeshManagerApi.meshNetwork)
val meshMessage = DoozScenarioSet(
mMeshManagerApi.meshNetwork!!.getAppKey(keyIndex),
scenarioId,
command,
io,
isActive,
unused,
value,
transition,
startAt,
duration,
daysInWeek,
correlation,
extra,
sequenceNumber,
)
mMeshManagerApi.createMeshPdu(address, meshMessage)
result.success(null)
}
"doozScenarioEpochSet" -> {
val packed = call.argument<Int>("packed")!!
val epoch = call.argument<Int>("epoch")!!
val correlation = call.argument<Int>("correlation")!!
val extra = call.argument<Int?>("extra")
val address = call.argument<Int>("address")!!
val keyIndex = call.argument<Int>("keyIndex")!!
val sequenceNumber = getSequenceNumber(mMeshManagerApi.meshNetwork)
val meshMessage = DoozEpochSet(
mMeshManagerApi.meshNetwork!!.getAppKey(keyIndex),
packed,
epoch,
correlation,
extra,
sequenceNumber,
)
mMeshManagerApi.createMeshPdu(address, meshMessage)
result.success(null)
}
"getPublicationSettings" -> {
val elementAddress = call.argument<Int>("elementAddress")!!
val modelIdentifier = call.argument<Int>("modelIdentifier")!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ class DoozMeshStatusCallbacks(var eventSink: EventChannel.EventSink?): MeshStatu
))
}
}
is DoozScenarioStatus -> {
Handler(Looper.getMainLooper()).post {
eventSink?.success(mapOf(
"eventName" to "onDoozScenarioStatus",
"scenarioId" to meshMessage.scenarioId,
"command" to meshMessage.command,
"io" to meshMessage.io,
"isActive" to meshMessage.isActive,
"unused" to meshMessage.unused,
"value" to meshMessage.value,
"transition" to meshMessage.transition,
"startAt" to meshMessage.startAt,
"duration" to meshMessage.duration,
"daysInWeek" to meshMessage.daysInWeek,
"correlation" to meshMessage.correlation,
"extra" to meshMessage.extra,
"source" to meshMessage.src,
"destination" to meshMessage.dst
))
}
}
is DoozEpochStatus -> {
Handler(Looper.getMainLooper()).post {
eventSink?.success(mapOf(
"eventName" to "onDoozEpochStatus",
"packed" to meshMessage.packed,
"epoch" to meshMessage.epoch,
"correlation" to meshMessage.correlation,
"extra" to meshMessage.extra,
"source" to meshMessage.src,
"destination" to meshMessage.dst
))
}
}
is MagicLevelSetStatus -> {
Handler(Looper.getMainLooper()).post {
eventSink?.success(mapOf(
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.7.0"
version: "0.8.0"
package_config:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// DoozEpochSetArguments.swift
// nordic_nrf_mesh
//
// Created by OZEO DOOZ on 11/02/2022.
//

import Foundation

struct DoozEpochSetArguments: BaseFlutterArguments {
let address: Int
let keyIndex: Int
let packed: UInt16
let epoch: UInt32
let correlation: UInt32
let extra: UInt16?
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum DoozMeshManagerApiChannel {
case networkIdMatches(_ data: NetworkIdMatchesArguments)
case sendV2MagicLevel(_ data: SendV2MagicLevelArguments)
case getV2MagicLevel(_ data: GetV2MagicLevelArguments)
case doozScenarioEpochSet(_ data: DoozEpochSetArguments)
case deprovision(_ data: DeprovisionArguments)

case error(_ error: Error)
Expand Down Expand Up @@ -132,7 +133,8 @@ enum DoozMeshManagerApiChannel {
self = .sendV2MagicLevel(try SendV2MagicLevelArguments(arguments))
case "getV2MagicLevel":
self = .getV2MagicLevel(try GetV2MagicLevelArguments(arguments))

case "doozScenarioEpochSet":
self = .doozScenarioEpochSet(try DoozEpochSetArguments(arguments))
//getDeviceUuid
case "handleWriteCallbacks":
self = .handleWriteCallbacks(try HandleWriteCallbacksArguments(arguments))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ extension DoozMeshManagerApi: MeshNetworkDelegate{
EventSinkKeys.message.destination.rawValue : destination,
]
_sendFlutterMessage(message)
case let status as DoozEpochStatus:
let message: FlutterMessage = [
EventSinkKeys.eventName.rawValue : MessageEvent.onDoozEpochStatus.rawValue,
EventSinkKeys.message.packed.rawValue : status.mPacked,
EventSinkKeys.message.epoch.rawValue : status.mEpoch,
EventSinkKeys.message.correlation.rawValue : status.mCorrelation,
EventSinkKeys.message.extra.rawValue : status.mExtra ?? 0,
EventSinkKeys.source.rawValue : source,
EventSinkKeys.message.destination.rawValue : destination,
]
_sendFlutterMessage(message)
default:
break
}
Expand Down
21 changes: 20 additions & 1 deletion ios/Classes/DoozMeshManagerApi/DoozMeshManagerApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,26 @@ private extension DoozMeshManagerApi {
result(FlutterError(code: String(nsError.code), message: nsError.localizedDescription, details: nil))
}
break

case .doozScenarioEpochSet(let data):
guard let appKey = meshNetworkManager.meshNetwork?.applicationKeys[KeyIndex(data.keyIndex)] else{
let error = MeshNetworkError.keyIndexOutOfRange
let nsError = error as NSError
result(FlutterError(code: String(nsError.code), message: nsError.localizedDescription, details: nil))
return
}
let message = DoozEpochSet(packed: UInt16(data.packed), epoch: UInt32(data.epoch), correlation: UInt32(data.correlation), extra: UInt16?(data.extra ?? 0))
do{
_ = try meshNetworkManager.send(
message,
to: MeshAddress(Address(exactly: data.address)!),
using: appKey
)
result(nil)
}catch{
let nsError = error as NSError
result(FlutterError(code: String(nsError.code), message: nsError.localizedDescription, details: nil))
}
break
case .isAdvertisingWithNetworkIdentity(let data):
result(isAdvertisingWithNetworkIdentity(data: data.serviceData.data))
case .isAdvertisedWithNodeIdentity(let data):
Expand Down
3 changes: 2 additions & 1 deletion ios/Classes/ModelDelegate/GenericLevelClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class GenericLevelClientDelegate: ModelDelegate {
let types: [GenericMessage.Type] = [
GenericLevelStatus.self,
MagicLevelSetStatus.self,
MagicLevelGetStatus.self
MagicLevelGetStatus.self,
DoozEpochStatus.self
]
messageTypes = types.toMap()
}
Expand Down
17 changes: 14 additions & 3 deletions ios/Classes/ModelDelegate/GenericLevelServerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class GenericLevelServerDelegate: ModelDelegate {
GenericMoveSet.self,
GenericMoveSetUnacknowledged.self,
MagicLevelGet.self,
MagicLevelSet.self
MagicLevelSet.self,
DoozEpochSet.self
]
messageTypes = types.toMap()
}
Expand Down Expand Up @@ -162,8 +163,18 @@ class GenericLevelServerDelegate: ModelDelegate {
}
lastTransaction = (source: source, destination: destination, tid: request.tid, timestamp: Date())

return MagicLevelSetStatus(io: request.mIO, index: request.mIndex, value: request.mValue, correlation: request.mCorrelation, tId: request.tid)

return MagicLevelSetStatus(io: request.mIO, index: request.mIndex, value: request.mValue, correlation: request.mCorrelation, tid: request.tid)
case let request as DoozEpochSet:
// Ignore a repeated request (with the same TID) from the same source
// and sent to the same destinatino when it was received within 6 seconds.
guard lastTransaction == nil ||
lastTransaction!.source != source || lastTransaction!.destination != destination ||
request.isNewTransaction(previousTid: lastTransaction!.tid, timestamp: lastTransaction!.timestamp) else {
lastTransaction = (source: source, destination: destination, tid: request.tid, timestamp: Date())
break
}
lastTransaction = (source: source, destination: destination, tid: request.tid, timestamp: Date())
return DoozEpochStatus(packed: request.mPacked, epoch: request.mEpoch, correlation: request.mCorrelation, extra: request.mExtra, tid: request.tid)
default:
// Not possible.
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import Foundation

struct NodeNameArguments: BaseFlutterArguments {
struct NodeNameArguments: BaseFlutterArguments {
let name: String
}
5 changes: 5 additions & 0 deletions ios/Classes/Utils/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ enum MessageEvent: String{
case onConfigBeaconStatus
case onMagicLevelSetStatus
case onMagicLevelGetStatus
case onDoozEpochStatus
}

enum EventSinkKeys: String{
Expand Down Expand Up @@ -170,6 +171,10 @@ enum EventSinkKeys: String{
case correlation

case enable

case packed
case epoch
case extra
}

enum network: String{
Expand Down
1 change: 1 addition & 0 deletions lib/nordic_nrf_mesh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export 'src/ble/ble_mesh_manager_callbacks.dart';
export 'src/utils/provisioning.dart' show ProvisioningEvent;
export 'src/contants.dart' show ProvisioningFailureCode, BleManagerFailureCode;
export 'src/exceptions/exceptions.dart';
export 'src/extensions/extensions.dart';
21 changes: 21 additions & 0 deletions lib/src/events/data/dooz_epoch_status/dooz_epoch_status.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'dooz_epoch_status.freezed.dart';
part 'dooz_epoch_status.g.dart';

@freezed
class DoozEpochStatusData with _$DoozEpochStatusData {
const factory DoozEpochStatusData(
int tzData,
int command,
int io,
int unused,
int epoch,
int correlation,
int extra,
int source,
int destination,
) = _DoozEpochStatusData;

factory DoozEpochStatusData.fromJson(Map<String, dynamic> json) => _$DoozEpochStatusDataFromJson(json);
}
Loading