Merge XBee api fragments from serial port
<p>I try to merge the fragments of a packet I receive by my Xbee (802.15.4) in API mode througth my RS-232 serial port. I get my fragment with the readBytes method from the jssc library for java.</p>

<p>Here is my reception code</p>

<pre><code>    private static class PortReader implements SerialPortEventListener {

    @Override
    public void serialEvent(SerialPortEvent event) {
        if(event.isRXCHAR() &amp;&amp; event.getEventValue() &gt; 0) {
            try {
                byte[] receivedData = serialPort.readBytes(event.getEventValue());
                if(Utils.isConfirmPacket(Utils.toHex(receivedData))){
                    System.out.println("XBee confim that msg is sent!");
                }else{
                    System.out.println("Received response from port: " + Utils.toHex(receivedData));
                    int dataLength = Utils.toHex(receivedData).length();
                    receiveFile("testRx", receivedData, dataLength);
                }

            }
            catch (SerialPortException ex) {
                System.out.println("Error in receiving response from port: " + ex);
            }
        }
    }
</code></pre>

<p>My receiveFile() method need the full packet in one fragment. Here is what I get in my console:</p>

<pre><code>Received response from port: 7e003c8100013200
Received response from port: 2000123200ff1200
Received response from port: 0001000500000000
Received response from port: 0000000020000000
Received response from port: 1251000012455222
Received response from port: 446174613a206365
Received response from port: 6369206573742075
Received response from port: 6e20746573743b90
</code></pre>

<p>Since I'm using the API mode, I have not been able to send an end delimiter to specified the end of the packet like I saw in other solutions (<a href="https://stackoverflow.com/questions/28691742/read-complete-line-java-serial-port">Read Complete Line Java Serial Port</a>).</p>

<p>I was thinking of using the start delimiter of the next packet, but it didn't worked out.</p>