use of org.traccar.NetworkMessage in project traccar by tananaev.
the class OmnicommProtocolDecoder method sendResponse.
private void sendResponse(Channel channel, int type, long index) {
if (channel != null) {
ByteBuf response = Unpooled.buffer();
response.writeByte(0xC0);
response.writeByte(type);
response.writeShortLE(4);
response.writeIntLE((int) index);
response.writeShortLE(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, response.nioBuffer(1, response.writerIndex() - 1)));
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class OrionProtocolDecoder method sendResponse.
private static void sendResponse(Channel channel, ByteBuf buf) {
if (channel != null) {
ByteBuf response = Unpooled.buffer(4);
response.writeByte('*');
response.writeShort(buf.getUnsignedShort(buf.writerIndex() - 2));
response.writeByte(buf.getUnsignedByte(buf.writerIndex() - 3));
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class Minifinder2ProtocolDecoder method sendResponse.
private void sendResponse(Channel channel, SocketAddress remoteAddress, int index, int type, ByteBuf buf) {
if (channel != null) {
ByteBuf body = Unpooled.buffer();
if (type == MSG_SERVICES) {
while (buf.isReadable()) {
int endIndex = buf.readUnsignedByte() + buf.readerIndex();
int key = buf.readUnsignedByte();
switch(key) {
case 0x11:
case 0x21:
case 0x22:
// length
body.writeByte(9 + 1);
body.writeByte(key);
// latitude
body.writeIntLE(0);
// longitude
body.writeIntLE(0);
// address
body.writeByte(0);
break;
case 0x12:
// length
body.writeByte(5);
body.writeByte(key);
body.writeIntLE((int) (System.currentTimeMillis() / 1000));
break;
default:
break;
}
buf.readerIndex(endIndex);
}
} else {
// key length
body.writeByte(1);
// success
body.writeByte(0);
}
ByteBuf content = Unpooled.buffer();
content.writeByte(type == MSG_SERVICES ? type : MSG_RESPONSE);
content.writeBytes(body);
body.release();
ByteBuf response = Unpooled.buffer();
// header
response.writeByte(0xAB);
// properties
response.writeByte(0x00);
response.writeShortLE(content.readableBytes());
response.writeShortLE(Checksum.crc16(Checksum.CRC16_XMODEM, content.nioBuffer()));
response.writeShortLE(index);
response.writeBytes(content);
content.release();
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class MxtProtocolDecoder method sendResponse.
private static void sendResponse(Channel channel, int device, long id, int crc) {
if (channel != null) {
ByteBuf response = Unpooled.buffer();
response.writeByte(device);
response.writeByte(MSG_ACK);
response.writeIntLE((int) id);
response.writeShortLE(crc);
response.writeShortLE(Checksum.crc16(Checksum.CRC16_XMODEM, response.nioBuffer()));
ByteBuf encoded = Unpooled.buffer();
// header
encoded.writeByte(0x01);
while (response.isReadable()) {
int b = response.readByte();
if (b == 0x01 || b == 0x04 || b == 0x10 || b == 0x11 || b == 0x13) {
encoded.writeByte(0x10);
b += 0x20;
}
encoded.writeByte(b);
}
response.release();
// ending
encoded.writeByte(0x04);
channel.writeAndFlush(new NetworkMessage(encoded, channel.remoteAddress()));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class NeosProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
if (channel != null) {
channel.writeAndFlush(new NetworkMessage("$OK!", remoteAddress));
}
Parser parser = new Parser(PATTERN, (String) msg);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(parser.nextInt() > 0);
position.setTime(parser.nextDateTime());
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setSpeed(parser.nextInt());
position.setCourse(parser.nextInt());
position.set(Position.KEY_RSSI, parser.nextInt());
position.set(Position.PREFIX_ADC + 1, parser.nextInt());
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
position.set(Position.KEY_INPUT, parser.nextBinInt());
return position;
}
Aggregations