Merge pull request '添加备用基站' (#15) from feature/backup-basestation into develop
Reviewed-on: #15
This commit is contained in:
commit
8115e54fcc
@ -81,6 +81,8 @@ public class GnssDevice {
|
||||
// 参数改变
|
||||
private Integer change_flag = 0;
|
||||
|
||||
private String parentid1;
|
||||
|
||||
private String getBatteryConfigCmd(){
|
||||
return "d3130006"+ HexUtil.Int2HexString(Integer.parseInt(deviceid))+
|
||||
"55"+(has_battery?"01":"00");
|
||||
|
||||
@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -60,11 +61,17 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
|
||||
// 推送基站数据
|
||||
if(deviceBs.getOpMode() == GnssDevice.OP_MODE_USE) {
|
||||
byte[] forwardBytes = message.getSrcData();
|
||||
// 要求快速转发,因此用缓存,不要每次都查数据库
|
||||
List<Device> deviceList = deviceService.findByParentId(id);
|
||||
//logger.debug("base station {} has {} rovers: ", message.getId(),deviceList.size());
|
||||
// 获取使用该基站(包括作为主基站和备选基站)的所有测站
|
||||
List<Device> primaryDevices = deviceService.findByParentId(id);
|
||||
List<Device> backupDevices = deviceService.findByParentId1(id);
|
||||
|
||||
// 合并两个列表
|
||||
List<Device> allDevices = new ArrayList<>();
|
||||
allDevices.addAll(primaryDevices);
|
||||
allDevices.addAll(backupDevices);
|
||||
|
||||
DeviceChannel deviceChannel = null;
|
||||
for (Device device : deviceList) {
|
||||
for (Device device : allDevices) {
|
||||
if (device.getOpMode() != GnssDevice.OP_MODE_USE) continue;
|
||||
if (device.getFixedNum()>0 && device.getGnssSampleRate()>1
|
||||
&& (deviceBs.getD3xxCount()%device.getGnssSampleRate()) != 0) {
|
||||
@ -72,6 +79,20 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
|
||||
continue;
|
||||
}
|
||||
String deviceId = device.getDeviceId();
|
||||
|
||||
// 检查该设备是否应该接收此基站的数据
|
||||
String primaryBaseId = device.getParentId();
|
||||
String backupBaseId = device.getParentId1();
|
||||
|
||||
// 如果当前基站是该设备的备选基站,需要检查主基站是否离线
|
||||
if (id.equals(backupBaseId)) {
|
||||
Device primaryBase = deviceService.findByDeviceId(primaryBaseId);
|
||||
// 如果主基站仍然在线,则跳过备选基站的数据
|
||||
if (primaryBase != null && isBaseStationOnline(primaryBase)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取设备通道并发送数据
|
||||
if(device.getDataChannelType() == Device.CHANNEL_TYPE_UDP) {
|
||||
deviceChannel = OnlineChannels.INSTANCE.getDataChannel(deviceId);
|
||||
@ -96,6 +117,9 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
buf.writeBytes(forwardBytes);
|
||||
deviceChannel.writeAndFlush(buf);
|
||||
if(deviceChannel != null && deviceChannel.isOnline()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("forward d331 rtcm from {} to device {}", id, deviceId);
|
||||
}
|
||||
} else if (baseStationModel == 0) {
|
||||
//logger.info("Base station model is 0 for device: {}", deviceId);
|
||||
@ -293,8 +317,20 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getMessageType() {
|
||||
return D331RtcmMessage.class;
|
||||
|
||||
/**
|
||||
* 判断住基站是否在线
|
||||
* @param baseStation 基站
|
||||
* @return 是否在线
|
||||
*/
|
||||
|
||||
private boolean isBaseStationOnline(Device baseStation){
|
||||
if(baseStation == null) return false;
|
||||
|
||||
LocalDateTime now =LocalDateTime.now();
|
||||
return baseStation.getLastRxTime() !=null &&
|
||||
baseStation.getLastRxTime().isAfter(now.minusMinutes(30));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -90,6 +90,8 @@ public class Device {
|
||||
byte cfgChannelType = CHANNEL_TYPE_TCP; // 0:TCP;1:DUP
|
||||
byte dataChannelType = CHANNEL_TYPE_UDP; // 0:TCP;1:DUP
|
||||
|
||||
private String parentId1;
|
||||
|
||||
public void updateRx(int head, int bytes,int count){
|
||||
lastRxHead = head;
|
||||
|
||||
|
||||
@ -11,4 +11,6 @@ public interface DeviceService {
|
||||
Device findByDeviceId(String deviceId);
|
||||
|
||||
List<Device> findByParentId(String parentId);
|
||||
|
||||
List<Device> findByParentId1(String parentId1);
|
||||
}
|
||||
|
||||
@ -65,6 +65,19 @@ public class LocalDeviceServiceImpl implements DeviceService {
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
public List<Device> getDeviceListFromDBByParentId1(String parentId1) {
|
||||
QueryWrapper<GnssDevice> query = new QueryWrapper();
|
||||
query.eq("parentid1", parentId1);
|
||||
List<GnssDevice> gnssDeviceList = gnssDeviceMapper.selectList(query);
|
||||
List<Device> deviceList = new ArrayList<>(gnssDeviceList.size());
|
||||
for (GnssDevice gnssDevice : gnssDeviceList) {
|
||||
Device device = findByDeviceId(gnssDevice.getDeviceid());
|
||||
if(device!=null) deviceList.add(device);
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device findByDeviceId(String deviceId) {
|
||||
Device device = deviceCache.getIfPresent(deviceId);
|
||||
@ -89,6 +102,18 @@ public class LocalDeviceServiceImpl implements DeviceService {
|
||||
return devices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> findByParentId1(String parentId1) {
|
||||
List<Device> devices = subDeviceCache.getIfPresent(parentId1);
|
||||
if (devices == null) {
|
||||
devices = getDeviceListFromDBByParentId1(parentId1);
|
||||
if (devices != null) {
|
||||
subDeviceCache.put(parentId1, devices);
|
||||
}
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
public void refresh(String deviceId, String oldParentId){
|
||||
Device device = deviceCache.getIfPresent(deviceId);
|
||||
if (device != null) {
|
||||
|
||||
@ -89,6 +89,12 @@
|
||||
<input type="number" name="parentid" id="parentid" th:field="*{parentid}" placeholder="请输入关联基准站编号" value="" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline" >
|
||||
<label class="layui-form-label">备选基站</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="parentid1" id="parentid1" th:field="*{parentid1}" placeholder="请输入备选基准站编号" value="" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item" id="ecef_div">
|
||||
<div class="layui-inline">
|
||||
@ -307,7 +313,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
function checkDeviceId(){
|
||||
var $ = layui.$;
|
||||
var value = $("#deviceid").val();
|
||||
console.log(value);
|
||||
if(value.startsWith("6") || value.startsWith("7")){
|
||||
$("#has_battery").val('1');
|
||||
$("#has_battery").attr('disabled',true);
|
||||
}
|
||||
else{
|
||||
$("#has_battery").attr('disabled',false);
|
||||
}
|
||||
layui.form.render();
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user