优化统计消息

This commit is contained in:
weidong 2024-02-15 11:18:49 +08:00
parent 97acf5442c
commit 0206d6c097
8 changed files with 54 additions and 18 deletions

View File

@ -33,8 +33,6 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
// 补齐tenantId
Device device1 = deviceService.findByDeviceId(id);
if(device1 == null || device1.getOpMode() == GnssDevice.OP_MODE_UNUSE) return null;
message.setTenantId(device1.getTenantId());
device1.updateD331Bytes(message.getLen());
if (logger.isDebugEnabled()) {
logger.debug("receive d331 rtcm message of device: "+message.getId()+", seq:"+message.getSeq()+", len:"+message.getLen());
}
@ -57,6 +55,8 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
}
}
message.setTenantId(device1.getTenantId());
device1.updateD331Bytes(message.getLen(),message.getPacketNum());
Gga gga = message.getGga();
if(gga != null) {
device1.updateSatelitesNum(gga.getSatellitesInUsed());

View File

@ -49,8 +49,10 @@ public class D3F2StopIndicationMessageExecutor implements Executor<D3F2StopIndic
if(device == null) return null;
message.setTenantId(device.getTenantId());
GnssTrxMsg gnssTrxMsg = message.getTrxMsg();
gnssTrxMsg.setTenantid(device.getTenantId());
gnssTrxMsg.setD3xxbytes(device.getD3xxbytes());
gnssTrxMsg.setB562bytes(device.getD341bytes());
gnssTrxMsg.setSatelliteinuse(device.getSatelitesInUse());
// 储设备收发字节数统计信息
ThreadManager.getFixedThreadPool().submit(() -> {

View File

@ -26,12 +26,12 @@ public abstract class BaseMessage {
this.createTime = LocalDateTime.now();
if (shouldDecodeHeader()) {
// read操作会移动ByteBuf内部指针除D331外其他都用read来读
int packetLen = src.readableBytes();
//int packetLen = src.readableBytes();
this.header = src.readUnsignedShort();
this.len = src.readUnsignedShort();
this.seq = this.len >> 11;
this.len = packetLen;//this.len & 0x7FF;
this.len = this.len & 0x7FF;
this.id = String.valueOf(src.readUnsignedInt());
/*if (packetLen - 4 != this.len) {
String msg = (String.format("id[%s],长度字段值[%s]与包的消息体长度[%s]不匹配", id, this.len, packetLen - 4));

View File

@ -2,22 +2,38 @@ package com.imdroid.sideslope.message;
import com.imdroid.sideslope.bd.Gga;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author Layton
* @date 2023/2/2 20:47
*/
@Data
@EqualsAndHashCode(callSuper=true)
public class D331RtcmMessage extends BaseMessage {
Gga gga;
int packetNum;
@Override
public void decodeBody(ByteBuf src) {
// get操作不会移动指针这样可以确保整个全转发出去
this.header = src.getUnsignedShort(0); // flag
this.len = src.getUnsignedShort(2); // length:11 bits
this.seq = this.len >> 11;
this.packetNum = 1;
this.len = src.readableBytes();//this.len & 0x7FF;//有可能两个d331粘包
this.header = src.getUnsignedShort(0); // flag
int onePacketLen = src.getUnsignedShort(2); // length:11 bits
this.seq = onePacketLen >> 11;
onePacketLen = onePacketLen&0x7FF;
this.id = String.valueOf(src.getUnsignedInt(4)); //id
int pos = onePacketLen + 4;
while(pos < this.len){
if(src.getUnsignedShort(pos) == 0xd331){
onePacketLen = src.getUnsignedShort(pos+2)&0x7FF;
pos = pos+4+onePacketLen;
packetNum ++;
}
else pos++;
}
/*if (src.readableBytes() - 4 < this.len) {
String msg = String.format("id[%s],长度字段值[%s]效益包的消息体长度[%s]", id, this.len, src.readableBytes() - 4);
WrongMessageRecorder.INSTANCE.append("receive wrong message," + msg);
@ -31,6 +47,4 @@ public class D331RtcmMessage extends BaseMessage {
public boolean shouldDecodeHeader() {
return false;
}
public Gga getGga() {return gga;}
}

View File

@ -20,12 +20,12 @@ public class D341LocationMessage extends BaseMessage {
@Override
public void decodeBody(ByteBuf src) {
// read操作会移动ByteBuf内部指针除D331外其他都用read来读
int packetLen = src.readableBytes();
//int packetLen = src.readableBytes();
int pos = 0;
this.header = src.getUnsignedShort(pos);pos+=2;
this.len = src.getUnsignedShort(pos);pos+=2;
this.seq = this.len >> 11;
this.len = packetLen;//this.len & 0x7FF;
this.len = this.len & 0x7FF;
this.id = String.valueOf(src.getUnsignedInt(pos));pos+=4; //id
/*if (packetLen - 4 != this.len) {
String msg = (String.format("id[%s],长度字段值[%s]与包的消息体长度[%s]不匹配", id, this.len, packetLen - 4));

View File

@ -17,6 +17,7 @@ import java.time.LocalTime;
public class D3F2StopIndicationMessage extends BaseMessage {
private GnssTrxMsg trxMsg = new GnssTrxMsg();
private String otherInfo;
@Override
public void decodeBody(ByteBuf src) {
@ -39,7 +40,17 @@ public class D3F2StopIndicationMessage extends BaseMessage {
trxMsg.setUart2rxbytes((int) value);
} else if (key == 5) {
trxMsg.setUart2unknown((int) value);
}else if (key == 6) {//粘包
otherInfo = "stick num:"+value;
//trxMsg.setUart2unknown((int) value);
}else if (key == 7) {//分片
otherInfo = otherInfo + ", frag num:"+value;
//trxMsg.setUart2unknown((int) value);
}else if (key == 8) {//其他错误
otherInfo = otherInfo + ", other err:"+value;
//trxMsg.setUart2unknown((int) value);
}
}
}

View File

@ -39,14 +39,15 @@ public class Device {
int d3xxbytes = 0;
int d341Count = 0;
int d341bytes = 0;
int satelitesInUse = 0;
int satelitesInUse = 0;//平均卫星数
int sataStatCount = 0;
Double latitude;
Double longitude;
Double altitude;
public void updateD331Bytes(int bytes){
d3xxCount++;
public void updateD331Bytes(int bytes,int count){
d3xxCount+=count;
d3xxbytes += bytes;
}
@ -56,7 +57,10 @@ public class Device {
}
public void updateSatelitesNum(int num){
satelitesInUse = num;
if(num>0) {
sataStatCount++;
satelitesInUse = (satelitesInUse*(sataStatCount-1) + num) / sataStatCount;
}
}
public void clearStat(){
@ -64,6 +68,8 @@ public class Device {
d3xxbytes = 0;
d341Count = 0;
d341bytes = 0;
sataStatCount = 0;
satelitesInUse = 0;
}
}

View File

@ -91,11 +91,14 @@ public class DataPersistServiceImpl implements DataPersistService {
try {
// 添加到trxmsg里
GnssTrxMsg trxMsg = message.getTrxMsg();
trxMsg.setTenantid(message.getTenantId());
trxMsg.setSatelliteinuse(device.getSatelitesInUse());
trxMsgMapper.insert(trxMsg);
// 保存消息摘要
saveMsg(message,null);
if(device.getDeviceType() == GnssDevice.TYPE_ROVER) {
saveMsg(message, "d341 num: "+device.getD341Count()+","+message.getOtherInfo());
}
else{
saveMsg(message, "d331 num: "+device.getD3xxCount()+","+message.getOtherInfo());
}
// 检测该对象是否已存在
GnssStatus deviceState = deviceStateRepository.getByDeviceId(message.getId());