diff options
-rw-r--r-- | src/org/traccar/FilterHandler.java | 23 | ||||
-rw-r--r-- | src/org/traccar/protocol/H02ProtocolDecoder.java | 3 | ||||
-rw-r--r-- | src/org/traccar/protocol/SuntechProtocolDecoder.java | 41 | ||||
-rw-r--r-- | test/org/traccar/BaseTest.java | 8 | ||||
-rw-r--r-- | test/org/traccar/FilterHandlerTest.java | 64 | ||||
-rw-r--r-- | test/org/traccar/protocol/H02ProtocolDecoderTest.java | 5 |
6 files changed, 120 insertions, 24 deletions
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index f63fd17dd..4cd3eb0eb 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -30,7 +30,7 @@ public class FilterHandler extends BaseDataHandler { private int filterDistance; private int filterMaxSpeed; private long skipLimit; - private boolean skipAlarms; + private boolean skipAttributes; public void setFilterInvalid(boolean filterInvalid) { this.filterInvalid = filterInvalid; @@ -68,8 +68,8 @@ public class FilterHandler extends BaseDataHandler { this.skipLimit = skipLimit; } - public void setSkipAlarms(boolean skipAlarms) { - this.skipAlarms = skipAlarms; + public void setSkipAttributes(boolean skipAttributes) { + this.skipAttributes = skipAttributes; } public FilterHandler() { @@ -84,7 +84,7 @@ public class FilterHandler extends BaseDataHandler { filterDistance = config.getInteger("filter.distance"); filterMaxSpeed = config.getInteger("filter.maxSpeed"); skipLimit = config.getLong("filter.skipLimit") * 1000; - skipAlarms = config.getBoolean("filter.skipAlarms"); + skipAttributes = config.getBoolean("filter.skipAttributes.enable"); } } @@ -145,8 +145,17 @@ public class FilterHandler extends BaseDataHandler { return false; } - private boolean skipAlarms(Position position) { - return skipAlarms && position.getAttributes().containsKey(Position.KEY_ALARM); + private boolean skipAttributes(Position position) { + if (skipAttributes) { + String attributesString = Context.getIdentityManager().lookupAttributeString( + position.getDeviceId(), "filter.skipAttributes", "", true); + for (String attribute : attributesString.split("[ ,]")) { + if (position.getAttributes().containsKey(attribute)) { + return true; + } + } + } + return false; } private boolean filter(Position position) { @@ -158,7 +167,7 @@ public class FilterHandler extends BaseDataHandler { last = Context.getIdentityManager().getLastPosition(position.getDeviceId()); } - if (skipLimit(position, last) || skipAlarms(position)) { + if (skipLimit(position, last) || skipAttributes(position)) { return false; } diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index c31f9edbb..aea8f0b3b 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -152,7 +152,6 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .groupBegin() .text("VP1,") - .expression("[ABV],") .or() .groupBegin() .text("V1,") @@ -164,7 +163,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .groupEnd() .number("(?:(dd)(dd)(dd))?,") // time (hhmmss) .groupEnd() - .expression("([AV])?,") // validity + .expression("([ABV])?,") // validity .groupBegin() .number("-(d+)-(d+.d+),") // latitude .or() diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index 68c920899..3025bbdd5 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -109,6 +109,24 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { return position; } + private String decodeEmergency(int value) { + switch (value) { + case 1: + return Position.ALARM_SOS; + case 3: + return Position.ALARM_POWER_CUT; + case 5: + case 6: + return Position.ALARM_DOOR; + case 7: + return Position.ALARM_MOVEMENT; + case 8: + return Position.ALARM_SHOCK; + default: + return null; + } + } + private Position decode235( Channel channel, SocketAddress remoteAddress, String protocol, String[] values) throws ParseException { int index = 0; @@ -121,10 +139,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); - - if (type.equals("EMG") || type.equals("ALT")) { - position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - } + position.set(Position.KEY_TYPE, type); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]); if (deviceSession == null) { @@ -160,10 +175,20 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_IO + 1, values[index++]); - index += 1; // mode - - if (type.equals("STT")) { - position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); + switch (type) { + case "STT": + index += 1; // mode + position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); + break; + case "EMG": + position.set(Position.KEY_ALARM, decodeEmergency(Integer.parseInt(values[index++]))); + break; + case "EVT": + case "ALT": + position.set(Position.KEY_EVENT, Integer.parseInt(values[index++])); + break; + default: + break; } if (hbm) { diff --git a/test/org/traccar/BaseTest.java b/test/org/traccar/BaseTest.java index 37956f11d..4b9ee5451 100644 --- a/test/org/traccar/BaseTest.java +++ b/test/org/traccar/BaseTest.java @@ -40,25 +40,25 @@ public class BaseTest { @Override public boolean lookupAttributeBoolean( long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig) { - return false; + return defaultValue; } @Override public String lookupAttributeString( long deviceId, String attributeName, String defaultValue, boolean lookupConfig) { - return null; + return defaultValue; } @Override public int lookupAttributeInteger( long deviceId, String attributeName, int defaultValue, boolean lookupConfig) { - return 0; + return defaultValue; } @Override public long lookupAttributeLong( long deviceId, String attributeName, long defaultValue, boolean lookupConfig) { - return 0; + return defaultValue; } }); diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java index e91566635..7ebab3af5 100644 --- a/test/org/traccar/FilterHandlerTest.java +++ b/test/org/traccar/FilterHandlerTest.java @@ -3,6 +3,8 @@ package org.traccar; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.traccar.database.IdentityManager; +import org.traccar.model.Device; import org.traccar.model.Position; import java.util.Date; @@ -10,7 +12,65 @@ import java.util.Date; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -public class FilterHandlerTest extends BaseTest { +public class FilterHandlerTest { + + static { + Context.init(new IdentityManager() { + + private Device createDevice() { + Device device = new Device(); + device.setId(1); + device.setName("test"); + device.setUniqueId("123456789012345"); + return device; + } + + @Override + public Device getById(long id) { + return createDevice(); + } + + @Override + public Device getByUniqueId(String uniqueId) { + return createDevice(); + } + + @Override + public Position getLastPosition(long deviceId) { + return null; + } + + @Override + public boolean isLatestPosition(Position position) { + return true; + } + + @Override + public boolean lookupAttributeBoolean( + long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig) { + return defaultValue; + } + + @Override + public String lookupAttributeString( + long deviceId, String attributeName, String defaultValue, boolean lookupConfig) { + return "alarm,result"; + } + + @Override + public int lookupAttributeInteger( + long deviceId, String attributeName, int defaultValue, boolean lookupConfig) { + return defaultValue; + } + + @Override + public long lookupAttributeLong( + long deviceId, String attributeName, long defaultValue, boolean lookupConfig) { + return defaultValue; + } + + }); + } private FilterHandler filtingHandler; private FilterHandler passingHandler; @@ -77,7 +137,7 @@ public class FilterHandlerTest extends BaseTest { assertNotNull(passingHandler.decode(null, null, position)); position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - filtingHandler.setSkipAlarms(true); + filtingHandler.setSkipAttributes(true); assertNotNull(filtingHandler.decode(null, null, position)); } diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java index 0b90a4767..103746e5e 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -12,9 +12,12 @@ public class H02ProtocolDecoderTest extends ProtocolTest { H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol()); verifyPosition(decoder, buffer( + "*hq,356327080425330,VP1,A,2702.7245,S,15251.9311,E,0.48,0.0000,080917#")); + + verifyPosition(decoder, buffer( "*HQ,4209951296,V19,214452,A,5201.0178,N,01830.5029,E,000.00,000,200417,,195.63.13.195,89480610500392633029,BFFFFBFF#")); - verifyNull(decoder, buffer( + verifyPosition(decoder, buffer( "*hq,356327080425330,VP1,A,2702.7215,S,15251.9309,E,0.62,0.0000,050917#")); verifyNull(decoder, buffer( |