aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/NDTPv6ProtocolEncoder.java
blob: af0dd58f9e4a3359b7aaa7f657dc12eb3110338e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * 2020 - NDTP v6 Protocol Encoder
 */
package org.traccar.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
import org.traccar.BaseProtocolEncoder;
import org.traccar.Protocol;
import org.traccar.model.Command;

public class NDTPv6ProtocolEncoder extends BaseProtocolEncoder {

  public NDTPv6ProtocolEncoder(Protocol protocol) {
    super(protocol);
  }

  private ByteBuf encodeCommand(String commandString) {
    ByteBuf buffer = Unpooled.buffer();
    buffer.writeBytes(commandString.getBytes(StandardCharsets.US_ASCII));
    return buffer;
  }

  @Override
  protected Object encodeCommand(Command command) {
    switch (command.getType()) {
      case Command.TYPE_IDENTIFICATION:
        return encodeCommand("BB+IDNT");
      case Command.TYPE_REBOOT_DEVICE:
        return encodeCommand("BB+RESET");
      case Command.TYPE_POSITION_SINGLE:
        return encodeCommand("BB+RRCD");
      default:
        return null;
    }
  }
}