254 lines
7.1 KiB
Java
254 lines
7.1 KiB
Java
package com.ubtrobot.jimu.bluetooth.base;
|
|
|
|
import android.util.Log;
|
|
import com.ijm.dataencryption.de.DataDecryptTool;
|
|
import java.nio.ByteBuffer;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class ProtocolPacket implements IPacket {
|
|
private byte[] a;
|
|
private int b;
|
|
private byte c;
|
|
private byte[] d;
|
|
private int e;
|
|
private PROTOCOL_STATE f = PROTOCOL_STATE.HEADER1;
|
|
private ByteBuffer g = ByteBuffer.allocate(DataDecryptTool.DECRYPT_SP_FILE);
|
|
|
|
/* renamed from: com.ubtrobot.jimu.bluetooth.base.ProtocolPacket$1, reason: invalid class name */
|
|
static /* synthetic */ class AnonymousClass1 {
|
|
static final /* synthetic */ int[] a = new int[PROTOCOL_STATE.values().length];
|
|
|
|
static {
|
|
try {
|
|
a[PROTOCOL_STATE.HEADER1.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
a[PROTOCOL_STATE.HEADER2.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
a[PROTOCOL_STATE.LENGHT.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
try {
|
|
a[PROTOCOL_STATE.CMD.ordinal()] = 4;
|
|
} catch (NoSuchFieldError unused4) {
|
|
}
|
|
try {
|
|
a[PROTOCOL_STATE.PARAM.ordinal()] = 5;
|
|
} catch (NoSuchFieldError unused5) {
|
|
}
|
|
try {
|
|
a[PROTOCOL_STATE.CHECKSUM.ordinal()] = 6;
|
|
} catch (NoSuchFieldError unused6) {
|
|
}
|
|
try {
|
|
a[PROTOCOL_STATE.END.ordinal()] = 7;
|
|
} catch (NoSuchFieldError unused7) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public ProtocolPacket() {
|
|
this.g.clear();
|
|
}
|
|
|
|
public byte a(byte[] bArr, int i, int i2) {
|
|
byte b = 0;
|
|
while (i <= i2) {
|
|
b = (byte) (b + bArr[i]);
|
|
i++;
|
|
}
|
|
return b;
|
|
}
|
|
|
|
public void a(String str) {
|
|
}
|
|
|
|
public void b(byte[] bArr) {
|
|
this.a = new byte[2];
|
|
System.arraycopy(bArr, 0, this.a, 0, 2);
|
|
this.b = bArr[2] & 255;
|
|
this.c = bArr[3];
|
|
int i = this.b;
|
|
int i2 = 4;
|
|
if (i - 5 > 0) {
|
|
this.d = new byte[i - 5];
|
|
System.arraycopy(bArr, 4, this.d, 0, i - 5);
|
|
int i3 = this.b;
|
|
i2 = 4 + (i3 - 5);
|
|
this.e = i3 - 5;
|
|
}
|
|
byte b = bArr[i2];
|
|
byte b2 = bArr[i2 + 1];
|
|
}
|
|
|
|
public Object clone() {
|
|
try {
|
|
return (ProtocolPacket) super.clone();
|
|
} catch (CloneNotSupportedException e) {
|
|
Log.e("ContentValues", "Clone BleProtocolPacket fail!", e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override // com.ubtrobot.jimu.bluetooth.base.IPacket
|
|
public byte f() {
|
|
return this.c;
|
|
}
|
|
|
|
@Override // com.ubtrobot.jimu.bluetooth.base.IPacket
|
|
public byte[] g() {
|
|
return this.d;
|
|
}
|
|
|
|
@Override // com.ubtrobot.jimu.bluetooth.base.IPacket
|
|
public int getId() {
|
|
return this.c;
|
|
}
|
|
|
|
@Override // com.ubtrobot.jimu.bluetooth.base.IPacket
|
|
public boolean isValid() {
|
|
return true;
|
|
}
|
|
|
|
public void a(byte b) {
|
|
this.c = b;
|
|
}
|
|
|
|
public void a(byte[] bArr) {
|
|
this.d = bArr;
|
|
if (bArr == null) {
|
|
this.e = 0;
|
|
} else {
|
|
this.e = bArr.length;
|
|
}
|
|
}
|
|
|
|
public ProtocolPacket(int i, byte[] bArr) {
|
|
this.g.clear();
|
|
a((byte) i);
|
|
a(bArr);
|
|
}
|
|
|
|
public int a() {
|
|
return this.e;
|
|
}
|
|
|
|
public void a(int i) {
|
|
this.e = i;
|
|
}
|
|
|
|
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
|
|
public boolean b(byte b) {
|
|
try {
|
|
int i = 0;
|
|
switch (AnonymousClass1.a[this.f.ordinal()]) {
|
|
case 1:
|
|
if (b != -5) {
|
|
Log.v("error_blue", "1");
|
|
} else {
|
|
this.g.clear();
|
|
this.g.put(b);
|
|
this.f = PROTOCOL_STATE.HEADER2;
|
|
}
|
|
return false;
|
|
case 2:
|
|
if (b != -65) {
|
|
this.f = PROTOCOL_STATE.HEADER1;
|
|
Log.v("error_blue", "2");
|
|
if (b == -5) {
|
|
b(b);
|
|
}
|
|
} else {
|
|
this.g.put(b);
|
|
this.f = PROTOCOL_STATE.LENGHT;
|
|
}
|
|
return false;
|
|
case 3:
|
|
this.b = b & 255;
|
|
this.g.put(b);
|
|
this.f = PROTOCOL_STATE.CMD;
|
|
return false;
|
|
case 4:
|
|
this.c = b;
|
|
this.g.put(b);
|
|
this.f = PROTOCOL_STATE.PARAM;
|
|
this.e = this.b - 5;
|
|
this.d = new byte[this.e];
|
|
return false;
|
|
case 5:
|
|
this.g.put(b);
|
|
this.e--;
|
|
if (this.e == 0) {
|
|
this.f = PROTOCOL_STATE.CHECKSUM;
|
|
}
|
|
return false;
|
|
case 6:
|
|
if (a(this.g.array(), 2, this.g.position() - 1) != b) {
|
|
this.f = PROTOCOL_STATE.HEADER1;
|
|
Log.v("error_blue", "3");
|
|
if (b == -5) {
|
|
b(b);
|
|
}
|
|
} else {
|
|
this.g.put(b);
|
|
this.f = PROTOCOL_STATE.END;
|
|
}
|
|
return false;
|
|
case 7:
|
|
if (b != -19) {
|
|
this.f = PROTOCOL_STATE.HEADER1;
|
|
Log.v("error_blue", "4");
|
|
if (b == -5) {
|
|
b(b);
|
|
}
|
|
return false;
|
|
}
|
|
this.g.put(b);
|
|
this.f = PROTOCOL_STATE.HEADER1;
|
|
int i2 = 0;
|
|
while (i < this.b - 5) {
|
|
this.d[i2] = this.g.get(i + 4);
|
|
i++;
|
|
i2++;
|
|
}
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
} catch (Exception e) {
|
|
e.getMessage();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public byte[] b() {
|
|
int i;
|
|
int i2 = this.e;
|
|
int i3 = (short) (i2 == 0 ? 7 : i2 + 6);
|
|
byte[] bArr = new byte[i3];
|
|
int i4 = 0;
|
|
bArr[0] = -5;
|
|
bArr[1] = -65;
|
|
bArr[2] = (byte) ((i3 - 1) & 255);
|
|
bArr[3] = this.c;
|
|
if (this.e == 0) {
|
|
i = 5;
|
|
bArr[4] = 0;
|
|
} else {
|
|
i = 4;
|
|
while (i4 < this.e) {
|
|
bArr[i] = this.d[i4];
|
|
i4++;
|
|
i++;
|
|
}
|
|
}
|
|
int i5 = i + 1;
|
|
bArr[i] = a(bArr, 2, i5);
|
|
bArr[i5] = -19;
|
|
return bArr;
|
|
}
|
|
}
|