驾舱IP
This commit is contained in:
parent
c7dc602b7f
commit
11501f8e96
@ -1,13 +1,14 @@
|
||||
package cn.iocoder.yudao.module.remote.api.robot;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.module.remote.config.ip.IpProperties;
|
||||
import cn.iocoder.yudao.module.remote.controller.admin.robot.dto.Cockpit;
|
||||
import cn.iocoder.yudao.module.remote.controller.admin.robot.dto.RemoteControllerSocketDTO;
|
||||
import cn.iocoder.yudao.module.remote.enums.robot.RemoteIpTypeEnum;
|
||||
import cn.iocoder.yudao.module.remote.util.crc.CRCUtil;
|
||||
import cn.iocoder.yudao.module.system.api.remote.dto.RemoteRobotTransferDTO;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -35,11 +36,6 @@ public class RemoteControllerProcessor {
|
||||
@Value("${remote.msg}")
|
||||
private String defaultMsg;
|
||||
|
||||
@Value("${remote.controller-ip}")
|
||||
private String remoteControllerIp;
|
||||
|
||||
@Value("${remote.controller-port}")
|
||||
private int remoteControllerPort;
|
||||
|
||||
@Value("${remote.cockpit-time-out}")
|
||||
private int cockpitTimeOut;
|
||||
@ -53,8 +49,15 @@ public class RemoteControllerProcessor {
|
||||
private final String ONE = "01";
|
||||
private final String TWO = "02";
|
||||
|
||||
public void addCache(RemoteRobotTransferDTO dto) {
|
||||
RemoteControllerSocketDTO remoteControllerSocketDTO = cache.get(remoteControllerIp);
|
||||
@Autowired
|
||||
private IpProperties ipProperties;
|
||||
|
||||
public void addCache(RemoteRobotTransferDTO dto,String ip) {
|
||||
Cockpit cockpit = ipProperties.getCockpitByIp(ip);
|
||||
String cockpitIp = cockpit.getControllerIp();
|
||||
int cockpitPort = cockpit.getControllerPort();
|
||||
|
||||
RemoteControllerSocketDTO remoteControllerSocketDTO = cache.get(cockpitIp);
|
||||
log.info("是否为空 :{}",ObjectUtil.isEmpty(remoteControllerSocketDTO));
|
||||
if (ObjectUtil.isNotEmpty(remoteControllerSocketDTO)) {
|
||||
try {
|
||||
@ -62,26 +65,26 @@ public class RemoteControllerProcessor {
|
||||
if (socket != null && !socket.isClosed()) {
|
||||
socket.close();
|
||||
}
|
||||
log.info("关闭socket :{}", remoteControllerIp);
|
||||
log.info("关闭socket :{}", cockpitIp);
|
||||
} catch (IOException e) {
|
||||
log.error("关闭socket出现异常 :{}", remoteControllerIp);
|
||||
log.error("关闭socket出现异常 :{}", cockpitIp);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
remoteControllerSocketDTO = new RemoteControllerSocketDTO();
|
||||
}
|
||||
remoteControllerSocketDTO.setHost(remoteControllerIp);
|
||||
remoteControllerSocketDTO.setPort(remoteControllerPort);
|
||||
remoteControllerSocketDTO.setControllerIp(cockpitIp);
|
||||
remoteControllerSocketDTO.setControllerPort(cockpitPort);
|
||||
Socket socket = new Socket();
|
||||
try {
|
||||
socket.connect(new InetSocketAddress(remoteControllerIp, remoteControllerPort), 1000);
|
||||
socket.connect(new InetSocketAddress(cockpitIp, cockpitPort), 1000);
|
||||
remoteControllerSocketDTO.setSocket(socket);
|
||||
} catch (IOException e) {
|
||||
log.error("添加socket失败 :{}", e);
|
||||
throw exception(REMOTE_ROBOT_CONNECT_FAIL);
|
||||
}
|
||||
setMsg(remoteControllerSocketDTO, RemoteIpTypeEnum.ONE.getType(), dto);
|
||||
cache.put(remoteControllerIp, remoteControllerSocketDTO);
|
||||
cache.put(cockpitIp, remoteControllerSocketDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,34 +139,36 @@ public class RemoteControllerProcessor {
|
||||
remoteControllerSocket.setMsg(msg);
|
||||
}
|
||||
|
||||
public void remoteCache(RemoteRobotTransferDTO dto) {
|
||||
RemoteControllerSocketDTO remoteControllerSocketDTO = cache.get(remoteControllerIp);
|
||||
public void remoteCache(RemoteRobotTransferDTO dto,String ip) {
|
||||
Cockpit cockpit = ipProperties.getCockpitByIp(ip);
|
||||
String cockpitIp = cockpit.getControllerIp();
|
||||
RemoteControllerSocketDTO remoteControllerSocketDTO = cache.get(cockpitIp);
|
||||
if (ObjectUtil.isEmpty(remoteControllerSocketDTO)) {
|
||||
return;
|
||||
}
|
||||
setMsg(remoteControllerSocketDTO, RemoteIpTypeEnum.THREE.getType(), dto);
|
||||
cache.remove(remoteControllerIp);
|
||||
cache.remove(cockpitIp);
|
||||
|
||||
Socket socket = remoteControllerSocketDTO.getSocket();
|
||||
if (socket == null || socket.isClosed()) {
|
||||
try {
|
||||
socket = new Socket();
|
||||
socket.connect(new InetSocketAddress(remoteControllerIp, remoteControllerPort), 1000);
|
||||
socket.connect(new InetSocketAddress(cockpitIp, cockpit.getControllerPort()), 1000);
|
||||
} catch (IOException e) {
|
||||
log.error("连接socket出现异常 :{}", remoteControllerIp);
|
||||
log.error("连接socket出现异常 :{}", cockpitIp);
|
||||
}
|
||||
}
|
||||
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = socket.getOutputStream();
|
||||
log.info("断开连接 :{} ,对应的IP :{}", remoteControllerSocketDTO.getMsg(), remoteControllerSocketDTO.getHost());
|
||||
log.info("断开连接 :{} ,对应的IP :{}", remoteControllerSocketDTO.getMsg(), remoteControllerSocketDTO.getControllerIp());
|
||||
os.write(remoteControllerSocketDTO.getMsg().getBytes());
|
||||
socket.shutdownInput();
|
||||
socket.close();
|
||||
log.info("关闭socket :{}", remoteControllerIp);
|
||||
log.info("关闭socket :{}", cockpitIp);
|
||||
} catch (IOException e) {
|
||||
log.error("关闭socket出现异常 :{}", remoteControllerIp);
|
||||
log.error("关闭socket出现异常 :{}", cockpitIp);
|
||||
} finally {
|
||||
if (ObjectUtil.isNotEmpty(os)) {
|
||||
try {
|
||||
@ -173,7 +178,7 @@ public class RemoteControllerProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
remoteCache(dto);
|
||||
remoteCache(dto,ip);
|
||||
}
|
||||
|
||||
|
||||
@ -189,25 +194,12 @@ public class RemoteControllerProcessor {
|
||||
// log.info("socket发送数据开始");
|
||||
for (Map.Entry<String, RemoteControllerSocketDTO> v : cache.entrySet()) {
|
||||
RemoteControllerSocketDTO remoteControllerSocketDTO = v.getValue();
|
||||
if (ObjectUtil.isEmpty(remoteControllerSocketDTO)) {
|
||||
remoteControllerSocketDTO = new RemoteControllerSocketDTO();
|
||||
remoteControllerSocketDTO.setHost(v.getKey());
|
||||
remoteControllerSocketDTO.setPort(remoteControllerPort);
|
||||
try {
|
||||
Socket socket = new Socket();
|
||||
socket.connect(new InetSocketAddress(v.getKey(), remoteControllerPort), 1000);
|
||||
remoteControllerSocketDTO.setSocket(socket);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
cache.put(v.getKey(), remoteControllerSocketDTO);
|
||||
}
|
||||
|
||||
Socket socket = remoteControllerSocketDTO.getSocket();
|
||||
if (socket == null || socket.isClosed()) {
|
||||
socket = new Socket();
|
||||
try {
|
||||
socket.connect(new InetSocketAddress(v.getKey(), remoteControllerPort), 1000);
|
||||
socket.connect(new InetSocketAddress(v.getKey(), remoteControllerSocketDTO.getControllerPort()), 1000);
|
||||
remoteControllerSocketDTO.setSocket(socket);
|
||||
} catch (IOException e) {
|
||||
log.error("socket重连异常 :{}", e);
|
||||
|
@ -0,0 +1,31 @@
|
||||
package cn.iocoder.yudao.module.remote.config.ip;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.remote.controller.admin.robot.dto.Cockpit;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix ="remote",ignoreInvalidFields = true)
|
||||
@Getter
|
||||
@Setter
|
||||
public class IpProperties {
|
||||
|
||||
private List<Cockpit> cockpit;
|
||||
|
||||
public Cockpit getCockpitByIp(String ip) {
|
||||
for (Cockpit v : cockpit) {
|
||||
if (ip.equals(v.getControllerIp())){
|
||||
return v;
|
||||
}
|
||||
}
|
||||
Cockpit data = new Cockpit();
|
||||
data.setControllerIp("127.0.0.1");
|
||||
data.setControllerPort(9000);
|
||||
return data;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package cn.iocoder.yudao.module.remote.controller.admin.robot.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Cockpit {
|
||||
@Schema(description = "驾舱端口")
|
||||
private int controllerPort;
|
||||
@Schema(description = "驾舱IP")
|
||||
private String controllerIp;
|
||||
}
|
@ -1,13 +1,16 @@
|
||||
package cn.iocoder.yudao.module.remote.controller.admin.robot.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
@Data
|
||||
public class RemoteControllerSocketDTO {
|
||||
private String host;
|
||||
private int port;
|
||||
@Schema(description = "驾舱IP")
|
||||
private String controllerIp;
|
||||
@Schema(description = "驾舱端口")
|
||||
private int controllerPort;
|
||||
private Socket socket;
|
||||
private String msg;
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ import cn.iocoder.yudao.module.remote.api.path.dto.RemoteRobotDistanceInformatio
|
||||
import cn.iocoder.yudao.module.remote.api.path.dto.RemoteRobotWirelessSignalDTO;
|
||||
import cn.iocoder.yudao.module.remote.api.robot.RemoteControllerProcessor;
|
||||
import cn.iocoder.yudao.module.remote.api.webSocket.RequestProcessor;
|
||||
import cn.iocoder.yudao.module.remote.config.ip.IpProperties;
|
||||
import cn.iocoder.yudao.module.remote.constant.robot.RobotTaskChcheConstant;
|
||||
import cn.iocoder.yudao.module.remote.controller.admin.robot.dto.Cockpit;
|
||||
import cn.iocoder.yudao.module.remote.controller.admin.robot.dto.PositionMapRespDTO;
|
||||
import cn.iocoder.yudao.module.remote.controller.admin.robot.dto.RemoteRobotChangeModeDTO;
|
||||
import cn.iocoder.yudao.module.remote.controller.admin.robot.dto.RemoteRobotTaskDoneDTO;
|
||||
@ -23,6 +25,7 @@ import cn.iocoder.yudao.module.system.api.remote.dto.RemoteRobotTransferDTO;
|
||||
import cn.iocoder.yudao.module.system.api.robot.dto.FloorZoneDTO;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -43,17 +46,11 @@ public class RemoteRobotServiceImpl implements RemoteRobotService {
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Resource
|
||||
private RequestProcessor processor;
|
||||
|
||||
@Resource
|
||||
private RemoteControllerProcessor remoteControllerProcessor;
|
||||
|
||||
@Value("${remote.controller-port}")
|
||||
private int remoteControllerPort;
|
||||
|
||||
@Value("${remote.controller-ip}")
|
||||
private String remoteControllerIp;
|
||||
@Autowired
|
||||
private IpProperties ipProperties;
|
||||
|
||||
/**
|
||||
* 获取地图区域对应的机器人信息
|
||||
@ -128,15 +125,16 @@ public class RemoteRobotServiceImpl implements RemoteRobotService {
|
||||
@Override
|
||||
public void robotChangeMode(RemoteRobotChangeModeDTO data, HttpServletRequest request) {
|
||||
String ip = IpUtils.getIp(request);
|
||||
CommonResult<RemoteRobotTransferDTO> result = remoteRobotApi.robotChangeMode(data.getRemoteMode(), ip, data.getRobotNo(),remoteControllerPort,remoteControllerIp);
|
||||
Cockpit cockpit = ipProperties.getCockpitByIp(ip);
|
||||
CommonResult<RemoteRobotTransferDTO> result = remoteRobotApi.robotChangeMode(data.getRemoteMode(), ip, data.getRobotNo(),cockpit.getControllerPort(),cockpit.getControllerIp());
|
||||
if (!result.isSuccess()) {
|
||||
throw exception0(TASK_COMMONG_FAIL.getCode(), result.getMsg());
|
||||
}
|
||||
//非自动模式
|
||||
if (0!= data.getRemoteMode()) {
|
||||
remoteControllerProcessor.addCache(result.getData());
|
||||
remoteControllerProcessor.addCache(result.getData(),ip);
|
||||
}else {
|
||||
remoteControllerProcessor.remoteCache(result.getData());
|
||||
remoteControllerProcessor.remoteCache(result.getData(),ip);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +161,7 @@ public class RemoteRobotServiceImpl implements RemoteRobotService {
|
||||
return;
|
||||
}
|
||||
|
||||
remoteControllerProcessor.remoteCache(result.getData());
|
||||
remoteControllerProcessor.remoteCache(result.getData(),ip);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,8 +53,11 @@ logging:
|
||||
name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径
|
||||
|
||||
remote:
|
||||
controller-port: 9000
|
||||
controller-ip: 127.0.0.1
|
||||
cockpit:
|
||||
- controllerPort: 9001
|
||||
controllerIp: 127.0.0.2
|
||||
- controllerPort: 9001
|
||||
controllerIp: 127.0.0.3
|
||||
msg: AA 55 13 04 01 88 88 # 驾舱socket头信息
|
||||
cockpit-time-out: 120 # 驾舱超时报警时间
|
||||
industrial-control-time-out: 120 # 工控通信超时报警时间
|
||||
|
@ -53,8 +53,11 @@ logging:
|
||||
name: C:\system\install\log/${spring.application.name}.log
|
||||
|
||||
remote:
|
||||
controller-port: 9000
|
||||
controller-ip: 127.0.0.1
|
||||
cockpit: # 远遥控制车辆最大速度 m/s
|
||||
- controllerPort: 9001
|
||||
controllerIp: 127.0.0.2
|
||||
- controllerPort: 9001
|
||||
controllerIp: 127.0.0.3
|
||||
msg: AA 55 13 04 01 88 88 # 驾舱socket头信息
|
||||
cockpit-time-out: 120 # 驾舱超时报警时间
|
||||
industrial-control-time-out: 120 # 工控通信超时报警时间
|
||||
|
@ -34,8 +34,11 @@ logging:
|
||||
name: D:/project/rcs/logs/${spring.application.name}.log
|
||||
|
||||
remote:
|
||||
controller-port: 9000
|
||||
controller-ip: 127.0.0.1
|
||||
cockpit:
|
||||
- controllerPort: 9001
|
||||
controllerIp: 127.0.0.2
|
||||
- controllerPort: 9001
|
||||
controllerIp: 127.0.0.3
|
||||
msg: AA 55 13 04 01 88 88 # 驾舱socket头信息
|
||||
cockpit-time-out: 120 # 驾舱超时报警时间
|
||||
industrial-control-time-out: 120 # 工控通信超时报警时间
|
||||
|
Loading…
Reference in New Issue
Block a user