From d701e4cd549e99c594a7ddf41359b59f34ad2cff Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 9 Apr 2019 21:30:05 -0700 Subject: Support letters in device id --- .../org/traccar/protocol/Tk103ProtocolDecoder.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java index 9e28b5051..feedb2c5e 100644 --- a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 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. @@ -44,7 +44,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("(").optional() - .number("(d+)(,)?") // device id + .groupBegin() + .expression("(.{12})") // device id + .or() + .expression("(.+),") // device id + .groupEnd() .expression("(.{4}),?") // command .number("(d*)") .number("(dd)(dd)(dd),?") // date (mmddyy if comma-delimited, otherwise yyddmm) @@ -371,7 +375,17 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { return null; } - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + String id = null; + boolean alternative = false; + if (parser.hasNext()) { + id = parser.next(); + } + if (parser.hasNext()) { + id = parser.next(); + alternative = true; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; } @@ -379,8 +393,6 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - boolean alternative = parser.next() != null; - decodeType(position, parser.next(), parser.next()); DateBuilder dateBuilder = new DateBuilder(); -- cgit v1.2.3