package amos.doip.helper;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.LinkedList;
import java.util.List;

public class DoipMessageGenerator {

    public static final Charset ASCII = Charset.forName("US-ASCII");

    private static DoipMessage[] dmsgs = {
        /* 0 - Generic doip header negative acknowledge */
        new DoipMessage(0, new byte[]{0}),
        new DoipMessage(0, new byte[]{1}),
        new DoipMessage(0, new byte[]{2}),
        new DoipMessage(0, new byte[]{3}),
        new DoipMessage(0, new byte[]{4}),
        new DoipMessage(0, new byte[]{5}),
        new DoipMessage(0, new byte[]{(byte)0xFF}),


        /* 0x0001 - Vehicle identification request message */
        new DoipMessage(1, new byte[]{0x0}),

        /* 0x0002 - vehicle identification request message with EID */
        new DoipMessage(2, new byte[]{0x00, 0x11, 0x22, 0x33, 0x44, 0x55}),

        /* 0x0003 - vehicle identification request message with VIN */
        //new DoipMessage(3, "Hallo Welt!".getBytes(ASCII)),
        new DoipMessage(3, "12345678901234567".getBytes(ASCII)),
        new DoipMessage(3, new byte[]{'1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7'}),



        /* 0x8001 - */
        new DoipMessage(0x8001, new byte[]{0x03, (byte)0x80, (byte)0xe4,0x00, 0x3e, (byte)0x80})
    };
        
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        List<byte[]> msgs = new LinkedList<byte[]>();
        for(DoipMessage dmsg : dmsgs){
            msgs.add(dmsg.toByteArray());
        }
        
        
        try {
            DoipServer serverImpl = new DoipServer();
            Thread server = new Thread(serverImpl);
            Thread client = new Thread(new DoipClient("localhost" ,13400, msgs));
            
            server.start();
            client.start();
        
            
            client.join();
            Thread.sleep(300);
            serverImpl.close();
            server.join();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

@@ -81,16 +81,44 @@
 harset;%0A
+import java.util.ArrayList;%0A
 import j
@@ -1102,156 +1102,1289 @@
 (3, 
-%2212345678901234567%22.getBytes(ASCII)),%0A        new DoipMessage(3, new byte%5B%5D%7B'1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7'%7D),%0A%0A
+new byte%5B%5D%7B'1','2','3','4','5','6','7','8','9','0','1','2','3','4','5',0,0%7D),%0A        new DoipMessage(3, %2212345678901234567%22.getBytes(ASCII)),%0A        new DoipMessage(3, %22123456789012345678%22.getBytes(ASCII)),%0A%0A        /* 0x0004 - vehicle announcement/vehicle identification response message */%0A        new DoipMessage(4, new byte%5B%5D%7B%0A            /* VIN */%0A            '1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7',%0A            /* Logical address */ %0A            (byte) 0x13, (byte)0x37,%0A            /* EID */%0A            0x00, 0x11, 0x22, 0x33, 0x44, 0x55,%0A            /* GID */%0A            (byte) 0xFF, (byte)0xEE, (byte) 0xDD, (byte) 0xCC, (byte) 0xBB, (byte) 0xAA,%0A            /* Further action required */%0A            0x00%0A        %7D),%0A        new DoipMessage(4, new byte%5B%5D%7B%0A            /* VIN */%0A            '1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7',%0A            /* Logical address */ %0A            (byte) 0x13, (byte)0x37,%0A            /* EID */%0A            0x00, 0x11, 0x22, 0x33, 0x44, 0x55,%0A            /* GID */%0A            (byte) 0xFF, (byte)0xEE, (byte) 0xDD, (byte) 0xCC, (byte) 0xBB, (byte) 0xAA,%0A            /* Further action required */%0A            0x00,%0A            /* VIN/GID sync status */%0A            0x00%0A        %7D),
 %0A%0A  
@@ -2605,16 +2605,17 @@
 od stub%0A
+%0A
         

I have implemented example messages for payload type 3 + 4. issue #9