diff options
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 7 | ||||
-rw-r--r-- | src/org/traccar/TrackerServer.java | 30 | ||||
-rw-r--r-- | src/org/traccar/api/resource/DeviceResource.java | 1 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 3 | ||||
-rw-r--r-- | src/org/traccar/protocol/MeitrackProtocolDecoder.java | 24 | ||||
-rw-r--r-- | src/org/traccar/protocol/TaipProtocolDecoder.java | 16 | ||||
-rw-r--r-- | src/org/traccar/protocol/TelicProtocolDecoder.java | 13 | ||||
-rw-r--r-- | test/org/traccar/protocol/MeitrackProtocolDecoderTest.java | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/TaipProtocolDecoderTest.java | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/TelicProtocolDecoderTest.java | 6 |
10 files changed, 68 insertions, 38 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 775d609a7..33f778885 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -112,9 +112,12 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { public BasePipelineFactory(TrackerServer server, String protocol) { this.server = server; - timeout = Context.getConfig().getInteger(protocol + ".timeout", 0); + timeout = Context.getConfig().getInteger(protocol + ".timeout"); if (timeout == 0) { - timeout = Context.getConfig().getInteger(protocol + ".resetDelay", 0); // temporary + timeout = Context.getConfig().getInteger(protocol + ".resetDelay"); // temporary + if (timeout == 0) { + timeout = Context.getConfig().getInteger("server.timeout"); + } } if (Context.getConfig().getBoolean("filter.enable")) { diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index 108688fb8..7e0a6f0c6 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2014 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,6 @@ import org.jboss.netty.channel.group.DefaultChannelGroup; import java.net.InetSocketAddress; import java.nio.ByteOrder; -/** - * Tracker server - */ public abstract class TrackerServer { private final Bootstrap bootstrap; @@ -49,7 +46,6 @@ public abstract class TrackerServer { this.bootstrap = bootstrap; this.protocol = protocol; - // Set appropriate channel factory if (bootstrap instanceof ServerBootstrap) { bootstrap.setFactory(GlobalChannelFactory.getFactory()); } else if (bootstrap instanceof ConnectionlessBootstrap) { @@ -69,22 +65,16 @@ public abstract class TrackerServer { protected abstract void addSpecificHandlers(ChannelPipeline pipeline); - /** - * Server port - */ - private Integer port; + private int port; - public Integer getPort() { + public int getPort() { return port; } - public void setPort(Integer port) { + public void setPort(int port) { this.port = port; } - /** - * Server listening interface - */ private String address; public String getAddress() { @@ -95,17 +85,11 @@ public abstract class TrackerServer { this.address = address; } - /** - * Set endianness - */ public void setEndianness(ByteOrder byteOrder) { bootstrap.setOption("bufferFactory", new HeapChannelBufferFactory(byteOrder)); bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(byteOrder)); } - /** - * Opened channels - */ private final ChannelGroup allChannels = new DefaultChannelGroup(); public ChannelGroup getChannelGroup() { @@ -120,9 +104,6 @@ public abstract class TrackerServer { return bootstrap.getPipelineFactory(); } - /** - * Start server - */ public void start() { InetSocketAddress endpoint; if (address == null) { @@ -143,9 +124,6 @@ public abstract class TrackerServer { } } - /** - * Stop server - */ public void stop() { ChannelGroupFuture future = getChannelGroup().close(); future.awaitUninterruptibly(); diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index e0c2335f9..bfd05aad5 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -80,6 +80,7 @@ public class DeviceResource extends BaseResource { Context.getPermissionsManager().checkDeviceReadonly(getUserId()); Context.getPermissionsManager().checkDevice(getUserId(), entity.getId()); Context.getDeviceManager().updateDevice(entity); + Context.getPermissionsManager().refreshPermissions(); if (Context.getGeofenceManager() != null) { Context.getGeofenceManager().refresh(); } diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index bbba639c1..d94df7531 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -184,9 +184,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case 0x11: return Position.ALARM_POWER_OFF; default: - break; + return null; } - return null; } @Override diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index bd6f3e8be..9189d2a66 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,6 +84,27 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { .text("\r\n").optional() .compile(); + private String decodeAlarm(int event) { + switch (event) { + case 1: + return Position.ALARM_SOS; + case 17: + return Position.ALARM_LOW_BATTERY; + case 18: + return Position.ALARM_POWER_CUT; + case 19: + return Position.ALARM_OVERSPEED; + case 20: + return Position.ALARM_GEOFENCE_ENTER; + case 21: + return Position.ALARM_GEOFENCE_EXIT; + case 36: + return Position.ALARM_TOW; + default: + return null; + } + } + private Position decodeRegularMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII)); @@ -102,6 +123,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { int event = parser.nextInt(); position.set(Position.KEY_EVENT, event); + position.set(Position.KEY_ALARM, decodeAlarm(event)); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index 309263cd5..a46cdefe3 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -54,8 +54,13 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { .number("(dd)(dd)(dd)") // date (mmddyy) .number("(dd)(dd)(dd)") // time (hhmmss) .groupEnd() + .groupBegin() .number("([-+]dd)(d{5})") // latitude .number("([-+]ddd)(d{5})") // longitude + .or() + .number("([-+])(dd)(dd.dddd)") // latitude + .number("([-+])(ddd)(dd.dddd)") // longitude + .groupEnd() .number("(ddd)") // speed .number("(ddd)") // course .groupBegin() @@ -112,8 +117,15 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); } - position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG)); - position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG)); + if (parser.hasNext(4)) { + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG)); + } + if (parser.hasNext(6)) { + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); + } + position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble())); position.setCourse(parser.nextDouble()); diff --git a/src/org/traccar/protocol/TelicProtocolDecoder.java b/src/org/traccar/protocol/TelicProtocolDecoder.java index f6be15cce..bbd4b0574 100644 --- a/src/org/traccar/protocol/TelicProtocolDecoder.java +++ b/src/org/traccar/protocol/TelicProtocolDecoder.java @@ -50,11 +50,11 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder { .number("(d),") // validity .number("(d+),") // speed .number("(d+),") // course - .number("(d+),") // satellites + .number("(d+)?,") // satellites .expression("(?:[^,]*,){7}") .number("(d+),") // battery .expression("[^,]*,") - .number("(d+),") // external + .number("(d+)") // external .any() .compile(); @@ -125,9 +125,12 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); position.setCourse(parser.nextDouble()); - position.set(Position.KEY_SATELLITES, parser.next()); - position.set(Position.KEY_BATTERY, 3.4 + parser.nextInt() * 0.00345); - position.set(Position.KEY_POWER, 6.0 + parser.nextInt() * 0.125); + if (parser.hasNext()) { + position.set(Position.KEY_SATELLITES, parser.nextInt()); + } + + position.set(Position.KEY_BATTERY, parser.nextInt()); + position.set(Position.KEY_POWER, parser.nextInt()); return position; } diff --git a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java index 9534df2e0..d387332d6 100644 --- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -12,6 +12,9 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest { MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new MeitrackProtocol()); verifyPosition(decoder, buffer( + "$$T143,869013024733944,AAA,1,18.459575,-69.947161,170220142912,A,5,15,10,300,1.6,115,3989,187884,370|2|5337|2B2C,0100,0000|0000|0000|0964|0B04,,*C2")); + + verifyPosition(decoder, buffer( "$$K157,866771027160687,AAA,3,37.040231,10.042391,160412151656,A,10,11,0,48,0.8,21,1035518,774980,605|2|0010|307B,0400,0000|0000|0000|0A47|03E3,,,1,0000,001206*2C")); verifyNothing(decoder, buffer( diff --git a/test/org/traccar/protocol/TaipProtocolDecoderTest.java b/test/org/traccar/protocol/TaipProtocolDecoderTest.java index 74956f51c..121ffa5a6 100644 --- a/test/org/traccar/protocol/TaipProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TaipProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class TaipProtocolDecoderTest extends ProtocolTest { TaipProtocolDecoder decoder = new TaipProtocolDecoder(new TaipProtocol(), false); verifyPosition(decoder, text( + ">RGP200317010815-3852.9306-06204.88560000003000101;&01;ID=5555;#7AD7*51<")); + + verifyPosition(decoder, text( ">RCQ09000000000000-3460365-058381460000007F0000000000000115000FFFF1099;#0000;ID=555224;*05<")); verifyPosition(decoder, text( diff --git a/test/org/traccar/protocol/TelicProtocolDecoderTest.java b/test/org/traccar/protocol/TelicProtocolDecoderTest.java index f473bc8d5..6c3c30fea 100644 --- a/test/org/traccar/protocol/TelicProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TelicProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class TelicProtocolDecoderTest extends ProtocolTest { TelicProtocolDecoder decoder = new TelicProtocolDecoder(new TelicProtocol()); + verifyPosition(decoder, text( + "232027997498,230317083900,0,230317083900,260105,444112,3,22,259,,,,111,61110817,226,01,00,255,218,00000000000000")); + + verifyPosition(decoder, text( + "072027997498,230317082635,0,230317082635,260332,444265,3,28,165,,,,124,61107582,226,01,00,255,219,00000000000000")); + verifyNothing(decoder, text( "0026203393|226|10|002004010")); |