aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-04-01 14:11:20 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-04-01 14:11:20 +1300
commit571078422b3e1162870d777124a3844da56583b0 (patch)
tree74aff22ab9f71e7170d2e618af70745c207ad92c /src/org/traccar
parent8972c89df0efd530197dcc3d33cb928124a799c7 (diff)
downloadtraccar-server-571078422b3e1162870d777124a3844da56583b0.tar.gz
traccar-server-571078422b3e1162870d777124a3844da56583b0.tar.bz2
traccar-server-571078422b3e1162870d777124a3844da56583b0.zip
Refactor GL200 protocol decoder
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java157
1 files changed, 49 insertions, 108 deletions
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 886c3d08d..1c81ca5d6 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -115,16 +115,14 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.number("(dddd)(dd)(dd)") // date (yyyymmdd)
.number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
.text(",")
- .groupBegin()
- .number("(0ddd)?,") // mcc
- .number("(0ddd)?,") // mnc
- .number("(xxxx)?,") // lac
- .number("(xxxx)?,") // cell
- .or()
.number("(d+)?,") // mcc
.number("(d+)?,") // mnc
- .number("(d+)?,") // lac
- .number("(d+)?,") // cell
+ .groupBegin()
+ .number("(d+),") // lac
+ .number("(d+),") // cid
+ .or()
+ .number("(x+)?,") // lac
+ .number("(x+)?,") // cid
.groupEnd()
.number("(?:d+|(d+.d))?,") // odometer
.compile();
@@ -296,10 +294,10 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.number("(dddd)(dd)(dd)") // date (yyyymmdd)
.number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
.text(",")
- .number("(0ddd),") // mcc
- .number("(0ddd),") // mnc
- .number("(xxxx),") // lac
- .number("(xxxx),").optional(4) // cell
+ .number("(d+),") // mcc
+ .number("(d+),") // mnc
+ .number("(x+),") // lac
+ .number("(x+),").optional(4) // cell
.any()
.number("(dddd)(dd)(dd)") // date (yyyymmdd)
.number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
@@ -334,22 +332,26 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- private Object decodeInf(Channel channel, SocketAddress remoteAddress, String sentence) {
-
- Parser parser = new Parser(PATTERN_INF, sentence);
- if (!parser.matches()) {
- return null;
+ private Position initPosition(Parser parser, Channel channel, SocketAddress remoteAddress) {
+ if (parser.matches()) {
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession != null) {
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+ return position;
+ }
}
+ return null;
+ }
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
+ private Object decodeInf(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_INF, sentence);
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
position.set(Position.KEY_STATUS, parser.next());
parser.next(); // odometer or external power
@@ -378,19 +380,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeVer(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_VER, sentence);
- if (!parser.matches()) {
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
position.set("deviceType", parser.next());
position.set(Position.KEY_VERSION_FW, parser.nextInt(16));
position.set(Position.KEY_VERSION_HW, parser.nextInt(16));
@@ -418,31 +412,26 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
}
- if (parser.hasNext(4)) {
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16))));
+ if (parser.hasNext(6)) {
+ int mcc = parser.nextInt();
+ int mnc = parser.nextInt();
+ if (parser.hasNext(2)) {
+ position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(), parser.nextInt())));
+ } else {
+ position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(16), parser.nextInt(16))));
+ }
}
- parser.skip(4); // alternative networks
-
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
}
private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_OBD, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
position.set(Position.KEY_RPM, parser.next());
position.set(Position.KEY_OBD_SPEED, parser.next());
position.set(Position.PREFIX_TEMP + 1, parser.next());
@@ -536,19 +525,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeIgn(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_IGN, sentence);
- if (!parser.matches()) {
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
decodeLocation(position, parser);
position.set(Position.KEY_HOURS, parser.next());
@@ -563,19 +544,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeIda(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_IDA, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
position.set(Position.KEY_RFID, parser.next());
decodeLocation(position, parser);
@@ -591,19 +564,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeWif(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_WIF, sentence);
- if (!parser.matches()) {
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
getLastLocation(position, null);
Network network = new Network();
@@ -625,19 +590,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeGsm(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_GSM, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
getLastLocation(position, null);
Network network = new Network();
@@ -659,19 +616,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeOther(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
int reportType = parser.nextInt();
if (type.equals("NMR")) {
position.set(Position.KEY_MOTION, reportType);
@@ -699,19 +648,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeBasic(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
Parser parser = new Parser(PATTERN_BASIC, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
int hdop = parser.nextInt();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop);