package com.ifpdos.mcusdk;

import android.os.Parcel;
import android.os.Parcelable;
import com.ifpdos.mcusdk.McuCommandList;
import com.ifpdos.mcusdk.utils.ByteUtils;

/* JADX INFO: loaded from: classes.dex */
public class McuCommonBase implements Parcelable {
    public static final Parcelable.Creator<McuCommonBase> CREATOR = new Parcelable.Creator<McuCommonBase>() { // from class: com.ifpdos.mcusdk.McuCommonBase.1
        /* JADX WARN: Can't rename method to resolve collision */
        @Override // android.os.Parcelable.Creator
        public McuCommonBase createFromParcel(Parcel parcel) {
            return new McuCommonBase(parcel);
        }

        /* JADX WARN: Can't rename method to resolve collision */
        @Override // android.os.Parcelable.Creator
        public McuCommonBase[] newArray(int i) {
            return new McuCommonBase[i];
        }
    };
    public Byte backId;
    protected byte[] bufferData;
    protected Byte last;
    private Byte mainId;
    protected Byte singleData;
    private Byte subId;
    public int type;

    @Override // android.os.Parcelable
    public int describeContents() {
        return 0;
    }

    public McuCommonBase(int i, Byte b, Byte b2, Byte b3, byte[] bArr, Byte b4, Byte b5) {
        this.type = i;
        this.mainId = b;
        this.subId = b2;
        this.singleData = b3;
        this.bufferData = bArr;
        this.last = b4;
        this.backId = b5;
    }

    public McuCommonBase(int i, Byte b, Byte b2, byte[] bArr, Byte b3) {
        this(i, b, b2, Byte.valueOf(bufferDataNotEmpty(bArr) ? bArr[0] : (byte) 0), bufferDataNotEmpty(bArr) ? bArr : new byte[]{0}, b3);
    }

    private McuCommonBase(int i, Byte b, Byte b2, Byte b3, byte[] bArr, Byte b4) {
        this(i, b, b2, b3, bArr, Byte.valueOf(bufferDataNotEmpty(bArr) ? bArr[bArr.length - 1] : (byte) 0), b4);
    }

    protected McuCommonBase(Parcel parcel) {
        this.type = parcel.readInt();
        if (parcel.readByte() == 0) {
            this.mainId = null;
        } else {
            this.mainId = Byte.valueOf(parcel.readByte());
        }
        if (parcel.readByte() == 0) {
            this.backId = null;
        } else {
            this.backId = Byte.valueOf(parcel.readByte());
        }
        if (parcel.readByte() == 0) {
            this.subId = null;
        } else {
            this.subId = Byte.valueOf(parcel.readByte());
        }
        if (parcel.readByte() == 0) {
            this.singleData = null;
        } else {
            this.singleData = Byte.valueOf(parcel.readByte());
        }
        this.bufferData = parcel.createByteArray();
        if (parcel.readByte() == 0) {
            this.last = null;
        } else {
            this.last = Byte.valueOf(parcel.readByte());
        }
    }

    private static boolean bufferDataNotEmpty(byte[] bArr) {
        return bArr != null && bArr.length > 0;
    }

    public int getType() {
        return this.type;
    }

    public Byte getMainId() {
        return this.mainId;
    }

    public Byte getSubId() {
        return this.subId;
    }

    public Byte getSingleData() {
        return this.singleData;
    }

    public byte[] getBufferData() {
        return this.bufferData;
    }

    public Byte getLast() {
        return this.last;
    }

    public String toString() {
        return "[ " + McuCommandList.CommandType.values()[this.type] + " ]: [ " + ByteUtils.changeByteToHexString(this.mainId.byteValue()) + " ] [ " + ByteUtils.changeByteToHexString(this.subId.byteValue()) + " ][ " + ByteUtils.changeByteArrayToString(this.bufferData) + " ]";
    }

    @Override // android.os.Parcelable
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(this.type);
        if (this.mainId == null) {
            parcel.writeByte((byte) 0);
        } else {
            parcel.writeByte((byte) 1);
            parcel.writeByte(this.mainId.byteValue());
        }
        if (this.backId == null) {
            parcel.writeByte((byte) 0);
        } else {
            parcel.writeByte((byte) 1);
            parcel.writeByte(this.backId.byteValue());
        }
        if (this.subId == null) {
            parcel.writeByte((byte) 0);
        } else {
            parcel.writeByte((byte) 1);
            parcel.writeByte(this.subId.byteValue());
        }
        if (this.singleData == null) {
            parcel.writeByte((byte) 0);
        } else {
            parcel.writeByte((byte) 1);
            parcel.writeByte(this.singleData.byteValue());
        }
        parcel.writeByteArray(this.bufferData);
        if (this.last == null) {
            parcel.writeByte((byte) 0);
        } else {
            parcel.writeByte((byte) 1);
            parcel.writeByte(this.last.byteValue());
        }
    }
}
