Skip to content

Commit

Permalink
fixed 8bit voice message
Browse files Browse the repository at this point in the history
  • Loading branch information
flocsy committed Feb 12, 2019
1 parent c37ebc1 commit c1de08d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/org/traccar/protocol/WatchProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import io.netty.handler.codec.string.StringEncoder;

import java.nio.charset.StandardCharsets;

public class WatchProtocol extends BaseProtocol {

public WatchProtocol() {
Expand All @@ -45,7 +47,7 @@ public WatchProtocol() {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast(new WatchFrameDecoder());
pipeline.addLast(new StringEncoder());
pipeline.addLast(new StringEncoder(StandardCharsets.ISO_8859_1));
pipeline.addLast(new WatchProtocolEncoder());
pipeline.addLast(new WatchProtocolDecoder(WatchProtocol.this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/traccar/protocol/WatchProtocolEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private String getBinaryData(Command command) {
index += 1;
}

return new String(encodedData, StandardCharsets.US_ASCII);
return new String(encodedData, StandardCharsets.ISO_8859_1);
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions test/org/traccar/protocol/WatchProtocolEncoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.traccar.ProtocolTest;
import org.traccar.model.Command;

import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;

public class WatchProtocolEncoderTest extends ProtocolTest {
Expand Down Expand Up @@ -39,6 +41,18 @@ public void testEncode() throws Exception {
command.set(Command.KEY_DATA, "2321414d520a2573");
assertEquals("[CS*123456789012345*000b*TK,#!AMR\n%s]", encoder.encodeCommand(null, command));

command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_VOICE_MESSAGE);
command.set(Command.KEY_DATA, "ff");
assertEquals("[CS*123456789012345*0004*TK," + binary("ff").toString(StandardCharsets.ISO_8859_1) + ']', encoder.encodeCommand(null, command));

command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_VOICE_MESSAGE);
command.set(Command.KEY_DATA, "7d5b5d2c2a");
assertEquals("[CS*123456789012345*000d*TK," + binary("7d017d027d037d047d05").toString(StandardCharsets.ISO_8859_1) + ']', encoder.encodeCommand(null, command));

command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_MESSAGE);
Expand Down

0 comments on commit c1de08d

Please sign in to comment.