aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/Context.java6
-rw-r--r--src/org/traccar/DetectorHandler.java122
-rw-r--r--src/org/traccar/ServerManager.java26
-rw-r--r--src/org/traccar/geocode/GoogleReverseGeocoder.java4
-rw-r--r--src/org/traccar/model/Command.java7
-rw-r--r--src/org/traccar/model/Server.java10
-rw-r--r--src/org/traccar/model/User.java10
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java51
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/MeitrackProtocol.java3
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolEncoder.java7
12 files changed, 83 insertions, 175 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 55561b921..e87f78d20 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -148,7 +148,11 @@ public final class Context {
reverseGeocoder = new FactualReverseGeocoder(url, key, cacheSize);
break;
default:
- reverseGeocoder = new GoogleReverseGeocoder(cacheSize);
+ if (key != null) {
+ reverseGeocoder = new GoogleReverseGeocoder(key, cacheSize);
+ } else {
+ reverseGeocoder = new GoogleReverseGeocoder(cacheSize);
+ }
break;
}
}
diff --git a/src/org/traccar/DetectorHandler.java b/src/org/traccar/DetectorHandler.java
deleted file mode 100644
index 223985906..000000000
--- a/src/org/traccar/DetectorHandler.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2015 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;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.SimpleChannelHandler;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.traccar.helper.Log;
-
-import java.lang.reflect.Method;
-import java.net.SocketAddress;
-import java.util.List;
-
-public class DetectorHandler extends SimpleChannelHandler {
-
- private final List<TrackerServer> serverList;
-
- private boolean showFailed;
-
- DetectorHandler(List<TrackerServer> serverList) {
- this.serverList = serverList;
- }
-
- public void checkPipeline(String protocol, ChannelPipeline pipeline, ChannelBuffer buf) throws Exception {
- Object tmp = buf.duplicate();
-
- // Frame decoder
- FrameDecoder frameDecoder = (FrameDecoder) pipeline.get("frameDecoder");
- if (frameDecoder != null) {
- try {
- Method method = frameDecoder.getClass().getDeclaredMethod(
- "decode", ChannelHandlerContext.class, Channel.class, ChannelBuffer.class);
- method.setAccessible(true);
- tmp = method.invoke(frameDecoder, null, null, tmp);
- } catch (NoSuchMethodException error) {
- Method method = frameDecoder.getClass().getSuperclass().getDeclaredMethod(
- "decode", ChannelHandlerContext.class, Channel.class, ChannelBuffer.class);
- method.setAccessible(true);
- tmp = method.invoke(frameDecoder, null, null, tmp);
- }
- }
-
- // String decoder
- if (pipeline.get("stringDecoder") != null) {
- StringDecoder stringDecoder = new StringDecoder();
- if (tmp != null) {
- try {
- Method method = stringDecoder.getClass().getDeclaredMethod(
- "decode", ChannelHandlerContext.class, Channel.class, Object.class);
- method.setAccessible(true);
- tmp = method.invoke(stringDecoder, null, null, tmp);
- } catch (NoSuchMethodException error) {
- Method method = stringDecoder.getClass().getSuperclass().getDeclaredMethod(
- "decode", ChannelHandlerContext.class, Channel.class, Object.class);
- method.setAccessible(true);
- tmp = method.invoke(stringDecoder, null, null, tmp);
- }
- }
- }
-
- // Protocol decoder
- BaseProtocolDecoder protocolDecoder = (BaseProtocolDecoder) pipeline.get("objectDecoder");
- if (tmp != null) {
- try {
- Method method = protocolDecoder.getClass().getDeclaredMethod(
- "decode", ChannelHandlerContext.class, Channel.class, SocketAddress.class, Object.class);
- method.setAccessible(true);
- tmp = method.invoke(protocolDecoder, null, null, null, tmp);
- } catch (NoSuchMethodException error) {
- Method method = protocolDecoder.getClass().getSuperclass().getDeclaredMethod(
- "decode", ChannelHandlerContext.class, Channel.class, SocketAddress.class, Object.class);
- method.setAccessible(true);
- tmp = method.invoke(protocolDecoder, null, null, null, tmp);
- }
- }
-
- if (tmp != null) {
- Log.info("Protocol " + protocol + " possible match");
- } else if (showFailed) {
- Log.info("Protocol " + protocol + " no match");
- }
- }
-
- @Override
- public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
-
- if (e.getMessage() instanceof ChannelBuffer) {
- ChannelBuffer buf = (ChannelBuffer) e.getMessage();
-
- for (TrackerServer server : serverList) {
- try {
- if (!server.getProtocol().equals("detector")) {
- checkPipeline(server.getProtocol(), server.getPipelineFactory().getPipeline(), buf);
- }
- } catch (Exception error) {
- if (showFailed) {
- Log.info("Protocol " + server.getProtocol() + " error");
- }
- }
- }
- }
- }
-
-}
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index 08557a5d6..2fa44831f 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -68,8 +68,6 @@ public class ServerManager {
initProtocolServer((BaseProtocol) protocolClass.newInstance());
}
}
-
- initProtocolDetector();
}
public void start() {
@@ -88,30 +86,8 @@ public class ServerManager {
GlobalTimer.release();
}
- private boolean isProtocolEnabled(String protocol) {
- return Context.getConfig().hasKey(protocol + ".port");
- }
-
- private void initProtocolDetector() {
- String protocol = "detector";
- if (isProtocolEnabled(protocol)) {
- serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("detectorHandler", new DetectorHandler(serverList));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("detectorHandler", new DetectorHandler(serverList));
- }
- });
- }
- }
-
private void initProtocolServer(final Protocol protocol) {
- if (isProtocolEnabled(protocol.getName())) {
+ if (Context.getConfig().hasKey(protocol.getName() + ".port")) {
protocol.initTrackerServers(serverList);
}
}
diff --git a/src/org/traccar/geocode/GoogleReverseGeocoder.java b/src/org/traccar/geocode/GoogleReverseGeocoder.java
index f1c27c5d3..be863718b 100644
--- a/src/org/traccar/geocode/GoogleReverseGeocoder.java
+++ b/src/org/traccar/geocode/GoogleReverseGeocoder.java
@@ -29,6 +29,10 @@ public class GoogleReverseGeocoder extends JsonReverseGeocoder {
super("http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f", cacheSize);
}
+ public GoogleReverseGeocoder(String key, int cacheSize) {
+ super("http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=" + key, cacheSize);
+ }
+
@Override
public Address parseAddress(JsonObject json) {
JsonArray results = json.getJsonArray("results");
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
index dd541e643..eda5f61d1 100644
--- a/src/org/traccar/model/Command.java
+++ b/src/org/traccar/model/Command.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.
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Command extends Extensible {
+ public static final String TYPE_CUSTOM = "custom";
public static final String TYPE_POSITION_SINGLE = "positionSingle";
public static final String TYPE_POSITION_PERIODIC = "positionPeriodic";
public static final String TYPE_POSITION_STOP = "positionStop";
@@ -31,12 +32,14 @@ public class Command extends Extensible {
public static final String TYPE_REQUEST_PHOTO = "requestPhoto";
public static final String TYPE_REBOOT_DEVICE = "rebootDevice";
public static final String TYPE_MOVEMENT_ALARM = "movementAlarm";
+ public static final String TYPE_SEND_SMS = "sendSms";
public static final String KEY_UNIQUE_ID = "uniqueId";
public static final String KEY_FREQUENCY = "frequency";
public static final String KEY_TIMEZONE = "timezone";
public static final String KEY_DEVICE_PASSWORD = "devicePassword";
public static final String KEY_RADIUS = "radius";
+ public static final String KEY_PHONE_NUMBER = "phoneNumber";
+ public static final String KEY_MESSAGE = "message";
- public static final String TYPE_CUSTOM = "CUSTOM";
}
diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java
index f03a0aa60..270fd61fa 100644
--- a/src/org/traccar/model/Server.java
+++ b/src/org/traccar/model/Server.java
@@ -77,16 +77,6 @@ public class Server {
this.mapUrl = mapUrl;
}
- private String language;
-
- public String getLanguage() {
- return language;
- }
-
- public void setLanguage(String language) {
- this.language = language;
- }
-
private String distanceUnit;
public String getDistanceUnit() {
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
index e58311834..f22a2e632 100644
--- a/src/org/traccar/model/User.java
+++ b/src/org/traccar/model/User.java
@@ -80,16 +80,6 @@ public class User {
this.map = map;
}
- private String language;
-
- public String getLanguage() {
- return language;
- }
-
- public void setLanguage(String language) {
- this.language = language;
- }
-
private String distanceUnit;
public String getDistanceUnit() {
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index a3d34cf3c..c2eb8a1f5 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -222,7 +222,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
int event = buf.readUnsignedByte();
position.set(Event.KEY_EVENT, event);
- buf.readUnsignedByte();
+ position.set("event-info", buf.readUnsignedByte());
if ((selector & 0x0008) != 0) {
position.setValid((buf.readUnsignedByte() & 0x40) != 0);
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 574f9a8c3..7d0c58c57 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -158,6 +158,22 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.text("$").optional()
.compile();
+ private static final Pattern PATTERN_IGN = new PatternBuilder()
+ .text("+").expression("(?:RESP|BUFF):GTIG[NF],")
+ .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
+ .number("(d{15}),") // imei
+ .expression("[^,]*,") // device name
+ .number("d+,") // ignition off duration
+ .expression(PATTERN_LOCATION.pattern())
+ .number("(d{5}:dd:dd)?,") // hour meter
+ .number("(d{1,7}.d)?,") // odometer
+ .number("(dddd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd)").optional(2) // time
+ .text(",")
+ .number("(xxxx)") // count number
+ .text("$").optional()
+ .compile();
+
private static final Pattern PATTERN = new PatternBuilder()
.text("+").expression("(?:RESP|BUFF):GT...,")
.number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
@@ -376,6 +392,37 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
return positions;
}
+ private Object decodeIgn(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_IGN, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ if (!identify(parser.next(), channel, remoteAddress)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ decodeLocation(position, parser);
+
+ position.set(Event.KEY_HOURS, parser.next());
+ position.set(Event.KEY_ODOMETER, parser.next());
+
+ if (parser.hasNext(6)) {
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) {
+ position.setTime(dateBuilder.getDate());
+ }
+ }
+
+ return position;
+ }
+
private Object decodeOther(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
@@ -469,6 +516,10 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
case "FRI":
result = decodeFri(channel, remoteAddress, sentence);
break;
+ case "IGN":
+ case "IGF":
+ result = decodeIgn(channel, remoteAddress, sentence);
+ break;
default:
result = decodeOther(channel, remoteAddress, sentence);
break;
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index e2aed6309..ce5a54141 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -87,11 +87,13 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // odometer
.number("(d+.d+)?,") // fuel instant
.number("(?:d+.d+)?,") // fuel average
+ .number("(d+),") // hours
.number("(d+),") // speed
- .number("d+,") // power load
- .number("(d+.d+%),") // throttle
+ .number("d+.?d*%,") // power load
+ .number("(d+),") // temperature
+ .number("(d+.?d*%),") // throttle
.number("(d+),") // rpm
- .number("(d+.d+%),") // battery
+ .number("(d+.d+),") // battery
.number("[^,]*,") // dtc 1
.number("[^,]*,") // dtc 2
.number("[^,]*,") // dtc 3
@@ -166,7 +168,9 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_ODOMETER, parser.nextInt());
position.set(Event.KEY_FUEL, parser.next());
+ position.set(Event.KEY_HOURS, parser.next());
position.set(Event.KEY_OBD_SPEED, parser.next());
+ position.set(Event.PREFIX_TEMP + 1, parser.next());
position.set(Event.KEY_THROTTLE, parser.next());
position.set(Event.KEY_RPM, parser.next());
position.set(Event.KEY_BATTERY, parser.next());
diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java
index e5b5ddf2b..a004d5cb6 100644
--- a/src/org/traccar/protocol/MeitrackProtocol.java
+++ b/src/org/traccar/protocol/MeitrackProtocol.java
@@ -36,7 +36,8 @@ public class MeitrackProtocol extends BaseProtocol {
Command.TYPE_ENGINE_RESUME,
Command.TYPE_ALARM_ARM,
Command.TYPE_ALARM_DISARM,
- Command.TYPE_REQUEST_PHOTO);
+ Command.TYPE_REQUEST_PHOTO,
+ Command.TYPE_SEND_SMS);
}
@Override
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
index 381935c58..04cb39637 100644
--- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -20,6 +20,8 @@ import org.traccar.helper.Checksum;
import org.traccar.helper.Log;
import org.traccar.model.Command;
+import java.util.Map;
+
public class MeitrackProtocolEncoder extends StringProtocolEncoder {
private Object formatCommand(Command command, char dataId, String content) {
@@ -33,6 +35,8 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
+ Map<String, Object> attributes = command.getAttributes();
+
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
return formatCommand(command, 'Q', "A10");
@@ -46,6 +50,9 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
return formatCommand(command, 'M', "C01,0,22022");
case Command.TYPE_REQUEST_PHOTO:
return formatCommand(command, 'D', "D03,1,camera_picture.jpg");
+ case Command.TYPE_SEND_SMS:
+ return formatCommand(command, 'f', "C02,0,"
+ + attributes.get(Command.KEY_PHONE_NUMBER) + "," + attributes.get(Command.KEY_MESSAGE));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;