From 787f10186dff867f67d5f3f486797d9fb7a70b38 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 21 Mar 2017 19:30:57 +1300 Subject: Implement Ruptela responses --- .../traccar/protocol/RuptelaProtocolDecoder.java | 47 +++++++++++++++++----- .../traccar/protocol/RuptelaProtocolEncoder.java | 2 +- 2 files changed, 39 insertions(+), 10 deletions(-) (limited to 'src/org') 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))); -- cgit v1.2.3