diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/DeviceChannel.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/DeviceChannel.java index a206d0fd..fb892d5b 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/DeviceChannel.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/DeviceChannel.java @@ -14,6 +14,7 @@ import java.net.InetSocketAddress; @Data public class DeviceChannel { private String deviceId; + private String imei; private Channel channel; diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/OnlineChannels.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/OnlineChannels.java index 752dad77..bcef3704 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/OnlineChannels.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/OnlineChannels.java @@ -5,6 +5,7 @@ import io.netty.channel.Channel; import io.netty.util.Attribute; import io.netty.util.AttributeKey; +import java.net.InetSocketAddress; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -12,6 +13,8 @@ import java.util.stream.Collectors; /** * @author Layton * @date 2023/2/2 21:00 + * 提供两种获取channel的方法:通过deviceId;通过imei。imei是DTU连接服务器最先上报的消息 + * 利用imei-ipaddr-deviceId,可以发现imei和deviceId的绑定关系 */ public class OnlineChannels { @@ -19,7 +22,7 @@ public class OnlineChannels { // DTU已连接,有imei上报,但deviceId还没上报 // 记录DTU连接的好处:当DTU重连接而设备还没上报deviceId时,可以通过IMEI或广播消息来找到设备 - private final Map dtuChannels = new ConcurrentHashMap<>(); + private final Map dtuChannels = new ConcurrentHashMap<>(); // 设备已连接,deviceId已上报 private final Map channels = new ConcurrentHashMap<>(); @@ -36,16 +39,25 @@ public class OnlineChannels { return (attr.get()==null); } - public void putDtuChannel(Channel channel, String imei){ - dtuChannels.put(imei, channel); - Attribute attr = channel.attr(AttributeKey.valueOf("imei")); - attr.set(imei); + public void putDtuChannel(String imei, InetSocketAddress address){ + dtuChannels.put(address, imei); } - public void putDeviceChannel(DeviceChannel channel) { - Attribute attr = channel.getChannel().attr(AttributeKey.valueOf("device_id")); - attr.set(channel.getDeviceId()); - channels.put(channel.getDeviceId(), channel); + public DeviceChannel updateDeviceChannel(String deviceId, Channel channel, InetSocketAddress address) { + DeviceChannel deviceChannel = channels.get(deviceId); + if(deviceChannel == null){ + deviceChannel = new DeviceChannel(deviceId, channel, address); + channels.put(deviceId, deviceChannel); + } + else { + deviceChannel.setChannel(channel); + deviceChannel.setAddress(address); + } + + String imei = dtuChannels.get(address); + if(imei != null) deviceChannel.setImei(imei); + + return deviceChannel; } public Optional get(String deviceId) { @@ -59,4 +71,5 @@ public class OnlineChannels { public DeviceChannel getDeviceChannel(String deviceId){ return channels.get(deviceId); } + } diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/udp/RtcmUdpHandler.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/udp/RtcmUdpHandler.java index 6237ab64..c711cd77 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/udp/RtcmUdpHandler.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/udp/RtcmUdpHandler.java @@ -49,16 +49,16 @@ public class RtcmUdpHandler extends ChannelInboundHandlerAdapter { } // 消息解析 BaseMessage message = MessageParser.instance.parse(packet.content()); - // 更新通道 - DeviceChannel deviceChannel; - if(onlineChannels.isNewDeviceChannel(ctx.channel())){ - deviceChannel = new DeviceChannel(message.getId(), ctx.channel(), packet.sender()); - onlineChannels.putDeviceChannel(deviceChannel); + // 为加快处理速度,只有收到D3F0/D3F2时才更新通道,包括对端地址和绑定imei + DeviceChannel deviceChannel = null; + if(message.getHeader() == (short)0xD3F0 || message.getHeader() == (short)0xD3F2){ + onlineChannels.updateDeviceChannel(message.getId(), ctx.channel(), packet.sender()); } - else{ - deviceChannel = onlineChannels.getDeviceChannel(message.getId()); + else deviceChannel = onlineChannels.getDeviceChannel(message.getId()); + + if(deviceChannel!= null) { + deviceChannel.updateRxBytes(message.getLen(), message.getHeader()); } - deviceChannel.updateRxBytes(message.getLen(), message.getHeader()); // 业务处理 bizExecutors.execute(message); } catch (UnSupportedMessageException e) { @@ -67,7 +67,7 @@ public class RtcmUdpHandler extends ChannelInboundHandlerAdapter { byte[] data = new byte[packet.content().readableBytes()]; packet.content().getBytes(0, data); if(data.length == 15 && data[0]=='8' && data[1]=='6') { - OnlineChannels.INSTANCE.putDtuChannel(ctx.channel(), new String(data)); + OnlineChannels.INSTANCE.putDtuChannel(new String(data), packet.sender()); } else logger.warn("receive un supported message: {}", e.getMessage()); } @@ -82,7 +82,6 @@ public class RtcmUdpHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { super.exceptionCaught(ctx, cause); - ctx.close(); logger.error("Exception caught: {}", cause.toString()); } } diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssSingleCalcDataController.java b/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssSingleCalcDataController.java new file mode 100644 index 00000000..b176776d --- /dev/null +++ b/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssSingleCalcDataController.java @@ -0,0 +1,37 @@ +package com.imdroid.beidou.controller; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.imdroid.secapi.dto.GnssMsg; +import com.imdroid.secapi.dto.GnssSingleCalcData; +import com.imdroid.secapi.dto.GnssSingleCalcDataMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class GnssSingleCalcDataController extends BasicController{ + @Autowired + GnssSingleCalcDataMapper dataMapper; + @RequestMapping("/page/gnss_data_raw") + public String gnssDataRaw()throws Exception { + return "/page/gnss_data_raw"; + } + + /**** 推送数据 *****/ + @RequestMapping("/gnss/data/list_raw") + @ResponseBody + public JSONObject listMsg(int page, int limit) { + Page pageable = new Page<>(page, limit); + IPage cs = dataMapper.selectPage(pageable, null); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code", 0); + jsonObject.put("msg", ""); + jsonObject.put("count", cs.getTotal()); + jsonObject.put("data", cs.getRecords()); + return jsonObject; + } +} diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/controller/LayuiController.java b/sec-beidou/src/main/java/com/imdroid/beidou/controller/LayuiController.java index 242a586a..45a4993e 100644 --- a/sec-beidou/src/main/java/com/imdroid/beidou/controller/LayuiController.java +++ b/sec-beidou/src/main/java/com/imdroid/beidou/controller/LayuiController.java @@ -30,11 +30,6 @@ public class LayuiController extends BasicController{ return "/page/gnss_data_calc"; } - @RequestMapping("/page/gnss_data_raw") - public String gnssDataRaw()throws Exception { - return "/page/gnss_data_raw"; - } - @RequestMapping("/page/gnss_data_tools") public String gnssDataTools()throws Exception { return "/page/gnss_data_tools"; diff --git a/sec-beidou/src/main/resources/static/api/gnss_data_raw.json b/sec-beidou/src/main/resources/static/api/gnss_data_raw.json deleted file mode 100644 index 7e49315e..00000000 --- a/sec-beidou/src/main/resources/static/api/gnss_data_raw.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "code": 0, - "msg": "", - "count": 1000, - "data": [ - { - "deviceid": "2307001", - "report_time": "2023-01-01 12:23:56", - "b562e": "22.12", - "b562n": "10.24", - "b562d": "5.1", - "roll": "0.1", - "pitch": "0.2", - "yaw": "90.1", - "pps": "512", - "sat_count": "24", - "sat_used": "10" - }, - { - "deviceid": "2307001", - "report_time": "2023-01-01 12:23:56", - "b562e": "22.12", - "b562n": "10.24", - "b562d": "5.1", - "roll": "0.1", - "pitch": "0.2", - "yaw": "90.1", - "pps": "512", - "sat_count": "24", - "sat_used": "10" - }, - { - "deviceid": "2307001", - "report_time": "2023-01-01 12:23:56", - "b562e": "22.12", - "b562n": "10.24", - "b562d": "5.1", - "roll": "0.1", - "pitch": "0.2", - "yaw": "90.1", - "pps": "512", - "sat_count": "24", - "sat_used": "10" - } - ] -} \ No newline at end of file diff --git a/sec-beidou/src/main/resources/static/api/gnss_dev_cfg.json b/sec-beidou/src/main/resources/static/api/gnss_dev_cfg.json deleted file mode 100644 index c53c44ae..00000000 --- a/sec-beidou/src/main/resources/static/api/gnss_dev_cfg.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "code": 0, - "msg": "", - "count": 100, - "data": [ - { - "id": "2307001", - "name": "1号机", - "parent_id": "", - "device_type": "基站", - "location": "广州", - "project_id": "0", - "group_id": "1", - "calc_id": "1", - "op_mode": "正常", - "syn": "是" - }, - { - "id": "2307002", - "name": "2号机", - "parent_id": "2307001", - "device_type": "测站", - "location": "广州", - "project_id": "0", - "group_id": "1", - "calc_id": "1", - "op_mode": "正常", - "syn": "是" - }, - { - "id": "2307003", - "name": "3号机", - "parent_id": "2307001", - "device_type": "测站", - "location": "广州", - "project_id": "0", - "group_id": "1", - "calc_id": "1", - "op_mode": "正常", - "syn": "是" - }, - { - "id": "2307004", - "name": "1号机", - "parent_id": "2307001", - "device_type": "测站", - "location": "广州", - "project_id": "0", - "group_id": "1", - "calc_id": "1", - "op_mode": "维护", - "syn": "否" - } - ] -} \ No newline at end of file diff --git a/sec-beidou/src/main/resources/static/api/gnss_msg.json b/sec-beidou/src/main/resources/static/api/gnss_msg.json deleted file mode 100644 index 357c7525..00000000 --- a/sec-beidou/src/main/resources/static/api/gnss_msg.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "code": 0, - "msg": "", - "count": 1000, - "data": [ - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "type": "配置", - "content": "D3 11 00 09 00 23 33 DD 1E 06 00 00 01" - }, - { - "device_id": "2307011", - "report_time": "2023-01-01 12:23:56", - "type": "配置应答", - "content": "D3 11 00 0A 00 23 33 DD 1E 06 00 00 01 01" - }, - { - "device_id": "2307021", - "report_time": "2023-01-01 12:23:56", - "type": "通知", - "content": "D3 F0 00 09 00 23 33 DD" - }, - { - "device_id": "2307031", - "report_time": "2023-01-01 12:23:56", - "type": "通知", - "content": "D3 F2 00 09 00 23 33 DD" - } - ] -} \ No newline at end of file diff --git a/sec-beidou/src/main/resources/static/api/gnss_msg_status.json b/sec-beidou/src/main/resources/static/api/gnss_msg_status.json deleted file mode 100644 index 16ea5009..00000000 --- a/sec-beidou/src/main/resources/static/api/gnss_msg_status.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "code": 0, - "msg": "", - "count": 1000, - "data": [ - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "local_time": "2023-01-01 12:23:56", - "roll": "0.1", - "pitch": "0.2", - "yaw": "90.1", - "rssi": "31", - "voltage": "9900", - "temperature": "45", - "humidity": "30" - }, - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "local_time": "2023-01-01 12:23:56", - "roll": "0.1", - "pitch": "0.2", - "yaw": "90.1", - "rssi": "31", - "voltage": "9900", - "temperature": "45", - "humidity": "30" - }, - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "local_time": "2023-01-01 12:23:56", - "roll": "0.1", - "pitch": "0.2", - "yaw": "90.1", - "rssi": "31", - "voltage": "9900", - "temperature": "45", - "humidity": "30" - }, - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "local_time": "2023-01-01 12:23:56", - "roll": "0.1", - "pitch": "0.2", - "yaw": "90.1", - "rssi": "31", - "voltage": "9900", - "temperature": "45", - "humidity": "30" - } - ] -} \ No newline at end of file diff --git a/sec-beidou/src/main/resources/static/api/gnss_msg_trx.json b/sec-beidou/src/main/resources/static/api/gnss_msg_trx.json deleted file mode 100644 index 4e949622..00000000 --- a/sec-beidou/src/main/resources/static/api/gnss_msg_trx.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "code": 0, - "msg": "", - "count": 1000, - "data": [ - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "local_time": "12:23:56", - "server_rx": "300123", - "server_tx": "212200", - "uart1_rx": "212200", - "uart1_tx": "300123", - "uart1_unknown": "9900", - "uart2_rx": "300123", - "uart2_tx": "212200", - "uart2_unknown": "30" - }, - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "local_time": "12:23:56", - "server_rx": "300123", - "server_tx": "212200", - "uart1_rx": "212200", - "uart1_tx": "300123", - "uart1_unknown": "9900", - "uart2_rx": "300123", - "uart2_tx": "212200", - "uart2_unknown": "30" - }, - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "local_time": "12:23:56", - "server_rx": "300123", - "server_tx": "212200", - "uart1_rx": "212200", - "uart1_tx": "300123", - "uart1_unknown": "9900", - "uart2_rx": "300123", - "uart2_tx": "212200", - "uart2_unknown": "30" - }, - { - "device_id": "2307001", - "report_time": "2023-01-01 12:23:56", - "local_time": "12:23:56", - "server_rx": "300123", - "server_tx": "212200", - "uart1_rx": "212200", - "uart1_tx": "300123", - "uart1_unknown": "9900", - "uart2_rx": "300123", - "uart2_tx": "212200", - "uart2_unknown": "30" - } - ] -} \ No newline at end of file diff --git a/sec-beidou/src/main/resources/templates/page/gnss_data_raw.html b/sec-beidou/src/main/resources/templates/page/gnss_data_raw.html index c7c69f8b..e7f04641 100644 --- a/sec-beidou/src/main/resources/templates/page/gnss_data_raw.html +++ b/sec-beidou/src/main/resources/templates/page/gnss_data_raw.html @@ -53,7 +53,7 @@ table.render({ elem: '#currentTableId', - url: 'api/gnss_data_raw.json',//假数据 + url: '/gnss/data/list_raw',//假数据 defaultToolbar: ['filter', 'exports', 'print', { title: '提示', layEvent: 'LAYTABLE_TIPS', @@ -61,16 +61,14 @@ }], cols: [[ {field: 'deviceid', title: '设备号'}, - {field: 'report_time', title: '时间'}, + {field: 'createtime', title: '上报时间', templet: "
{{layui.util.toDateString(d.createtime, 'yyyy-MM-dd HH:mm:ss')}}
"}, {field: 'b562e', title: '原始东'}, {field: 'b562n', title: '原始北'}, {field: 'b562d', title: '原始天'}, {field: 'roll', title: 'roll'}, {field: 'pitch', title: 'pitch'}, {field: 'yaw', title: 'yaw'}, - {field: 'pps', title: '平均延迟'}, - {field: 'sat_count', title: '卫星数'}, - {field: 'sat_used', title: '使用卫星数'}, + {field: 'shock', title: 'shock'} ]], limits: [10, 15, 20, 25, 50, 100], limit: 15,