1、增加设置后台命令,数据从UDP或TCP发送
This commit is contained in:
parent
d51b83069b
commit
f415441562
@ -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);
|
||||
|
||||
|
||||
@ -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<D331RtcmMessage, Void>
|
||||
// 要求快速转发,因此用缓存,不要每次都查数据库
|
||||
List<Device> 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<D331RtcmMessage, Void>
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
buf.writeBytes(forwardBytes);
|
||||
deviceChannel.writeAndFlush(buf);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<String, Object> 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<String, Object> 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) {
|
||||
// 更新设备缓存
|
||||
|
||||
@ -70,9 +70,21 @@ public class CmdLineController extends BasicController{
|
||||
return HttpResult.fail("设备号不能为空");
|
||||
}
|
||||
|
||||
String sendCmd = cmd.replaceAll(" +","");
|
||||
String sendCmd;
|
||||
short len = 0;
|
||||
int msgType = 0xD310 + cmdType;
|
||||
HttpResp<HashMap<String, Object>> rsp;
|
||||
|
||||
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)+
|
||||
@ -84,10 +96,10 @@ public class CmdLineController extends BasicController{
|
||||
sendCmd = Integer.toHexString(msgType) + HexUtil.Short2HexString(len)+
|
||||
HexUtil.Int2HexString(Integer.parseInt(deviceId))+sendCmd;
|
||||
}
|
||||
HttpResp<HashMap<String, Object>> rsp;
|
||||
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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user