Search in sources :

Example 76 with Command

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

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 77 with Command

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

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 78 with Command

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

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 79 with Command

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

the class CellocatorProtocolEncoderTest method testEncode.

@Ignore
@Test
public void testEncode() throws Exception {
    CellocatorProtocolEncoder encoder = new CellocatorProtocolEncoder();
    Command command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_OUTPUT_CONTROL);
    command.set(Command.KEY_INDEX, 0);
    command.set(Command.KEY_DATA, "1");
    verifyCommand(encoder, command, binary("4D434750000000000000000000000303101000000000000026"));
}
Also used : Command(org.traccar.model.Command) Ignore(org.junit.Ignore) ProtocolTest(org.traccar.ProtocolTest) Test(org.junit.Test)

Example 80 with Command

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

the class Tk103ProtocolEncoderTest method testEncodePositionPeriodicAlternative.

@Test
public void testEncodePositionPeriodicAlternative() throws Exception {
    Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(true);
    Command command = new Command();
    command.setDeviceId(1);
    command.setType(Command.TYPE_POSITION_PERIODIC);
    assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(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