當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelBuffer.readUnsignedMedium方法代碼示例

本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.readUnsignedMedium方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.readUnsignedMedium方法的具體用法?Java ChannelBuffer.readUnsignedMedium怎麽用?Java ChannelBuffer.readUnsignedMedium使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.buffer.ChannelBuffer的用法示例。


在下文中一共展示了ChannelBuffer.readUnsignedMedium方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readFloat

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
public float readFloat(ChannelBuffer buf) {
    switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) {
        case 0:
            previousFloat = buf.readInt() << 2;
            break;
        case 1:
            previousFloat = (previousFloat & 0xffffff00) + ((buf.readUnsignedByte() & 0x3f) << 2);
            break;
        case 2:
            previousFloat = (previousFloat & 0xffff0000) + ((buf.readUnsignedShort() & 0x3fff) << 2);
            break;
        case 3:
            previousFloat = (previousFloat & 0xff000000) + ((buf.readUnsignedMedium() & 0x3fffff) << 2);
            break;
        default:
            Log.warning(new IllegalArgumentException());
            break;
    }
    return Float.intBitsToFloat(previousFloat);
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:21,代碼來源:Mta6ProtocolDecoder.java

示例2: decodeEventData

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void decodeEventData(Position position, ChannelBuffer buf, int event) {
    switch (event) {
        case 2:
        case 40:
            buf.readUnsignedByte();
            break;
        case 9:
            buf.readUnsignedMedium();
            break;
        case 31:
        case 32:
            buf.readUnsignedShort();
            break;
        case 38:
            buf.skipBytes(4 * 9);
            break;
        case 113:
            buf.readUnsignedInt();
            buf.readUnsignedByte();
            break;
        case 121:
        case 142:
            buf.readLong();
            break;
        case 130:
            buf.readUnsignedInt(); // incorrect
            break;
        case 188:
            decodeEB(position, buf);
            break;
        default:
            break;
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:35,代碼來源:AplicomProtocolDecoder.java

示例3: 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

示例4: 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(); // header

    DeviceSession deviceSession = getDeviceSession(
            channel, remoteAddress, buf.readBytes(7).toString(StandardCharsets.US_ASCII));
    if (deviceSession == null) {
        return null;
    }

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

    position.set("eventType", buf.readUnsignedByte());
    position.set("packetVersion", buf.readUnsignedByte());
    position.set(Position.KEY_STATUS, buf.readUnsignedByte());
    position.set(Position.KEY_RSSI, buf.readUnsignedByte());
    position.set(Position.KEY_GPS, buf.readUnsignedByte());

    position.setTime(new DateBuilder()
            .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
            .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate());

    position.setValid(true);

    double lat = buf.getUnsignedShort(buf.readerIndex()) / 100;
    lat += (buf.readUnsignedShort() % 100 * 10000 + buf.readUnsignedShort()) / 600000.0;
    position.setLatitude(buf.readUnsignedByte() == 'S' ? -lat : lat);

    double lon = buf.getUnsignedMedium(buf.readerIndex()) / 100;
    lon += (buf.readUnsignedMedium() % 100 * 10000 + buf.readUnsignedShort()) / 600000.0;
    position.setLongitude(buf.readUnsignedByte() == 'W' ? -lon : lon);

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

    position.set(Position.KEY_INPUT, buf.readUnsignedShort());
    position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());

    position.set("analogAlerts", buf.readUnsignedByte());
    position.set("customAlertTypes", buf.readUnsignedShort());

    for (int i = 1; i <= 5; i++) {
        position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
    }

    position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
    position.set(Position.KEY_RPM, buf.readUnsignedShort());

    if (channel != null) {
        channel.write(ChannelBuffers.copiedBuffer("ACK", StandardCharsets.US_ASCII), remoteAddress);
    }

    return position;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:60,代碼來源:PricolProtocolDecoder.java

示例5: decode

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

    ChannelBuffer buf = (ChannelBuffer) msg;

    if (channel != null) {
        channel.write(ChannelBuffers.wrappedBuffer(new byte[] {0x06}), remoteAddress);
    }

    buf.readUnsignedByte(); // protocol
    buf.readUnsignedShort(); // length

    String imei = String.format("%08d", buf.readUnsignedInt()) + String.format("%07d", buf.readUnsignedMedium());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
    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());

        buf.readUnsignedByte(); // index

        position.setValid(true);
        position.setLatitude(buf.readInt() * 0.000001);
        position.setLongitude(buf.readInt() * 0.000001);

        DateBuilder dateBuilder = new DateBuilder()
                .setDate(1980, 1, 6).addMillis(buf.readUnsignedInt() * 1000L);
        position.setTime(dateBuilder.getDate());

        position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte() * 2));
        position.setCourse(buf.readUnsignedByte() * 2);

        int reason = buf.readUnsignedMedium();
        position.set(Position.KEY_EVENT, reason);

        int status = buf.readUnsignedShort();
        position.set(Position.KEY_STATUS, status);

        position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte());
        position.set(Position.PREFIX_ADC + 1, buf.readUnsignedByte());
        position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
        position.set(Position.KEY_POWER, buf.readUnsignedByte());

        buf.readUnsignedByte(); // max journey speed
        buf.skipBytes(6); // accelerometer
        position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
        buf.readUnsignedShort(); // journey idle time

        position.setAltitude(buf.readUnsignedByte() * 20);

        int quality = buf.readUnsignedByte();
        position.set(Position.KEY_SATELLITES, quality & 0xf);
        position.set(Position.KEY_RSSI, quality >> 4);

        buf.readUnsignedByte(); // geofence events

        if (BitUtil.check(status, 8)) {
            position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readBytes(7).toString(StandardCharsets.US_ASCII));
            position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000);
            position.set(Position.KEY_HOURS, buf.readUnsignedShort());
        }

        if (BitUtil.check(status, 6)) {
            Log.warning("Extension data is not supported");
            return position;
        }

        positions.add(position);

    }

    return positions;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:82,代碼來源:AstraProtocolDecoder.java

示例6: decodeCanData

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void decodeCanData(ChannelBuffer buf, Position position) {

        buf.readUnsignedMedium(); // packet identifier
        position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
        int count = buf.readUnsignedByte();
        buf.readUnsignedByte(); // batch count
        buf.readUnsignedShort(); // selector bit
        buf.readUnsignedInt(); // timestamp

        buf.skipBytes(8);

        ArrayList<ChannelBuffer> values = new ArrayList<>(count);

        for (int i = 0; i < count; i++) {
            values.add(buf.readBytes(8));
        }

        for (int i = 0; i < count; i++) {
            ChannelBuffer value = values.get(i);
            switch (buf.readInt()) {
                case 0x20D:
                    position.set(Position.KEY_RPM, ChannelBuffers.swapShort(value.readShort()));
                    position.set("dieselTemperature", ChannelBuffers.swapShort(value.readShort()) * 0.1);
                    position.set("batteryVoltage", ChannelBuffers.swapShort(value.readShort()) * 0.01);
                    position.set("supplyAirTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1);
                    break;
                case 0x30D:
                    position.set("activeAlarm", ChannelBuffers.hexDump(value));
                    break;
                case 0x40C:
                    position.set("airTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1);
                    position.set("airTempDep2", ChannelBuffers.swapShort(value.readShort()) * 0.1);
                    break;
                case 0x40D:
                    position.set("coldUnitState", ChannelBuffers.hexDump(value));
                    break;
                case 0x50C:
                    position.set("defrostTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1);
                    position.set("defrostTempDep2", ChannelBuffers.swapShort(value.readShort()) * 0.1);
                    break;
                case 0x50D:
                    position.set("condenserPressure", ChannelBuffers.swapShort(value.readShort()) * 0.1);
                    position.set("suctionPressure", ChannelBuffers.swapShort(value.readShort()) * 0.1);
                    break;
                case 0x58C:
                    value.readByte();
                    value.readShort(); // index
                    switch (value.readByte()) {
                        case 0x01:
                            position.set("setpointZone1", ChannelBuffers.swapInt(value.readInt()) * 0.1);
                            break;
                        case 0x02:
                            position.set("setpointZone2", ChannelBuffers.swapInt(value.readInt()) * 0.1);
                            break;
                        case 0x05:
                            position.set("unitType", ChannelBuffers.swapInt(value.readInt()));
                            break;
                        case 0x13:
                            position.set("dieselHours", ChannelBuffers.swapInt(value.readInt()) / 60 / 60);
                            break;
                        case 0x14:
                            position.set("electricHours", ChannelBuffers.swapInt(value.readInt()) / 60 / 60);
                            break;
                        case 0x17:
                            position.set("serviceIndicator", ChannelBuffers.swapInt(value.readInt()));
                            break;
                        case 0x18:
                            position.set("softwareVersion", ChannelBuffers.swapInt(value.readInt()) * 0.01);
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    Log.warning(new UnsupportedOperationException());
                    break;
            }
        }
    }
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:80,代碼來源:AplicomProtocolDecoder.java

示例7: 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.readUnsignedMedium方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。