Skip to content

Commit

Permalink
Fix DSF22 decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Jan 25, 2022
1 parent 5a854ce commit fd536f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/main/java/org/traccar/protocol/Dsf22ProtocolDecoder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Anton Tananaev (anton@traccar.org)
* Copyright 2021 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,6 @@
package org.traccar.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
Expand Down Expand Up @@ -46,7 +45,7 @@ protected Object decode(

buf.skipBytes(2); // header

String id = ByteBufUtil.hexDump(buf.readSlice(2));
String id = String.valueOf(buf.readUnsignedShortLE());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
Expand All @@ -61,12 +60,12 @@ protected Object decode(
position.setDeviceId(deviceSession.getDeviceId());

position.setValid(true);
position.setLatitude(buf.readInt());
position.setLongitude(buf.readInt());
position.setTime(new Date(946684800000L + buf.readUnsignedInt()));
position.setLatitude(buf.readIntLE() / 10000000.0);
position.setLongitude(buf.readIntLE() / 10000000.0);
position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));

position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.001);
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShortLE() * 0.001);

int status = buf.readUnsignedByte();
position.set(Position.KEY_IGNITION, BitUtil.check(status, 0));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.traccar.protocol;

import org.junit.Ignore;
import org.junit.Test;
import org.traccar.ProtocolTest;

@Ignore
public class Dsf22ProtocolDecoderTest extends ProtocolTest {

@Test
public void testDecode() throws Exception {

var decoder = new Dsf22ProtocolDecoder(null);

verifyPositions(decoder, binary(
"4642a82d01c8f6aa1af1792c0c1411eb61001e0000"));

verifyPositions(decoder, binary(
"4642000101A8EE5F0ECA5FF421B33F524E32610401"));

Expand Down

0 comments on commit fd536f9

Please sign in to comment.