aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-05-02 22:16:14 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-05-02 22:16:14 +1200
commit81beb5afb946d8c9ccfa2bbdfcfe884771a5bd3b (patch)
treece4d0b24f1c82381da30472844052f8cfdc1a164 /src
parentf367b71b9c081416f6d64f6efd9844cd05f047ea (diff)
downloadtrackermap-server-81beb5afb946d8c9ccfa2bbdfcfe884771a5bd3b.tar.gz
trackermap-server-81beb5afb946d8c9ccfa2bbdfcfe884771a5bd3b.tar.bz2
trackermap-server-81beb5afb946d8c9ccfa2bbdfcfe884771a5bd3b.zip
Fix extended info XML format
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/model/ExtendedInfoFormatter.java47
-rw-r--r--src/org/traccar/protocol/Avl08ProtocolDecoder.java58
-rw-r--r--src/org/traccar/protocol/CarscopProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java9
-rw-r--r--src/org/traccar/protocol/Ev603ProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java7
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java29
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/IntellitracProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java27
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java40
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java36
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java83
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java76
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java33
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/St210ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/SyrusProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/Tk102ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Tr20ProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/V680ProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java7
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java37
-rw-r--r--src/org/traccar/protocol/Xexun2ProtocolDecoder.java32
-rw-r--r--src/org/traccar/protocol/Xt7ProtocolDecoder.java31
-rw-r--r--src/org/traccar/protocol/YwtProtocolDecoder.java13
32 files changed, 268 insertions, 504 deletions
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("<protocol>").append(protocol).append("</protocol>");
+ }
+
+ public void set(String key, Object value) {
+ if (value != null) {
+ data.append("<").append(key).append(">");
+ data.append(value);
+ data.append("</").append(key).append(">");
+ }
+ }
+
+ @Override
+ public String toString() {
+ data.append("</").append(rootNode).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("<protocol>avl08</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("avl08");
Integer index = 1;
@@ -98,9 +99,7 @@ public class Avl08ProtocolDecoder extends BaseProtocolDecoder {
}
// Alarm type
- extendedInfo.append("<alarm>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</alarm>");
+ 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("<pdop>");
- extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", ""));
- extendedInfo.append("</pdop>");
- extendedInfo.append("<hdop>");
- extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", ""));
- extendedInfo.append("</hdop>");
- extendedInfo.append("<vdop>");
- extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", ""));
- extendedInfo.append("</vdop>");
+ 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("<status>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</status>");
+ extendedInfo.set("status", parser.group(index++));
// Real time clock
- extendedInfo.append("<clock>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</clock>");
+ extendedInfo.set("clock", parser.group(index++));
// Voltage
String voltage = parser.group(index++);
position.setPower(Double.valueOf(voltage.substring(1, 4)) / 100);
- extendedInfo.append("<voltage>");
- extendedInfo.append(voltage);
- extendedInfo.append("</voltage>");
+ extendedInfo.set("voltage", voltage);
// ADC
- extendedInfo.append("<adc>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</adc>");
+ extendedInfo.set("adc", parser.group(index++));
// Cell
- extendedInfo.append("<cell>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</cell>");
+ extendedInfo.set("cell", parser.group(index++));
// Temperature
- extendedInfo.append("<temperature>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</temperature>");
+ extendedInfo.set("temperature", parser.group(index++));
// Mileage
- extendedInfo.append("<mileage>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</mileage>");
+ extendedInfo.set("mileage", parser.group(index++));
// Serial
- extendedInfo.append("<serial>");
- extendedInfo.append(parser.group(index++).replaceFirst ("^0*", ""));
- extendedInfo.append("</serial>");
+ extendedInfo.set("serial", parser.group(index++).replaceFirst ("^0*", ""));
// RFID
- String rfid = parser.group(index++);
- if (rfid != null) {
- extendedInfo.append("<rfid>");
- extendedInfo.append(rfid);
- extendedInfo.append("</rfid>");
- }
+ 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("<protocol>carscop</protocol>");
+ 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("<state>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</state>");
+ extendedInfo.set("state", parser.group(index++));
// Milage
- extendedInfo.append("<milage>");
- extendedInfo.append(Integer.valueOf(parser.group(index++)));
- extendedInfo.append("</milage>");
+ 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("<protocol>cellocator</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("cellocator");
// Device identifier
try {
@@ -117,9 +118,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // protocol version
// Status
- extendedInfo.append("<status>");
- extendedInfo.append(buf.getUnsignedByte(buf.readerIndex()) & 0x0f);
- extendedInfo.append("</status>");
+ 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("<operator>").append(operator).append("</operator>");
+ 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("<protocol>ev603</protocol>");
+ 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("<protocol>galileo</protocol>");
+ 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("<status>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</status>");
+ extendedInfo.set("status", buf.readUnsignedShort());
break;
case TAG_POWER:
@@ -144,15 +143,11 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
break;
case TAG_BATTERY:
- extendedInfo.append("<battery>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</battery>");
+ extendedInfo.set("battery", buf.readUnsignedShort());
break;
case TAG_MILAGE:
- extendedInfo.append("<milage>");
- extendedInfo.append(buf.readUnsignedInt());
- extendedInfo.append("</milage>");
+ 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("<protocol>gps103</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("gps103");
Integer index = 1;
@@ -99,9 +100,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
}
// Alarm message
- extendedInfo.append("<alarm>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</alarm>");
+ 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("<protocol>gt06</protocol>");
+ 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("<satellites>");
- extendedInfo.append(gpsLength & 0xf);
- extendedInfo.append("</satellites>");
+ extendedInfo.set("satellites", gpsLength & 0xf);
gpsLength >>= 4;
// Latitude
@@ -158,32 +157,22 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
}
// Cell information
- extendedInfo.append("<mcc>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</mcc>");
- extendedInfo.append("<mnc>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</mnc>");
- extendedInfo.append("<lac>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</lac>");
- extendedInfo.append("<cell>");
- extendedInfo.append(buf.readUnsignedShort() << 8 + buf.readUnsignedByte());
- extendedInfo.append("</cell>");
+ 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("<alarm>true</alarm>");
+ extendedInfo.set("alarm", true);
// Voltage
position.setPower((double) buf.readUnsignedByte());
// GSM signal
- extendedInfo.append("<gsm>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</gsm>");
+ 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("<protocol>h02</protocol>");
+ 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("<protocol>intellitrac</protocol>");
+ 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("<satellites>");
- extendedInfo.append(satellites);
- extendedInfo.append("</satellites>");
+ extendedInfo.set("satellites", satellites);
// Report identifier
position.setId(Long.valueOf(parser.group(index++)));
// Input
- extendedInfo.append("<input>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</input>");
+ extendedInfo.set("input", parser.group(index++));
// Output
- extendedInfo.append("<output>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</output>");
+ extendedInfo.set("output", parser.group(index++));
// ADC1
String adc1 = parser.group(index++);
if (adc1 != null) {
- extendedInfo.append("<adc1>").append(adc1).append("</adc1>");
+ extendedInfo.set("adc1", adc1);
}
// ADC2
String adc2 = parser.group(index++);
if (adc2 != null) {
- extendedInfo.append("<adc2>").append(adc2).append("</adc2>");
+ 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("<protocol>megastek</protocol>");
+ 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("<alarm>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</alarm>");
+ 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("<satellites>");
- extendedInfo.append(satellites);
- extendedInfo.append("</satellites>");
+ 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("<charger>");
- extendedInfo.append(Integer.valueOf(charger) == 1);
- extendedInfo.append("</charger>");
+ extendedInfo.set("charger", Integer.valueOf(charger) == 1);
}
// MCC
- extendedInfo.append("<mcc>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</mcc>");
+ extendedInfo.set("mcc", parser.group(index++));
// MNC
- extendedInfo.append("<mnc>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</mnc>");
+ extendedInfo.set("mnc", parser.group(index++));
// LAC
- extendedInfo.append("<lac>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</lac>");
+ 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("<protocol>meiligao</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("meiligao");
// Alarm
if (command == 0x9999) {
- extendedInfo.append("<alarm>");
- extendedInfo.append(buf.getUnsignedByte(offset));
- extendedInfo.append("</alarm>");
+ 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("<hdop>");
- extendedInfo.append(hdop);
- extendedInfo.append("</hdop>");
- }
+ 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("<state>");
- extendedInfo.append(state);
- extendedInfo.append("</state>");
+ extendedInfo.set("state", state);
}
// ADC
for (int i = 1; i <= 8; i++) {
String adc = parser.group(index++);
if (adc != null) {
- extendedInfo.append("<adc").append(i).append(">");
- extendedInfo.append(Integer.parseInt(adc, 16));
- extendedInfo.append("</adc").append(i).append(">");
+ extendedInfo.set("adc" + i, Integer.parseInt(adc, 16));
}
}
// Cell identifier
String cell = parser.group(index++);
if (cell != null) {
- extendedInfo.append("<cell>");
- extendedInfo.append(cell);
- extendedInfo.append("</cell>");
+ extendedInfo.set("cell", cell);
}
// GSM signal
String gsm = parser.group(index++);
if (gsm != null) {
- extendedInfo.append("<gsm>");
- extendedInfo.append(Integer.parseInt(gsm, 16));
- extendedInfo.append("</gsm>");
+ extendedInfo.set("gsm", Integer.parseInt(gsm, 16));
}
// Milage
String milage = parser.group(index++);
if (milage != null) {
- extendedInfo.append("<milage>");
- extendedInfo.append(Integer.parseInt(milage, 16));
- extendedInfo.append("</milage>");
+ 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("<protocol>meitrack</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("meitrack");
Integer index = 1;
@@ -91,9 +81,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
// Event
- extendedInfo.append("<event>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</event>");
+ 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("<satellites>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</satellites>");
+ extendedInfo.set("satellites", parser.group(index++));
// GSM Signal
- extendedInfo.append("<gsm>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</gsm>");
+ 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("<hdop>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</hdop>");
+ extendedInfo.set("hdop", parser.group(index++));
// Altitude
position.setAltitude(Double.valueOf(parser.group(index++)));
// Milage
- extendedInfo.append("<milage>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</milage>");
+ 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("<protocol>mta6</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("mta6");
short flags = buf.readUnsignedByte();
@@ -162,50 +163,40 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
}
if (checkBit(flags, 3)) {
- extendedInfo.append("<milage>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</milage>");
+ extendedInfo.set("milage", buf.readUnsignedShort());
}
if (checkBit(flags, 4)) {
- extendedInfo.append("<fuel1>").append(buf.readUnsignedInt()).append("</fuel1>");
- extendedInfo.append("<fuel2>").append(buf.readUnsignedInt()).append("</fuel2>");
- extendedInfo.append("<hours1>").append(buf.readUnsignedShort()).append("</hours1>");
- extendedInfo.append("<hours2>").append(buf.readUnsignedShort()).append("</hours2>");
+ 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("<adc1>").append(buf.readUnsignedShort() & 0x03ff).append("</adc1>");
- extendedInfo.append("<adc2>").append(buf.readUnsignedShort() & 0x03ff).append("</adc2>");
- extendedInfo.append("<adc3>").append(buf.readUnsignedShort() & 0x03ff).append("</adc3>");
- extendedInfo.append("<adc4>").append(buf.readUnsignedShort() & 0x03ff).append("</adc4>");
+ 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("<temperature>");
- extendedInfo.append(buf.readByte());
- extendedInfo.append("</temperature>");
+ extendedInfo.set("temperature", buf.readByte());
buf.getUnsignedByte(buf.readerIndex()); // control (>> 4)
- extendedInfo.append("<sensor>");
- extendedInfo.append(buf.readUnsignedShort() & 0x0fff);
- extendedInfo.append("</sensor>");
+ extendedInfo.set("sensor", buf.readUnsignedShort() & 0x0fff);
buf.readUnsignedShort(); // old sensor state (& 0x0fff)
}
if (checkBit(flags, 7)) {
- extendedInfo.append("<battery>");
- extendedInfo.append(buf.getUnsignedByte(buf.readerIndex()) >> 2);
- extendedInfo.append("</battery>");
+ extendedInfo.set("battery", buf.getUnsignedByte(buf.readerIndex()) >> 2);
position.setPower((double) (buf.readUnsignedShort() & 0x03ff));
buf.readByte(); // microcontroller temperature
- extendedInfo.append("<gsm>");
- extendedInfo.append((buf.getUnsignedByte(buf.readerIndex()) >> 4) & 0x07);
- extendedInfo.append("</gsm>");
+ extendedInfo.set("gsm", (buf.getUnsignedByte(buf.readerIndex()) >> 4) & 0x07);
int satellites = buf.readUnsignedByte() & 0x0f;
position.setValid(satellites >= 3);
- extendedInfo.append("<satellites>").append(satellites).append("</satellites>");
+ 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("<protocol>mta6can</protocol>");
+ 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("<milage>");
- extendedInfo.append(new FloatReader().readFloat(buf));
- extendedInfo.append("</milage>");
+ extendedInfo.set("milage", new FloatReader().readFloat(buf));
}
if (checkBit(flags, 1)) {
new FloatReader().readFloat(buf); // fuel consumtion
- extendedInfo.append("<hours>").append(new FloatReader().readFloat(buf)).append("</hours>");
- extendedInfo.append("<tank>").append(buf.readUnsignedByte() * 0.4).append("</tank>");
+ extendedInfo.set("hours", new FloatReader().readFloat(buf));
+ extendedInfo.set("tank", buf.readUnsignedByte() * 0.4);
}
if (checkBit(flags, 2)) {
- extendedInfo.append("<engine>").append(buf.readUnsignedShort() * 0.125).append("</engine>");
- extendedInfo.append("<pedals>").append(buf.readUnsignedByte()).append("</pedals>");
- extendedInfo.append("<temperature>").append(buf.readUnsignedByte() - 40).append("</temperature>");
+ 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("<fuel>").append(buf.readUnsignedShort()).append("</fuel>");
- extendedInfo.append("<adc2>").append(buf.readUnsignedShort()).append("</adc2>");
- extendedInfo.append("<adc3>").append(buf.readUnsignedShort()).append("</adc3>");
- extendedInfo.append("<adc4>").append(buf.readUnsignedShort()).append("</adc4>");
+ 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("<temperature>");
- extendedInfo.append(buf.readByte());
- extendedInfo.append("</temperature>");
+ extendedInfo.set("temperature", buf.readByte());
buf.getUnsignedByte(buf.readerIndex()); // control (>> 4)
- extendedInfo.append("<sensor>");
- extendedInfo.append(buf.readUnsignedShort() & 0x0fff);
- extendedInfo.append("</sensor>");
+ extendedInfo.set("sensor", buf.readUnsignedShort() & 0x0fff);
buf.readUnsignedShort(); // old sensor state (& 0x0fff)
}
if (checkBit(flags, 5)) {
- extendedInfo.append("<battery>");
- extendedInfo.append(buf.getUnsignedByte(buf.readerIndex()) >> 2);
- extendedInfo.append("</battery>");
+ extendedInfo.set("battery", buf.getUnsignedByte(buf.readerIndex()) >> 2);
position.setPower((double) (buf.readUnsignedShort() & 0x03ff));
buf.readByte(); // microcontroller temperature
- extendedInfo.append("<gsm>");
- extendedInfo.append(buf.getUnsignedByte(buf.readerIndex()) >> 5);
- extendedInfo.append("</gsm>");
+ extendedInfo.set("gsm", buf.getUnsignedByte(buf.readerIndex()) >> 5);
int satellites = buf.readUnsignedByte() & 0x1f;
position.setValid(satellites >= 3);
- extendedInfo.append("<satellites>").append(satellites).append("</satellites>");
+ 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("<protocol>navigil</protocol>");
+ 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("<protocol>navigil</protocol>");
+ 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("<protocol>navigil</protocol>");
+ 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("<protocol>navigil</protocol>");
+ 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("<protocol>navigil</protocol>");
+ 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("<protocol>navigil</protocol>");
+ 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("<protocol>navis</protocol>");
+ 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("<format>");
- extendedInfo.append(format);
- extendedInfo.append("</format>");
+ extendedInfo.set("format", format);
position.setId(buf.readUnsignedInt()); // sequence number
// Event type
- extendedInfo.append("<event>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</event>");
+ 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("<time>");
- extendedInfo.append(time.getTimeInMillis());
- extendedInfo.append("</time>");
+ extendedInfo.set("time", time.getTimeInMillis());
// Alarm status
- extendedInfo.append("<alarm>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</alarm>");
+ extendedInfo.set("alarm", buf.readUnsignedByte());
// Modules status
- extendedInfo.append("<status>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</status>");
+ extendedInfo.set("status", buf.readUnsignedByte());
// GSM signal
- extendedInfo.append("<gsm>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</gsm>");
+ extendedInfo.set("gsm", buf.readUnsignedByte());
// Output
- extendedInfo.append("<output>");
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("</output>");
// Input
- extendedInfo.append("<input>");
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("</input>");
position.setPower(buf.readUnsignedShort() / 1000.0); // power
// Battery power
- extendedInfo.append("<battery>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</battery>");
+ extendedInfo.set("battery", buf.readUnsignedShort());
// Temperature
if (isFormat(format, F10, F20, F30)) {
- extendedInfo.append("<temperature>");
- extendedInfo.append(buf.readShort());
- extendedInfo.append("</temperature>");
+ extendedInfo.set("temperature", buf.readShort());
}
if (isFormat(format, F10, F20, F50, F52)) {
- // ADC 1
- extendedInfo.append("<adc1>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</adc1>");
-
- // ADC 2
- extendedInfo.append("<adc2>");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</adc2>");
+ 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("<milage>");
- extendedInfo.append(buf.readFloat());
- extendedInfo.append("</milage>");
+ extendedInfo.set("milage", buf.readFloat());
// Last segment
- extendedInfo.append("<segment>");
- extendedInfo.append(buf.readFloat());
- extendedInfo.append("</segment>");
+ 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("<protocol>progress</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("progress");
position.setDeviceId(deviceId);
// Message index
if (type == MSG_LOGMSG) {
- extendedInfo.append("<archive>true</archive>");
+ extendedInfo.set("archive", true);
int subtype = buf.readUnsignedShort();
if (subtype == MSG_ALARM) {
- extendedInfo.append("<alarm>true</alarm>");
+ 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("<satellites>");
- extendedInfo.append(satellitesNumber);
- extendedInfo.append("</satellites>");
+ extendedInfo.set("satellites", satellitesNumber);
// Validity
position.setValid(satellitesNumber >= 3); // TODO: probably wrong
// Cell signal
- extendedInfo.append("<gsm>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</gsm>");
+ extendedInfo.set("gsm", buf.readUnsignedByte());
// Milage
- extendedInfo.append("<milage>");
- extendedInfo.append(buf.readUnsignedInt());
- extendedInfo.append("</milage>");
+ 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("<adc").append(i).append(">");
- extendedInfo.append(buf.readUnsignedShort());
- extendedInfo.append("</adc").append(i).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("<can>");
- extendedInfo.append(buf.toString(buf.readerIndex(), size, Charset.defaultCharset()));
- extendedInfo.append("</can>");
+ 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("<passenger>");
- extendedInfo.append(hex);
- extendedInfo.append("</passenger>");
+ 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("<alarm>true</alarm>");
+ 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("<protocol>pt502</protocol>");
+ 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("<protocol>skypatrol</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("skypatrol");
// Status code
if (checkBit(mask, 1)) {
- extendedInfo.append("<status>");
- extendedInfo.append(buf.readUnsignedInt());
- extendedInfo.append("</status>");
+ extendedInfo.set("status", buf.readUnsignedInt());
}
// Device id
@@ -183,9 +182,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
// Satellites
if (checkBit(mask, 16)) {
- extendedInfo.append("<satellites>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</satellites>");
+ extendedInfo.set("satellites", buf.readUnsignedByte());
}
// Battery percentage
@@ -195,16 +192,12 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
// Trip milage
if (checkBit(mask, 20)) {
- extendedInfo.append("<trip>");
- extendedInfo.append(buf.readUnsignedInt());
- extendedInfo.append("</trip>");
+ extendedInfo.set("trip", buf.readUnsignedInt());
}
// Milage
if (checkBit(mask, 21)) {
- extendedInfo.append("<milage>");
- extendedInfo.append(buf.readUnsignedInt());
- extendedInfo.append("</milage>");
+ 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("<protocol>syrus</protocol>");
+ 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("<protocol>teltonika</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("teltonika");
position.setDeviceId(deviceId);
position.setTime(new Date(buf.readLong()));
-
- extendedInfo.append("<priority>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</priority>");
+
+ 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("<satellites>");
int satellites = buf.readUnsignedByte();
- extendedInfo.append(satellites);
- extendedInfo.append("</satellites>");
+ extendedInfo.set("satellites", satellites);
position.setValid(satellites != 0);
position.setSpeed((double) buf.readUnsignedShort());
-
- extendedInfo.append("<event>");
- extendedInfo.append(buf.readUnsignedByte());
- extendedInfo.append("</event>");
+
+ 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("<protocol>tk102</protocol>");
+ 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("<protocol>tk103</protocol>");
+ 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("<state>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</state>");
+ extendedInfo.set("state", parser.group(index++));
// Milage
- extendedInfo.append("<milage>");
- extendedInfo.append(Integer.parseInt(parser.group(index++), 16));
- extendedInfo.append("</milage>");
+ 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("<protocol>tlt2h</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("tlt2h");
position.setDeviceId(deviceId);
Integer index = 1;
// Cell
- String cell = parser.group(index++);
- if (cell != null) {
- extendedInfo.append("<cell>").append(cell).append("</cell>");
- }
+ 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("<protocol>tr20</protocol>");
+ 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("<protocol>V680</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("v680");
Integer index = 1;
// Get device by IMEI
@@ -80,27 +81,19 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
}
// User
- extendedInfo.append("<user>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</user>");
+ extendedInfo.set("user", parser.group(index++));
// Validity
position.setValid(parser.group(index++).compareTo("1") == 0 ? true : false);
// Password
- extendedInfo.append("<password>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</password>");
+ extendedInfo.set("password", parser.group(index++));
// Packet number
- extendedInfo.append("<packet>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</packet>");
+ extendedInfo.set("packet", parser.group(index++));
// GSM base station
- extendedInfo.append("<gsm>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</gsm>");
+ 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("<protocol>wialon</protocol>");
+ 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("<satellites>");
- extendedInfo.append(satellites);
- extendedInfo.append("</satellites>");
+ 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("<protocol>wondex</protocol>");
+ 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("<satellites>").append(satellites).append("</satellites>");
+ extendedInfo.set("satellites", satellites);
// Event
- extendedInfo.append("<event>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</event>");
+ extendedInfo.set("event", parser.group(index++));
// Milage
- String milage = parser.group(index++);
- if (milage != null) {
- extendedInfo.append("<milage>").append(milage).append("</milage>");
- }
+ extendedInfo.set("milage", parser.group(index++));
// Input
- String input = parser.group(index++);
- if (input != null) {
- extendedInfo.append("<input>").append(input).append("</input>");
- }
+ extendedInfo.set("input", parser.group(index++));
// ADC
- String adc1 = parser.group(index++);
- if (adc1 != null) {
- extendedInfo.append("<adc1>").append(adc1).append("</adc1>");
- }
- String adc2 = parser.group(index++);
- if (adc2 != null) {
- extendedInfo.append("<adc2>").append(adc2).append("</adc2>");
- }
+ extendedInfo.set("adc1", parser.group(index++));
+ extendedInfo.set("adc2", parser.group(index++));
// Output
- String output = parser.group(index++);
- if (output != null) {
- extendedInfo.append("<output>").append(output).append("</output>");
- }
+ 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("<protocol>xexun2</protocol>");
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("xexun2");
Integer index = 1;
// Serial
- extendedInfo.append("<serial>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</serial>");
+ extendedInfo.set("serial", parser.group(index++));
// Number
- extendedInfo.append("<number>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</number>");
+ 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("<signal>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</signal>");
+ extendedInfo.set("signal", parser.group(index++));
// Alarm
- extendedInfo.append("<alarm>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</alarm>");
+ 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("<satellites>");
- extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", ""));
- extendedInfo.append("</satellites>");
+ 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("<protocol>xt7</protocol>");
+ 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("<imsi>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</imsi>");
+ extendedInfo.set("imsi", parser.group(index++));
// Cell
- extendedInfo.append("<cell>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</cell>");
+ extendedInfo.set("cell", parser.group(index++));
// GSM signal quality
- extendedInfo.append("<gsm>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</gsm>");
+ extendedInfo.set("gsm", parser.group(index++));
// Battery
position.setPower(Double.valueOf(parser.group(index++)));
// Flags
- extendedInfo.append("<flags>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</flags>");
+ extendedInfo.set("flags", parser.group(index++));
// Sensors
- extendedInfo.append("<sensors>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</sensors>");
+ extendedInfo.set("sensors", parser.group(index++));
// Fuel
- extendedInfo.append("<fuel>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</fuel>");
+ extendedInfo.set("fuel", parser.group(index++));
// Alarm
- extendedInfo.append("<alarm>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</alarm>");
+ 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("<protocol>ywt</protocol>");
+ 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("<satellites>").append(satellites).append("</satellites>");
+ extendedInfo.set("satellites", satellites);
// Report identifier
String reportId = parser.group(index++);
// Status
- extendedInfo.append("<status>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</status>");
+ extendedInfo.set("status", parser.group(index++));
// Send response
if (type.equals("KP") || type.equals("EP") || type.equals("EP")) {