@autorunify/capacitor-nrfmesh 0.0.17 → 0.0.18
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
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
|
|