//Create a class for three axis
package ThreeAxis
-import Timer.SimulatedTimer
-import groovy.json.JsonSlurper
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
public class ThreeAxis {
- private String id
- private String label
- private String displayName
- private LinkedHashMap threeAxis
+ // id, label, and display name of the device
+ StringBuilder id = new StringBuilder()
+ StringBuilder label = new StringBuilder()
+ StringBuilder displayName = new StringBuilder()
+ // Other variables
+ def sendEvent
+ LinkedHashMap currentThreeAxis
+
- ThreeAxis(String id, String label, String displayName, LinkedHashMap threeAxis) {
+ ThreeAxis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, LinkedHashMap currentThreeAxis) {
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.threeAxis = threeAxis
+ this.currentThreeAxis = currentThreeAxis
+ this.sendEvent = sendEvent
}
+ // Methods to set values
def setValue(LinkedHashMap eventDataMap) {
- threeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
- println("the three axis of cube is chagned to $threeAxis!")
+ def tmpID = id.toString()
+ currentThreeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
+ println("the three axis with id:$tmpID of cube is chagned to $currentThreeAxis!")
+ sendEvent(eventDataMap)
+ }
+
+ // Methods to return values
+ def getCurrentThreeAxis() {
+ return currentThreeAxis
}
def currentState(String deviceFeature) {
currentValue(deviceFeature)
}
- def currentValue(String deviceFeature) {
- if (deviceFeature == "threeAxis" || deviceFeature == "status")
- return threeAxis
+ def latestValue(String deviceFeature) {
+ currentValue(deviceFeature)
}
- def latestValue(String deviceFeature) {
+ def currentValue(String deviceFeature) {
if (deviceFeature == "threeAxis" || deviceFeature == "status")
- return threeAxis
+ return currentThreeAxis
}
}