diff options
author | Hans van den Elsen <hans.elsen@esds.nl> | 2016-03-11 22:16:25 +0100 |
---|---|---|
committer | Hans van den Elsen <hans.elsen@esds.nl> | 2016-03-11 22:16:25 +0100 |
commit | 4606737cc07b736f9c8f98ae680b928c94c082c8 (patch) | |
tree | bdd29b24a16403b1e8a3d7cd4325391063b34b8a /src/org/traccar/protocol/MeitrackProtocolEncoder.java | |
parent | 3ced99384b1967f5cde9abdf30c1c0184a5ae3f6 (diff) | |
parent | ab5d21e16ac44957e04da0f06daf148af95e96be (diff) | |
download | trackermap-server-4606737cc07b736f9c8f98ae680b928c94c082c8.tar.gz trackermap-server-4606737cc07b736f9c8f98ae680b928c94c082c8.tar.bz2 trackermap-server-4606737cc07b736f9c8f98ae680b928c94c082c8.zip |
Merge remote-tracking branch 'refs/remotes/tananaev/master'
Diffstat (limited to 'src/org/traccar/protocol/MeitrackProtocolEncoder.java')
-rw-r--r-- | src/org/traccar/protocol/MeitrackProtocolEncoder.java | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java index bfda2b7d2..381935c58 100644 --- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.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. @@ -16,23 +16,36 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; +import org.traccar.helper.Checksum; import org.traccar.helper.Log; import org.traccar.model.Command; public class MeitrackProtocolEncoder extends StringProtocolEncoder { + private Object formatCommand(Command command, char dataId, String content) { + String uniqueId = getUniqueId(command.getDeviceId()); + int length = 1 + uniqueId.length() + 1 + content.length() + 5; + String result = String.format("@@%c%02d,%s,%s*", dataId, length, uniqueId, content); + result += Checksum.sum(result) + "\r\n"; + return result; + } + @Override protected Object encodeCommand(Command command) { switch (command.getType()) { + case Command.TYPE_POSITION_SINGLE: + return formatCommand(command, 'Q', "A10"); case Command.TYPE_ENGINE_STOP: - return formatCommand(command, "@@M33,{%s},C01,0,12222*18\r\n", Command.KEY_UNIQUE_ID); + return formatCommand(command, 'M', "C01,0,12222"); case Command.TYPE_ENGINE_RESUME: - return formatCommand(command, "@@M33,{%s},C01,0,02222*18\r\n", Command.KEY_UNIQUE_ID); + return formatCommand(command, 'M', "C01,0,02222"); case Command.TYPE_ALARM_ARM: - return formatCommand(command, "@@M33,{%s},C01,0,22122*18\r\n", Command.KEY_UNIQUE_ID); + return formatCommand(command, 'M', "C01,0,22122"); case Command.TYPE_ALARM_DISARM: - return formatCommand(command, "@@M33,{%s},C01,0,22022*18\r\n", Command.KEY_UNIQUE_ID); + return formatCommand(command, 'M', "C01,0,22022"); + case Command.TYPE_REQUEST_PHOTO: + return formatCommand(command, 'D', "D03,1,camera_picture.jpg"); default: Log.warning(new UnsupportedOperationException(command.getType())); break; |