aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
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/java/org/traccar/protocol/StartekProtocolEncoder.java
parentd45729113d11116d1645d26e7606560aecbb8b11 (diff)
downloadtrackermap-server-d1d3be228d270355c9d48ede69a6e3570d3710b7.tar.gz
trackermap-server-d1d3be228d270355c9d48ede69a6e3570d3710b7.tar.bz2
trackermap-server-d1d3be228d270355c9d48ede69a6e3570d3710b7.zip
Implement iStartek commands
Diffstat (limited to 'src/main/java/org/traccar/protocol/StartekProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/StartekProtocolEncoder.java54
1 files changed, 54 insertions, 0 deletions
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;
+ }
+ }
+
+}