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;
}
Aggregations