use of org.traccar.NetworkMessage in project traccar by tananaev.
the class TeltonikaProtocolDecoder method sendImageRequest.
private void sendImageRequest(Channel channel, SocketAddress remoteAddress, long id, int offset, int size) {
if (channel != null) {
ByteBuf response = Unpooled.buffer();
response.writeInt(0);
response.writeShort(0);
// length
response.writeShort(19);
response.writeByte(CODEC_12);
// nod
response.writeByte(1);
// camera
response.writeByte(0x0D);
// payload length
response.writeInt(11);
// command
response.writeByte(2);
response.writeInt((int) id);
response.writeInt(offset);
response.writeShort(size);
// nod
response.writeByte(1);
response.writeShort(0);
response.writeShort(Checksum.crc16(Checksum.CRC16_IBM, response.nioBuffer(8, response.readableBytes() - 10)));
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class TeltonikaProtocolDecoder method parseData.
private List<Position> parseData(Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) {
List<Position> positions = new LinkedList<>();
if (!connectionless) {
// data length
buf.readUnsignedInt();
}
int codec = buf.readUnsignedByte();
int count = buf.readUnsignedByte();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
if (codec == CODEC_13) {
// type
buf.readUnsignedByte();
int length = buf.readInt() - 4;
getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
if (isPrintable(buf, length)) {
position.set(Position.KEY_RESULT, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString().trim());
} else {
position.set(Position.KEY_RESULT, ByteBufUtil.hexDump(buf.readSlice(length)));
}
} else if (codec == CODEC_12) {
decodeSerial(channel, remoteAddress, position, buf);
} else {
decodeLocation(position, buf, codec);
}
if (!position.getOutdated() || !position.getAttributes().isEmpty()) {
positions.add(position);
}
}
if (channel != null && codec != CODEC_12 && codec != CODEC_13) {
ByteBuf response = Unpooled.buffer();
if (connectionless) {
response.writeShort(5);
response.writeShort(0);
response.writeByte(0x01);
response.writeByte(locationPacketId);
response.writeByte(count);
} else {
response.writeInt(count);
}
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
return positions.isEmpty() ? null : positions;
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class Tk102ProtocolDecoder method sendResponse.
private void sendResponse(Channel channel, int type, ByteBuf dataSequence, ByteBuf content) {
if (channel != null) {
ByteBuf response = Unpooled.buffer();
response.writeByte('[');
response.writeByte(type);
response.writeBytes(dataSequence);
response.writeByte(content.readableBytes());
response.writeBytes(content);
content.release();
response.writeByte(']');
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class TlvProtocolDecoder method sendResponse.
private void sendResponse(Channel channel, SocketAddress remoteAddress, String type, String... arguments) {
if (channel != null) {
ByteBuf response = Unpooled.buffer();
response.writeCharSequence(type, StandardCharsets.US_ASCII);
for (String argument : arguments) {
response.writeByte(argument.length());
response.writeCharSequence(argument, StandardCharsets.US_ASCII);
}
response.writeByte(0);
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class UlbotechProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) {
if (channel != null) {
ByteBuf response = Unpooled.buffer();
response.writeByte(0xF8);
response.writeByte(DATA_GPS);
response.writeByte(0xFE);
response.writeShort(buf.getShort(response.writerIndex() - 1 - 2));
response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.nioBuffer(1, 4)));
response.writeByte(0xF8);
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
return decodeBinary(channel, remoteAddress, buf);
} else {
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(Unpooled.copiedBuffer(String.format("*TS01,ACK:%04X#", Checksum.crc16(Checksum.CRC16_XMODEM, buf.nioBuffer(1, buf.writerIndex() - 2))), StandardCharsets.US_ASCII), remoteAddress));
}
return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII));
}
}
Aggregations