package c0;

import com.vacenter.Taurus.Controller;
import com.vacenter.Taurus.Device;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import u.g;

/* JADX INFO: loaded from: classes2.dex */
public class a {
    public static a a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public List<Device> f957b = new ArrayList();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Controller f958c = b.d().c();

    public static a g() {
        if (a == null) {
            a = new a();
        }
        return a;
    }

    public int a(Device device) {
        g.a("TaurusCameraController", String.format("ability_type:%x name:%s address:%s%n", Integer.valueOf(device.info.abilityType), device.info.name, device.address));
        Iterator<Device> it = this.f957b.iterator();
        while (it.hasNext()) {
            if (d(it.next(), device)) {
                g.a("TaurusCameraController", "Device already exists");
                return -1;
            }
        }
        this.f957b.add(device);
        return 0;
    }

    public Controller b() {
        if (this.f958c == null) {
            g.a("TaurusCameraController", "[init]mController is null. start to init gController.");
            this.f958c = b.d().c();
        }
        return this.f958c;
    }

    public String c(String str, String str2) {
        String strF = f(str);
        g.a("TaurusCameraController", "[sendCustomerStringWithReturn] devName: " + str + " mAddress = " + strF);
        if (u.b.b().d(strF)) {
            g.a("TaurusCameraController", "Can't find device: " + str);
            return "";
        }
        String strSendCustomerString = this.f958c.sendCustomerString(strF, str2);
        g.a("TaurusCameraController", "[sendCustomerStringWithReturn] response_str: " + strSendCustomerString);
        return strSendCustomerString;
    }

    public boolean d(Device device, Device device2) {
        return device.uuid.equals(device2.uuid) && device.address.equals(device2.address) && device.version.equals(device2.version) && device.info.name.equals(device2.info.name);
    }

    public int e(String str, String str2) {
        g.a("TaurusCameraController", "[sendCustomerStringWithoutReturn]");
        String strF = f(str);
        if (u.b.b().d(strF)) {
            g.a("TaurusCameraController", "Can't find device: " + str);
            return -1;
        }
        g.a("TaurusCameraController", "[sendCustomerStringWithoutReturn] response_str: " + this.f958c.sendCustomerString(strF, str2));
        return 0;
    }

    public String f(String str) {
        String str2;
        String strT;
        if (str != null && !str.isEmpty()) {
            for (Device device : this.f957b) {
                if (device.info.name.startsWith(str)) {
                    str2 = device.address;
                    break;
                }
            }
        } else {
            g.a("TaurusCameraController", "Name is null or empty");
        }
        str2 = "";
        if (str2.isEmpty()) {
            strT = g.a.a.a.a.t("Can't find device: ", str);
        } else if (this.f958c == null) {
            strT = "mController is null";
        } else {
            if (h(str2)) {
                return str2;
            }
            strT = "Can't find device by address";
        }
        g.a("TaurusCameraController", strT);
        return "";
    }

    public boolean h(String str) {
        if (str == null || str.isEmpty()) {
            g.a("TaurusCameraController", "Address is null or empty");
            return false;
        }
        Iterator<Device> it = this.f957b.iterator();
        while (it.hasNext()) {
            if (it.next().address.split(":")[0].equals(str.split(":")[0])) {
                return true;
            }
        }
        return false;
    }
}
