From 2c49e03702b7a9959eed87b8d5b2ae48c380025d Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Fri, 12 Jul 2019 19:01:01 -0400 Subject: Allow to know if last position was found --- src/main/java/org/traccar/BaseProtocolDecoder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java index aa5be612e..f0642f509 100644 --- a/src/main/java/org/traccar/BaseProtocolDecoder.java +++ b/src/main/java/org/traccar/BaseProtocolDecoder.java @@ -184,7 +184,9 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } } - public void getLastLocation(Position position, Date deviceTime) { + public boolean getLastLocation(Position position, Date deviceTime) { + boolean found = false; + if (position.getDeviceId() != 0) { position.setOutdated(true); @@ -198,6 +200,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { position.setSpeed(last.getSpeed()); position.setCourse(last.getCourse()); position.setAccuracy(last.getAccuracy()); + found = true; } else { position.setFixTime(new Date(0)); } @@ -208,6 +211,8 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { position.setDeviceTime(new Date()); } } + + return found; } @Override -- cgit v1.2.3 From 646a9874c7a18d032627360bbcf948bf154a0ead Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Fri, 12 Jul 2019 19:03:57 -0400 Subject: Laipac protocol decoder: decode EAVSYS messages --- .../traccar/protocol/LaipacProtocolDecoder.java | 54 +++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 2302015f5..13451f798 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -40,7 +40,20 @@ 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("([^,]*),") // reserved + .expression("([^,]*),") // reserved + .text("0x") + .number("(xx)") // product type + .number("(dd)(dd)(dd)") // firmware version (major, minor, revision) + .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 +171,45 @@ 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()); + + if (!getLastLocation(position, null)) { + return null; + } + + position.set(Position.KEY_ICCID, parser.next()); + + String unused = parser.next(); + unused = parser.next(); + + int hardware = parser.nextHexInt(); + position.set(Position.KEY_VERSION_HW, + (hardware == 0x12) ? "SF-Lite" : (hardware == 0x52) ? "S911 Lola" : null); + position.set(Position.KEY_VERSION_FW, String.format("%d.%02d.%02d", + parser.nextInt(), parser.nextInt(), parser.nextInt())); + + 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 +282,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); } -- cgit v1.2.3 From d60f27310aa094b8b58b66a5833e639cd45f4f93 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Tue, 16 Jul 2019 10:05:37 -0400 Subject: Changes after first review --- src/main/java/org/traccar/BaseProtocolDecoder.java | 7 +----- src/main/java/org/traccar/model/Position.java | 1 + .../traccar/protocol/LaipacProtocolDecoder.java | 27 ++++++++++------------ .../protocol/LaipacProtocolDecoderTest.java | 2 +- 4 files changed, 15 insertions(+), 22 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java index f0642f509..aa5be612e 100644 --- a/src/main/java/org/traccar/BaseProtocolDecoder.java +++ b/src/main/java/org/traccar/BaseProtocolDecoder.java @@ -184,9 +184,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } } - public boolean getLastLocation(Position position, Date deviceTime) { - boolean found = false; - + public void getLastLocation(Position position, Date deviceTime) { if (position.getDeviceId() != 0) { position.setOutdated(true); @@ -200,7 +198,6 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { position.setSpeed(last.getSpeed()); position.setCourse(last.getCourse()); position.setAccuracy(last.getAccuracy()); - found = true; } else { position.setFixTime(new Date(0)); } @@ -211,8 +208,6 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { position.setDeviceTime(new Date()); } } - - return found; } @Override diff --git a/src/main/java/org/traccar/model/Position.java b/src/main/java/org/traccar/model/Position.java index 4c28ae59b..51743d0de 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_NUMBER = "phoneNumber"; 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 13451f798..924725041 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -44,11 +44,9 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { .text("$EAVSYS,") .expression("([^,]+),") // identifier .expression("([0-9]+),") // iccid - .expression("([^,]*),") // reserved - .expression("([^,]*),") // reserved - .text("0x") - .number("(xx)") // product type - .number("(dd)(dd)(dd)") // firmware version (major, minor, revision) + .expression("(\\+?[0-9]*),") // sim phone number + .expression("(?:[^,]*),") // owner name + .expression("([^,]*)") // firmware version .text("*") .number("(xx)") // checksum .compile(); @@ -188,20 +186,19 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - if (!getLastLocation(position, null)) { - return null; - } + getLastLocation(position, null); position.set(Position.KEY_ICCID, parser.next()); - String unused = parser.next(); - unused = parser.next(); + String phoneNumber = parser.next(); + if (!phoneNumber.isEmpty()) { + position.set(Position.KEY_PHONE_NUMBER, phoneNumber); + } - int hardware = parser.nextHexInt(); - position.set(Position.KEY_VERSION_HW, - (hardware == 0x12) ? "SF-Lite" : (hardware == 0x52) ? "S911 Lola" : null); - position.set(Position.KEY_VERSION_FW, String.format("%d.%02d.%02d", - parser.nextInt(), parser.nextInt(), parser.nextInt())); + String firmware = parser.next(); + if (!firmware.isEmpty()) { + position.set(Position.KEY_VERSION_FW, firmware); + } return position; } diff --git a/src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java index 0bbb58490..1cbf50e2c 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( + verifyNotNull(decoder, text( "$EAVSYS,MSG00002,8931086013104404999,,Owner,0x52014406*76")); verifyNull(decoder, text( -- cgit v1.2.3 From 84fd882f8a9ca7d1e90cd5f40dfe04979498e7f5 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Tue, 16 Jul 2019 12:04:50 -0400 Subject: Changes after second review --- src/main/java/org/traccar/model/Position.java | 2 +- .../java/org/traccar/protocol/LaipacProtocolDecoder.java | 16 ++++------------ .../org/traccar/protocol/LaipacProtocolDecoderTest.java | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/model/Position.java b/src/main/java/org/traccar/model/Position.java index 51743d0de..2c0e22c9e 100644 --- a/src/main/java/org/traccar/model/Position.java +++ b/src/main/java/org/traccar/model/Position.java @@ -84,7 +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_NUMBER = "phoneNumber"; + 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 924725041..2185b707e 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -44,9 +44,9 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { .text("$EAVSYS,") .expression("([^,]+),") // identifier .expression("([0-9]+),") // iccid - .expression("(\\+?[0-9]*),") // sim phone number + .expression("(\\+?[0-9]+)?,") // sim phone number .expression("(?:[^,]*),") // owner name - .expression("([^,]*)") // firmware version + .expression("([^,]*)?") // firmware version .text("*") .number("(xx)") // checksum .compile(); @@ -189,16 +189,8 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); position.set(Position.KEY_ICCID, parser.next()); - - String phoneNumber = parser.next(); - if (!phoneNumber.isEmpty()) { - position.set(Position.KEY_PHONE_NUMBER, phoneNumber); - } - - String firmware = parser.next(); - if (!firmware.isEmpty()) { - position.set(Position.KEY_VERSION_FW, firmware); - } + position.set(Position.KEY_PHONE, parser.next()); + position.set(Position.KEY_VERSION_FW, parser.next()); return position; } diff --git a/src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/LaipacProtocolDecoderTest.java index 1cbf50e2c..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")); - verifyNotNull(decoder, text( + verifyAttributes(decoder, text( "$EAVSYS,MSG00002,8931086013104404999,,Owner,0x52014406*76")); verifyNull(decoder, text( -- cgit v1.2.3