aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/RuptelaProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-03-21 17:09:35 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-03-21 17:09:35 +1300
commitb6bf899a4fc9a97a69f8424cad6990e4d533e57d (patch)
tree54b785cd69b28e4d8598d762b219b70d87bc9d01 /src/org/traccar/protocol/RuptelaProtocolEncoder.java
parent568e88255e282084b8af46aca3acf27f0822b2d2 (diff)
downloadtrackermap-server-b6bf899a4fc9a97a69f8424cad6990e4d533e57d.tar.gz
trackermap-server-b6bf899a4fc9a97a69f8424cad6990e4d533e57d.tar.bz2
trackermap-server-b6bf899a4fc9a97a69f8424cad6990e4d533e57d.zip
Implement more Ruptela commands
Diffstat (limited to 'src/org/traccar/protocol/RuptelaProtocolEncoder.java')
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolEncoder.java34
1 files changed, 28 insertions, 6 deletions
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;