diff options
-rw-r--r-- | src/org/traccar/protocol/RuptelaProtocolDecoder.java | 47 | ||||
-rw-r--r-- | src/org/traccar/protocol/RuptelaProtocolEncoder.java | 2 | ||||
-rw-r--r-- | test/org/traccar/protocol/RuptelaProtocolDecoderTest.java | 3 |
3 files changed, 42 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java index 1409c7c4d..5e67acc21 100644 --- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java @@ -37,15 +37,42 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { } public static final int MSG_RECORDS = 1; + public static final int MSG_DEVICE_CONFIGURATION = 2; + public static final int MSG_DEVICE_VERSION = 3; + public static final int MSG_FIRMWARE_UPDATE = 4; + public static final int MSG_SET_CONNECTION = 5; + public static final int MSG_SET_ODOMETER = 6; + public static final int MSG_SMS_VIA_GPRS_RESPONSE = 7; + public static final int MSG_SMS_VIA_GPRS = 8; public static final int MSG_DTCS = 9; + public static final int MSG_SET_IO = 17; 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; + + private Position decodeCommandResponse(DeviceSession deviceSession, int type, ChannelBuffer buf) { + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + position.set(Position.KEY_TYPE, type); + + switch (type) { + case MSG_DEVICE_CONFIGURATION: + case MSG_DEVICE_VERSION: + case MSG_FIRMWARE_UPDATE: + case MSG_SMS_VIA_GPRS_RESPONSE: + position.set(Position.KEY_RESULT, + buf.toString(buf.readerIndex(), buf.readableBytes() - 2, StandardCharsets.US_ASCII).trim()); + return position; + case MSG_SET_IO: + position.set(Position.KEY_RESULT, + String.valueOf(buf.readUnsignedByte())); + return position; + default: + return null; + } + } @Override protected Object decode( @@ -173,9 +200,11 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { return positions; - } + } else { + + return decodeCommandResponse(deviceSession, type, buf); - return null; + } } } diff --git a/src/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/org/traccar/protocol/RuptelaProtocolEncoder.java index 420e2cb3d..564d80869 100644 --- a/src/org/traccar/protocol/RuptelaProtocolEncoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolEncoder.java @@ -31,7 +31,7 @@ public class RuptelaProtocolEncoder extends BaseProtocolEncoder { ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); buf.writeShort(1 + content.readableBytes()); - buf.writeByte(type); + buf.writeByte(100 + type); buf.writeBytes(content); buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer(2, buf.writerIndex() - 2))); diff --git a/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java index 2d5fa5e26..50908ad77 100644 --- a/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class RuptelaProtocolDecoderTest extends ProtocolTest { RuptelaProtocolDecoder decoder = new RuptelaProtocolDecoder(new RuptelaProtocol()); + verifyPosition(decoder, binary( + "0011000315A07F440B1D07534554494f20636f6e66696775726174696f6e2064617461206f6b341C")); + verifyPositions(decoder, binary( "000B00000B1A29F64B1A0902FF4E9CAF2C07D608F11A1480BA015030303130FF4E9CAF2C07D608F11A1480BA0250303031318C91")); |