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