| | |
| | | |
| | | public static void main(String[] args) { |
| | | |
| | | double d1 = hexToBigInt("000906EB")/100.0; |
| | | double d2 = hexToBigInt("0004F6E6")/100.0; |
| | | // double d1 = hexToBigInt("000906EB")/100.0; |
| | | // double d2 = hexToBigInt("0004F6E6")/100.0; |
| | | // |
| | | // System.out.println(d1); |
| | | // System.out.println(d2); |
| | | // |
| | | // System.out.println(d1 + d2); |
| | | |
| | | System.out.println(d1); |
| | | System.out.println(d2); |
| | | |
| | | System.out.println(d1 + d2); |
| | | String kyeNumBin = "10100100"; |
| | | String key = "00000" + kyeNumBin.substring(0, 3); |
| | | |
| | | System.out.println("-----key-----" + key); |
| | | |
| | | String bin2hex = BytesUtil.bin2Hex(key); |
| | | |
| | | System.out.println("-----bin2hex-----" + bin2hex); |
| | | |
| | | int keyValue = BytesUtil.hexToInt(bin2hex); |
| | | |
| | | System.out.println("-----keyValue-----" + keyValue); |
| | | |
| | | key = "0000" + kyeNumBin.substring(4); |
| | | |
| | | System.out.println("-----key-----" + key); |
| | | |
| | | bin2hex = BytesUtil.bin2Hex(key); |
| | | System.out.println("-----bin2hex-----" + bin2hex); |
| | | keyValue = BytesUtil.hexToInt(bin2hex); |
| | | System.out.println("-----keyValue-----" + keyValue); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 将 4字节的16进制字符串,转换为32位带符号的十进制浮点型 |
| | | * |
| | | * <p> |
| | | * 42c60000 -> 99.00 |
| | | * |
| | | * @param str |
| | | * 4字节 16进制字符 |
| | | * @param str 4字节 16进制字符 |
| | | * @return |
| | | */ |
| | | public static float hexToFloat(String str) { |
| | |
| | | |
| | | /** |
| | | * 将带符号的32位浮点数装换为16进制 |
| | | * |
| | | * <p> |
| | | * 99.00 -> 42c60000 |
| | | * |
| | | * |
| | | * @param value |
| | | * @return |
| | |
| | | |
| | | /** |
| | | * 将二进制转换为10进制 |
| | | * |
| | | * @param binStr |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 二进制补码:取反口加1 |
| | | * |
| | | * @param str |
| | | * @return |
| | | */ |
| | |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.fzzy.api.data.PushProtocol; |
| | | import com.fzzy.data.ConfigData; |
| | | import com.fzzy.gateway.api.GatewayDeviceReportService; |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | |
| | | import com.fzzy.gateway.hx2023.data.WeightInfo; |
| | | import com.fzzy.gateway.hx2023.kafka.KafkaDeviceReportService; |
| | | import com.fzzy.mqtt.MqttGatewayService; |
| | | import jdk.nashorn.internal.runtime.regexp.joni.Config; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | private KafkaDeviceReportService kafkaDeviceReportService; |
| | | @Resource |
| | | private MqttGatewayService publishService; |
| | | @Resource |
| | | private ConfigData configData; |
| | | |
| | | @Override |
| | | public String getProtocol() { |
| | |
| | | String topic = ScConstant.TOPIC_REPORT; |
| | | topic = topic.replace("${productId}", reqData.getProductId()).replace("${deviceId}", reqData.getDeviceId()); |
| | | |
| | | //如果是测试模式不执行推送 |
| | | if(configData.getActive().indexOf("dev")>=0){ |
| | | |
| | | log.info("----------------------------推送MQTT粮情信息,注:调试模式不推送---------------------------"); |
| | | log.info("-----TOPIC-----{}", topic); |
| | | log.info("-----Message-----{}", reqData.getData()); |
| | | |
| | | return new BaseResp(); |
| | | } |
| | | |
| | | publishService.publishMqttWithTopic(reqData.getData(), topic); |
| | | |
| | | log.info("----------------------------推送MQTT粮情信息---------------------------"); |
| | |
| | | package com.fzzy.protocol.youxian0.analysis; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fzzy.api.Constant; |
| | | import com.fzzy.api.data.GatewayDeviceType; |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.api.utils.NumberUtil; |
| | |
| | | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | |
| | | |
| | | private static Map<String, GrainRoot> contextGrainRoot = new HashMap<>(); |
| | | |
| | |
| | | |
| | | //粮情返回 |
| | | if (ServiceUtils.FUNCTION_66.equalsIgnoreCase(funId)) { |
| | | |
| | | log.info("---------开始解析粮情信息---------"); |
| | | this.analysisGrainStep1(device, msgId, strMsg); |
| | | } |
| | | |
| | | //温湿度返回 |
| | | if (ServiceUtils.FUNCTION_68.equalsIgnoreCase(funId)) { |
| | | log.info("---------开始解析仓温湿度信息---------"); |
| | | this.analysisGrainTh(device, strMsg); |
| | | } |
| | | |
| | |
| | | String kyeNumHex = strMsg.substring(2, 4); |
| | | String kyeNumBin = BytesUtil.toBinary8String(BytesUtil.hexToInt(kyeNumHex)); |
| | | |
| | | String key = kyeNumBin.substring(0, 3); |
| | | String key = "00000" + kyeNumBin.substring(0, 3); |
| | | int keyValue = BytesUtil.hexToInt(BytesUtil.bin2Hex(key)); |
| | | key = kyeNumBin.substring(4); |
| | | key = "0000" + kyeNumBin.substring(4); |
| | | int numValue = BytesUtil.hexToInt(BytesUtil.bin2Hex(key)); |
| | | |
| | | //02 A4 BB BA BA B4 |
| | |
| | | point = this.getGrainTemp(keyValue, tempHex); |
| | | log.debug("--------解析后的温度点----{}---{}", tempHex, point); |
| | | grainRoot.getPoints().add(point); |
| | | start = 2 * 2; |
| | | } |
| | | |
| | | |
| | |
| | | log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", reqData.getDevice().getDeviceName()); |
| | | return; |
| | | } |
| | | |
| | | reportService.reportGrainData(reqData); |
| | | } |
| | | |
| | |
| | | InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); |
| | | |
| | | log.info("连接终端掉线,IP={},port={}", socketAddress.getAddress(), socketAddress.getPort()); |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | String hexStr = ""; |
| | | InvokeResult message; |
| | | for (int i = 1; i <= cableX; i++) { |
| | | if (1 == i) start = 255; |
| | | start = i * cableY + 1; |
| | | if (1 == i) { |
| | | start = 255; |
| | | } else { |
| | | start = (i - 1) * cableY + 1; |
| | | } |
| | | |
| | | hexStr = this.buildGrainCmd(device, i, start, length); |
| | | |
| | | // 发送命令 |
| | | Channel channel = ClientEngine.getChannel(device.getIp()); |
| | | // 发送命令 TODO----->>>暂时调整为每次创建一个新连接 |
| | | //Channel channel = ClientEngine.getChannel(device.getIp()); |
| | | Channel channel = null; |
| | | if (null == channel) { |
| | | ClientEngine clientEngine = new ClientEngine(device.getIp(), device.getPort()); |
| | | clientEngine.start(); |
| | | Thread.sleep(500); |
| | | Thread.sleep(300); |
| | | channel = clientEngine.getChannel(); |
| | | } |
| | | message = ClientEngine.send2(hexStr, channel); |
| | | |
| | | log.error("平台------>>>>控制柜:发送粮情检测命令-{}", message); |
| | | log.error("平台------>>>>主控:发送粮情检测命令-{}---{}", message,hexStr); |
| | | |
| | | // 封装返回信息 |
| | | if (!InvokeResult.SUCCESS.getCode().equals(message.getCode())) { |
| | |
| | | //开始封装消息体-主机ID |
| | | String deviceSn = device.getDeviceSn(); |
| | | deviceSn = BytesUtil.intToHexStr1(Integer.valueOf(deviceSn)); |
| | | content = content.replaceAll("\\{id}", deviceSn); |
| | | content = content.replace("{id}", deviceSn); |
| | | content = content.replace("{id}", deviceSn); |
| | | |
| | | //命令ID |
| | | String msgIdHex = BytesUtil.intToHexStr1(cur); |
| | | content = content.replace("\\{msgId}", msgIdHex); |
| | | content = content.replace("{msgId}", msgIdHex); |
| | | |
| | | //命令类型 |
| | | content = content.replace("\\{funId}", ServiceUtils.FUNCTION_66); |
| | | content = content.replace("{funId}", ServiceUtils.FUNCTION_66); |
| | | |
| | | //开始根号 |
| | | String startCurHex = BytesUtil.intToHexStr1(startCur); |
| | | content = content.replace("\\{start}", startCurHex); |
| | | content = content.replace("{start}", startCurHex); |
| | | |
| | | //截取长度 |
| | | String lenHex = BytesUtil.intToHexStr1(length); |
| | | content = content.replace("\\{length}", lenHex); |
| | | content = content.replace("{length}", lenHex); |
| | | |
| | | //校验码 |
| | | String crcCode = this.getCRC(content); |