jimu-decompiled/sources/com/ubtrobot/jimu/robotapi/BoardInfo.java
2025-05-13 19:24:51 +02:00

277 lines
7.6 KiB
Java

package com.ubtrobot.jimu.robotapi;
import com.afunx.ble.blelitelib.utils.HexUtils;
import com.ubtech.utils.XLog;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* loaded from: classes2.dex */
public class BoardInfo {
private String a;
private float c;
private String f;
private byte[] i;
private int b = 0;
private List<Integer> d = new ArrayList();
private List<Integer> e = new ArrayList();
private List<Integer> g = new ArrayList();
private HashMap<Integer, SensorBoardInfo> h = new HashMap<>();
public class SensorBoardInfo {
private List<Integer> a;
private List<Integer> b;
private String c;
private List<Integer> d;
public SensorBoardInfo(BoardInfo boardInfo) {
}
public List<Integer> d() {
return this.d;
}
public List<Integer> b() {
return this.a;
}
public String c() {
return this.c;
}
public List<Integer> a() {
return this.b;
}
}
private boolean a(int i, int i2) {
return ((i >> i2) & 1) > 0;
}
public List<Integer> a() {
return this.e;
}
public float b() {
return this.c;
}
public int c() {
return this.b;
}
public String d() {
return this.a;
}
public int e() {
return (this.a.startsWith("Jimu_p") || this.a.startsWith("JIMU") || !this.a.startsWith("Jimu_b")) ? 112 : 113;
}
public byte[] f() {
return this.i;
}
public Map<Integer, Integer> g() {
List<Integer> b;
HashMap<Integer, SensorBoardInfo> hashMap = this.h;
if (hashMap == null || hashMap.size() <= 0) {
return null;
}
HashMap hashMap2 = new HashMap(this.h.size());
Iterator<Integer> it = this.h.keySet().iterator();
while (it.hasNext()) {
int intValue = it.next().intValue();
SensorBoardInfo sensorBoardInfo = this.h.get(Integer.valueOf(intValue));
if (sensorBoardInfo != null && (b = sensorBoardInfo.b()) != null && b.size() > 0) {
hashMap2.put(Integer.valueOf(intValue), Integer.valueOf(b.size()));
}
}
return hashMap2;
}
public HashMap<Integer, SensorBoardInfo> h() {
return this.h;
}
public List<Integer> i() {
return this.d;
}
public String j() {
return this.f;
}
public List<Integer> k() {
return this.g;
}
public boolean l() {
if (a().size() != 0) {
return true;
}
Iterator<Map.Entry<Integer, SensorBoardInfo>> it = h().entrySet().iterator();
while (it.hasNext()) {
if (it.next().getValue().a().size() != 0) {
return true;
}
}
return false;
}
private List<Integer> b(byte[] bArr) {
ArrayList arrayList = new ArrayList();
int i = (bArr[3] & 255) | ((bArr[0] & 255) << 24) | ((bArr[1] & 255) << 16) | ((bArr[2] & 255) << 8);
for (int i2 = 0; i2 < 32; i2++) {
if (a(i, i2)) {
arrayList.add(Integer.valueOf(i2 + 1));
}
}
return arrayList;
}
public int a(byte[] bArr) {
int i;
this.i = bArr;
int length = bArr.length;
if (length == 1) {
int i2 = bArr[0] & 255;
if (i2 == 1) {
XLog.d("BoardInfo", "Read board info fail!", new Object[0]);
} else if (i2 == 238) {
XLog.d("BoardInfo", "Read board info fail for board is initing", new Object[0]);
}
return -1;
}
if (length < 10) {
XLog.b("BoardInfo", "Invalid param");
return -1;
}
byte[] bArr2 = new byte[10];
System.arraycopy(bArr, 0, bArr2, 0, bArr2.length);
try {
this.a = new String(bArr2, "UTF-8");
} catch (UnsupportedEncodingException unused) {
XLog.b("BoardInfo", "Unsupported encoding board version name");
}
int i3 = length - 10;
if (i3 < 1) {
XLog.b("BoardInfo", "Board info(0x08 cmd response) not any battery info");
return 0;
}
if (a(bArr[10], 7)) {
this.b = 1;
} else {
this.b = 0;
}
this.c = (r6 & Byte.MAX_VALUE) / 10.0f;
int i4 = i3 - 1;
if (i4 < 16) {
XLog.b("BoardInfo", "Board info(0x08 cmd response) not any servo info");
return 0;
}
byte[] bArr3 = new byte[4];
System.arraycopy(bArr, 11, bArr3, 0, bArr3.length);
int length2 = 11 + bArr3.length;
this.d = b(bArr3);
System.arraycopy(bArr, length2, bArr3, 0, bArr3.length);
int length3 = length2 + bArr3.length;
this.e = b(bArr3);
this.f = HexUtils.bytes2HexString(bArr, length3, 4);
int i5 = length3 + 4;
System.arraycopy(bArr, i5, bArr3, 0, bArr3.length);
int length4 = i5 + bArr3.length;
this.g = b(bArr3);
int i6 = i4 - 16;
if (i6 < 1) {
XLog.b("BoardInfo", "Board info(0x08 cmd response) not any Flash size info");
return 0;
}
int i7 = length4 + 1;
byte b = bArr[length4];
int i8 = (i6 - 1) / 7;
for (int i9 = 1; i9 <= i8; i9++) {
int a = a(i9);
SensorBoardInfo sensorBoardInfo = new SensorBoardInfo(this);
sensorBoardInfo.c = "";
int i10 = i7 + 1;
sensorBoardInfo.a = a(bArr[i7]);
int i11 = i10 + 1;
sensorBoardInfo.b = a(bArr[i10]);
if (a == 10) {
sensorBoardInfo.c = HexUtils.bytes2HexString(bArr, i11, 4);
i = i11 + 4;
} else {
int i12 = i11;
int i13 = 0;
while (i13 < 4) {
int i14 = i12 + 1;
String valueOf = String.valueOf((int) bArr[i12]);
if (valueOf.length() == 1) {
valueOf = "0" + valueOf;
}
sensorBoardInfo.c += valueOf;
i13++;
i12 = i14;
}
i = i12;
}
sensorBoardInfo.d = a(bArr[i]);
i7 = i + 1;
this.h.put(Integer.valueOf(a), sensorBoardInfo);
}
return 0;
}
private List<Integer> a(byte b) {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < 8; i++) {
if (a(b, i)) {
arrayList.add(Integer.valueOf(i + 1));
}
}
return arrayList;
}
private int a(int i) {
switch (i) {
case 1:
return 1;
case 2:
return 3;
case 3:
return 2;
case 4:
return 4;
case 5:
return 5;
case 6:
return 6;
case 7:
return 7;
case 8:
return 8;
case 9:
return 12;
case 10:
return 97;
case 11:
return 96;
case 12:
return 11;
case 13:
return 9;
case 14:
return 10;
case 15:
return 14;
default:
XLog.b("BoardInfo", "INVALID SENSOR INDEX");
return -1;
}
}
}