electric-monk / pycarplay

Python Carplay library for the "Autobox" dongles
MIT License
268 stars 36 forks source link

protocol.py - Message interface for keypresses #6

Open harrylepotter opened 3 years ago

harrylepotter commented 3 years ago

I've been trying to figure out how to get key presses sent via protocol.py. Thus far from Jadding i think i've found the appropriate function:

 public boolean mo3439b(int i) {
        if (i == 202) {
            if (this.f2584H != null) {
                this.f2584H.mo3362a(true);
            }
        } else if (i == 201 && this.f2584H != null) {
            this.f2584H.mo3362a(false);
        }
        if (!this.f2602v.mo3742a().booleanValue()) {
            C0881i.m4227c("BoxProtocol,send_carplay_cmd:  failed: cmd=" + i);
            return false;
        }
        C0881i.m4227c("BoxProtocol,send_carplay_cmd: start, cmd=" + i);
        C0773e eVar = new C0773e(4);
        int unused = eVar.f2641b.f2621d = 8;
        int unused2 = eVar.f2641b.f2620c = 4;
        eVar.mo3497h();
        eVar.mo3495f().putInt(0, i);
        eVar.mo3498i();
        synchronized (this) {
            if (!C0753c.m3486b(eVar.mo3492c(), eVar.mo3493d())) {
                C0881i.m4227c("BoxProtocol,send_carplay_cmd: Write carplay_cmd head err");
                return false;
            } else if (C0753c.m3486b(eVar.mo3494e(), eVar.mo3496g())) {
                C0881i.m4227c("BoxProtocol,send_carplay_cmd: success ");
                return true;
            } else {
                C0881i.m4227c("BoxProtocol,send_carplay_cmd: Write carplay_cmd data err");
                return false;
            }
        }
    }

if i'm guessing correctly, eVar.f2641b.f2621d is the message type, and eVar.f2641b.f2620c means 'carplay command'. There's another block that executes before this, that seems to resolve android keycodes to something the box interprets as a button press:

    public static void m4010h(int i) {
        C0881i.m4225b("sendCarControlByKey: cmd = " + i);
        switch (i) {
            case 1:
                if (m3996a()) {
                    m4009g(300);
                    return;
                } else {
                    m4009g(205);
                    return;
                }
            case 2:
                if (m3996a()) {
                    m4009g(301);
                    return;
                } else {
                    m4009g(204);
                    return;
                }
            case 3:
                m4009g(201);
                return;
            case 4:
                m4009g(202);
                return;
            case 5:
                m4009g(203);
                return;
            case 6:
                m4009g(204);
                return;
            case 7:
                m4009g(205);
                return;
            case 8:
                m4009g(5);
                m4009g(6);
                return;
            case 9:
                m4009g(200);
                return;
            case 10:
                m4009g(106);
                return;
            case 11:
                if (m4007e()) {
                    C0753c.m3483a(4, 0);
                    return;
                } else {
                    C0753c.m3483a(4, 1);
                    return;
                }
            case 12:
                m4009g(104);
                m4009g(105);
                return;
            case 13:
                m4009g(100);
                return;
            case 14:
                m4009g(101);
                return;
            case 15:
                m4009g(102);
                return;
            case 16:
                m4009g(103);
                return;
            case 17:
                m4009g(300);
                return;
            case 18:
                m4009g(301);
                return;
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
                m4009g(i + 283);
                return;
            default:
                return;
        }
    }

for some reason though, nothing i've tried pushing through seems to work... at the point where i'm entering random numbers, but nothing....

    def _keylistener_thread(self):
        while True:
           #get a keycode and send it?
            input1 = int(input())
            keys = protocol.Message(8)
            mcVal = struct.pack("<LL",4, input1)
            keys._setdata(mcVal)
            self.connection.send_message(keys)
harrylepotter commented 3 years ago

PR for button support here : https://github.com/electric-monk/pycarplay/pull/7