161 lines
6.2 KiB
Java
161 lines
6.2 KiB
Java
package com.ubtrobot.jimu.robotapi;
|
|
|
|
import android.util.Log;
|
|
import com.afunx.ble.blelitelib.utils.HexUtils;
|
|
import com.ubtech.utils.XLog;
|
|
import com.ubtrobot.jimu.bluetooth.base.IPacket;
|
|
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
|
|
import com.ubtrobot.jimu.connection.RequestException;
|
|
import com.ubtrobot.jimu.connection.RobotConnection;
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class DeviceManager {
|
|
private RobotConnection a;
|
|
|
|
public DeviceManager(RobotConnection robotConnection) {
|
|
this.a = robotConnection;
|
|
}
|
|
|
|
public void a(boolean z) throws JimuException {
|
|
try {
|
|
byte[] g = this.a.a(new ProtocolPacket(5, z ? new byte[]{0} : new byte[]{1})).g();
|
|
if (g[0] == 0) {
|
|
return;
|
|
}
|
|
throw new JimuException(-21, "read robot battery info fail! ErrCode:" + ((int) g[0]));
|
|
} catch (RequestException e) {
|
|
throw new JimuException(e.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
public String b() throws JimuException {
|
|
ProtocolPacket protocolPacket = new ProtocolPacket(44, new byte[]{0});
|
|
try {
|
|
byte[] g = this.a.a(protocolPacket).g();
|
|
if (g[0] != 0) {
|
|
XLog.b("DeviceManager", "read McuId fail!");
|
|
throw new JimuException(-21, "read McuId fail!");
|
|
}
|
|
byte[] bArr = new byte[g.length - 1];
|
|
System.arraycopy(g, 1, bArr, 0, bArr.length);
|
|
String bytes2HexString = HexUtils.bytes2HexString(bArr);
|
|
Log.d("DeviceManager", "McuId:" + bytes2HexString);
|
|
return bytes2HexString;
|
|
} catch (RequestException e) {
|
|
Log.e("DeviceManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
|
|
throw new JimuException(e.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
public String c() throws JimuException {
|
|
ProtocolPacket protocolPacket = new ProtocolPacket(54, new byte[]{0});
|
|
try {
|
|
byte[] g = this.a.a(protocolPacket).g();
|
|
if (g.length <= 1) {
|
|
return "";
|
|
}
|
|
if (g.length == 1 && g[0] != 0) {
|
|
XLog.b("DeviceManager", "read device type(cmd:0x36) fail! errResult:" + ((int) g[0]));
|
|
throw new JimuException(-21, "read device type(cmd:0x36) fail! errResult:" + ((int) g[0]));
|
|
}
|
|
byte[] bArr = new byte[g.length - 1];
|
|
System.arraycopy(g, 1, bArr, 0, bArr.length);
|
|
try {
|
|
String str = new String(bArr, "UTF-8");
|
|
XLog.a("DeviceManager", "productName:" + str);
|
|
return str;
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
return String.valueOf(bArr);
|
|
}
|
|
} catch (RequestException e2) {
|
|
Log.e("DeviceManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e2);
|
|
throw new JimuException(e2.getCode(), e2.getMessage());
|
|
}
|
|
}
|
|
|
|
public BatteryInfo d() throws JimuException {
|
|
boolean z = true;
|
|
ProtocolPacket protocolPacket = new ProtocolPacket(39, new byte[]{0});
|
|
try {
|
|
byte[] g = this.a.a(protocolPacket).g();
|
|
if (g.length != 1) {
|
|
boolean z2 = g[0] != 0;
|
|
if (g[1] != 1) {
|
|
z = false;
|
|
}
|
|
return new BatteryInfo(g[2], g[3], z2, z);
|
|
}
|
|
throw new JimuException(-21, "read robot battery info fail! ErrCode:" + ((int) g[0]));
|
|
} catch (RequestException e) {
|
|
Log.e("DeviceManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
|
|
throw new JimuException(e.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
public BoardInfo e() throws JimuException {
|
|
String str;
|
|
try {
|
|
byte[] g = this.a.a(new ProtocolPacket(8, new byte[]{0})).g();
|
|
if (g.length != 1) {
|
|
BoardInfo boardInfo = new BoardInfo();
|
|
boardInfo.a(g);
|
|
return boardInfo;
|
|
}
|
|
int i = g[0] & 255;
|
|
if (i == 1) {
|
|
str = "Read board info fail!";
|
|
XLog.d("DeviceManager", "Read board info fail!", new Object[0]);
|
|
} else if (i != 238) {
|
|
str = "Read board info fail for invalid error code!";
|
|
XLog.d("DeviceManager", "Read board info fail for invalid error code!", new Object[0]);
|
|
} else {
|
|
str = "Read board info fail for board is initing!";
|
|
XLog.d("DeviceManager", "Read board info fail for board is initing!", new Object[0]);
|
|
}
|
|
throw new JimuException(g[0] & 255, str);
|
|
} catch (RequestException e) {
|
|
Log.e("DeviceManager", "Read board info fail", e);
|
|
throw new JimuException(e.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
public String f() throws JimuException {
|
|
ProtocolPacket protocolPacket = new ProtocolPacket(43, new byte[]{7});
|
|
try {
|
|
byte[] g = this.a.a(protocolPacket).g();
|
|
if (g[0] != 0) {
|
|
XLog.b("DeviceManager", "read SN fail!");
|
|
throw new JimuException(-21, "excuse cmd fail!");
|
|
}
|
|
byte[] bArr = new byte[g.length - 1];
|
|
System.arraycopy(g, 1, bArr, 0, bArr.length);
|
|
String str = new String(bArr);
|
|
Log.d("DeviceManager", "SN:" + str);
|
|
return str;
|
|
} catch (RequestException e) {
|
|
Log.e("DeviceManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
|
|
throw new JimuException(e.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
public int g() throws RequestException {
|
|
try {
|
|
IPacket a = this.a.a(new ProtocolPacket(1, new byte[]{0}));
|
|
if (a.g().length == 1) {
|
|
return a.g()[0] == 0 ? 0 : -1;
|
|
}
|
|
return -1;
|
|
} catch (RequestException e) {
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
public boolean a() throws JimuException {
|
|
String c = c();
|
|
Log.d("DeviceManager", "Product type:" + c);
|
|
return "".equals(c) || c.startsWith("JIMU") || c.startsWith("Jimu") || c.startsWith("S1JIMU");
|
|
}
|
|
}
|