diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-07-07 00:11:19 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-07 00:11:19 +1200 |
commit | 81cac93e54e336b78c80e3a099b72d6bb8f3e1b4 (patch) | |
tree | 39e2e1730d8711c7512b4e870fcd380e1b62a822 /src/org/traccar/protocol/GranitProtocolEncoder.java | |
parent | 21a8fb81a0aa88a7bc1cb6804da034ecc9a79bcd (diff) | |
parent | f8f21ce131556ca5c1ea44ede496ace9d810c844 (diff) | |
download | trackermap-server-81cac93e54e336b78c80e3a099b72d6bb8f3e1b4.tar.gz trackermap-server-81cac93e54e336b78c80e3a099b72d6bb8f3e1b4.tar.bz2 trackermap-server-81cac93e54e336b78c80e3a099b72d6bb8f3e1b4.zip |
Merge pull request #2081 from Abyss777/master
Granit protocol implementation
Diffstat (limited to 'src/org/traccar/protocol/GranitProtocolEncoder.java')
-rw-r--r-- | src/org/traccar/protocol/GranitProtocolEncoder.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/org/traccar/protocol/GranitProtocolEncoder.java b/src/org/traccar/protocol/GranitProtocolEncoder.java new file mode 100644 index 000000000..961f183f5 --- /dev/null +++ b/src/org/traccar/protocol/GranitProtocolEncoder.java @@ -0,0 +1,55 @@ +/* + * 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 java.nio.charset.StandardCharsets; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.traccar.BaseProtocolEncoder; +import org.traccar.helper.Log; +import org.traccar.model.Command; + +public class GranitProtocolEncoder extends BaseProtocolEncoder { + @Override + protected Object encodeCommand(Command command) { + + String commandString = ""; + + switch (command.getType()) { + case Command.TYPE_IDENTIFICATION: + commandString = "BB+IDNT"; + break; + case Command.TYPE_REBOOT_DEVICE: + commandString = "BB+RESET"; + break; + case Command.TYPE_POSITION_SINGLE: + commandString = "BB+RRCD"; + break; + default: + Log.warning(new UnsupportedOperationException(command.getType())); + return null; + } + if (!commandString.isEmpty()) { + ChannelBuffer commandBuf = ChannelBuffers.dynamicBuffer(); + commandBuf.writeBytes(commandString.getBytes(StandardCharsets.US_ASCII)); + GranitProtocolDecoder.appendChecksum(commandBuf, commandString.length()); + return commandBuf; + } + return null; + } + +} |