traccar icon indicating copy to clipboard operation
traccar copied to clipboard

Complete implementation of huabao protocol (JT808 document attached)

Open K1DV5 opened this issue 3 years ago • 16 comments

I'm using the huabao protocol and I need to get fuel consumption reports. I checked if it is implemented but many things are not implemented for this protocol, including fuel consumption. I checked the linked documents in https://www.traccar.org/protocols/ and those documents are not fully JT808 compliant. I have the full document here. But I have little to no java knowledge. Can you please implement the full location information report protocol, including the fuel level part?

K1DV5 avatar Jun 21 '22 09:06 K1DV5

If you're interested in sponsoring the work, please send us an email. If not, we can leave this here until we have time and enough interest from community to implement this.

tananaev avatar Jun 21 '22 13:06 tananaev

I understand. And I apologize for not checking thoroughly, it seems that fuel level and consumption is implemented. But there are still features not implemented, especially many commands. Will leave it here as you said. Thank you for your work.

K1DV5 avatar Jun 22 '22 18:06 K1DV5

Hi Anton, I want to slowly implement this (and learn java in the process.) I want to start with canbus data uploading (0x0705) and telephone handling (0x8400 and 0x8401). Do you have any suggestion on where I should start?

K1DV5 avatar Jul 17 '22 06:07 K1DV5

Check the decoder class. That's where all the relevant code is.

tananaev avatar Jul 17 '22 14:07 tananaev

Thank you @tananaev. I'm looking at the class and one question came up. The can bus data comes on its own, not attached to the location report. It is a report on its own, with its own interval. So how can I handle that? Should I make it an event? Or something else? If event, how do I do that?

K1DV5 avatar Jul 21 '22 08:07 K1DV5

You still make a position and reuse the last known location. That's a pretty common case.

tananaev avatar Jul 21 '22 13:07 tananaev

Thank you, will continue working on #4904.

K1DV5 avatar Jul 21 '22 13:07 K1DV5

Hi Anton, I implemented 0x0705 (can bus data decoding), wrote a test which passed and all but when I tried it with a real device, I get this log entry:

2022-07-25 14:26:04  WARN: Failed to store position - ERROR: value too long for type character varying(4000) - PSQLException (... < QueryBuilder:472 < DatabaseStorage:89 < DefaultDataHandler:45 < ...)

What I did was decode the data into a list, which can contain several items (frames), convert it into a json string and store it as an attribute using Position.set(). I think the problem is that the attributes column in the database has a type character varying(4000) and the data is more than that. How can I tackle this?

K1DV5 avatar Jul 26 '22 08:07 K1DV5

@tananaev can I just change the column type to character varying (without a limit)? That would change it for all protocols but I don't think it will break anything.

K1DV5 avatar Jul 28 '22 05:07 K1DV5

You can change it locally, but we want to have some limit in the official version.

tananaev avatar Jul 28 '22 12:07 tananaev

Ok can we make it bigger? Like 100k?

K1DV5 avatar Jul 28 '22 12:07 K1DV5

No because it doesn't work on all databases. We already selected the highest limit.

tananaev avatar Jul 28 '22 12:07 tananaev

Ok so I'll save it across multiple positions as a workaround, although I fear it'll perform a little worse and bloat the database.

Another question, is it ok if lists and maps are accepted as position attributes? Because although I can just convert it to a json string (which is what I do now), I think it'll be redundant as it will later be saved as json among the other attributes. I'm asking to add overloads for Position.set that'll accept lists and maps.

K1DV5 avatar Jul 28 '22 13:07 K1DV5

Can you please provide more details on what you're trying to save exactly. It seems weird that 4000 characters is not enough.

tananaev avatar Jul 28 '22 13:07 tananaev

Right, the device sends CAN bus data, good info about the vehicle, in a format most of which is a sequence of 4 byte can id and 8 byte can data.

58f64544 576d358c44365497
58d24344 56654b6557733475
...

The first 3 bits of can id is info about channel, originality and frame type. The rest 29 bits are the frame ID. Then the data follows. The device sends several frames at once and that's where the problem happened. I was trying to store the data as a list of maps.

K1DV5 avatar Jul 28 '22 13:07 K1DV5

Yeah, you should probably split frames.

tananaev avatar Jul 28 '22 15:07 tananaev