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


Java ChannelBuffer.readUnsignedShort方法代码示例

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


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

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

示例2: 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,代码来源:RuptelaProtocolDecoder.java

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

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

示例5: parseUnitReport

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private Position parseUnitReport(
        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
    position.set(Position.KEY_FLAGS, buf.readUnsignedShort());

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

    position.set(Position.KEY_SATELLITES, buf.readUnsignedShort());
    position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShort());
    position.set("gpsAntennaState", buf.readUnsignedShort());

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

    position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
    position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());

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

    position.set(Position.KEY_CHARGE, buf.readUnsignedShort());

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

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

示例6: getOspfHeader

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
/**
 * Gets the OSPF packet Header.
 *
 * @param channelBuffer channel buffer instance.
 * @return Ospf Header instance.
 */
private OspfPacketHeader getOspfHeader(ChannelBuffer channelBuffer) throws Exception {
    OspfPacketHeader ospfPacketHeader = new OspfPacketHeader();

    // Determine OSPF version & Packet Type
    int version = channelBuffer.readByte(); //byte 1 is ospf version
    int packetType = channelBuffer.readByte(); //byte 2 is ospf packet type

    // byte 3 & 4 combine is packet length.
    int packetLength = channelBuffer.readShort();

    byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
    channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
    Ip4Address routerId = Ip4Address.valueOf(tempByteArray);

    tempByteArray = new byte[OspfUtil.FOUR_BYTES];
    channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
    Ip4Address areaId = Ip4Address.valueOf(tempByteArray);

    int checkSum = channelBuffer.readUnsignedShort();
    int auType = channelBuffer.readUnsignedShort();
    int authentication = (int) channelBuffer.readLong();

    ospfPacketHeader.setOspfVer(version);
    ospfPacketHeader.setOspftype(packetType);
    ospfPacketHeader.setOspfPacLength(packetLength);
    ospfPacketHeader.setRouterId(routerId);
    ospfPacketHeader.setAreaId(areaId);
    ospfPacketHeader.setChecksum(checkSum);
    ospfPacketHeader.setAuthType(auType);
    ospfPacketHeader.setAuthentication(authentication);

    return ospfPacketHeader;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:40,代码来源:OspfMessageReader.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;

    buf.readUnsignedByte(); // protocol version
    buf.readUnsignedByte(); // version id
    int sequenceNumber = buf.readUnsignedShort();
    int messageId = buf.readUnsignedShort();
    buf.readUnsignedShort(); // length
    int flags = buf.readUnsignedShort();
    buf.readUnsignedShort(); // checksum

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

    long timestamp = buf.readUnsignedInt();

    if ((flags & 0x1) == 0x0) {
        sendAcknowledgment(channel, sequenceNumber);
    }

    switch (messageId) {
        case MSG_UNIT_REPORT:
            return parseUnitReport(deviceSession, buf, sequenceNumber);
        case MSG_TG2_REPORT:
            return parseTg2Report(deviceSession, buf, sequenceNumber);
        case MSG_POSITION_REPORT:
            return parsePositionReport(deviceSession, buf, sequenceNumber, timestamp);
        case MSG_POSITION_REPORT_2:
            return parsePositionReport2(deviceSession, buf, sequenceNumber, timestamp);
        case MSG_SNAPSHOT4:
            return parseSnapshot4(deviceSession, buf, sequenceNumber);
        case MSG_TRACKING_DATA:
            return parseTrackingData(deviceSession, buf, sequenceNumber, timestamp);
        default:
            Log.warning(new UnsupportedOperationException(String.valueOf(messageId)));
            break;
    }

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

示例8: decodeEB

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

        if (buf.readByte() != (byte) 'E' || buf.readByte() != (byte) 'B') {
            return;
        }

        position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
        position.set(Position.KEY_EVENT, buf.readUnsignedShort());
        position.set("dataValidity", buf.readUnsignedByte());
        position.set("towed", buf.readUnsignedByte());
        buf.readUnsignedShort(); // length

        while (buf.readableBytes() > 0) {
            buf.readUnsignedByte(); // towed position
            int type = buf.readUnsignedByte();
            int length = buf.readUnsignedByte();
            int end = buf.readerIndex() + length;

            switch (type) {
                case 0x01:
                    position.set("brakeFlags", ChannelBuffers.hexDump(buf.readBytes(length)));
                    break;
                case 0x02:
                    position.set("wheelSpeed", buf.readUnsignedShort() / 256.0);
                    position.set("wheelSpeedDifference", buf.readUnsignedShort() / 256.0 - 125.0);
                    position.set("lateralAcceleration", buf.readUnsignedByte() / 10.0 - 12.5);
                    position.set("vehicleSpeed", buf.readUnsignedShort() / 256.0);
                    break;
                case 0x03:
                    position.set("axleLoadSum", buf.readUnsignedShort() * 2);
                    break;
                case 0x04:
                    position.set("tyrePressure", buf.readUnsignedByte() * 10);
                    position.set("pneumaticPressure", buf.readUnsignedByte() * 5);
                    break;
                case 0x05:
                    position.set("brakeLining", buf.readUnsignedByte() * 0.4);
                    position.set("brakeTemperature", buf.readUnsignedByte() * 10);
                    break;
                case 0x06:
                    position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 5L);
                    position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt() * 5L);
                    position.set(Position.KEY_ODOMETER_SERVICE, (buf.readUnsignedInt() - 2105540607) * 5L);
                    break;
                case 0x0A:
                    position.set("absStatusCounter", buf.readUnsignedShort());
                    position.set("atvbStatusCounter", buf.readUnsignedShort());
                    position.set("vdcActiveCounter", buf.readUnsignedShort());
                    break;
                case 0x0B:
                    position.set("brakeMinMaxData", ChannelBuffers.hexDump(buf.readBytes(length)));
                    break;
                case 0x0C:
                    position.set("missingPgn", ChannelBuffers.hexDump(buf.readBytes(length)));
                    break;
                case 0x0D:
                    buf.readUnsignedByte();
                    position.set("towedDetectionStatus", buf.readUnsignedInt());
                    buf.skipBytes(17); // vin
                    break;
                case 0x0E:
                default:
                    break;
            }

            buf.readerIndex(end);
        }
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:69,代码来源:AplicomProtocolDecoder.java

示例9: parseFormatA1

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

    short flags = buf.readUnsignedByte();

    // Skip events
    short event = buf.readUnsignedByte();
    if (BitUtil.check(event, 7)) {
        if (BitUtil.check(event, 6)) {
            buf.skipBytes(8);
        } else {
            while (BitUtil.check(event, 7)) {
                event = buf.readUnsignedByte();
            }
        }
    }

    position.setLatitude(new FloatReader().readFloat(buf) / Math.PI * 180);
    position.setLongitude(new FloatReader().readFloat(buf) / Math.PI * 180);
    position.setTime(new TimeReader().readTime(buf));

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

    if (BitUtil.check(flags, 0)) {
        position.setAltitude(buf.readUnsignedShort());
        position.setSpeed(buf.readUnsignedByte());
        position.setCourse(buf.readByte());
        position.set(Position.KEY_ODOMETER, new FloatReader().readFloat(buf));
    }

    if (BitUtil.check(flags, 1)) {
        position.set(Position.KEY_FUEL_CONSUMPTION, new FloatReader().readFloat(buf));
        position.set(Position.KEY_HOURS, new FloatReader().readFloat(buf));
        position.set("tank", buf.readUnsignedByte() * 0.4);
    }

    if (BitUtil.check(flags, 2)) {
        position.set("engine", buf.readUnsignedShort() * 0.125);
        position.set("pedals", buf.readUnsignedByte());
        position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte() - 40);
        position.set(Position.KEY_ODOMETER_SERVICE, buf.readUnsignedShort());
    }

    if (BitUtil.check(flags, 3)) {
        position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort());
        position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
        position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort());
        position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShort());
    }

    if (BitUtil.check(flags, 4)) {
        position.set(Position.PREFIX_TEMP + 1, buf.readByte());
        buf.getUnsignedByte(buf.readerIndex()); // control (>> 4)
        position.set(Position.KEY_INPUT, buf.readUnsignedShort() & 0x0fff);
        buf.readUnsignedShort(); // old sensor state (& 0x0fff)
    }

    if (BitUtil.check(flags, 5)) {
        position.set(Position.KEY_BATTERY, buf.getUnsignedByte(buf.readerIndex()) >> 2);
        position.set(Position.KEY_POWER, buf.readUnsignedShort() & 0x03ff);
        position.set(Position.KEY_DEVICE_TEMP, buf.readByte());

        position.set(Position.KEY_RSSI, buf.getUnsignedByte(buf.readerIndex()) >> 5);

        int satellites = buf.readUnsignedByte() & 0x1f;
        position.setValid(satellites >= 3);
        position.set(Position.KEY_SATELLITES, satellites);
    }

    // other data

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

示例10: 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.skipBytes(2); // header
    buf.readShort(); // length
    ChannelBuffer id = buf.readBytes(7);
    int command = buf.readUnsignedShort();
    ChannelBuffer response;

    if (channel != null) {
        if (command == MSG_LOGIN) {
            response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
            sendResponse(channel, remoteAddress, id, MSG_LOGIN_RESPONSE, response);
            return null;
        } else if (command == MSG_HEARTBEAT) {
            response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
            sendResponse(channel, remoteAddress, id, MSG_HEARTBEAT, response);
            return null;
        } else if (command == MSG_SERVER) {
            response = ChannelBuffers.copiedBuffer(getServer(channel), StandardCharsets.US_ASCII);
            sendResponse(channel, remoteAddress, id, MSG_SERVER, response);
            return null;
        }
    }

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

    if (command == MSG_ALARM) {
        short alarmCode = buf.readUnsignedByte();
        position.set(Position.KEY_ALARM, decodeAlarm(alarmCode));
        if (alarmCode >= 0x02 && alarmCode <= 0x05) {
            position.set(Position.PREFIX_IN + alarmCode, 1);
        } else if (alarmCode >= 0x32 && alarmCode <= 0x35) {
            position.set(Position.PREFIX_IN + (alarmCode - 0x30), 0);
        }
    } else if (command == MSG_POSITION_LOGGED) {
        buf.skipBytes(6);
    }

    DeviceSession deviceSession = identify(id, channel, remoteAddress);
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());

    if (command == MSG_RFID) {
        for (int i = 0; i < 15; i++) {
            long rfid = buf.readUnsignedInt();
            if (rfid != 0) {
                String card = String.format("%010d", rfid);
                position.set("card" + (i + 1), card);
                position.set(Position.KEY_DRIVER_UNIQUE_ID, card);
            }
        }
    }

    String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII);

    if (command == MSG_POSITION || command == MSG_POSITION_LOGGED || command == MSG_ALARM) {
        return decodeRegular(position, sentence);
    } else if (command == MSG_RFID) {
        return decodeRfid(position, sentence);
    } else if (command == MSG_OBD_RT) {
        return decodeObd(position, sentence);
    } else if (command == MSG_OBD_RTA) {
        return decodeObdA(position, sentence);
    }

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

示例11: decodeH

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

        if ((selector & 0x0004) != 0) {
            getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
        } else {
            getLastLocation(position, null);
        }

        if ((selector & 0x0040) != 0) {
            buf.readUnsignedInt(); // reset time
        }

        if ((selector & 0x2000) != 0) {
            buf.readUnsignedShort(); // snapshot counter
        }

        int index = 1;
        while (buf.readableBytes() > 0) {

            position.set("h" + index + "Index", buf.readUnsignedByte());

            buf.readUnsignedShort(); // length

            int n = buf.readUnsignedByte();
            int m = buf.readUnsignedByte();

            position.set("h" + index + "XLength", n);
            position.set("h" + index + "YLength", m);

            if ((selector & 0x0008) != 0) {
                position.set("h" + index + "XType", buf.readUnsignedByte());
                position.set("h" + index + "YType", buf.readUnsignedByte());
                position.set("h" + index + "Parameters", buf.readUnsignedByte());
            }

            boolean percentageFormat = (selector & 0x0020) != 0;

            StringBuilder data = new StringBuilder();
            for (int i = 0; i < n * m; i++) {
                if (percentageFormat) {
                    data.append(buf.readUnsignedByte() * 0.5).append("%").append(" ");
                } else {
                    data.append(buf.readUnsignedShort()).append(" ");
                }
            }

            position.set("h" + index + "Data", data.toString().trim());

            position.set("h" + index + "Total", buf.readUnsignedInt());

            if ((selector & 0x0010) != 0) {
                int k = buf.readUnsignedByte();

                data = new StringBuilder();
                for (int i = 1; i < n; i++) {
                    if (k == 1) {
                        data.append(buf.readByte()).append(" ");
                    } else if (k == 2) {
                        data.append(buf.readShort()).append(" ");
                    }
                }
                position.set("h" + index + "XLimits", data.toString().trim());

                data = new StringBuilder();
                for (int i = 1; i < m; i++) {
                    if (k == 1) {
                        data.append(buf.readByte()).append(" ");
                    } else if (k == 2) {
                        data.append(buf.readShort()).append(" ");
                    }
                }
                position.set("h" + index + "YLimits", data.toString().trim());
            }

            index += 1;
        }
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:78,代码来源:AplicomProtocolDecoder.java

示例12: decodePosition

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

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

        if (!history) {
            buf.readUnsignedByte(); // interval
            buf.skipBytes(8); // settings
        }
        position.set(Position.KEY_STATUS, buf.readUnsignedByte());
        if (!history) {
            buf.readUnsignedShort();
        }
        position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
        buf.skipBytes(6); // time

        if (!history) {
            for (int i = 0; i < 2; i++) {
                buf.skipBytes(5); // time
                buf.readUnsignedShort(); // interval
                buf.skipBytes(5); // mode
            }
        }

        position.set(Position.PREFIX_TEMP + 1, buf.readByte());

        int rssi = buf.readUnsignedByte();
        CellTower cellTower = CellTower.from(
                buf.readUnsignedShort(), buf.readUnsignedShort(),
                buf.readUnsignedShort(), buf.readUnsignedShort(), rssi);
        position.setNetwork(new Network(cellTower));

        int valid = buf.readUnsignedByte();
        position.setValid((valid & 0xc0) != 0);
        position.set(Position.KEY_SATELLITES, valid & 0x3f);

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

        position.setLatitude(convertCoordinate(buf.readInt()));
        position.setLongitude(convertCoordinate(buf.readInt()));
        position.setAltitude(buf.readShort());
        position.setSpeed(buf.readUnsignedByte());
        position.setCourse(buf.readUnsignedByte() * 2.0);

        position.set(Position.KEY_HDOP, buf.readUnsignedShort());

        buf.readUnsignedShort(); // reserved
        buf.readUnsignedByte(); // checksum
        return position;
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:55,代码来源:AutoFonProtocolDecoder.java

示例13: 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.skipBytes(2); // header
    buf.readUnsignedShort(); // length

    String imei = ChannelBuffers.hexDump(buf.readBytes(7));
    DeviceSession deviceSession = getDeviceSession(
            channel, remoteAddress, imei, imei + Checksum.luhn(Long.parseLong(imei)));
    if (deviceSession == null) {
        return null;
    }

    int type = buf.readUnsignedShort();

    if (type == MSG_LOCATION_REPORT || type == MSG_LOCATION_REQUEST) {

        String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 8, StandardCharsets.US_ASCII);
        Parser parser = new Parser(PATTERN, sentence);
        if (!parser.matches()) {
            return null;
        }

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

        if (parser.hasNext(15)) {

            position.setTime(parser.nextDateTime());

            position.setValid(parser.next().equals("A"));
            position.set(Position.KEY_SATELLITES, parser.nextInt());

            position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
            position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));

            position.setSpeed(parser.nextDouble(0));
            position.set(Position.KEY_HDOP, parser.nextDouble(0));
            position.setAltitude(parser.nextDouble(0));

        } else {

            getLastLocation(position, null);

        }

        position.setNetwork(new Network(CellTower.from(
                parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0))));

        return position;
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:59,代码来源:CityeasyProtocolDecoder.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.skipBytes(2); // header

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

    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedShort()));
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());

    position.set("mode", buf.readUnsignedByte());
    position.set(Position.KEY_COMMAND, buf.readUnsignedByte());
    position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);

    buf.skipBytes(5);  // status
    buf.readUnsignedShort();  // idleCount
    buf.readUnsignedShort();  // idleTime in seconds

    position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
    position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());

    // Parse GPRMC
    int end = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
    String gprmc = buf.toString(buf.readerIndex(), end - buf.readerIndex(), StandardCharsets.US_ASCII);
    Parser parser = new Parser(PATTERN, gprmc);
    if (!parser.matches()) {
        return null;
    }

    DateBuilder dateBuilder = new DateBuilder()
            .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));

    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));

    dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setTime(dateBuilder.getDate());

    return position;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:51,代码来源:RitiProtocolDecoder.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;

    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


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