More about SALT language

NOTA: You can't use a0, a1 etc as an input. In the input, you check the order, and in output, you access to args (As you can't make tests in output, you must store the values)

TODO: Check how many args, how many variables (from 0 to 9 ?) SALT accept.

TODO: Give a precise list of features, and associated orders

Here comes some example, with there graphical representation, the XML version, and an analysis of the code.

Example : ButtonPush.xml

ardPush

This is a very small example designed for a Button (genericity is offered through a feature) : When a user presses the button, this FST just sends a "toggle" message to listeners

Required features : button

Output : Toggle

<?xml version="1.0"?>
<configuration initial="init">
  <rules>
    <rule>
      <input state="init">
        <message name="push" category="hardware"/>
      </input>
      <output state="init">
        <message name="toggle" category="external"/>
      </output>
    </rule>
  </rules>
</configuration>

Example : led.xml

led

This second example is to be used on a object that is listening to the first one. The FST presented above send some "toggle" messages. This one, running on an object with a "led" feature, will react.

Required features : led

Input : Toggle

<?xml version="1.0"?>
<configuration initial="off">
  <rules>
    <rule>
      <input state="off">
        <message name="toggle" category="external"/>
      </input>
      <output state="on">
        <message name="led" category="hardware">
          <param>on</param>
        </message>
      </output>
    </rule>
    <rule>
      <input state="on">
        <message name="toggle" category="external"/>
      </input>
      <output state="off">
        <message name="led" category="hardware">
          <param>off</param>
        </message>
      </output>
    </rule>
  </rules>
</configuration>

Example : countingLed1.xml

CountingLed

This FST can be deployed on one of the listener of the first example. Each time it receives a "toggle" message, a register (r0) is incremented. When it reaches 3, the led is switched on, and the count restart from 0. So we have a 3-time-ligth : 2 switch off, and one switch on.

Required features : led, cpu

Input : Toggle

<?xml version="1.0"?>
<configuration initial="off">
  <rules>
   <rule>
     <input state="off">
       <message name="toggle" category="external"/>
     </input>
     <output state="off">
       <message name="+=" category="logic">
         <param>r0</param>
         <param>1</param>
       </message>
       <message name="led" category="hardware">
 	  <param>off</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="off">
       <message name="==" category="logic">
         <param>r0</param>
         <param>3</param>
       </message>
     </input>
     <output state="off">
       <message name="led" category="hardware">
 	  <param>on</param>
       </message>
       <message name="=" category="logic">
         <param>r0</param>
         <param>0</param>
      </message>
     </output>
   </rule>
  </rules>
</configuration>

Example : countingLed.xml

CountingLed again

The same as above, but we introduce 'epsilon' here, in the case there is nothing to do. Init state goes directly to Counting state. Register 0 is initialized here, thanks to epsilon. No need for an event. This FST daesn't work well, because the light is never switched off.

Required features : led, cpu

Input : Toggle

<?xml version="1.0"?>
<configuration initial="init">
  <rules>
   <rule>
     <input state="counting">
       <message name="==" category="logic">
         <param>r0</param>
         <param>3</param>
       </message>
     </input>
     <output state="init">
       <message name="led" category="hardware">
 	  <param>on</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="init"/>
     <output state="counting">
       <message name="=" category="logic">
         <param>r0</param>
         <param>0</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="counting">
       <message name="toggle" category="external"/>
     </input>
     <output state="counting">
       <message name="+=" category="logic">
         <param>r0</param>
         <param>1</param>
       </message>
     </output>
   </rule>
  </rules>
</configuration>

Example : delayedLed.xml

DelayedLed

By using a Timer, a programmer can introduce new capabilities. Here for example, we introduce a delay before changing the light state. If no new message is received for 5 seconds, we change the light's state. Note that this FST can be used with the first example, because it still deals with the same "toggle" message (This coherence is provided by the Interaction Patterns list)

Required features : led, cpu, timer

Input : Toggle

<?xml version="1.0"?>
<configuration initial="off">
  <rules>
   <rule>
     <input state="on">
       <message name="toggle" category="external"/>
     </input>
     <output state="off">
       <message name="timer" category="hardware">
         <param>5</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="off">
       <message name="timer" category="hardware"/>
     </input>
     <output state="off">
       <message name="led" category="hardware">
         <param>off</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="on">
       <message name="timer" category="hardware"/>
     </input>
     <output state="on">
       <message name="led" category="hardware">
         <param>on</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="off">
       <message name="toggle" category="external"/>
     </input>
     <output state="on">
       <message name="timer" category="hardware">
         <param>5</param>
       </message>
     </output>
   </rule>
  </rules>
</configuration>

Example : deriveeB.xml

DeviveeB

This FST shows that we can consider more complex programs. here, we calculate the number of "push" hardware messages by second. Division by zero is avoided through the test on register r0. This example uses timer, and messages with param (we send the word "send" (standardized by the "Send" Interaction Pattern) followed by an argument : the content of the register r0).

Required features : button, cpu, timer

Output : Send

<?xml version="1.0"?>
<configuration initial="init">
  <rules>
   <rule>
     <input state="test">
       <message name="!=" category="logic">
         <param>r0</param>
         <param>0</param>
       </message>
     </input>
     <output state="working">
       <message name="/=" category="logic">
         <param>r0</param>
         <param>r2</param>
       </message>
       <message name="send" category="external">
         <param>r0</param>
       </message>
       <message name="=" category="logic">
         <param>r2</param>
         <param>0</param>
       </message>
       <message name="=" category="logic">
         <param>r0</param>
         <param>0</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="working">
       <message name="timer" category="hardware"/>
     </input>
     <output state="test">
       <message name="+=" category="logic">
         <param>r2</param>
         <param>1</param>
       </message>
       <message name="timer" category="hardware">
         <param>1</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="working">
       <message name="push" category="hardware"/>
     </input>
     <output state="working">
       <message name="+=" category="logic">
         <param>r0</param>
         <param>1</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="test">
       <message name="==" category="logic">
         <param>r0</param>
         <param>0</param>
       </message>
     </input>
     <output state="working"/>
   </rule>
   <rule>
     <input state="init">
       <message name="push" category="hardware"/>
     </input>
     <output state="working">
       <message name="=" category="logic">
         <param>r0</param>
         <param>1</param>
       </message>
       <message name="=" category="logic">
         <param>r2</param>
         <param>0</param>
       </message>
       <message name="timer" category="hardware">
         <param>1</param>
       </message>
     </output>
   </rule>
  </rules>
</configuration>

Example : deriveeNotify.xml

DeriveeNotify

This one is an example of listeners for the FST above. It works with "send" messages containing a value. The value (a0 for arg0) is stored in register r0. We used then a hardware capability to display the content (commande "message" offered by the "display" features). Here, we use epsilon in the case the value is less than 3.

Required features : display, cpu

Input : Send

<?xml version="1.0"?>
<configuration initial="init">
  <rules>
   <rule>
     <input state="test">
       <message name=">=" category="logic">
         <param>r0</param>
         <param>3</param>
       </message>
     </input>
     <output state="init">
       <message name="=" category="logic">
         <param>r0</param>
         <param>Derivee >= 3 :</param>
       </message>
       <message name="message" category="hardware">
         <param>r0</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="test">
       <message name="<" category="logic">
         <param>r0</param>
         <param>3</param>
       </message>
     </input>
     <output state="init"/>
  </rule>
   <rule>
     <input state="init">
       <message name="send" category="external"/>
     </input>
     <output state="test"/>
       <message name="=" category="logic">
         <param>r0</param>
         <param>a0</param>
       </message>
    </output>
   </rule>
  </rules>
</configuration>

Example : deriveePhoto.xml

DeriveePhoto

Another simple example, where epsilon is used. TODO : put some value in a0, because this variable is tested, but has no value.

Required features : photo, cpu

Input : Toggle

<?xml version="1.0"?>
<configuration initial="init">
 <rules>
   <rule>
     <input state="test">
       <message name=">=" category="logic">
         <param>a0</param>
         <param>3</param>
       </message>
     </input>
     <output state="init">
       <message name="takePhoto" category="hardware"/>
     </output>
   </rule>
   <rule>
     <input state="test">
       <message name="<" category="logic">
         <param>a0</param>
         <param>3</param>
       </message>
     </input>
     <output state="init"/>
   </rule>
   <rule>
     <input state="init">
       <message name="toggle" category="external"/>
     </input>
     <output state="test"/>
   </rule>
  </rules>
</configuration>

Example : deriveeSMS.xml

DeriveeSMS

This example uses the sms feature to send a message to a user (telephone number used here is 0102010203). This FST also invoke the feature vibrator of the phone, and also display a "Toast" (for information : "Sending an SMS"). This demo is adapted for Smartphones.

Required features : sms, cpu, vibrator, notification

Input : Toggle

<?xml version="1.0"?>
<configuration initial="init">
  <rules>
   <rule>
     <input state="test">
       <message name=">=" category="logic">
         <param>a0</param>
         <param>3</param>
       </message>
     </input>
     <output state="init">
       <message name="vibrator" category="hardware">
         <param>medium</param>
       </message>
       <message name="sms" category="hardware">
         <param>0102010203</param>
         <param>Hi, i'm a robot</param>
       </message>
       <message name="notify" category="hardware">
         <param>Sending an SMS</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="test">
       <message name="<" category="logic">
         <param>a0</param>
         <param>3</param>
       </message>
     </input>
     <output state="init"/>
   </rule>
   <rule>
     <input state="init">
       <message name="toggle" category="external"/>
     </input>
     <output state="test"/>
   </rule>
  </rules>
</configuration>

Example : deriveeTest.xml

DeriveeTest

Required features : led, cpu

Input : Toggle

<?xml version="1.0"?>
<configuration initial="init">
  <rules>
   <rule>
     <input state="test">
       <message name="<=" category="logic">
         <param>a0</param>
         <param>0</param>
       </message>
     </input>
     <output state="init">
       <message name="led" category="hardware">
         <param>off</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="test">
       <message name=">" category="logic">
         <param>a0</param>
         <param>0</param>
       </message>
     </input>
     <output state="init">
       <message name="led" category="hardware">
         <param>on</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="init">
       <message name="toggle" category="external"/>
     </input>
     <output state="test"/>
   </rule>
  </rules>
</configuration>

Example : derivee.xml

Derivee

This example uses a humidity sensor, and send the variation to a displayer.

Required features : hum, cpu, timer

Output : Send

<?xml version="1.0"?>
<configuration initial="init">
  <rules>
   <rule>
     <input state="init">
       <message name="hum" category="hardware"/>
     </input>
     <output state="working">
       <message name="=" category="logic">
         <param>r0</param>
         <param>a0</param>
       </message>
       <message name="=" category="logic">
         <param>r1</param>
         <param>r0</param>
       </message>
       <message name="=" category="logic">
         <param>r2</param>
         <param>0</param>
       </message>
       <message name="timer" category="hardware">
         <param>1</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="working">
       <message name="timer" category="hardware"/>
     </input>
     <output state="test">
       <message name="+=" category="logic">
         <param>r2</param>
         <param>1</param>
       </message>
       <message name="-=" category="logic">
         <param>r1</param>
         <param>r0</param>
       </message>
       <message name="timer" category="hardware">
         <param>1</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="working">
       <message name="hum" category="hardware"/>
     </input>
     <output state="working">
       <message name="=" category="logic">
         <param>r0</param>
         <param>a0</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="test">
       <message name="!=" category="logic">
         <param>r1</param>
         <param>0</param>
       </message>
     </input>
     <output state="working">
       <message name="*=" category="logic">
         <param>r1</param>
         <param>-1</param>
       </message>
       <message name="/=" category="logic">
         <param>r1</param>
         <param>r2</param>
       </message>
       <message name="send" category="external">
         <param>r1</param>
       </message>
       <message name="=" category="logic">
         <param>r2</param>
         <param>0</param>
       </message>
       <message name="=" category="logic">
         <param>r1</param>
         <param>r0</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="test">
       <message name="==" category="logic">
         <param>r1</param>
         <param>0</param>
       </message>
     </input>
     <output state="working">
       <message name="=" category="logic">
         <param>r1</param>
         <param>r0</param>
       </message>
     </output>
   </rule>
  </rules>
</configuration>

Example : lightSensor.xml

LightSensor

Required features : lum_photo, cpu

Output : Send

<?xml version="1.0"?>
<configuration initial="dark">
  <rules>
    <rule>
      <input state="dark">
        <message name="lump" category="hardware"/>
      </input>
      <output state="dark">
       <message name="=" category="logic">
         <param>r0</param>
         <param>a0</param>
       </message>
     </output>
    </rule>
    <rule>
      <input state="light">
        <message name="lump" category="hardware"/>
      </input>
      <output state="light">
       <message name="=" category="logic">
         <param>r0</param>
         <param>a0</param>
       </message>
     </output>
    </rule>
    <rule>
      <input state="dark">
        <message name=">=" category="logic">
          <param>a0</param>
          <param>15</param>
        </message>
      </input>
      <output state="light">
        <message name="send" category="external">
          <param>Light</param>
        </message>
      </output>
    </rule>
    <rule>
      <input state="light">
        <message name="<" category="logic">
          <param>a0</param>
          <param>15</param>
        </message>
      </input>
      <output state="dark">
        <message name="send" category="external">
          <param>Dark</param>
        </message>
      </output>
    </rule>
  </rules>
</configuration>

Example : sample.xml

Sample

Required features : cpu

Input : ????

<?xml version="1.0"?>
<configuration initial="state1">
  <rules>
    <rule>
      <input state="state1">
        <message name="msg1" category="logic">
          <param>param1</param>
          <param>param2</param>
        </message>
      </input>
      <output state="state2">
        <message name="msg2" category="hardware">
          <param>param1</param>
          <param>param2</param>
        </message>
        <message name="msg3" category="external">
          <param>param1</param>
          <param>param2</param>
        </message>
      </output>
    </rule>
    <rule>
      <input state="state2">
        <message name="msg1" category="logic">
          <param>param1</param>
          <param>param2</param>
        </message>
      </input>
      <output state="state1">
        <message name="msg2" category="hardware">
          <param>param1</param>
          <param>param2</param>
        </message>
        <message name="msg3" category="external">
          <param>param1</param>
          <param>param2</param>
        </message>
      </output>
    </rule>
  </rules>
</configuration>

Example : sliderDivider.xml

SlideDivider

Required features : TODO

Input : ????

<?xml version="1.0"?>
<configuration initial="init1">
  <rules>
   <rule>
     <input state="send"/>
     <output state="init"/>
   </rule>
   <rule>
     <input state="init1"/>
     <output state="init">
       <message name="=" category="logic">
         <param>r0</param>
         <param>0</param>
       </message>
       <message name="=" category="logic">
         <param>r1</param>
         <param>0</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="init">
       <message name="slide" category="hardware"/>
     </input>
     <output state="init">
       <message name="=" category="logic">
         <param>r0</param>
         <param>a0</param>
       </message>
       <message name="/=" category="logic">
         <param>r0</param>
         <param>10</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="init">
       <message name="!=" category="logic">
         <param>r0</param>
         <param>r1</param>
       </message>
     </input>
     <output state="send">
       <message name="blink" category="external">
         <param>r0</param>
       </message>
       <message name="=" category="logic">
         <param>r1</param>
         <param>r0</param>
       </message>
     </output>
   </rule>
  </rules>
</configuration>

Example : test.xml

test

Required features : TODO

Input :

<?xml version="1.0"?>
<configuration initial="off">
  <rules>
    <rule>
      <input state="on">
        <message name="push" category="hardware"/>
      </input>
      <output state="off">
        <message name="led" category="hardware">
          <param>off</param>
        </message>
        <message name="push" category="external"/>
      </output>
    </rule>
    <rule>
      <input state="off">
        <message name="push" category="hardware"/>
      </input>
      <output state="on">
        <message name="led" category="hardware">
          <param>on</param>
        </message>
        <message name="push" category="external"/>
      </output>
    </rule>
  </rules>
</configuration>

Example : toggleTest.xml

toggleTest

Required features : TODO

Input :

<?xml version="1.0"?>
<configuration initial="off">
  <rules>
   <rule>
     <input state="on">
       <message name="push" category="hardware"/>
     </input>
     <output state="off">
       <message name="led" category="hardware">
         <param>off</param>
       </message>
       <message name="toggle" category="hardware">
         <param>off</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="off">
       <message name="push" category="hardware"/>
     </input>
     <output state="on">
       <message name="led" category="hardware">
         <param>on</param>
       </message>
       <message name="toggle" category="hardware">
         <param>on</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="off">
       <message name="toggle" category="hardware"/>
     </input>
     <output state="on">
       <message name="led" category="hardware">
         <param>a0</param>
       </message>
     </output>
   </rule>
   <rule>
     <input state="on">
       <message name="toggle" category="hardware"/>
     </input>
     <output state="off">
       <message name="led" category="hardware">
         <param>a0</param>
       </message>
     </output>
   </rule>
  </rules>
</configuration>