Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jul 30 2022 14:17
    xiong-kun starred jbeard4/SCION
  • Jul 06 2022 06:21
  • Apr 14 2022 21:19
    fawaz-alesayi starred jbeard4/SCION
  • Jan 26 2022 05:17
    GitLab | Jacob Beard pushed 1 commits to scion
  • Jan 26 2022 05:17
    GitLab | Jacob Beard pushed 1 commits to scion
  • Jan 26 2022 05:15
    GitLab | Jacob Beard pushed 3 commits to scion
  • Jan 26 2022 05:06
    GitLab | Jacob Beard pushed 1 commits to scion
  • Dec 17 2021 21:09
  • Nov 07 2021 20:37
    agrrd starred jbeard4/SCION
  • Nov 02 2021 12:53
    jgshumate1 starred jbeard4/SCION
  • Sep 29 2021 20:56
    Abdallah Nasser commented on issue #4 eslint-plugin does not process .scxml files in visual studio code in scion
  • Sep 29 2021 17:09
    Christophe Gerard commented on issue #4 eslint-plugin does not process .scxml files in visual studio code in scion
  • Sep 29 2021 16:50
    Abdallah Nasser commented on issue #4 eslint-plugin does not process .scxml files in visual studio code in scion
  • Aug 02 2021 18:36
  • Jul 29 2021 04:22
    GitLab | Jacob Beard pushed 1 commits to scion
  • Jul 09 2021 21:55
    GitLab | Jacob Beard pushed 1 commits to scion
  • Jul 09 2021 21:55
    GitLab | Jacob Beard pushed 1 commits to scion
  • Jul 09 2021 21:52
    Jacob Beard merged merge request scion-scxml/scion!2 in scion
  • Jul 09 2021 21:52
    GitLab | Jacob Beard pushed to scion
  • Jul 09 2021 21:52
    GitLab | Jacob Beard pushed 3 commits to scion
Jacob Beard
@jbeard4

@davidkpiano most likely test570 is about this

this seems right

David Khourshid
@davidkpiano
Thanks!
Prashant Mumbarkar
@Mumbasms

@jbeard4 Thanks for the detailed answer. And apologise for the late reply. Life is becoming quite busy with the vaccine, student job, full-time job search, thesis, Euro football, summer :D
Anyway to answer your question //I am not fully following this. What is #{}, and what is ${}? What language is this?// I meant Expression Language we use in HTML to bind java beans.

More likely, I am not going to use a binding or custom data model for my solution. I created a sample solution "how to implement Ramp function in SCXML" and try to ran it in JS Bins but it didn't work.

Below is the file. Could you please check if I am doing something wrong
? Does JS bins handle Raise event?

<?xml version="1.0" encoding="UTF-8"?>
<scxml
    xmlns="http://www.w3.org/2005/07/scxml"
    xmlns:capl="http://www.NotRealURL.de"
    xmlns:cs="http://commons.apache.org/scxml" version="1.0" initial="startup" datamodel="ecmascript" name="TestCase">
    <datamodel>
        <data id= "var1" expr="{&quot;name&quot;:&quot; var1&quot;,&quot;type&quot;:&quot;Integer&quot;, &quot;value&quot;:8}"/>
    </datamodel>
    <parallel id="logicMore">
        <state id="startup">
            <onentry>
                <log label="before" expr="var1.value"/>
                <raise event="starRamp" />
                <log label="after" expr="var1.value"/>

            </onentry>
            <transition target="logic" />
            <transition event="TestCase.error" target="teardown" />
        </state>
        <state id="startup2"  initial="wait">
            <state id="wait">
                <transition event="starRamp" target="rampBody" />
                <transition target="wait" />
            </state>
            <state id="rampBody">
                <onentry>
                    <assign location="var1.value" expr="var1.value + 4"/>
                    <log label="during" expr="var1.value"/>
                </onentry>
                <transition target="rampBody" />
                <transition event="stopRamp" target="finalOne" />
            </state>
            <final id="finalOne"/>
        </state>
    </parallel>
    <parallel id="logic">
        <state id="logic_c0" />
        <state id="logic_c1" />
    </parallel>
    <state id="teardown">
        <transition target="final" />
    </state>
    <final id="final" />
</scxml>
In startup2 , I just wait in loop till I receive event starRamp and then I just continually add 4 to var1.value and will stop only if I receive stopRamp event. Basically, it is ramp function with slope 4
Jacob Beard
@jbeard4
@Mumbasms The issue is your initial state is transitioning to the startup state, rather than the startup2 state. After that, the startup state will automatically transition to the logic state, because it contains an eventless transition. So you should probably remove the transition from startup2 to the logic state. I would recommend visualizing your SCXML during development, as it will make these kinds of logic errors clearer
SCION has two tools for visualizing your SCXML: a CLI tool, and a VSCode extension
You can run the cli tool with: npm install @scion-scxml/cli, then run scion viz my.scxml
Should work on linux and mac OS. Unknown if it works on Windows
Jacob Beard
@jbeard4
Then there is a Visual Studio Code extension called SCXML Preview
Prashant Mumbarkar
@Mumbasms
Thanks @jbeard4 . I installed Visual Studio code and SCXML preview too. And you are right , visualisation became easy and very helpful :)
<?xml version="1.0" encoding="UTF-8"?>
<scxml
    xmlns="http://www.w3.org/2005/07/scxml"
    xmlns:capl="http://www.NotRealURL.de"
    xmlns:cs="http://commons.apache.org/scxml" version="1.0" initial="startup" datamodel="ecmascript" name="TestCase">
    <datamodel>
        <data id= "var1" expr="{&quot;name&quot;:&quot; var1&quot;,&quot;type&quot;:&quot;Integer&quot;, &quot;value&quot;:8}"/>
    </datamodel>
    <state id="startup">
        <onentry>
            <raise event="startRamp"/>
        </onentry>
        <transition target="logic" />
        <transition event="TestCase.error" target="teardown" />
    </state>
    <parallel id="logic">
        <state id="logic_c0" />
        <state id="logic_c1" />
        <transition target="teardown" />
    </parallel>
    <state id="teardown">
        <transition target="final" />
    </state>
    <final id="final" >
        <onentry>
            <raise event="stopRamp"/>
        </onentry>
    </final>
</scxml>
image.png
So this is my input file. This is a test case flow. And at some point this test case wants to run Ramp function on Var1 betweeen event "startRamp" and "stopRamp". Now I need to create output file from this but provide implementation for Ramp function on Var1
<?xml version="1.0" encoding="UTF-8"?>
<scxml
    xmlns="http://www.w3.org/2005/07/scxml"
    xmlns:capl="http://www.NotRealURL.de"
    xmlns:cs="http://commons.apache.org/scxml" version="1.0" initial="NewParent" datamodel="ecmascript" name="TestCase">
    <datamodel>
        <data id= "var1" expr="{&quot;name&quot;:&quot; var1&quot;,&quot;type&quot;:&quot;Integer&quot;, &quot;value&quot;:8}"/>
    </datamodel>
    <parallel id="NewParent">
        <state id="rampFuction"  initial="loopWait">
            <state id="loopWait">
                <transition event="startRamp" target="rampBody" />
                <transition target="loopWait" />
            </state>
            <state id="rampBody">
                <onentry>
                    <assign location="var1.value" expr="var1.value + 4"/>
                    <log label="during" expr="var1.value"/>
                </onentry>
                <transition target="rampBody" />
                <transition event="stopRamp" target="finalOne" />
            </state>
            <final id="finalOne"/>
        </state>
        <state id="OrigialFlow">
            <state id="startup">
                <onentry>
                    <raise event="startRamp"/>
                </onentry>
                <transition target="logic" />
                <transition event="TestCase.error" target="teardown" />
            </state>
            <parallel id="logic">
                <state id="logic_c0" />
                <state id="logic_c1" />
                <transition target="teardown" />
            </parallel>
            <state id="teardown">
                <transition target="final" />
            </state>
            <final id="final" >
                <onentry>
                    <raise event="stopRamp"/>
                </onentry>
            </final>
        </state>
    </parallel>
</scxml>
So I thought I will put eveything from origial input file inside its own state "OrigialFlow" so that flow remain intact and I create sibling for this as "rampFuction" which will take care of ramp function by waiting in loop. And put both these children inside parallel "NewParent" and ask SCXML to start with inital ="NewParent".
image.png
Prashant Mumbarkar
@Mumbasms
I feel like the above diagram does look like what I want. But my problem now is JS Bins hangs when I try to run this script. Because I want to see it "live" in action by using <log> . I mean I want to execute SCXML file and it is not working .
Jacob Beard
@jbeard4
@Mumbasms You may want to try some of SCION's tools for graphical debugging shown here: https://www.youtube.com/watch?v=GbP3_b8GVbM
Jacob Beard
@jbeard4
@Mumbasms I took a look at your code, and I think the reason it is hanging is due to this code:
           <state id="loopWait">
                <transition event="startRamp" target="rampBody" />
                <transition target="loopWait" />
            </state>
This targetless transition will loop infinitely
Jacob Beard
@jbeard4
Could you explain in natural language your system requirements? Maybe I can help direct you
Jacob Beard
@jbeard4
Sorry, I said "targetless transition", but I meant "eventless" or "default" transition
This will cause the state machine to loop infinitely in loopWait
Prashant Mumbarkar
@Mumbasms
@jbeard4 I saw your master thesis. Well written and excellent yet simple LaTex format. Is it possible to share the LaTeX template you used?:)
Jacob Beard
@jbeard4
@Mumbasms I'll post it to gitlab later and you can review it
Jacob Beard
@jbeard4
@Mumbasms Having some trouble finding the source code. I will need to get this to you later
Prashant Mumbarkar
@Mumbasms
@jbeard4 all good. I am currently focusing on the writing content part. Will check once you upload the code. thanks :)
Prashant Mumbarkar
@Mumbasms

I am in trouble. :)
I have 2 SCXML files : input and output. My program creates output file. Now I have to show: both files are semantically equivalent, somehow.

Input File: <ccdl:wait> means "wait for 100ms" then continue execution

<?xml version="1.0" encoding="UTF-8"?>
<scxml
    xmlns="http://www.w3.org/2005/07/scxml"
    xmlns:ccdl="http://www.NotRealURL.de"
    xmlns:cs="http://commons.apache.org/scxml" version="1.0" initial="startup" datamodel="ecmascript" name="TestCase">
    <datamodel>
        <data id= "var1" expr="{'name':' var1','type':'Integer', 'value':8}"/>
        <data id="dummyVariable" expr="0"/>
    </datamodel>
    <state id="startup">
        <onentry>
            <assign location="dummyVariable" expr="110"/>
            <assign location="dummyVariable" expr="120"/>
            <ccdl:wait duration="100 ms" />
            <assign location="dummyVariable" expr="310"/>
            <assign location="dummyVariable" expr="410"/>
        </onentry>
        <transition target="logic" />
        <transition event="TestCase.error" target="teardown" />
        <onexit>
            <assign location="dummyVariable" expr="10"/>
            <assign location="dummyVariable" expr="10"/>
        </onexit>
    </state>
    <parallel id="logic">
        <state id="logic_c0" />
        <state id="logic_c1" />
        <transition target="teardown" />
    </parallel>
    <state id="teardown">
        <transition target="final" />
    </state>
    <final id="final" />
</scxml>
Output File: I divided onEntry into 2 parts. First part becomes onEntry and the second part becomes OnExit of new state "child"
as below. This "child" state creates "wait" for 100 ms
    <?xml version="1.0" encoding="UTF-8"?>
<scxml
    xmlns="http://www.w3.org/2005/07/scxml"
    xmlns:ccdl="http://www.NotRealURL.de"
    xmlns:cs="http://commons.apache.org/scxml" version="1.0" initial="startup" datamodel="ecmascript" name="TestCase">
    <!--https://commons.apache.org/scxml-->
    <datamodel>
        <data id="var1" expr="{'name':' var1','type':'Integer', 'value':8}"/>
        <data id="dummyVariable" expr="0"/>       
        <data id="duration" expr="0"/>
        <data id="startTime" expr="0"/>
    </datamodel>
    <state id="startup" initial="child">
        <transition target="logic"/>
        <transition event="TestCase.error" target="teardown"/>
        <state id="child" initial="hold">
            <onentry>
                <assign location="dummyVariable" expr="110"/>
                <assign location="dummyVariable" expr="120"/>
                <assign location="startTime" expr="Date.now()"/>
            </onentry>
            <state id="hold">
                <onentry>
                    <assign location="duration" expr="Date.now()- startTime"/>
                </onentry>
                <transition cond="duration!=100" target="hold"/>
                <transition cond="duration==100" target="child_Final"/>
            </state>
            <final id="child_Final"/>
            <onexit>
                <assign location="dummyVariable" expr="310"/>
                <assign location="dummyVariable" expr="410"/>
            </onexit>
        </state>
        <onexit>
            <assign location="dummyVariable" expr="10"/>
            <assign location="dummyVariable" expr="10"/>
        </onexit>
    </state>
    <parallel id="logic">
        <transition target="teardown"/>
        <state id="logic_c0"/>
        <state id="logic_c1"/>
    </parallel>
    <state id="teardown">
        <transition target="final"/>
    </state>
    <final id="final"/>
</scxml>
Prashant Mumbarkar
@Mumbasms
This is a simple case. Is there a way to modify >> JSbins << so that I can execute my both input and output file and compare the output. Right now I can only execute the output file as it has no custom tags..
I am trying to understand this Custom-Action-Tags-(DEPRECATED))
Jacob Beard
@jbeard4

Hi @Mumbasms,

First, here is how you can add custom action tags to SCION:

Use the scion.scxml.registerCustomActionTags API. This takes a data structure of the form { <xml namespace> -> { <tag name> -> compiler function } }. This API is used internally to implement the core action tags, so you can use that as an example:

https://gitlab.com/scion-scxml/scion/-/blob/main/projects/libraries/scxml/lib/runtime/facade.js#L44
https://gitlab.com/scion-scxml/scion/-/blob/main/projects/libraries/scxml/lib/compiler/coreActionTags.js

Next, here is how you might implement ccdl:wait (untested, but should plausibly work):

{
  "http://www.NotRealURL.de" : {
    "wait": function(action, builder){
      return ```
        const tic = new Date()
        while(true){
          const toc = new Date()
          const duration = toc - tic
          if(duration >= getDelayInMs("${action.duration}")){
            break
          }
        }
      ```

    }
  }
}

Big disclaimer: this solution is appropriate for research purposes only. This is not a practical solution, as Node.js is single-threaded, and the while loop would block the main thread, and any other asynchronous actions. A more appropriate solution is to use SCXML's <send> tag with @delay attribute. But this does require breaking the state machine into two states. Something like this:

    <state id="startup">
        <onentry>
            <assign location="dummyVariable" expr="110"/>
            <assign location="dummyVariable" expr="120"/>
            <send event="ccdl_wait" delay="100ms"/>
        </onentry>
        <transition target="after_delay" event="ccdl_wait"/>
    </state>

    <state id="after_delay">
        <onentry>
            <assign location="dummyVariable" expr="310"/>
            <assign location="dummyVariable" expr="410"/>
        </onentry>
        <transition target="logic" />
        <transition event="TestCase.error" target="teardown" />
        <onexit>
            <assign location="dummyVariable" expr="10"/>
            <assign location="dummyVariable" expr="10"/>
        </onexit>
    </state>

Hope this helps.

Prashant Mumbarkar
@Mumbasms
Hey @jbeard4 . This is very helpful. Thanks.
Forgive me if I misunderstood. Java is my main language. So in order to write my own custom action, I will add a javascript file like coreActionTags and then call that file in tagRegistry.registerCustomActionTags. So far so good.
Prashant Mumbarkar
@Mumbasms
My friend , Korel sending one issue about this on gitlab. Please check :)
Prashant Mumbarkar
@Mumbasms

For some reason ramp function in <transition> is not updating datamodel. Otherwise our solution works

index.js

const scxml = require("@scion-scxml/scxml");
const core = require("@scion-scxml/core");

let action = {
  "http://www.NotRealURL.de": {
    wait: function (action, builder) {
      const tic = new Date();
      while (true) {
        const toc = new Date();
        const duration = toc - tic;

        if (duration >= parseInt(action.duration.replace("ms", ""))) {
          console.log(duration + "here");
          break;
        }
      }

      return "something";
    },

    expect: function (action, builder) {
      let expr = builder.generateFnCall(
        builder.generateAttributeExpression(action, "expr")
      );
      return `if(${expr}){
            this.log('Expect Action Success');
        } else {
            this.log('Expect Action Failed');
        }`;
    },
    ramp: function (action, builder) {



        return `this.log(${action.dataid}.value); 
        for (let i =0 ; i < 10; i++) { 
          let temp=${action.dataid}.value + parseInt(${action.slope});
            ${action.dataid}.value = temp;
           // this.log(${action.dataid}.value);
          }
          this.log(${action.dataid}.value);   


          `;
    }
  }
};

scxml.registerCustomActionTags(action);
scxml.pathToModel(
  "rampINPUT.scxml",
  function (err, model) {
    if (err) throw err;
    model.prepare(function (err, fnModel) {
      if (err) throw err;
      //instantiate the interpreter
      var sc = new core.Statechart(fnModel);
      //start the interpreter
      sc.start();
    });
  }
);

Input File below rampINPUT.scxml

<?xml version="1.0" encoding="UTF-8"?>
<scxml
    xmlns="http://www.w3.org/2005/07/scxml"
    xmlns:ccdl="http://www.NotRealURL.de"
    xmlns:cs="http://commons.apache.org/scxml" version="1.0" initial="startup" datamodel="ecmascript" name="TestCase">
    <datamodel>
       <data id= "var1" expr="{'name':' var1','type':'Integer', 'value':2}"/>
        <data id= "var2" expr="{'name':' var2','type':'Integer', 'value':10}"/>
        <data id= "var3" expr="{'name':' var3','type':'Integer', 'value':5}"/>
       <data id="dummyVariable" expr="0"/>
    </datamodel>
    <state id="startup">
        <onentry>
            <assign location="dummyVariable" expr="10"/>
            <assign location="dummyVariable" expr="20"/>           
            <ccdl:ramp id="ramp1" dataid="var1" slope="4"/>
            <assign location="dummyVariable" expr="30"/>           
            <assign location="dummyVariable" expr="40"/>
        </onentry>
        <transition target="logic" >
            <assign location="dummyVariable" expr="605"/>
            <ccdl:ramp id="ramp2" dataid="var2" slope="400"/>
            <assign location="dummyVariable" expr="750"/> 
            <log label="dummyVariable here" expr="dummyVariable"/> 

        </transition>
        <transition event="TestCase.error" target="teardown" />
        <onexit>
            <assign location="dummyVariable" expr="60"/>
            <ccdl:ramp id="ramp3" dataid="var3" slope="8"/>
            <assign location="dummyVariable" expr="70"/>  

            <log label="var1" expr="var1.value"/>       
            <log label="var2" expr="var2.value"/>              
            <log label="var3" expr="var3.value"/>  
            <log label="dummyVariable last" expr="dummyVariable"/>     
        </onexit>
    </state>
    <parallel id="logic">
        <state id="logic_c0" />
        <state id="logic_c1" />
        <transition target="teardown" />

    </parallel>
    <state id="teardown">
        <transition target="final" />
    </state>
    <final id="final" />
</scxml>

console output

2
42
5
85
var1 42
var2 10
var3 85
dummyVariable last 70
10
4010
dummyVariable here 750
P.S : I deleted old messages as those problems were resolved and to declutter the space :)
Jacob Beard
@jbeard4
@Mumbasms Sorry, I just saw your messages. I will review and follow up with you shortly
Jacob Beard
@jbeard4
Reading through this, it looks like the datamodel should be getting updated
there is something strange about the console output. It looks like dummyVariable here shoudl occur after dummyVariable last
I would need to step through this in a debugger to investigate
Thanks for opening scion-scxml/scion#25. This looks like a bug in registerCustomActionTags and I will plan to fix this soon
it sounds like you have a workaround right now to that issue
Prashant Mumbarkar
@Mumbasms

@jbeard4 Oh understand. So far everything worked out.

1) "dummyVariable last" in <onexit> and "dummyVariable here" inside <transition> so as per SCXML rule, if I am not wrong,
while transitioning out from the state , sequence of execution : <onexit> of source state, <transition> executatable content
and then <onentry> of target state..

2) We wanted to use the ramp in parallel to the main execution i.e. in a separate thread.But it was pointed out to me that javascript is a single thread framework. Hence I decided to use uscxml- SCXML interpreter and transformer/compiler written in C/C++,
just to compare input and output files in the ramp. All credit goes to Korel for this :)

Prashant Mumbarkar
@Mumbasms
@jbeard4 I have a question. Have you ever used XSLT to transform SCXML into XML/SCXML or something similar? In my thesis, I used Apache SCXML to transform input to output, needless to say, the transformation logic is "hardcoded" in java. I was wondering if the same transformation is possible via XSLT or not ..
Jacob Beard
@jbeard4

@Mumbasms Yes, in 2010 I developed an early version of SCION (then called scxml-js) as a project for the Apache Software Foundation as a part of Google Summer of Code, and this was implemented as an XSLT pipeline, such that it transformed SCXML to Javascript. I wrote a paper about it, which you can read here:

http://www.graphicalweb.org/2010/papers/45-Developing_a_StatecharttoECMAScript_Compiler_Optimized_for_SVG_User_Interface_Development_for_the_World_Wide_Web/index.html

Slides are here:

http://www.graphicalweb.org/2010/presentations/45-Developing_a_StatecharttoECMAScript_Compiler_Optimized_for_SVG_User_Interface_Development_for_the_World_Wide_Web/index.pdf

Here is the source code:

http://svn.apache.org/repos/asf/commons/sandbox/gsoc/2010/scxml-js/trunk/

Hope this helps.

I feel like there were some pretty good ideas in that project. It would be neat to extend it to support multiple language compilation targets, like Ragel:

http://www.colm.net/open-source/ragel/