aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorninioe <ninioe@gmail.com>2016-07-24 10:12:29 +0300
committerninioe <ninioe@gmail.com>2016-07-24 10:12:29 +0300
commitefb18afb3bc265e0d3525ad66ee0e0558d95f478 (patch)
treef5d4cc82a144072a8eec0d25f9fb592422285e1f
parentfd3a695813f511d1b94775bd4e8a4c57053fc66d (diff)
parent0c61dddb5f875e34c819f6d936fcb5e7f45d88ed (diff)
downloadtraccar-server-efb18afb3bc265e0d3525ad66ee0e0558d95f478.tar.gz
traccar-server-efb18afb3bc265e0d3525ad66ee0e0558d95f478.tar.bz2
traccar-server-efb18afb3bc265e0d3525ad66ee0e0558d95f478.zip
Merge remote-tracking branch 'refs/remotes/tananaev/master'
# Conflicts: # tools/test-generator.py
-rw-r--r--.gitignore1
-rw-r--r--src/org/traccar/api/resource/GroupResource.java10
-rw-r--r--src/org/traccar/database/DataManager.java94
-rw-r--r--src/org/traccar/database/DeviceManager.java291
-rw-r--r--src/org/traccar/database/GeofenceManager.java24
-rw-r--r--src/org/traccar/database/PermissionsManager.java3
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/L100FrameDecoder.java50
-rw-r--r--src/org/traccar/protocol/L100Protocol.java42
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java118
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java6
-rw-r--r--swagger.json603
-rw-r--r--test/org/traccar/protocol/GpsGateProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/Gt02ProtocolDecoderTest.java6
-rw-r--r--test/org/traccar/protocol/L100FrameDecoderTest.java24
-rw-r--r--test/org/traccar/protocol/L100ProtocolDecoderTest.java18
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolDecoderTest.java2
-rw-r--r--test/org/traccar/protocol/WatchProtocolDecoderTest.java4
22 files changed, 1065 insertions, 272 deletions
diff --git a/.gitignore b/.gitignore
index 4bb6eefb9..00818a38a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ nbactions.xml
.idea
*.iml
.DS_Store
+.checkstyle
diff --git a/src/org/traccar/api/resource/GroupResource.java b/src/org/traccar/api/resource/GroupResource.java
index 957f39ebe..eec28e325 100644
--- a/src/org/traccar/api/resource/GroupResource.java
+++ b/src/org/traccar/api/resource/GroupResource.java
@@ -43,20 +43,20 @@ public class GroupResource extends BaseResource {
@QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException {
if (all) {
Context.getPermissionsManager().checkAdmin(getUserId());
- return Context.getDataManager().getAllGroups();
+ return Context.getDeviceManager().getAllGroups();
} else {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- return Context.getDataManager().getGroups(userId);
+ return Context.getDeviceManager().getGroups(userId);
}
}
@POST
public Response add(Group entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getDataManager().addGroup(entity);
+ Context.getDeviceManager().addGroup(entity);
Context.getDataManager().linkGroup(getUserId(), entity.getId());
Context.getPermissionsManager().refresh();
if (Context.getGeofenceManager() != null) {
@@ -70,7 +70,7 @@ public class GroupResource extends BaseResource {
public Response update(@PathParam("id") long id, Group entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), id);
- Context.getDataManager().updateGroup(entity);
+ Context.getDeviceManager().updateGroup(entity);
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
@@ -82,7 +82,7 @@ public class GroupResource extends BaseResource {
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), id);
- Context.getDataManager().removeGroup(id);
+ Context.getDeviceManager().removeGroup(id);
Context.getPermissionsManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 710eceebb..04d0d44ea 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -20,16 +20,9 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.naming.InitialContext;
import javax.sql.DataSource;
@@ -43,7 +36,6 @@ import liquibase.resource.FileSystemResourceAccessor;
import liquibase.resource.ResourceAccessor;
import org.traccar.Config;
-import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.DevicePermission;
@@ -64,25 +56,15 @@ import com.zaxxer.hikari.HikariDataSource;
public class DataManager {
- public static final long DEFAULT_REFRESH_DELAY = 300;
-
private final Config config;
private DataSource dataSource;
- private final long dataRefreshDelay;
-
- private final ReadWriteLock groupsLock = new ReentrantReadWriteLock();
- private final Map<Long, Group> groupsById = new HashMap<>();
- private long groupsLastUpdate;
-
public DataManager(Config config) throws Exception {
this.config = config;
initDatabase();
initDatabaseSchema();
-
- dataRefreshDelay = config.getLong("database.refreshDelay", DEFAULT_REFRESH_DELAY) * 1000;
}
public DataSource getDataSource() {
@@ -131,54 +113,6 @@ public class DataManager {
}
}
- private void updateGroupCache(boolean force) throws SQLException {
- boolean needWrite;
- groupsLock.readLock().lock();
- try {
- needWrite = force || System.currentTimeMillis() - groupsLastUpdate > dataRefreshDelay;
- } finally {
- groupsLock.readLock().unlock();
- }
-
- if (needWrite) {
- groupsLock.writeLock().lock();
- try {
- if (force || System.currentTimeMillis() - groupsLastUpdate > dataRefreshDelay) {
- groupsById.clear();
- for (Group group : getAllGroups()) {
- groupsById.put(group.getId(), group);
- }
- groupsLastUpdate = System.currentTimeMillis();
- }
- } finally {
- groupsLock.writeLock().unlock();
- }
- }
- }
-
- public Group getGroupById(long id) {
- boolean forceUpdate;
- groupsLock.readLock().lock();
- try {
- forceUpdate = !groupsById.containsKey(id);
- } finally {
- groupsLock.readLock().unlock();
- }
-
- try {
- updateGroupCache(forceUpdate);
- } catch (SQLException e) {
- Log.warning(e);
- }
-
- groupsLock.readLock().lock();
- try {
- return groupsById.get(id);
- } finally {
- groupsLock.readLock().unlock();
- }
- }
-
private String getQuery(String key) {
String query = config.getString(key);
if (query == null) {
@@ -311,44 +245,16 @@ public class DataManager {
.executeQuery(Group.class);
}
- public Collection<Group> getGroups(long userId) throws SQLException {
- Collection<Group> groups = new ArrayList<>();
- for (long id : Context.getPermissionsManager().getGroupPermissions(userId)) {
- groups.add(getGroupById(id));
- }
- return groups;
- }
-
- private void checkGroupCycles(Group group) {
- groupsLock.readLock().lock();
- try {
- Set<Long> groups = new HashSet<>();
- while (group != null) {
- if (groups.contains(group.getId())) {
- throw new IllegalArgumentException("Cycle in group hierarchy");
- }
- groups.add(group.getId());
- group = groupsById.get(group.getGroupId());
- }
- } finally {
- groupsLock.readLock().unlock();
- }
- }
-
public void addGroup(Group group) throws SQLException {
- checkGroupCycles(group);
group.setId(QueryBuilder.create(dataSource, getQuery("database.insertGroup"), true)
.setObject(group)
.executeUpdate());
- updateGroupCache(true);
}
public void updateGroup(Group group) throws SQLException {
- checkGroupCycles(group);
QueryBuilder.create(dataSource, getQuery("database.updateGroup"))
.setObject(group)
.executeUpdate();
- updateGroupCache(true);
}
public void removeGroup(long groupId) throws SQLException {
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 173e68062..4dd7b41cb 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -18,39 +18,46 @@ package org.traccar.database;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.atomic.AtomicLong;
import org.traccar.Config;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Device;
+import org.traccar.model.Group;
import org.traccar.model.Position;
public class DeviceManager implements IdentityManager {
+ public static final long DEFAULT_REFRESH_DELAY = 300;
+
private final Config config;
private final DataManager dataManager;
private final long dataRefreshDelay;
- private final ReadWriteLock devicesLock = new ReentrantReadWriteLock();
- private final Map<Long, Device> devicesById = new HashMap<>();
- private final Map<String, Device> devicesByUniqueId = new HashMap<>();
- private long devicesLastUpdate;
+ private Map<Long, Device> devicesById;
+ private Map<String, Device> devicesByUniqueId;
+ private AtomicLong devicesLastUpdate = new AtomicLong();
+
+ private Map<Long, Group> groupsById;
+ private AtomicLong groupsLastUpdate = new AtomicLong();
private final Map<Long, Position> positions = new ConcurrentHashMap<>();
public DeviceManager(DataManager dataManager) {
this.dataManager = dataManager;
this.config = Context.getConfig();
- dataRefreshDelay = config.getLong("database.refreshDelay", DataManager.DEFAULT_REFRESH_DELAY) * 1000;
+ dataRefreshDelay = config.getLong("database.refreshDelay", DEFAULT_REFRESH_DELAY) * 1000;
if (dataManager != null) {
try {
+ updateGroupCache(true);
+ updateDeviceCache(true);
for (Position position : dataManager.getLatestPositions()) {
positions.put(position.getDeviceId(), position);
}
@@ -61,91 +68,77 @@ public class DeviceManager implements IdentityManager {
}
private void updateDeviceCache(boolean force) throws SQLException {
- boolean needWrite;
- devicesLock.readLock().lock();
- try {
- needWrite = force || System.currentTimeMillis() - devicesLastUpdate > dataRefreshDelay;
- } finally {
- devicesLock.readLock().unlock();
- }
- if (needWrite) {
- devicesLock.writeLock().lock();
- try {
- if (force || System.currentTimeMillis() - devicesLastUpdate > dataRefreshDelay) {
- devicesById.clear();
- devicesByUniqueId.clear();
- GeofenceManager geofenceManager = Context.getGeofenceManager();
- for (Device device : dataManager.getAllDevices()) {
- devicesById.put(device.getId(), device);
- devicesByUniqueId.put(device.getUniqueId(), device);
- if (geofenceManager != null) {
- Position lastPosition = getLastPosition(device.getId());
- if (lastPosition != null) {
- device.setGeofenceIds(geofenceManager.getCurrentDeviceGeofences(lastPosition));
- }
+ long lastUpdate = devicesLastUpdate.get();
+ if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
+ && devicesLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) {
+ GeofenceManager geofenceManager = Context.getGeofenceManager();
+ Collection<Device> databaseDevices = dataManager.getAllDevices();
+ if (devicesById == null) {
+ devicesById = new ConcurrentHashMap<>(databaseDevices.size());
+ }
+ if (devicesByUniqueId == null) {
+ devicesByUniqueId = new ConcurrentHashMap<>(databaseDevices.size());
+ }
+ Set<Long> databaseDevicesIds = new HashSet<>();
+ Set<String> databaseDevicesUniqueIds = new HashSet<>();
+ for (Device device : databaseDevices) {
+ databaseDevicesIds.add(device.getId());
+ databaseDevicesUniqueIds.add(device.getUniqueId());
+ if (devicesById.containsKey(device.getId())) {
+ Device cachedDevice = devicesById.get(device.getId());
+ cachedDevice.setName(device.getName());
+ cachedDevice.setGroupId(device.getGroupId());
+ cachedDevice.setAttributes(device.getAttributes());
+ if (!device.getUniqueId().equals(cachedDevice.getUniqueId())) {
+ devicesByUniqueId.remove(cachedDevice.getUniqueId());
+ devicesByUniqueId.put(device.getUniqueId(), cachedDevice);
+ }
+ cachedDevice.setUniqueId(device.getUniqueId());
+ } else {
+ devicesById.put(device.getId(), device);
+ devicesByUniqueId.put(device.getUniqueId(), device);
+ if (geofenceManager != null) {
+ Position lastPosition = getLastPosition(device.getId());
+ if (lastPosition != null) {
+ device.setGeofenceIds(geofenceManager.getCurrentDeviceGeofences(lastPosition));
}
}
- devicesLastUpdate = System.currentTimeMillis();
+ device.setStatus(Device.STATUS_OFFLINE);
+ device.setMotion(Device.STATUS_STOPPED);
+ }
+ }
+ for (Long cachedDeviceId : devicesById.keySet()) {
+ if (!databaseDevicesIds.contains(cachedDeviceId)) {
+ devicesById.remove(cachedDeviceId);
}
- } finally {
- devicesLock.writeLock().unlock();
}
+ for (String cachedDeviceUniqId : devicesByUniqueId.keySet()) {
+ if (!databaseDevicesUniqueIds.contains(cachedDeviceUniqId)) {
+ devicesByUniqueId.remove(cachedDeviceUniqId);
+ }
+ }
+ databaseDevicesIds.clear();
+ databaseDevicesUniqueIds.clear();
}
}
@Override
public Device getDeviceById(long id) {
- boolean forceUpdate;
- devicesLock.readLock().lock();
- try {
- forceUpdate = !devicesById.containsKey(id);
- } finally {
- devicesLock.readLock().unlock();
- }
-
- try {
- updateDeviceCache(forceUpdate);
- } catch (SQLException e) {
- Log.warning(e);
- }
-
- devicesLock.readLock().lock();
- try {
- return devicesById.get(id);
- } finally {
- devicesLock.readLock().unlock();
- }
+ return devicesById.get(id);
}
@Override
public Device getDeviceByUniqueId(String uniqueId) throws SQLException {
- boolean forceUpdate;
- devicesLock.readLock().lock();
- try {
- forceUpdate = !devicesByUniqueId.containsKey(uniqueId) && !config.getBoolean("database.ignoreUnknown");
- } finally {
- devicesLock.readLock().unlock();
- }
+ boolean forceUpdate = !devicesByUniqueId.containsKey(uniqueId) && !config.getBoolean("database.ignoreUnknown");
updateDeviceCache(forceUpdate);
- devicesLock.readLock().lock();
- try {
- return devicesByUniqueId.get(uniqueId);
- } finally {
- devicesLock.readLock().unlock();
- }
+ return devicesByUniqueId.get(uniqueId);
}
public Collection<Device> getAllDevices() {
- boolean forceUpdate;
- devicesLock.readLock().lock();
- try {
- forceUpdate = devicesById.isEmpty();
- } finally {
- devicesLock.readLock().unlock();
- }
+ boolean forceUpdate = devicesById.isEmpty();
try {
updateDeviceCache(forceUpdate);
@@ -153,23 +146,13 @@ public class DeviceManager implements IdentityManager {
Log.warning(e);
}
- devicesLock.readLock().lock();
- try {
- return devicesById.values();
- } finally {
- devicesLock.readLock().unlock();
- }
+ return devicesById.values();
}
public Collection<Device> getDevices(long userId) throws SQLException {
Collection<Device> devices = new ArrayList<>();
- devicesLock.readLock().lock();
- try {
- for (long id : Context.getPermissionsManager().getDevicePermissions(userId)) {
- devices.add(devicesById.get(id));
- }
- } finally {
- devicesLock.readLock().unlock();
+ for (long id : Context.getPermissionsManager().getDevicePermissions(userId)) {
+ devices.add(devicesById.get(id));
}
return devices;
}
@@ -177,56 +160,34 @@ public class DeviceManager implements IdentityManager {
public void addDevice(Device device) throws SQLException {
dataManager.addDevice(device);
- devicesLock.writeLock().lock();
- try {
- devicesById.put(device.getId(), device);
- devicesByUniqueId.put(device.getUniqueId(), device);
- } finally {
- devicesLock.writeLock().unlock();
- }
+ devicesById.put(device.getId(), device);
+ devicesByUniqueId.put(device.getUniqueId(), device);
}
public void updateDevice(Device device) throws SQLException {
dataManager.updateDevice(device);
- devicesLock.writeLock().lock();
- try {
- devicesById.put(device.getId(), device);
- devicesByUniqueId.put(device.getUniqueId(), device);
- } finally {
- devicesLock.writeLock().unlock();
- }
+ devicesById.put(device.getId(), device);
+ devicesByUniqueId.put(device.getUniqueId(), device);
}
public void updateDeviceStatus(Device device) throws SQLException {
dataManager.updateDeviceStatus(device);
-
- devicesLock.writeLock().lock();
- try {
- if (devicesById.containsKey(device.getId())) {
- Device cachedDevice = devicesById.get(device.getId());
- cachedDevice.setStatus(device.getStatus());
- cachedDevice.setMotion(device.getMotion());
- }
- } finally {
- devicesLock.writeLock().unlock();
+ if (devicesById.containsKey(device.getId())) {
+ Device cachedDevice = devicesById.get(device.getId());
+ cachedDevice.setStatus(device.getStatus());
+ cachedDevice.setMotion(device.getMotion());
}
}
public void removeDevice(long deviceId) throws SQLException {
dataManager.removeDevice(deviceId);
- devicesLock.writeLock().lock();
- try {
- if (devicesById.containsKey(deviceId)) {
- String deviceUniqueId = devicesById.get(deviceId).getUniqueId();
- devicesById.remove(deviceId);
- devicesByUniqueId.remove(deviceUniqueId);
- }
- } finally {
- devicesLock.writeLock().unlock();
+ if (devicesById.containsKey(deviceId)) {
+ String deviceUniqueId = devicesById.get(deviceId).getUniqueId();
+ devicesById.remove(deviceId);
+ devicesByUniqueId.remove(deviceUniqueId);
}
-
positions.remove(deviceId);
}
@@ -237,13 +198,8 @@ public class DeviceManager implements IdentityManager {
dataManager.updateLatestPosition(position);
- devicesLock.writeLock().lock();
- try {
- if (devicesById.containsKey(position.getDeviceId())) {
- devicesById.get(position.getDeviceId()).setPositionId(position.getId());
- }
- } finally {
- devicesLock.writeLock().unlock();
+ if (devicesById.containsKey(position.getDeviceId())) {
+ devicesById.get(position.getDeviceId()).setPositionId(position.getId());
}
positions.put(position.getDeviceId(), position);
@@ -273,4 +229,85 @@ public class DeviceManager implements IdentityManager {
return result;
}
+
+ private void updateGroupCache(boolean force) throws SQLException {
+
+ long lastUpdate = groupsLastUpdate.get();
+ if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
+ && groupsLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) {
+ Collection<Group> databaseGroups = dataManager.getAllGroups();
+ if (groupsById == null) {
+ groupsById = new ConcurrentHashMap<>(databaseGroups.size());
+ }
+ Set<Long> databaseGroupsIds = new HashSet<>();
+ for (Group group : databaseGroups) {
+ databaseGroupsIds.add(group.getId());
+ if (groupsById.containsKey(group.getId())) {
+ Group cachedGroup = groupsById.get(group.getId());
+ cachedGroup.setName(group.getName());
+ cachedGroup.setGroupId(group.getGroupId());
+ } else {
+ groupsById.put(group.getId(), group);
+ }
+ }
+ for (Long cachedGroupId : groupsById.keySet()) {
+ if (!databaseGroupsIds.contains(cachedGroupId)) {
+ devicesById.remove(cachedGroupId);
+ }
+ }
+ databaseGroupsIds.clear();
+ }
+ }
+
+ public Group getGroupById(long id) {
+ return groupsById.get(id);
+ }
+
+ public Collection<Group> getAllGroups() {
+ boolean forceUpdate = groupsById.isEmpty();
+
+ try {
+ updateGroupCache(forceUpdate);
+ } catch (SQLException e) {
+ Log.warning(e);
+ }
+
+ return groupsById.values();
+ }
+
+ public Collection<Group> getGroups(long userId) throws SQLException {
+ Collection<Group> groups = new ArrayList<>();
+ for (long id : Context.getPermissionsManager().getGroupPermissions(userId)) {
+ groups.add(getGroupById(id));
+ }
+ return groups;
+ }
+
+ private void checkGroupCycles(Group group) {
+ Set<Long> groups = new HashSet<>();
+ while (group != null) {
+ if (groups.contains(group.getId())) {
+ throw new IllegalArgumentException("Cycle in group hierarchy");
+ }
+ groups.add(group.getId());
+ group = groupsById.get(group.getGroupId());
+ }
+ }
+
+ public void addGroup(Group group) throws SQLException {
+ checkGroupCycles(group);
+ dataManager.addGroup(group);
+ groupsById.put(group.getId(), group);
+ }
+
+ public void updateGroup(Group group) throws SQLException {
+ checkGroupCycles(group);
+ dataManager.updateGroup(group);
+ groupsById.put(group.getId(), group);
+ }
+
+ public void removeGroup(long groupId) throws SQLException {
+ dataManager.removeGroup(groupId);
+ groupsById.remove(groupId);
+ }
}
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
index dc31172b9..74dff70f4 100644
--- a/src/org/traccar/database/GeofenceManager.java
+++ b/src/org/traccar/database/GeofenceManager.java
@@ -155,31 +155,41 @@ public class GeofenceManager {
public final void refresh() {
if (dataManager != null) {
try {
+
+ Collection<GroupGeofence> databaseGroupGeofences = dataManager.getGroupGeofences();
groupGeofencesLock.writeLock().lock();
- deviceGeofencesLock.writeLock().lock();
try {
groupGeofences.clear();
- for (GroupGeofence groupGeofence : dataManager.getGroupGeofences()) {
+ for (GroupGeofence groupGeofence : databaseGroupGeofences) {
getGroupGeofences(groupGeofence.getGroupId()).add(groupGeofence.getGeofenceId());
}
+ } finally {
+ groupGeofencesLock.writeLock().unlock();
+ }
+ Collection<DeviceGeofence> databaseDeviceGeofences = dataManager.getDeviceGeofences();
+ Collection<Device> allDevices = Context.getDeviceManager().getAllDevices();
+
+ groupGeofencesLock.readLock().lock();
+ deviceGeofencesLock.writeLock().lock();
+ try {
deviceGeofences.clear();
deviceGeofencesWithGroups.clear();
- for (DeviceGeofence deviceGeofence : dataManager.getDeviceGeofences()) {
+ for (DeviceGeofence deviceGeofence : databaseDeviceGeofences) {
getDeviceGeofences(deviceGeofences, deviceGeofence.getDeviceId())
.add(deviceGeofence.getGeofenceId());
getDeviceGeofences(deviceGeofencesWithGroups, deviceGeofence.getDeviceId())
.add(deviceGeofence.getGeofenceId());
}
- for (Device device : Context.getDeviceManager().getAllDevices()) {
+ for (Device device : allDevices) {
long groupId = device.getGroupId();
while (groupId != 0) {
getDeviceGeofences(deviceGeofencesWithGroups,
device.getId()).addAll(getGroupGeofences(groupId));
- if (dataManager.getGroupById(groupId) != null) {
- groupId = dataManager.getGroupById(groupId).getGroupId();
+ if (Context.getDeviceManager().getGroupById(groupId) != null) {
+ groupId = Context.getDeviceManager().getGroupById(groupId).getGroupId();
} else {
groupId = 0;
}
@@ -204,8 +214,8 @@ public class GeofenceManager {
}
} finally {
- groupGeofencesLock.writeLock().unlock();
deviceGeofencesLock.writeLock().unlock();
+ groupGeofencesLock.readLock().unlock();
}
} catch (SQLException error) {
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 5a15375b4..d786dcc4e 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -78,7 +78,8 @@ public class PermissionsManager {
users.put(user.getId(), user);
}
- GroupTree groupTree = new GroupTree(dataManager.getAllGroups(), Context.getDeviceManager().getAllDevices());
+ GroupTree groupTree = new GroupTree(Context.getDeviceManager().getAllGroups(),
+ Context.getDeviceManager().getAllDevices());
for (GroupPermission permission : dataManager.getGroupPermissions()) {
Set<Long> userGroupPermissions = getGroupPermissions(permission.getUserId());
Set<Long> userDevicePermissions = getDevicePermissions(permission.getUserId());
diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
index fa792d7b5..41f395fd9 100644
--- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
@@ -86,13 +86,13 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
.setTime(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16));
position.setTime(dateBuilder.getDate());
- if (BitUtil.check(parser.nextInt(16), 7)) {
+ if (BitUtil.check(parser.nextInt(16), 3)) {
position.setLatitude(-parser.nextInt(16) / 600000.0);
} else {
position.setLatitude(parser.nextInt(16) / 600000.0);
}
- if (BitUtil.check(parser.nextInt(16), 7)) {
+ if (BitUtil.check(parser.nextInt(16), 3)) {
position.setLongitude(-parser.nextInt(16) / 600000.0);
} else {
position.setLongitude(parser.nextInt(16) / 600000.0);
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
index 1cb0ddfde..afc17a9f7 100644
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
@@ -58,10 +58,10 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
.expression("([EW]),")
.number("(d+.?d*),") // altitude
.number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
+ .number("(d+.?d*)?,") // course
.number("(dd)(dd)(dd),") // date (ddmmyy)
.number("(dd)(dd)(dd).?(d+)?,") // time
- .expression("([01]),") // validity
+ .expression("([01])") // validity
.any()
.compile();
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index d93b93b83..dea1416ac 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 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.
@@ -26,6 +26,7 @@ import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
@@ -33,8 +34,9 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- public static final int MSG_HEARTBEAT = 0x1A;
public static final int MSG_DATA = 0x10;
+ public static final int MSG_HEARTBEAT = 0x1A;
+ public static final int MSG_RESPONSE = 0x1C;
@Override
protected Object decode(
@@ -102,6 +104,13 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(latitude);
position.setLongitude(longitude);
+ } else if (type == MSG_RESPONSE) {
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_RESULT,
+ buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII));
+
} else {
return null;
diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java
new file mode 100644
index 000000000..92af255dd
--- /dev/null
+++ b/src/org/traccar/protocol/L100FrameDecoder.java
@@ -0,0 +1,50 @@
+/*
+ * 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.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 L100FrameDecoder extends FrameDecoder {
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+
+ if (buf.readableBytes() < 80) {
+ return null;
+ }
+
+ int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02);
+ if (index == -1) {
+ index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04);
+ if (index == -1) {
+ return null;
+ }
+ }
+
+ index += 2; // checksum
+
+ if (buf.readableBytes() >= index - buf.readerIndex()) {
+ return buf.readBytes(index - buf.readerIndex());
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/L100Protocol.java b/src/org/traccar/protocol/L100Protocol.java
new file mode 100644
index 000000000..95a4dce68
--- /dev/null
+++ b/src/org/traccar/protocol/L100Protocol.java
@@ -0,0 +1,42 @@
+/*
+ * 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.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 L100Protocol extends BaseProtocol {
+
+ public L100Protocol() {
+ super("l100");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new L100FrameDecoder());
+ pipeline.addLast("objectDecoder", new L100ProtocolDecoder(L100Protocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
new file mode 100644
index 000000000..ff0687751
--- /dev/null
+++ b/src/org/traccar/protocol/L100ProtocolDecoder.java
@@ -0,0 +1,118 @@
+/*
+ * 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.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.regex.Pattern;
+
+public class L100ProtocolDecoder extends BaseProtocolDecoder {
+
+ public L100ProtocolDecoder(L100Protocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("ATL")
+ .number("(d{15}),") // imei
+ .text("$GPRMC,")
+ .number("(dd)(dd)(dd).ddd,") // time
+ .expression("([AV]),") // validity
+ .number("(dd)(dd.d+),") // latitude
+ .expression("([NS]),")
+ .number("(ddd)(dd.d+),") // longitude
+ .expression("([EW]),")
+ .number("(d+.?d*)?,") // speed
+ .number("(d+.?d*)?,") // course
+ .number("(dd)(dd)(dd),") // date
+ .any()
+ .text("#")
+ .number("([01]+),") // io status
+ .number("(d+.d+|N.C),") // adc
+ .expression("[^,]*,") // reserved
+ .expression("[^,]*,") // reserved
+ .number("(d+.d+),") // odometer
+ .number("(d+.d+),") // temperature
+ .number("(d+.d+),") // battery
+ .number("(d+),") // gsm
+ .number("(d+),") // mcc
+ .number("(d+),") // mnc
+ .number("(d+),") // lac
+ .number("(d+)") // cid
+ .text("ATL")
+ .compile();
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ buf.readUnsignedByte(); // start marker
+ buf.readUnsignedByte(); // type
+
+ String sentence = buf.readBytes(buf.readableBytes() - 2).toString(StandardCharsets.US_ASCII);
+
+ Parser parser = new Parser(PATTERN, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ position.setValid(parser.next().equals("A"));
+ position.setLatitude(parser.nextCoordinate());
+ position.setLongitude(parser.nextCoordinate());
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextDouble());
+
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.set(Position.KEY_STATUS, parser.next());
+ position.set(Position.PREFIX_ADC + 1, parser.next());
+ position.set(Position.KEY_ODOMETER, parser.nextDouble());
+ position.set(Position.PREFIX_TEMP + 1, parser.nextDouble());
+ position.set(Position.KEY_BATTERY, parser.nextDouble());
+ position.set(Position.KEY_GSM, parser.nextInt());
+ position.set(Position.KEY_MCC, parser.nextInt());
+ position.set(Position.KEY_MNC, parser.nextInt());
+ position.set(Position.KEY_LAC, parser.nextInt());
+ position.set(Position.KEY_CID, parser.nextInt());
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index cfa8990dd..f46511b27 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -16,10 +16,8 @@
package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
@@ -50,8 +48,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
Map<String, List<String>> params = decoder.getParameters();
if (params.isEmpty()) {
- decoder = new QueryStringDecoder(
- request.getContent().toString(StandardCharsets.US_ASCII), false);
+ decoder = new QueryStringDecoder(request.getContent().toString(StandardCharsets.US_ASCII), false);
params = decoder.getParameters();
}
@@ -66,6 +63,10 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
case "deviceid":
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
if (deviceSession == null) {
+ if (channel != null) {
+ channel.write(
+ new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST));
+ }
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
@@ -123,9 +124,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
}
if (channel != null) {
- HttpResponse response = new DefaultHttpResponse(
- HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
- channel.write(response).addListener(ChannelFutureListener.CLOSE);
+ channel.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
}
return position;
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index a0998d50d..a76c208b5 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -118,12 +118,12 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
int battery = parser.nextInt();
if (battery != 65535) {
- position.set(Position.KEY_BATTERY, battery);
+ position.set(Position.KEY_BATTERY, battery * 0.01);
}
int power = parser.nextInt();
if (power != 65535) {
- position.set(Position.KEY_POWER, power);
+ position.set(Position.KEY_POWER, power * 0.1);
}
return position;
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index ca63e701e..326552e7f 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.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.
@@ -47,9 +47,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.number("(dd)(dd)(dd),") // date (ddmmyy)
.number("(dd)(dd)(dd),") // time
.expression("([AV]),") // validity
- .number(" *-?(d+.d+),") // latitude
+ .number(" *(-?d+.d+),") // latitude
.expression("([NS]),")
- .number(" *-?(d+.d+),") // longitude
+ .number(" *(-?d+.d+),") // longitude
.expression("([EW])?,")
.number("(d+.d+),") // speed
.number("(d+.?d*),") // course
diff --git a/swagger.json b/swagger.json
index 12b5020c7..a16794a41 100644
--- a/swagger.json
+++ b/swagger.json
@@ -1,7 +1,7 @@
{
"swagger": "2.0",
"info": {
- "version": "3.5",
+ "version": "3.7",
"title": "traccar"
},
"host": "traccar.org",
@@ -159,6 +159,59 @@
}
}
},
+ "/devices/geofences": {
+ "post": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/DeviceGeofence"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "$ref": "#/definitions/DeviceGeofence"
+ }
+ }
+ }
+ },
+ "delete": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/DeviceGeofence"
+ }
+ }
+ ],
+ "responses": {
+ "204": {
+ "description": "No Content",
+ "headers": {}
+ }
+ }
+ }
+ },
"/groups": {
"get": {
"consumes": [
@@ -279,6 +332,59 @@
}
}
},
+ "/groups/geofences": {
+ "post": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/GroupGeofence"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "$ref": "#/definitions/GroupGeofence"
+ }
+ }
+ }
+ },
+ "delete": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/GroupGeofence"
+ }
+ }
+ ],
+ "responses": {
+ "204": {
+ "description": "No Content",
+ "headers": {}
+ }
+ }
+ }
+ },
"/permissions/devices": {
"post": {
"consumes": [
@@ -385,6 +491,59 @@
}
}
},
+ "/permissions/geofences": {
+ "post": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/GeofencePermission"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "$ref": "#/definitions/GeofencePermission"
+ }
+ }
+ }
+ },
+ "delete": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/GeofencePermission"
+ }
+ }
+ ],
+ "responses": {
+ "204": {
+ "description": "No Content",
+ "headers": {}
+ }
+ }
+ }
+ },
"/positions": {
"get": {
"consumes": [
@@ -654,11 +813,314 @@
}
}
}
+ },
+ "/users/notifications": {
+ "get": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "all",
+ "in": "query",
+ "required": true,
+ "type": "boolean"
+ },
+ {
+ "name": "userId",
+ "in": "query",
+ "required": true,
+ "type": "integer"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/Notification"
+ }
+ }
+ }
+ }
+ },
+ "post": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/Notification"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "$ref": "#/definitions/Notification"
+ }
+ }
+ }
+ }
+ },
+ "/commandtypes": {
+ "post": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "deviceId",
+ "in": "query",
+ "required": true,
+ "type": "integer"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/CommandType"
+ }
+ }
+ }
+ }
+ }
+ },
+ "/geofences": {
+ "get": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "all",
+ "in": "query",
+ "required": true,
+ "type": "boolean"
+ },
+ {
+ "name": "userId",
+ "in": "query",
+ "required": true,
+ "type": "integer"
+ },
+ {
+ "name": "groupId",
+ "in": "query",
+ "required": true,
+ "type": "integer"
+ },
+ {
+ "name": "deviceId",
+ "in": "query",
+ "required": true,
+ "type": "integer"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/Geofence"
+ }
+ }
+ }
+ }
+ },
+ "post": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/Geofence"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "$ref": "#/definitions/Geofence"
+ }
+ }
+ }
+ }
+ },
+ "/geofences/{id}": {
+ "put": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "id",
+ "in": "path",
+ "required": true,
+ "type": "integer"
+ },
+ {
+ "name": "body",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/Geofence"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "$ref": "#/definitions/Geofence"
+ }
+ }
+ }
+ },
+ "delete": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "id",
+ "in": "path",
+ "required": true,
+ "type": "integer"
+ }
+ ],
+ "responses": {
+ "204": {
+ "description": "No Content",
+ "headers": {}
+ }
+ }
+ }
+ },
+ "/events": {
+ "get": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "deviceId",
+ "in": "query",
+ "required": true,
+ "type": "integer"
+ },
+ {
+ "name": "type",
+ "in": "query",
+ "required": true,
+ "type": "string"
+ },
+ {
+ "name": "interval",
+ "in": "query",
+ "required": true,
+ "type": "integer"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/Event"
+ }
+ }
+ }
+ }
+ }
+ },
+ "/events/{id}": {
+ "get": {
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "id",
+ "in": "path",
+ "required": true,
+ "type": "integer"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "headers": {},
+ "schema": {
+ "$ref": "#/definitions/Event"
+ }
+ }
+ }
+ }
}
},
"definitions": {
"Position": {
"properties": {
+ "id": {
+ "type": "integer"
+ },
+ "protocol": {
+ "type": "string"
+ },
+ "deviceTime": {
+ "type": "string"
+ },
"fixTime": {
"type": "string"
},
@@ -685,13 +1147,14 @@
},
"address": {
"type": "string"
- }
+ },
+ "attributes": {}
}
},
"User": {
"properties": {
"id": {
- "type": "number"
+ "type": "integer"
},
"name": {
"type": "string"
@@ -724,20 +1187,21 @@
"type": "number"
},
"zoom": {
- "type": "number"
+ "type": "integer"
},
"password": {
"type": "string"
},
"twelveHourFormat": {
"type": "boolean"
- }
+ },
+ "attributes": {}
}
},
"Server": {
"properties": {
"id": {
- "type": "number"
+ "type": "integer"
},
"registration": {
"type": "boolean"
@@ -767,7 +1231,7 @@
"type": "number"
},
"zoom": {
- "type": "number"
+ "type": "integer"
},
"twelveHourFormat": {
"type": "boolean"
@@ -775,12 +1239,20 @@
}
},
"Command": {
- "properties": {}
+ "properties": {
+ "deviceId": {
+ "type": "integer"
+ },
+ "type": {
+ "type": "string"
+ },
+ "attributes": {}
+ }
},
"Device": {
"properties": {
"id": {
- "type": "number"
+ "type": "integer"
},
"name": {
"type": "string"
@@ -795,45 +1267,138 @@
"type": "string"
},
"positionId": {
- "type": "number"
+ "type": "integer"
},
"groupId": {
- "type": "number"
- }
+ "type": "integer"
+ },
+ "geofenceIds": {},
+ "attributes": {}
}
},
"Group": {
"properties": {
"id": {
- "type": "number"
+ "type": "integer"
},
"name": {
"type": "string"
},
"groupId": {
- "type": "number"
+ "type": "integer"
}
}
},
"DevicePermission": {
"properties": {
"userId": {
- "type": "number"
+ "type": "integer"
},
"deviceId": {
- "type": "number"
+ "type": "integer"
}
}
},
"GroupPermission": {
"properties": {
"userId": {
- "type": "number"
+ "type": "integer"
},
"groupId": {
- "type": "number"
+ "type": "integer"
+ }
+ }
+ },
+ "GeofencePermission": {
+ "properties": {
+ "userId": {
+ "type": "integer"
+ },
+ "geofenceId": {
+ "type": "integer"
+ }
+ }
+ },
+ "GroupGeofence": {
+ "properties": {
+ "groupId": {
+ "type": "integer"
+ },
+ "geofenceId": {
+ "type": "integer"
+ }
+ }
+ },
+ "DeviceGeofence": {
+ "properties": {
+ "deviceId": {
+ "type": "integer"
+ },
+ "geofenceId": {
+ "type": "integer"
+ }
+ }
+ },
+ "CommandType": {
+ "properties": {
+ "type": {
+ "type": "string"
}
}
+ },
+ "Geofence": {
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
+ },
+ "area": {
+ "type": "string"
+ },
+ "attributes": {}
+ }
+ },
+ "Notification": {
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "type": {
+ "type": "string"
+ },
+ "userId": {
+ "type": "integer"
+ },
+ "attributes": {}
+ }
+ },
+ "Event": {
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "type": {
+ "type": "string"
+ },
+ "serverTime": {
+ "type": "string"
+ },
+ "deviceId": {
+ "type": "integer"
+ },
+ "positionId": {
+ "type": "integer"
+ },
+ "geofenceId": {
+ "type": "integer"
+ },
+ "attributes": {}
+ }
}
}
-}
+} \ No newline at end of file
diff --git a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
index 30861099f..11cfb66f5 100644
--- a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class GpsGateProtocolDecoderTest extends ProtocolTest {
GpsGateProtocolDecoder decoder = new GpsGateProtocolDecoder(new GpsGateProtocol());
verifyPosition(decoder, text(
+ "$FRCMD,356406061385182,_SendMessage,,5223.88542,N,11440.45866,W,951.2,0.027,,220716,153507.00,1*5F"));
+
+ verifyPosition(decoder, text(
"$FRCMD,353067011068246,_SendMessage,,1918.1942,N,09906.3696,W,2246.5,000.0,295.9,150416,213147.00,1,Odometer=*70"));
verifyNothing(decoder, text(
diff --git a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
index 3cfa0ea4a..c957acd6c 100644
--- a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
@@ -11,6 +11,12 @@ public class Gt02ProtocolDecoderTest extends ProtocolTest {
Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(new Gt02Protocol());
verifyAttributes(decoder, binary(
+ "6868150000035889905895258400831c07415045584f4b210d0a"));
+
+ verifyAttributes(decoder, binary(
+ "68682d0000035889905895258400951c1f415045584572726f723a20506172616d65746572203120284f4e2f4f4646290d0a"));
+
+ verifyAttributes(decoder, binary(
"68680f0504035889905831401700df1a00000d0a"));
verifyAttributes(decoder, binary(
diff --git a/test/org/traccar/protocol/L100FrameDecoderTest.java b/test/org/traccar/protocol/L100FrameDecoderTest.java
new file mode 100644
index 000000000..f474fa678
--- /dev/null
+++ b/test/org/traccar/protocol/L100FrameDecoderTest.java
@@ -0,0 +1,24 @@
+package org.traccar.protocol;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class L100FrameDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ L100FrameDecoder decoder = new L100FrameDecoder();
+
+ Assert.assertEquals(
+ binary("200141544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735242c2330313130303131313030313031302c4e2e432c4e2e432c4e2e432c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c027a"),
+ decoder.decode(null, null, binary("200141544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735242c2330313130303131313030313031302c4e2e432c4e2e432c4e2e432c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c027a")));
+
+ Assert.assertEquals(
+ binary("200341544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735244c4f432c436f6e6e61756768742043697263757320c2a0436f6e6e617567687420506c61636520c2a04e65772044656c686920c2a044656c6869c2a0496e6469612c2330313130303130313130313031302c322e332c33352e36372c38302c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c047a"),
+ decoder.decode(null, null, binary("200341544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735244c4f432c436f6e6e61756768742043697263757320c2a0436f6e6e617567687420506c61636520c2a04e65772044656c686920c2a044656c6869c2a0496e6469612c2330313130303130313130313031302c322e332c33352e36372c38302c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c047a")));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/L100ProtocolDecoderTest.java b/test/org/traccar/protocol/L100ProtocolDecoderTest.java
new file mode 100644
index 000000000..07e72140d
--- /dev/null
+++ b/test/org/traccar/protocol/L100ProtocolDecoderTest.java
@@ -0,0 +1,18 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class L100ProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ L100ProtocolDecoder decoder = new L100ProtocolDecoder(new L100Protocol());
+
+ verifyPosition(decoder, binary(
+ "200141544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a37352c2330313130303131313030313031302c4e2e432c4e2e432c4e2e432c31323334352e36372c33312e342c342e322c32312c3130302c3030302c3030303030312c303030303041544c027a"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
index bd54a4ade..b15d7894e 100644
--- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
@@ -23,7 +23,7 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest {
"(088047194605BZ00,510,010,36e6,932c,43,36e6,766b,36,36e6,7668,32"));
verifyAttributes(decoder, text(
- "(013632651491,ZC20,040613,040137,6,42,112,0"));
+ "(013632651491,ZC20,040613,040137,6,421,112,0"));
verifyAttributes(decoder, text(
"(864768010159785,ZC20,291015,030413,3,362,65535,255"));
diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
index 89e9a7e77..a8f7b12bc 100644
--- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
@@ -11,6 +11,10 @@ public class WatchProtocolDecoderTest extends ProtocolTest {
WatchProtocolDecoder decoder = new WatchProtocolDecoder(new WatchProtocol());
verifyPosition(decoder, text(
+ "[3G*6105117105*008D*UD2,210716,231601,V,-33.480366,N,-70.7630692,E,0.00,0.0,0.0,0,100,34,0,0,00000000,3,255,730,2,29731,54315,167,29731,54316,162,29731,54317,145"),
+ position("2016-07-21 23:16:01.000", false, -33.48037, -70.76307));
+
+ verifyPosition(decoder, text(
"[3G*4700222306*0077*UD,120316,140610,V,48.779045,N, 9.1574736,E,0.00,0.0,0.0,0,25,83,0,0,00000000,2,255,262,1,21041,9067,121,21041,5981,116"));
verifyPosition(decoder, text(