From 81beb5afb946d8c9ccfa2bbdfcfe884771a5bd3b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 2 May 2013 22:16:14 +1200 Subject: Fix extended info XML format --- src/org/traccar/model/ExtendedInfoFormatter.java | 47 ++++++++++++ src/org/traccar/protocol/Avl08ProtocolDecoder.java | 58 ++++----------- .../traccar/protocol/CarscopProtocolDecoder.java | 11 ++- .../protocol/CellocatorProtocolDecoder.java | 9 ++- src/org/traccar/protocol/Ev603ProtocolDecoder.java | 19 +---- .../traccar/protocol/GalileoProtocolDecoder.java | 15 ++-- .../traccar/protocol/Gps103ProtocolDecoder.java | 7 +- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 29 +++----- src/org/traccar/protocol/H02ProtocolDecoder.java | 3 +- .../protocol/IntellitracProtocolDecoder.java | 23 +++--- .../traccar/protocol/MegastekProtocolDecoder.java | 27 +++---- .../traccar/protocol/MeiligaoProtocolDecoder.java | 40 +++-------- .../traccar/protocol/MeitrackProtocolDecoder.java | 36 +++------- src/org/traccar/protocol/Mta6ProtocolDecoder.java | 83 +++++++++------------- .../traccar/protocol/NavigilProtocolDecoder.java | 13 ++-- src/org/traccar/protocol/NavisProtocolDecoder.java | 76 +++++--------------- .../traccar/protocol/ProgressProtocolDecoder.java | 33 +++------ src/org/traccar/protocol/Pt502ProtocolDecoder.java | 17 +---- .../traccar/protocol/SkypatrolProtocolDecoder.java | 19 ++--- src/org/traccar/protocol/St210ProtocolDecoder.java | 3 +- src/org/traccar/protocol/SyrusProtocolDecoder.java | 3 +- .../traccar/protocol/TeltonikaProtocolDecoder.java | 19 ++--- src/org/traccar/protocol/Tk102ProtocolDecoder.java | 3 +- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 14 ++-- src/org/traccar/protocol/Tlt2hProtocolDecoder.java | 11 +-- src/org/traccar/protocol/Tr20ProtocolDecoder.java | 15 +--- src/org/traccar/protocol/V680ProtocolDecoder.java | 19 ++--- .../traccar/protocol/WialonProtocolDecoder.java | 7 +- .../traccar/protocol/WondexProtocolDecoder.java | 37 +++------- .../traccar/protocol/Xexun2ProtocolDecoder.java | 32 +++------ src/org/traccar/protocol/Xt7ProtocolDecoder.java | 31 +++----- src/org/traccar/protocol/YwtProtocolDecoder.java | 13 ++-- 32 files changed, 268 insertions(+), 504 deletions(-) create mode 100644 src/org/traccar/model/ExtendedInfoFormatter.java (limited to 'src/org/traccar') diff --git a/src/org/traccar/model/ExtendedInfoFormatter.java b/src/org/traccar/model/ExtendedInfoFormatter.java new file mode 100644 index 000000000..e17c96cb8 --- /dev/null +++ b/src/org/traccar/model/ExtendedInfoFormatter.java @@ -0,0 +1,47 @@ +/* + * Copyright 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. + * 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.model; + +/** + * Format extended tracker status + */ +public class ExtendedInfoFormatter { + + private static final String rootNode = "info"; + + private StringBuilder data; + + public ExtendedInfoFormatter(String protocol) { + data = new StringBuilder(); + data.append("<").append(rootNode).append(">"); + data.append("").append(protocol).append(""); + } + + public void set(String key, Object value) { + if (value != null) { + data.append("<").append(key).append(">"); + data.append(value); + data.append(""); + } + } + + @Override + public String toString() { + data.append(""); + return data.toString(); + } + +} diff --git a/src/org/traccar/protocol/Avl08ProtocolDecoder.java b/src/org/traccar/protocol/Avl08ProtocolDecoder.java index 7cd64ad2b..c08b56129 100644 --- a/src/org/traccar/protocol/Avl08ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl08ProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; /** @@ -84,7 +85,7 @@ public class Avl08ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("avl08"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("avl08"); Integer index = 1; @@ -98,9 +99,7 @@ public class Avl08ProtocolDecoder extends BaseProtocolDecoder { } // Alarm type - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("alarm", parser.group(index++)); // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); @@ -146,65 +145,38 @@ public class Avl08ProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); // Dilution of precision - extendedInfo.append(""); - extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); - extendedInfo.append(""); - extendedInfo.append(""); - extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); - extendedInfo.append(""); - extendedInfo.append(""); - extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); - extendedInfo.append(""); + extendedInfo.set("pdop", parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.set("hdop", parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.set("vdop", parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); // Status - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("status", parser.group(index++)); // Real time clock - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("clock", parser.group(index++)); // Voltage String voltage = parser.group(index++); position.setPower(Double.valueOf(voltage.substring(1, 4)) / 100); - extendedInfo.append(""); - extendedInfo.append(voltage); - extendedInfo.append(""); + extendedInfo.set("voltage", voltage); // ADC - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("adc", parser.group(index++)); // Cell - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("cell", parser.group(index++)); // Temperature - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("temperature", parser.group(index++)); // Mileage - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("mileage", parser.group(index++)); // Serial - extendedInfo.append(""); - extendedInfo.append(parser.group(index++).replaceFirst ("^0*", "")); - extendedInfo.append(""); + extendedInfo.set("serial", parser.group(index++).replaceFirst ("^0*", "")); // RFID - String rfid = parser.group(index++); - if (rfid != null) { - extendedInfo.append(""); - extendedInfo.append(rfid); - extendedInfo.append(""); - } + extendedInfo.set("rfid", parser.group(index++)); // Extended info position.setExtendedInfo(extendedInfo.toString()); diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java index accc04ebd..93354498a 100644 --- a/src/org/traccar/protocol/CarscopProtocolDecoder.java +++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class CarscopProtocolDecoder extends BaseProtocolDecoder { @@ -79,7 +80,7 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(deviceId); - StringBuilder extendedInfo = new StringBuilder("carscop"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("carscop"); index = 1; // Time @@ -120,14 +121,10 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder { position.setCourse(Double.valueOf(parser.group(index++))); // State - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("state", parser.group(index++)); // Milage - extendedInfo.append(""); - extendedInfo.append(Integer.valueOf(parser.group(index++))); - extendedInfo.append(""); + extendedInfo.set("milage", Integer.valueOf(parser.group(index++))); position.setExtendedInfo(extendedInfo.toString()); return position; diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java index aabda6f51..3ca7853e0 100644 --- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java @@ -25,6 +25,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class CellocatorProtocolDecoder extends BaseProtocolDecoder { @@ -102,7 +103,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { // Parse location if (type == MSG_CLIENT_STATUS) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("cellocator"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("cellocator"); // Device identifier try { @@ -117,9 +118,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // protocol version // Status - extendedInfo.append(""); - extendedInfo.append(buf.getUnsignedByte(buf.readerIndex()) & 0x0f); - extendedInfo.append(""); + extendedInfo.set("status", buf.getUnsignedByte(buf.readerIndex()) & 0x0f); int operator = (buf.readUnsignedByte() & 0xf0) << 4; operator += buf.readUnsignedByte(); @@ -131,7 +130,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { operator <<= 8; operator += buf.readUnsignedByte(); - extendedInfo.append("").append(operator).append(""); + extendedInfo.set("operator", operator); buf.readUnsignedInt(); // ADC buf.readUnsignedMedium(); // milage diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java index e80717cdf..322d7dd61 100644 --- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ev603ProtocolDecoder.java @@ -25,28 +25,17 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; -/** - * Ev603 Protocol Decoder - */ public class Ev603ProtocolDecoder extends BaseProtocolDecoder{ - /** - * Device ID - */ private Long deviceId; - /** - * Initialize - */ public Ev603ProtocolDecoder(ServerManager serverManager) { super(serverManager); } - /** - * Regular expressions pattern - */ static private Pattern pattern = Pattern.compile( "!A," + // Type "(\\d{2})\\/(\\d{2})\\/(\\d{2})," + // Date dd/mm/YY @@ -57,9 +46,7 @@ public class Ev603ProtocolDecoder extends BaseProtocolDecoder{ "(\\d+\\.?\\d+)," + // Course ".*"); - /** - * Decode message - */ + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { @@ -87,7 +74,7 @@ public class Ev603ProtocolDecoder extends BaseProtocolDecoder{ // Create new position Position position = new Position(); position.setDeviceId(deviceId); - StringBuilder extendedInfo = new StringBuilder("ev603"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("ev603"); Integer index = 1; // Date diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java index 62669eb1c..d56bc0f6d 100644 --- a/src/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java @@ -29,6 +29,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class GalileoProtocolDecoder extends BaseProtocolDecoder { @@ -98,7 +99,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("galileo"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("galileo"); while (buf.readerIndex() < length) { int tag = buf.readUnsignedByte(); @@ -134,9 +135,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { break; case TAG_STATUS: - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); + extendedInfo.set("status", buf.readUnsignedShort()); break; case TAG_POWER: @@ -144,15 +143,11 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { break; case TAG_BATTERY: - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); + extendedInfo.set("battery", buf.readUnsignedShort()); break; case TAG_MILAGE: - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedInt()); - extendedInfo.append(""); + extendedInfo.set("milage", buf.readUnsignedInt()); break; default: diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 9646a5e6c..344d985e9 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Gps103ProtocolDecoder extends BaseProtocolDecoder { @@ -85,7 +86,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("gps103"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("gps103"); Integer index = 1; @@ -99,9 +100,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } // Alarm message - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("alarm", parser.group(index++)); // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 741841a11..a0113b362 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -25,6 +25,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Crc; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Gt06ProtocolDecoder extends BaseProtocolDecoder { @@ -108,7 +109,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(deviceId); - StringBuilder extendedInfo = new StringBuilder("gt06"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("gt06"); // Date and time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); @@ -123,9 +124,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { // GPS length and Satellites count int gpsLength = buf.readUnsignedByte(); - extendedInfo.append(""); - extendedInfo.append(gpsLength & 0xf); - extendedInfo.append(""); + extendedInfo.set("satellites", gpsLength & 0xf); gpsLength >>= 4; // Latitude @@ -158,32 +157,22 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } // Cell information - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort() << 8 + buf.readUnsignedByte()); - extendedInfo.append(""); + extendedInfo.set("mcc", buf.readUnsignedShort()); + extendedInfo.set("mnc", buf.readUnsignedByte()); + extendedInfo.set("lac", buf.readUnsignedShort()); + extendedInfo.set("cell", buf.readUnsignedShort() << 8 + buf.readUnsignedByte()); buf.skipBytes(lbsLength - 9); // Status if (type == MSG_GPS_LBS_STATUS) { int flags = buf.readUnsignedByte(); // TODO parse flags - extendedInfo.append("true"); + extendedInfo.set("alarm", true); // Voltage position.setPower((double) buf.readUnsignedByte()); // GSM signal - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); + extendedInfo.set("gsm", buf.readUnsignedByte()); } } diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 1163ac75d..0b6d9e560 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class H02ProtocolDecoder extends BaseProtocolDecoder { @@ -64,7 +65,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("h02"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("h02"); Integer index = 1; diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java index 7b1cb3880..de1ce35de 100644 --- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java +++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class IntellitracProtocolDecoder extends BaseProtocolDecoder { @@ -36,8 +37,8 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { "(?:.+,)?(\\d+)," + // Device Identifier "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) - "(\\d+\\.\\d+)," + // Longitude - "(\\d+\\.\\d+)," + // Latitude + "(-?\\d+\\.\\d+)," + // Longitude + "(-?\\d+\\.\\d+)," + // Latitude "(\\d+\\.?\\d*)," + // Speed "(\\d+\\.?\\d*)," + // Course "(\\d+\\.?\\d*)," + // Altitude @@ -63,7 +64,7 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("intellitrac"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("intellitrac"); Integer index = 1; // Detect device @@ -96,33 +97,27 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { // Satellites int satellites = Integer.valueOf(parser.group(index++)); position.setValid(satellites >= 3); - extendedInfo.append(""); - extendedInfo.append(satellites); - extendedInfo.append(""); + extendedInfo.set("satellites", satellites); // Report identifier position.setId(Long.valueOf(parser.group(index++))); // Input - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("input", parser.group(index++)); // Output - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("output", parser.group(index++)); // ADC1 String adc1 = parser.group(index++); if (adc1 != null) { - extendedInfo.append("").append(adc1).append(""); + extendedInfo.set("adc1", adc1); } // ADC2 String adc2 = parser.group(index++); if (adc2 != null) { - extendedInfo.append("").append(adc2).append(""); + extendedInfo.set("adc2", adc2); } position.setExtendedInfo(extendedInfo.toString()); diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 0a25f0b4a..649e9c45e 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class MegastekProtocolDecoder extends BaseProtocolDecoder { @@ -73,7 +74,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("megastek"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("megastek"); int index = 1; // Time @@ -121,9 +122,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); // Alarm - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("alarm", parser.group(index++)); // IMEI String imei = parser.group(index++); @@ -137,9 +136,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { // Satellites String satellites = parser.group(index++); if (satellites != null) { - extendedInfo.append(""); - extendedInfo.append(satellites); - extendedInfo.append(""); + extendedInfo.set("satellites", satellites); } // Altitude @@ -151,25 +148,17 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { // Charger String charger = parser.group(index++); if (charger != null) { - extendedInfo.append(""); - extendedInfo.append(Integer.valueOf(charger) == 1); - extendedInfo.append(""); + extendedInfo.set("charger", Integer.valueOf(charger) == 1); } // MCC - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("mcc", parser.group(index++)); // MNC - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("mnc", parser.group(index++)); // LAC - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("lac", parser.group(index++)); // Extended info position.setExtendedInfo(extendedInfo.toString()); diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 1d2b6584d..42d7ca350 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -29,6 +29,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Crc; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { @@ -37,12 +38,6 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - //"134743.003,A,0648.9866,S,10707.5795,E,000.0,000.0,260313" - //,,*38|0.8|245|2000|03F6,0000,0000,001C,0000,0000,0000,0000|0194000201CC627C|1A|01160849yt - - /** - * Regular expressions pattern - */ static private Pattern pattern = Pattern.compile( "(\\d{2})(\\d{2})(\\d{2})\\.(\\d+)," + // Time (HHMMSS.SSS) "([AV])," + // Validity @@ -121,13 +116,11 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("meiligao"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("meiligao"); // Alarm if (command == 0x9999) { - extendedInfo.append(""); - extendedInfo.append(buf.getUnsignedByte(offset)); - extendedInfo.append(""); + extendedInfo.set("alarm", buf.getUnsignedByte(offset)); } // Data offset @@ -200,12 +193,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); // Dilution of precision - String hdop = parser.group(index++); - if (hdop != null) { - extendedInfo.append(""); - extendedInfo.append(hdop); - extendedInfo.append(""); - } + extendedInfo.set("hdop", parser.group(index++)); // Altitude String altitude = parser.group(index++); @@ -218,43 +206,33 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { // State String state = parser.group(index++); if (state != null) { - extendedInfo.append(""); - extendedInfo.append(state); - extendedInfo.append(""); + extendedInfo.set("state", state); } // ADC for (int i = 1; i <= 8; i++) { String adc = parser.group(index++); if (adc != null) { - extendedInfo.append(""); - extendedInfo.append(Integer.parseInt(adc, 16)); - extendedInfo.append(""); + extendedInfo.set("adc" + i, Integer.parseInt(adc, 16)); } } // Cell identifier String cell = parser.group(index++); if (cell != null) { - extendedInfo.append(""); - extendedInfo.append(cell); - extendedInfo.append(""); + extendedInfo.set("cell", cell); } // GSM signal String gsm = parser.group(index++); if (gsm != null) { - extendedInfo.append(""); - extendedInfo.append(Integer.parseInt(gsm, 16)); - extendedInfo.append(""); + extendedInfo.set("gsm", Integer.parseInt(gsm, 16)); } // Milage String milage = parser.group(index++); if (milage != null) { - extendedInfo.append(""); - extendedInfo.append(Integer.parseInt(milage, 16)); - extendedInfo.append(""); + extendedInfo.set("milage", Integer.parseInt(milage, 16)); } // Extended info diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 87d222c37..e3b5187f4 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -24,23 +24,15 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; -/** - * Meitrack protocol decoder - */ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { - /** - * Initialize - */ public MeitrackProtocolDecoder(ServerManager serverManager) { super(serverManager); } - /** - * Regular expressions pattern - */ static private Pattern pattern = Pattern.compile( "\\$\\$." + // Flag "\\d+," + // Length @@ -61,9 +53,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { "(\\d+)," + // Milage ".*"); // TODO: parse other stuff - /** - * Decode message - */ + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { @@ -77,7 +67,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("meitrack"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("meitrack"); Integer index = 1; @@ -91,9 +81,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } // Event - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("event", parser.group(index++)); // Coordinates position.setLatitude(Double.valueOf(parser.group(index++))); @@ -114,14 +102,10 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); // Satellites - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("satellites", parser.group(index++)); // GSM Signal - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("gsm", parser.group(index++)); // Speed position.setSpeed(Double.valueOf(parser.group(index++))); @@ -130,17 +114,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.setCourse(Double.valueOf(parser.group(index++))); // HDOP - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("hdop", parser.group(index++)); // Altitude position.setAltitude(Double.valueOf(parser.group(index++))); // Milage - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("milage", parser.group(index++)); // Extended info position.setExtendedInfo(extendedInfo.toString()); diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java index 749c01393..108e74963 100644 --- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java +++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java @@ -34,6 +34,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Mta6ProtocolDecoder extends BaseProtocolDecoder { @@ -128,7 +129,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { while (buf.readable()) { Position position = new Position(); position.setDeviceId(deviceId); - StringBuilder extendedInfo = new StringBuilder("mta6"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("mta6"); short flags = buf.readUnsignedByte(); @@ -162,50 +163,40 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { } if (checkBit(flags, 3)) { - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); + extendedInfo.set("milage", buf.readUnsignedShort()); } if (checkBit(flags, 4)) { - extendedInfo.append("").append(buf.readUnsignedInt()).append(""); - extendedInfo.append("").append(buf.readUnsignedInt()).append(""); - extendedInfo.append("").append(buf.readUnsignedShort()).append(""); - extendedInfo.append("").append(buf.readUnsignedShort()).append(""); + extendedInfo.set("fuel1", buf.readUnsignedInt()); + extendedInfo.set("fuel2", buf.readUnsignedInt()); + extendedInfo.set("hours1", buf.readUnsignedShort()); + extendedInfo.set("hours2", buf.readUnsignedShort()); } if (checkBit(flags, 5)) { - extendedInfo.append("").append(buf.readUnsignedShort() & 0x03ff).append(""); - extendedInfo.append("").append(buf.readUnsignedShort() & 0x03ff).append(""); - extendedInfo.append("").append(buf.readUnsignedShort() & 0x03ff).append(""); - extendedInfo.append("").append(buf.readUnsignedShort() & 0x03ff).append(""); + extendedInfo.set("adc1", buf.readUnsignedShort() & 0x03ff); + extendedInfo.set("adc2", buf.readUnsignedShort() & 0x03ff); + extendedInfo.set("adc3", buf.readUnsignedShort() & 0x03ff); + extendedInfo.set("adc4", buf.readUnsignedShort() & 0x03ff); } if (checkBit(flags, 6)) { - extendedInfo.append(""); - extendedInfo.append(buf.readByte()); - extendedInfo.append(""); + extendedInfo.set("temperature", buf.readByte()); buf.getUnsignedByte(buf.readerIndex()); // control (>> 4) - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort() & 0x0fff); - extendedInfo.append(""); + extendedInfo.set("sensor", buf.readUnsignedShort() & 0x0fff); buf.readUnsignedShort(); // old sensor state (& 0x0fff) } if (checkBit(flags, 7)) { - extendedInfo.append(""); - extendedInfo.append(buf.getUnsignedByte(buf.readerIndex()) >> 2); - extendedInfo.append(""); + extendedInfo.set("battery", buf.getUnsignedByte(buf.readerIndex()) >> 2); position.setPower((double) (buf.readUnsignedShort() & 0x03ff)); buf.readByte(); // microcontroller temperature - extendedInfo.append(""); - extendedInfo.append((buf.getUnsignedByte(buf.readerIndex()) >> 4) & 0x07); - extendedInfo.append(""); + extendedInfo.set("gsm", (buf.getUnsignedByte(buf.readerIndex()) >> 4) & 0x07); int satellites = buf.readUnsignedByte() & 0x0f; position.setValid(satellites >= 3); - extendedInfo.append("").append(satellites).append(""); + extendedInfo.set("satellites", satellites); } position.setExtendedInfo(extendedInfo.toString()); @@ -220,7 +211,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { private Position parseFormatA1(ChannelBuffer buf, long deviceId) { Position position = new Position(); position.setDeviceId(deviceId); - StringBuilder extendedInfo = new StringBuilder("mta6can"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("mta6"); short flags = buf.readUnsignedByte(); @@ -246,56 +237,46 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { position.setAltitude((double) buf.readUnsignedShort()); position.setSpeed((double) buf.readUnsignedByte()); position.setCourse((double) buf.readByte()); - extendedInfo.append(""); - extendedInfo.append(new FloatReader().readFloat(buf)); - extendedInfo.append(""); + extendedInfo.set("milage", new FloatReader().readFloat(buf)); } if (checkBit(flags, 1)) { new FloatReader().readFloat(buf); // fuel consumtion - extendedInfo.append("").append(new FloatReader().readFloat(buf)).append(""); - extendedInfo.append("").append(buf.readUnsignedByte() * 0.4).append(""); + extendedInfo.set("hours", new FloatReader().readFloat(buf)); + extendedInfo.set("tank", buf.readUnsignedByte() * 0.4); } if (checkBit(flags, 2)) { - extendedInfo.append("").append(buf.readUnsignedShort() * 0.125).append(""); - extendedInfo.append("").append(buf.readUnsignedByte()).append(""); - extendedInfo.append("").append(buf.readUnsignedByte() - 40).append(""); + extendedInfo.set("engine", buf.readUnsignedShort() * 0.125); + extendedInfo.set("pedals", buf.readUnsignedByte()); + extendedInfo.set("temperature", buf.readUnsignedByte() - 40); buf.readUnsignedShort(); // service milage } if (checkBit(flags, 3)) { - extendedInfo.append("").append(buf.readUnsignedShort()).append(""); - extendedInfo.append("").append(buf.readUnsignedShort()).append(""); - extendedInfo.append("").append(buf.readUnsignedShort()).append(""); - extendedInfo.append("").append(buf.readUnsignedShort()).append(""); + extendedInfo.set("fuel", buf.readUnsignedShort()); + extendedInfo.set("adc2", buf.readUnsignedShort()); + extendedInfo.set("adc3", buf.readUnsignedShort()); + extendedInfo.set("adc4", buf.readUnsignedShort()); } if (checkBit(flags, 4)) { - extendedInfo.append(""); - extendedInfo.append(buf.readByte()); - extendedInfo.append(""); + extendedInfo.set("temperature", buf.readByte()); buf.getUnsignedByte(buf.readerIndex()); // control (>> 4) - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort() & 0x0fff); - extendedInfo.append(""); + extendedInfo.set("sensor", buf.readUnsignedShort() & 0x0fff); buf.readUnsignedShort(); // old sensor state (& 0x0fff) } if (checkBit(flags, 5)) { - extendedInfo.append(""); - extendedInfo.append(buf.getUnsignedByte(buf.readerIndex()) >> 2); - extendedInfo.append(""); + extendedInfo.set("battery", buf.getUnsignedByte(buf.readerIndex()) >> 2); position.setPower((double) (buf.readUnsignedShort() & 0x03ff)); buf.readByte(); // microcontroller temperature - extendedInfo.append(""); - extendedInfo.append(buf.getUnsignedByte(buf.readerIndex()) >> 5); - extendedInfo.append(""); + extendedInfo.set("gsm", buf.getUnsignedByte(buf.readerIndex()) >> 5); int satellites = buf.readUnsignedByte() & 0x1f; position.setValid(satellites >= 3); - extendedInfo.append("").append(satellites).append(""); + extendedInfo.set("satellites", satellites); } // TODO: process other data diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java index 58ea6e577..34642496a 100644 --- a/src/org/traccar/protocol/NavigilProtocolDecoder.java +++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java @@ -25,6 +25,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Crc; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class NavigilProtocolDecoder extends BaseProtocolDecoder { @@ -79,7 +80,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parseUnitReport(ChannelBuffer buf, long deviceId, int sequenceNumber) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("navigil"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("navigil"); position.setValid(true); position.setId((long) sequenceNumber); @@ -116,7 +117,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parseTg2Report(ChannelBuffer buf, long deviceId, int sequenceNumber) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("navigil"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("navigil"); position.setValid(true); position.setId((long) sequenceNumber); @@ -155,7 +156,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parsePositionReport(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("navigil"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("navigil"); position.setId((long) sequenceNumber); position.setDeviceId(deviceId); @@ -179,7 +180,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parsePositionReport2(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("navigil"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("navigil"); position.setId((long) sequenceNumber); position.setDeviceId(deviceId); @@ -206,7 +207,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parseSnapshot4(ChannelBuffer buf, long deviceId, int sequenceNumber) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("navigil"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("navigil"); position.setId((long) sequenceNumber); position.setDeviceId(deviceId); @@ -247,7 +248,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parseTrackingData(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("navigil"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("navigil"); position.setId((long) sequenceNumber); position.setDeviceId(deviceId); diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 1c384969d..9de70595a 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -28,11 +28,9 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; -/** - * Navis protocol decoder - */ public class NavisProtocolDecoder extends BaseProtocolDecoder { private String prefix; @@ -43,9 +41,6 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { private String imei; private Long databaseDeviceId; - /** - * Initialize - */ public NavisProtocolDecoder(ServerManager serverManager) { super(serverManager); } @@ -70,7 +65,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { private Position parsePosition(ChannelBuffer buf) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("navis"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("navis"); position.setDeviceId(databaseDeviceId); position.setAltitude(0.0); @@ -82,16 +77,12 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { } else { format = buf.readUnsignedByte(); } - extendedInfo.append(""); - extendedInfo.append(format); - extendedInfo.append(""); + extendedInfo.set("format", format); position.setId(buf.readUnsignedInt()); // sequence number // Event type - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); + extendedInfo.set("event", buf.readUnsignedShort()); // Event time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); @@ -102,67 +93,44 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte()); time.set(Calendar.MONTH, buf.readUnsignedByte()); time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); - extendedInfo.append(""); + extendedInfo.set("time", time.getTimeInMillis()); // Alarm status - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); + extendedInfo.set("alarm", buf.readUnsignedByte()); // Modules status - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); + extendedInfo.set("status", buf.readUnsignedByte()); // GSM signal - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); + extendedInfo.set("gsm", buf.readUnsignedByte()); // Output - extendedInfo.append(""); if (isFormat(format, F10, F20, F30)) { - extendedInfo.append(buf.readUnsignedShort()); + extendedInfo.set("output", buf.readUnsignedShort()); } else if (isFormat(format, F40, F50, F51, F52)) { - extendedInfo.append(buf.readUnsignedByte()); + extendedInfo.set("output", buf.readUnsignedByte()); } - extendedInfo.append(""); // Input - extendedInfo.append(""); if (isFormat(format, F10, F20, F30, F40)) { - extendedInfo.append(buf.readUnsignedShort()); + extendedInfo.set("input", buf.readUnsignedShort()); } else if (isFormat(format, F50, F51, F52)) { - extendedInfo.append(buf.readUnsignedByte()); + extendedInfo.set("input", buf.readUnsignedByte()); } - extendedInfo.append(""); position.setPower(buf.readUnsignedShort() / 1000.0); // power // Battery power - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); + extendedInfo.set("battery", buf.readUnsignedShort()); // Temperature if (isFormat(format, F10, F20, F30)) { - extendedInfo.append(""); - extendedInfo.append(buf.readShort()); - extendedInfo.append(""); + extendedInfo.set("temperature", buf.readShort()); } if (isFormat(format, F10, F20, F50, F52)) { - // ADC 1 - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); - - // ADC 2 - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); + extendedInfo.set("adc1", buf.readUnsignedShort()); + extendedInfo.set("adc2", buf.readUnsignedShort()); } if (isFormat(format, F20, F50, F51, F52)) { @@ -193,14 +161,10 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { position.setCourse((double) buf.readUnsignedShort()); // Milage - extendedInfo.append(""); - extendedInfo.append(buf.readFloat()); - extendedInfo.append(""); + extendedInfo.set("milage", buf.readFloat()); // Last segment - extendedInfo.append(""); - extendedInfo.append(buf.readFloat()); - extendedInfo.append(""); + extendedInfo.set("segment", buf.readFloat()); // Segment times buf.readUnsignedShort(); @@ -308,9 +272,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { } } - /** - * Decode message - */ + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 312886591..87fc0ae44 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -32,6 +32,7 @@ import org.traccar.ServerManager; import org.traccar.helper.AdvancedConnection; import org.traccar.helper.Log; import org.traccar.helper.NamedParameterStatement; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; /** @@ -139,15 +140,15 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { for (int j = 0; j < recordCount; j++) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("progress"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("progress"); position.setDeviceId(deviceId); // Message index if (type == MSG_LOGMSG) { - extendedInfo.append("true"); + extendedInfo.set("archive", true); int subtype = buf.readUnsignedShort(); if (subtype == MSG_ALARM) { - extendedInfo.append("true"); + extendedInfo.set("alarm", true); } if (buf.readUnsignedShort() > buf.readableBytes()) { lastIndex += 1; @@ -182,22 +183,16 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { // Satellites int satellitesNumber = buf.readUnsignedByte(); - extendedInfo.append(""); - extendedInfo.append(satellitesNumber); - extendedInfo.append(""); + extendedInfo.set("satellites", satellitesNumber); // Validity position.setValid(satellitesNumber >= 3); // TODO: probably wrong // Cell signal - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); + extendedInfo.set("gsm", buf.readUnsignedByte()); // Milage - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedInt()); - extendedInfo.append(""); + extendedInfo.set("milage", buf.readUnsignedInt()); long extraFlags = buf.readLong(); @@ -205,9 +200,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { if ((extraFlags & 0x1) == 0x1) { int count = buf.readUnsignedShort(); for (int i = 1; i <= count; i++) { - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); + extendedInfo.set("adc" + i, buf.readUnsignedShort()); } } @@ -215,9 +208,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { // CAN adapter if ((extraFlags & 0x2) == 0x2) { int size = buf.readUnsignedShort(); - extendedInfo.append(""); - extendedInfo.append(buf.toString(buf.readerIndex(), size, Charset.defaultCharset())); - extendedInfo.append(""); + extendedInfo.set("can", buf.toString(buf.readerIndex(), size, Charset.defaultCharset())); buf.skipBytes(size); } @@ -233,9 +224,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { hex.append(HEX_CHARS.charAt((b & 0x0F))); } - extendedInfo.append(""); - extendedInfo.append(hex); - extendedInfo.append(""); + extendedInfo.set("passenger", hex); buf.skipBytes(size); } @@ -245,7 +234,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { byte[] response = {(byte)0xC9,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; channel.write(ChannelBuffers.wrappedBuffer(response)); - extendedInfo.append("true"); + extendedInfo.set("alarm", true); } // Skip CRC diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index a00913ae4..1d9a7a058 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -25,24 +25,15 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; -/** - * PT502 tracker protocol decoder - */ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { - /** - * Initialize - */ public Pt502ProtocolDecoder(ServerManager serverManager) { super(serverManager); } - /** - * Regular expressions pattern - */ - //$POS,6094,205523.000,A,1013.6223,N,06728.4248,W,0.0,99.3,011112,,,A/00000,00000/0/23895000// static private Pattern pattern = Pattern.compile( "\\$POS," + // Data Frame start "(\\d+)," + // Id @@ -57,9 +48,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { "(\\d{2})(\\d{2})(\\d{2})," + // Date ".*"); - /* - * Decode message - */ + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { @@ -75,7 +64,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("pt502"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("pt502"); Integer index = 1; diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index 11f9424aa..fedb411a6 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; /** @@ -84,13 +85,11 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("skypatrol"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("skypatrol"); // Status code if (checkBit(mask, 1)) { - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedInt()); - extendedInfo.append(""); + extendedInfo.set("status", buf.readUnsignedInt()); } // Device id @@ -183,9 +182,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { // Satellites if (checkBit(mask, 16)) { - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); + extendedInfo.set("satellites", buf.readUnsignedByte()); } // Battery percentage @@ -195,16 +192,12 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { // Trip milage if (checkBit(mask, 20)) { - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedInt()); - extendedInfo.append(""); + extendedInfo.set("trip", buf.readUnsignedInt()); } // Milage if (checkBit(mask, 21)) { - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedInt()); - extendedInfo.append(""); + extendedInfo.set("milage", buf.readUnsignedInt()); } // Time of message generation diff --git a/src/org/traccar/protocol/St210ProtocolDecoder.java b/src/org/traccar/protocol/St210ProtocolDecoder.java index bea7d1ad6..5e1ac1bf6 100644 --- a/src/org/traccar/protocol/St210ProtocolDecoder.java +++ b/src/org/traccar/protocol/St210ProtocolDecoder.java @@ -12,6 +12,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; import org.traccar.model.DataManager; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class St210ProtocolDecoder extends BaseProtocolDecoder { @@ -645,7 +646,7 @@ public class St210ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setAltitude(0D); - position.setExtendedInfo(""); + position.setExtendedInfo(new ExtendedInfoFormatter("st210").toString()); position.setValid(true); Integer index = 0; diff --git a/src/org/traccar/protocol/SyrusProtocolDecoder.java b/src/org/traccar/protocol/SyrusProtocolDecoder.java index 7e809212a..66d6872e4 100644 --- a/src/org/traccar/protocol/SyrusProtocolDecoder.java +++ b/src/org/traccar/protocol/SyrusProtocolDecoder.java @@ -25,6 +25,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class SyrusProtocolDecoder extends BaseProtocolDecoder { @@ -127,7 +128,7 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("syrus"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("syrus"); position.setDeviceId(deviceId); Integer index = 1; diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 100792cb9..4d9e72588 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -26,6 +26,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { @@ -65,32 +66,26 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { for (int i = 0; i < count; i++) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("teltonika"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("teltonika"); position.setDeviceId(deviceId); position.setTime(new Date(buf.readLong())); - - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); + + extendedInfo.set("priority", buf.readUnsignedByte()); position.setLongitude(buf.readUnsignedInt() / 10000000.0); position.setLatitude(buf.readUnsignedInt() / 10000000.0); position.setAltitude((double) buf.readUnsignedShort()); position.setCourse((double) buf.readUnsignedShort()); - extendedInfo.append(""); int satellites = buf.readUnsignedByte(); - extendedInfo.append(satellites); - extendedInfo.append(""); + extendedInfo.set("satellites", satellites); position.setValid(satellites != 0); position.setSpeed((double) buf.readUnsignedShort()); - - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); + + extendedInfo.set("event", buf.readUnsignedByte()); // Skip IO data buf.readUnsignedByte(); // total IO data records diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java index f30acd486..fd760e795 100644 --- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Tk102ProtocolDecoder extends BaseProtocolDecoder { @@ -74,7 +75,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("tk102"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("tk102"); position.setDeviceId(deviceId); Integer index = 1; diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 6f58b17d2..92febe756 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Tk103ProtocolDecoder extends BaseProtocolDecoder { @@ -32,9 +33,6 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - /** - * Regular expressions pattern - */ static private Pattern pattern = Pattern.compile( "(\\d{12})" + // Device ID ".{4}" + // Command @@ -75,7 +73,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("tk103"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("tk103"); Integer index = 1; // Get device by IMEI @@ -130,14 +128,10 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { position.setCourse(Double.valueOf(parser.group(index++))); // State - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("state", parser.group(index++)); // Milage - extendedInfo.append(""); - extendedInfo.append(Integer.parseInt(parser.group(index++), 16)); - extendedInfo.append(""); + extendedInfo.set("milage", Integer.parseInt(parser.group(index++), 16)); position.setExtendedInfo(extendedInfo.toString()); return position; diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java index 66146b6fb..e38b3ab7b 100644 --- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java +++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java @@ -26,6 +26,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { @@ -34,9 +35,6 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - /** - * Regular expressions pattern - */ static private Pattern pattern = Pattern.compile( "#([0-9a-f]+)?" + // Cell info "\\$GPRMC," + @@ -75,16 +73,13 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { Matcher parser = pattern.matcher(message); if (parser.matches()) { Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("tlt2h"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("tlt2h"); position.setDeviceId(deviceId); Integer index = 1; // Cell - String cell = parser.group(index++); - if (cell != null) { - extendedInfo.append("").append(cell).append(""); - } + extendedInfo.set("cell", parser.group(index++)); // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java index 95935cd29..5b48566b7 100644 --- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java @@ -24,16 +24,11 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; -/** - * TR20 tracker protocol decoder - */ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { - /** - * Initialize - */ public Tr20ProtocolDecoder(ServerManager serverManager) { super(serverManager); } @@ -41,8 +36,6 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { static private Pattern patternPing = Pattern.compile( "\\%\\%[^,]+,(\\d+)"); - //%%TR-10,A,050916070549,N2240.8887E11359.2994,0,000,NA,D3800000,150,CFG:resend| - //%%123456789012345,A,120101121800,N6000.0000E13000.0000,0,000,0,01034802,150,[Message] static private Pattern patternData = Pattern.compile( "\\%\\%" + "([^,]+)," + // Id @@ -57,9 +50,7 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { "(\\d+)," + // Course ".*"); - /** - * Decode message - */ + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { @@ -86,7 +77,7 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("tr20"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("tr20"); Integer index = 1; diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java index 40549857a..205036ebb 100644 --- a/src/org/traccar/protocol/V680ProtocolDecoder.java +++ b/src/org/traccar/protocol/V680ProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class V680ProtocolDecoder extends BaseProtocolDecoder { @@ -67,7 +68,7 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("V680"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("v680"); Integer index = 1; // Get device by IMEI @@ -80,27 +81,19 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder { } // User - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("user", parser.group(index++)); // Validity position.setValid(parser.group(index++).compareTo("1") == 0 ? true : false); // Password - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("password", parser.group(index++)); // Packet number - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("packet", parser.group(index++)); // GSM base station - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("gsm", parser.group(index++)); // Longitude Double lonlitude = Double.valueOf(parser.group(index++)); diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index c3ea94624..cb89693f7 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class WialonProtocolDecoder extends BaseProtocolDecoder { @@ -93,7 +94,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("wialon"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("wialon"); position.setDeviceId(deviceId); Integer index = 1; @@ -133,9 +134,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { // Satellites int satellites = Integer.valueOf(parser.group(index++)); position.setValid(satellites >= 3); - extendedInfo.append(""); - extendedInfo.append(satellites); - extendedInfo.append(""); + extendedInfo.set("satellites", satellites); // Extended info position.setExtendedInfo(extendedInfo.toString()); diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java index ebae99bb4..65fb3526d 100644 --- a/src/org/traccar/protocol/WondexProtocolDecoder.java +++ b/src/org/traccar/protocol/WondexProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class WondexProtocolDecoder extends BaseProtocolDecoder { @@ -32,9 +33,6 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - /** - * Regular expressions pattern - */ static private Pattern pattern = Pattern.compile( "[^\\d]*" + // Header "(\\d+)," + // Device Identifier @@ -66,7 +64,7 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("wondex"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("wondex"); int index = 1; // Device identifier @@ -99,40 +97,23 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { // Satellites int satellites = Integer.valueOf(parser.group(index++)); position.setValid(satellites >= 3); - extendedInfo.append("").append(satellites).append(""); + extendedInfo.set("satellites", satellites); // Event - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("event", parser.group(index++)); // Milage - String milage = parser.group(index++); - if (milage != null) { - extendedInfo.append("").append(milage).append(""); - } + extendedInfo.set("milage", parser.group(index++)); // Input - String input = parser.group(index++); - if (input != null) { - extendedInfo.append("").append(input).append(""); - } + extendedInfo.set("input", parser.group(index++)); // ADC - String adc1 = parser.group(index++); - if (adc1 != null) { - extendedInfo.append("").append(adc1).append(""); - } - String adc2 = parser.group(index++); - if (adc2 != null) { - extendedInfo.append("").append(adc2).append(""); - } + extendedInfo.set("adc1", parser.group(index++)); + extendedInfo.set("adc2", parser.group(index++)); // Output - String output = parser.group(index++); - if (output != null) { - extendedInfo.append("").append(output).append(""); - } + extendedInfo.set("output", parser.group(index++)); position.setExtendedInfo(extendedInfo.toString()); return position; diff --git a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java index 6981c8d42..900315d20 100644 --- a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { @@ -32,13 +33,10 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - /** - * Regular expressions pattern - */ static private Pattern pattern = Pattern.compile( "[\r\n]*" + "(\\d+)," + // Serial - "(\\+?\\d+)," + // Number + "(\\+?\\d+)," + // Number "GPRMC," + "(\\d{2})(\\d{2})(\\d{2})\\.(\\d{3})," + // Time (HHMMSS.SSS) "([AV])," + // Validity @@ -55,8 +53,8 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { ".*imei:" + "(\\d+)," + // IMEI "(\\d+)," + // Satellites - "(-?\\d+\\.\\d+)," + // Altitude - "[FL]:(\\d+\\.\\d+)V," + // Power + "(-?\\d+\\.\\d+)," + // Altitude + "[FL]:(\\d+\\.\\d+)V," + // Power ".*" + "[\r\n]*"); @@ -74,19 +72,15 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("xexun2"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("xexun2"); Integer index = 1; // Serial - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("serial", parser.group(index++)); // Number - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("number", parser.group(index++)); // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); @@ -129,14 +123,10 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); // Signal - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("signal", parser.group(index++)); // Alarm - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("alarm", parser.group(index++)); // Get device by IMEI String imei = parser.group(index++); @@ -148,9 +138,7 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { } // Satellites - extendedInfo.append(""); - extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); - extendedInfo.append(""); + extendedInfo.set("satellites", parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); // Altitude position.setAltitude(Double.valueOf(parser.group(index++))); diff --git a/src/org/traccar/protocol/Xt7ProtocolDecoder.java b/src/org/traccar/protocol/Xt7ProtocolDecoder.java index 79f793d8a..a47577c5e 100644 --- a/src/org/traccar/protocol/Xt7ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xt7ProtocolDecoder.java @@ -26,6 +26,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Xt7ProtocolDecoder extends BaseProtocolDecoder { @@ -66,7 +67,7 @@ public class Xt7ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("xt7"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("xt7"); // Get device by id String id = buf.readBytes(16).toString(Charset.defaultCharset()).trim(); @@ -130,42 +131,28 @@ public class Xt7ProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); // IMSI - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("imsi", parser.group(index++)); // Cell - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("cell", parser.group(index++)); // GSM signal quality - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("gsm", parser.group(index++)); // Battery position.setPower(Double.valueOf(parser.group(index++))); // Flags - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("flags", parser.group(index++)); // Sensors - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("sensors", parser.group(index++)); // Fuel - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("fuel", parser.group(index++)); // Alarm - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("alarm", parser.group(index++)); // Extended info position.setExtendedInfo(extendedInfo.toString()); diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java index c28c7b7d7..c93545f50 100644 --- a/src/org/traccar/protocol/YwtProtocolDecoder.java +++ b/src/org/traccar/protocol/YwtProtocolDecoder.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class YwtProtocolDecoder extends BaseProtocolDecoder { @@ -32,10 +33,6 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - /** - * Regular expressions pattern - */ - //%GP,3000012345:0,090723182813,E114.602345,N22.069725,,30,160,4,0,00,,2794-10FF-46000,3>0-0 static private Pattern pattern = Pattern.compile( "%(..)," + // Type "(\\d+):" + // Unit identifier @@ -69,7 +66,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("ywt"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("ywt"); Integer index = 1; String type = parser.group(index++); @@ -122,15 +119,13 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { // Satellites int satellites = Integer.valueOf(parser.group(index++)); position.setValid(satellites >= 3); - extendedInfo.append("").append(satellites).append(""); + extendedInfo.set("satellites", satellites); // Report identifier String reportId = parser.group(index++); // Status - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); + extendedInfo.set("status", parser.group(index++)); // Send response if (type.equals("KP") || type.equals("EP") || type.equals("EP")) { -- cgit v1.2.3