use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class DyIOChannel method flush.
/**
* This method performs a single channel flush. This method will take the cached value, or the current value if none were cached, and
* send it to the device.
* @return true if success
*/
public boolean flush() {
// if(getCachedMode())
// throw new RuntimeException("In chached mode and flushing from channel");
// Log.enableDebugPrint(true);
Log.info("Flushing channel: " + number);
if (getDevice().isLegacyParser()) {
ByteList b = new ByteList();
switch(getMode()) {
case COUNT_IN_INT:
case COUNT_IN_DIR:
case COUNT_IN_HOME:
case COUNT_OUT_INT:
case COUNT_OUT_DIR:
case COUNT_OUT_HOME:
b.addAs32(getCachedValue());
b.addAs32((int) (getCachedTime() * 1000));
break;
case SERVO_OUT:
b.add(getCachedValue());
b.addAs16((int) (getCachedTime() * 1000));
break;
default:
b.add(getCachedValue());
}
Log.info("Setting channel: " + getChannelNumber() + " to value: " + b);
boolean back = setValue(b);
// Log.enableDebugPrint(false);
return back;
} else {
// Log.info("Setting channel: "+number+" to value: "+getCachedValue());
getDevice().send("bcs.io.*;0.3;;", BowlerMethod.POST, "schv", new Object[] { number, getCachedValue(), (int) (getCachedTime() * 1000) });
return true;
}
}
use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class NRBootLoader method write.
public boolean write(int core, ByteData flashData) {
BowlerDatagram b = null;
for (int i = 0; i < 10; i++) {
try {
b = send(new ProgramSectionCommand(core, (int) flashData.getStartAddress(), new ByteList(flashData.getData())));
} catch (Exception e) {
e.printStackTrace();
b = null;
}
if (b != null) {
if (!b.getRPC().contains("_err"))
return true;
}
}
System.err.println("\nFailed to send 10 times!\n");
return false;
}
use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class BowlerCamDevice method onAsyncResponse.
public void onAsyncResponse(BowlerDatagram data) {
if (data.getRPC().contains("_img")) {
ByteList d = data.getData();
int camera = ByteList.convertToInt(d.popList(2));
int index = ByteList.convertToInt(d.popList(2));
int total = ByteList.convertToInt(d.popList(2));
byte[] imgData = d.popList(d.size());
Log.info("Got image chunk\n" + data + "\nindex: " + index + ", total: " + total + ", len: " + imgData.length);
synchronized (tmp) {
tmp.add(imgData);
}
if (index == (total)) {
// //System.out.println("Making image");
BufferedImage image = null;
try {
synchronized (tmp) {
image = ByteArrayToImage(tmp.getBytes());
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
image = null;
}
synchronized (tmp) {
tmp.clear();
}
images.set(camera, image);
fireIWebcamImageListenerEvent(camera, images.get(camera));
// System.out.println("Image OK");
}
}
if (data.getRPC().contains("blob")) {
int x = ByteList.convertToInt(data.getData().getBytes(0, 4));
int y = ByteList.convertToInt(data.getData().getBytes(4, 4));
int r = ByteList.convertToInt(data.getData().getBytes(8, 4));
if (x == 0 && y == 0 && r == 0) {
gotLastMark = true;
return;
}
mark.add(new ItemMarker(x, y, r));
}
}
use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class HokuyoURGDevice method connectDeviceImp.
@Override
public boolean connectDeviceImp() {
serial.connect();
ins = new DataInputStream(serial.getInputStream());
outs = new DataOutputStream(serial.getOutputStream());
receive = new Thread() {
public void run() {
setName("HokuyoURGDevice updater");
ByteList bl = new ByteList();
// System.out.println("Starting listener");
while (run && !Thread.interrupted()) {
try {
if (ins.available() > 0) {
while (ins.available() > 0 && run && !Thread.interrupted()) {
int b = ins.read();
if (b == 10 && bl.get(bl.size() - 1) == 10) {
if (bl.size() > 0) {
try {
URG2Packet p = new URG2Packet(new String(bl.getBytes()));
Log.debug("New Packet: \n" + p);
setPacket(p);
bl = new ByteList();
} catch (Exception ex) {
setPacket(null);
// System.out.println("Unknown packet");
// ex.printStackTrace();
}
}
} else {
bl.add(b);
}
ThreadUtil.wait(1);
}
} else {
}
} catch (Exception e) {
// e.printStackTrace();
run = false;
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
run = false;
}
}
done = true;
}
};
clear();
receive.start();
return serial.isConnected();
}
use of com.neuronrobotics.sdk.common.ByteList 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