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;
}
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();
}
}
}
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));
}
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"));
}
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));
}
Aggregations