From 6271b433cdada9b94b93db7f30bf8f8d7efe4b52 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 12 Feb 2013 23:51:42 +1300 Subject: Improve TK103 protocol decoder --- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 48 +++++++++++----------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 65cf6fcd0..9d28256e3 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,14 +26,8 @@ import org.traccar.ServerManager; import org.traccar.helper.Log; import org.traccar.model.Position; -/** - * Gps 103 tracker protocol decoder - */ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { - /** - * Initialize - */ public Tk103ProtocolDecoder(ServerManager serverManager) { super(serverManager); } @@ -43,31 +37,29 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { */ static private Pattern pattern = Pattern.compile( "\\(" + - "(\\d+)" + // Device ID - "(.{4})" + // Command - "(\\d{15})" + // IMEI (?) + "(\\d{12})" + // Device ID + ".{4}" + // Command + "\\d+" + // IMEI (?) "(\\d{2})(\\d{2})(\\d{2})" + // Date (YYMMDD) "([AV])" + // Validity - "(\\d{2})(\\d{2}\\.\\d{4})" + // Latitude (DDMM.MMMM) + "(\\d{2})(\\d{2}\\.\\d{4})" + // Latitude (DDMM.MMMM) "([NS])" + - "(\\d{3})(\\d{2}\\.\\d{4})" + // Longitude (DDDMM.MMMM) + "(\\d{3})(\\d{2}\\.\\d{4})" + // Longitude (DDDMM.MMMM) "([EW])" + "(\\d+\\.\\d)" + // Speed "(\\d{2})(\\d{2})(\\d{2})" + // Time (HHMMSS) - "(\\d+\\.\\d{2})" + // Course - "(\\d+)" + // State - ".+"); // Mileage (?) + "(\\d+\\.\\d+)" + // Course + "(\\d{8})" + // State + "L([0-9a-fA-F]+)"); // Milage - /** - * Decode message - */ + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { String sentence = (String) msg; - // TODO: Send answer + // TODO: Send answer? //(090411121854AP05) // Parse message @@ -78,12 +70,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - + StringBuilder extendedInfo = new StringBuilder("tk103"); Integer index = 1; - index += 2; // Skip Device ID and command // Get device by IMEI - String imei = parser.group(index++); + String imei = "000" + parser.group(index++); try { position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); } catch(Exception error) { @@ -127,7 +118,18 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { // Course position.setCourse(Double.valueOf(parser.group(index++))); - + + // State + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); + + // Milage + extendedInfo.append(""); + extendedInfo.append(Integer.parseInt(parser.group(index++), 16)); + extendedInfo.append(""); + + position.setExtendedInfo(extendedInfo.toString()); return position; } -- cgit v1.2.3