use of org.traccar.BaseProtocol in project traccar by tananaev.
the class CommandsManager method getCommandTypes.
public Collection<Typed> getCommandTypes(long deviceId, boolean textChannel) {
List<Typed> result = new ArrayList<>();
Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId);
if (lastPosition != null) {
BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol());
Collection<String> commands;
commands = textChannel ? protocol.getSupportedTextCommands() : protocol.getSupportedDataCommands();
for (String commandKey : commands) {
result.add(new Typed(commandKey));
}
} else {
result.add(new Typed(Command.TYPE_CUSTOM));
}
return result;
}
use of org.traccar.BaseProtocol 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;
}
use of org.traccar.BaseProtocol in project traccar by tananaev.
the class CommandsManager method sendCommand.
public boolean sendCommand(Command command) throws Exception {
long deviceId = command.getDeviceId();
if (command.getId() != 0) {
command = getById(command.getId()).clone();
command.setDeviceId(deviceId);
}
if (command.getTextChannel()) {
Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId);
String phone = Context.getIdentityManager().getById(deviceId).getPhone();
if (lastPosition != null) {
BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol());
protocol.sendTextCommand(phone, command);
} else if (command.getType().equals(Command.TYPE_CUSTOM)) {
if (Context.getSmppManager() != null) {
Context.getSmppManager().sendMessageSync(phone, command.getString(Command.KEY_DATA), true);
} else {
throw new RuntimeException("SMPP client is not enabled");
}
} else {
throw new RuntimeException("Command " + command.getType() + " is not supported");
}
} else {
ActiveDevice activeDevice = Context.getConnectionManager().getActiveDevice(deviceId);
if (activeDevice != null) {
activeDevice.sendCommand(command);
} else {
getDeviceQueue(deviceId).add(command);
return false;
}
}
return true;
}
Aggregations