Search in sources :

Example 31 with ByteBuf

use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.

the class AppLayerMessage method deserialize.

public static AppLayerMessage deserialize(ByteBuf byteBuf) throws Exception {
    byte version = byteBuf.readByte();
    byte service = byteBuf.readByte();
    short command = byteBuf.readShort();
    short error = byteBuf.readShort();
    byte[] data = byteBuf.readBytes();
    if (version != VERSION)
        throw new InvalidAppVersionError(version, VERSION);
    if (!MESSAGES.containsKey(service))
        throw new UnknownServiceError(service);
    Class<? extends AppLayerMessage> clazz = MESSAGES.get(service).get(command);
    if (clazz == null)
        throw new UnknownAppMessageError(service, command);
    if (error != 0x0000 && error != 0xF0CC) {
        Class<? extends AppErrorCodeError> errorClass = Errors.ERRORS.get(error);
        if (errorClass != null)
            throw errorClass.getConstructor(Class.class, short.class).newInstance(clazz, error);
        else
            throw new UnknownAppErrorCodeError(clazz, error);
    }
    AppLayerMessage message = clazz.newInstance();
    ByteBuf dataBuf = new ByteBuf(data.length);
    dataBuf.putBytes(data);
    if (message.inCRC()) {
        int crc = dataBuf.getUInt16LE(data.length - 2);
        byte[] bytes = dataBuf.getBytes(data.length - 2);
        int calculatedCRC = Cryptograph.calculateCRC(bytes);
        if (crc != calculatedCRC)
            throw new InvalidAppCRCError(crc, calculatedCRC);
        dataBuf = new ByteBuf(bytes.length);
        dataBuf.putBytes(bytes);
    }
    message.parse(dataBuf);
    return message;
}
Also used : UnknownAppErrorCodeError(sugar.free.sightparser.error.UnknownAppErrorCodeError) ByteBuf(sugar.free.sightparser.pipeline.ByteBuf) SuppressLint(android.annotation.SuppressLint) InvalidAppCRCError(sugar.free.sightparser.error.InvalidAppCRCError) UnknownServiceError(sugar.free.sightparser.error.UnknownServiceError) UnknownAppMessageError(sugar.free.sightparser.error.UnknownAppMessageError) InvalidAppVersionError(sugar.free.sightparser.error.InvalidAppVersionError)

Example 32 with ByteBuf

use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.

the class MaxBRAmountBlock method getData.

@Override
public byte[] getData() {
    ByteBuf byteBuf = new ByteBuf(2);
    byteBuf.putUInt16LE(Helpers.roundDoubleToInt(maximumAmount * 100D));
    return byteBuf.getBytes();
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf)

Example 33 with ByteBuf

use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.

the class MaxBolusAmountBlock method getData.

@Override
public byte[] getData() {
    ByteBuf byteBuf = new ByteBuf(2);
    byteBuf.putUInt16LE(Helpers.roundDoubleToInt(maximumAmount * 100D));
    return byteBuf.getBytes();
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf)

Example 34 with ByteBuf

use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.

the class NameBlock method getData.

@Override
public byte[] getData() {
    ByteBuf byteBuf = new ByteBuf(42);
    byteBuf.putUTF16LE(name, 42);
    return byteBuf.getBytes();
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf)

Example 35 with ByteBuf

use of sugar.free.sightparser.pipeline.ByteBuf in project SightRemote by TebbeUbben.

the class KeyRequest method getData.

@Override
protected byte[] getData() {
    ByteBuf byteBuf = new ByteBuf(288);
    byteBuf.putBytes(randomBytes);
    byteBuf.putUInt32LE(translateDate());
    byteBuf.putBytes(preMasterKey);
    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