aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/Context.java2
-rw-r--r--src/org/traccar/database/NotificationManager.java4
-rw-r--r--src/org/traccar/model/Position.java5
-rw-r--r--src/org/traccar/notification/EventForwarder.java17
-rw-r--r--src/org/traccar/protocol/MegastekFrameDecoder.java10
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java41
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/XexunFrameDecoder.java4
9 files changed, 69 insertions, 25 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);
}