-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More work about write attribute support.
- Loading branch information
1 parent
f1b0023
commit a4c7318
Showing
7 changed files
with
232 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...main/java/org/eclipse/leshan/client/notification/checker/CriteriaBasedOnValueChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.client.notification.checker; | ||
|
||
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttributeSet; | ||
|
||
public interface CriteriaBasedOnValueChecker { | ||
boolean shouldTriggerNotificationBasedOnValueChange(LwM2mAttributeSet attributes, Object lastSentValue, | ||
Object newValue); | ||
} |
40 changes: 40 additions & 0 deletions
40
...lient-core/src/main/java/org/eclipse/leshan/client/notification/checker/FloatChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.client.notification.checker; | ||
|
||
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttributeSet; | ||
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttributes; | ||
|
||
public class FloatChecker implements CriteriaBasedOnValueChecker { | ||
|
||
@Override | ||
public boolean shouldTriggerNotificationBasedOnValueChange(LwM2mAttributeSet attributes, Object lastSentValue, | ||
Object newValue) { | ||
Double lastSentDouble = (Double) lastSentValue; | ||
Double newDouble = (Double) newValue; | ||
|
||
if (attributes.contains(LwM2mAttributes.STEP)) { | ||
return Math.abs(lastSentDouble - newDouble) >= attributes.get(LwM2mAttributes.STEP).getValue(); | ||
} else if (attributes.contains(LwM2mAttributes.LESSER_THAN)) { | ||
Double lessThan = attributes.get(LwM2mAttributes.LESSER_THAN).getValue(); | ||
return lastSentDouble >= lessThan && newDouble < lessThan; | ||
} else if (attributes.contains(LwM2mAttributes.GREATER_THAN)) { | ||
Double greaterThan = attributes.get(LwM2mAttributes.LESSER_THAN).getValue(); | ||
return lastSentDouble <= greaterThan && newDouble < greaterThan; | ||
} | ||
return true; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ent-core/src/main/java/org/eclipse/leshan/client/notification/checker/IntegerChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.client.notification.checker; | ||
|
||
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttributeSet; | ||
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttributes; | ||
|
||
public class IntegerChecker implements CriteriaBasedOnValueChecker { | ||
|
||
@Override | ||
public boolean shouldTriggerNotificationBasedOnValueChange(LwM2mAttributeSet attributes, Object lastSentValue, | ||
Object newValue) { | ||
Long lastSentLong = (Long) lastSentValue; | ||
Long newLong = (Long) newValue; | ||
|
||
if (attributes.contains(LwM2mAttributes.STEP)) { | ||
return Math.abs(lastSentLong - newLong) >= attributes.get(LwM2mAttributes.STEP).getValue(); | ||
} else if (attributes.contains(LwM2mAttributes.LESSER_THAN)) { | ||
Double lessThan = attributes.get(LwM2mAttributes.LESSER_THAN).getValue(); | ||
return lastSentLong >= lessThan && newLong < lessThan; | ||
} else if (attributes.contains(LwM2mAttributes.GREATER_THAN)) { | ||
Double greaterThan = attributes.get(LwM2mAttributes.LESSER_THAN).getValue(); | ||
return lastSentLong <= greaterThan && newLong < greaterThan; | ||
} | ||
return true; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
.../src/main/java/org/eclipse/leshan/client/notification/checker/UnsignedIntegerChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.client.notification.checker; | ||
|
||
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttributeSet; | ||
|
||
public class UnsignedIntegerChecker implements CriteriaBasedOnValueChecker { | ||
|
||
@Override | ||
public boolean shouldTriggerNotificationBasedOnValueChange(LwM2mAttributeSet attributes, Object lastSentValue, | ||
Object newValue) { | ||
// ULong lastSentULong = (ULong) lastSentValue; | ||
// ULong newULong = (ULong) newValue; | ||
|
||
throw new IllegalStateException("Not implemented yet"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters