diff options
-rw-r--r-- | src/org/traccar/model/Command.java | 7 | ||||
-rw-r--r-- | src/org/traccar/protocol/RuptelaProtocol.java | 8 | ||||
-rw-r--r-- | src/org/traccar/protocol/RuptelaProtocolDecoder.java | 50 | ||||
-rw-r--r-- | src/org/traccar/protocol/RuptelaProtocolEncoder.java | 34 | ||||
-rw-r--r-- | test/org/traccar/protocol/RuptelaProtocolDecoderTest.java | 3 |
5 files changed, 92 insertions, 10 deletions
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index 016862214..190c0d753 100644 --- a/src/org/traccar/model/Command.java +++ b/src/org/traccar/model/Command.java @@ -42,6 +42,11 @@ public class Command extends Message { public static final String TYPE_VOICE_MONITORING = "voiceMonitoring"; public static final String TYPE_SET_AGPS = "setAgps"; public static final String TYPE_SET_INDICATOR = "setIndicator"; + public static final String TYPE_CONFIGURATION = "configuration"; + public static final String TYPE_GET_VERSION = "getVersion"; + public static final String TYPE_FIRMWARE_UPDATE = "firmwareUpdate"; + public static final String TYPE_SET_CONNECTION = "setConnection"; + public static final String TYPE_SET_ODOMETER = "setOdometer"; public static final String TYPE_MODE_POWER_SAVING = "modePowerSaving"; public static final String TYPE_MODE_DEEP_SLEEP = "modeDeepSleep"; @@ -65,6 +70,8 @@ public class Command extends Message { public static final String KEY_DATA = "data"; public static final String KEY_INDEX = "index"; public static final String KEY_PHONE = "phone"; + public static final String KEY_SERVER = "server"; + public static final String KEY_PORT = "port"; private boolean textChannel; diff --git a/src/org/traccar/protocol/RuptelaProtocol.java b/src/org/traccar/protocol/RuptelaProtocol.java index 4be07307d..fc3b17dd9 100644 --- a/src/org/traccar/protocol/RuptelaProtocol.java +++ b/src/org/traccar/protocol/RuptelaProtocol.java @@ -29,7 +29,13 @@ public class RuptelaProtocol extends BaseProtocol { public RuptelaProtocol() { super("ruptela"); setSupportedDataCommands( - Command.TYPE_CUSTOM); + Command.TYPE_CUSTOM, + Command.TYPE_CONFIGURATION, + Command.TYPE_GET_VERSION, + Command.TYPE_FIRMWARE_UPDATE, + Command.TYPE_OUTPUT_CONTROL, + Command.TYPE_SET_CONNECTION, + Command.TYPE_SET_ODOMETER); } @Override diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java index 461f9abc0..1409c7c4d 100644 --- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2017 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. @@ -23,7 +23,9 @@ import org.traccar.DeviceSession; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; +import javax.xml.bind.DatatypeConverter; import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -35,8 +37,15 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { } public static final int MSG_RECORDS = 1; + public static final int MSG_DTCS = 9; public static final int MSG_EXTENDED_RECORDS = 68; + public static final int MSG_DEVICE_CONFIGURATION = 102; + public static final int MSG_DEVICE_VERSION = 103; + public static final int MSG_FIRMWARE_UPDATE = 104; + public static final int MSG_SET_CONNECTION = 105; + public static final int MSG_SET_ODOMETER = 106; public static final int MSG_SMS_VIA_GPRS = 108; + public static final int MSG_SET_IO = 117; @Override protected Object decode( @@ -55,6 +64,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); if (type == MSG_RECORDS || type == MSG_EXTENDED_RECORDS) { + List<Position> positions = new LinkedList<>(); buf.readUnsignedByte(); // records left @@ -124,11 +134,45 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { } if (channel != null) { - byte[] response = {0x00, 0x02, 0x64, 0x01, 0x13, (byte) 0xbc}; - channel.write(ChannelBuffers.wrappedBuffer(response)); // acknowledgement + channel.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary("0002640113bc"))); + } + + return positions; + + } else if (type == MSG_DTCS) { + + List<Position> positions = new LinkedList<>(); + + int count = buf.readUnsignedByte(); + + for (int i = 0; i < count; i++) { + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + buf.readUnsignedByte(); // reserved + + position.setTime(new Date(buf.readUnsignedInt() * 1000)); + + position.setValid(true); + position.setLongitude(buf.readInt() / 10000000.0); + position.setLatitude(buf.readInt() / 10000000.0); + + if (buf.readUnsignedByte() == 2) { + position.set(Position.KEY_ARCHIVE, true); + } + + position.set(Position.KEY_DTCS, buf.readBytes(5).toString(StandardCharsets.US_ASCII)); + + positions.add(position); + } + + if (channel != null) { + channel.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary("00026d01c4a4"))); } return positions; + } return null; diff --git a/src/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/org/traccar/protocol/RuptelaProtocolEncoder.java index 0abfa18ce..420e2cb3d 100644 --- a/src/org/traccar/protocol/RuptelaProtocolEncoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2017 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. @@ -26,13 +26,13 @@ import java.nio.charset.StandardCharsets; public class RuptelaProtocolEncoder extends BaseProtocolEncoder { - private ChannelBuffer encodeContent(String content) { + private ChannelBuffer encodeContent(int type, ChannelBuffer content) { ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - buf.writeShort(1 + content.length()); - buf.writeByte(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS); - buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII)); + buf.writeShort(1 + content.readableBytes()); + buf.writeByte(type); + buf.writeBytes(content); buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer(2, buf.writerIndex() - 2))); return buf; @@ -41,9 +41,31 @@ public class RuptelaProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { + ChannelBuffer content = ChannelBuffers.dynamicBuffer(); + switch (command.getType()) { case Command.TYPE_CUSTOM: - return encodeContent(command.getString(Command.KEY_DATA)); + content.writeBytes(command.getString(Command.KEY_DATA).getBytes(StandardCharsets.US_ASCII)); + return encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content); + case Command.TYPE_CONFIGURATION: + content.writeBytes((command.getString(Command.KEY_DATA) + "\r\n").getBytes(StandardCharsets.US_ASCII)); + return encodeContent(RuptelaProtocolDecoder.MSG_DEVICE_CONFIGURATION, content); + case Command.TYPE_GET_VERSION: + return encodeContent(RuptelaProtocolDecoder.MSG_DEVICE_VERSION, content); + case Command.TYPE_FIRMWARE_UPDATE: + content.writeBytes("|FU_STRT*\r\n".getBytes(StandardCharsets.US_ASCII)); + return encodeContent(RuptelaProtocolDecoder.MSG_FIRMWARE_UPDATE, content); + case Command.TYPE_OUTPUT_CONTROL: + content.writeInt(command.getInteger(Command.KEY_INDEX)); + content.writeInt(Integer.parseInt(command.getString(Command.KEY_DATA))); + return encodeContent(RuptelaProtocolDecoder.MSG_SET_IO, content); + case Command.TYPE_SET_CONNECTION: + String c = command.getString(Command.KEY_SERVER) + "," + command.getInteger(Command.KEY_PORT) + ",TCP"; + content.writeBytes(c.getBytes(StandardCharsets.US_ASCII)); + return encodeContent(RuptelaProtocolDecoder.MSG_SET_CONNECTION, content); + case Command.TYPE_SET_ODOMETER: + content.writeInt(Integer.parseInt(command.getString(Command.KEY_DATA))); + return encodeContent(RuptelaProtocolDecoder.MSG_SET_ODOMETER, content); default: Log.warning(new UnsupportedOperationException(command.getType())); break; diff --git a/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java index cc457efca..2d5fa5e26 100644 --- a/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class RuptelaProtocolDecoderTest extends ProtocolTest { RuptelaProtocolDecoder decoder = new RuptelaProtocolDecoder(new RuptelaProtocol()); verifyPositions(decoder, binary( + "000B00000B1A29F64B1A0902FF4E9CAF2C07D608F11A1480BA015030303130FF4E9CAF2C07D608F11A1480BA0250303031318C91")); + + verifyPositions(decoder, binary( "01a4000315bc70f9b69244000458068f4a0030000d11398a1c0c19fd056524040b000c0a00090c0005010031f40032fd0033f200ce47002400002500001c010199000195010196010086000900aa0000001e0ff000d3ffff0043ffff01930000019200000194000002220000022300000200300000000200af000e872401008e000000000000000058068f4a0031000d11398a1c0c19fd056524040b000c0a00090400870000880000a90000820010008b0002021e0000021f0000021d0000021c0000022400000225000000890000008505f00220000002210000008300000084000002260000022700000228000003008a00000000008d00000000008c000000000058068f4a0032000d11398a1c0c19fd056524040b000c0a000905019f01005800001b1f00ad0000cfb10b02290000022a0000022b0000022c0000022d00000012000000130000001d367400c52f8000740055023e0502060097000000000096000058520041007746cb00d0000003f1005c0007c21b0072001864880058068f4a0033000d11398a1c0c19fd056524040b000c0a000900000001008e0000000000000000e815")); verifyPositions(decoder, binary( |