aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-04-12 22:16:30 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-04-12 22:16:30 -0700
commit826af6579290e9c96a5958115a017297fa6d7f79 (patch)
tree7352b9b03ad302c0f103e6a80bff9e8c1ad013b7 /src/main/java/org/traccar/protocol
parentc850469c29465abb7ed446492d0bd2351b760203 (diff)
downloadtraccar-server-826af6579290e9c96a5958115a017297fa6d7f79.tar.gz
traccar-server-826af6579290e9c96a5958115a017297fa6d7f79.tar.bz2
traccar-server-826af6579290e9c96a5958115a017297fa6d7f79.zip
Implement Xirgo UDP response
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r--src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java b/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
index 6d215e672..08809307f 100644
--- a/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -16,9 +16,11 @@
package org.traccar.protocol;
import io.netty.channel.Channel;
+import io.netty.channel.socket.nio.NioDatagramChannel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
@@ -27,6 +29,7 @@ import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class XirgoProtocolDecoder extends BaseProtocolDecoder {
@@ -174,6 +177,15 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
+
+ if (channel instanceof NioDatagramChannel) {
+ Matcher matcher = Pattern.compile("\\$\\$\\d+,(\\d+),.*,(\\d+)##").matcher(sentence);
+ if (matcher.matches()) {
+ String response = "!UDP_ACK," + matcher.group(1) + "," + matcher.group(2);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
+ }
+ }
+
if (form != null) {
return decodeCustom(channel, remoteAddress, sentence);
} else {
@@ -188,10 +200,14 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
String[] keys = form.split(",");
String[] values = sentence.replace("$$", "").replace("##", "").split(",");
+ if (values.length < keys.length) {
+ return null;
+ }
+
Position position = new Position(getProtocolName());
DateBuilder dateBuilder = new DateBuilder();
- for (int i = 0; i < Math.min(keys.length, values.length); i++) {
+ for (int i = 0; i < keys.length; i++) {
switch (keys[i]) {
case "UID":
case "IM":