Version: | v0.2 |
---|
NB: this document relies on certain terms and concepts introduced in :ref:`saoverarch` , :ref:`sazeptovm` , and :ref:`saplugin` documents, please make sure to read them before proceeding.
Zepto VM does not intend to provide highly sophisticated and/or mathematics-oriented functionality; instead, it intends to support very limited but highly practical scenarios, which allow to minimize communications between SmartAnthill Central Controller and SmartAnthill Device, therefore allowing to minimize power consumption on the side of SmartAnthill Device.
Currently, Zepto programming patterns are described in terms of Zepto JavaScript. This in an extremely limited version of normal JavaScript ("zepto" means "10^-21", so you get about 10^-21 functionality out of original language). Basically, whatever is not in these examples, you shouldn't use.
Contents
The very primitive (though, when aided with a program on Central Controller side, sufficient to implement any kind of logic) program:
return TemperatureSensor.Execute();
This program should compile to all Zepto VM Levels.
Sleep for several minutes (turning off transmitter), then report back.
mcu_sleep(5*60); //5*60 is a compile-time constant,
// so no multiplication is performed on MCU here
return TemperatureSensor.Execute();
This program should compile to all Zepto VM Levels.
The same thing, but asking to report only if measurements exceed certain bounds. Still, once per 5 cycles, SmartAnthill Device reports back, so that Central Controller knows that the Device is still alive.
for (var i = 0; i < 5; i++) {
temp = TemperatureSensor.Execute();
if (temp.Temperature < 36.0 ||
temp.Temperature > 38.9)
//Note that both comparisons should compile
// into integer comparisons, using Plugin Manifest
return temp;
mcu_sleep(5*60);
}
return TemperatureSensor.Execute();
This program should compile to all Zepto VM Levels, starting from Zepto VM Small.
temp = TemperatureSensor.Execute();
humi = HumiditySensor.Execute();
return [temp, humi];
or
return [TemperatureSensor.Execute(), HumiditySensor.Execute()];
In all these (equivalent) cases compiler, if possible, SHOULD implicitly call both sensor Execute() functions in parallel (see PARALLEL Zepto VM instruction), reducing processing time.
Now let's consider an example where we want to perform temperature measurements more frequently than humidity ones, and
humi = HumiditySensor.Execute();
for (var i = 0; i < 5; i++) {
if (i%2 == 0) //SHOULD compile into '&1' to avoid division
humi = HumiditySensor.Execute();
temp = TemperatureSensor.Execute(); //SHOULD be performed in parallel
// with HumiditySensor() when applicable
if (humi.HumiditySensor > 80 &&
temp.Temperature > 30.0)
return [temp, humi];
mcu_sleep(5*60);
}
return [TemperatureSensor.Execute(), HumiditySensor.Execute()];
TODO: calculation plugins(?)