package com.ubtrobot.jimu.robotapi; import android.content.Context; import android.text.TextUtils; import com.ubtech.utils.XLog; import com.ubtrobot.jimu.bluetooth.base.IPacket; import com.ubtrobot.jimu.exception.BatteryException; import com.ubtrobot.jimu.exception.EngineProtectException; import com.ubtrobot.jimu.exception.EngineVersionException; import com.ubtrobot.jimu.exception.RobotActiveException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /* loaded from: classes2.dex */ public class GlobalExceptionUtil { public interface ExceptionCallback { void a(String str, RobotActiveException robotActiveException, List list); } private boolean a(int i, int i2) { return ((i >> i2) & 1) > 0; } public RobotActiveException a(IPacket iPacket, String str) { byte[] g = iPacket.g(); int i = g[0] & 255; XLog.a("woo", "errorCode: %d", Integer.valueOf(i)); if (i == 0) { return null; } if (i == 1) { return new BatteryException(i, g[1] & 255, "Battery Error"); } if (i == 2) { Map> a = a(g); if (a == null || a.size() <= 0) { return null; } return new EngineProtectException(i, "Servo is protected", PeripheralType.SERVO, a); } if (i == 3) { return new EngineVersionException(i, "The Servo version is inconformity", PeripheralType.SERVO, g[1] & 255); } if (i != 4) { return i != 5 ? new RobotActiveException(i, "Unknown Exception") : new EngineVersionException(i, "The Motor version is inconformity", 10, g[1] & 255); } Map> a2 = a(g); if (a2 == null || a2.size() <= 0) { return null; } return new EngineProtectException(i, "Motor is protected", 10, a2); } private Map> a(byte[] bArr) { HashMap hashMap = new HashMap(); List a = a(a(bArr, 1)); if (a != null && a.size() > 0) { hashMap.put(1, a); } List a2 = a(a(bArr, 5)); if (a2 != null && a2.size() > 0) { hashMap.put(2, a2); } List a3 = a(a(bArr, 9)); if (a3 != null && a3.size() > 0) { hashMap.put(4, a3); } List a4 = a(a(bArr, 13)); if (a4 != null && a4.size() > 0) { hashMap.put(8, a4); } List a5 = a(a(bArr, 17)); if (a5 != null && a5.size() > 0) { hashMap.put(16, a5); } List a6 = a(a(bArr, 21)); if (a6 != null && a6.size() > 0) { hashMap.put(32, a6); } List a7 = a(a(bArr, 25)); if (a7 != null && a7.size() > 0) { hashMap.put(64, a7); } return hashMap; } private List a(int i) { ArrayList arrayList = null; for (int i2 = 0; i2 < 32; i2++) { if (a(i, i2)) { if (arrayList == null) { arrayList = new ArrayList(); } arrayList.add(Integer.valueOf(i2 + 1)); } } return arrayList; } private int a(byte[] bArr, int i) { return bArr[i + 3] | (bArr[i] << 24) | (bArr[i + 1] << 16) | (bArr[i + 2] << 8); } public static void a(Context context, RobotActiveException robotActiveException, ExceptionCallback exceptionCallback) { int errorCode = robotActiveException.getErrorCode(); if ((errorCode == 2 || errorCode == 4) && (robotActiveException instanceof EngineProtectException)) { EngineProtectException engineProtectException = (EngineProtectException) robotActiveException; int higherExceptionCode = engineProtectException.getHigherExceptionCode(); List errorMapByCode = engineProtectException.getErrorMapByCode(higherExceptionCode); String errorMessage = engineProtectException.getErrorMessage(context, higherExceptionCode, errorMapByCode); if (TextUtils.isEmpty(errorMessage) || exceptionCallback == null) { return; } exceptionCallback.a(errorMessage, engineProtectException, errorMapByCode); return; } if (errorCode == 1 && (robotActiveException instanceof BatteryException)) { BatteryException batteryException = (BatteryException) robotActiveException; String errorMessage2 = batteryException.getErrorMessage(context); if (TextUtils.isEmpty(errorMessage2) || exceptionCallback == null) { return; } exceptionCallback.a(errorMessage2, batteryException, null); } } }