Protocol implementation in NodeJS

Malkit Singh7 years ago

Hi All,

I am trying to implement the protocol in NodeJs (I guess its LKGPS protocol).
Here is the link to protocol document
https://drive.google.com/file/d/0Bw13bQgIGLTaSkEzTFJlZjNaWVk/view

As per the document, the device sends 2 types of data

  1. Heartbeat.
  2. GPS data.

Here are few samples of data I am receiving at the server. I made one vanilla server which is listening at some port and console logs the received data.
I am getting data like in buffers like this

{"type":"Buffer","data":[42,72,81,44,52,50,49,48,49,54,57,55,56,55,44,86,49,44,49,49,48,50,53,50,44,65,44,51,48,52,50,46,53,49,49,57,44,78,44,48,55,54,52,49,46,55,48,54,51,44,69,44,48,48,48,46,49,48,44,48,48,48,44,50,53,48,51,49,55,44,70,70,70,70,70,66,70,70,35]}

When I am hex decoding this buffer I am getting this string

2a48512c343231303136393738372c56312c3131303235322c412c333034322e353131392c4e2c30373634312e373036332c452c3030302e31302c3030302c3235303331372c464646464642464623

Which decodes to

*HQ,4210169787,V1,110252,A,3042.5119,N,07641.7063,E,000.10,000,250317,FFFFFBFF#

using https://www.traccar.org/hex-decoder/

This information is perfect. As per the documentation of this protocol, this is heartbeat data because it starts with *HQ and ends with #.

Can you please guide me how to understand last part of this string i.e. FFFFFBFF#
From the documentation I know it's a vehicle status but I don't know how to decode it.

Also. I am getting different types of heart beat messages like these

*HQ,4210169787,V1,110252,A,3042.5119,N,07641.7063,E,000.10,000,250317,FFFFFBFF#
*HQ,4210169787,V19,110253,A,3042.5119,N,07641.7063,E,000.10,000,250317,,,8991184124050941671F,FFFFFBFF#
*HQ,4210169787,V19,110326,A,3042.4700,N,07641.6195,E,000.00,000,250317,,,8991184124050941671F,FFFFFBFF#$...

The first message type is ok but what about second and third messages? Is there anything wrong with my decoding code or these message mean something else?

Coming to the second type of data i.e. GPS data which device sends (as per the documentation this data start with 24).
Here is one sample of this data which I am getting at the server end.

2442101697871103292503173042465006076416360e000000fffffbffff0001

But whenever I try to decode these message using https://www.traccar.org/hex-decoder/
I am getting weird results like

$...binary data

It doesn't decode correctly. What could be the reason for this?

Thanks

Anton Tananaev7 years ago

Vehicle status is a number in HEX format.

If you carefully read the documentation that you referenced, you'll notice that there are two types of messages. One is text-based and the other one is binary. Obviously you can't decode binary message into a text string.

Malkit Singh7 years ago

So, you mean the heartbeat message is the only thing which I should worry about and calculate everything from this?

Anton Tananaev7 years ago

No, that's not what I meant.

Malkit Singh7 years ago

ok I spent some more time to read this document and found "FFFFFBFF" in the end, is in hex format which when converts to decimal gives us 4294966271 and further this is converted in binary gives us 11111111111111111111101111111111 and if I split it into chunks of eight like this 11111111 11111111 11111011 11111111 I can make some information out of it. I am not sure how to decode information from these 0s and 1s based on that document, how should I understand this part? Also Can you please clarify about "negative logic" does this means I consider everything in opposite i.e. 1 means 0 and 0 mean 1?

Anton Tananaev7 years ago

Documentation includes active value column. For example, "Low battery alarm" active value is 0.

jrischma7 years ago

Hi, hex =

24420996067215543031081733259600060703338602000000fffffbfdff00120d0000000002da010000000003333836332c572c3030302e30302c3030302c3331303831372c46464646464246442c3733302c30312c302c302c3623

hex is data packet for LKGPS protocol, this data packet container date,time,odometer, speed, angle, lat, lng,N/S, E/W, imei,battery level, GSM Signal, country code, iccid, baseStation, cellID

the hex is the real GPS LOCATION from LKGPS Protocol, the other only is the heartbeat package

the problem is decode the hex string , when is decode return:

$...3863,W,000.00,000,310817,FFFFFBFD,730,01,0,0,6#

what is the solution for get all data ?

thanks

Anton Tananaev7 years ago

The problem is that you are trying to decode binary data into text. It's never going to work.

jrischma7 years ago

so what is the correct way?

Anton Tananaev7 years ago

Correct way is to decode it as binary data. I'm sure node is capable of handling binary data.

Malkit Singh7 years ago

I have implemented this whole thing in NodeJs. Let me know if anyone needs this protocol decoder ;)

jrischma7 years ago

Thanks Malkit, i need, where can i see it? or send to my mail [removed], regards

Purnesh Tiwari6 years ago

Hi All ,

I am trying to writing the LKGPS protocol decoder in NodeJs.

BufferIN String (input Data):

2a48512c343231303136393738372c56312c3131303235322c412c333034322e353131392c4e2c30373634312e373036332c452c3030302e31302c3030302c3235303331372c464646464642464623

buffer Length : 79

After Decoding input buffer data then i am getting below data
hexdecodedata : *HQ,4210169787,V1,110252,A,3042.5119,N,07641.7063,E,000.10,000,250317,FFFFFBFF#
BitData : 0 - *HQ
BitData : 1 - 4210169787
BitData : 2 - V1
BitData : 3 - 110252
BitData : 4 - A
BitData : 5 - 3042.5119
BitData : 6 - N
BitData : 7 - 07641.7063
BitData : 8 - E
BitData : 9 - 000.10
BitData : 10 - 000
BitData : 11 - 250317
BitData : 12 - FFFFFBFF#

How to parse the or Decode these hexdecodedata and get all information. Please help !

Shaan3 years ago

Please Malkit Singh share the code