use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.
the class CustomBolusBlock method getData.
@Override
public byte[] getData() {
ByteBuf byteBuf = new ByteBuf(14);
byteBuf.putShort(bolusType.getValue());
byteBuf.putUInt16LE(Helpers.roundDoubleToInt(immediateAmount * 100D));
byteBuf.putUInt16LE(Helpers.roundDoubleToInt(extendedAmount * 100D));
byteBuf.putShort((short) 0x0000);
byteBuf.putUInt16LE(duration);
byteBuf.putBoolean(configured);
return byteBuf.getBytes();
}
use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.
the class ReadStatusParamBlockMessage method getData.
@Override
protected byte[] getData() throws Exception {
ByteBuf byteBuf = new ByteBuf(2);
byteBuf.putShort(statusBlockId);
return byteBuf.getBytes();
}
use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.
the class CRCAuthLayerMessage method serialize.
@Override
public ByteBuf serialize(BigInteger nonce, long commID, byte[] key) {
byte[] data = getData();
short dataLength = (short) (data.length + 2);
short length = (short) (29 + dataLength);
ByteBuf byteBuf = new ByteBuf(length + 8);
byteBuf.putBytes(MAGIC_HEADER);
byteBuf.putUInt16LE(length);
byteBuf.putUInt16LE((short) ~length);
byteBuf.putByte(VERSION);
byteBuf.putByte(getCommand());
byteBuf.putUInt16LE(dataLength);
byteBuf.putUInt32LE(commID);
byteBuf.putBytes(processNonce(nonce));
byteBuf.putBytes(data);
byteBuf.putUInt16LE((short) Cryptograph.calculateCRC(byteBuf.getBytes(8, length - 10)));
byteBuf.putBytes((byte) 0x00, 8);
return byteBuf;
}
use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.
the class ReadHistoryFramesMessage method parse.
@Override
protected void parse(ByteBuf byteBuf) throws Exception {
historyFrames = new ArrayList<>();
byteBuf.shift(2);
int frameCount = byteBuf.readUInt16LE();
for (int i = 0; i < frameCount; i++) {
int length = byteBuf.readUInt16LE();
short eventType = byteBuf.readShort();
ByteBuf eventBuf = new ByteBuf(length - 2);
eventBuf.putBytes(byteBuf.readBytes(length - 2));
long eventNumber = eventBuf.getUInt32LE(8);
if (eventNumber > latestEventNumber)
latestEventNumber = eventNumber;
Class<? extends HistoryFrame> clazz = HistoryFrame.HISTORY_FRAMES.get(eventType);
if (clazz != null) {
HistoryFrame historyFrame = clazz.newInstance();
historyFrame.parseHeader(eventBuf);
historyFrame.parse(eventBuf);
historyFrames.add(historyFrame);
} else
Log.d("SightServiceHistory", "UNKNOWN HISTORY FRAME: EVENT TYPE: " + eventType + " CONTENT: " + Hex.toHexString(eventBuf.getBytes()));
}
}
use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.
the class CancelBolusMessage method getData.
@Override
protected byte[] getData() throws Exception {
ByteBuf byteBuf = new ByteBuf(2);
byteBuf.putUInt16LE(bolusId);
return byteBuf.getBytes();
}
Aggregations