aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
diff options
context:
space:
mode:
authorNikolay Vlahovski <nvlahovski@gmail.com>2023-05-17 11:00:43 +0300
committerNikolay Vlahovski <nvlahovski@gmail.com>2023-05-17 11:00:43 +0300
commit7e403cf979d3c01acb5b3dfe0ee37dfa83cba4ff (patch)
treee4e8180b5a6e239279fbc4950b9a6db8409409ff /src/main/java/org/traccar/protocol
parent8ee05feeafbf7c6356e1afd65e140823c717aef8 (diff)
downloadtrackermap-server-7e403cf979d3c01acb5b3dfe0ee37dfa83cba4ff.tar.gz
trackermap-server-7e403cf979d3c01acb5b3dfe0ee37dfa83cba4ff.tar.bz2
trackermap-server-7e403cf979d3c01acb5b3dfe0ee37dfa83cba4ff.zip
Add LengthFieldBasedFrameDecoder to TranSyncProtocol
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r--src/main/java/org/traccar/protocol/TranSyncProtocol.java19
-rw-r--r--src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java15
2 files changed, 33 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/protocol/TranSyncProtocol.java b/src/main/java/org/traccar/protocol/TranSyncProtocol.java
index 0634642df..39db67585 100644
--- a/src/main/java/org/traccar/protocol/TranSyncProtocol.java
+++ b/src/main/java/org/traccar/protocol/TranSyncProtocol.java
@@ -1,5 +1,22 @@
+/*
+ * Copyright 2013 - 2023 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.handler.codec.LengthFieldBasedFrameDecoder;
+import io.netty.handler.codec.LineBasedFrameDecoder;
import org.traccar.BaseProtocol;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
@@ -14,9 +31,9 @@ public class TranSyncProtocol extends BaseProtocol {
addServer(new TrackerServer(config, getName(), false) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) {
+ pipeline.addLast(new LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0, true));
pipeline.addLast(new TranSyncProtocolDecoder(TranSyncProtocol.this));
}
});
}
-
}
diff --git a/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java b/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
index d07b70365..bb8c9bbf9 100644
--- a/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
@@ -17,8 +17,10 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
@@ -106,6 +108,18 @@ public class TranSyncProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private void sendResponse(Channel channel) {
+ if (channel != null) {
+ ByteBuf response = Unpooled.buffer(5);
+ response.writeByte(22);
+ response.writeByte(1);
+ response.writeShort(response.capacity()); // length
+ response.writeByte(4);
+
+ channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
+ }
+ }
+
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
@@ -189,6 +203,7 @@ public class TranSyncProtocolDecoder extends BaseProtocolDecoder {
}
}
}
+ sendResponse(channel);
return position;
}
}