use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class CounterOutputChannel method setValue.
/* (non-Javadoc)
* @see com.neuronrobotics.sdk.dyio.peripherals.DyIOAbstractPeripheral#setValue(int)
*/
public boolean setValue(int value) {
Log.info("Setting counter set point");
ByteList b = new ByteList();
b.addAs32(value);
return setValue(b);
}
use of com.neuronrobotics.sdk.common.ByteList 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.ByteList in project java-bowler by NeuronRobotics.
the class DyIO method powerEvent.
/**
* Parses a datagram into the power event data
* @param data
*/
private void powerEvent(BowlerDatagram data) {
// Log.warning("POWER event "+data);
if (data.getRPC().contains("_pwr")) {
ByteList bl = data.getData();
if (isLegacyParser() && bl.size() == 1) {
enableBrownOut = bl.get(0) != 0;
}
if (bl.size() > 1) {
batteryVoltage = ((double) (ByteList.convertToInt(bl.getBytes(2, 2), false))) / 1000.0;
bankAState = DyIOPowerState.valueOf(bl.get(0), batteryVoltage);
bankBState = DyIOPowerState.valueOf(bl.get(1), batteryVoltage);
if (!isLegacyParser()) {
enableBrownOut = bl.get(4) != 0;
}
}
fireDyIOEvent(new DyIOPowerEvent(bankAState, bankBState, batteryVoltage));
return;
} else {
Log.error("Wrong type for updating Power state " + data);
}
}
use of com.neuronrobotics.sdk.common.ByteList 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.ByteList in project java-bowler by NeuronRobotics.
the class DyIOChannel method getValue.
/* (non-Javadoc)
* @see com.neuronrobotics.sdk.dyio.IDyIOChannel#getValue()
*/
public int getValue() {
int val = 0;
if (getDevice().isLegacyParser()) {
BowlerDatagram response = null;
try {
response = getDevice().send(new GetValueCommand(number));
} catch (InvalidResponseException e) {
response = getDevice().send(new GetValueCommand(number));
}
ByteList bl = response.getData();
Byte b = bl.pop();
if (b == null || b.intValue() != number) {
Log.error("Failed to get value " + response);
return 0;
}
val = new DyIOChannelEvent(this, bl).getValue();
setCachedValue(val);
setPreviousValue(val);
} else {
// Object [] args =getDevice().send("bcs.io.*;0.3;;",
// BowlerMethod.GET,
// "gchv",
// new Object[]{number});
// val=(Integer)args[1];
// Log.debug("Got Value: "+val);
// For the new API the channel values should come in through the asynchronous path.
val = getPreviousValue();
}
return val;
}
Aggregations