use of com.neuronrobotics.sdk.network.BowlerTCPClient in project BowlerStudio by CommonWealthRobotics.
the class TestServer method main.
public static void main(String[] args) throws Exception {
class SampleBowlerServer extends BowlerAbstractServer {
BowlerAbstractDeviceServerNamespace ns = new BowlerAbstractDeviceServerNamespace(getMacAddress(), "test.thingy.*;0.3;;") {
};
public SampleBowlerServer() {
super(new MACAddress());
ns.addRpc(new RpcEncapsulation(ns.getNamespaceIndex(), ns.getNamespace(), "test", BowlerMethod.GET, new BowlerDataType[] { BowlerDataType.I32, BowlerDataType.I32, // send 3
BowlerDataType.I32 }, // integers
BowlerMethod.POST, new BowlerDataType[] { BowlerDataType.I32, BowlerDataType.I32, // get 3 integers back
BowlerDataType.I32 }, new IBowlerCommandProcessor() {
public Object[] process(Object[] data) {
for (int i = 0; i < data.length; i++) {
System.out.println("Server Got # " + data[i]);
}
return new Object[] { 37, 42, 999999 };
}
}));
addBowlerDeviceServerNamespace(ns);
Log.info("Starting UDP");
try {
startNetworkServer(1865);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// starts the UDP server
// this also starts tcp server on port+1, in this case 1866
}
}
class SampleBowlerClient extends BowlerAbstractDevice {
public void runCommand() {
Object[] args = send("test.thingy.*;0.3;;", BowlerMethod.GET, "test", // send some numbers
new Object[] { 36, 83, 13 });
for (int i = 0; i < args.length; i++) {
System.out.println("Client Received # " + args[i]);
}
}
@Override
public void onAsyncResponse(BowlerDatagram data) {
}
// no async in this demo
}
SampleBowlerClient client = new SampleBowlerClient();
// client.setConnection(new UDPBowlerConnection(InetAddress.getByName("127.0.0.1"), 1865));
// Alternately you can use the tcp connection
client.setConnection(new BowlerTCPClient("127.0.0.1", 1866));
DeviceManager.addConnection(client, "sampleClient");
// runs our test command from client to server and
client.runCommand();
// back
}
use of com.neuronrobotics.sdk.network.BowlerTCPClient 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;
}
use of com.neuronrobotics.sdk.network.BowlerTCPClient in project java-bowler by NeuronRobotics.
the class GenericPIDTest method main.
/**
* @param args
*/
public static void main(String[] args) {
Log.enableDebugPrint();
GenericPIDDevice pid = new GenericPIDDevice();
// }
try {
try {
pid.setConnection(new BowlerTCPClient("cortex.wpi.edu", 1965));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// pid.setConnection(new BowlerTCPClient("192.168.0.134", 1965));
pid.GetAllPIDPosition();
pid.GetPIDPosition(2);
pid.disconnect();
System.out.println("All OK!");
System.exit(0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
pid.disconnect();
System.exit(1);
}
}
use of com.neuronrobotics.sdk.network.BowlerTCPClient in project java-bowler by NeuronRobotics.
the class TCPConnectionPanel method getConnection.
@Override
public BowlerAbstractConnection getConnection() {
if (clnt == null) {
try {
int thePort = Integer.parseInt(port.getText());
if (thePort < 0) {
throw new NumberFormatException();
}
String address = connectionCbo.getSelectedItem().toString();
Log.info("Connecting on: " + address + ":" + thePort);
clnt = new BowlerTCPClient(address, thePort);
setVisible(false);
return clnt;
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Invalid port given.", "Invalid port", JOptionPane.ERROR_MESSAGE);
} catch (RuntimeException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Invalid address given.", "Invalid address", JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Invalid address given.", "Invalid address", JOptionPane.ERROR_MESSAGE);
} finally {
setVisible(false);
}
return null;
}
return clnt;
}
Aggregations