Hi Anton
We have a customize GPS device with custom protocol.
I'm trying to implement it's protocol from the legacy hasty server codes.(I don't have their document)
I almost know what to send and expect what to receive in the decoder class.
My problem when I send the binary data in response to the device it became something else when I look at log .
For example header of response which I'm making is :
private ByteBuf makeHeader() {
ByteBuf response = Unpooled.buffer();
response.writeByte(1);
response.writeByte(0);
response.writeByte(0);
response.writeByte(0);
response.writeByte(0);
response.writeByte(0);
response.writeByte(0);
response.writeByte(0);
response.writeByte(5); //route
return response;
}
but the log is no way the same.
log:
d8: gset < 5.123.213.191] HEX: 0000000000000000007e37470001e84b3836353036373032323739363437310d02050000ffffffffffffffffffff
2021-09-23 11:35:59 INFO: [9fe5b1d8: gset > 5.123.213.191] HEX: 81475052534441544181
81475052534441544181 I don't understand where does this hex come from my protocol
this adds some extra bytes to the final response :
private ByteBuf prepareToSend(ByteBuf message){
ByteBuf response = Unpooled.buffer();
response.writeByte(129); //10000001
response.writeByte(71);//G
response.writeByte(80);//P
response.writeByte(82);//R
response.writeByte(83);//S
response.writeByte(68);//D
response.writeByte(65);//A
response.writeByte(84);//T
response.writeByte(65);//A
response.writeByte(129); //10000001
response.setBytes(response.writerIndex(),message);
return response;
}
These are parts of my code is there some thing wrong with that?
What is setBytes
and how does it work? Why are you not using writeBytes
?
Thanks dear Anton.
It was the first method I found to insert my bytes and the problem was that.
Another question
In the protocol only the first message contains the device id and after that I can not extract device id from messages.
With this situation I can not insert Position without device id
I searched about but no success
You can get device session without id.
Check other protocols that work the same way. For example, GT06.
Ok I look. But I have philosophical question. How does the server recognize the device? Where did we introduced the device to server which this device is the registered device in DB?
Sorry it's bothering me not to ask.
Server recognizes a device by the unique id.
I don't provide the unique id anywhere.
What part of protocol implementation I should do this?
I would recommend studying the code before asking any more questions.
Thanks. Can you just minimize the scope of study and tell me which section I should look?
Thanks again Anton you are Lord Of the GPSs it's working finally.
And thanks for your patience.
Hi Anton
We have a customize GPS device with custom protocol.
I'm trying to implement it's protocol from the legacy hasty server codes.(I don't have their document)
I almost know what to send and expect what to receive in the decoder class.
My problem when I send the binary data in response to the device it became something else when I look at log .
For example header of response which I'm making is :
but the log is no way the same.
log:
81475052534441544181 I don't understand where does this hex come from my protocol
this adds some extra bytes to the final response :
These are parts of my code is there some thing wrong with that?