Search in sources :

Example 1 with UDPBowlerConnection

use of com.neuronrobotics.sdk.network.UDPBowlerConnection in project java-bowler by NeuronRobotics.

the class ConfigManager method loadDefaultConnection.

public static BowlerAbstractConnection loadDefaultConnection(String filename) {
    try {
        File file = new File(filename);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(file);
        doc.getDocumentElement().normalize();
        NodeList nodeLst = doc.getElementsByTagName("connection");
        for (int s = 0; s < nodeLst.getLength(); s++) {
            Node fstNode = nodeLst.item(s);
            if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
                Element e = (Element) fstNode;
                String type = getElementValue(e, "type", "");
                String port = getElementValue(e, "port", "");
                String baud = getElementValue(e, "baud", "0");
                String host = getElementValue(e, "host", "127.0.0.1");
                if (type.equalsIgnoreCase("serial")) {
                // return new SerialConnection(port, Integer.parseInt(baud));
                }
                if (type.equalsIgnoreCase("udp")) {
                    return new UDPBowlerConnection(Integer.parseInt(port));
                }
                if (type.equalsIgnoreCase("tcp")) {
                    return new BowlerTCPClient(host, Integer.parseInt(port));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) UDPBowlerConnection(com.neuronrobotics.sdk.network.UDPBowlerConnection) Document(org.w3c.dom.Document) File(java.io.File) BowlerTCPClient(com.neuronrobotics.sdk.network.BowlerTCPClient)

Aggregations

BowlerTCPClient (com.neuronrobotics.sdk.network.BowlerTCPClient)1 UDPBowlerConnection (com.neuronrobotics.sdk.network.UDPBowlerConnection)1 File (java.io.File)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1