aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-07-16 09:49:51 -0700
committerGitHub <noreply@github.com>2019-07-16 09:49:51 -0700
commit4c4fb4d90a1aeb1acbdfd11516644b1a149605bd (patch)
tree8bc5b6e449c4a7203fc7fc3d87deabae2d125ccc /src
parent89b62696bdd9afa6a6f5eec65c4282bf4131ffd7 (diff)
parent84fd882f8a9ca7d1e90cd5f40dfe04979498e7f5 (diff)
downloadtraccar-server-4c4fb4d90a1aeb1acbdfd11516644b1a149605bd.tar.gz
traccar-server-4c4fb4d90a1aeb1acbdfd11516644b1a149605bd.tar.bz2
traccar-server-4c4fb4d90a1aeb1acbdfd11516644b1a149605bd.zip
Merge pull request #4352 from edvalley/proposed
Enhance Laipac protocol decoder (2)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/model/Position.java1
-rw-r--r--src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java43
-rw-r--r--src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java2
3 files changed, 43 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/model/Position.java b/src/main/java/org/traccar/model/Position.java
index 4c28ae59b..2c0e22c9e 100644
--- a/src/main/java/org/traccar/model/Position.java
+++ b/src/main/java/org/traccar/model/Position.java
@@ -84,6 +84,7 @@ public class Position extends Message {
public static final String KEY_AXLE_WEIGHT = "axleWeight";
public static final String KEY_G_SENSOR = "gSensor";
public static final String KEY_ICCID = "iccid";
+ public static final String KEY_PHONE = "phone";
public static final String KEY_DTCS = "dtcs";
public static final String KEY_OBD_SPEED = "obdSpeed"; // knots
diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
index 2302015f5..2185b707e 100644
--- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -40,7 +40,18 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
public static final String DEFAULT_DEVICE_PASSWORD = "00000000";
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_EAVSYS = new PatternBuilder()
+ .text("$EAVSYS,")
+ .expression("([^,]+),") // identifier
+ .expression("([0-9]+),") // iccid
+ .expression("(\\+?[0-9]+)?,") // sim phone number
+ .expression("(?:[^,]*),") // owner name
+ .expression("([^,]*)?") // firmware version
+ .text("*")
+ .number("(xx)") // checksum
+ .compile();
+
+ private static final Pattern PATTERN_AVRMC = new PatternBuilder()
.text("$AVRMC,")
.expression("([^,]+),") // identifier
.number("(dd)(dd)(dd),") // time (hhmmss)
@@ -158,10 +169,36 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
}
+ protected Object decodeEavsys(
+ String sentence, Channel channel, SocketAddress remoteAddress) {
+
+ Parser parser = new Parser(PATTERN_EAVSYS, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession =
+ getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_ICCID, parser.next());
+ position.set(Position.KEY_PHONE, parser.next());
+ position.set(Position.KEY_VERSION_FW, parser.next());
+
+ return position;
+ }
+
protected Object decodeAvrmc(
String sentence, Channel channel, SocketAddress remoteAddress) {
- Parser parser = new Parser(PATTERN, sentence);
+ Parser parser = new Parser(PATTERN_AVRMC, sentence);
if (!parser.matches()) {
return null;
}
@@ -234,6 +271,8 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(sentence + "\r\n", remoteAddress));
}
+ } else if (sentence.startsWith("$EAVSYS")) {
+ return decodeEavsys(sentence, channel, remoteAddress);
} else if (sentence.startsWith("$AVRMC")) {
return decodeAvrmc(sentence, channel, remoteAddress);
}
diff --git a/src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java
index 0bbb58490..5b66ed865 100644
--- a/src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java
@@ -22,7 +22,7 @@ public class LaipacProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, text(
"$AVSYS,MSG00002,14406,7046811160,64*1A"));
- verifyNull(decoder, text(
+ verifyAttributes(decoder, text(
"$EAVSYS,MSG00002,8931086013104404999,,Owner,0x52014406*76"));
verifyNull(decoder, text(