-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator-feed.js
40 lines (34 loc) · 1011 Bytes
/
generator-feed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* The values we fed in last time.
*/
User.history = null;
/*
* The generator is called whenever new data is required.
* @param mote The Saguaro.Mote instance.
* @param device The device feeder object.
*/
User.randomTemperature = function(/** Sonoran.Mote */mote, /** Saguaro.Device */device, /** Number */nanos) {
printf("Feeder: mote %s, time %s\n", mote, Util.nanos2str(nanos));
/*
* Increasing temperature/humidity values. Tuples with timespamp (in millis) and values for sensor.
* The simulation interpolates the values between the specified intervals.
*/
User.history = [
1000, [ getRandomTemperature(), getRandomHumidity() ]
];
return User.history;
};
/*
* Helper methods
*/
function getRandomTemperature() {
return getRandomInt(0, 45);
}
function getRandomHumidity() {
return getRandomInt(0, 100);
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}