Java Code Examples for org.jboss.netty.buffer.ChannelBuffers.directBuffer()

The following are Jave code examples for showing how to use directBuffer() of the org.jboss.netty.buffer.ChannelBuffers class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: traccar-service   File: TeltonikaProtocolDecoder.java   Source Code and License Vote up 6 votes
private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {

        int length = buf.readUnsignedShort();
        String imei = buf.toString(buf.readerIndex(), length, StandardCharsets.US_ASCII);
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);

        if (channel != null) {
            ChannelBuffer response = ChannelBuffers.directBuffer(1);
            if (deviceSession != null) {
                response.writeByte(1);
            } else {
                response.writeByte(0);
            }
            channel.write(response);
        }
        return deviceSession;
    }
 
Example 2
Project: traccar-service   File: CellocatorProtocolDecoder.java   Source Code and License Vote up 6 votes
private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) {
    ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 28);
    reply.writeByte('M');
    reply.writeByte('C');
    reply.writeByte('G');
    reply.writeByte('P');
    reply.writeByte(MSG_SERVER_ACKNOWLEDGE);
    reply.writeInt((int) deviceId);
    reply.writeByte(commandCount++);
    reply.writeInt(0); // authentication code
    reply.writeByte(0);
    reply.writeByte(packetNumber);
    reply.writeZero(11);

    byte checksum = 0;
    for (int i = 4; i < 27; i++) {
        checksum += reply.getByte(i);
    }
    reply.writeByte(checksum);

    if (channel != null) {
        channel.write(reply, remoteAddress);
    }
}
 
Example 3
Project: traccar-service   File: CastelProtocolDecoder.java   Source Code and License Vote up 6 votes
private void sendResponse(
        Channel channel, SocketAddress remoteAddress,
        int version, ChannelBuffer id, short type, ChannelBuffer content) {

    if (channel != null) {
        int length = 2 + 2 + 1 + id.readableBytes() + 2 + 2 + 2;
        if (content != null) {
            length += content.readableBytes();
        }

        ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
        response.writeByte('@'); response.writeByte('@');
        response.writeShort(length);
        response.writeByte(version);
        response.writeBytes(id);
        response.writeShort(ChannelBuffers.swapShort(type));
        if (content != null) {
            response.writeBytes(content);
        }
        response.writeShort(
                Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex())));
        response.writeByte(0x0D); response.writeByte(0x0A);
        channel.write(response, remoteAddress);
    }
}
 
Example 4
Project: traccar-service   File: CastelProtocolDecoder.java   Source Code and License Vote up 6 votes
private void sendResponse(
        Channel channel, SocketAddress remoteAddress, ChannelBuffer id, short type) {

    if (channel != null) {
        int length = 2 + 2 + id.readableBytes() + 2 + 4 + 8 + 2 + 2;

        ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
        response.writeByte('@'); response.writeByte('@');
        response.writeShort(length);
        response.writeBytes(id);
        response.writeShort(ChannelBuffers.swapShort(type));
        response.writeInt(0);
        for (int i = 0; i < 8; i++) {
            response.writeByte(0xff);
        }
        response.writeShort(
                Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex())));
        response.writeByte(0x0D); response.writeByte(0x0A);
        channel.write(response, remoteAddress);
    }
}
 
Example 5
Project: traccar-service   File: NavigilProtocolDecoder.java   Source Code and License Vote up 6 votes
private void sendAcknowledgment(Channel channel, int sequenceNumber) {
    ChannelBuffer data = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 4);
    data.writeShort(sequenceNumber);
    data.writeShort(0); // OK

    ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 20);
    header.writeByte(1); header.writeByte(0);
    header.writeShort(senderSequenceNumber++);
    header.writeShort(MSG_ACKNOWLEDGEMENT);
    header.writeShort(header.capacity() + data.capacity());
    header.writeShort(0);
    header.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, data.toByteBuffer()));
    header.writeInt(0);
    header.writeInt((int) (System.currentTimeMillis() / 1000) + LEAP_SECONDS_DELTA);

    if (channel != null) {
        channel.write(ChannelBuffers.copiedBuffer(header, data));
    }
}
 
Example 6
Project: traccar-service   File: BlackKiteProtocolDecoder.java   Source Code and License Vote up 5 votes
private void sendReply(Channel channel, int checksum) {
    ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 3);
    reply.writeByte(0x02);
    reply.writeShort((short) checksum);
    if (channel != null) {
        channel.write(reply);
    }
}
 
Example 7
Project: traccar-service   File: ProgressProtocolDecoder.java   Source Code and License Vote up 5 votes
private void requestArchive(Channel channel) {
    if (lastIndex == 0) {
        lastIndex = newIndex;
    } else if (newIndex > lastIndex) {
        ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 12);
        request.writeShort(MSG_LOG_SYNC);
        request.writeShort(4);
        request.writeInt((int) lastIndex);
        request.writeInt(0);
        channel.write(request);
    }
}
 
Example 8
Project: traccar-service   File: ApelProtocolDecoder.java   Source Code and License Vote up 5 votes
private void sendSimpleMessage(Channel channel, short type) {
    ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 8);
    request.writeShort(type);
    request.writeShort(0);
    request.writeInt(Checksum.crc32(request.toByteBuffer(0, 4)));
    channel.write(request);
}
 
Example 9
Project: traccar-service   File: ApelProtocolDecoder.java   Source Code and License Vote up 5 votes
private void requestArchive(Channel channel) {
    if (lastIndex == 0) {
        lastIndex = newIndex;
    } else if (newIndex > lastIndex) {
        ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 14);
        request.writeShort(MSG_REQUEST_LOG_RECORDS);
        request.writeShort(6);
        request.writeInt((int) lastIndex);
        request.writeShort(512);
        request.writeInt(Checksum.crc32(request.toByteBuffer(0, 10)));
        channel.write(request);
    }
}
 
Example 10
Project: traccar-service   File: CalAmpProtocolDecoder.java   Source Code and License Vote up 5 votes
private void sendResponse(Channel channel, SocketAddress remoteAddress, int type, int index, int result) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.directBuffer(10);
        response.writeByte(SERVICE_RESPONSE);
        response.writeByte(MSG_ACK);
        response.writeShort(index);
        response.writeByte(type);
        response.writeByte(result);
        response.writeByte(0);
        response.writeMedium(0);
        channel.write(response, remoteAddress);
    }
}
 
Example 11
Project: traccar-service   File: AtrackProtocolDecoder.java   Source Code and License Vote up 5 votes
private static void sendResponse(Channel channel, SocketAddress remoteAddress, long rawId, int index) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.directBuffer(12);
        response.writeShort(0xfe02);
        response.writeLong(rawId);
        response.writeShort(index);
        channel.write(response, remoteAddress);
    }
}
 
Example 12
Project: traccar-service   File: GalileoProtocolDecoder.java   Source Code and License Vote up 5 votes
private void sendReply(Channel channel, int checksum) {
    ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 3);
    reply.writeByte(0x02);
    reply.writeShort((short) checksum);
    if (channel != null) {
        channel.write(reply);
    }
}
 
Example 13
Project: traccar-service   File: Avl301ProtocolDecoder.java   Source Code and License Vote up 5 votes
private void sendResponse(Channel channel, int type) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.directBuffer(5);
        response.writeByte('$');
        response.writeByte(type);
        response.writeByte('#');
        response.writeByte('\r'); response.writeByte('\n');
        channel.write(response);
    }
}
 
Example 14
Project: traccar-service   File: At2000FrameDecoder.java   Source Code and License Vote up 5 votes
private void sendResponse(Channel channel) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 2 * BLOCK_LENGTH);
        response.writeByte(At2000ProtocolDecoder.MSG_ACKNOWLEDGEMENT);
        response.writeMedium(ChannelBuffers.swapMedium(1));
        response.writeByte(0x00); // success
        response.writerIndex(2 * BLOCK_LENGTH);
        channel.write(response);
    }
}
 
Example 15
Project: traccar-service   File: At2000ProtocolDecoder.java   Source Code and License Vote up 5 votes
private static void sendRequest(Channel channel) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, BLOCK_LENGTH);
        response.writeByte(MSG_TRACK_REQUEST);
        response.writeMedium(ChannelBuffers.swapMedium(0));
        response.writerIndex(BLOCK_LENGTH);
        channel.write(response);
    }
}
 
Example 16
Project: traccar-service   File: NavisProtocolDecoder.java   Source Code and License Vote up 5 votes
private void sendReply(Channel channel, ChannelBuffer data) {
    ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 16);
    header.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, prefix, StandardCharsets.US_ASCII));
    header.writeInt((int) deviceUniqueId);
    header.writeInt((int) serverId);
    header.writeShort(data.readableBytes());
    header.writeByte(checksum(data));
    header.writeByte(checksum(header));

    if (channel != null) {
        channel.write(ChannelBuffers.copiedBuffer(header, data));
    }
}
 
Example 17
Project: traccar-service   File: OrionProtocolDecoder.java   Source Code and License Vote up 5 votes
private static void sendResponse(Channel channel, ChannelBuffer buf) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.directBuffer(4);
        response.writeByte('*');
        response.writeShort(buf.getUnsignedShort(buf.writerIndex() - 2));
        response.writeByte(buf.getUnsignedByte(buf.writerIndex() - 3));
        channel.write(response);
    }
}
 
Example 18
Project: traccar-service   File: Mta6ProtocolDecoder.java   Source Code and License Vote up 5 votes
private void sendResponse(Channel channel, short packetId, short packetCount) {
    HttpResponse response = new DefaultHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK);

    ChannelBuffer begin = ChannelBuffers.copiedBuffer("#ACK#", StandardCharsets.US_ASCII);
    ChannelBuffer end = ChannelBuffers.directBuffer(3);
    end.writeByte(packetId);
    end.writeByte(packetCount);
    end.writeByte(0);

    response.setContent(ChannelBuffers.wrappedBuffer(begin, end));
    channel.write(response);
}
 
Example 19
Project: traccar-service   File: T800xProtocolDecoder.java   Source Code and License Vote up 5 votes
private void sendResponse(Channel channel, int type, ChannelBuffer imei) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.directBuffer(15);
        response.writeByte(0x23);
        response.writeByte(0x23); // header
        response.writeByte(type);
        response.writeShort(response.capacity()); // length
        response.writeShort(0x0001); // index
        response.writeBytes(imei);
        channel.write(response);
    }
}