aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/ItsFrameDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-04-13 22:25:50 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-04-13 22:25:50 -0700
commitb595ec1bede3e30447b49bb7340f88c9b3a3f97f (patch)
tree7fa7a21fe803d68032a9ad3301ffb12eb3733b1f /src/main/java/org/traccar/protocol/ItsFrameDecoder.java
parenta3269fda8b77c6af0e810222dae4aff6faf1df3f (diff)
downloadtrackermap-server-b595ec1bede3e30447b49bb7340f88c9b3a3f97f.tar.gz
trackermap-server-b595ec1bede3e30447b49bb7340f88c9b3a3f97f.tar.bz2
trackermap-server-b595ec1bede3e30447b49bb7340f88c9b3a3f97f.zip
Support ITS binary checksum
Diffstat (limited to 'src/main/java/org/traccar/protocol/ItsFrameDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/ItsFrameDecoder.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/protocol/ItsFrameDecoder.java b/src/main/java/org/traccar/protocol/ItsFrameDecoder.java
new file mode 100644
index 000000000..79b341760
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/ItsFrameDecoder.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import org.traccar.BaseFrameDecoder;
+
+public class ItsFrameDecoder extends BaseFrameDecoder {
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
+
+ int delimiterIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+
+ if (buf.writerIndex() > delimiterIndex + 1 && buf.getByte(delimiterIndex + 1) == '*') {
+ delimiterIndex += 1;
+ }
+
+ ByteBuf frame;
+ if (buf.getByte(delimiterIndex - 2) == ',') {
+ frame = buf.readRetainedSlice(delimiterIndex - 1 - buf.readerIndex());
+ buf.skipBytes(1); // binary checksum
+ } else {
+ frame = buf.readRetainedSlice(delimiterIndex - buf.readerIndex());
+ }
+
+ buf.skipBytes(1); // delimiter
+
+ return frame;
+ }
+
+}