栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

消防栓数据接入Java

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

消防栓数据接入Java

说明

接入为拓普索尔 无线智能消防栓监测终端

厂家报文说明

sample_data说明 

代码
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        ByteBuf buf = (ByteBuf) msg;
        byte[] req = new byte[buf.readableBytes()];
        buf.readBytes(req);

        String strReq = Util.bytesToHexString(req);
        log.info("收到的请求是:" + strReq);
        log.info("收到请求字节长度是:" + req.length);

        log.info("header:"+Util.convertHexToString(strReq.substring(0,8)));
        strReq = strReq.substring(8);
        log.info("type:"+strReq.substring(0,2));
        strReq = strReq.substring(2);

        log.info("length:" +Integer.parseInt(strReq.substring(0,4),16));
        strReq = strReq.substring(4);

        log.info("device type:" +strReq.substring(0,2));
        strReq = strReq.substring(2);

        log.info("device id:" +Util.convertHexToString(strReq.substring(0,32)));
        strReq = strReq.substring(32);

        log.info("send_time yy :" +strReq.substring(0,2));
        log.info("send_time mm :" +strReq.substring(2,4));
        log.info("send_time dd :" +strReq.substring(4,6));
        log.info("send_time hh :" +strReq.substring(6,8));
        log.info("send_time mm :" +strReq.substring(8,10));
        log.info("send_time ss:" +strReq.substring(10,12));
        strReq = strReq.substring(12);

        // 电池电量
        log.info("battery_level:" +Integer.parseInt(strReq.substring(0,2),16));
        strReq = strReq.substring(2);

        //信号强度
        log.info("signal_strength:" +Integer.parseInt(strReq.substring(0,2),16));
        strReq = strReq.substring(2);


        String dataHex = strReq.substring(0,8);
        log.info("sample_data:" +dataHex);
        Integer deviceType = Integer.parseInt(dataHex.substring(0,1),16);

        switch (deviceType){
            case 1:
                System.out.println("表示数据阈值下限告警");
                break;
            case 2:
                System.out.println("表示数据阈值上限");
                break;
            case 3:
                System.out.println("表示设备故障");
                break;
            case 4:
                System.out.println("表示数据动态变化阈值告警");
                break;
            case 5:
                System.out.println("表示碰撞告警");
                break;
            case 6:
                System.out.println("表示倾斜告警");
                break;
            case 7:
                System.out.println("表示水流告警");
                break;
            case 8:
                System.out.println("表示进水告警");
                break;
            case 9:
                System.out.println("表示低电量告警");
                break;
            default:
                break;
        }

        System.out.println("unit:"+Util.convertHexToUnit(dataHex.substring(1,2)));


        Integer validBit = Integer.parseInt(dataHex.substring(2,3));
        System.out.println("有效位数:"+ validBit);

        BigDecimal value = new BigDecimal(Math.pow(10,-validBit) * Integer.parseInt(dataHex.substring(3,8))).setScale(4, BigDecimal.ROUND_DOWN);
        System.out.println("value:"+ value);


        strReq = strReq.substring(8);
        log.info("crc16:" +strReq.substring(0,4));
        strReq = strReq.substring(4);

        log.info("iot:" +strReq.substring(0,6));

        buf.clear();
    }
工具类
    
    public static String convertHexToUnit(String hex){
        Integer hexInt = Integer.parseInt(hex,16);
        switch (hexInt){
            case 1:
                return "MPa";
            case 2:
                return "Bar";
            case 3:
                return "KPa";
            case 4:
                return "M";
            case 5:
                return "℃";
            case 6:
                return "m³/h";
            case 7:
                return "°";
            default:
                break;

        }
        return "";
    }

    
    public static String convertHexToString(String hex){
        StringBuilder sb = new StringBuilder();
        StringBuilder temp = new StringBuilder();
        for( int i=0; i 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/863139.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号