From 1ece1b23364a41114a13c324f0459ed1cf98a6a4 Mon Sep 17 00:00:00 2001 From: rqian <1206436827@qq.com> Date: Tue, 9 Jun 2026 15:30:06 +0800 Subject: [PATCH] #update --- .../core/business/device/NettyDevice.java | 36 +++++++++++++++++-- .../com/maibu/service/DeviceTaskService.java | 15 ++++---- .../java/com/maibu/utils/CommandUtils.java | 1 + .../maibu/netty/handler/ClientHandler.java | 2 +- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java b/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java index 21c1625..0ccfd11 100644 --- a/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java +++ b/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java @@ -15,16 +15,20 @@ import com.maibu.mapper.WorkRecordMapper; import com.maibu.memory.GlobalMemory; import com.maibu.memory.SiteMemory; import com.maibu.utils.spring.SpringUtils; +import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import io.netty.util.CharsetUtil; import lombok.Data; import lombok.EqualsAndHashCode; import com.maibu.core.business.path.LatAndLngEntity; +import lombok.extern.slf4j.Slf4j; import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.LinkedList; import java.util.Queue; +@Slf4j @EqualsAndHashCode(callSuper = true) @Data public class NettyDevice extends Connector { @@ -65,6 +69,24 @@ public class NettyDevice extends Connector { this.deviceType = deviceType; } +// abaa 00 18 06 18 06 00 00 00 00 00 00 aaab +// +// ab aa 01 01 00 3c 88 +// 2d e0 48 05 40 40 +// 22 07 d0 42 c6 33 +// 5e 40 e8 03 00 00 aa ab + private static final byte[] PACKET = {(byte) 0xAB, (byte) 0xAA, + (byte) 0x00, (byte) 0x18,(byte) 0x06,(byte) 0x18,(byte) 0x06, + (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00, + (byte) 0xAA, (byte) 0xAB}; + + private static final byte[] route = {(byte) 0xab, (byte) 0xaa, + (byte) 0x01, (byte) 0x01,(byte) 0x00,(byte) 0x3c,(byte) 0x88, + (byte) 0x2d, (byte) 0xe0,(byte) 0x48,(byte) 0x05,(byte) 0x40,(byte) 0x40, + (byte) 0x22, (byte) 0x07,(byte) 0xd0,(byte) 0x42,(byte) 0xc6,(byte) 0x33, + (byte) 0x5e,(byte) 0x40,(byte) 0xe8,(byte) 0x03,(byte) 0x00,(byte) 0x00, + (byte) 0xaa, (byte) 0xab}; + //todo 重发 public void sendNextPoint() { if (task.getTaskStaus().equals(DeviceTaskStaus.PAUSE)) return; if (!locationQueue.isEmpty()) { @@ -77,8 +99,7 @@ public class NettyDevice extends Connector { routePlanSendEntity.setTargetLongitude(entity.getLng()); routePlanSendEntity.setSpeed((short) 1000); byte[] bytes = routePlanSendEntity.toBytes(); - System.out.println("====Lat:" + entity.getLat() + " ====Lng:" + entity.getLng()); - + log.debug("下发路径的报文:{}", toHexString(bytes)); currentPoint = entity; if (this.getChannel() != null && this.getChannel().isActive()) { this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes)); @@ -87,6 +108,14 @@ public class NettyDevice extends Connector { } } + private static String toHexString(byte[] bytes) { + StringBuilder sb = new StringBuilder(); + for (byte b : bytes) { + sb.append(String.format("%02X ", b)); + } + return sb.toString().trim(); + } + public synchronized void finishTask() { if (executingTask) { task.setTaskStaus(DeviceTaskStaus.FINISH); @@ -106,6 +135,7 @@ public class NettyDevice extends Connector { task.setUpdateTime(LocalDateTime.now()); devicePlanTaskMapper.saveOrUpdate(task); SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(), task.getSiteId()); + siteMemory.removeDevicePlanPrepare(task); siteMemory.removeDevicePlanExecute(task.getDeviceId()); task = null; currentTaskId = null; @@ -136,7 +166,7 @@ public class NettyDevice extends Connector { executingTask = true; sendNextPoint(); return true; - }else { + } else { return false; } } diff --git a/maibu-netty-server/src/main/java/com/maibu/service/DeviceTaskService.java b/maibu-netty-server/src/main/java/com/maibu/service/DeviceTaskService.java index 5ca60ad..13c4ac0 100644 --- a/maibu-netty-server/src/main/java/com/maibu/service/DeviceTaskService.java +++ b/maibu-netty-server/src/main/java/com/maibu/service/DeviceTaskService.java @@ -443,17 +443,14 @@ public class DeviceTaskService { } } else { Long taskId = dto.getTaskId(); - Long siteId = dto.getSiteId(); - Long orgId = dto.getOrgId(); +// Long siteId = dto.getSiteId(); +// Long orgId = dto.getOrgId(); DevicePlanTask devicePlanTask = devicePlanTaskMapper.selectById(taskId); if (devicePlanTask != null) { - devicePlanTask.setUpdateTime(LocalDateTime.now()); - devicePlanTask.setTaskStaus(DeviceTaskStaus.CANCELED); - devicePlanTask.setUpdateBy(username); - devicePlanTaskMapper.saveOrUpdate(devicePlanTask); - SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId); - siteMemory.removeDevicePlanPrepare(devicePlanTask); - siteMemory.removeDevicePlanExecute(devicePlanTask.getDeviceId()); + NettyDevice device = deviceSessionManager.getDevice(devicePlanTask.getDeviceId()); + if (device != null) { + return device.cancelTask(); + } } } return false; diff --git a/maibu-netty-server/src/main/java/com/maibu/utils/CommandUtils.java b/maibu-netty-server/src/main/java/com/maibu/utils/CommandUtils.java index b3e5365..83cc1f9 100644 --- a/maibu-netty-server/src/main/java/com/maibu/utils/CommandUtils.java +++ b/maibu-netty-server/src/main/java/com/maibu/utils/CommandUtils.java @@ -23,4 +23,5 @@ public class CommandUtils { buf.writeByte(0x00); buf.writeShort(0xAAAB); } + } diff --git a/maibu-web-middleware/src/main/java/com/maibu/netty/handler/ClientHandler.java b/maibu-web-middleware/src/main/java/com/maibu/netty/handler/ClientHandler.java index b060d2d..1981a3c 100644 --- a/maibu-web-middleware/src/main/java/com/maibu/netty/handler/ClientHandler.java +++ b/maibu-web-middleware/src/main/java/com/maibu/netty/handler/ClientHandler.java @@ -266,7 +266,7 @@ public class ClientHandler extends ChannelInboundHandlerAdapter { transferData.add(detail13); DeviceStatusDetail detail14 = new DeviceStatusDetail(); - detail14.setName("headingStatus"); + detail14.setName("qual"); detail14.setValue(split[14]); detail14.setUnit(""); transferData.add(detail14);