Search in sources :

Example 1 with ByteBuf

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();
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf)

Example 2 with ByteBuf

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();
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf)

Example 3 with ByteBuf

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;
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf)

Example 4 with 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()));
    }
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf) HistoryFrame(sugar.free.sightparser.applayer.descriptors.history_frames.HistoryFrame)

Example 5 with ByteBuf

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();
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf)

Aggregations

ByteBuf (sugar.free.sightparser.pipeline.ByteBuf)35 SuppressLint (android.annotation.SuppressLint)3 InvalidAuthCRCError (sugar.free.sightparser.error.InvalidAuthCRCError)2 InvalidNonceError (sugar.free.sightparser.error.InvalidNonceError)2 InvalidTrailerError (sugar.free.sightparser.error.InvalidTrailerError)2 CustomEvent (com.crashlytics.android.answers.CustomEvent)1 BigInteger (java.math.BigInteger)1 HistoryFrame (sugar.free.sightparser.applayer.descriptors.history_frames.HistoryFrame)1 AppLayerMessage (sugar.free.sightparser.applayer.messages.AppLayerMessage)1 AuthLayerMessage (sugar.free.sightparser.authlayer.AuthLayerMessage)1 CRCAuthLayerMessage (sugar.free.sightparser.authlayer.CRCAuthLayerMessage)1 DataMessage (sugar.free.sightparser.authlayer.DataMessage)1 InvalidAppCRCError (sugar.free.sightparser.error.InvalidAppCRCError)1 InvalidAppVersionError (sugar.free.sightparser.error.InvalidAppVersionError)1 InvalidAuthVersionError (sugar.free.sightparser.error.InvalidAuthVersionError)1 UnknownAppErrorCodeError (sugar.free.sightparser.error.UnknownAppErrorCodeError)1 UnknownAppMessageError (sugar.free.sightparser.error.UnknownAppMessageError)1 UnknownAuthMessageError (sugar.free.sightparser.error.UnknownAuthMessageError)1 UnknownServiceError (sugar.free.sightparser.error.UnknownServiceError)1