aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/model/Command.java7
-rw-r--r--src/org/traccar/protocol/RuptelaProtocol.java8
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java50
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolEncoder.java34
4 files changed, 89 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;