aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--setup/unix/traccar.xml4
-rw-r--r--src/org/traccar/BaseProtocol.java5
-rw-r--r--src/org/traccar/ServerManager.java26
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java13
-rw-r--r--src/org/traccar/database/DataManager.java7
-rw-r--r--src/org/traccar/model/SupportedCommand.java39
-rw-r--r--web/app/Application.js5
-rw-r--r--web/app/model/SupportedCommand.js28
-rw-r--r--web/app/store/SupportedCommands.js (renamed from web/app/store/CommandTypes.js)31
-rw-r--r--web/app/view/CommandDialog.js2
-rw-r--r--web/app/view/DevicesController.js7
11 files changed, 141 insertions, 26 deletions
diff --git a/setup/unix/traccar.xml b/setup/unix/traccar.xml
index 2ddf6551f..8dfcf6386 100644
--- a/setup/unix/traccar.xml
+++ b/setup/unix/traccar.xml
@@ -152,6 +152,10 @@
SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime;
</entry>
+ <entry key='database.selectLatestPosition'>
+ SELECT TOP 1 * FROM positions WHERE deviceId = :deviceId AND protocol IS NOT NULL;
+ </entry>
+
<entry key='database.insertPosition'>
INSERT INTO positions (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes)
VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes);
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index 3af39a07c..58ca837ce 100644
--- a/src/org/traccar/BaseProtocol.java
+++ b/src/org/traccar/BaseProtocol.java
@@ -16,6 +16,7 @@
package org.traccar;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.traccar.database.ActiveDevice;
@@ -39,6 +40,10 @@ public abstract class BaseProtocol implements Protocol {
supportedCommands.addAll(Arrays.asList(commands));
}
+ public Collection<String> getSupportedCommands() {
+ return supportedCommands;
+ }
+
@Override
public void sendCommand(ActiveDevice activeDevice, Command command) {
if (!supportedCommands.contains(command.getType())) {
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index cd6a071db..dae693080 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -15,19 +15,20 @@
*/
package org.traccar;
+import org.traccar.model.SupportedCommand;
+
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class ServerManager {
+ private final Map<String, BaseProtocol> protocols = new HashMap<>();
private final List<TrackerServer> serverList = new LinkedList<>();
public ServerManager() throws Exception {
@@ -62,7 +63,9 @@ public class ServerManager {
for (String name : names) {
Class protocolClass = Class.forName(packageName + '.' + name);
if (BaseProtocol.class.isAssignableFrom(protocolClass)) {
- initProtocolServer((BaseProtocol) protocolClass.newInstance());
+ BaseProtocol baseProtocol = (BaseProtocol) protocolClass.newInstance();
+ protocols.put(baseProtocol.getName(), baseProtocol);
+ initProtocolServer(baseProtocol);
}
}
}
@@ -89,4 +92,19 @@ public class ServerManager {
}
}
+ public Collection<SupportedCommand> getProtocolSuppportedCommands(String protocol) {
+ ArrayList<SupportedCommand> result = new ArrayList<>();
+
+ if (protocol != null) {
+ BaseProtocol baseProtocol = protocols.get(protocol);
+ for (String commandKey : baseProtocol.getSupportedCommands()) {
+ SupportedCommand supportedCommand = new SupportedCommand();
+ supportedCommand.setKey(commandKey);
+ supportedCommand.setName(commandKey);
+ result.add(supportedCommand);
+ }
+ }
+
+ return result;
+ }
}
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index a4bfc1030..90d3ef675 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -19,6 +19,7 @@ import org.traccar.Context;
import org.traccar.api.BaseResource;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -31,7 +32,12 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+
+import org.traccar.helper.Log;
+import org.traccar.model.Command;
import org.traccar.model.Device;
+import org.traccar.model.Position;
+import org.traccar.model.SupportedCommand;
@Path("devices")
@Produces(MediaType.APPLICATION_JSON)
@@ -81,4 +87,11 @@ public class DeviceResource extends BaseResource {
return Response.noContent().build();
}
+ @Path("{id}/supportedcommands")
+ @GET
+ public Collection<SupportedCommand> get(@PathParam("id") long id) throws SQLException {
+ Context.getPermissionsManager().checkDevice(getUserId(), id);
+ Position latestPosition = Context.getDataManager().getLatestPosition(id);
+ return Context.getServerManager().getProtocolSuppportedCommands(latestPosition.getProtocol());
+ }
}
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index eb0be9274..3dba215f6 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -472,6 +472,12 @@ public class DataManager implements IdentityManager {
.executeQuery(Position.class);
}
+ public Position getLatestPosition(long deviceId) throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectLatestPosition"))
+ .setLong("deviceId", deviceId)
+ .executeQuerySingle(Position.class);
+ }
+
public Server getServer() throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectServers"))
.executeQuerySingle(Server.class);
@@ -482,5 +488,4 @@ public class DataManager implements IdentityManager {
.setObject(server)
.executeUpdate();
}
-
}
diff --git a/src/org/traccar/model/SupportedCommand.java b/src/org/traccar/model/SupportedCommand.java
new file mode 100644
index 000000000..a8f31ab30
--- /dev/null
+++ b/src/org/traccar/model/SupportedCommand.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@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.model;
+
+public class SupportedCommand {
+
+ private String key;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/web/app/Application.js b/web/app/Application.js
index 69ce8f891..da3fdd505 100644
--- a/web/app/Application.js
+++ b/web/app/Application.js
@@ -30,7 +30,8 @@ Ext.define('Traccar.Application', {
'Device',
'Position',
'Attribute',
- 'Command'
+ 'Command',
+ 'SupportedCommand'
],
stores: [
@@ -45,7 +46,7 @@ Ext.define('Traccar.Application', {
'MapTypes',
'DistanceUnits',
'SpeedUnits',
- 'CommandTypes',
+ 'SupportedCommands',
'TimeUnits',
'Languages'
],
diff --git a/web/app/model/SupportedCommand.js b/web/app/model/SupportedCommand.js
new file mode 100644
index 000000000..35c34c8cd
--- /dev/null
+++ b/web/app/model/SupportedCommand.js
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@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.
+ */
+
+Ext.define('Traccar.model.SupportedCommand', {
+ extend: 'Ext.data.Model',
+ identifier: 'negative',
+
+ fields: [{
+ name: 'key',
+ type: 'string'
+ }, {
+ name: 'name',
+ type: 'string'
+ }]
+});
diff --git a/web/app/store/CommandTypes.js b/web/app/store/SupportedCommands.js
index 3f5094266..2b052b902 100644
--- a/web/app/store/CommandTypes.js
+++ b/web/app/store/SupportedCommands.js
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,21 +14,20 @@
* limitations under the License.
*/
-Ext.define('Traccar.store.CommandTypes', {
+Ext.define('Traccar.store.SupportedCommands', {
extend: 'Ext.data.Store',
- fields: ['key', 'name'],
+ model: 'Traccar.model.SupportedCommand',
- data: [{
- key: 'positionPeriodic',
- name: Strings.commandPositionPeriodic
- }, {
- key: 'positionStop',
- name: Strings.commandPositionStop
- }, {
- key: 'engineStop',
- name: Strings.commandEngineStop
- }, {
- key: 'engineResume',
- name: Strings.commandEngineResume
- }]
+ listeners: {
+ 'beforeload' : function(store, options) {
+ var proxy;
+ proxy = store.getProxy();
+ proxy.setUrl('/api/devices/' + proxy.extraParams.deviceId + '/supportedcommands');
+ }
+ },
+
+ proxy: {
+ type: 'rest',
+ url: ''
+ }
});
diff --git a/web/app/view/CommandDialog.js b/web/app/view/CommandDialog.js
index 66cd190ea..e24105699 100644
--- a/web/app/view/CommandDialog.js
+++ b/web/app/view/CommandDialog.js
@@ -30,7 +30,7 @@ Ext.define('Traccar.view.CommandDialog', {
xtype: 'combobox',
name: 'type',
fieldLabel: Strings.commandType,
- store: 'CommandTypes',
+ store: 'SupportedCommands',
displayField: 'name',
valueField: 'key',
listeners: {
diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js
index 10918c13a..9dee0ff7c 100644
--- a/web/app/view/DevicesController.js
+++ b/web/app/view/DevicesController.js
@@ -80,11 +80,14 @@ Ext.define('Traccar.view.DevicesController', {
},
onCommandClick: function () {
- var device, command, dialog;
+ var device, deviceId, command, dialog, comboStore;
device = this.getView().getSelectionModel().getSelection()[0];
+ deviceId = device.get('id');
command = Ext.create('Traccar.model.Command');
- command.set('deviceId', device.get('id'));
+ command.set('deviceId', deviceId);
dialog = Ext.create('Traccar.view.CommandDialog');
+ comboStore = dialog.down('form').down('combobox').getStore();
+ comboStore.getProxy().setExtraParam('deviceId', deviceId);
dialog.down('form').loadRecord(command);
dialog.show();
},