bug fixed: D342消息处理,已在本地做过单元测试
This commit is contained in:
parent
ee9cd377f1
commit
b4d0f27cc7
@ -3,6 +3,7 @@ package com.imdroid.sideslope.calc;
|
|||||||
import com.imdroid.sideslope.message.BaseMessage;
|
import com.imdroid.sideslope.message.BaseMessage;
|
||||||
import com.imdroid.sideslope.message.D341LocationMessage;
|
import com.imdroid.sideslope.message.D341LocationMessage;
|
||||||
import com.imdroid.sideslope.message.D342LocationMessage;
|
import com.imdroid.sideslope.message.D342LocationMessage;
|
||||||
|
import com.imdroid.sideslope.service.GNSSDeviceLocationRecordService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -18,6 +19,8 @@ public class MultiLineGNSSCalcService {
|
|||||||
private static final Map<String, LocalDateTime> deviceMap = new ConcurrentHashMap<>();
|
private static final Map<String, LocalDateTime> deviceMap = new ConcurrentHashMap<>();
|
||||||
@Autowired
|
@Autowired
|
||||||
SingleLineGNSSCalcService calcService;
|
SingleLineGNSSCalcService calcService;
|
||||||
|
@Autowired
|
||||||
|
private GNSSDeviceLocationRecordService dataPersistService;
|
||||||
|
|
||||||
public void calc(D342LocationMessage d342Message){
|
public void calc(D342LocationMessage d342Message){
|
||||||
// 如果时间跨度大于1分钟,或者不含d341,则计算平滑值
|
// 如果时间跨度大于1分钟,或者不含d341,则计算平滑值
|
||||||
@ -38,6 +41,7 @@ public class MultiLineGNSSCalcService {
|
|||||||
for(BaseMessage message: d342Message.getMessageList()){
|
for(BaseMessage message: d342Message.getMessageList()){
|
||||||
D341LocationMessage d341Message = (D341LocationMessage)message;
|
D341LocationMessage d341Message = (D341LocationMessage)message;
|
||||||
calcService.calcSingle(d341Message, false);
|
calcService.calcSingle(d341Message, false);
|
||||||
|
dataPersistService.saveRawData(d341Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import java.time.LocalDateTime;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public abstract class BaseMessage {
|
public abstract class BaseMessage {
|
||||||
protected short header;
|
protected int header;
|
||||||
protected String id;
|
protected String id;
|
||||||
protected int len;
|
protected int len;
|
||||||
protected int seq;
|
protected int seq;
|
||||||
@ -28,7 +28,7 @@ public abstract class BaseMessage {
|
|||||||
if (shouldDecodeHeader()) {
|
if (shouldDecodeHeader()) {
|
||||||
// read操作会移动ByteBuf内部指针,除D331外,其他都用read来读
|
// read操作会移动ByteBuf内部指针,除D331外,其他都用read来读
|
||||||
int packetLen = src.readableBytes();
|
int packetLen = src.readableBytes();
|
||||||
this.header = src.readShort();
|
this.header = src.readUnsignedShort();
|
||||||
|
|
||||||
this.len = src.readUnsignedShort();
|
this.len = src.readUnsignedShort();
|
||||||
this.seq = this.len >> 11;
|
this.seq = this.len >> 11;
|
||||||
|
|||||||
@ -12,7 +12,7 @@ public class D31xConfigAckMessage extends BaseMessage {
|
|||||||
@Override
|
@Override
|
||||||
public void decodeBody(ByteBuf src) {
|
public void decodeBody(ByteBuf src) {
|
||||||
//srcData需要完整的消息,所以解析头用get方法
|
//srcData需要完整的消息,所以解析头用get方法
|
||||||
this.header = src.getShort(0); // flag
|
this.header = src.getUnsignedShort(0); // flag
|
||||||
this.len = src.getUnsignedShort(2); // length:11bit
|
this.len = src.getUnsignedShort(2); // length:11bit
|
||||||
this.seq = this.len >> 11;
|
this.seq = this.len >> 11;
|
||||||
this.len = this.len & 0x7FF;
|
this.len = this.len & 0x7FF;
|
||||||
|
|||||||
@ -12,7 +12,7 @@ public class D331RtcmMessage extends BaseMessage {
|
|||||||
@Override
|
@Override
|
||||||
public void decodeBody(ByteBuf src) {
|
public void decodeBody(ByteBuf src) {
|
||||||
// get操作不会移动指针,这样可以确保整个全转发出去
|
// get操作不会移动指针,这样可以确保整个全转发出去
|
||||||
this.header = src.getShort(0); // flag
|
this.header = src.getUnsignedShort(0); // flag
|
||||||
this.len = src.getUnsignedShort(2); // length:11 bits
|
this.len = src.getUnsignedShort(2); // length:11 bits
|
||||||
this.seq = this.len >> 11;
|
this.seq = this.len >> 11;
|
||||||
this.len = this.len & 0x7FF;
|
this.len = this.len & 0x7FF;
|
||||||
|
|||||||
@ -20,7 +20,7 @@ public class D342LocationMessage extends BaseMessage {
|
|||||||
@Override
|
@Override
|
||||||
public void decodeBody(ByteBuf src) {
|
public void decodeBody(ByteBuf src) {
|
||||||
// d3 51 length(2048+6) device_id(4bytes) seq(2bytes) data
|
// d3 51 length(2048+6) device_id(4bytes) seq(2bytes) data
|
||||||
this.header = src.readShort(); // flag
|
this.header = src.readUnsignedShort(); // flag
|
||||||
this.len = src.readUnsignedShort();
|
this.len = src.readUnsignedShort();
|
||||||
this.id = String.valueOf(src.readUnsignedInt()); //id
|
this.id = String.valueOf(src.readUnsignedInt()); //id
|
||||||
this.seq = src.readUnsignedShort();
|
this.seq = src.readUnsignedShort();
|
||||||
@ -37,12 +37,22 @@ public class D342LocationMessage extends BaseMessage {
|
|||||||
// 拆分D341,指针已移动到d341了
|
// 拆分D341,指针已移动到d341了
|
||||||
int totalLen = src.readableBytes();
|
int totalLen = src.readableBytes();
|
||||||
int begin = 15; // d341 head: 10, date: 5
|
int begin = 15; // d341 head: 10, date: 5
|
||||||
|
if(totalLen + begin - 4 > this.len) totalLen = this.len + 4 - begin;
|
||||||
|
|
||||||
|
int msgLen = 0;
|
||||||
while(begin+2 < totalLen){
|
while(begin+2 < totalLen){
|
||||||
int msgLen = src.getUnsignedShort(begin+2);
|
int flag = src.getUnsignedShort(begin);
|
||||||
msgLen = msgLen&0x07FF;
|
// 有时候两个d341会多一些字节,原因未明
|
||||||
msgLen = msgLen + 4;
|
if(flag != 0xD341){
|
||||||
if(msgLen > totalLen) break; //error
|
if(begin+msgLen > totalLen) break;
|
||||||
|
else {
|
||||||
|
begin++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msgLen = src.getUnsignedShort(begin+2);
|
||||||
|
msgLen = (msgLen&0x07FF) + 4;
|
||||||
|
if(begin+msgLen > totalLen) break; //error
|
||||||
|
|
||||||
ByteBuf msgBuf = src.slice(begin,msgLen);
|
ByteBuf msgBuf = src.slice(begin,msgLen);
|
||||||
BaseMessage message = new D341LocationMessage();
|
BaseMessage message = new D341LocationMessage();
|
||||||
@ -51,7 +61,6 @@ public class D342LocationMessage extends BaseMessage {
|
|||||||
messageList.add(message);
|
messageList.add(message);
|
||||||
|
|
||||||
// next data
|
// next data
|
||||||
totalLen -= msgLen;
|
|
||||||
begin += msgLen;
|
begin += msgLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,9 +53,9 @@ public class DeviceChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRxBytes(int bytes, short header){
|
public void updateRxBytes(int bytes, int header){
|
||||||
rxbytes += bytes;
|
rxbytes += bytes;
|
||||||
if(header == (short) 0xd331) d3xxbytes += bytes;
|
if(header == 0xd331) d3xxbytes += bytes;
|
||||||
else if(header == (short)0xd341) b562bytes += bytes;
|
else if(header == 0xd341) b562bytes += bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user