package de.diesner.ehzlogger;

import java.io.IOException;
import java.util.List;

import gnu.io.PortInUseException;
import gnu.io.UnsupportedCommOperationException;
import org.openmuc.jsml.structures.*;
import org.openmuc.jsml.tl.SML_SerialReceiver;

public class EhzLogger {

    public static void main(String[] args) throws IOException, PortInUseException, UnsupportedCommOperationException {
        System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyUSB0");
        final SML_SerialReceiver receiver = new SML_SerialReceiver();
        receiver.setupComPort("/dev/ttyUSB0");

        Runtime.getRuntime().addShutdownHook(new Thread()
        {
            public void run()
            {
                try {
                    receiver.close();

                } catch (IOException e) {
                    System.err.println("Error while trying to close serial port: " + e.getMessage());
                }
            }
        });

        SmlForwarder forwarder = new CmdLinePrint();

        while (true) {

            SML_File smlFile = receiver.getSMLFile();
            System.out.println("Got SML_File");

            forwarder.messageReceived(smlFile.getMessages());
        }
    }

}

@@ -28,60 +28,8 @@
 r;%0A%0A
-import java.io.IOException;%0Aimport java.util.List;%0A%0A
 impo
@@ -146,9 +146,16 @@
 res.
-*
+SML_File
 ;%0Aim
@@ -200,16 +200,96 @@
 eiver;%0A%0A
+import java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 public c
@@ -984,16 +984,21 @@
         
+List%3C
 SmlForwa
@@ -1001,16 +1001,17 @@
 orwarder
+%3E
  forward
@@ -1016,28 +1016,187 @@
 rder
+List
  = new 
-CmdLinePrint(
+ArrayList%3C%3E();%0A        forwarderList.add(new CmdLinePrint());%0A        forwarderList.add(new InfluxDbForward(%22http://localhost:8086/write?db=home&precision=ms%22, %22strom%22)
 );%0A%0A
@@ -1218,17 +1218,16 @@
 true) %7B%0A
-%0A
         
@@ -1288,45 +1288,59 @@
     
-System.out.println(%22Got SML_File%22);%0A%0A
+for (SmlForwarder forwarder : forwarderList) %7B%0A    
     
@@ -1393,24 +1393,38 @@
 essages());%0A
+            %7D%0A
         %7D%0A  

Add multiple data forwarder