aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Xexun2ProtocolDecoder.java
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/org/traccar/protocol/Xexun2ProtocolDecoder.java
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/org/traccar/protocol/Xexun2ProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/Xexun2ProtocolDecoder.java32
1 files changed, 10 insertions, 22 deletions
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++)));