From d62797376e7dc1d5810c1b8728da1e5443cc8e14 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 18 Jul 2017 06:56:03 +1200 Subject: Refactor TAIP decoder --- src/org/traccar/protocol/TaipProtocolDecoder.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol/TaipProtocolDecoder.java') diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index 7702a89fb..a08bb6f2b 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -104,15 +104,21 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); + Integer event = null; + if (parser.hasNext(3)) { - position.set(Position.KEY_EVENT, parser.nextInt(0)); + event = parser.nextInt(); position.setTime(getTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0))); } else if (parser.hasNext()) { position.setTime(getTime(parser.nextInt(0))); } if (parser.hasNext()) { - position.set(Position.KEY_EVENT, parser.nextInt(0)); + event = parser.nextInt(); + } + + if (event != null) { + position.set(Position.KEY_EVENT, event); } if (parser.hasNext(6)) { @@ -150,6 +156,12 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { attributes = sentence.substring(beginIndex, endIndex).split(";"); } + return decodeAttributes(channel, remoteAddress, position, attributes); + } + + private Position decodeAttributes( + Channel channel, SocketAddress remoteAddress, Position position, String[] attributes) { + String uniqueId = null; DeviceSession deviceSession = null; String messageIndex = null; -- cgit v1.2.3 From a7c2aa4a3faddb007a82523b2119134eaa45bea7 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 18 Jul 2017 07:28:00 +1200 Subject: Implement additional Syrus data --- src/org/traccar/model/Position.java | 1 + src/org/traccar/protocol/TaipProtocolDecoder.java | 40 +++++++++++++++++----- .../traccar/protocol/TaipProtocolDecoderTest.java | 3 ++ 3 files changed, 36 insertions(+), 8 deletions(-) (limited to 'src/org/traccar/protocol/TaipProtocolDecoder.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 9e7bac932..4412b012c 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -111,6 +111,7 @@ public class Position extends Message { public static final String ALARM_TOW = "tow"; public static final String ALARM_ACCELERATION = "hardAcceleration"; public static final String ALARM_BREAKING = "hardBreaking"; + public static final String ALARM_CORNERING = "hardCornering"; public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving"; public static final String ALARM_POWER_CUT = "powerCut"; public static final String ALARM_POWER_RESTORED = "powerRestored"; diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index a08bb6f2b..6edf4a93e 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -18,6 +18,7 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.helper.BitUtil; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.DateUtil; @@ -118,7 +119,24 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { } if (event != null) { - position.set(Position.KEY_EVENT, event); + switch (event) { + case 22: + position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + break; + case 23: + position.set(Position.KEY_ALARM, Position.ALARM_BREAKING); + break; + case 24: + position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); + break; + case 26: + case 28: + position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + break; + default: + position.set(Position.KEY_EVENT, event); + break; + } } if (parser.hasNext(6)) { @@ -173,7 +191,6 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { String key = attribute.substring(0, index).toLowerCase(); String value = attribute.substring(index + 1); switch (key) { - case "id": uniqueId = value; deviceSession = getDeviceSession(channel, remoteAddress, value); @@ -181,23 +198,30 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); } break; - + case "io": + position.set(Position.KEY_IGNITION, BitUtil.check(value.charAt(0) - '0', 0)); + position.set(Position.KEY_CHARGE, BitUtil.check(value.charAt(0) - '0', 1)); + position.set(Position.KEY_OUTPUT, value.charAt(1) - '0'); + position.set(Position.KEY_INPUT, value.charAt(2) - '0'); + break; + case "ix": + position.set(Position.PREFIX_IO + 1, value); + break; + case "ad": + position.set(Position.PREFIX_ADC + 1, Integer.parseInt(value)); + break; case "sv": position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); break; - case "bl": - position.set(Position.KEY_BATTERY, Integer.parseInt(value)); + position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.001); break; - case "vo": position.set(Position.KEY_ODOMETER, Long.parseLong(value)); break; - default: position.set(key, value); break; - } } else if (attribute.startsWith("#")) { messageIndex = attribute; diff --git a/test/org/traccar/protocol/TaipProtocolDecoderTest.java b/test/org/traccar/protocol/TaipProtocolDecoderTest.java index 6d24a504f..e2de26ec0 100644 --- a/test/org/traccar/protocol/TaipProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TaipProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class TaipProtocolDecoderTest extends ProtocolTest { TaipProtocolDecoder decoder = new TaipProtocolDecoder(new TaipProtocol()); + verifyPosition(decoder, text( + ">REV001958003965+0307178+1016144900031532;IO=300;SV=8;BL=4159;CF=8161,C,13;AD=14145;IX=10233040;FF=0,0,0,0;VO=338578;ID=357042063052352<")); + verifyPosition(decoder, text( ">REV011958000369+0307185+1016144400000032;IO=200;SV=9;BL=4158;CF=0,0,0;AD=12347;IX=10213040;FF=0,0,0,0;VO=338572;ID=357042063052352<")); -- cgit v1.2.3 From 4ef26b62cb97fc2afa5fdcf260c5fffbdc454c25 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 27 Sep 2017 15:27:10 +1300 Subject: Fix typo in alarm name --- src/org/traccar/model/Position.java | 2 +- src/org/traccar/protocol/AplicomProtocolDecoder.java | 2 +- src/org/traccar/protocol/AquilaProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 14 +++++++------- src/org/traccar/protocol/Pt502ProtocolDecoder.java | 2 +- src/org/traccar/protocol/SuntechProtocolDecoder.java | 2 +- src/org/traccar/protocol/TaipProtocolDecoder.java | 2 +- src/org/traccar/protocol/TzoneProtocolDecoder.java | 2 +- src/org/traccar/protocol/Vt200ProtocolDecoder.java | 2 +- src/org/traccar/protocol/VtfmsProtocolDecoder.java | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/org/traccar/protocol/TaipProtocolDecoder.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 93456b1b0..099e6d686 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -115,7 +115,7 @@ public class Position extends Message { public static final String ALARM_ACCIDENT = "accident"; public static final String ALARM_TOW = "tow"; public static final String ALARM_ACCELERATION = "hardAcceleration"; - public static final String ALARM_BREAKING = "hardBreaking"; + public static final String ALARM_BRAKING = "hardBraking"; public static final String ALARM_CORNERING = "hardCornering"; public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving"; public static final String ALARM_POWER_CUT = "powerCut"; diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index 94d12c633..154451b5b 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -568,7 +568,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); position.set("speedMax", buf.readUnsignedByte()); position.set("speedMin", buf.readUnsignedByte()); - position.set("hardBreaking", buf.readUnsignedByte()); + position.set("hardBraking", buf.readUnsignedByte()); } if ((selector & 0x0200) != 0) { diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java index 5ff974a7d..773210b04 100644 --- a/src/org/traccar/protocol/AquilaProtocolDecoder.java +++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java @@ -81,7 +81,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { .number("[01],") // corner packet .number("(?:d+,){6}") // reserved .number("[01],") // hard acceleration - .number("[01],") // hard breaking + .number("[01],") // hard braking .number("[01],[01],[01],[01],") // course bits .number("(d+),") // external voltage .number("(d+),") // internal voltage @@ -115,7 +115,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { .number("[01],") // do 1 .number("[01],") // reserved .number("[01],") // hard acceleration - .number("[01],") // hard breaking + .number("[01],") // hard braking .number("(?:[01],){4}") // reserved .number("(d+),") // external voltage .number("(d+),") // internal voltage diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index b9725337b..e41a42843 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -94,8 +94,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // single fuel consumption .number("(d+.d+),") // total fuel consumption .number("(d+),") // error code count - .number("(d+),") // harsh acceleration count - .number("(d+)") // harsh break count + .number("(d+),") // hard acceleration count + .number("(d+)") // hard brake count .compile(); private static final Pattern PATTERN_OBDA = new PatternBuilder() @@ -106,8 +106,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // average speed .number("(d+),") // history highest speed .number("(d+),") // history highest rpm - .number("(d+),") // total harsh acceleration - .number("(d+)") // total harsh break n0 + .number("(d+),") // total hard acceleration + .number("(d+)") // total hard brake .compile(); public static final int MSG_HEARTBEAT = 0x0001; @@ -201,7 +201,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { case 0x53: return Position.ALARM_GPS_ANTENNA_CUT; case 0x72: - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case 0x73: return Position.ALARM_ACCELERATION; default: @@ -301,8 +301,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { position.set("singleFuelConsumption", parser.nextDouble()); position.set("totalFuelConsumption", parser.nextDouble()); position.set(Position.KEY_DTCS, parser.nextInt()); - position.set("harshAcelerationNo", parser.nextInt()); - position.set("harshBreakerNo", parser.nextInt()); + position.set("hardAccelerationCount", parser.nextInt()); + position.set("hardBrakingCount", parser.nextInt()); return position; } diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index e12bbdf28..fef5d9b39 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -67,7 +67,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { case "HDA": return Position.ALARM_ACCELERATION; case "HDB": - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case "FDA": return Position.ALARM_FATIGUE_DRIVING; case "SKA": diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index 320df9c94..6dfc6f77f 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -147,7 +147,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { case 46: return Position.ALARM_ACCELERATION; case 47: - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case 48: return Position.ALARM_ACCIDENT; case 50: diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index 6edf4a93e..c6220ab1d 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -124,7 +124,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); break; case 23: - position.set(Position.KEY_ALARM, Position.ALARM_BREAKING); + position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); break; case 24: position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index 69aa916df..76903c90c 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -43,7 +43,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { case 0x11: return Position.ALARM_OVERSPEED; case 0x14: - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case 0x15: return Position.ALARM_ACCELERATION; case 0x30: diff --git a/src/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/org/traccar/protocol/Vt200ProtocolDecoder.java index 6be70c3c1..2ae24efbb 100644 --- a/src/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -124,7 +124,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { position.set("maxRpm", buf.readUnsignedShort()); position.set("maxTemp", buf.readUnsignedByte() - 40); position.set("hardAccelerationCount", buf.readUnsignedByte()); - position.set("hardBreakingCount", buf.readUnsignedByte()); + position.set("hardBrakingCount", buf.readUnsignedByte()); for (String speedType : Arrays.asList("over", "high", "normal", "low")) { position.set(speedType + "SpeedTime", buf.readUnsignedShort()); diff --git a/src/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/org/traccar/protocol/VtfmsProtocolDecoder.java index 852b9a749..5fb687e6d 100644 --- a/src/org/traccar/protocol/VtfmsProtocolDecoder.java +++ b/src/org/traccar/protocol/VtfmsProtocolDecoder.java @@ -84,7 +84,7 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { case 15: return Position.ALARM_POWER_RESTORED; case 32: - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case 33: return Position.ALARM_ACCELERATION; default: -- cgit v1.2.3 From 96e15853b9c28bd31295ca2c014e226e4a50aaa1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 24 Oct 2017 23:41:30 +1300 Subject: Improve TAIP validity handling --- src/org/traccar/protocol/TaipProtocolDecoder.java | 3 +-- test/org/traccar/protocol/TaipProtocolDecoderTest.java | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol/TaipProtocolDecoder.java') diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index c6220ab1d..e7117a5c9 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -68,7 +68,6 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { .number("(x{8})") // odometer .number("[01]") // gps power .groupEnd("?") - .number("(d)") // fix mode .any() .compile(); @@ -162,7 +161,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0)); } - position.setValid(parser.nextInt(0) != 0); + position.setValid(true); String[] attributes = null; beginIndex = sentence.indexOf(';'); diff --git a/test/org/traccar/protocol/TaipProtocolDecoderTest.java b/test/org/traccar/protocol/TaipProtocolDecoderTest.java index e2de26ec0..beba54d74 100644 --- a/test/org/traccar/protocol/TaipProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TaipProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class TaipProtocolDecoderTest extends ProtocolTest { TaipProtocolDecoder decoder = new TaipProtocolDecoder(new TaipProtocol()); + verifyPosition(decoder, text( + ">RPV46640+4197412-0752857900015802;ID=5102;*71<")); + + verifyNull(decoder, text( + ">RCP46640+419741-075285802;ID=5102;*6C<")); + verifyPosition(decoder, text( ">REV001958003965+0307178+1016144900031532;IO=300;SV=8;BL=4159;CF=8161,C,13;AD=14145;IX=10233040;FF=0,0,0,0;VO=338578;ID=357042063052352<")); -- cgit v1.2.3