This commit is contained in:
2026-06-09 15:30:06 +08:00
parent 665e3f3632
commit 1ece1b2336
4 changed files with 41 additions and 13 deletions

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -23,4 +23,5 @@ public class CommandUtils {
buf.writeByte(0x00);
buf.writeShort(0xAAAB);
}
}

View File

@@ -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);