Search in sources :

Example 71 with Command

use of org.traccar.model.Command in project traccar by tananaev.

the class Tk103ProtocolEncoderTest method testEncodeGetVersionAlternative.

@Test
public void testEncodeGetVersionAlternative() {
    var encoder = new Tk103ProtocolEncoder(null, true);
    Command command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_GET_VERSION);
    assertEquals("[begin]sms2,*about*,[end]", encoder.encodeCommand(command));
}
Also used : Command(org.traccar.model.Command) ProtocolTest(org.traccar.ProtocolTest) Test(org.junit.Test)

Example 72 with Command

use of org.traccar.model.Command in project traccar by tananaev.

the class BaseProtocolEncoder method encode.

@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    if (msg instanceof Command) {
        Command command = (Command) msg;
        Object encodedCommand = encodeCommand(command);
        // Log command
        StringBuilder s = new StringBuilder();
        s.append(String.format("[%08X] ", channel.getId()));
        s.append("id: ").append(getUniqueId(command.getDeviceId())).append(", ");
        s.append("command type: ").append(command.getType()).append(" ");
        if (encodedCommand != null) {
            s.append("sent");
        } else {
            s.append("not sent");
        }
        Log.info(s.toString());
        return encodedCommand;
    }
    return msg;
}
Also used : Command(org.traccar.model.Command)

Example 73 with Command

use of org.traccar.model.Command in project traccar by tananaev.

the class CommandsManager method sendQueuedCommands.

public void sendQueuedCommands(ActiveDevice activeDevice) {
    Queue<Command> deviceQueue = deviceQueues.get(activeDevice.getDeviceId());
    if (deviceQueue != null) {
        Command command = deviceQueue.poll();
        while (command != null) {
            activeDevice.sendCommand(command);
            command = deviceQueue.poll();
        }
    }
}
Also used : Command(org.traccar.model.Command)

Example 74 with Command

use of org.traccar.model.Command in project traccar by traccar.

the class BaseProtocolEncoder method encode.

@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    if (msg instanceof Command) {
        Command command = (Command) msg;
        Object encodedCommand = encodeCommand(channel, command);
        // Log command
        StringBuilder s = new StringBuilder();
        s.append(String.format("[%08X] ", channel.getId()));
        s.append("id: ").append(getUniqueId(command.getDeviceId())).append(", ");
        s.append("command type: ").append(command.getType()).append(" ");
        if (encodedCommand != null) {
            s.append("sent");
        } else {
            s.append("not sent");
        }
        Log.info(s.toString());
        return encodedCommand;
    }
    return msg;
}
Also used : Command(org.traccar.model.Command)

Example 75 with Command

use of org.traccar.model.Command in project traccar by traccar.

the class WatchProtocolEncoderTest method testEncode.

@Test
public void testEncode() throws Exception {
    WatchProtocolEncoder encoder = new WatchProtocolEncoder();
    Command command;
    command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_REBOOT_DEVICE);
    assertEquals("[CS*123456789012345*0005*RESET]", encoder.encodeCommand(null, command));
    command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_SOS_NUMBER);
    command.set(Command.KEY_INDEX, 1);
    command.set(Command.KEY_PHONE, "123456789");
    assertEquals("[CS*123456789012345*000e*SOS1,123456789]", encoder.encodeCommand(null, command));
    command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_VOICE_MESSAGE);
    command.set(Command.KEY_DATA, "3333");
    assertEquals("[CS*123456789012345*0005*TK,33]", encoder.encodeCommand(null, command));
    command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_CUSTOM);
    command.set(Command.KEY_DATA, "WORK,6-9,11-13,13-15,17-19");
    assertEquals("[CS*123456789012345*001a*WORK,6-9,11-13,13-15,17-19]", encoder.encodeCommand(null, command));
    command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_SET_TIMEZONE);
    command.set(Command.KEY_TIMEZONE, "Europe/Amsterdam");
    assertEquals("[CS*123456789012345*0006*LZ,,+1]", encoder.encodeCommand(null, command));
    command.set(Command.KEY_TIMEZONE, "GMT+01:30");
    assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", encoder.encodeCommand(null, command));
    command.set(Command.KEY_TIMEZONE, "Atlantic/Azores");
    assertEquals("[CS*123456789012345*0006*LZ,,-1]", encoder.encodeCommand(null, command));
    command.set(Command.KEY_TIMEZONE, "GMT-11:30");
    assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", encoder.encodeCommand(null, command));
}
Also used : Command(org.traccar.model.Command) ProtocolTest(org.traccar.ProtocolTest) Test(org.junit.Test)

Aggregations

Command (org.traccar.model.Command)129 Test (org.junit.Test)120 ProtocolTest (org.traccar.ProtocolTest)120 Ignore (org.junit.Ignore)4 ArrayList (java.util.ArrayList)3 Position (org.traccar.model.Position)3 BaseProtocol (org.traccar.BaseProtocol)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 DeviceSession (org.traccar.DeviceSession)1 CommandsManager (org.traccar.database.CommandsManager)1 Network (org.traccar.model.Network)1