use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class BowlerUDPServer method loadPacketFromPhy.
@Override
public BowlerDatagram loadPacketFromPhy(ByteList bytesToPacketBuffer) throws NullPointerException, IOException {
byte[] receiveData = new byte[4096];
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
Log.info("Waiting for UDP packet");
try {
udpSock.receive(receivePacket);
} catch (SocketException ex) {
// disconnect called
Log.warning("Receive bailed out because of close");
return null;
}
IPAddressSet = (receivePacket.getAddress());
destinationPort = receivePacket.getPort();
Log.info("Got UDP packet from " + IPAddressSet + " : " + destinationPort);
byte[] data = receivePacket.getData();
for (int i = 0; i < receivePacket.getLength(); i++) {
internalReceiveBuffer.add(data[i]);
}
BowlerDatagram bd = null;
while (internalReceiveBuffer.size() > 0) {
bytesToPacketBuffer.add(internalReceiveBuffer.pop());
if (bd == null) {
bd = BowlerDatagramFactory.build(bytesToPacketBuffer);
}
}
return bd;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class DyIO method getAvailibleChannelModes.
public ArrayList<DyIOChannelMode> getAvailibleChannelModes(int channel) {
ArrayList<DyIOChannelMode> modes = new ArrayList<DyIOChannelMode>();
ByteList m;
if (isLegacyParser()) {
BowlerDatagram dg = send(new GetChannelModeListCommand(channel));
m = dg.getData();
Log.error("Packet " + channel + "\r\n" + dg);
Log.error("Data: " + channel + "\r\n" + m);
} else {
// int l = Log.getMinimumPrintLevel();
// Log.enableInfoPrint();
Object[] args = send("bcs.io.*;0.3;;", BowlerMethod.GET, "gcml", new Object[] { channel });
m = (ByteList) args[0];
// Log.setMinimumPrintLevel(l);
}
String modeString = " Availible modes on " + channel;
for (int i = 0; i < m.size(); i++) {
DyIOChannelMode tmpMode = DyIOChannelMode.get(m.getByte(i));
modeString += "\r\n\t" + tmpMode.toString() + "\r\n\t";
modes.add(tmpMode);
}
Log.info(modeString);
return modes;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class DyIO method getAllChannelValues.
/**
* Gets the values of all channels as an array
* @return the values of all non stream arrays.
*/
public int[] getAllChannelValues() {
int[] back = new int[getInternalChannels().size()];
if (isLegacyParser()) {
BowlerDatagram gacv = send(new GetAllChannelValuesCommand());
Log.info("GACV RX<<\n" + gacv);
ByteList bl = gacv.getData();
int i = 0;
for (DyIOChannel c : getChannels()) {
if (!c.isStreamChannel()) {
ByteList val = new ByteList(bl.popList(4));
DyIOChannelEvent ev = new DyIOChannelEvent(c, val);
back[i++] = ev.getValue();
if (!c.isStreamChannel()) {
c.fireChannelEvent(ev);
}
} else {
back[i++] = 0;
}
}
} else {
// Log.enableInfoPrint();
Object[] args = send("bcs.io.*;0.3;;", BowlerMethod.GET, "gacv", new Object[] {});
Integer[] values = (Integer[]) args[0];
for (int i = 0; i < getChannels().size(); i++) {
DyIOChannel c = getChannels().get(i);
if (!c.isStreamChannel()) {
DyIOChannelEvent ev = new DyIOChannelEvent(c, values[i]);
back[i] = values[i];
if (!c.isStreamChannel()) {
c.fireChannelEvent(ev);
}
}
}
}
return back;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class DyIO method getBatteryVoltage.
/**
* THis method will return the current voltage on the battery connected to the DyIO external power connector.
* @param refresh true if you want to query the device, false to just get the cached value from the last async.
* @return the voltage of the battery in Volts
*/
public double getBatteryVoltage(boolean refresh) {
if (refresh) {
BowlerDatagram data = send(new PowerCommand());
powerEvent(data);
}
return batteryVoltage;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class DyIO method getDyIOChannelCount.
public Integer getDyIOChannelCount() {
if (dyioChanCount == null) {
if (isLegacyParser()) {
try {
BowlerDatagram dg = send(new GetDyIOChannelCountCommand());
dyioChanCount = ByteList.convertToInt(dg.getData().getBytes(0, 4));
} catch (InvalidResponseException ex) {
ex.printStackTrace();
}
} else {
Object[] args = send("bcs.io.*;0.3;;", BowlerMethod.GET, "gchc", new Object[] {});
dyioChanCount = (Integer) args[0];
}
}
return dyioChanCount;
}
Aggregations