diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-04-25 12:30:44 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-04-25 12:30:44 +1200 |
commit | 3d9b8bdd2a4df0ef055e3dd064209fc5c3e8401d (patch) | |
tree | 03759d24808581f8234c8d1f62d3d22e75d37499 | |
parent | dceebc4430b3df2f4033b6d9cace29e58d94cefa (diff) | |
download | trackermap-server-3d9b8bdd2a4df0ef055e3dd064209fc5c3e8401d.tar.gz trackermap-server-3d9b8bdd2a4df0ef055e3dd064209fc5c3e8401d.tar.bz2 trackermap-server-3d9b8bdd2a4df0ef055e3dd064209fc5c3e8401d.zip |
Start implementing watch commands
-rw-r--r-- | src/org/traccar/protocol/WatchProtocol.java | 6 | ||||
-rw-r--r-- | src/org/traccar/protocol/WatchProtocolEncoder.java | 38 | ||||
-rw-r--r-- | test/org/traccar/protocol/WatchProtocolEncoderTest.java | 24 |
3 files changed, 67 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java index 1198f689e..05308a7e2 100644 --- a/src/org/traccar/protocol/WatchProtocol.java +++ b/src/org/traccar/protocol/WatchProtocol.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. @@ -22,6 +22,7 @@ import org.jboss.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; import org.traccar.CharacterDelimiterFrameDecoder; import org.traccar.TrackerServer; +import org.traccar.model.Command; import java.util.List; @@ -29,6 +30,8 @@ public class WatchProtocol extends BaseProtocol { public WatchProtocol() { super("watch"); + setSupportedCommands( + Command.TYPE_REBOOT_DEVICE); } @Override @@ -39,6 +42,7 @@ public class WatchProtocol extends BaseProtocol { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ']')); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectEncoder", new WatchProtocolEncoder()); pipeline.addLast("objectDecoder", new WatchProtocolDecoder(WatchProtocol.this)); } }); diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java new file mode 100644 index 000000000..f93cb7568 --- /dev/null +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -0,0 +1,38 @@ +/* + * 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.traccar.StringProtocolEncoder; +import org.traccar.helper.Log; +import org.traccar.model.Command; + +public class WatchProtocolEncoder extends StringProtocolEncoder { + + @Override + protected Object encodeCommand(Command command) { + + switch (command.getType()) { + case Command.TYPE_REBOOT_DEVICE: + return formatCommand(command, "[CS*{%s}*0005*RESET]", Command.KEY_UNIQUE_ID); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; + } + + return null; + } + +} diff --git a/test/org/traccar/protocol/WatchProtocolEncoderTest.java b/test/org/traccar/protocol/WatchProtocolEncoderTest.java new file mode 100644 index 000000000..c7cf584c4 --- /dev/null +++ b/test/org/traccar/protocol/WatchProtocolEncoderTest.java @@ -0,0 +1,24 @@ +package org.traccar.protocol; + +import org.junit.Assert; +import org.junit.Test; +import org.traccar.ProtocolTest; +import org.traccar.model.Command; + +public class WatchProtocolEncoderTest extends ProtocolTest { + + @Test + public void testEncode() throws Exception { + + WatchProtocolEncoder encoder = new WatchProtocolEncoder(); + + Command command = new Command(); + command.setDeviceId(1); + command.setType(Command.TYPE_POSITION_PERIODIC); + command.set(Command.KEY_FREQUENCY, 300); + + Assert.assertEquals("**,imei:123456789012345,C,05m", encoder.encodeCommand(command)); + + } + +} |