Search in sources :

Example 1 with Command

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

the class CommandsManager method getSupportedCommands.

public Collection<Long> getSupportedCommands(long deviceId) {
    List<Long> result = new ArrayList<>();
    Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId);
    for (long commandId : getAllDeviceItems(deviceId)) {
        Command command = getById(commandId);
        if (lastPosition != null) {
            BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol());
            if (command.getTextChannel() && protocol.getSupportedTextCommands().contains(command.getType()) || !command.getTextChannel() && protocol.getSupportedDataCommands().contains(command.getType())) {
                result.add(commandId);
            }
        } else if (command.getType().equals(Command.TYPE_CUSTOM)) {
            result.add(commandId);
        }
    }
    return result;
}
Also used : Position(org.traccar.model.Position) Command(org.traccar.model.Command) ArrayList(java.util.ArrayList) BaseProtocol(org.traccar.BaseProtocol)

Example 2 with Command

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

the class AdmProtocolEncoderTest method testEncode.

@Test
public void testEncode() throws Exception {
    AdmProtocolEncoder encoder = new AdmProtocolEncoder();
    Command command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_GET_DEVICE_STATUS);
    assertEquals("STATUS\r\n", encoder.encodeCommand(command));
    command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_CUSTOM);
    command.set(Command.KEY_DATA, "INPUT 0");
    assertEquals("INPUT 0\r\n", encoder.encodeCommand(command));
}
Also used : Command(org.traccar.model.Command) ProtocolTest(org.traccar.ProtocolTest) Test(org.junit.Test)

Example 3 with Command

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

the class CastelProtocolEncoderTest method testEncode.

@Test
public void testEncode() throws Exception {
    CastelProtocolEncoder encoder = new CastelProtocolEncoder();
    Command command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_ENGINE_STOP);
    verifyCommand(encoder, command, binary("40402000013132333435363738393031323334350000000000458301a94a0d0a"));
}
Also used : Command(org.traccar.model.Command) ProtocolTest(org.traccar.ProtocolTest) Test(org.junit.Test)

Example 4 with Command

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

the class GalileoProtocolEncoderTest method testEncode.

@Test
public void testEncode() throws Exception {
    GalileoProtocolEncoder encoder = new GalileoProtocolEncoder();
    Command command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_CUSTOM);
    command.set(Command.KEY_DATA, "status");
    verifyCommand(encoder, command, binary("01200003313233343536373839303132333435040000e000000000e1067374617475731f64"));
}
Also used : Command(org.traccar.model.Command) ProtocolTest(org.traccar.ProtocolTest) Test(org.junit.Test)

Example 5 with Command

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

the class Gps103ProtocolEncoderTest method testEncodePositionPeriodic.

@Test
public void testEncodePositionPeriodic() throws Exception {
    Gps103ProtocolEncoder encoder = new Gps103ProtocolEncoder();
    Command command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_POSITION_PERIODIC);
    command.set(Command.KEY_FREQUENCY, 300);
    assertEquals("**,imei:123456789012345,C,05m", encoder.encodeCommand(command));
}
Also used : Command(org.traccar.model.Command) ProtocolTest(org.traccar.ProtocolTest) Test(org.junit.Test)

Aggregations

Command (org.traccar.model.Command)104 Test (org.junit.Test)98 ProtocolTest (org.traccar.ProtocolTest)98 Ignore (org.junit.Ignore)4 ArrayList (java.util.ArrayList)2 BaseProtocol (org.traccar.BaseProtocol)2 Position (org.traccar.model.Position)2