louis49 / androidtv-remote

MIT License
68 stars 23 forks source link

how ping packet looks like? #1

Closed Ganime422 closed 2 years ago

Ganime422 commented 2 years ago

Hi, How did u know how to parse a ping packet and to identify it and send a ping packet back (and also how that one looks like?) cuz sometime I get from the tv a ping message that starts like this: [66, 8, 8 ...] sometimes like this: [66, 7, 8 ... ]

is there any logic behing this?

louis49 commented 2 years ago

Ping request is formed by two varint, you need to resend only first :

Receive : 9,66,7,8,1,16,148,250,150,55 09420708011094fa9637 Receive : {"remotePingRequest":{"val1":1,"val2":115719444}}

Sending 4,74,2,8,1 044a020801 Sending {"remotePingResponse":{"val1":1}}

proto form is here simple :

RemotePingRequest remote_ping_request = 8; RemotePingResponse remote_ping_response = 9;

message RemotePingResponse { int32 val1 = 1; }

message RemotePingRequest { int32 val1 = 1; int32 val2 = 2; }

You can deduce ping request from https://protogen.marcgravell.com/decode by tapping hex form without length of your buffer : 420708011094fa9637

Field #8: 42 String Length = 7, Hex = 07, UTF8 = "���7" As sub-object : Field #1: 42 Varint Value = 1, Hex = 07 Field #2: 08 Varint Value = 115719444, Hex = 01-10-94-FA

Ganime422 commented 2 years ago

I am not sure I understand your answer. when I get a message from the tv, how can I identify that message as a ping request? I need to parse the bytes into a hex string, and then if the length of the hex string is 7, it means it's a ping request?

louis49 commented 2 years ago

No. You need to analyse the frame - read this doc to understand : https://developers.google.com/protocol-buffers/docs/encoding 1rst byte is the length of the frame 2nd byte is the composition of field number and wire type This second byte is by definition composed of 8 bits 0 or 1 : 10101010 You need to take 5th first bits and convert it to int : it’s your field number => 8 is the ping field number The last 3 bits represent the wire type (2 it’s a embedded messages)