Skip to content

Commit

Permalink
Handle binary custom commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 3, 2019
1 parent 8a918e1 commit a379356
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.helper.Checksum;
import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
import org.traccar.Protocol;

Expand Down Expand Up @@ -49,8 +50,14 @@ protected Object encodeCommand(Command command) {

switch (command.getType()) {
case Command.TYPE_CUSTOM:
content.writeBytes(command.getString(Command.KEY_DATA).getBytes(StandardCharsets.US_ASCII));
return encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content);
String data = command.getString(Command.KEY_DATA);
if (data.matches("(\\p{XDigit}{2})+")) {
content.writeBytes(DataConverter.parseHex(data));
return content;
} else {
content.writeBytes(data.getBytes(StandardCharsets.US_ASCII));
return encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content);
}
case Command.TYPE_REQUEST_PHOTO:
content.writeByte(1); // sub-command
content.writeByte(0); // source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ public void testEncode() throws Exception {
Command command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, " Setio 2,1");

command.set(Command.KEY_DATA, " Setio 2,1");
verifyCommand(encoder, command, binary("000b6c20536574696F20322C31eb3e"));

command.set(Command.KEY_DATA, "000b890100000000007fffffff89f0");
verifyCommand(encoder, command, binary("000b890100000000007fffffff89f0"));

}

}

0 comments on commit a379356

Please sign in to comment.