1 //Create a class for acceleration sensor
2 package AccelerationSensor
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class AccelerationSensors {
9 private int deviceNumbers
10 private List accelerationSensors
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "accelerationSensorID0"
15 private String label = "accelerationSensor0"
16 private String displayName = "accelerationSensor0"
17 private String acceleration = "inactive"
18 private String currentAcceleration = "inactive"
19 private String accelerationLatestValue = "inactive"
23 AccelerationSensors(Closure sendEvent, int deviceNumbers) {
24 this.sendEvent = sendEvent
25 this.deviceNumbers = deviceNumbers
26 this.accelerationSensors = []
28 /*def init = Verify.getBoolean()
30 this.acceleration = "inactive"
31 this.accelerationLatestValue = "inactive"
33 this.acceleration = "active"
34 this.accelerationLatestValue = "active"
36 accelerationSensors.add(new AccelerationSensor(id, label, displayName, this.acceleration, this.accelerationLatestValue))
40 def setValue(LinkedHashMap eventDataMap) {
41 if (eventDataMap["value"] != accelerationSensors[0].acceleration) {
42 this.accelerationLatestValue = eventDataMap["value"]
43 this.acceleration = eventDataMap["value"]
44 this.currentAcceleration = eventDataMap["value"]
45 accelerationSensors[0].setValue(eventDataMap["value"])
46 sendEvent(eventDataMap)
51 def eventsSince(Date dateObj) {
52 return accelerationSensors[0].eventsSince()
55 def statesSince(String info, Date dateObj) {
56 return accelerationSensors[0].statesSince()
59 //Methods for closures
60 def count(Closure Input) {
61 accelerationSensors.count(Input)
64 accelerationSensors.size()
66 def each(Closure Input) {
67 accelerationSensors.each(Input)
69 def sort(Closure Input) {
70 accelerationSensors.each(Input)
72 def find(Closure Input) {
73 accelerationSensors.find(Input)
75 def collect(Closure Input) {
76 accelerationSensors.collect(Input)
80 def currentValue(String deviceFeature) {
81 accelerationSensors[0].currentValue(deviceFeature)//It is called if we have only one device
84 def latestValue(String deviceFeature) {
85 accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device
89 accelerationSensors[ix]