Skip to content

Commit

Permalink
Merge pull request #559 from NordicSemiconductor/bugfix/excludes-unkn…
Browse files Browse the repository at this point in the history
…own-node-features

Excludes unknown features from the network json
  • Loading branch information
roshanrajaratnam committed May 26, 2023
2 parents a5cd85a + 89ae082 commit fbd5843
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
10 changes: 9 additions & 1 deletion mesh/src/main/java/no/nordicsemi/android/mesh/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
public class Features implements Parcelable {

@Retention(RetentionPolicy.SOURCE)
@IntDef({DISABLED, ENABLED, UNSUPPORTED})
@IntDef({DISABLED, ENABLED, UNSUPPORTED, UNKNOWN})
@interface FeatureState {
}

//feature states
public static final int DISABLED = 0; //Feature is disabled
public static final int ENABLED = 1; //Feature is enabled
public static final int UNSUPPORTED = 2; //Feature is not supported
public static final int UNKNOWN = 3; //Feature is not supported

@SerializedName("friend")
@Expose
Expand Down Expand Up @@ -57,6 +58,13 @@ public Features(@FeatureState final int friend, @FeatureState final int lowPower
this.relay = relay;
}

public Features() {
friend = UNKNOWN;
lowPower = UNKNOWN;
proxy = UNKNOWN;
relay = UNKNOWN;
}

private Features(Parcel in) {
friend = in.readInt();
lowPower = in.readInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,20 @@ public List<ProvisionedMeshNode> deserialize(final JsonElement json, final Type

if (jsonObject.has("features")) {
final JsonObject featuresJson = jsonObject.get("features").getAsJsonObject();
node.nodeFeatures = new Features(featuresJson.get("friend").getAsInt(),
featuresJson.get("lowPower").getAsInt(),
featuresJson.get("proxy").getAsInt(),
featuresJson.get("relay").getAsInt());

node.nodeFeatures = new Features();
if(featuresJson.has("friend")){
node.nodeFeatures.setFriend(featuresJson.get("friend").getAsInt());
}
if(featuresJson.has("lowPower")){
node.nodeFeatures.setLowPower(featuresJson.get("lowPower").getAsInt());
}
if(featuresJson.has("proxy")){
node.nodeFeatures.setProxy(featuresJson.get("proxy").getAsInt());
}
if(featuresJson.has("relay")){
node.nodeFeatures.setRelay(featuresJson.get("relay").getAsInt());
}
}

if (jsonObject.has("secureNetworkBeacon")) {
Expand Down Expand Up @@ -187,10 +197,18 @@ public JsonElement serialize(final List<ProvisionedMeshNode> nodes, final Type t

if (node.getNodeFeatures() != null) {
final JsonObject json = new JsonObject();
json.addProperty("friend", node.getNodeFeatures().getFriend());
json.addProperty("lowPower", node.getNodeFeatures().getLowPower());
json.addProperty("proxy", node.getNodeFeatures().getProxy());
json.addProperty("relay", node.getNodeFeatures().getRelay());
if(node.getNodeFeatures().getFriend() != Features.UNKNOWN){
json.addProperty("friend", node.getNodeFeatures().getFriend());
}
if(node.getNodeFeatures().getLowPower() != Features.UNKNOWN){
json.addProperty("lowPower", node.getNodeFeatures().getLowPower());
}
if(node.getNodeFeatures().getProxy() != Features.UNKNOWN){
json.addProperty("proxy", node.getNodeFeatures().getProxy());
}
if(node.getNodeFeatures().getRelay() != Features.UNKNOWN){
json.addProperty("relay", node.getNodeFeatures().getRelay());
}
nodeJson.add("features", json);
}

Expand Down

0 comments on commit fbd5843

Please sign in to comment.