package com.ifpdos.autotest.k0.g;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import d.n;
import d.n0.c.l;
import d.n0.c.s;
import d.s0.r;
import java.util.List;

/* JADX INFO: compiled from: SerialPortUtil.kt */
/* JADX INFO: loaded from: classes.dex */
@n
public final class c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final a f2056a = new a(null);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private String f2057b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final Handler f2058c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final Runnable f2059d;

    /* JADX INFO: compiled from: SerialPortUtil.kt */
    @n
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(l lVar) {
            this();
        }

        public final c a() {
            return new c(null);
        }
    }

    private c() {
        this.f2057b = "";
        this.f2058c = new Handler(Looper.getMainLooper());
        this.f2059d = new Runnable() { // from class: com.ifpdos.autotest.k0.g.a
            @Override // java.lang.Runnable
            public final void run() {
                c.c(this.f2052c);
            }
        };
    }

    public /* synthetic */ c(l lVar) {
        this();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void c(c cVar) {
        s.e(cVar, "this$0");
        Log.i("SerialPortUtil", "-------------------------- time out!!! ---------------------------");
        cVar.f2057b = "";
    }

    public final void b(byte[] bArr, com.ifpdos.autotest.lancontrol.serialport.c cVar) {
        if (bArr == null || cVar == null) {
            return;
        }
        this.f2058c.removeCallbacks(this.f2059d);
        String str = new String(bArr, d.s0.d.f2700b);
        this.f2057b += str;
        Log.i("SerialPortUtil", "out=" + str);
        if (!r.w(this.f2057b, "\n", false, 2, null)) {
            this.f2058c.postDelayed(this.f2059d, 600L);
            return;
        }
        List listW = r.W(this.f2057b, new String[]{"\n"}, false, 0, 6, null);
        Log.i("SerialPortUtil", "result[0]=" + ((String) listW.get(0)));
        cVar.a(((String) listW.get(0)) + '\n');
        this.f2057b = "";
    }
}
