Java Code Examples for io.netty.buffer.ByteBuf#getDouble()

The following examples show how to use io.netty.buffer.ByteBuf#getDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettyServerHandler.java    From iot-dc3 with Apache License 2.0 4 votes vote down vote up
@Override
@SneakyThrows
public void channelRead(ChannelHandlerContext context, Object msg) {
    ByteBuf byteBuf = (ByteBuf) msg;
    log.info("{}->{}", context.channel().remoteAddress(), ByteBufUtil.hexDump(byteBuf));
    String deviceName = byteBuf.toString(0, 22, CharsetUtil.CHARSET_ISO_8859_1);
    Long deviceId = nettyServerHandler.driverContext.getDeviceIdByName(deviceName);
    String hexKey = ByteBufUtil.hexDump(byteBuf, 22, 1);

    List<PointValue> pointValues = new ArrayList<>();
    Map<Long, Map<String, AttributeInfo>> pointInfoMap = nettyServerHandler.driverContext.getDevicePointInfoMap().get(deviceId);
    for (Long pointId : pointInfoMap.keySet()) {
        Point point = nettyServerHandler.driverContext.getDevicePoint(deviceId, pointId);
        Map<String, AttributeInfo> infoMap = pointInfoMap.get(pointId);
        int start = DriverUtils.value(infoMap.get("start").getType(), infoMap.get("start").getValue());
        int end = DriverUtils.value(infoMap.get("end").getType(), infoMap.get("end").getValue());

        if (infoMap.get("key").getValue().equals(hexKey)) {
            PointValue pointValue = null;
            switch (point.getName()) {
                case "海拔":
                    float altitude = byteBuf.getFloat(start);
                    pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(altitude));
                    break;
                case "速度":
                    double speed = byteBuf.getDouble(start);
                    pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(speed));
                    break;
                case "液位":
                    long level = byteBuf.getLong(start);
                    pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(level));
                    break;
                case "方向":
                    int direction = byteBuf.getInt(start);
                    pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(direction));
                    break;
                case "锁定":
                    boolean lock = byteBuf.getBoolean(start);
                    pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(lock));
                    break;
                case "经纬":
                    String lalo = byteBuf.toString(start, end, CharsetUtil.CHARSET_ISO_8859_1).trim();
                    pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(lalo));
                    break;
                default:
                    break;
            }
            if (null != pointValue) {
                pointValues.add(pointValue);
            }
        }
    }
    nettyServerHandler.driverService.pointValueSender(pointValues);
}
 
Example 2
Source File: DataTypeCodec.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
private static Double binaryDecodeFLOAT8(int index, int len, ByteBuf buff) {
  return buff.getDouble(index);
}