aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java9
-rw-r--r--src/org/traccar/BaseProtocol.java2
-rw-r--r--src/org/traccar/BaseProtocolEncoder.java4
-rw-r--r--src/org/traccar/DistanceHandler.java6
-rw-r--r--src/org/traccar/FilterHandler.java2
-rw-r--r--src/org/traccar/api/resource/UserResource.java7
-rw-r--r--src/org/traccar/database/DeviceManager.java8
-rw-r--r--src/org/traccar/events/IgnitionEventHandler.java12
-rw-r--r--src/org/traccar/events/MaintenanceEventHandler.java67
-rw-r--r--src/org/traccar/model/Event.java2
-rw-r--r--src/org/traccar/model/Extensible.java40
-rw-r--r--src/org/traccar/notification/NotificationFormatter.java22
-rw-r--r--src/org/traccar/notification/PropertiesProvider.java2
-rw-r--r--src/org/traccar/protocol/At2000FrameDecoder.java57
-rw-r--r--src/org/traccar/protocol/At2000Protocol.java42
-rw-r--r--src/org/traccar/protocol/At2000ProtocolDecoder.java134
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolEncoder.java4
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolEncoder.java8
-rw-r--r--src/org/traccar/protocol/NoranProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/T800xProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/WatchProtocolEncoder.java4
-rw-r--r--src/org/traccar/reports/ReportUtils.java13
-rw-r--r--src/org/traccar/reports/Summary.java8
28 files changed, 413 insertions, 54 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 22bb80ca1..d73b022ae 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -32,6 +32,7 @@ import org.jboss.netty.handler.timeout.IdleStateHandler;
import org.traccar.events.CommandResultEventHandler;
import org.traccar.events.GeofenceEventHandler;
import org.traccar.events.IgnitionEventHandler;
+import org.traccar.events.MaintenanceEventHandler;
import org.traccar.events.MotionEventHandler;
import org.traccar.events.OverspeedEventHandler;
import org.traccar.events.AlertEventHandler;
@@ -58,6 +59,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private GeofenceEventHandler geofenceEventHandler;
private AlertEventHandler alertEventHandler;
private IgnitionEventHandler ignitionEventHandler;
+ private MaintenanceEventHandler maintenanceEventHandler;
private static final class OpenChannelHandler extends SimpleChannelHandler {
@@ -164,6 +166,9 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
if (Context.getConfig().getBoolean("event.ignitionHandler")) {
ignitionEventHandler = new IgnitionEventHandler();
}
+ if (Context.getConfig().getBoolean("event.maintenanceHandler")) {
+ maintenanceEventHandler = new MaintenanceEventHandler();
+ }
}
protected abstract void addSpecificHandlers(ChannelPipeline pipeline);
@@ -242,6 +247,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("IgnitionEventHandler", ignitionEventHandler);
}
+ if (maintenanceEventHandler != null) {
+ pipeline.addLast("MaintenanceEventHandler", maintenanceEventHandler);
+ }
+
pipeline.addLast("mainHandler", new MainEventHandler());
return pipeline;
}
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index 4cbb5bd7c..59331d7cc 100644
--- a/src/org/traccar/BaseProtocol.java
+++ b/src/org/traccar/BaseProtocol.java
@@ -56,7 +56,7 @@ public abstract class BaseProtocol implements Protocol {
if (supportedCommands.contains(command.getType())) {
activeDevice.write(command);
} else if (command.getType().equals(Command.TYPE_CUSTOM)) {
- String data = (String) command.getAttributes().get(Command.KEY_DATA);
+ String data = command.getString(Command.KEY_DATA);
if (activeDevice.getChannel().getPipeline().get(StringEncoder.class) != null) {
activeDevice.write(data);
} else {
diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java
index 5c2c503e4..3c2d08471 100644
--- a/src/org/traccar/BaseProtocolEncoder.java
+++ b/src/org/traccar/BaseProtocolEncoder.java
@@ -31,8 +31,8 @@ public abstract class BaseProtocolEncoder extends OneToOneEncoder {
protected void initDevicePassword(Command command, String defaultPassword) {
if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId());
- if (device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
- String password = (String) device.getAttributes().get(Command.KEY_DEVICE_PASSWORD);
+ String password = device.getString(Command.KEY_DEVICE_PASSWORD);
+ if (password != null) {
command.set(Command.KEY_DEVICE_PASSWORD, password);
} else {
command.set(Command.KEY_DEVICE_PASSWORD, defaultPassword);
diff --git a/src/org/traccar/DistanceHandler.java b/src/org/traccar/DistanceHandler.java
index 138fc85d6..fdf9847a7 100644
--- a/src/org/traccar/DistanceHandler.java
+++ b/src/org/traccar/DistanceHandler.java
@@ -38,9 +38,7 @@ public class DistanceHandler extends BaseDataHandler {
Position last = getLastPosition(position.getDeviceId());
if (last != null) {
- if (last.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) {
- totalDistance = ((Number) last.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue();
- }
+ totalDistance = last.getDouble(Position.KEY_TOTAL_DISTANCE);
if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
distance = DistanceCalculator.distance(
@@ -49,7 +47,7 @@ public class DistanceHandler extends BaseDataHandler {
distance = BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
} else {
- distance = ((Number) position.getAttributes().get(Position.KEY_DISTANCE)).doubleValue();
+ distance = position.getDouble(Position.KEY_DISTANCE);
}
}
if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index 40676c72d..898651837 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -111,7 +111,7 @@ public class FilterHandler extends BaseDataHandler {
}
private boolean filterApproximate(Position position) {
- Boolean approximate = (Boolean) position.getAttributes().get(Position.KEY_APPROXIMATE);
+ Boolean approximate = position.getBoolean(Position.KEY_APPROXIMATE);
return filterApproximate && approximate != null && approximate;
}
diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java
index ddbca6b0f..678daac9b 100644
--- a/src/org/traccar/api/resource/UserResource.java
+++ b/src/org/traccar/api/resource/UserResource.java
@@ -32,6 +32,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Date;
@Path("users")
@Produces(MediaType.APPLICATION_JSON)
@@ -50,6 +51,12 @@ public class UserResource extends BaseResource {
if (!Context.getPermissionsManager().isAdmin(getUserId())) {
Context.getPermissionsManager().checkRegistration(getUserId());
Context.getPermissionsManager().checkUserUpdate(getUserId(), new User(), entity);
+ entity.setDeviceLimit(Context.getConfig().getInteger("users.defaultDeviceLimit"));
+ int expirationDays = Context.getConfig().getInteger("users.defaultExpirationDays");
+ if (expirationDays > 0) {
+ entity.setExpirationTime(
+ new Date(System.currentTimeMillis() + (long) expirationDays * 24 * 3600 * 1000));
+ }
}
Context.getPermissionsManager().addUser(entity);
if (Context.getNotificationManager() != null) {
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 5681602fe..600669579 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -401,14 +401,12 @@ public class DeviceManager implements IdentityManager {
String result = null;
Device device = getDeviceById(deviceId);
if (device != null) {
- if (device.getAttributes().containsKey(attributeName)) {
- result = (String) device.getAttributes().get(attributeName);
- }
+ result = device.getString(attributeName);
if (result == null && lookupGroupsAttribute) {
long groupId = device.getGroupId();
while (groupId != 0) {
if (getGroupById(groupId) != null) {
- result = (String) getGroupById(groupId).getAttributes().get(attributeName);
+ result = getGroupById(groupId).getString(attributeName);
if (result != null) {
break;
}
@@ -421,7 +419,7 @@ public class DeviceManager implements IdentityManager {
if (result == null) {
if (lookupServer) {
Server server = Context.getPermissionsManager().getServer();
- result = (String) server.getAttributes().get(attributeName);
+ result = server.getString(attributeName);
} else {
result = Context.getConfig().getString(attributeName);
}
diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java
index b52083f57..3086adb13 100644
--- a/src/org/traccar/events/IgnitionEventHandler.java
+++ b/src/org/traccar/events/IgnitionEventHandler.java
@@ -39,20 +39,12 @@ public class IgnitionEventHandler extends BaseEventHandler {
Collection<Event> result = null;
- boolean ignition = false;
- Object ignitionObject = position.getAttributes().get(Position.KEY_IGNITION);
- if (ignitionObject != null && ignitionObject instanceof Boolean) {
- ignition = (Boolean) ignitionObject;
- }
+ boolean ignition = position.getBoolean(Position.KEY_IGNITION);
boolean oldIgnition = false;
- Object oldIgnitionObject = null;
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
if (lastPosition != null) {
- oldIgnitionObject = lastPosition.getAttributes().get(Position.KEY_IGNITION);
- }
- if (oldIgnitionObject != null && oldIgnitionObject instanceof Boolean) {
- oldIgnition = (Boolean) oldIgnitionObject;
+ oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION);
}
if (ignition && !oldIgnition) {
diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java
new file mode 100644
index 000000000..f423e035b
--- /dev/null
+++ b/src/org/traccar/events/MaintenanceEventHandler.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
+ *
+ * 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.events;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.traccar.BaseEventHandler;
+import org.traccar.Context;
+import org.traccar.model.Device;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
+
+public class MaintenanceEventHandler extends BaseEventHandler {
+
+ public static final String ATTRIBUTE_MAINTENANCE_START = "maintenance.start";
+ public static final String ATTRIBUTE_MAINTENANCE_INTERVAL = "maintenance.interval";
+
+ @Override
+ protected Collection<Event> analyzePosition(Position position) {
+ Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId());
+ if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
+ return null;
+ }
+
+ double maintenanceInterval = Context.getDeviceManager()
+ .lookupServerDouble(device.getId(), ATTRIBUTE_MAINTENANCE_INTERVAL, 0);
+ if (maintenanceInterval == 0) {
+ return null;
+ }
+ double maintenanceStart = Context.getDeviceManager()
+ .lookupServerDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0);
+
+ Collection<Event> events = new ArrayList<>();
+ double oldTotalDistance = 0.0;
+ double newTotalDistance = 0.0;
+
+ Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ if (lastPosition != null) {
+ oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE);
+ }
+ newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE);
+
+ oldTotalDistance -= maintenanceStart;
+ newTotalDistance -= maintenanceStart;
+ if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) {
+ events.add(new Event(Event.TYPE_MAINTENANCE_NEEDED, position.getDeviceId(), position.getId()));
+ }
+
+ return events;
+ }
+
+}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 3dc4778e1..45da9a711 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -56,6 +56,8 @@ public class Event extends Message {
public static final String TYPE_IGNITION_ON = "ignitionOn";
public static final String TYPE_IGNITION_OFF = "ignitionOff";
+ public static final String TYPE_MAINTENANCE_NEEDED = "maintenanceNeeded";
+
private Date serverTime;
public Date getServerTime() {
diff --git a/src/org/traccar/model/Extensible.java b/src/org/traccar/model/Extensible.java
index efe60fb75..b8c83bb21 100644
--- a/src/org/traccar/model/Extensible.java
+++ b/src/org/traccar/model/Extensible.java
@@ -68,4 +68,44 @@ public class Extensible {
}
}
+ public String getString(String key) {
+ if (attributes.containsKey(key)) {
+ return (String) attributes.get(key);
+ } else {
+ return null;
+ }
+ }
+
+ public double getDouble(String key) {
+ if (attributes.containsKey(key)) {
+ return ((Number) attributes.get(key)).doubleValue();
+ } else {
+ return 0.0;
+ }
+ }
+
+ public boolean getBoolean(String key) {
+ if (attributes.containsKey(key)) {
+ return Boolean.parseBoolean(attributes.get(key).toString());
+ } else {
+ return false;
+ }
+ }
+
+ public int getInteger(String key) {
+ if (attributes.containsKey(key)) {
+ return ((Number) attributes.get(key)).intValue();
+ } else {
+ return 0;
+ }
+ }
+
+ public long getLong(String key) {
+ if (attributes.containsKey(key)) {
+ return ((Number) attributes.get(key)).longValue();
+ } else {
+ return 0;
+ }
+ }
+
}
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java
index 2355d1793..38a228beb 100644
--- a/src/org/traccar/notification/NotificationFormatter.java
+++ b/src/org/traccar/notification/NotificationFormatter.java
@@ -39,6 +39,10 @@ public final class NotificationFormatter {
public static final String MESSAGE_TEMPLATE_TYPE_DEVICE_ONLINE = "Device: %1$s%n"
+ "Online%n"
+ "Time: %2$tc%n";
+ public static final String TITLE_TEMPLATE_TYPE_DEVICE_UNKNOWN = "%1$s: status is unknown";
+ public static final String MESSAGE_TEMPLATE_TYPE_DEVICE_UNKNOWN = "Device: %1$s%n"
+ + "Status is unknown%n"
+ + "Time: %2$tc%n";
public static final String TITLE_TEMPLATE_TYPE_DEVICE_OFFLINE = "%1$s: offline";
public static final String MESSAGE_TEMPLATE_TYPE_DEVICE_OFFLINE = "Device: %1$s%n"
+ "Offline%n"
@@ -88,6 +92,11 @@ public final class NotificationFormatter {
+ "Ignition OFF%n"
+ "Point: https://www.openstreetmap.org/?mlat=%3$f&mlon=%4$f#map=16/%3$f/%4$f%n"
+ "Time: %2$tc%n";
+ public static final String TITLE_TEMPLATE_TYPE_MAINTENANCE_NEEDED = "%1$s: maintenance is needed";
+ public static final String MESSAGE_TEMPLATE_TYPE_MAINTENANCE_NEEDED = "Device: %1$s%n"
+ + "Maintenance is needed%n"
+ + "Point: https://www.openstreetmap.org/?mlat=%3$f&mlon=%4$f#map=16/%3$f/%4$f%n"
+ + "Time: %2$tc%n";
public static String formatTitle(long userId, Event event, Position position) {
Device device = Context.getIdentityManager().getDeviceById(event.getDeviceId());
@@ -101,6 +110,9 @@ public final class NotificationFormatter {
case Event.TYPE_DEVICE_ONLINE:
formatter.format(TITLE_TEMPLATE_TYPE_DEVICE_ONLINE, device.getName());
break;
+ case Event.TYPE_DEVICE_UNKNOWN:
+ formatter.format(TITLE_TEMPLATE_TYPE_DEVICE_UNKNOWN, device.getName());
+ break;
case Event.TYPE_DEVICE_OFFLINE:
formatter.format(TITLE_TEMPLATE_TYPE_DEVICE_OFFLINE, device.getName());
break;
@@ -128,6 +140,9 @@ public final class NotificationFormatter {
case Event.TYPE_IGNITION_OFF:
formatter.format(TITLE_TEMPLATE_TYPE_IGNITION_OFF, device.getName());
break;
+ case Event.TYPE_MAINTENANCE_NEEDED:
+ formatter.format(TITLE_TEMPLATE_TYPE_MAINTENANCE_NEEDED, device.getName());
+ break;
default:
formatter.format("Unknown type");
break;
@@ -150,6 +165,9 @@ public final class NotificationFormatter {
case Event.TYPE_DEVICE_ONLINE:
formatter.format(MESSAGE_TEMPLATE_TYPE_DEVICE_ONLINE, device.getName(), event.getServerTime());
break;
+ case Event.TYPE_DEVICE_UNKNOWN:
+ formatter.format(MESSAGE_TEMPLATE_TYPE_DEVICE_UNKNOWN, device.getName(), event.getServerTime());
+ break;
case Event.TYPE_DEVICE_OFFLINE:
formatter.format(MESSAGE_TEMPLATE_TYPE_DEVICE_OFFLINE, device.getName(), event.getServerTime());
break;
@@ -188,6 +206,10 @@ public final class NotificationFormatter {
formatter.format(MESSAGE_TEMPLATE_TYPE_IGNITION_OFF, device.getName(), position.getFixTime(),
position.getLatitude(), position.getLongitude());
break;
+ case Event.TYPE_MAINTENANCE_NEEDED:
+ formatter.format(MESSAGE_TEMPLATE_TYPE_MAINTENANCE_NEEDED, device.getName(), position.getFixTime(),
+ position.getLatitude(), position.getLongitude());
+ break;
default:
formatter.format("Unknown type");
break;
diff --git a/src/org/traccar/notification/PropertiesProvider.java b/src/org/traccar/notification/PropertiesProvider.java
index 9136288f8..e7cac8d0f 100644
--- a/src/org/traccar/notification/PropertiesProvider.java
+++ b/src/org/traccar/notification/PropertiesProvider.java
@@ -36,7 +36,7 @@ public class PropertiesProvider {
if (config != null) {
return config.getString(key);
} else {
- return (String) extensible.getAttributes().get(key);
+ return extensible.getString(key);
}
}
diff --git a/src/org/traccar/protocol/At2000FrameDecoder.java b/src/org/traccar/protocol/At2000FrameDecoder.java
new file mode 100644
index 000000000..d0be3f5f4
--- /dev/null
+++ b/src/org/traccar/protocol/At2000FrameDecoder.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016 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.
+ * 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.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.codec.frame.FrameDecoder;
+
+public class At2000FrameDecoder extends FrameDecoder {
+
+ private static final int BLOCK_LENGTH = 16;
+
+ private boolean firstPacket = true;
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+
+ if (buf.readableBytes() < 5) {
+ return null;
+ }
+
+ int length;
+ if (firstPacket) {
+ firstPacket = false;
+ length = buf.getUnsignedMedium(buf.readerIndex() + 2);
+ } else {
+ length = buf.getUnsignedMedium(buf.readerIndex() + 1);
+ }
+
+ length += BLOCK_LENGTH;
+ if (length % BLOCK_LENGTH != 0) {
+ length = (length / BLOCK_LENGTH + 1) * BLOCK_LENGTH;
+ }
+
+ if (buf.readableBytes() >= length) {
+ return buf.readBytes(length);
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/At2000Protocol.java b/src/org/traccar/protocol/At2000Protocol.java
new file mode 100644
index 000000000..418619cb4
--- /dev/null
+++ b/src/org/traccar/protocol/At2000Protocol.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 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.
+ * 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.protocol;
+
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.traccar.BaseProtocol;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class At2000Protocol extends BaseProtocol {
+
+ public At2000Protocol() {
+ super("at2000");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new At2000FrameDecoder());
+ pipeline.addLast("objectDecoder", new At2000ProtocolDecoder(At2000Protocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java
new file mode 100644
index 000000000..17da0eef7
--- /dev/null
+++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2016 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.
+ * 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.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Position;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import java.net.SocketAddress;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+
+public class At2000ProtocolDecoder extends BaseProtocolDecoder {
+
+ private static final int BLOCK_LENGTH = 16;
+
+ public At2000ProtocolDecoder(At2000Protocol protocol) {
+ super(protocol);
+ }
+
+ public static final int MSG_ACKNOWLEDGEMENT = 0x00;
+ public static final int MSG_DEVICE_ID = 0x01;
+ public static final int MSG_TRACK_REQUEST = 0x88;
+ public static final int MSG_TRACK_RESPONSE = 0x89;
+ public static final int MSG_SESSION_END = 0x0c;
+
+ private Cipher cipher;
+
+ private static void sendResponse(Channel channel) {
+ if (channel != null) {
+ ChannelBuffer response = ChannelBuffers.directBuffer(BLOCK_LENGTH);
+ response.writeByte(MSG_ACKNOWLEDGEMENT);
+ response.writeMedium(1);
+ response.writeByte(0x00); // success
+ response.writerIndex(BLOCK_LENGTH);
+ channel.write(response);
+ }
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ if (buf.getUnsignedByte(buf.readerIndex()) == 0x01) {
+ buf.readUnsignedByte(); // codec id
+ }
+
+ int type = buf.readUnsignedByte();
+ buf.readUnsignedMedium(); // length
+ buf.skipBytes(BLOCK_LENGTH - 1 - 3);
+
+ if (type == MSG_DEVICE_ID) {
+
+ String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
+ if (getDeviceSession(channel, remoteAddress, imei) != null) {
+
+ byte[] iv = new byte[BLOCK_LENGTH];
+ buf.readBytes(iv);
+ IvParameterSpec ivSpec = new IvParameterSpec(iv);
+
+ SecretKeySpec keySpec = new SecretKeySpec(
+ DatatypeConverter.parseHexBinary("000102030405060708090a0b0c0d0e0f"), "AES");
+
+ cipher = Cipher.getInstance("AES/CBC/NoPadding");
+ cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
+
+ byte[] data = new byte[BLOCK_LENGTH];
+ buf.readBytes(data);
+ cipher.update(data);
+
+ }
+
+ } else if (type == MSG_TRACK_RESPONSE) {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ byte[] data = new byte[buf.capacity() - BLOCK_LENGTH];
+ buf.readBytes(data);
+ buf = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, cipher.update(data));
+
+ buf.readUnsignedShort(); // index
+ buf.readUnsignedShort(); // reserved
+
+ position.setValid(true);
+
+ position.setTime(new Date(buf.readLong() * 1000));
+
+ position.setLatitude(buf.readFloat());
+ position.setLongitude(buf.readFloat());
+ position.setAltitude(buf.readFloat());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloat()));
+ position.setCourse(buf.readFloat());
+
+ return position;
+
+ }
+
+ sendResponse(channel);
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
index 0c149c1c9..c800131d6 100644
--- a/src/org/traccar/protocol/CityeasyProtocolEncoder.java
+++ b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
@@ -50,13 +50,13 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder {
case Command.TYPE_POSITION_SINGLE:
return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_REQUEST, content);
case Command.TYPE_POSITION_PERIODIC:
- content.writeShort(((Number) command.getAttributes().get(Command.KEY_FREQUENCY)).intValue());
+ content.writeShort(command.getInteger(Command.KEY_FREQUENCY));
return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content);
case Command.TYPE_POSITION_STOP:
content.writeShort(0);
return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content);
case Command.TYPE_SET_TIMEZONE:
- int timezone = ((Number) command.getAttributes().get(Command.KEY_TIMEZONE)).intValue();
+ int timezone = command.getInteger(Command.KEY_TIMEZONE);
if (timezone < 0) {
content.writeByte(1);
} else {
diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java
index b9d6b6f97..5a28733f7 100644
--- a/src/org/traccar/protocol/EelinkProtocolEncoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolEncoder.java
@@ -47,7 +47,7 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent((String) command.getAttributes().get(Command.KEY_DATA));
+ return encodeContent(command.getString(Command.KEY_DATA));
case Command.TYPE_ENGINE_STOP:
return encodeContent("RELAY,1#");
case Command.TYPE_ENGINE_RESUME:
diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
index b6ec5a0d1..8e00522a7 100644
--- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
@@ -59,7 +59,7 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder {
boolean alternative;
Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId());
if (device.getAttributes().containsKey("gt06.alternative")) {
- alternative = Boolean.parseBoolean((String) device.getAttributes().get("gt06.alternative"));
+ alternative = device.getBoolean("gt06.alternative");
} else {
alternative = Context.getConfig().getBoolean("gt06.alternative");
}
diff --git a/src/org/traccar/protocol/Jt600ProtocolEncoder.java b/src/org/traccar/protocol/Jt600ProtocolEncoder.java
index 3eb0566a4..0bf389460 100644
--- a/src/org/traccar/protocol/Jt600ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolEncoder.java
@@ -29,7 +29,7 @@ public class Jt600ProtocolEncoder extends StringProtocolEncoder {
case Command.TYPE_ENGINE_RESUME:
return "(S07,1)";
case Command.TYPE_SET_TIMEZONE:
- int offset = ((Number) command.getAttributes().get(Command.KEY_TIMEZONE)).intValue() / 60;
+ int offset = command.getInteger(Command.KEY_TIMEZONE) / 60;
return "(S09,1," + offset + ")";
case Command.TYPE_REBOOT_DEVICE:
return "(S17)";
diff --git a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
index a91b33a60..268bae392 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
@@ -24,7 +24,6 @@ import org.traccar.model.Command;
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
-import java.util.Map;
public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
@@ -62,13 +61,12 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
protected Object encodeCommand(Command command) {
ChannelBuffer content = ChannelBuffers.dynamicBuffer();
- Map<String, Object> attributes = command.getAttributes();
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
return encodeContent(command.getDeviceId(), MSG_TRACK_ON_DEMAND, content);
case Command.TYPE_POSITION_PERIODIC:
- content.writeShort(((Number) attributes.get(Command.KEY_FREQUENCY)).intValue() / 10);
+ content.writeShort(command.getInteger(Command.KEY_FREQUENCY) / 10);
return encodeContent(command.getDeviceId(), MSG_TRACK_BY_INTERVAL, content);
case Command.TYPE_ENGINE_STOP:
content.writeByte(0x01);
@@ -77,10 +75,10 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
content.writeByte(0x00);
return encodeContent(command.getDeviceId(), MSG_OUTPUT_CONTROL, content);
case Command.TYPE_ALARM_GEOFENCE:
- content.writeShort(((Number) attributes.get(Command.KEY_RADIUS)).intValue());
+ content.writeShort(command.getInteger(Command.KEY_RADIUS));
return encodeContent(command.getDeviceId(), MSG_MOVEMENT_ALARM, content);
case Command.TYPE_SET_TIMEZONE:
- int offset = ((Number) attributes.get(Command.KEY_TIMEZONE)).intValue() / 60;
+ int offset = command.getInteger(Command.KEY_TIMEZONE) / 60;
content.writeBytes(String.valueOf(offset).getBytes(StandardCharsets.US_ASCII));
return encodeContent(command.getDeviceId(), MSG_TIME_ZONE, content);
case Command.TYPE_REBOOT_DEVICE:
diff --git a/src/org/traccar/protocol/NoranProtocolEncoder.java b/src/org/traccar/protocol/NoranProtocolEncoder.java
index 5bd069218..25b510a73 100644
--- a/src/org/traccar/protocol/NoranProtocolEncoder.java
+++ b/src/org/traccar/protocol/NoranProtocolEncoder.java
@@ -52,7 +52,7 @@ public class NoranProtocolEncoder extends BaseProtocolEncoder {
case Command.TYPE_POSITION_SINGLE:
return encodeContent("*KW,000,000,000000#");
case Command.TYPE_POSITION_PERIODIC:
- int interval = ((Number) command.getAttributes().get(Command.KEY_FREQUENCY)).intValue();
+ int interval = command.getInteger(Command.KEY_FREQUENCY);
return encodeContent("*KW,000,002,000000," + interval + "#");
case Command.TYPE_POSITION_STOP:
return encodeContent("*KW,000,002,000000,0#");
diff --git a/src/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/org/traccar/protocol/RuptelaProtocolEncoder.java
index c3b3a3619..0abfa18ce 100644
--- a/src/org/traccar/protocol/RuptelaProtocolEncoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolEncoder.java
@@ -43,7 +43,7 @@ public class RuptelaProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent((String) command.getAttributes().get(Command.KEY_DATA));
+ return encodeContent(command.getString(Command.KEY_DATA));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/T800xProtocolEncoder.java b/src/org/traccar/protocol/T800xProtocolEncoder.java
index 7b02ed10b..6ed5dbccd 100644
--- a/src/org/traccar/protocol/T800xProtocolEncoder.java
+++ b/src/org/traccar/protocol/T800xProtocolEncoder.java
@@ -51,7 +51,7 @@ public class T800xProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent(command, (String) command.getAttributes().get(Command.KEY_DATA));
+ return encodeContent(command, command.getString(Command.KEY_DATA));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
index eb83477b8..fd6eae744 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
@@ -50,7 +50,7 @@ public class TeltonikaProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent((String) command.getAttributes().get(Command.KEY_DATA));
+ return encodeContent(command.getString(Command.KEY_DATA));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java
index f15c0f0c0..0b6a83ce9 100644
--- a/src/org/traccar/protocol/WatchProtocolEncoder.java
+++ b/src/org/traccar/protocol/WatchProtocolEncoder.java
@@ -33,7 +33,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder {
}
private int getEnableFlag(Command command) {
- if ((Boolean) command.getAttributes().get(Command.KEY_ENABLE)) {
+ if (command.getBoolean(Command.KEY_ENABLE)) {
return 1;
} else {
return 0;
@@ -51,7 +51,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder {
}
private String getBinaryData(Command command) {
- byte[] data = DatatypeConverter.parseHexBinary((String) command.getAttributes().get(Command.KEY_DATA));
+ byte[] data = DatatypeConverter.parseHexBinary(command.getString(Command.KEY_DATA));
int encodedLength = data.length;
for (byte b : data) {
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 7fcc767e9..032925a4a 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -63,18 +63,15 @@ public final class ReportUtils {
double distance = 0.0;
double firstOdometer = 0.0;
double lastOdometer = 0.0;
- if (firstPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) {
- firstOdometer = ((Number) firstPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue();
- }
- if (lastPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) {
- lastOdometer = ((Number) lastPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue();
- }
+ firstOdometer = firstPosition.getDouble(Position.KEY_ODOMETER);
+ lastOdometer = lastPosition.getDouble(Position.KEY_ODOMETER);
+
if (useOdometer && (firstOdometer != 0.0 || lastOdometer != 0.0)) {
distance = lastOdometer - firstOdometer;
} else if (firstPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)
&& lastPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) {
- distance = ((Number) lastPosition.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue()
- - ((Number) firstPosition.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue();
+ distance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE)
+ - firstPosition.getDouble(Position.KEY_TOTAL_DISTANCE);
}
return distance;
}
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
index 02791fb5e..4d6446017 100644
--- a/src/org/traccar/reports/Summary.java
+++ b/src/org/traccar/reports/Summary.java
@@ -50,12 +50,8 @@ public final class Summary {
if (firstPosition == null) {
firstPosition = position;
}
- if (previousPosition != null
- && position.getAttributes().get(Position.KEY_IGNITION) != null
- && Boolean.parseBoolean(position.getAttributes().get(Position.KEY_IGNITION).toString())
- && previousPosition.getAttributes().get(Position.KEY_IGNITION) != null
- && Boolean.parseBoolean(previousPosition.getAttributes()
- .get(Position.KEY_IGNITION).toString())) {
+ if (previousPosition != null && position.getBoolean(Position.KEY_IGNITION)
+ && previousPosition.getBoolean(Position.KEY_IGNITION)) {
result.addEngineHours(position.getFixTime().getTime()
- previousPosition.getFixTime().getTime());
}