Facility Control

 View Only
Expand all | Collapse all

Catch mos message with null terminators from inception

alex samih-zade

alex samih-zade05-05-2020 21:59

Hello I trying to catch mos messages from ross inception NRCS. So, here is the message example: {00}{3C}{00}{6D}{00}{6F}{00}{73}{00}{3E}{00}{0A}{00}{3C}{00}{6D}{00}{6F}{00}{73}{00}{49}{00}{44}{00}{3E}{00}{56}{00}{54}{00}{52}{00}{3C}{00}{2F}{00}{6D}{00}{6F}{00}{73}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{6E}{00}{63}{00}{73}{00}{49}{00}{44}{00}{3E}{00}{49}{00}{4E}{00}{43}{00}{45}{00}{50}{00}{54}{00}{49}{00}{4F}{00}{4E}{00}{3C}{00}{2F}{00}{6E}{00}{63}{00}{73}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{72}{00}{6F}{00}{45}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{41}{00}{63}{00}{74}{00}{69}{00}{6F}{00}{6E}{00}{20}{00}{6F}{00}{70}{00}{65}{00}{72}{00}{61}{00}{74}{00}{69}{00}{6F}{00}{6E}{00}{3D}{00}{22}{00}{52}{00}{45}{00}{50}{00}{4C}{00}{41}{00}{43}{00}{45}{00}{22}{00}{3E}{00}{0A}{00}{3C}{00}{72}{00}{6F}{00}{49}{00}{44}{00}{3E}{00}{35}{00}{32}{00}{34}{00}{37}{00}{3C}{00}{2F}{00}{72}{00}{6F}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{65}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{5F}{00}{74}{00}{61}{00}{72}{00}{67}{00}{65}{00}{74}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{49}{00}{44}{00}{3E}{00}{39}{00}{36}{00}{38}{00}{32}{00}{38}{00}{37}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{65}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{5F}{00}{74}{00}{61}{00}{72}{00}{67}{00}{65}{00}{74}{00}{3E}{00}{0A}{00}{3C}{00}{65}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{5F}{00}{73}{00}{6F}{00}{75}{00}{72}{00}{63}{00}{65}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{49}{00}{44}{00}{3E}{00}{39}{00}{36}{00}{38}{00}{32}{00}{38}{00}{37}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{53}{00}{6C}{00}{75}{00}{67}{00}{3E}{00}{26}{00}{23}{00}{31}{00}{35}{00}{30}{00}{35}{00}{3B}{00}{26}{00}{23}{00}{31}{00}{35}{00}{30}{00}{32}{00}{3B}{00}{26}{00}{23}{00}{31}{00}{34}{00}{39}{00}{37}{00}{3B}{00}{26}{00}{23}{00}{31}{00}{34}{00}{39}{00}{33}{00}{3B}{00}{26}{00}{23}{00}{31}{00}{35}{00}{30}{00}{33}{00}{3B}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{53}{00}{6C}{00}{75}{00}{67}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{4E}{00}{75}{00}{6D}{00}{3E}{00}{36}{00}{36}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{4E}{00}{75}{00}{6D}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{65}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{5F}{00}{73}{00}{6F}{00}{75}{00}{72}{00}{63}{00}{65}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{72}{00}{6F}{00}{45}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{41}{00}{63}{00}{74}{00}{69}{00}{6F}{00}{6E}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{6D}{00}{6F}{00}{73}{00}{3E}{00}{0A} ...
  • 1.  Catch mos message with null terminators from inception

    Posted 05-05-2020 21:59

    Hello

    I trying to catch mos messages from ross inception NRCS. So, here is the message example:

    {00}{3C}{00}{6D}{00}{6F}{00}{73}{00}{3E}{00}{0A}{00}{3C}{00}{6D}{00}{6F}{00}{73}{00}{49}{00}{44}{00}{3E}{00}{56}{00}{54}{00}{52}{00}{3C}{00}{2F}{00}{6D}{00}{6F}{00}{73}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{6E}{00}{63}{00}{73}{00}{49}{00}{44}{00}{3E}{00}{49}{00}{4E}{00}{43}{00}{45}{00}{50}{00}{54}{00}{49}{00}{4F}{00}{4E}{00}{3C}{00}{2F}{00}{6E}{00}{63}{00}{73}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{72}{00}{6F}{00}{45}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{41}{00}{63}{00}{74}{00}{69}{00}{6F}{00}{6E}{00}{20}{00}{6F}{00}{70}{00}{65}{00}{72}{00}{61}{00}{74}{00}{69}{00}{6F}{00}{6E}{00}{3D}{00}{22}{00}{52}{00}{45}{00}{50}{00}{4C}{00}{41}{00}{43}{00}{45}{00}{22}{00}{3E}{00}{0A}{00}{3C}{00}{72}{00}{6F}{00}{49}{00}{44}{00}{3E}{00}{35}{00}{32}{00}{34}{00}{37}{00}{3C}{00}{2F}{00}{72}{00}{6F}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{65}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{5F}{00}{74}{00}{61}{00}{72}{00}{67}{00}{65}{00}{74}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{49}{00}{44}{00}{3E}{00}{39}{00}{36}{00}{38}{00}{32}{00}{38}{00}{37}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{65}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{5F}{00}{74}{00}{61}{00}{72}{00}{67}{00}{65}{00}{74}{00}{3E}{00}{0A}{00}{3C}{00}{65}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{5F}{00}{73}{00}{6F}{00}{75}{00}{72}{00}{63}{00}{65}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{49}{00}{44}{00}{3E}{00}{39}{00}{36}{00}{38}{00}{32}{00}{38}{00}{37}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{49}{00}{44}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{53}{00}{6C}{00}{75}{00}{67}{00}{3E}{00}{26}{00}{23}{00}{31}{00}{35}{00}{30}{00}{35}{00}{3B}{00}{26}{00}{23}{00}{31}{00}{35}{00}{30}{00}{32}{00}{3B}{00}{26}{00}{23}{00}{31}{00}{34}{00}{39}{00}{37}{00}{3B}{00}{26}{00}{23}{00}{31}{00}{34}{00}{39}{00}{33}{00}{3B}{00}{26}{00}{23}{00}{31}{00}{35}{00}{30}{00}{33}{00}{3B}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{53}{00}{6C}{00}{75}{00}{67}{00}{3E}{00}{0A}{00}{3C}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{4E}{00}{75}{00}{6D}{00}{3E}{00}{36}{00}{36}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{4E}{00}{75}{00}{6D}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{73}{00}{74}{00}{6F}{00}{72}{00}{79}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{65}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{5F}{00}{73}{00}{6F}{00}{75}{00}{72}{00}{63}{00}{65}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{72}{00}{6F}{00}{45}{00}{6C}{00}{65}{00}{6D}{00}{65}{00}{6E}{00}{74}{00}{41}{00}{63}{00}{74}{00}{69}{00}{6F}{00}{6E}{00}{3E}{00}{0A}{00}{3C}{00}{2F}{00}{6D}{00}{6F}{00}{73}{00}{3E}{00}{0A}

     

    Which means in ascii:

     

    <mosID>VTR</mosID>
    <ncsID>INCEPTION</ncsID>
    <roElementAction operation="REPLACE">
    <roID>5247</roID>
    <element_target>
    <storyID>968287</storyID>
    </element_target>
    <element_source>
    <story>
    <storyID>968287</storyID>
    <storySlug>&#1505;&#1502;&#1497;&#1493;&#1503;</storySlug>
    <storyNum>66</storyNum>
    </story>
    </element_source>
    </roElementAction>
    </mos>

     

    So, i tried many delimiter option (each message ends with "</mos>"). I started from delimiter type "bytes", delimiter "3C002F006D006F0073003E000A" (</mos>). Also tried ogscript.createMessageParser(this.getInputStream()); (with "stop all execution op pause checked on)

    Nothing. My only success was with fixed bytes - and event.getBytesAsString - then i got separated character. I believe now this is something about that null separator that comes before each byte in the message.

    Is there a way to catch the whole message as one part?

    Thanks, and sorry for that long boring hex numbers.. :)

    Alex.



  • 2.  RE: Catch mos message with null terminators from inception

    Posted 05-06-2020 06:36

    Hi Alex,

    That looks like UTF-16 encoding to me, which is 16 bits per character instead of the normal 8 bits. I'm not sure if there's a way in ogscript to work with UTF-16, but if there is, that would fix your problem.

    James.

     

    EDIT: by the way, those aren't null terminators, rather, the first byte of the 2-byte UTF-16 characters.


    #DashBoard


  • 3.  RE: Catch mos message with null terminators from inception

    Posted 05-06-2020 06:57

    Hello James,
    Ok, even if this is utf16 encoded characters, they still comes as bytes stream, no? So, why i can't get that raw bytes with "bytes" delimiter, i know the last bytes sequence, there is always "/mos" .. if i could get those bytes as array or even string, i can manipulate it with standart js methods and get what i need in the end..


    #DashBoard


  • 4.  RE: Catch mos message with null terminators from inception

    Posted 05-06-2020 07:03

    Have you tried the readUTF() function on the object returned from createMessageParser()? I have no data to test it on myself, though.

    Example:

    var messageReader = ogscript.createMessageParser(this.getInputStream());
    var str = messageReader.readUTF();


    #DashBoard


  • 5.  RE: Catch mos message with null terminators from inception

    Posted 05-06-2020 16:58

    Hi Alex

    James is correct that this definitely appears to be a UTF-16 encoding (whereas we default everything to UTF-8 in DashBoard). This will cause some complexity (but is solvable) when you go to look at your strings but you should definitely still be able to get your messages.

    The delimiter as bytes is the right approach if you want to to break on the </mos> part of the message. If that isn't working for you, can you please post your <listener/> tag so we can see what is happening?

    Thanks

    James


    #DashBoard


  • 6.  RE: Catch mos message with null terminators from inception

    Posted 05-06-2020 19:53

    Hello James, 

    The delimiter="003C002F006D006F0073003E" value is actually an bytes sequence that represents "</mos>". I'm using dashboard 9.0. 

    Here is my panel:

    <abs contexttype="opengear" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" maxlength="0" name="textinput" oid="textinput" type="STRING" value="" widget="multiline-text"/>
    </params>
    </meta>
    <meta/>
    <abs height="898" left="4" top="3" width="1316">
    <listener autostart="false" blockingpause="true" bottom="860" buttontype="toggle" delimiter="003C002F006D006F0073003E" delimitertype="bytes" id="listener.10541" left="0" listenport="10541" name="mos 10541" right="1232" top="0">
    <task tasktype="ogscript">if (event.isConnectEvent())
    {
    //ogscript.putObject('E', this);
    ogscript.debug("connect event..");
    }

    if (event.isMessageEvent())
    {


    var messageParser = ogscript.createMessageParser(this.getInputStream());
    var utfStr = messageParser.readUTF();
    //var byteArray = messageReader.readBytes(length);
    params.setValue('textinput', 0, utfStr); // put data on text entry

    ogscript.debug(utfStr.length);


    }




    /*
    * var byteArray = messageReader.readBytes(length);
    * messageReader.skipBytes(length);
    * var boolVal = messageReader.readBoolean();
    * var byteVal = messageReader.readByte();
    * var byteVal = messageReader.readUnsignedByte();
    * var shortVal = messageReader.readShort();
    * var shortVal = messageReader.readUnsignedShort();
    * var charVal = messageReader.readChar();
    * var intVal = messageReader.readInt();
    * var longVal = messageReader.readLong();
    * var floatVal = messageReader.readFloat();
    * var doubleVal = messageReader.readDouble();
    * var str = messageReader.readUTF(); //includes 2-byte length count
    * var str = messageReader.readLine(); //read bytes until newline character is reached
    * var str = messageReader.readString(length); //without 2-byte length count
    */</task>
    </listener>
    <listener autostart="false" buttontype="toggle" connecthost="10.168.1.130" connectport="10540" delimiter="&lt;/mos&gt;" delimitertype="string" id="listener.10540" left="82" name="mos 10540" top="0"/>
    <param expand="true" height="533" left="66" oid="textinput" top="231" width="479"/>
    </abs>
    </abs>




    #DashBoard


  • 7.  RE: Catch mos message with null terminators from inception

    Posted 05-06-2020 21:04

    Ok, i got some progress, this one is working, but i needed to match messageParser.readString(470) length value manually, no one of the messageparser methods can provide me length value.. for some reason.. 

    <?xml version="1.0" encoding="UTF-8"?><abs contexttype="opengear" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" maxlength="0" name="textinput" oid="textinput" type="STRING" value="mos&gt;&#10;&lt;mosID&gt;VTR&lt;/mosID&gt;&#10;&lt;ncsID&gt;INCEPTION&lt;/ncsID&gt;&#10;&lt;messageID&gt;1&lt;/messageID&gt;&#10;&lt;roMetadataReplace&gt;&#10;&lt;roID&gt;5180&lt;/roID&gt;&#10;&lt;roSlug&gt;alexxx&lt;/roSlug&gt;&#10;&lt;roEdStart&gt;2020-05-06T12:02:41&lt;/roEdStart&gt;&#10;&lt;roEdDur&gt;07:59:59&lt;/roEdDur&gt;&#10;&lt;/roMetadataReplace&gt;&#10;&lt;/mos&gt;&#10;" widget="multiline-text"/>
    </params>
    </meta>
    <meta/>
    <abs height="898" left="4" top="3" width="1316">
    <meta>
    <context/>
    </meta>
    <listener autostart="false" blockingpause="true" bottom="860" buttontype="toggle" delimiter="2" delimitertype="fixedlen" id="listener.10541" left="0" listenport="10541" name="mos 10541" right="1232" top="0">
    <task tasktype="ogscript">if (event.isConnectEvent())
    {
    //ogscript.putObject('E', this);
    ogscript.debug("connect event..");
    }

    if (event.isMessageEvent())
    {
    //var utfStr = messageParser.readUTF();
    //var split = utfStr.split('NUL');
    var messageParser = ogscript.createMessageParser(this.getInputStream());
    var length = messageParser.readString(470);
    var split = length.split('NUL');
    params.setValue('textinput', 0, length); // put data on text entry

    ogscript.debug(length.length);
    ogscript.debug(split[3]);


    }




    /*
    * var byteArray = messageReader.readBytes(length);
    * messageReader.skipBytes(length);
    * var boolVal = messageReader.readBoolean();
    * var byteVal = messageReader.readByte();
    * var byteVal = messageReader.readUnsignedByte();
    * var shortVal = messageReader.readShort();
    * var shortVal = messageReader.readUnsignedShort();
    * var charVal = messageReader.readChar();
    * var intVal = messageReader.readInt();
    * var longVal = messageReader.readLong();
    * var floatVal = messageReader.readFloat();
    * var doubleVal = messageReader.readDouble();
    * var str = messageReader.readUTF(); //includes 2-byte length count
    * var str = messageReader.readLine(); //read bytes until newline character is reached
    * var str = messageReader.readString(length); //without 2-byte length count
    */</task>
    </listener>
    <listener autostart="false" buttontype="toggle" connecthost="10.168.1.130" connectport="10540" delimiter="&lt;/mos&gt;" delimitertype="string" id="listener.10540" left="82" name="mos 10540" top="0"/>
    <param expand="true" height="533" left="66" oid="textinput" top="231" width="479"/>
    </abs>
    </abs>

    #DashBoard


  • 8.  RE: Catch mos message with null terminators from inception

    Posted 05-07-2020 15:44

    Hi Alex

    The message parser does not currently have a UTF-16 read method (we may consider adding one in the future). Until then, you can manually-create the String by passing it the byte array and the "UTF-16" character encoding option:

    var str = new java.lang.String(event.getBytes(), "UTF-16");

    #DashBoard


  • 9.  RE: Catch mos message with null terminators from inception

    Posted 05-07-2020 17:24

    Thank you for testing,James.
    I will test it later. With that method, I'll still be able to got whole message if i'll use .getInputStream, with blocking pause?

     

    UDP: Ok, after a little playing with that, i understand that i need an fixed length delimiter, and there is no method to work with getInputStream if there is UTF16 strings.. So, need to collects those bytes together byte by byte. So, i guess, it would be a nice option as an future request to dashboard. Just when you will add that, dont forget the ability to construct UTF16 and fire it back, something like ogscript.stringType(str,"UTF16").

    Thanks!


    #DashBoard


  • 10.  RE: Catch mos message with null terminators from inception

    Posted 05-07-2020 22:00

    Hi Alex

    You would need all of your bytes collected into a byte array of some kind prior to building the string. If you use messageParser.readBytes(lengthCount), you can get your byte array directly from the listener input stream and pass that to the string constructor.


    #DashBoard


  • 11.  RE: Catch mos message with null terminators from inception

    Posted 05-07-2020 22:33

    I try to got the point.. i set up listener to 2 bytes length,so, i will recieve each character in its own listener event. So, the messageParser should be global, outside of the listener script? Otherwise it will collect only one character. I thought to write all characters to multiline text parameter ,and set up timer that if there is no change on that parameter for an 2 sec for example, it will change some flag parameter to 1 from 0, and in listener i will use if condition to that flag. So,if flag is 0 means ack message to the server doesnt sent yet, do nothing even if there is messageevent, else run the listener script..

    And, other question, i want now to send back ack message, so i built it byte by byte using messageBuilder, and using put/get object i can send the writeString messages. But i didnt find howto send writeBytes. How can i send byteArray back through the listener, that listens tcp "as server"?
    Thanks!


    #DashBoard


  • 12.  RE: Catch mos message with null terminators from inception

    Posted 05-11-2020 18:51

    You can probably get away without having to write byte-by-byte to a parameter. I would recommend pausing execution on first receive (one of the checkboxes in the listener editor) and loading the listener's input stream into the message parser. This would allow you to read your entire message in one task execution which would be more efficient.

    As for writing data back to the listener, you can find a lively discussion of this here:

    https://support.rossvideo.com/hc/en-us/community/posts/360062338471-sendTCPString-with-a-Listener

    You'll want to use writeBytes(BYTE_ARRAY) or writeAsBytes(BYTES_AS_HEX_STRING) to write your reply back to the listener's current connection.

     

    Cheers

    James


    #DashBoard


  • 13.  RE: Catch mos message with null terminators from inception

    Posted 05-11-2020 20:33

    Hello James, 

    I just created an panel with 2 listeners on port 10540 and 10541, and button for each listener that simulates the mos message - 10541 listener is collecting the message byte by byte - the 10540 tryes to collect the whole message. So, the 10540 doesnt work for some reason. 

    <?xml version="1.0" encoding="UTF-8"?><abs contexttype="opengear" gridsize="20" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" maxlength="0" name="textinput" oid="textinput" type="STRING" value="&lt;mos&gt;&lt;mosID&gt;VTR&lt;/mosID&gt;&lt;ncsID&gt;INCEPTION&lt;/ncsID&gt;&lt;messageID&gt;1&lt;/messageID&gt;&lt;roAck&gt;&lt;roID&gt;5180&lt;/roID&gt;&lt;/roAck&gt;&lt;/mos&gt;&lt;mos&gt;&lt;mosID&gt;VTR&lt;/mosID&gt;&lt;ncsID&gt;INCEPTION&lt;/ncsID&gt;&lt;messageID&gt;1&lt;/messageID&gt;&lt;roAck&gt;&lt;roID&gt;5180&lt;/roID&gt;&lt;/roAck&gt;&lt;/mos&gt;" widget="multiline-text"/>
    <param access="1" maxlength="0" name="textinput2" oid="textinput2" type="STRING" value="" widget="multiline-text"/>
    </params>
    </meta>
    <meta/>
    <abs height="898" left="4" scroll="vertical" top="3" width="1316">
    <meta>
    <context/>
    </meta>
    <listener autostart="false" blockingpause="true" bottom="840" buttontype="toggle" delimiter="2" delimitertype="fixedlen" left="600" listenport="10540" name="listener 10540" right="580" top="20">
    <task tasktype="ogscript">if (event.isMessageEvent())
    {
    var messageReader = ogscript.createMessageParser(this.getInputStream());
    var bytes = messageReader.readByte();
    var str = new java.lang.String(bytes, "UTF-16");
    params.setValue('textinput2', 0, params.getValue('textinput2', 0) + str); // put data on text entry

    }

    </task>
    </listener>
    <listener autostart="false" bottom="840" buttontype="toggle" delimiter="2" delimitertype="fixedlen" id="listener.10541" left="100" listenport="10541" name="listener 10541" right="1060" top="20">
    <task tasktype="ogscript">if (event.isMessageEvent())
    {

    var str = new java.lang.String(event.getBytes(), "UTF-16");
    params.setValue('textinput', 0, params.getValue('textinput', 0) + str); // put data on text entry

    }</task>
    </listener>
    <param expand="true" height="540" left="60" oid="textinput" scroll="vertical" top="240" width="340"/>
    <button buttontype="push" height="60" left="100" name="message to 10541" top="60" width="140">
    <task tasktype="ogscript">rosstalk.sendAsBytes('localhost', 10541,'003c006d006f0073003e003c006d006f007300490044003e005600540052003c002f006d006f007300490044003e003c006e0063007300490044003e0049004e00430045005000540049004f004e003c002f006e0063007300490044003e003c006d00650073007300610067006500490044003e0031003c002f006d00650073007300610067006500490044003e003c0072006f00410063006b003e003c0072006f00490044003e0035003100380030003c002f0072006f00490044003e003c002f0072006f00410063006b003e003c002f006d006f0073003e',null);</task>
    </button>
    <button buttontype="push" height="100" left="400" name="reset log" top="680" width="100">
    <task tasktype="ogscript">params.setValue('textinput', 0, '');
    params.setValue('textinput2', 0, '');</task>
    </button>
    <label height="40" left="80" name="listener1 - byte by byte collection- port 10541" style="txt-align:west;" top="200" width="340"/>
    <param expand="true" height="540" left="500" oid="textinput2" top="240" width="340"/>
    </abs>
    <button buttontype="push" height="60" left="600" name="message to 10540" top="60" width="140">
    <task tasktype="ogscript">rosstalk.sendAsBytes('localhost', 10540,'003c006d006f0073003e003c006d006f007300490044003e005600540052003c002f006d006f007300490044003e003c006e0063007300490044003e0049004e00430045005000540049004f004e003c002f006e0063007300490044003e003c006d00650073007300610067006500490044003e0031003c002f006d00650073007300610067006500490044003e003c0072006f00410063006b003e003c0072006f00490044003e0035003100380030003c002f0072006f00490044003e003c002f0072006f00410063006b003e003c002f006d006f0073003e',null);</task>
    </button>
    <label height="40" left="520" name="listener2 - try to collect whole message- port 10541" style="txt-align:west;" top="200" width="340"/>
    </abs>

    #DashBoard


  • 14.  RE: Catch mos message with null terminators from inception

    Posted 05-11-2020 20:46

    Hi Alex

    The problem is that you are using readByte instead of readBytes(len). Here is a modified version of your code that would work:

    <listener autostart="false" blockingpause="true" bottom="840" buttontype="toggle" delimiter="2" delimitertype="fixedlen" left="600" listenport="10540" name="listener 10540" right="580" top="20">
    <task tasktype="ogscript">if (event.isMessageEvent())
    {
    var totalString = new java.lang.String(event.getBytes(), "UTF-16");
    var messageReader = ogscript.createMessageParser(this.getInputStream());
    while (totalString.indexOf('&lt;/mos&gt;') &lt; 0)
    {
    totalString += new java.lang.String(messageReader.readBytes(2), "UTF-16");
    }
    params.setValue('textinput2', 0, params.getValue('textinput2', 0) + totalString); // put data on text entry
    }</task>
    </listener>

     

    That said, I have run your test output through another version of the listener that just listens for the UTF-16 bytes for "</mos>" and it seems to work. Here is that version:

    <listener autostart="false" blockingpause="true" buttontype="toggle" delimiter="003C002F006D006F0073003E" delimitertype="bytes" height="40" left="760" listenport="10540" name="listener 2 10540" top="20" width="140">
    <task tasktype="ogscript">if (event.isMessageEvent())
    {
    var totalString = new java.lang.String(event.getBytes(), "UTF-16") + "&lt;/mos&gt;";
    params.setValue('textinput2', 0, params.getValue('textinput2', 0) + totalString); // put data on text entry
    }</task>
    </listener>

    Cheers

    James


    #DashBoard


  • 15.  RE: Catch mos message with null terminators from inception

    Posted 05-11-2020 20:59

    Ohhh..

    The option with the delimiter is preferred of course..  I feel foolishly with myself now..

    Thank you, as always, for you help.

    Alex.  


    #DashBoard


  • 16.  RE: Catch mos message with null terminators from inception

    Posted 05-11-2020 21:29

    Now i have a little trouble, i got the utf16 characters of hebrew letters instead the hebrew letter itself.. 

    Something like this:

    <roSlug> 10.5.20 &#1508;&#1493;&#1514;&#1495;&#1497;&#1501; &#1497;&#1493;&#1501;</roSlug>

    Now, on UTF16 table i see that those numbers is the letters in hebrew.. 

    So i need to use String.fromCharCode(1508,1493) etc i guess and exclude it from the string?

    Or maybe is there simplier way to achieve that?

     


    #DashBoard


  • 17.  RE: Catch mos message with null terminators from inception

    Posted 05-12-2020 15:36

    You can use DashBoard's XML parsing capabilities once you have your string:

    var xml = ogscript.parseXML('<roSlug> 10.5.20 &#1508;&#1493;&#1514;&#1495;&#1497;&#1501; &#1497;&#1493;&#1501;</roSlug>');
    ogscript.debug(xml.getDocumentElement().getTextContent());

    Cheers

    James


    #DashBoard