当前位置: 首页>>代码示例>>Java>>正文


Java ChannelBuffer.readUnsignedByte方法代码示例

本文整理汇总了Java中org.jboss.netty.buffer.ChannelBuffer.readUnsignedByte方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelBuffer.readUnsignedByte方法的具体用法?Java ChannelBuffer.readUnsignedByte怎么用?Java ChannelBuffer.readUnsignedByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.netty.buffer.ChannelBuffer的用法示例。


在下文中一共展示了ChannelBuffer.readUnsignedByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parsePositionReport2

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private Position parsePositionReport2(
        DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
    Position position = new Position();
    position.setProtocol(getProtocolName());

    position.set(Position.KEY_INDEX, sequenceNumber);
    position.setDeviceId(deviceSession.getDeviceId());
    position.setTime(convertTimestamp(timestamp));

    position.setLatitude(buf.readInt() * 0.0000001);
    position.setLongitude(buf.readInt() * 0.0000001);

    buf.readUnsignedByte(); // report trigger

    position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));

    short flags = buf.readUnsignedByte();
    position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);

    position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
    position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());

    return position;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:25,代码来源:NavigilProtocolDecoder.java

示例2: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;

    buf.readUnsignedShort(); // device id

    int size = buf.readUnsignedByte();
    if (size != CMD_RESPONSE_SIZE) {
        int type = buf.readUnsignedByte();
        if (type == MSG_IMEI) {
            getDeviceSession(channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.UTF_8));
        } else {
            return decodeData(channel, remoteAddress, buf, type);
        }
    } else {
        return parseCommandResponse(channel, remoteAddress, buf);
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:21,代码来源:AdmProtocolDecoder.java

示例3: readCoordinate

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
public static double readCoordinate(ChannelBuffer buf) {
    int b1 = buf.readUnsignedByte();
    int b2 = buf.readUnsignedByte();
    int b3 = buf.readUnsignedByte();
    int b4 = buf.readUnsignedByte();

    double value = (b2 & 0xf) * 10 + (b3 >> 4);
    value += (((b3 & 0xf) * 10 + (b4 >> 4)) * 10 + (b4 & 0xf)) / 1000.0;
    value /= 60;
    value += ((b1 >> 4 & 0x7) * 10 + (b1 & 0xf)) * 10 + (b2 >> 4);

    if ((b1 & 0x80) != 0) {
        value = -value;
    }

    return value;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:18,代码来源:BcdUtil.java

示例4: readImei

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private String readImei(ChannelBuffer buf) {
    int b = buf.readUnsignedByte();
    StringBuilder imei = new StringBuilder();
    imei.append(b & 0x0F);
    for (int i = 0; i < 7; i++) {
        b = buf.readUnsignedByte();
        imei.append((b & 0xF0) >> 4);
        imei.append(b & 0x0F);
    }
    return imei.toString();
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:12,代码来源:Avl301ProtocolDecoder.java

示例5: readValue

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private long readValue(ChannelBuffer buf, int length, boolean signed) {
    switch (length) {
        case 1:
            return signed ? buf.readByte() : buf.readUnsignedByte();
        case 2:
            return signed ? buf.readShort() : buf.readUnsignedShort();
        case 4:
            return signed ? buf.readInt() : buf.readUnsignedInt();
        default:
            return buf.readLong();
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:13,代码来源:TeltonikaProtocolDecoder.java

示例6: decodeUdp

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private Object decodeUdp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {

        buf.readUnsignedShort(); // length
        buf.readUnsignedShort(); // packet id
        buf.readUnsignedByte(); // packet type
        int locationPacketId = buf.readUnsignedByte();
        String imei = buf.readBytes(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII);

        return parseData(channel, remoteAddress, buf, locationPacketId, imei);

    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:12,代码来源:TeltonikaProtocolDecoder.java

示例7: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx,
        Channel channel,
        ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < 2) {
        return null;
    }

    int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xC0);
    if (index != -1) {
        ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex());

        while (buf.readerIndex() <= index) {
            int b = buf.readUnsignedByte();
            if (b == 0xDB) {
                int ext = buf.readUnsignedByte();
                if (ext == 0xDC) {
                    result.writeByte(0xC0);
                } else if (ext == 0xDD) {
                    result.writeByte(0xDB);
                }
            } else {
                result.writeByte(b);
            }
        }

        return result;
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:34,代码来源:HuaShengFrameDecoder.java

示例8: parseTg2Report

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private Position parseTg2Report(
        DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
    Position position = new Position();
    position.setProtocol(getProtocolName());

    position.setValid(true);
    position.set(Position.KEY_INDEX, sequenceNumber);
    position.setDeviceId(deviceSession.getDeviceId());

    buf.readUnsignedShort(); // report trigger
    buf.readUnsignedByte(); // reserved
    buf.readUnsignedByte(); // assisted GPS age

    position.setTime(convertTimestamp(buf.readUnsignedInt()));

    position.setLatitude(buf.readInt() * 0.0000001);
    position.setLongitude(buf.readInt() * 0.0000001);
    position.setAltitude(buf.readUnsignedShort());

    position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
    position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());

    position.setSpeed(buf.readUnsignedShort() * 0.194384);
    position.setCourse(buf.readUnsignedShort());

    position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
    position.set("maximumSpeed", buf.readUnsignedShort());
    position.set("minimumSpeed", buf.readUnsignedShort());

    position.set(Position.PREFIX_IO + 1, buf.readUnsignedShort()); // VSAUT1 voltage
    position.set(Position.PREFIX_IO + 2, buf.readUnsignedShort()); // VSAUT2 voltage
    position.set(Position.PREFIX_IO + 3, buf.readUnsignedShort()); // solar voltage

    position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);

    return position;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:38,代码来源:NavigilProtocolDecoder.java

示例9: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    HttpRequest request = (HttpRequest) msg;
    ChannelBuffer buf = request.getContent();

    buf.skipBytes("id=".length());
    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
    String uniqueId = buf.toString(buf.readerIndex(), index - buf.readerIndex(), StandardCharsets.US_ASCII);
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
    if (deviceSession == null) {
        return null;
    }
    buf.skipBytes(uniqueId.length());
    buf.skipBytes("&bin=".length());

    short packetId = buf.readUnsignedByte();
    short offset = buf.readUnsignedByte(); // dataOffset
    short packetCount = buf.readUnsignedByte();
    buf.readUnsignedByte(); // reserved
    buf.readUnsignedByte(); // timezone
    buf.skipBytes(offset - 5);

    if (channel != null) {
        sendContinue(channel);
        sendResponse(channel, packetId, packetCount);
    }

    if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) {
        if (simple) {
            return parseFormatA1(deviceSession, buf);
        } else {
            return parseFormatA(deviceSession, buf);
        }
    } //else if (0x34 0x38 0x4F 0x59)

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:40,代码来源:Mta6ProtocolDecoder.java

示例10: decodeObd

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private void decodeObd(Position position, ChannelBuffer buf, boolean groups) {

        int count = buf.readUnsignedByte();

        int[] pids = new int[count];
        for (int i = 0; i < count; i++) {
            pids[i] = buf.readUnsignedShort() & 0xff;
        }

        if (groups) {
            buf.readUnsignedByte(); // group count
            buf.readUnsignedByte(); // group size
        }

        for (int i = 0; i < count; i++) {
            int value;
            switch (PID_LENGTH_MAP.get(pids[i])) {
                case 1:
                    value = buf.readUnsignedByte();
                    break;
                case 2:
                    value = buf.readUnsignedShort();
                    break;
                case 4:
                    value = buf.readInt();
                    break;
                default:
                    value = 0;
                    break;
            }
            position.add(ObdDecoder.decodeData(pids[i], value, false));
        }
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:34,代码来源:CastelProtocolDecoder.java

示例11: decodeStatus

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private boolean decodeStatus(Position position, ChannelBuffer buf) {

        int status = buf.readUnsignedByte();

        position.set(Position.KEY_STATUS, status);
        position.set(Position.KEY_IGNITION, BitUtil.check(status, 1));
        position.set(Position.KEY_CHARGE, BitUtil.check(status, 2));
        position.set(Position.KEY_BLOCKED, BitUtil.check(status, 7));

        switch (BitUtil.between(status, 3, 6)) {
            case 1:
                position.set(Position.KEY_ALARM, Position.ALARM_SHOCK);
                break;
            case 2:
                position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
                break;
            case 3:
                position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
                break;
            case 4:
                position.set(Position.KEY_ALARM, Position.ALARM_SOS);
                break;
            default:
                break;
        }

        position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
        position.set(Position.KEY_RSSI, buf.readUnsignedByte());
        position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));

        return true;
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:33,代码来源:Gt06ProtocolDecoder.java

示例12: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    ChannelBuffer buf = (ChannelBuffer) msg;

    buf.readUnsignedByte(); // protocol
    buf.readUnsignedShort(); // length
    int index = buf.readUnsignedByte() >> 3;

    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.copiedBuffer(
                "^" + index, StandardCharsets.US_ASCII);
        channel.write(response, remoteAddress);
    }

    String id = String.valueOf(buf.readUnsignedInt());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
    if (deviceSession == null) {
        return null;
    }

    List<Position> positions = new LinkedList<>();

    while (buf.readableBytes() > 2) {

        Position position = new Position();
        position.setProtocol(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());

        int end = buf.readerIndex() + buf.readUnsignedByte();

        position.setTime(new Date(buf.readUnsignedInt() * 1000));

        int flags = buf.readUnsignedByte();
        position.set(Position.KEY_SATELLITES, BitUtil.from(flags, 2));
        position.setValid(BitUtil.to(flags, 2) > 0);

        // Latitude
        double lat = buf.readUnsignedMedium();
        lat = lat * -180 / 16777216 + 90;
        position.setLatitude(lat);

        // Longitude
        double lon = buf.readUnsignedMedium();
        lon = lon * 360 / 16777216 - 180;
        position.setLongitude(lon);

        // Status
        flags = buf.readUnsignedByte();
        position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
        position.set(Position.KEY_RSSI, BitUtil.between(flags, 2, 5));
        position.setCourse((BitUtil.from(flags, 5) * 45 + 180) % 360);

        // Speed
        int speed = buf.readUnsignedByte();
        if (speed < 250) {
            position.setSpeed(UnitsConverter.knotsFromKph(speed));
        }

        decodeExtraData(position, buf, end);

        positions.add(position);
    }

    return positions;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:68,代码来源:TytanProtocolDecoder.java

示例13: decodeInformation

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private Position decodeInformation(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {

        Position position = new Position();
        position.setProtocol(getProtocolName());

        int type = buf.readUnsignedByte();

        buf.readUnsignedInt(); // mask
        buf.readUnsignedShort(); // length

        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.format("%015d", buf.readLong()));
        if (deviceSession == null) {
            return null;
        }
        position.setDeviceId(deviceSession.getDeviceId());

        buf.readUnsignedByte(); // device type
        buf.readUnsignedShort(); // protocol version

        position.set(Position.KEY_VERSION_FW, String.valueOf(buf.readUnsignedShort()));

        if (type == MSG_INF_VER) {
            buf.readUnsignedShort(); // hardware version
            buf.readUnsignedShort(); // mcu version
            buf.readUnsignedShort(); // reserved
        }

        buf.readUnsignedByte(); // motion status
        buf.readUnsignedByte(); // reserved

        position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());

        buf.readUnsignedByte(); // mode
        buf.skipBytes(7); // last fix time
        buf.readUnsignedByte(); // reserved
        buf.readUnsignedByte();
        buf.readUnsignedShort(); // response report mask
        buf.readUnsignedShort(); // ign interval
        buf.readUnsignedShort(); // igf interval
        buf.readUnsignedInt(); // reserved
        buf.readUnsignedByte(); // reserved

        if (type == MSG_INF_BAT) {
            position.set(Position.KEY_CHARGE, buf.readUnsignedByte() != 0);
            position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
            position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
            position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
        }

        buf.skipBytes(10); // iccid

        if (type == MSG_INF_CSQ) {
            position.set(Position.KEY_RSSI, buf.readUnsignedByte());
            buf.readUnsignedByte();
        }

        buf.readUnsignedByte(); // time zone flags
        buf.readUnsignedShort(); // time zone offset

        if (type == MSG_INF_GIR) {
            buf.readUnsignedByte(); // gir trigger
            buf.readUnsignedByte(); // cell number
            position.setNetwork(new Network(CellTower.from(
                    buf.readUnsignedShort(), buf.readUnsignedShort(),
                    buf.readUnsignedShort(), buf.readUnsignedShort())));
            buf.readUnsignedByte(); // ta
            buf.readUnsignedByte(); // rx level
        }

        getLastLocation(position, decodeTime(buf));

        return position;
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:74,代码来源:Gl200BinaryProtocolDecoder.java

示例14: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    ChannelBuffer buf = (ChannelBuffer) msg;

    buf.readUnsignedByte(); // start marker
    int type = buf.readUnsignedShort();
    buf.readUnsignedShort(); // body length
    ChannelBuffer id = buf.readBytes(6); // phone number
    int index = buf.readUnsignedShort();

    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(id));
    if (deviceSession == null) {
        return null;
    }

    if (type == MSG_TERMINAL_REGISTER) {

        if (channel != null) {
            ChannelBuffer response = ChannelBuffers.dynamicBuffer();
            response.writeShort(index);
            response.writeByte(RESULT_SUCCESS);
            response.writeBytes("authentication".getBytes(StandardCharsets.US_ASCII));
            channel.write(formatMessage(MSG_TERMINAL_REGISTER_RESPONSE, id, response), remoteAddress);
        }

    } else if (type == MSG_TERMINAL_AUTH) {

        sendGeneralResponse(channel, remoteAddress, id, type, index);

    } else if (type == MSG_LOCATION_REPORT) {

        Position position = new Position();
        position.setProtocol(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());

        position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedInt()));

        int flags = buf.readInt();

        position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));

        position.setValid(BitUtil.check(flags, 1));

        double lat = buf.readUnsignedInt() * 0.000001;
        double lon = buf.readUnsignedInt() * 0.000001;

        if (BitUtil.check(flags, 2)) {
            position.setLatitude(-lat);
        } else {
            position.setLatitude(lat);
        }

        if (BitUtil.check(flags, 3)) {
            position.setLongitude(-lon);
        } else {
            position.setLongitude(lon);
        }

        position.setAltitude(buf.readShort());
        position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
        position.setCourse(buf.readUnsignedShort());

        DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+8"))
                .setYear(BcdUtil.readInteger(buf, 2))
                .setMonth(BcdUtil.readInteger(buf, 2))
                .setDay(BcdUtil.readInteger(buf, 2))
                .setHour(BcdUtil.readInteger(buf, 2))
                .setMinute(BcdUtil.readInteger(buf, 2))
                .setSecond(BcdUtil.readInteger(buf, 2));
        position.setTime(dateBuilder.getDate());

        // additional information

        return position;

    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:82,代码来源:HuabaoProtocolDecoder.java

示例15: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    ChannelBuffer buf = (ChannelBuffer) msg;

    char protocol = (char) buf.readByte();
    int version = buf.readUnsignedByte();

    String imei;
    if ((version & 0x80) != 0) {
        imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium());
    } else {
        imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium()));
    }

    buf.readUnsignedShort(); // length

    int selector = DEFAULT_SELECTOR_D;
    if (protocol == 'E') {
        selector = DEFAULT_SELECTOR_E;
    } else if (protocol == 'F') {
        selector = DEFAULT_SELECTOR_F;
    }
    if ((version & 0x40) != 0) {
        selector = buf.readUnsignedMedium();
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());

    int event = buf.readUnsignedByte();
    position.set(Position.KEY_EVENT, event);
    position.set("eventInfo", buf.readUnsignedByte());

    if (protocol == 'D') {
        decodeD(position, buf, selector, event);
    } else if (protocol == 'E') {
        decodeE(position, buf, selector);
    } else if (protocol == 'H') {
        decodeH(position, buf, selector);
    } else if (protocol == 'F') {
        decodeF(position, buf, selector);
    } else {
        return null;
    }

    return position;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:54,代码来源:AplicomProtocolDecoder.java


注:本文中的org.jboss.netty.buffer.ChannelBuffer.readUnsignedByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。