Avatar for nailxx

nailxx

Member since Oct 2015 • Last active Nov 2015
  • 1 conversations
  • 5 comments

Most recent activity

  • in General
    Avatar for nailxx

    Well, the root is here:

    void jshPushIOCharEvent(IOEventFlags channel, char charData) {
      if (charData==3 && channel==jsiGetConsoleDevice()) {
        // Ctrl-C - force interrupt
        execInfo.execute |= EXEC_CTRL_C;
        return;
      }
      //...
    }
    

    If the board wasn't idle and didn't consume IO buffer, \x03 will be just extracted out of context. And next time idle routine will try to handle IO buffer the first thing it will see is EXEC_CTRL_C flag. No matter that there were characters before the flag was set. These chars will be processed later.

    First possible solution is to add some magic to jshPushIOCharEvent so that \x03 will clear buffer. Not sure it's a good idea.

    A quick fix that works is to send some trash chars, wait, and then send the expression that starts with \x03. I've made a pull request with this fix.

  • in General
    Avatar for nailxx

    BTW, if I try this:

    Espruino.Core.Serial.write('ffff\x03echo(0);\nconsole.log("<<"+"<<<"+JSON.stringify('+expressionToExecute+')+">>>"+">>");\n');
    

    I get:

    Uncaught ReferenceError: "ffffecho" is not defined
     at line 1 col 1
    ffffecho(0);
    

    Someone processed \x03 without clearing leading characters ffff.

  • in General
    Avatar for nailxx

    I have github’s master. And, yes, the behavior is the same. It clears line for the first Ctrl-C and interrupts for the second. That's fine. What I cant understand is why if I ever add leading space to:

    // string adds to stop the command tag being detected in the output
    Espruino.Core.Serial.write(' \x03echo(0);\nconsole.log("<<"+"<<<"+JSON.stringify('+expressionToExecute+')+">>>"+">>");\n');
    

    …I always get setInterval interrupt once connected.

    The only reason to have \x03 here as you've said is just to ensure that the line is clear. Right? And if we add some leading trash it should never lead to interrupt. If it should work like this there is a bug somewhere. I can try to find it.

  • in General
    Avatar for nailxx

    Ah… I see the reason, thank you.

    If you enter a few characters before you disconnect, when you reconnect do you get the same problem? If I changed the Web IDE to send a space before the Ctrl-C it might magically fix it?

    No few chars doesn't fix this. However looking at jsinteractive.c I can't understand why. Looks like jsvIsEmptyString(inputLine) always true… I need to inverstigate deeper.

  • in General
    Avatar for nailxx

    Hello!

    I have a saved program that sends some data from Espruino to PC via console.log every 100 ms. It works fine until I try to connect from IDE after the board reboot. Once powered up the board begins to do its job every 100 ms and when I connect it says “Ctrl-C while processing interval - removing it”. And as it said the scheduled job is cancelled.

    The underlying reason is \x03 character (Ctrl-C) that IDE sends once connection established:

    ---> "\u0003echo(0);\nconsole.log(\"<<\"+\"<<<\"+JSON.stringify(process.env)+\">>>\"+\">>\");\n"

    OK, it is necessary to check out process.env to setup IDE properly but is there any reason to start with \u0003 in this case?

Actions