use of com.neuronrobotics.sdk.common.BowlerDatagram 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.common.BowlerDatagram in project BowlerStudio by CommonWealthRobotics.
the class RpcCommandPanel method actionPerformed.
@Override
public void actionPerformed(ActionEvent arg0) {
Object[] values = new Object[tx.size()];
for (int i = 0; i < values.length; i++) {
if (rpc.getDownstreamArguments()[i] == BowlerDataType.ASCII)
values[i] = tx.get(i).getText();
else
values[i] = Integer.parseInt(tx.get(i).getText());
}
BowlerDatagram bd = device.send(rpc.getCommand(values));
rxRpc.setText(bd.getRPC());
Object[] up = rpc.parseResponse(bd);
for (int i = 0; i < up.length; i++) {
if (up[i] != null)
rx.get(i).setText(up[i].toString());
else {
rx.get(i).setText("Null");
}
}
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class LegacyPidNamespaceImp method getPIDConfiguration.
@Override
public /* (non-Javadoc)
* @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#getPIDConfiguration
*/
PIDConfiguration getPIDConfiguration(int group) {
BowlerDatagram conf = getDevice().send(new ConfigurePIDCommand((char) group));
PIDConfiguration back = new PIDConfiguration(conf);
return back;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class LegacyPidNamespaceImp method ResetPIDChannel.
/* (non-Javadoc)
* @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#ResetPIDChannel
*/
@Override
public boolean ResetPIDChannel(int group, int valueToSetCurrentTo) {
BowlerDatagram rst = getDevice().send(new ResetPIDCommand((char) group, valueToSetCurrentTo));
if (rst == null)
return false;
int val = GetPIDPosition(group);
firePIDResetEvent(group, val);
return true;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class LegacyPidNamespaceImp method GetAllPIDPosition.
@Override
public int[] GetAllPIDPosition() {
Log.debug("Getting All PID Positions");
BowlerDatagram b = getDevice().send(new ControlAllPIDCommand());
ByteList data = b.getData();
int[] back = new int[data.size() / 4];
for (int i = 0; i < back.length; i++) {
int start = i * 4;
byte[] tmp = data.getBytes(start, 4);
back[i] = ByteList.convertToInt(tmp, true);
}
if (back.length != getNumberOfChannels()) {
lastPacketTime = new long[back.length];
for (int i = 0; i < back.length; i++) {
PIDChannel c = new PIDChannel(this, i);
c.setCachedTargetValue(back[i]);
getChannels().add(c);
}
}
return back;
}
Aggregations