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