diff options
-rw-r--r-- | src/org/traccar/helper/ObdDecoder.java | 14 | ||||
-rw-r--r-- | src/org/traccar/protocol/CastelProtocolDecoder.java | 51 | ||||
-rw-r--r-- | test/org/traccar/protocol/CastelProtocolDecoderTest.java | 12 |
3 files changed, 66 insertions, 11 deletions
diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java index 4686aa682..6ffe39662 100644 --- a/src/org/traccar/helper/ObdDecoder.java +++ b/src/org/traccar/helper/ObdDecoder.java @@ -25,9 +25,9 @@ public final class ObdDecoder { private ObdDecoder() { } - public static final int MODE_CURRENT = 0x01; - public static final int MODE_FREEZE_FRAME = 0x02; - public static final int MODE_CODES = 0x03; + private static final int MODE_CURRENT = 0x01; + private static final int MODE_FREEZE_FRAME = 0x02; + private static final int MODE_CODES = 0x03; private static final int PID_ENGINE_LOAD = 0x04; private static final int PID_COOLANT_TEMPERATURE = 0x05; @@ -54,7 +54,7 @@ public final class ObdDecoder { return new AbstractMap.SimpleEntry<>(key, value); } - private static Map.Entry<String, Object> decodeCodes(String value) { + public static Map.Entry<String, Object> decodeCodes(String value) { StringBuilder codes = new StringBuilder(); for (int i = 0; i < value.length() / 4; i++) { int numValue = Integer.parseInt(value.substring(i * 4, (i + 1) * 4), 16); @@ -75,7 +75,11 @@ public final class ObdDecoder { } codes.append(String.format("%04X", numValue & 0x3FFF)); } - return createEntry("dtcs", codes.toString().replaceFirst(",", "")); + if (codes.length() > 0) { + return createEntry("dtcs", codes.toString().replaceFirst(",", "")); + } else { + return null; + } } private static Map.Entry<String, Object> decodeData(int pid, String value) { diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 38fb11164..b8faed077 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -22,6 +22,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; +import org.traccar.helper.ObdDecoder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -43,7 +44,13 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { private static final short MSG_SC_HEARTBEAT = 0x1003; private static final short MSG_SC_HEARTBEAT_RESPONSE = (short) 0x9003; private static final short MSG_SC_GPS = 0x4001; + private static final short MSG_SC_PID_DATA = 0x4002; + private static final short MSG_SC_SUPPORTED_PID = 0x4004; + private static final short MSG_SC_OBD_DATA = 0x4005; + private static final short MSG_SC_DTCS_PASSENGER = 0x4006; + private static final short MSG_SC_DTCS_COMMERCIAL = 0x400B; private static final short MSG_SC_ALARM = 0x4007; + private static final short MSG_SC_CELL = 0x4008; private static final short MSG_SC_GPS_SLEEP = 0x4009; private static final short MSG_SC_AGPS_REQUEST = 0x5101; private static final short MSG_SC_CURRENT_LOCATION = (short) 0xB001; @@ -193,6 +200,50 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return readPosition(deviceSession, buf); + } else if (type == MSG_SC_DTCS_PASSENGER) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + buf.skipBytes(6 * 4 + 2 + 8); + + buf.readUnsignedByte(); // flag + position.add(ObdDecoder.decodeCodes(ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte())))); + + return position; + + } else if (type == MSG_SC_OBD_DATA) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + buf.skipBytes(6 * 4 + 2 + 8); + + // decode data + + return position; + + } else if (type == MSG_SC_CELL) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + buf.skipBytes(6 * 4 + 2 + 8); + + position.set(Position.KEY_LAC, buf.readUnsignedShort()); + position.set(Position.KEY_CID, buf.readUnsignedShort()); + + return position; + } return null; diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java index a5b477ea5..ccdd6f726 100644 --- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java @@ -18,10 +18,10 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40407800043231334e583230313630303131373700000000004004fa52ce574b53ce57cad1020041020000050c00000d0000000400036401240b0503001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021384e0d0a")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040a600043231334e583230313630303131373700000000004005fa52ce575053ce57cad102006b020000050c00000d0000000400036401240b050300001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021015bd604301f500600000653000000bc0bffff78250000ff2d98642401000f8080e038000f0f0000000000000077b10d0a")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40404300043231334e583230313630303131373700000000004006fa52ce574e53ce57cad1020053020000050c00000d0000000400036401240b0503000000feec0d0a")); verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -54,10 +54,10 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40405900043130303131313235323939383700000000000000400101C1F06952E7F069529C9111000000000069830000070000000400036401014C00030001190A0D0412041480D60488C57218000000009F01E803ED9A0D0A")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040B9000431303031313132353239393837000000000000004005C1F069521BF169529C9111000000000069830000130000000400036401014C0003000022032104210521062107210C210D210E210F2110211121132115211C211F21212124212E212F2130213121322133213C214221432144214521472149214A214C214D214E210100643B6232E803003E64280A3C24FE00010E010F00D5805A483C640000000000010000E02E000000066400000500000000A7710D0A")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "404043000431303031313132353239393837000000000000004006C1F0695209F169529C91110000000000698300000D0000000400036401014C00030000009AF40D0A")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -72,7 +72,7 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40405c000c363131313530303030393536000000000000000040011c0a0f0e362dca53cd0860831303000000000300000000ff000000000000007ba083a650542d3639305f56312e312e320050542d3639302056312e32008a020d0a")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040450004323132474c31313433303035303033000000000040082ca89b55a6a99b555c57000000000000c40200000b0000001400036401111f000302f5533bd653f10d0a")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -81,7 +81,7 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040420004323132474c31313433303035303033000000000010022ca89b55cca99b555c57000000000000cf0200000b0000000000036401111f0000020013be0d0a")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040870004323132474c31313433303035303033000000000040052ca89b55e3a89b555c57000000000000c4020000040000001400036401111f0003000012042105210b210c210d210f211021112113211c2121212321242133213421422146214f212b50663603003ce9030dff060000600dffffc25865ffff9e02b43624000000003cbc0d0a")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, |