diff options
-rw-r--r-- | src/org/traccar/Context.java | 2 | ||||
-rw-r--r-- | src/org/traccar/database/NotificationManager.java | 4 | ||||
-rw-r--r-- | src/org/traccar/model/Position.java | 5 | ||||
-rw-r--r-- | src/org/traccar/notification/EventForwarder.java | 17 | ||||
-rw-r--r-- | src/org/traccar/protocol/MegastekFrameDecoder.java | 10 | ||||
-rw-r--r-- | src/org/traccar/protocol/MegastekProtocolDecoder.java | 6 | ||||
-rw-r--r-- | src/org/traccar/protocol/Pt502ProtocolDecoder.java | 41 | ||||
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 5 | ||||
-rw-r--r-- | src/org/traccar/protocol/XexunFrameDecoder.java | 4 | ||||
-rw-r--r-- | test/org/traccar/protocol/MegastekProtocolDecoderTest.java | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/Pt502ProtocolDecoderTest.java | 11 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 3 | ||||
-rw-r--r-- | web/app/Style.js | 6 | ||||
-rw-r--r-- | web/app/view/GeofenceMap.js | 10 |
14 files changed, 95 insertions, 32 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index d32837755..c7359e76c 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -130,7 +130,7 @@ public final class Context { private static EventForwarder eventForwarder; - public static EventForwarder getEventForvarder() { + public static EventForwarder getEventForwarder() { return eventForwarder; } diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 911c5d2dc..779f42483 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -68,8 +68,8 @@ public class NotificationManager { } } } - if (Context.getEventForvarder() != null) { - Context.getEventForvarder().forwardEvent(event, position); + if (Context.getEventForwarder() != null) { + Context.getEventForwarder().forwardEvent(event, position); } } diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index f592ee4b9..95a5011ec 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -85,7 +85,10 @@ public class Position extends Message { public static final String ALARM_GEOFENCE_EXIT = "geofenceExit"; public static final String ALARM_GPS_ANTENNA_CUT = "gpsAntennaCut"; public static final String ALARM_ACCIDENT = "accident"; - + public static final String ALARM_TOW = "tow"; + public static final String ALARM_ACCELETATION = "hardAcceleration"; + public static final String ALARM_BREAKING = "hardBreaking"; + public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving"; private String protocol; diff --git a/src/org/traccar/notification/EventForwarder.java b/src/org/traccar/notification/EventForwarder.java index 096026541..3bd7e5cf5 100644 --- a/src/org/traccar/notification/EventForwarder.java +++ b/src/org/traccar/notification/EventForwarder.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.notification; import java.nio.charset.StandardCharsets; @@ -33,7 +48,6 @@ public final class EventForwarder { public void forwardEvent(Event event, Position position) { - BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url); requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8"); @@ -72,4 +86,5 @@ public final class EventForwarder { } return json.build().toString().getBytes(StandardCharsets.UTF_8); } + } diff --git a/src/org/traccar/protocol/MegastekFrameDecoder.java b/src/org/traccar/protocol/MegastekFrameDecoder.java index ba2cc1d25..da77d95fd 100644 --- a/src/org/traccar/protocol/MegastekFrameDecoder.java +++ b/src/org/traccar/protocol/MegastekFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,10 +39,16 @@ public class MegastekFrameDecoder extends FrameDecoder { return buf.readBytes(length); } } else { + while (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n') { + buf.skipBytes(1); + } int delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n")); + if (delimiter == -1) { + delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '!'); + } if (delimiter != -1) { ChannelBuffer result = buf.readBytes(delimiter - buf.readerIndex()); - buf.skipBytes(2); + buf.skipBytes(1); return result; } } diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 81349ce3e..a330947b1 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -241,9 +241,9 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .number("(dd),") // satellites .number("dd,") .number("(d+.d+),") // hdop - .number("(d+.d+),") // speed - .number("(d+.d+),") // course - .number("(d+.d+),") // altitude + .number("(d+.d+)?,") // speed + .number("(d+.d+)?,") // course + .number("(-?d+.d+),") // altitude .number("(d+.d+)?,") // odometer .number("(d+),") // mcc .number("(d+),") // mnc diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index d925e1b4d..7dc4fbe5e 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -1,5 +1,5 @@ /*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
* Copyright 2012 Luis Parada (luis.parada@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,8 +35,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder()
.any().text("$")
- .expression("[A-Z]{3}")
- .number("d?,") // type
+ .expression("([^,]+),") // type
.number("(d+),") // id
.number("(dd)(dd)(dd).(ddd),") // time
.expression("([AV]),") // validity
@@ -57,19 +56,31 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { .any()
.compile();
+ private String decodeAlarm(String value) {
+ switch (value) {
+ case "TOW":
+ return Position.ALARM_TOW;
+ case "HDA":
+ return Position.ALARM_ACCELETATION;
+ case "HDB":
+ return Position.ALARM_BREAKING;
+ case "FDA":
+ return Position.ALARM_FATIGUE_DRIVING;
+ case "SKA":
+ return Position.ALARM_VIBRATION;
+ case "PMA":
+ return Position.ALARM_MOVEMENT;
+ default:
+ return null;
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
- if (sentence.startsWith("$PHO")) {
- if (channel != null) {
- channel.write("#PHD0," + sentence.substring(4));
- }
- return null;
- }
-
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
@@ -78,6 +89,16 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position();
position.setProtocol(getProtocolName());
+ String type = parser.next();
+
+ if (type.startsWith("PHO")) {
+ if (channel != null) {
+ channel.write("#PHD0," + type.substring(3) + "\r\n");
+ }
+ }
+
+ position.set(Position.KEY_ALARM, decodeAlarm(type));
+
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index ac99a1440..90c80be71 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -41,9 +41,9 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("d*") // imei? .number("(dd)(dd)(dd),?") // date .expression("([AV]),?") // validity - .number("(dd)(dd.d+)") // latitude + .number("(d+)(dd.d+)") // latitude .expression("([NS]),?") - .number("(ddd)(dd.d+)") // longitude + .number("(d+)(dd.d+)") // longitude .expression("([EW]),?") .number("(d+.d)(?:d*,)?") // speed .number("(dd)(dd)(dd),?") // time @@ -211,7 +211,6 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { position.setCourse(parser.nextDouble()); - // Status String status = parser.next(); if (status != null) { position.set(Position.KEY_STATUS, status); // binary status diff --git a/src/org/traccar/protocol/XexunFrameDecoder.java b/src/org/traccar/protocol/XexunFrameDecoder.java index 9b3438aaa..184e2f57b 100644 --- a/src/org/traccar/protocol/XexunFrameDecoder.java +++ b/src/org/traccar/protocol/XexunFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ public class XexunFrameDecoder extends FrameDecoder { return null; } - buf.skipBytes(beginIndex); + buf.skipBytes(beginIndex - buf.readerIndex()); return buf.readBytes(endIndex - beginIndex + 1); } diff --git a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java index d6056869b..fae0ef93d 100644 --- a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class MegastekProtocolDecoderTest extends ProtocolTest { MegastekProtocolDecoder decoder = new MegastekProtocolDecoder(new MegastekProtocol()); verifyPosition(decoder, text( + "$MGV002,869152024446923,,S,290816,200627,V,5056.21059,N,00439.25034,E,00,00,00,99.9,,,-25.1,,206,01,0BBB,4418,28,,,,,,,,,01,093,Timer;")); + + verifyPosition(decoder, text( "$MGV002,869152024446923,869152024446923,S,240816,151631,A,5053.83335,N,00424.05702,E,00,10,00,0.88,2.645,76.09,22.7,,206,01,07D1,6600,28,,,,,,,,,01,100,Timer;!")); verifyPosition(decoder, text( diff --git a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java index e8483fcff..3ea83ef60 100644 --- a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java @@ -9,6 +9,15 @@ public class Pt502ProtocolDecoderTest extends ProtocolTest { public void testDecode() throws Exception { Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(new Pt502Protocol()); + + verifyPosition(decoder, text( + "$PHO6608,115099,133140.000,A,1307.1238,N,05936.4194,W,0.00,21.50,290816,,,A/00010,00000/0,0,0,0/185100//f59/")); + + verifyPosition(decoder, text( + "$DFR,40456789,083125.000,A,2232.0971,N,11400.9504,E,0.0,5.00,090714,,,A/00000,00/0,0/200076//FE7/")); + + verifyPosition(decoder, text( + "$FDA,40456789,083125.000,A,2232.0971,N,11400.9504,E,0.0,5.00,090714,,,A/00000,00/0,0/200076//FE7/")); verifyPosition(decoder, text( "$POS,216769295715,163237.000,A,3258.1738,S,02755.4350,E,0.00,215.88,100915,,,A/0000,0//232300//5b3/"), @@ -29,7 +38,7 @@ public class Pt502ProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "$POS,6095,233344.000,V,0933.0451,N,06912.3360,W,,,151112,,,N/00000,00000/0/1677600/")); - verifyNothing(decoder, text( + verifyPosition(decoder, text( "$PHO0,6091,233606.000,A,0902.9855,N,06944.3654,W,0.0,43.8,141112,,,A/00010,00000/0/224000//")); verifyPosition(decoder, text( diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index c1bf148bc..ba820f2f6 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); verifyPosition(decoder, text( + "(01602009983BR00160830V1855.7022S4817.8731W000.0002729000.0010000000L00000000)")); + + verifyPosition(decoder, text( "(088046338039BR00160727A3354.7768N03540.7258E000.0140832068.4700000000L00BEB0D4+017.7)")); verifyPosition(decoder, text( diff --git a/web/app/Style.js b/web/app/Style.js index 6ca93c18c..b3b296b75 100644 --- a/web/app/Style.js +++ b/web/app/Style.js @@ -60,7 +60,6 @@ Ext.define('Traccar.Style', { mapColorOnline: 'rgba(77, 250, 144, 1.0)', mapColorUnknown: 'rgba(250, 190, 77, 1.0)', mapColorOffline: 'rgba(255, 84, 104, 1.0)', - mapColorOverlay: 'rgba(21, 127, 204, 0.2)', mapRadiusNormal: 9, mapRadiusSelected: 14, @@ -68,6 +67,11 @@ Ext.define('Traccar.Style', { mapMaxZoom: 19, mapDelay: 500, + mapGeofenceColor: 'rgba(21, 127, 204, 1.0)', + mapGeofenceOverlay: 'rgba(21, 127, 204, 0.2)', + mapGeofenceWidth: 5, + mapGeofenceRadius: 9, + coordinatePrecision: 6, numberPrecision: 2, diff --git a/web/app/view/GeofenceMap.js b/web/app/view/GeofenceMap.js index 573836bc9..933df2369 100644 --- a/web/app/view/GeofenceMap.js +++ b/web/app/view/GeofenceMap.js @@ -72,16 +72,16 @@ Ext.define('Traccar.view.GeofenceMap', { }), style: new ol.style.Style({ fill: new ol.style.Fill({ - color: Traccar.Style.mapColorOverlay + color: Traccar.Style.mapGeofenceOverlay }), stroke: new ol.style.Stroke({ - color: Traccar.Style.mapColorReport, - width: Traccar.Style.mapRouteWidth + color: Traccar.Style.mapGeofenceColor, + width: Traccar.Style.mapGeofenceWidth }), image: new ol.style.Circle({ - radius: Traccar.Style.mapRadiusNormal, + radius: Traccar.Style.mapGeofenceRadius, fill: new ol.style.Fill({ - color: Traccar.Style.mapColorReport + color: Traccar.Style.mapGeofenceColor }) }) }) |