@autorunify/capacitor-nrfmesh 0.0.18 → 0.0.20
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.
|
@@ -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))
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
package com.autorunify.capacitor.nrfmesh
|
|
2
2
|
|
|
3
|
-
import kotlin.math.ln
|
|
4
|
-
import kotlin.math.pow
|
|
5
|
-
|
|
6
3
|
class Utils {
|
|
7
4
|
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()
|
|
5
|
+
fun Pwr2(value: Int): Int {
|
|
6
|
+
val maskedVal =
|
|
7
|
+
value and 0xFF // Ensure we are only treating it as an 8-bit unsigned value
|
|
8
|
+
return when (maskedVal) {
|
|
9
|
+
0x00 -> 0x0000
|
|
10
|
+
0xFF -> 0xFFFF
|
|
11
|
+
else -> 1 shl (maskedVal - 1)
|
|
12
|
+
}
|
|
20
13
|
}
|
|
21
14
|
|
|
22
|
-
fun
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
fun Log2(value: Long): Int {
|
|
16
|
+
val maskedVal = value and 0xFFFFFFFFL // Ensure we treat it as a 32-bit unsigned value
|
|
17
|
+
if (value == 0xFFFFL) {
|
|
18
|
+
return 0xFF;
|
|
19
|
+
}
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
if (maskedVal == 0L) {
|
|
22
|
+
return 0x00
|
|
23
|
+
}
|
|
31
24
|
|
|
32
|
-
|
|
25
|
+
// Integer.numberOfLeadingZeros expects a 32-bit Int.
|
|
26
|
+
// We convert our masked value to Int to get the accurate leading zero count.
|
|
27
|
+
val leadingZeros = java.lang.Integer.numberOfLeadingZeros(maskedVal.toInt())
|
|
28
|
+
return 32 - leadingZeros
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
31
|
}
|