aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/CastelProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-02-19 11:16:42 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-02-19 11:16:42 +1300
commitb178acdc21483cc7bd9588453a4d8afc476ca294 (patch)
tree39458bdb15464823e848e0ffa09eca06d957a6d8 /src/org/traccar/protocol/CastelProtocolDecoder.java
parent1f4a8c8af7b67f0b48f30a442c74fbfcf7ccbe97 (diff)
downloadtrackermap-server-b178acdc21483cc7bd9588453a4d8afc476ca294.tar.gz
trackermap-server-b178acdc21483cc7bd9588453a4d8afc476ca294.tar.bz2
trackermap-server-b178acdc21483cc7bd9588453a4d8afc476ca294.zip
Fix check style and pmd issues
Diffstat (limited to 'src/org/traccar/protocol/CastelProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
index 3179cbd78..9f332dd04 100644
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/org/traccar/protocol/CastelProtocolDecoder.java
@@ -109,6 +109,28 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private void sendResponse(
+ Channel channel, SocketAddress remoteAddress, ChannelBuffer id, short type) {
+
+ if (channel != null) {
+ int length = 2 + 2 + id.readableBytes() + 2 + 4 + 8 + 2 + 2;
+
+ ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
+ response.writeByte('@'); response.writeByte('@');
+ response.writeShort(length);
+ response.writeBytes(id);
+ response.writeShort(ChannelBuffers.swapShort(type));
+ response.writeInt(0);
+ for (int i = 0; i < 8; i++) {
+ response.writeByte(0xff);
+ }
+ response.writeShort(
+ Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex())));
+ response.writeByte(0x0D); response.writeByte(0x0A);
+ channel.write(response, remoteAddress);
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -134,23 +156,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
if (type == 0x2001) {
- if (channel != null) {
- int length = 2 + 2 + id.readableBytes() + 2 + 4 + 8 + 2 + 2;
-
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
- response.writeByte('@'); response.writeByte('@');
- response.writeShort(length);
- response.writeBytes(id);
- response.writeShort(ChannelBuffers.swapShort((short) 0x1001));
- response.writeInt(0);
- for (int i = 0; i < 8; i++) {
- response.writeByte(0xff);
- }
- response.writeShort(
- Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex())));
- response.writeByte(0x0D); response.writeByte(0x0A);
- channel.write(response, remoteAddress);
- }
+ sendResponse(channel, remoteAddress, id, (short) 0x1001);
buf.readUnsignedInt(); // index
buf.readUnsignedInt(); // unix time