@autorunify/capacitor-nrfmesh 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Android-nRF-Mesh-Library/mesh/src/main/java/no/nordicsemi/android/mesh/MeshNetwork.java +31 -19
- package/android/src/main/java/com/autorunify/capacitor/nrfmesh/FormatManager.kt +4 -4
- package/android/src/main/java/com/autorunify/capacitor/nrfmesh/NrfMeshPlugin.kt +3 -3
- package/android/src/main/java/com/autorunify/capacitor/nrfmesh/Utils.kt +17 -22
- package/package.json +1 -1
package/Android-nRF-Mesh-Library/mesh/src/main/java/no/nordicsemi/android/mesh/MeshNetwork.java
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
|
|
2
2
|
package no.nordicsemi.android.mesh;
|
|
3
3
|
|
|
4
|
+
import static no.nordicsemi.android.mesh.AddressRange.isAddressInAnyRanges;
|
|
5
|
+
|
|
4
6
|
import android.text.TextUtils;
|
|
5
7
|
|
|
8
|
+
import androidx.annotation.NonNull;
|
|
9
|
+
import androidx.annotation.Nullable;
|
|
10
|
+
import androidx.annotation.RestrictTo;
|
|
11
|
+
import androidx.room.Entity;
|
|
12
|
+
|
|
6
13
|
import java.util.ArrayList;
|
|
7
14
|
import java.util.Collections;
|
|
8
15
|
import java.util.List;
|
|
9
16
|
import java.util.Map;
|
|
10
17
|
import java.util.UUID;
|
|
11
18
|
|
|
12
|
-
import androidx.annotation.NonNull;
|
|
13
|
-
import androidx.annotation.Nullable;
|
|
14
|
-
import androidx.annotation.RestrictTo;
|
|
15
|
-
import androidx.room.Entity;
|
|
16
19
|
import no.nordicsemi.android.mesh.transport.Element;
|
|
17
20
|
import no.nordicsemi.android.mesh.transport.MeshModel;
|
|
18
21
|
import no.nordicsemi.android.mesh.transport.ProvisionedMeshNode;
|
|
19
22
|
import no.nordicsemi.android.mesh.utils.MeshAddress;
|
|
20
23
|
|
|
21
|
-
import static no.nordicsemi.android.mesh.AddressRange.isAddressInAnyRanges;
|
|
22
|
-
|
|
23
24
|
@SuppressWarnings({"WeakerAccess", "UnusedReturnValue"})
|
|
24
25
|
@Entity(tableName = "mesh_network")
|
|
25
26
|
public final class MeshNetwork extends BaseMeshNetwork {
|
|
@@ -156,43 +157,54 @@ public final class MeshNetwork extends BaseMeshNetwork {
|
|
|
156
157
|
}
|
|
157
158
|
// Excluded addresses with the current IvIndex and current IvIndex - 1 must be considered as addresses in use.
|
|
158
159
|
final List<Integer> addressesWithCurrentIvIndex = networkExclusions.get(ivIndex.getIvIndex());
|
|
159
|
-
if (addressesWithCurrentIvIndex != null)
|
|
160
|
-
usedAddresses.addAll(addressesWithCurrentIvIndex);
|
|
160
|
+
// if (addressesWithCurrentIvIndex != null)
|
|
161
|
+
// usedAddresses.addAll(addressesWithCurrentIvIndex);
|
|
161
162
|
final List<Integer> addressesWithCurrentIvIndexMinusOne = networkExclusions.get(ivIndex.getIvIndex() - 1);
|
|
162
|
-
if (addressesWithCurrentIvIndexMinusOne != null)
|
|
163
|
-
usedAddresses.addAll(addressesWithCurrentIvIndexMinusOne);
|
|
163
|
+
// if (addressesWithCurrentIvIndexMinusOne != null)
|
|
164
|
+
// usedAddresses.addAll(addressesWithCurrentIvIndexMinusOne);
|
|
164
165
|
|
|
165
166
|
Collections.sort(usedAddresses);
|
|
166
167
|
// Iterate through all nodes just once, while iterating over ranges.
|
|
167
|
-
|
|
168
|
+
boolean findAddress = false;
|
|
168
169
|
for (AllocatedUnicastRange range : provisioner.getAllocatedUnicastRanges()) {
|
|
169
170
|
// Start from the beginning of the current range.
|
|
170
|
-
int
|
|
171
|
+
int lowAddress = range.getLowAddress();
|
|
172
|
+
findAddress = false;
|
|
171
173
|
|
|
172
174
|
// Iterate through nodes that weren't checked yet in essence the used addresses which include the excluded adresses
|
|
173
175
|
for (int usedAddress : usedAddresses) {
|
|
174
176
|
|
|
175
177
|
// Skip nodes with addresses below the range.
|
|
176
|
-
if (
|
|
178
|
+
if (lowAddress > usedAddress) {
|
|
177
179
|
continue;
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
// If we found a space before the current node, return the address.
|
|
181
|
-
if (usedAddress > (
|
|
182
|
-
|
|
183
|
+
if (usedAddress > (lowAddress + (elementCount - 1))) {
|
|
184
|
+
findAddress = true;
|
|
185
|
+
break;
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
// Else, move the address to the next available address.
|
|
186
|
-
|
|
189
|
+
lowAddress = usedAddress + 1;
|
|
187
190
|
|
|
188
191
|
// If the new address is outside of the range, go to the next one.
|
|
189
|
-
if (range.highAddress <
|
|
192
|
+
if (range.highAddress < lowAddress + (elementCount - 1)) {
|
|
190
193
|
break;
|
|
191
194
|
}
|
|
192
195
|
}
|
|
193
196
|
|
|
194
|
-
if (
|
|
195
|
-
|
|
197
|
+
if (findAddress || usedAddresses.size() == 1) {
|
|
198
|
+
for (int i = 0; i < elementCount; i++) {
|
|
199
|
+
if (addressesWithCurrentIvIndex != null)
|
|
200
|
+
addressesWithCurrentIvIndex.remove((Object) (lowAddress + i));
|
|
201
|
+
if (addressesWithCurrentIvIndexMinusOne != null)
|
|
202
|
+
addressesWithCurrentIvIndexMinusOne.remove((Object) (lowAddress + i));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (range.getHighAddress() >= lowAddress + (elementCount - 1)) {
|
|
207
|
+
return lowAddress;
|
|
196
208
|
}
|
|
197
209
|
}
|
|
198
210
|
|
|
@@ -311,8 +311,8 @@ class FormatManager {
|
|
|
311
311
|
val pub = msg.heartbeatPublication
|
|
312
312
|
return JSObject().apply {
|
|
313
313
|
put("address", pub.dst)
|
|
314
|
-
put("count", Utils.
|
|
315
|
-
put("period", Utils.
|
|
314
|
+
put("count", Utils.Pwr2(pub.countLog.toInt()))
|
|
315
|
+
put("period", Utils.Pwr2(pub.periodLog.toInt()))
|
|
316
316
|
put("ttl", pub.ttl)
|
|
317
317
|
put("netkeyIndex", pub.netKeyIndex)
|
|
318
318
|
put("features", JSObject().apply {
|
|
@@ -329,8 +329,8 @@ class FormatManager {
|
|
|
329
329
|
return JSObject().apply {
|
|
330
330
|
put("srcAddress", sub.src)
|
|
331
331
|
put("dstAddress", sub.dst)
|
|
332
|
-
put("period", Utils.
|
|
333
|
-
put("count", Utils.
|
|
332
|
+
put("period", Utils.Pwr2(sub.periodLog.toInt()))
|
|
333
|
+
put("count", Utils.Pwr2(sub.countLog.toInt()))
|
|
334
334
|
put("minHops", sub.minHops)
|
|
335
335
|
put("maxHops", sub.maxHops)
|
|
336
336
|
}
|
|
@@ -739,8 +739,8 @@ class NrfMeshPlugin : Plugin {
|
|
|
739
739
|
|
|
740
740
|
val message = ConfigHeartbeatPublicationSet(
|
|
741
741
|
address,
|
|
742
|
-
Utils.
|
|
743
|
-
Utils.
|
|
742
|
+
Utils.Log2(count.toLong()).toByte(),
|
|
743
|
+
Utils.Log2(period.toLong()).toByte(),
|
|
744
744
|
ttl,
|
|
745
745
|
features,
|
|
746
746
|
netkeyIndex
|
|
@@ -765,7 +765,7 @@ class NrfMeshPlugin : Plugin {
|
|
|
765
765
|
val message = ConfigHeartbeatSubscriptionSet(
|
|
766
766
|
srcAddress,
|
|
767
767
|
dstAddress,
|
|
768
|
-
Utils.
|
|
768
|
+
Utils.Log2(period.toLong()).toByte()
|
|
769
769
|
)
|
|
770
770
|
|
|
771
771
|
pairs.add(MessagePair(CONFIG_HEARTBEAT_SUBSCRIPTION_SET, message))
|
|
@@ -5,31 +5,26 @@ import kotlin.math.pow
|
|
|
5
5
|
|
|
6
6
|
class Utils {
|
|
7
7
|
companion object {
|
|
8
|
-
fun
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (period == 0x0000) return 0x00
|
|
17
|
-
if (period == 0xFFFF) return 0x11
|
|
18
|
-
|
|
19
|
-
return ((ln(period.toDouble()) / ln(2.0)) + 1).toInt()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
fun decodeHeartbeatCount(countLog: Int): Int {
|
|
23
|
-
if (countLog == 0x00) return 0x0000
|
|
24
|
-
if (countLog == -1 || countLog == 0x11) return 0xFFFF
|
|
25
|
-
return ((2.0).pow(countLog.toDouble() - 1)).toInt()
|
|
8
|
+
fun Pwr2(value: Int): Int {
|
|
9
|
+
val maskedVal =
|
|
10
|
+
value and 0xFF // Ensure we are only treating it as an 8-bit unsigned value
|
|
11
|
+
return when (maskedVal) {
|
|
12
|
+
0x00 -> 0x0000
|
|
13
|
+
0xFF -> 0xFFFF
|
|
14
|
+
else -> 1 shl (maskedVal - 1)
|
|
15
|
+
}
|
|
26
16
|
}
|
|
27
17
|
|
|
28
|
-
fun
|
|
29
|
-
|
|
30
|
-
if (
|
|
18
|
+
fun Log2(value: Long): Int {
|
|
19
|
+
val maskedVal = value and 0xFFFFFFFFL // Ensure we treat it as a 32-bit unsigned value
|
|
20
|
+
if (maskedVal == 0L) {
|
|
21
|
+
return 0x00
|
|
22
|
+
}
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
// Integer.numberOfLeadingZeros expects a 32-bit Int.
|
|
25
|
+
// We convert our masked value to Int to get the accurate leading zero count.
|
|
26
|
+
val leadingZeros = java.lang.Integer.numberOfLeadingZeros(maskedVal.toInt())
|
|
27
|
+
return 32 - leadingZeros
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
30
|
}
|