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

78 lines
3.0 KiB
Java

package com.ubtrobot.jimu.robotapi;
import android.util.Log;
import com.ubtrobot.jimu.bluetooth.base.ProtocolPacket;
import com.ubtrobot.jimu.connection.RequestException;
import com.ubtrobot.jimu.connection.RobotConnection;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes2.dex */
public class SensorManager {
private RobotConnection a;
public SensorManager(RobotConnection robotConnection) {
this.a = robotConnection;
}
public int a(int i, List<Integer> list, boolean z) throws JimuException {
ProtocolPacket protocolPacket = new ProtocolPacket(113, new byte[]{(byte) (i & 255), a(list), !z ? 1 : 0});
try {
byte[] g = this.a.a(protocolPacket).g();
if (g.length == 3) {
return g[2] & 255;
}
throw new JimuException(-22, "res argument is err!");
} catch (RequestException e) {
Log.e("SensorManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
public byte a(List<Integer> list) {
Iterator<Integer> it = list.iterator();
byte b = 0;
while (it.hasNext()) {
b = (byte) (b | (1 << (it.next().intValue() - 1)));
}
return b;
}
public BluetoothSpeakerInfo a(int i) throws JimuException {
if (i >= 1 && i <= 8) {
ProtocolPacket protocolPacket = new ProtocolPacket(114, new byte[]{8, (byte) (1 << (i - 1))});
try {
byte[] g = this.a.a(protocolPacket).g();
int i2 = 3;
if (g.length > 3) {
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
int i3 = 0;
while (i2 < g.length) {
if (i3 < 6) {
sb2.append(String.format("%02x:", Byte.valueOf(g[i2])));
} else {
sb.append((char) g[i2]);
}
i2++;
i3++;
}
if (sb2.length() == 0) {
Log.e("SensorManager", "Read speaker info fail! Mac is null!");
return null;
}
sb2.deleteCharAt(sb2.length() - 1);
return new BluetoothSpeakerInfo(sb2.toString(), sb.toString());
}
Log.e("SensorManager", "Read speaker info fail!");
throw new JimuException(-21, "Read speaker info fail!");
} catch (RequestException e) {
Log.e("SensorManager", "Call cmd fail! cmd:" + ((int) protocolPacket.f()), e);
throw new JimuException(e.getCode(), e.getMessage());
}
}
Log.e("SensorManager", "Invalid id");
throw new JimuException(-20, JimuException.ERR_MSG_ARGUMENT_INVALID);
}
}