aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-07-29 11:29:39 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-07-29 11:29:39 +1200
commit41f88170ba9c47a20a0dda9cb42a2fa151c57ade (patch)
tree60e398c2ed865243b34c922fbb81acb559455a01 /src/org
parent0de1d3e5ba4527bdef27b4e90f528300f5197c3e (diff)
parent44e0e42989bfba7159625b10a9b0e5023f6f6420 (diff)
downloadtraccar-server-41f88170ba9c47a20a0dda9cb42a2fa151c57ade.tar.gz
traccar-server-41f88170ba9c47a20a0dda9cb42a2fa151c57ade.tar.bz2
traccar-server-41f88170ba9c47a20a0dda9cb42a2fa151c57ade.zip
Merge pull request #1317 from al3x1s/master
Implement Totem commands support
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/model/Command.java6
-rw-r--r--src/org/traccar/protocol/TotemFrameDecoder.java18
-rw-r--r--src/org/traccar/protocol/TotemProtocol.java8
-rw-r--r--src/org/traccar/protocol/TotemProtocolEncoder.java40
4 files changed, 63 insertions, 9 deletions
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
index f7702dbd0..8c4e3f0f1 100644
--- a/src/org/traccar/model/Command.java
+++ b/src/org/traccar/model/Command.java
@@ -25,9 +25,11 @@ public class Command implements Factory {
public static final String TYPE_POSITION_STOP = "positionStop";
public static final String TYPE_POSITION_FIX = "positionFix";
public static final String TYPE_ENGINE_STOP = "engineStop";
- public static final String TYPE_ENGINE_RESUME = "engineResume";
-
+ public static final String TYPE_ENGINE_RESUME = "engineResume";
+
public static final String KEY_UNIQUE_ID = "uniqueId";
public static final String KEY_FREQUENCY = "frequency";
+ public static final String KEY_GPS_PASSWORD = "gpsPassword";
+
}
diff --git a/src/org/traccar/protocol/TotemFrameDecoder.java b/src/org/traccar/protocol/TotemFrameDecoder.java
index 5ac3064e6..6f7c3a37c 100644
--- a/src/org/traccar/protocol/TotemFrameDecoder.java
+++ b/src/org/traccar/protocol/TotemFrameDecoder.java
@@ -19,7 +19,7 @@ import java.nio.charset.Charset;
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;
+import org.jboss.netty.handler.codec.frame.FrameDecoder;
public class TotemFrameDecoder extends FrameDecoder {
@@ -38,13 +38,17 @@ public class TotemFrameDecoder extends FrameDecoder {
if (buf.getUnsignedShort(buf.readerIndex()) == 0x0d0a) {
buf.skipBytes(2);
}
-
- // Read message
- int length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, Charset.defaultCharset()), 16);
- if (length <= buf.readableBytes()) {
- return buf.readBytes(length);
+
+ if(buf.toString(buf.readerIndex(), 2, Charset.defaultCharset()).equals("$$")){
+ int length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, Charset.defaultCharset()), 16);
+ if (length <= buf.readableBytes()) {
+ return buf.readBytes(length);
+ }
+ }else{
+ //TODO: notify to user the GPS response
+ return buf.readBytes(buf.readableBytes());
}
-
+
return null;
}
diff --git a/src/org/traccar/protocol/TotemProtocol.java b/src/org/traccar/protocol/TotemProtocol.java
index cbc35a664..097f6a593 100644
--- a/src/org/traccar/protocol/TotemProtocol.java
+++ b/src/org/traccar/protocol/TotemProtocol.java
@@ -22,11 +22,17 @@ import org.traccar.BaseProtocol;
import org.traccar.TrackerServer;
import java.util.List;
+import org.jboss.netty.handler.codec.string.StringEncoder;
+import org.traccar.model.Command;
public class TotemProtocol extends BaseProtocol {
public TotemProtocol() {
super("totem");
+ setSupportedCommands(
+ Command.TYPE_ENGINE_RESUME,
+ Command.TYPE_ENGINE_STOP
+ );
}
@Override
@@ -36,7 +42,9 @@ public class TotemProtocol extends BaseProtocol {
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new TotemFrameDecoder());
pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("objectDecoder", new TotemProtocolDecoder(TotemProtocol.this));
+ pipeline.addLast("objectEncoder", new TotemProtocolEncoder());
}
});
}
diff --git a/src/org/traccar/protocol/TotemProtocolEncoder.java b/src/org/traccar/protocol/TotemProtocolEncoder.java
new file mode 100644
index 000000000..d236a7e2c
--- /dev/null
+++ b/src/org/traccar/protocol/TotemProtocolEncoder.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2015 alexis.
+ *
+ * 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.traccar.StringProtocolEncoder;
+import org.traccar.model.Command;
+
+/**
+ *
+ * @author Irving Gonzalez [ialexis93@gmail.com]
+ */
+public class TotemProtocolEncoder extends StringProtocolEncoder{
+
+ @Override
+ protected Object encodeCommand(Command command) {
+
+ switch (command.getType()) {
+ //Assuming PIN 8 (Output C) is the power wire, like manual says but it can be PIN 5,7,8
+ case Command.TYPE_ENGINE_STOP:
+ return formatCommand(command, "*{%s},025,C,1#", Command.KEY_GPS_PASSWORD);
+ case Command.TYPE_ENGINE_RESUME:
+ return formatCommand(command, "*{%s},025,C,0#", Command.KEY_GPS_PASSWORD);
+ }
+
+ return null;
+ }
+}