use of com.neuronrobotics.sdk.common.MACAddress 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.MACAddress in project java-bowler by NeuronRobotics.
the class BowlerAbstractServer method pushAsyncPacket.
/**
* THis is the scripting interface to Bowler devices. THis allows a user to
* describe a namespace, rpc, and array or arguments to be paced into the
* packet based on the data types of the argument. The response in likewise
* unpacked into an array of objects.
*
* @param namespace
* The string of the desired namespace
* @param rpcString
* The string of the desired RPC
* @param arguments
* An array of objects corresponding to the data to be stuffed
* into the packet.
* @throws DeviceConnectionException
* If the desired RPC's are not available then this will be
* thrown
*/
public void pushAsyncPacket(int namespaceIndex, String namespace, String rpcString, Object[] arguments, BowlerDataType[] asyncArguments) {
if (arguments.length != asyncArguments.length) {
throw new RuntimeException("Arguments must match argument types exactly, your two arrays are different lengths");
}
RpcEncapsulation rpcl = new RpcEncapsulation(namespaceIndex, namespace, rpcString, BowlerMethod.ASYNCHRONOUS, asyncArguments, null, null);
BowlerAbstractCommand command = BowlerAbstractConnection.getCommand(namespace, BowlerMethod.ASYNCHRONOUS, rpcString, arguments, rpcl);
BowlerDatagram cmd = BowlerDatagramFactory.build(new MACAddress(), command);
Log.debug("Async>>" + cmd);
pushAsyncPacket(cmd);
}
use of com.neuronrobotics.sdk.common.MACAddress in project java-bowler by NeuronRobotics.
the class PidDeviceServer method main.
public static void main(String[] args) {
Log.enableInfoPrint();
PidDeviceServer srv = new PidDeviceServer(new MACAddress(), new VirtualGenericPIDDevice(10000));
}
use of com.neuronrobotics.sdk.common.MACAddress in project java-bowler by NeuronRobotics.
the class BowlerDatagramFactoryTests method test.
@Test
public void test() {
// Must be a factor of default pool size
int testBifferSize = 10 * BowlerDatagramFactory.getDefaultPoolSize();
ArrayList<BowlerDatagram> myList = new ArrayList<BowlerDatagram>();
// verify initial state
if (BowlerDatagramFactory.getCurrentPoolSize() != BowlerDatagramFactory.getDefaultPoolSize()) {
fail();
}
for (int i = 0; i < testBifferSize; i++) {
myList.add(BowlerDatagramFactory.build(new MACAddress(), new PingCommand()));
}
for (BowlerDatagram b : myList) {
if (b.isFree()) {
// if any packets not marked as allocated
fail();
}
// System.out.println(b);
}
// wait for packets to timeout
ThreadUtil.wait((int) ((double) BowlerDatagramFactory.getPacketTimeout()) / 2);
for (BowlerDatagram b : myList) {
if (b.isFree())
// if any packets not marked as free too soon
fail();
// System.out.println(b);
}
// wait for packets to timeout
ThreadUtil.wait((int) ((double) BowlerDatagramFactory.getPacketTimeout()));
for (BowlerDatagram b : myList) {
if (!b.isFree())
// any packets that failed to timeout
fail();
}
// refill the array
myList.clear();
for (int i = 0; i < testBifferSize; i++) {
myList.add(BowlerDatagramFactory.build(new MACAddress(), new PingCommand()));
}
for (BowlerDatagram b : myList) {
if (b.isFree())
// if any packets not marked as before freeing
fail();
BowlerDatagramFactory.freePacket(b);
if (!b.isFree())
// if any packets not marked as free after freeing it
fail();
}
}
use of com.neuronrobotics.sdk.common.MACAddress in project java-bowler by NeuronRobotics.
the class PacketValidationTest method packetTest.
@Test
public void packetTest() {
Log.enableInfoPrint();
BowlerDatagram bd = BowlerDatagramFactory.build(new MACAddress(), new PingCommand());
System.out.println(bd);
ByteList data = new ByteList(bd.getBytes());
System.out.println(data);
BowlerDatagram back = BowlerDatagramFactory.build(data);
if (back == null)
fail();
System.out.println(back);
}
Aggregations