diff --git a/sec-api/src/main/java/com/imdroid/secapi/client/RtcmClient.java b/sec-api/src/main/java/com/imdroid/secapi/client/RtcmClient.java index 2781e2b0..50442e01 100644 --- a/sec-api/src/main/java/com/imdroid/secapi/client/RtcmClient.java +++ b/sec-api/src/main/java/com/imdroid/secapi/client/RtcmClient.java @@ -1,6 +1,7 @@ package com.imdroid.secapi.client; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -11,7 +12,10 @@ public interface RtcmClient { @PostMapping("/config_by_udp") HttpResp configByUdp(@RequestParam(name = "deviceId") String deviceId, @RequestParam(name = "configuration") String configData); - + @PostMapping(value = "/config_device") + public HttpResp configDevice(@RequestParam(name = "deviceId") String deviceId, @RequestParam(name = "configuration") String configData); + @GetMapping(value = "/get_device_info") + public HttpResp getDeviceInfo(@RequestParam(name = "deviceId") String deviceId, @RequestParam(name = "cmd") String cmd); @PostMapping("/device_param_changed") HttpResp deviceParamChanged(@RequestParam(name = "deviceId") String deviceId,@RequestParam(name = "oldParentId") String oldParentId); diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/executor/D331RtcmMessageExecutor.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/executor/D331RtcmMessageExecutor.java index 6240d092..7e30d7d1 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/executor/D331RtcmMessageExecutor.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/executor/D331RtcmMessageExecutor.java @@ -8,6 +8,7 @@ import com.imdroid.sideslope.bd.Gga; import com.imdroid.sideslope.message.D331RtcmMessage; import com.imdroid.sideslope.sal.Device; import com.imdroid.sideslope.sal.DeviceService; +import com.imdroid.sideslope.server.DeviceChannel; import com.imdroid.sideslope.server.OnlineChannels; import com.imdroid.sideslope.service.DataPersistService; import io.netty.buffer.ByteBuf; @@ -49,10 +50,18 @@ public class D331RtcmMessageExecutor implements Executor // 要求快速转发,因此用缓存,不要每次都查数据库 List deviceList = deviceService.findByParentId(id); //logger.debug("base station {} has {} rovers: ", message.getId(),deviceList.size()); + DeviceChannel deviceChannel = null; for (Device device : deviceList) { if (device.getOpMode() != GnssDevice.OP_MODE_USE) continue; String deviceId = device.getDeviceId(); - OnlineChannels.INSTANCE.get(deviceId).ifPresent(deviceChannel -> { + if(device.getDataChannelType() == Device.CHANNEL_TYPE_UDP) { + deviceChannel = OnlineChannels.INSTANCE.getDataChannel(deviceId); + } + else { + deviceChannel = OnlineChannels.INSTANCE.getConfigChannel(deviceId); + } + + if(deviceChannel!=null && deviceChannel.isOnline()){ if (logger.isDebugEnabled()) { logger.debug("forward d331 rtcm to device {}", deviceId); } @@ -62,7 +71,7 @@ public class D331RtcmMessageExecutor implements Executor ByteBuf buf = Unpooled.buffer(); buf.writeBytes(forwardBytes); deviceChannel.writeAndFlush(buf); - }); + } } } diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/sal/Device.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/sal/Device.java index 8b40a4f0..a1e80fe3 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/sal/Device.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/sal/Device.java @@ -26,6 +26,9 @@ public class Device { */ public static final int DEVICE_ROVER = 0; + public static final byte CHANNEL_TYPE_TCP = 0; + public static final byte CHANNEL_TYPE_UDP = 1; + private String name; private Integer tenantId; @@ -77,6 +80,8 @@ public class Device { LocalDateTime lastValidCalcDataTime; //最近一次有效解 int warningcode = 0; short abnormalD341Num = 0; + byte cfgChannelType = CHANNEL_TYPE_TCP; // 0:TCP;1:DUP + byte dataChannelType = CHANNEL_TYPE_UDP; // 0:TCP;1:DUP public void updateRx(int head, int bytes,int count){ lastRxHead = head; diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/web/ApiController.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/web/ApiController.java index 5fbc2585..75d3552a 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/web/ApiController.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/web/ApiController.java @@ -4,6 +4,7 @@ import com.imdroid.common.util.DataTypeUtil; import com.imdroid.secapi.client.HttpResp; import com.imdroid.sideslope.calc.MultiLineGNSSCalcService; import com.imdroid.sideslope.calc.SingleLineGNSSCalcService; +import com.imdroid.sideslope.sal.Device; import com.imdroid.sideslope.sal.LocalDeviceServiceImpl; import com.imdroid.sideslope.server.DeviceChannel; import com.imdroid.sideslope.server.OnlineChannels; @@ -13,6 +14,7 @@ import io.netty.buffer.Unpooled; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; @@ -97,6 +99,75 @@ public class ApiController { return resp; } + @PostMapping(value = "/config_device") + public HttpResp configDevice(String deviceId, String configuration) { + Map status = new HashMap<>(); + HttpResp resp = new HttpResp(); + // set channel0/channel1 tcp/udp + String[] paras = configuration.split("=| "); + Device device = localDeviceService.findByDeviceId(deviceId); + if(device!=null){ + resp.setResponseMessage("set OK."); + if(paras.length>=3){ + if(paras[1].equals("channel1")){ + if(paras[2].equals("tcp")) device.setDataChannelType(Device.CHANNEL_TYPE_TCP); + else device.setDataChannelType(Device.CHANNEL_TYPE_UDP); + } + else if(paras[1].equals("channel0")){ + if(paras[2].equals("tcp")) device.setCfgChannelType(Device.CHANNEL_TYPE_TCP); + else device.setCfgChannelType(Device.CHANNEL_TYPE_UDP); + } + } + else{ + status.put("paras", "error"); + } + } + else { + status.put("status", "Offline"); + resp.setCode(HttpResp.HTTP_RSP_FAILED); + resp.setResponseMessage("Offline."); + } + resp.setResponseObject(status); + return resp; + } + + @GetMapping(value = "/get_device_info") + public HttpResp getDeviceInfo(String deviceId, String cmd) { + Map status = new HashMap<>(); + HttpResp resp = new HttpResp(); + // get channel0/channel1 type + String[] paras = cmd.split("=| "); + Device device = localDeviceService.findByDeviceId(deviceId); + if(device!=null){ + resp.setResponseMessage("set OK."); + if(paras.length>=3){ + if(paras[2].equals("type")) { + if (paras[1].equals("channel1")) { + if (device.getDataChannelType()==Device.CHANNEL_TYPE_TCP) { + resp.setResponseMessage(paras[1]+" tcp"); + } + else resp.setResponseMessage(paras[1]+" udp"); + } else if (paras[1].equals("channel0")) { + if (device.getCfgChannelType()==Device.CHANNEL_TYPE_TCP) { + resp.setResponseMessage(paras[1]+" tcp"); + } + else resp.setResponseMessage(paras[1]+" udp"); + } + } + } + else{ + status.put("paras", "error"); + } + } + else { + status.put("status", "Offline"); + resp.setCode(HttpResp.HTTP_RSP_FAILED); + resp.setResponseMessage("Offline."); + } + resp.setResponseObject(status); + return resp; + } + @PostMapping("/device_param_changed") public HttpResp deviceParamChanged(String deviceId, String oldParentId) { // 更新设备缓存 diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/controller/CmdLineController.java b/sec-beidou/src/main/java/com/imdroid/beidou/controller/CmdLineController.java index 2c9cebd3..4993057e 100644 --- a/sec-beidou/src/main/java/com/imdroid/beidou/controller/CmdLineController.java +++ b/sec-beidou/src/main/java/com/imdroid/beidou/controller/CmdLineController.java @@ -70,24 +70,36 @@ public class CmdLineController extends BasicController{ return HttpResult.fail("设备号不能为空"); } - String sendCmd = cmd.replaceAll(" +",""); + String sendCmd; short len = 0; int msgType = 0xD310 + cmdType; - if(cmdType == 10 || cmdType==11){ // DTU,string format - len = (short) (sendCmd.length() + 5); - sendCmd = Integer.toHexString(msgType) + HexUtil.Short2HexString(len)+ - HexUtil.Int2HexString(Integer.parseInt(deviceId))+ - "01"+HexUtil.String2HexString(sendCmd); - } - else{ //hex format - len = (short) (sendCmd.length()/2+4); - sendCmd = Integer.toHexString(msgType) + HexUtil.Short2HexString(len)+ - HexUtil.Int2HexString(Integer.parseInt(deviceId))+sendCmd; - } HttpResp> rsp; - if(sendChannel == 0) - rsp = rtcmClient.config(deviceId,sendCmd); - else rsp = rtcmClient.configByUdp(deviceId,sendCmd); + + if(cmd.startsWith("set")||cmd.startsWith("get")){ + msgType = 0xD3FF;//后台命令 + sendCmd = cmd; + len = (short) cmd.length(); + if(cmd.charAt(0)=='s') rsp = rtcmClient.configDevice(deviceId,sendCmd); + else rsp = rtcmClient.getDeviceInfo(deviceId,sendCmd); + } + else{ + sendCmd = cmd.replaceAll(" +",""); + + if(cmdType == 10 || cmdType==11){ // DTU,string format + len = (short) (sendCmd.length() + 5); + sendCmd = Integer.toHexString(msgType) + HexUtil.Short2HexString(len)+ + HexUtil.Int2HexString(Integer.parseInt(deviceId))+ + "01"+HexUtil.String2HexString(sendCmd); + } + else{ //hex format + len = (short) (sendCmd.length()/2+4); + sendCmd = Integer.toHexString(msgType) + HexUtil.Short2HexString(len)+ + HexUtil.Int2HexString(Integer.parseInt(deviceId))+sendCmd; + } + if(sendChannel == 0) + rsp = rtcmClient.config(deviceId,sendCmd); + else rsp = rtcmClient.configByUdp(deviceId,sendCmd); + } String txInfo = "TX "+ dateFormat.format(System.currentTimeMillis())+ " "+deviceId+" "+sendCmd; @@ -95,6 +107,9 @@ public class CmdLineController extends BasicController{ if(rsp.getCode() != HttpResp.HTTP_RSP_OK){ txInfo += "\r\n" + rsp.getResponseMessage(); } + else if(msgType == 0xD3FF){ + txInfo += "\r\n" + rsp.getResponseMessage(); + } // 保存 GnssMsg gnssMsg = new GnssMsg();