aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-04-19 22:04:19 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-04-19 22:04:19 -0700
commitd1d3be228d270355c9d48ede69a6e3570d3710b7 (patch)
tree62b36176047fe17f6dd845e531a1575f30b44a3b /src/main
parentd45729113d11116d1645d26e7606560aecbb8b11 (diff)
downloadtraccar-server-d1d3be228d270355c9d48ede69a6e3570d3710b7.tar.gz
traccar-server-d1d3be228d270355c9d48ede69a6e3570d3710b7.tar.bz2
traccar-server-d1d3be228d270355c9d48ede69a6e3570d3710b7.zip
Implement iStartek commands
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/protocol/StartekProtocol.java6
-rw-r--r--src/main/java/org/traccar/protocol/StartekProtocolEncoder.java54
2 files changed, 60 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/protocol/StartekProtocol.java b/src/main/java/org/traccar/protocol/StartekProtocol.java
index e22973243..230dc3118 100644
--- a/src/main/java/org/traccar/protocol/StartekProtocol.java
+++ b/src/main/java/org/traccar/protocol/StartekProtocol.java
@@ -21,16 +21,22 @@ import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
+import org.traccar.model.Command;
public class StartekProtocol extends BaseProtocol {
public StartekProtocol() {
+ setSupportedDataCommands(
+ Command.TYPE_OUTPUT_CONTROL,
+ Command.TYPE_ENGINE_STOP,
+ Command.TYPE_ENGINE_RESUME);
addServer(new TrackerServer(false, getName()) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast(new LineBasedFrameDecoder(1024));
pipeline.addLast(new StringEncoder());
pipeline.addLast(new StringDecoder());
+ pipeline.addLast(new StartekProtocolEncoder(StartekProtocol.this));
pipeline.addLast(new StartekProtocolDecoder(StartekProtocol.this));
}
});
diff --git a/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java b/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
new file mode 100644
index 000000000..a96502f11
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2021 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 io.netty.channel.Channel;
+import org.traccar.Protocol;
+import org.traccar.StringProtocolEncoder;
+import org.traccar.helper.Checksum;
+import org.traccar.model.Command;
+
+public class StartekProtocolEncoder extends StringProtocolEncoder {
+
+ public StartekProtocolEncoder(Protocol protocol) {
+ super(protocol);
+ }
+
+ @Override
+ protected String formatCommand(Command command, String format, String... keys) {
+ String uniqueId = getUniqueId(command.getDeviceId());
+ String payload = super.formatCommand(command, format, keys);
+ int length = uniqueId.length() + 1 + payload.length();
+ String sentence = "$$:" + length + "," + uniqueId + "," + payload;
+ return sentence + Checksum.sum(sentence) + "\r\n";
+ }
+
+ @Override
+ protected Object encodeCommand(Channel channel, Command command) {
+
+ switch (command.getType()) {
+ case Command.TYPE_OUTPUT_CONTROL:
+ return formatCommand(command, "900,%s,%s", Command.KEY_INDEX, Command.KEY_DATA);
+ case Command.TYPE_ENGINE_STOP:
+ return formatCommand(command, "900,1,1");
+ case Command.TYPE_ENGINE_RESUME:
+ return formatCommand(command, "900,1,0");
+ default:
+ return null;
+ }
+ }
+
+}