| | |
| | | import java.util.concurrent.ScheduledFuture; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import static com.ard.utils.other.ByteUtils.toLittleEndian; |
| | | |
| | | /** |
| | | * @Description: 客户端处理器 |
| | | * @ClassName: ClientHandler |
| | |
| | | byte[] cmdId = Arrays.copyOfRange(data, 1, 2);//命令ID |
| | | // log.info("命令ID:" + DatatypeConverter.printHexBinary(cmdId)); |
| | | byte[] payloadSize = Arrays.copyOfRange(data, 2, 4);//有效负载大小 |
| | | payloadSize = ByteUtils.toLittleEndian(payloadSize); |
| | | payloadSize = toLittleEndian(payloadSize); |
| | | //log.info("payloadSize:" + DatatypeConverter.printHexBinary(payloadSize)); |
| | | int payloadSizeToDecimal = ByteUtils.bytesToDecimal(payloadSize); |
| | | // log.info("有效负载大小(转整型):" + payloadSizeToDecimal); |
| | | //endregion |
| | | List<ArdAlarmRadar> radarAlarmInfos = new ArrayList<>(); |
| | | List<ArdAlarmRadar> radarFollowInfos = new ArrayList<>(); |
| | | //抽油机状态雷达推送集合 |
| | | List<ArdAlarmRadar> well = new ArrayList<>(); |
| | | String alarmTime = ""; |
| | | Integer targetNum = 0; |
| | | //雷达移动防火报警 |
| | | if (Arrays.equals(cmdId, new byte[]{0x01})) { |
| | | //region 告警信息反馈 |
| | | byte[] dwTim = Arrays.copyOfRange(data, 4, 8); |
| | | dwTim = ByteUtils.toLittleEndian(dwTim); |
| | | dwTim = toLittleEndian(dwTim); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | long l = ByteUtils.bytesToDecimal(dwTim); |
| | | alarmTime = sdf.format(l * 1000); |
| | | // log.info("周视图像的出现时间(转date):" + alarmTime); |
| | | |
| | | byte[] wTargetNum = Arrays.copyOfRange(data, 8, 10); |
| | | wTargetNum = ByteUtils.toLittleEndian(wTargetNum); |
| | | wTargetNum = toLittleEndian(wTargetNum); |
| | | targetNum = ByteUtils.bytesToDecimal(wTargetNum); |
| | | if (targetNum == 0) { |
| | | return; |
| | |
| | | Integer index = 68 + uintSize * i; |
| | | byte[] dwID = Arrays.copyOfRange(data, index, index + 4); |
| | | // log.info("目标ID:" + DatatypeConverter.printHexBinary(cmdId)); |
| | | dwID = ByteUtils.toLittleEndian(dwID); |
| | | dwID = toLittleEndian(dwID); |
| | | int id = ByteUtils.bytesToDecimal(dwID); |
| | | // log.info("目标ID号:" + id); |
| | | |
| | | byte[] iDistance = Arrays.copyOfRange(data, index + 8, index + 12); |
| | | iDistance = ByteUtils.toLittleEndian(iDistance); |
| | | iDistance = toLittleEndian(iDistance); |
| | | double Distance = ByteUtils.bytesToDecimal(iDistance); |
| | | log.debug("目标当前直线距离(m):" + Distance); |
| | | |
| | |
| | | //endregion |
| | | String alarmType = ""; |
| | | byte[] cStat = Arrays.copyOfRange(data, index + 23, index + 24); |
| | | cStat = ByteUtils.toLittleEndian(cStat); |
| | | String binaryString = String.format("%8s", Integer.toBinaryString(cStat[0] & 0xFF)).replace(' ', '0'); |
| | | // log.info("目标当前状态:" + binaryString); |
| | | cStat = toLittleEndian(cStat); |
| | | // 提取第4位至第6位的值 |
| | | int extractedValue = (cStat[0] >> 4) & 0b00001111; |
| | | // 判断提取的值 |
| | |
| | | alarmType = "热源检测"; |
| | | } |
| | | // log.info("报警类型:" + alarmType); |
| | | |
| | | byte[] szName = Arrays.copyOfRange(data, index + 64, index + 96); |
| | | String alarmPointName = ByteUtils.bytesToStringZh(szName); |
| | | // log.info("所属告警区域名称:" + alarmPointName); |
| | | byte[] afTx = Arrays.copyOfRange(data, index + 96, index + 100); |
| | | afTx = ByteUtils.toLittleEndian(afTx); |
| | | afTx = toLittleEndian(afTx); |
| | | float fTx = ByteUtils.bytesToFloat(afTx); |
| | | // log.info("水平角度:" + fTx); |
| | | byte[] afTy = Arrays.copyOfRange(data, index + 112, index + 116); |
| | | afTy = ByteUtils.toLittleEndian(afTy); |
| | | afTy = toLittleEndian(afTy); |
| | | float fTy = ByteUtils.bytesToFloat(afTy); |
| | | log.debug("垂直角度:" + fTy); |
| | | // 将角度转换为弧度 |
| | |
| | | ardAlarmRadar.setLatitude(alarmXY[1]); |
| | | ardAlarmRadar.setAlarmType(alarmType); |
| | | radarAlarmInfos.add(ardAlarmRadar); |
| | | int bit1 = (cStat[0]>>1) & 0x1;; |
| | | //目标的B1=1 锁定 |
| | | if(bit1==1) { |
| | | //将锁定目标放入锁定list |
| | | radarFollowInfos.add(ardAlarmRadar); |
| | | } |
| | | } |
| | | //endregion |
| | | if (StringUtils.isEmpty(alarmTime)) { |
| | |
| | | radarAlarmData.setAlarmTime(alarmTime); |
| | | radarAlarmData.setArdAlarmRadars(radarAlarmInfos); |
| | | MqttProducer.publish(2, false, "radar", JSON.toJSONString(radarAlarmData)); |
| | | if(radarFollowInfos.size()>0) { |
| | | radarAlarmData.setArdFollowRadars(radarFollowInfos); |
| | | MqttProducer.publish(2, false, "radarFollowGuide", JSON.toJSONString(radarAlarmData)); |
| | | } |
| | | //抽油机状态MQTT队列 |
| | | radarAlarmData.setArdAlarmRadars(well); |
| | | MqttProducer.publish(2, false, "radarWellData", JSON.toJSONString(radarAlarmData)); |
| | | |
| | | } |
| | | //抽油机AI状态反馈 |
| | | if (Arrays.equals(cmdId, new byte[]{0x04})) { |
| | | //region抽油机AI状态反馈 |
| | | String hexString = DatatypeConverter.printHexBinary(data); |
| | | //log.info(hexString); |
| | | |
| | | byte[] dwTim = Arrays.copyOfRange(data, 4, 8); |
| | | dwTim = ByteUtils.toLittleEndian(dwTim); |
| | | dwTim = toLittleEndian(dwTim); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | long l = ByteUtils.bytesToDecimal(dwTim); |
| | | alarmTime = sdf.format(l * 1000); |
| | | //log.info("周视图像的出现时间(转date):" + alarmTime); |
| | | |
| | | byte[] wTargetNum = Arrays.copyOfRange(data, 8, 10); |
| | | wTargetNum = ByteUtils.toLittleEndian(wTargetNum); |
| | | wTargetNum = toLittleEndian(wTargetNum); |
| | | targetNum = ByteUtils.bytesToDecimal(wTargetNum); |
| | | log.debug("目标总点数(转整型):" + targetNum); |
| | | if (targetNum == 0) { |
| | |
| | | Integer index = 68 + uintSize * i; |
| | | byte[] dwID = Arrays.copyOfRange(data, index, index + 4); |
| | | //log.info("目标ID:" + DatatypeConverter.printHexBinary(dwID)); |
| | | dwID = ByteUtils.toLittleEndian(dwID); |
| | | dwID = toLittleEndian(dwID); |
| | | int id = ByteUtils.bytesToDecimal(dwID); |
| | | //log.info("目标ID号:" + id); |
| | | //region 不需要的字段 |
| | | byte[] iTw = Arrays.copyOfRange(data, index + 4, index + 8); |
| | | iTw = ByteUtils.toLittleEndian(iTw); |
| | | iTw = toLittleEndian(iTw); |
| | | int Tw = ByteUtils.bytesToDecimal(iTw); |
| | | // log.info("目标当前的像素宽度:" + Tw); |
| | | |
| | | byte[] iTh = Arrays.copyOfRange(data, index + 8, index + 12); |
| | | iTh = ByteUtils.toLittleEndian(iTh); |
| | | iTh = toLittleEndian(iTh); |
| | | int Th = ByteUtils.bytesToDecimal(iTh); |
| | | //log.info("目标当前的像素高度:" + Th); |
| | | |
| | | byte[] fTx = Arrays.copyOfRange(data, index + 12, index + 16); |
| | | fTx = ByteUtils.toLittleEndian(fTx); |
| | | fTx = toLittleEndian(fTx); |
| | | float fTxAngle = ByteUtils.bytesToFloat(fTx); |
| | | log.debug("p角度:" + fTxAngle); |
| | | byte[] fTy = Arrays.copyOfRange(data, index + 16, index + 20); |
| | | fTy = ByteUtils.toLittleEndian(fTy); |
| | | fTy = toLittleEndian(fTy); |
| | | float fTyAngle = ByteUtils.bytesToFloat(fTy); |
| | | log.debug("t角度:" + fTyAngle); |
| | | |
| | | byte[] sAreaNo = Arrays.copyOfRange(data, index + 20, index + 22); |
| | | sAreaNo = ByteUtils.toLittleEndian(sAreaNo); |
| | | sAreaNo = toLittleEndian(sAreaNo); |
| | | int AreaNo = ByteUtils.bytesToDecimal(sAreaNo); |
| | | log.debug("目标归属的告警区域号:" + AreaNo); |
| | | |
| | | byte[] cGrp = Arrays.copyOfRange(data, index + 22, index + 23); |
| | | cGrp = ByteUtils.toLittleEndian(cGrp); |
| | | cGrp = toLittleEndian(cGrp); |
| | | int Grp = ByteUtils.bytesToDecimal(cGrp); |
| | | //log.info("所属组:" + Grp); |
| | | //endregion |
| | |
| | | //抽油机状态变量 |
| | | String wellType; |
| | | byte[] cStat = Arrays.copyOfRange(data, index + 23, index + 24); |
| | | cStat = ByteUtils.toLittleEndian(cStat); |
| | | cStat = toLittleEndian(cStat); |
| | | //String binaryString = String.format("%8s", Integer.toBinaryString(cStat[0] & 0xFF)).replace(' ', '0'); |
| | | //log.info("目标当前状态:" + binaryString); |
| | | // 提取第0位值 |
| | |
| | | radarAlarmData.setArdAlarmRadars(well); |
| | | MqttProducer.publish(2, false, "radarWellData", JSON.toJSONString(radarAlarmData)); |
| | | } |
| | | //强制引导 |
| | | if (Arrays.equals(cmdId, new byte[]{0x02})) { |
| | | //region 告警前端发送的强制引导信息 |
| | | byte[] iDistance = Arrays.copyOfRange(data, 4, 8); |
| | | iDistance = ByteUtils.toLittleEndian(iDistance); |
| | | iDistance = toLittleEndian(iDistance); |
| | | long distance = ByteUtils.bytesToDecimal(iDistance); |
| | | log.info("目标当前距离(m):" + distance); |
| | | byte[] fTx = Arrays.copyOfRange(data, 8, 12); |
| | | fTx = ByteUtils.toLittleEndian(fTx); |
| | | fTx = toLittleEndian(fTx); |
| | | float tx = ByteUtils.bytesToFloat(fTx); |
| | | log.debug("方位:" + tx); |
| | | byte[] fTy = Arrays.copyOfRange(data, 12, 16); |
| | | fTy = ByteUtils.toLittleEndian(fTy); |
| | | fTy = toLittleEndian(fTy); |
| | | float ty = ByteUtils.bytesToFloat(fTy); |
| | | if (ty < 0) { |
| | | ty += 360; |